glogging
Loading...
Searching...
No Matches
GBatch_Session Class Reference

Batch-mode G4UIsession that tees Geant4 output to files and the terminal. More...

#include <gbatch_session.h>

Public Member Functions

 GBatch_Session ()
 Constructs the batch session and opens the log streams.
 
G4int ReceiveG4cout (const G4String &coutString) override
 Receives Geant4 standard output and tees it to gemc.log and std::cout.
 
G4int ReceiveG4cerr (const G4String &cerrString) override
 Receives Geant4 standard error and tees it to gemc.err and std::cerr.
 

Detailed Description

This class is designed to be passed to the Geant4 UI manager so that all G4cout and G4cerr traffic is redirected through G4UIsession callbacks. In batch/production runs, this enables persistent log capture while still keeping output visible on the console.

Operational behavior

  • On construction, the session opens two files in the current working directory:
    • gemc.log : destination for G4cout output
    • gemc.err : destination for G4cerr output
  • When ReceiveG4cout() is called by Geant4:
    • The message is appended to gemc.log
    • The same message is forwarded to std::cout
  • When ReceiveG4cerr() is called by Geant4:
    • The message is appended to gemc.err
    • The same message is forwarded to std::cerr
Note
The files are held open for the lifetime of the session object. They will be closed automatically when the std::ofstream members are destroyed.

Definition at line 31 of file gbatch_session.h.

Constructor & Destructor Documentation

◆ GBatch_Session()

GBatch_Session::GBatch_Session ( )
inline

This constructor opens gemc.log and gemc.err for writing.

Note
The default behavior of std::ofstream::open for a filename is to create/truncate the file unless additional open modes are specified.
Warning
If the process lacks permission to create or write these files in the current working directory, the streams may fail to open. Callers can inspect stream state if they need to handle such failures explicitly.

Definition at line 46 of file gbatch_session.h.

Member Function Documentation

◆ ReceiveG4cerr()

G4int GBatch_Session::ReceiveG4cerr ( const G4String & cerrString)
inlineoverride
Parameters
cerrStringThe message fragment provided by Geant4 for standard error.
Returns
Always returns 0 to indicate the message was handled.
Note
This method flushes both the file stream and std::cerr to reduce the chance of losing diagnostic output if the process terminates unexpectedly.

Definition at line 78 of file gbatch_session.h.

◆ ReceiveG4cout()

G4int GBatch_Session::ReceiveG4cout ( const G4String & coutString)
inlineoverride
Parameters
coutStringThe message fragment provided by Geant4 for standard output.
Returns
Always returns 0 to indicate the message was handled.
Note
This method flushes both the file stream and std::cout to keep logs consistent in long-running batch jobs.

Definition at line 61 of file gbatch_session.h.


The documentation for this class was generated from the following file: