Geant4  10.02.p03
G4MTcoutDestination Class Reference

#include <G4MTcoutDestination.hh>

Inheritance diagram for G4MTcoutDestination:
Collaboration diagram for G4MTcoutDestination:

Public Member Functions

 G4MTcoutDestination (const G4int &threadId, std::ostream &co=std::cout, std::ostream &ce=std::cerr)
 
virtual ~G4MTcoutDestination ()
 
virtual G4int ReceiveG4cout (const G4String &)
 
virtual G4int ReceiveG4cerr (const G4String &)
 
void SetCoutFileName (const G4String &fileN="G4cout.txt", G4bool ifAppend=true)
 
void SetCerrFileName (const G4String &fileN="G4cerr.txt", G4bool ifAppend=true)
 
void EnableBuffering (G4bool flag=true)
 
void SetPrefixString (const G4String &wd="G4WT")
 
void SetIgnoreCout (G4int tid=0)
 
void SetIgnoreInit (G4bool val=true)
 
G4String GetPrefixString () const
 
G4String GetFullPrefixString () const
 
- Public Member Functions inherited from G4coutDestination
 G4coutDestination ()
 
virtual ~G4coutDestination ()
 

Private Member Functions

void CloseCoutFile ()
 
void CloseCerrFile ()
 
void DumpBuffer ()
 

Private Attributes

std::ostream & finalcout
 
std::ostream & finalcerr
 
const G4int id
 
G4bool useBuffer
 
G4bool threadCoutToFile
 
G4bool threadCerrToFile
 
G4bool ignoreCout
 
G4bool ignoreInit
 
std::ostringstream cout_buffer
 
std::ostringstream cerr_buffer
 
std::ofstream coutFile
 
std::ofstream cerrFile
 
G4String prefix
 

Additional Inherited Members

- Static Protected Attributes inherited from G4coutDestination
static G4coutDestinationmasterG4coutDestination = 0
 

Detailed Description

Definition at line 45 of file G4MTcoutDestination.hh.

Constructor & Destructor Documentation

◆ G4MTcoutDestination()

G4MTcoutDestination::G4MTcoutDestination ( const G4int threadId,
std::ostream &  co = std::cout,
std::ostream &  ce = std::cerr 
)

Definition at line 38 of file G4MTcoutDestination.cc.

40 : finalcout(co), finalcerr(ce), id(threadId), useBuffer(false),
41  threadCoutToFile(false), threadCerrToFile(false),
42  ignoreCout(false), ignoreInit(true)
43 {
46  prefix = "G4WT";
47 }
G4strstreambuf G4coutbuf
Definition: G4ios.cc:82
void SetDestination(G4coutDestination *dest)
G4strstreambuf G4cerrbuf
Definition: G4ios.cc:83
Here is the call graph for this function:

◆ ~G4MTcoutDestination()

G4MTcoutDestination::~G4MTcoutDestination ( )
virtual

Definition at line 49 of file G4MTcoutDestination.cc.

Here is the call graph for this function:

Member Function Documentation

◆ CloseCerrFile()

void G4MTcoutDestination::CloseCerrFile ( )
private

Definition at line 165 of file G4MTcoutDestination.cc.

166 {
167  if( cerrFile.is_open() ) cerrFile.close();
168  threadCerrToFile = false;
169 }
Here is the caller graph for this function:

◆ CloseCoutFile()

void G4MTcoutDestination::CloseCoutFile ( )
private

Definition at line 159 of file G4MTcoutDestination.cc.

160 {
161  if( coutFile.is_open() ) coutFile.close();
162  threadCoutToFile = false;
163 }
Here is the caller graph for this function:

◆ DumpBuffer()

void G4MTcoutDestination::DumpBuffer ( )
private

Definition at line 171 of file G4MTcoutDestination.cc.

172 {
173  G4AutoLock l(&coutm);
174  finalcout<<"====================="<<std::endl;
175  finalcout<<"cout buffer for worker with ID:"<<id<<std::endl;
176  finalcout<<cout_buffer.str()<<std::endl;
177  finalcerr<<"====================="<<std::endl;
178  finalcerr<<"cerr buffer for worker with ID:"<<id<<std::endl;
179  finalcerr<<cerr_buffer.str()<<std::endl;
180  finalcerr<<"====================="<<std::endl;
181 }
std::ostringstream cout_buffer
std::ostringstream cerr_buffer
Here is the caller graph for this function:

◆ EnableBuffering()

void G4MTcoutDestination::EnableBuffering ( G4bool  flag = true)

Definition at line 142 of file G4MTcoutDestination.cc.

143 {
144  if(useBuffer && !flag) DumpBuffer();
145  useBuffer = flag;
146 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetFullPrefixString()

G4String G4MTcoutDestination::GetFullPrefixString ( ) const
inline

Definition at line 63 of file G4MTcoutDestination.hh.

63  {
64  std::stringstream os;
65  os<<prefix<<id;
66  return os.str();
67  }
Here is the call graph for this function:

◆ GetPrefixString()

G4String G4MTcoutDestination::GetPrefixString ( ) const
inline

Definition at line 62 of file G4MTcoutDestination.hh.

62 { return prefix; }

◆ ReceiveG4cerr()

G4int G4MTcoutDestination::ReceiveG4cerr ( const G4String msg)
virtual

Reimplemented from G4coutDestination.

Definition at line 90 of file G4MTcoutDestination.cc.

91 {
92  if( threadCerrToFile )
93  { cerrFile<<msg<<std::flush; }
94  if( useBuffer )
95  { cerr_buffer<<msg; }
96  else
97  { G4AutoLock l(&coutm);
100  finalcerr<<" > "<<msg<<std::flush;
101  }
102  //forward message to master G4coutDestination if set
104  ( !ignoreInit || G4StateManager::GetStateManager()->GetCurrentState() != G4State_Idle )
105  ){
106  G4AutoLock l(&coutm);
107  std::stringstream ss;
108  ss<<prefix;
109  if ( id!=G4Threading::GENERICTHREAD_ID ) ss<<id;
110  ss<<" > "<<msg;
112  }
113  return 0;
114 }
static G4coutDestination * masterG4coutDestination
static G4StateManager * GetStateManager()
virtual G4int ReceiveG4cerr(const G4String &)
std::ostringstream cerr_buffer
Here is the call graph for this function:

◆ ReceiveG4cout()

G4int G4MTcoutDestination::ReceiveG4cout ( const G4String msg)
virtual

Reimplemented from G4coutDestination.

Definition at line 59 of file G4MTcoutDestination.cc.

60 {
61  if( threadCoutToFile )
62  { coutFile<<msg<<std::flush; }
63  else if( useBuffer )
64  { cout_buffer<<msg; }
65  else if( !ignoreCout )
66  {
67  if(!ignoreInit ||
68  G4StateManager::GetStateManager()->GetCurrentState() != G4State_Idle )
69  {
70  G4AutoLock l(&coutm);
73  finalcout<<" > "<<msg<<std::flush;
74  }
75  }
76  //forward message to master G4coutDestination if set
78  ( !ignoreInit || G4StateManager::GetStateManager()->GetCurrentState() != G4State_Idle )
79  ){
80  G4AutoLock l(&coutm);
81  std::stringstream ss;
82  ss<<prefix;
83  if ( id!=G4Threading::GENERICTHREAD_ID ) ss<<id;
84  ss<<" > "<<msg;
86  }
87  return 0;
88 }
virtual G4int ReceiveG4cout(const G4String &)
static G4coutDestination * masterG4coutDestination
std::ostringstream cout_buffer
static G4StateManager * GetStateManager()
Here is the call graph for this function:

◆ SetCerrFileName()

void G4MTcoutDestination::SetCerrFileName ( const G4String fileN = "G4cerr.txt",
G4bool  ifAppend = true 
)

Definition at line 129 of file G4MTcoutDestination.cc.

130 {
132  if( fileN == "**Screen**" ) return;
133  if( ! cerrFile.is_open() )
134  {
135  std::ios::openmode mode = std::ios::out;
136  if ( ifAppend ) mode |= std::ios::app;
137  cerrFile.open(fileN,mode);
138  }
139  threadCerrToFile = true;
140 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetCoutFileName()

void G4MTcoutDestination::SetCoutFileName ( const G4String fileN = "G4cout.txt",
G4bool  ifAppend = true 
)

Definition at line 116 of file G4MTcoutDestination.cc.

117 {
119  if( fileN == "**Screen**" ) return;
120  if( ! coutFile.is_open() )
121  {
122  std::ios::openmode mode = std::ios::out;
123  if ( ifAppend ) mode |= std::ios::app;
124  coutFile.open(fileN,mode);
125  }
126  threadCoutToFile = true;
127 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetIgnoreCout()

void G4MTcoutDestination::SetIgnoreCout ( G4int  tid = 0)

Definition at line 151 of file G4MTcoutDestination.cc.

152 {
153  if(tid<0)
154  { ignoreCout = false; }
155  else
156  { ignoreCout = (tid!=id); }
157 }
Here is the caller graph for this function:

◆ SetIgnoreInit()

void G4MTcoutDestination::SetIgnoreInit ( G4bool  val = true)
inline

Definition at line 61 of file G4MTcoutDestination.hh.

61 { ignoreInit = val; }
Here is the caller graph for this function:

◆ SetPrefixString()

void G4MTcoutDestination::SetPrefixString ( const G4String wd = "G4WT")

Definition at line 148 of file G4MTcoutDestination.cc.

149 { prefix = wd; }
Here is the caller graph for this function:

Member Data Documentation

◆ cerr_buffer

std::ostringstream G4MTcoutDestination::cerr_buffer
private

Definition at line 87 of file G4MTcoutDestination.hh.

◆ cerrFile

std::ofstream G4MTcoutDestination::cerrFile
private

Definition at line 89 of file G4MTcoutDestination.hh.

◆ cout_buffer

std::ostringstream G4MTcoutDestination::cout_buffer
private

Definition at line 86 of file G4MTcoutDestination.hh.

◆ coutFile

std::ofstream G4MTcoutDestination::coutFile
private

Definition at line 88 of file G4MTcoutDestination.hh.

◆ finalcerr

std::ostream& G4MTcoutDestination::finalcerr
private

Definition at line 78 of file G4MTcoutDestination.hh.

◆ finalcout

std::ostream& G4MTcoutDestination::finalcout
private

Definition at line 77 of file G4MTcoutDestination.hh.

◆ id

const G4int G4MTcoutDestination::id
private

Definition at line 79 of file G4MTcoutDestination.hh.

◆ ignoreCout

G4bool G4MTcoutDestination::ignoreCout
private

Definition at line 83 of file G4MTcoutDestination.hh.

◆ ignoreInit

G4bool G4MTcoutDestination::ignoreInit
private

Definition at line 84 of file G4MTcoutDestination.hh.

◆ prefix

G4String G4MTcoutDestination::prefix
private

Definition at line 90 of file G4MTcoutDestination.hh.

◆ threadCerrToFile

G4bool G4MTcoutDestination::threadCerrToFile
private

Definition at line 82 of file G4MTcoutDestination.hh.

◆ threadCoutToFile

G4bool G4MTcoutDestination::threadCoutToFile
private

Definition at line 81 of file G4MTcoutDestination.hh.

◆ useBuffer

G4bool G4MTcoutDestination::useBuffer
private

Definition at line 80 of file G4MTcoutDestination.hh.


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