G4cout during a Run with a GUI

Dear all,

I have a question about the G4cout output using the Qt GUI.

If I have some G4cout in my code, for example in the SteppingAction and other classes, when I execute the command /run/beamOn the simulation starts, but all the cout are printed in the GUI at the end of the run.
And also, the GUI is like “frozen” during the Run (Windows say “not responds”).

Is there a way to get the cout during the Run?

I hope that the problem is clear…

Thank you for your help!

Andrea

Hi Andrea
I’m afraid the situation is exactly as you describe at the moment with the Qt GUI. In the past I have worked around it either by using std::out instead of G4cout or by writing to a file, which I can inspect even during a run (e.g., “less” in Unix). But be aware that for either of these workarounds in multithreading mode you have to do the mutex locking yourself (it is done for you in G4cout), as below.

John

namespace {
G4Mutex coutMutex = G4MUTEX_INITIALIZER;
}
...
  G4MUTEXLOCK(&coutMutex);
  std::out << whatever_you_want << std::endl;
  G4MUTEXUNLOCK(&coutMutex);

or

namespace {
G4Mutex outFileMutex = G4MUTEX_INITIALIZER;
std::ofstream outFile("outFile.dat");
}
...
  G4MUTEXLOCK(&outFileMutex);
  outFile << whatever_you_want << std::endl;
  G4MUTEXUNLOCK(&outFileMutex);

Hi,

I’m sorry for the delay in my answer!

Thanks a lot for this information, it will be very useful, specially for output to file!

I have found that in MT mode the G4cout works fine with the Qt GUI, in fact the output is printed during the simulation in the terminal window (I don’t know why not in the Qt GUI as in sequential mode, but that’s ok).

Andrea

Hi Andrea

You’re right about the Qt GUI. G4cout from worker threads is not captured by the GUI. I have just raised a bug report.

Best wishes

John