39 std::ostream& co, std::ostream& ce)
40 : finalcout(co), finalcerr(ce), id(threadId), useBuffer(false),
41 threadCoutToFile(false), threadCerrToFile(false),
42 ignoreCout(false), ignoreInit(true)
51 if( useBuffer ) DumpBuffer();
52 if( threadCoutToFile ) CloseCoutFile();
53 if( threadCerrToFile ) CloseCerrFile();
61 if( threadCoutToFile )
62 { coutFile<<msg<<std::flush; }
65 else if( !ignoreCout )
73 finalcout<<
" > "<<msg<<std::flush;
92 if( threadCerrToFile )
93 { cerrFile<<msg<<std::flush; }
100 finalcerr<<
" > "<<msg<<std::flush;
107 std::stringstream ss;
118 if( threadCoutToFile ) CloseCoutFile();
119 if( fileN ==
"**Screen**" )
return;
120 if( ! coutFile.is_open() )
122 std::ios::openmode mode = std::ios::out;
124 coutFile.open(fileN,mode);
126 threadCoutToFile =
true;
131 if( threadCerrToFile ) CloseCerrFile();
132 if( fileN ==
"**Screen**" )
return;
133 if( ! cerrFile.is_open() )
135 std::ios::openmode mode = std::ios::out;
137 cerrFile.open(fileN,mode);
139 threadCerrToFile =
true;
144 if(useBuffer && !flag) DumpBuffer();
154 { ignoreCout =
false; }
156 { ignoreCout = (tid!=id); }
159 void G4MTcoutDestination::CloseCoutFile()
161 if( coutFile.is_open() ) coutFile.close();
162 threadCoutToFile =
false;
165 void G4MTcoutDestination::CloseCerrFile()
167 if( cerrFile.is_open() ) cerrFile.close();
168 threadCerrToFile =
false;
171 void G4MTcoutDestination::DumpBuffer()
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;
void SetCerrFileName(const G4String &fileN="G4cerr.txt", G4bool ifAppend=true)
virtual G4int ReceiveG4cout(const G4String &)
static G4coutDestination * masterG4coutDestination
#define G4MUTEX_INITIALIZER
void SetPrefixString(const G4String &wd="G4WT")
void SetCoutFileName(const G4String &fileN="G4cout.txt", G4bool ifAppend=true)
static G4StateManager * GetStateManager()
G4MTcoutDestination(const G4int &threadId, std::ostream &co=std::cout, std::ostream &ce=std::cerr)
void EnableBuffering(G4bool flag=true)
virtual G4int ReceiveG4cerr(const G4String &)
void SetIgnoreCout(G4int tid=0)
void SetDestination(G4coutDestination *dest)
virtual G4int ReceiveG4cerr(const G4String &)
virtual G4int ReceiveG4cout(const G4String &)
virtual ~G4MTcoutDestination()