Geant4  10.02.p02
G4LocalThreadCoutMessenger.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4LocalThreadCoutMessenger.cc 66241 2012-12-13 18:34:42Z gunter $
28 //
29 //
30 
32 
33 #include "G4UImanager.hh"
34 
35 #include "G4UIdirectory.hh"
36 #include "G4UIcommand.hh"
37 #include "G4UIcmdWithABool.hh"
38 #include "G4UIcmdWithAString.hh"
39 #include "G4UIcmdWithAnInteger.hh"
40 #include "G4UIparameter.hh"
41 #include "G4Tokenizer.hh"
42 
44 {
45  coutDir = new G4UIdirectory("/control/cout/");
46  coutDir->SetGuidance("Control cout/cerr for local thread.");
47 
48  coutFileNameCmd = new G4UIcommand("/control/cout/setCoutFile",this);
49  coutFileNameCmd->SetGuidance("Send G4cout stream to a file dedicated to a thread. ");
50  coutFileNameCmd->SetGuidance("To have a display output, use special keyword \"**Screen**\".");
51  coutFileNameCmd->SetGuidance("If append flag is true output is appended to file,");
52  coutFileNameCmd->SetGuidance("otherwise file output is overwritten.");
54  G4UIparameter* pp = new G4UIparameter("fileName",'s',true);
55  pp->SetDefaultValue("**Screen**");
57  pp= new G4UIparameter("append",'b',true);
58  pp->SetDefaultValue(true);
60 
61  cerrFileNameCmd = new G4UIcommand("/control/cout/setCerrFile",this);
62  cerrFileNameCmd->SetGuidance("Send G4cerr stream to a file dedicated to a thread. ");
63  cerrFileNameCmd->SetGuidance("To have a display output, use special keyword \"**Screen**\".");
64  cerrFileNameCmd->SetGuidance("If append flag is true output is appended to file,");
65  cerrFileNameCmd->SetGuidance("otherwise file output is overwritten.");
67  pp = new G4UIparameter("fileName",'s',true);
68  pp->SetDefaultValue("**Screen**");
70  pp= new G4UIparameter("append",'b',true);
71  pp->SetDefaultValue(true);
73 
74  bufferCoutCmd = new G4UIcmdWithABool("/control/cout/useBuffer",this);
75  bufferCoutCmd->SetGuidance("Send cout and/or cerr stream to a buffer.");
76  bufferCoutCmd->SetGuidance("The buffered text will be printed at the end of the job");
77  bufferCoutCmd->SetGuidance("for each thread at a time, so that output of each thread is grouped.");
78  bufferCoutCmd->SetGuidance("This command has no effect if output goes to a file.");
79  bufferCoutCmd->SetParameterName("flag",true);
82 
83  prefixCmd = new G4UIcmdWithAString("/control/cout/prefixString",this);
84  prefixCmd->SetGuidance("Set the prefix string for each cout/cerr line from a thread.");
85  prefixCmd->SetParameterName("prefix",true);
86  prefixCmd->SetDefaultValue("G4WT");
88 
89  ignoreCmd = new G4UIcmdWithAnInteger("/control/cout/ignoreThreadsExcept",this);
90  ignoreCmd->SetGuidance("Omit cout from threads except the specified one.");
91  ignoreCmd->SetGuidance("This command takes effect only if cout destination is screen without buffering.");
92  ignoreCmd->SetGuidance("If specified thread ID is greater than the number of threads,");
93  ignoreCmd->SetGuidance("no cout is displayed from worker threads. -1 to reset.");
94  ignoreCmd->SetGuidance("This command does not affect to cerr.");
95  ignoreCmd->SetParameterName("threadID",true);
98 
99  ignoreInitCmd = new G4UIcmdWithABool("/control/cout/ignoreInitializationCout",this);
100  ignoreInitCmd->SetGuidance("Omit cout from threads during initialization, as they should be identical to the masther thread.");
101  ignoreInitCmd->SetGuidance("This command takes effect only if cout destination is screen without buffering.");
102  ignoreInitCmd->SetGuidance("This command does not affect to cerr.");
103  ignoreInitCmd->SetParameterName("IgnoreInit",true);
106 }
107 
109 {
110  delete coutFileNameCmd;
111  delete cerrFileNameCmd;
112  delete bufferCoutCmd;
113  delete prefixCmd;
114  delete ignoreCmd;
115  delete ignoreInitCmd;
116  delete coutDir;
117 }
118 
120 {
122  if(command == coutFileNameCmd)
123  {
124  G4Tokenizer next(newVal);
125  G4String fn = next();
126  G4bool af = StoB(next());
127  UI->SetCoutFileName(fn,af);
128  }
129  else if(command == cerrFileNameCmd)
130  {
131  G4Tokenizer next(newVal);
132  G4String fn = next();
133  G4bool af = StoB(next());
134  UI->SetCerrFileName(fn,af);
135  }
136  else if(command == bufferCoutCmd)
137  { UI->SetThreadUseBuffer(StoB(newVal)); }
138  else if(command == prefixCmd)
139  { UI->SetThreadPrefixString(newVal); }
140  else if(command == ignoreCmd)
141  { UI->SetThreadIgnore(StoI(newVal)); }
142  else if(command == ignoreInitCmd)
143  { UI->SetThreadIgnoreInit(StoB(newVal)); }
144 }
145 
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
void SetThreadPrefixString(const G4String &s="W")
Definition: G4UImanager.cc:775
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetCoutFileName(const G4String &fileN="G4cout.txt", G4bool ifAppend=true)
Definition: G4UImanager.cc:745
void SetNewValue(G4UIcommand *, G4String)
void SetDefaultValue(const char *theDefaultValue)
void SetThreadUseBuffer(G4bool flg=true)
Definition: G4UImanager.cc:782
void SetCerrFileName(const G4String &fileN="G4cerr.txt", G4bool ifAppend=true)
Definition: G4UImanager.cc:760
void SetDefaultValue(G4bool defVal)
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4bool StoB(G4String s)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetThreadIgnoreInit(G4bool flg=true)
Definition: G4UImanager.cc:800
bool G4bool
Definition: G4Types.hh:79
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:239
G4int StoI(G4String s)
void SetDefaultValue(const char *defVal)
void SetDefaultValue(G4int defVal)
void SetThreadIgnore(G4int tid=0)
Definition: G4UImanager.cc:789