Dear all, following a suggestion by a colleague of yours (here https://bugzilla-geant4.kek.jp/show_bug.cgi?id=2347) I am working on replacing my crude Geant4 output suppression via stream failbits with a more appropriate solution. As I understand, the best way to achieve my goal (having full control over terminal output) is to derive from G4UIsession and to overload the Receive*() methods. This is what I do (abbreviated): class G4LoggingDestination : public G4UIsession { public: G4int G4LoggingDestination::ReceiveG4cout(const G4String& msg) { MY_LOGGER << msg; return 0; } }; In order to activate this I attach this class to the UI session in the RunManager's constructor (abbreviated): class RunManager : public G4RunManager { public: RunManager() { auto* my_logger = new G4LoggingDestination(); G4UImanager* ui_g4 = G4UImanager::GetUIpointer(); ui_g4->SetCoutDestination(my_logger); } }; and do the same for possible WorkerRunManager in their constructor. This approach seems to work fine for most output, however, there are two bits that don't respect the G4UIsession cout target: * At construction of the run manager, the Geant4 version is printed to plain std::cout: ************************************************************** Geant4 version Name: geant4-10-07-patch-01 [MT] (5-February-2021) << in Multi-threaded mode >> [...] ************************************************************** I'm not sure if this can be changed, i.e. if the G4cout stream is already present. * During InitializePhysics() of the RunManagerKernel, so at a much later stage, there is one tiny bit of information that uses the G4cout stream but does not seem to respect the UIsession target - I always get this printed directly to the terminal and not to my own logger instance. This comes from the Dump() method of the class G4DeexPrecoParameters in source/processes/hadronic/models/de_excitation/management/src/G4DeexPrecoParameters.cc ======================================================================= ====== Pre-compound/De-excitation Physics Parameters ======== ======================================================================= Type of pre-compound inverse x-section 3 [...] ======================================================================= Is there a way to fix this? All the best, Simon
Thanks for your report. Concerning about the Geant4 banner, it is shown to G4cout at the construction of the G4RunManagerKernel class. If you do need to write this banner to alternative destination, you need to instantiate your UIsession and CoutDestination prior to the construction of G4RunManager. You do not need to create your own RunManager. About the printout of "Pre-compound/De-excitation Physics Parameters", it is weird. As far as I see the source code of this printout, it is sent to G4cout. Thus, there is no reason it goes to the original window. Let me forward your report to the author of this class. Kind regards, Makoto
Dear Makoto, you are of course right concerning the Geant4 banner - I just don't catch it because the base constructor is called before my own RunManager's constructor. Thanks for the clarification. As for the other part, I discovered that with Geant4 v10.6.p02 I also see this message from the G4RadioactiveDecay class, but with 10.7.p01 this message is gone. Checking the diff for the relevant files, I see several changes similar to: source/processes/hadronic/models/radioactive_decay/src/G4RadioactiveDecay.cc #ifdef G4VERBOSE - if(G4Threading::IsMasterThread()) { StreamInfo(G4cout, "\n"); } + if(G4HadronicParameters::Instance()->GetVerboseLevel() > 0 && + G4Threading::IsMasterThread()) { StreamInfo(G4cout, "\n"); } #endif So it seems like it has been fixed there by inheriting the verbosity from the G4HandronicParameters. Probably the same should be done here? Best regards and many thanks, Simon
Hello, this is likely the same problem as #2350 (https://bugzilla-geant4.kek.jp/show_bug.cgi?id=2350 ). The problem is fixed now and the fix will be publicly available with the new patch to 10.7 and in the new public release. VI