glogging
Loading...
Searching...
No Matches
gbatch_session.h
Go to the documentation of this file.
1#pragma once
2
3// geant4
4#include "G4UIsession.hh"
5
6// c++
7#include <fstream>
8
31class GBatch_Session : public G4UIsession
32{
33public:
47 // Open the batch log files immediately so all subsequent Geant4 output is captured.
48 logFile.open("gemc.log");
49 errFile.open("gemc.err");
50 }
51
61 G4int ReceiveG4cout(const G4String& coutString) override {
62 // Persist the message for post-run inspection...
63 logFile << coutString << std::flush;
64 // ...while also preserving real-time visibility on the terminal.
65 std::cout << coutString << std::flush;
66 return 0;
67 }
68
78 G4int ReceiveG4cerr(const G4String& cerrString) override {
79 // Persist stderr separately so errors can be grepped/triaged independently of stdout.
80 errFile << cerrString << std::flush;
81 std::cerr << cerrString << std::flush;
82 return 0;
83 }
84
85private:
86 std::ofstream logFile;
87 std::ofstream errFile;
88};
Batch-mode G4UIsession that tees Geant4 output to files and the terminal.
G4int ReceiveG4cerr(const G4String &cerrString) override
Receives Geant4 standard error and tees it to gemc.err and std::cerr.
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.