File indexing completed on 2024-04-06 12:30:22
0001 #include "SimG4Core/Geometry/interface/CustomUIsession.h"
0002
0003 CustomUIsession::CustomUIsession() : fout(nullptr) {}
0004
0005 CustomUIsession::~CustomUIsession() {}
0006
0007 G4int CustomUIsession::ReceiveG4cout(const G4String& coutString) {
0008 if (fout) {
0009 (*fout) << trim(coutString) << "\n";
0010 } else {
0011 edm::LogVerbatim("G4cout") << trim(coutString);
0012 }
0013 return 0;
0014 }
0015
0016 G4int CustomUIsession::ReceiveG4cerr(const G4String& cerrString) {
0017 edm::LogWarning("G4cerr") << trim(cerrString);
0018 return 0;
0019 }
0020
0021 std::string CustomUIsession::trim(const std::string& str) {
0022 if (!str.empty() && str.back() == '\n')
0023 return str.substr(0, str.length() - 1);
0024 return str;
0025 }
0026
0027 void CustomUIsession::sendToFile(std::ofstream* ptr) {
0028 if (ptr && !ptr->fail()) {
0029 fout = ptr;
0030 }
0031 }