LDMX Software
G4Session.cxx
Go to the documentation of this file.
1
7#include "SimCore/G4Session.h"
8
9#include "Framework/Exception/Exception.h"
10
11namespace simcore {
12
13LoggedSession::LoggedSession(const std::string& coutFileName,
14 const std::string& cerrFileName) {
15 coutFile_.open(coutFileName);
16 if (not coutFile_.is_open()) {
17 EXCEPTION_RAISE("G4Logging",
18 "Unable to open log file '" + coutFileName + "'.");
19 }
20
21 cerrFile_.open(cerrFileName);
22 if (not cerrFile_.is_open()) {
23 EXCEPTION_RAISE("G4Logging",
24 "Unable to open log file '" + cerrFileName + "'.");
25 }
26}
27
29 coutFile_.close();
30 cerrFile_.close();
31}
32
33G4int LoggedSession::ReceiveG4cout(const G4String& message) {
34 coutFile_ << message;
35 coutFile_.flush();
36 return 0; // 0 return value == sucess
37}
38
39G4int LoggedSession::ReceiveG4cerr(const G4String& message) {
40 cerrFile_ << message;
41 cerrFile_.flush();
42 return 0; // 0 return value == sucess
43}
44} // namespace simcore
Classes which redirect the output of G4cout and G4cerr.
std::ofstream cerrFile_
cerr log file
Definition G4Session.h:62
~LoggedSession()
Destructor.
Definition G4Session.cxx:28
G4int ReceiveG4cerr(const G4String &message)
Redirects cerr to file.
Definition G4Session.cxx:39
std::ofstream coutFile_
cout log file
Definition G4Session.h:59
LoggedSession(const std::string &coutFileName="G4cout.log", const std::string &cerrFileName="G4cerr.log")
Constructor.
Definition G4Session.cxx:13
G4int ReceiveG4cout(const G4String &message)
Redirects cout to file.
Definition G4Session.cxx:33