Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 ()
 

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 ( 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 }
G4GLOB_DLL G4strstreambuf G4coutbuf
Definition: G4ios.cc:82
G4GLOB_DLL G4strstreambuf G4cerrbuf
Definition: G4ios.cc:83
void SetDestination(G4coutDestination *dest)

Here is the call graph for this function:

G4MTcoutDestination::~G4MTcoutDestination ( )
virtual

Definition at line 49 of file G4MTcoutDestination.cc.

50 {
51  if( useBuffer ) DumpBuffer();
52  if( threadCoutToFile ) CloseCoutFile();
53  if( threadCerrToFile ) CloseCerrFile();
54 }

Member Function Documentation

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 caller graph for this function:

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  }
G4String G4MTcoutDestination::GetPrefixString ( ) const
inline

Definition at line 62 of file G4MTcoutDestination.hh.

62 { return prefix; }
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);
98  finalcerr<<prefix;
99  if ( id!=G4Threading::GENERICTHREAD_ID ) finalcerr<<id;
100  finalcerr<<" > "<<msg<<std::flush;
101  }
102  //forward message to master G4coutDestination if set
103  if ( masterG4coutDestination && !ignoreCout &&
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 &)

Here is the call graph for this function:

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);
71  finalcout<<prefix;
72  if ( id!=G4Threading::GENERICTHREAD_ID ) finalcout<<id;
73  finalcout<<" > "<<msg<<std::flush;
74  }
75  }
76  //forward message to master G4coutDestination if set
77  if ( masterG4coutDestination && !ignoreCout &&
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
static G4StateManager * GetStateManager()

Here is the call graph for this function:

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

Definition at line 129 of file G4MTcoutDestination.cc.

130 {
131  if( threadCerrToFile ) CloseCerrFile();
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 caller graph for this function:

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

Definition at line 116 of file G4MTcoutDestination.cc.

117 {
118  if( threadCoutToFile ) CloseCoutFile();
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 caller graph for this function:

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:

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:

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:


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