CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Member Functions | Private Attributes
CustomUIsession Class Reference

#include <CustomUIsession.h>

Inheritance diagram for CustomUIsession:
CustomUIsessionThreadPrefix CustomUIsessionToFile

Public Member Functions

 CustomUIsession ()
 
G4int ReceiveG4cerr (const G4String &cerrString) override
 
G4int ReceiveG4cout (const G4String &coutString) override
 
void sendToFile (std::ofstream *)
 
void stopSendToFile ()
 
 ~CustomUIsession () override
 

Protected Member Functions

std::string trim (const std::string &str)
 

Private Attributes

std::ofstream * fout
 

Detailed Description

Definition at line 13 of file CustomUIsession.h.

Constructor & Destructor Documentation

◆ CustomUIsession()

CustomUIsession::CustomUIsession ( )

Definition at line 3 of file CustomUIsession.cc.

3  : fout(nullptr) {
4  G4UImanager* UI = G4UImanager::GetUIpointer();
5  UI->SetCoutDestination(this);
6 }

◆ ~CustomUIsession()

CustomUIsession::~CustomUIsession ( )
override

Definition at line 8 of file CustomUIsession.cc.

8  {
9  G4UImanager* UI = G4UImanager::GetUIpointer();
10  UI->SetCoutDestination(nullptr);
11 }

Member Function Documentation

◆ ReceiveG4cerr()

G4int CustomUIsession::ReceiveG4cerr ( const G4String &  cerrString)
override

Definition at line 23 of file CustomUIsession.cc.

23  {
24  //std::cerr << cerrString << std::flush;
25  edm::LogWarning("G4cerr") << trim(cerrString);
26  return 0;
27 }

References trim().

◆ ReceiveG4cout()

G4int CustomUIsession::ReceiveG4cout ( const G4String &  coutString)
override

Definition at line 13 of file CustomUIsession.cc.

13  {
14  //std::cout << coutString << std::flush;
15  if (fout) {
16  (*fout) << trim(coutString) << "\n";
17  } else {
18  edm::LogVerbatim("G4cout") << trim(coutString);
19  }
20  return 0;
21 }

References fout, and trim().

◆ sendToFile()

void CustomUIsession::sendToFile ( std::ofstream *  ptr)

Definition at line 35 of file CustomUIsession.cc.

35  {
36  if (ptr && !ptr->fail()) {
37  fout = ptr;
38  }
39 }

References fout.

Referenced by CMSG4CheckOverlap::CMSG4CheckOverlap().

◆ stopSendToFile()

void CustomUIsession::stopSendToFile ( )
inline

Definition at line 22 of file CustomUIsession.h.

22 { fout = nullptr; }

References fout.

Referenced by CMSG4CheckOverlap::CMSG4CheckOverlap().

◆ trim()

std::string CustomUIsession::trim ( const std::string &  str)
protected

Definition at line 29 of file CustomUIsession.cc.

29  {
30  if (!str.empty() && str.back() == '\n')
31  return str.substr(0, str.length() - 1);
32  return str;
33 }

References str.

Referenced by CustomUIsessionThreadPrefix::ReceiveG4cerr(), ReceiveG4cerr(), ReceiveG4cout(), and CustomUIsessionThreadPrefix::ReceiveG4cout().

Member Data Documentation

◆ fout

std::ofstream* CustomUIsession::fout
private

Definition at line 28 of file CustomUIsession.h.

Referenced by ReceiveG4cout(), sendToFile(), and stopSendToFile().

CustomUIsession::trim
std::string trim(const std::string &str)
Definition: CustomUIsession.cc:29
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
str
#define str(s)
Definition: TestProcessor.cc:53
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
CustomUIsession::fout
std::ofstream * fout
Definition: CustomUIsession.h:28