39 std::ostream& co, std::ostream& ce)
40 : finalcout(co), finalcerr(ce), id(threadId), useBuffer(false),
41 threadCoutToFile(false), threadCerrToFile(false), ignoreCout(false)
50 if( useBuffer ) DumpBuffer();
51 if( threadCoutToFile ) CloseCoutFile();
52 if( threadCerrToFile ) CloseCerrFile();
59 if( threadCoutToFile )
60 { coutFile<<msg<<std::flush; }
63 else if( !ignoreCout )
70 if( threadCerrToFile )
71 { cerrFile<<msg<<std::flush; }
81 if( threadCoutToFile ) CloseCoutFile();
82 if( fileN ==
"**Screen**" )
return;
83 if( ! coutFile.is_open() )
85 std::ios::openmode mode = std::ios::out;
87 coutFile.open(fileN,mode);
89 threadCoutToFile =
true;
94 if( threadCerrToFile ) CloseCerrFile();
95 if( fileN ==
"**Screen**" )
return;
96 if( ! cerrFile.is_open() )
98 std::ios::openmode mode = std::ios::out;
100 cerrFile.open(fileN,mode);
102 threadCerrToFile =
true;
107 if(useBuffer && !flag) DumpBuffer();
117 { ignoreCout =
false; }
119 { ignoreCout = (tid!=id); }
122 void G4MTcoutDestination::CloseCoutFile()
124 if( coutFile.is_open() ) coutFile.close();
125 threadCoutToFile =
false;
128 void G4MTcoutDestination::CloseCerrFile()
130 if( cerrFile.is_open() ) cerrFile.close();
131 threadCerrToFile =
false;
134 void G4MTcoutDestination::DumpBuffer()
137 finalcout<<
"====================="<<std::endl;
138 finalcout<<
"cout buffer for worker with ID:"<<
id<<std::endl;
139 finalcout<<cout_buffer.str()<<std::endl;
140 finalcerr<<
"====================="<<std::endl;
141 finalcerr<<
"cerr buffer for worker with ID:"<<
id<<std::endl;
142 finalcerr<<cerr_buffer.str()<<std::endl;
143 finalcerr<<
"====================="<<std::endl;
void SetCerrFileName(const G4String &fileN="G4cerr.txt", G4bool ifAppend=true)
#define G4MUTEX_INITIALIZER
void SetPrefixString(const G4String &wd="G4WT")
void SetCoutFileName(const G4String &fileN="G4cout.txt", G4bool ifAppend=true)
G4MTcoutDestination(const G4int &threadId, std::ostream &co=std::cout, std::ostream &ce=std::cerr)
void EnableBuffering(G4bool flag=true)
void SetIgnoreCout(G4int tid=0)
void SetDestination(G4coutDestination *dest)
virtual G4int ReceiveG4cerr(const G4String &)
virtual G4int ReceiveG4cout(const G4String &)
virtual ~G4MTcoutDestination()