In the execution of Geant4 Simulation via DD4hep, random output was printed at the end of the execution from the destructor of the G4strstreambuffer. More details https://github.com/AIDASoft/DD4hep/issues/798. This bug is triggered because we don't use G4cout and G4endl anywhere in our execution, and because the G4DeexPrecoParameters::StreamInfo function never uses G4endl https://gitlab.cern.ch/geant4/geant4/-/blob/master/source/processes/hadronic/models/de_excitation/management/src/G4DeexPrecoParameters.cc#L294 to flush the output to screen. This lack of G4end is maybe also a bug, because this G4DeexPrecoParameter output appears far from where it should have been printed. But because G4endl isn't used, the G4strstreambuf sync() is never called, so at the end when the destructor is called and char* buffer is printed this buffer isn't '\0' terminated leading to the printout of random data. Proposed changes: 1) Add buffer[count] = '\0'; to ~G4strstreambuf ``` if(count != 0) { buffer[count] = '\0'; std::cout << buffer; } ``` 2) Add G4endl to G4DeexPrecoParameters::StreamInfo and similar functions.
Andre, I have replaced at the end of printout "\n" by G4endl. In my test there is no difference - the line break is the same. Can you, confirm, that this fix is working for you? Vladimir
Hi Vladimir, The main difference between `G4endl`(or std::endl); and `"\n"` is that the first one also causes a call to `flush()` (or equivalent), right? The change in https://github.com/AIDASoft/DD4hep/pull/799/files ``` try { return Geant4Exec::run(*this); auto result = Geant4Exec::run(*this); // flush the geant4 stream buffer G4cout << G4endl; return result; } ``` really fixes the "random" printout (also caused by that missing '\0', I believe). Having the G4endl at the end of G4DeexPrecoParameters::StreamInfo should also make this output appear at the actual time it is called and not at the end of our execution. Cheers, Andre
Hello, Many thanks for this report. The problem is fixed and will be available in next public version of Geant4 and in the next patch to 10.7 Vladimir