Geant4  10.01.p01
G4UImanager.hh
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: G4UImanager.hh 85249 2014-10-27 08:28:57Z gcosmo $
28 //
29 
30 #ifndef G4UImanager_h
31 #define G4UImanager_h 1
32 
33 #include "globals.hh"
34 
35 #include <vector>
36 #include <fstream>
37 #include "G4VStateDependent.hh"
38 #include "G4UIcommandStatus.hh"
39 class G4UIcommandTree;
40 class G4UIcommand;
41 class G4UIsession;
43 class G4UnitsMessenger;
45 class G4UIaliasList;
47 class G4UIbridge;
48 
49 // class description:
50 //
51 // This is a singlton class which controls the command manipulation
52 // and the user interface(s). The constructor of this class MUST NOT
53 // invoked by the user.
54 //
55 
57 {
58  public: // with description
59  static G4UImanager * GetUIpointer();
61  // A static method to get the pointer to the only existing object
62  // of this class.
63 
64  protected:
65  G4UImanager();
66  public:
67  ~G4UImanager();
68  private:
70  const G4UImanager & operator=(const G4UImanager &right);
71  G4int operator==(const G4UImanager &right) const;
72  G4int operator!=(const G4UImanager &right) const;
73 
74  public: // with description
75  G4String GetCurrentValues(const char * aCommand);
76  // This method returns a string which represents the current value(s)
77  // of the parameter(s) of the specified command. Null string will be
78  // returned if the given command is not defined or the command does
79  // not support the GetCurrentValues() method.
80  void AddNewCommand(G4UIcommand * newCommand);
81  // This method register a new command.
82  void RemoveCommand(G4UIcommand * aCommand);
83  // This command remove the registered command. After invokation of this
84  // command, that particular command cannot be applied.
85  void ExecuteMacroFile(const char * fileName);
86  // A macro file defined by the argument will be read by G4UIbatch object.
87  void Loop(const char * macroFile,const char * variableName,
88  G4double initialValue,G4double finalValue,G4double stepSize=1.0);
89  // Execute a macro file more than once with a loop counter.
90  void Foreach(const char * macroFile,const char * variableName,
91  const char * candidates);
92  // Execute a macro file more than once with an aliased variable which takes
93  // a value in the candidate list.
94  G4int ApplyCommand(const char * aCommand);
95  G4int ApplyCommand(const G4String& aCommand);
96  // A command (and parameter(s)) given
97  // by the method's argument will be applied. Zero will be returned in
98  // case the command is successfully executed. Positive non-zero value
99  // will be returned if the command couldn't be executed. The meaning of
100  // this non-zero value is the following.
101  // The returned number : xyy
102  // x00 : G4CommandStatus.hh enumeration
103  // yy : the problematic parameter (first found)
104  void StoreHistory(const char* fileName = "G4history.macro");
105  void StoreHistory(G4bool historySwitch,
106  const char* fileName = "G4history.macro");
107  // The executed commands will be stored in the defined file. If
108  // "historySwitch" is false, saving will be suspended.
109  void ListCommands(const char* direc);
110  // All commands registored under the given directory will be listed to
111  // G4cout.
112  void SetAlias(const char * aliasLine);
113  // Define an alias. The first word of "aliasLine" string is the
114  // alias name and the remaining word(s) is(are) string value
115  // to be aliased.
116  void RemoveAlias(const char * aliasName);
117  // Remove the defined alias.
118  void ListAlias();
119  // Print all aliases.
120  G4String SolveAlias(const char* aCmd);
121  // Convert a command string which contains alias(es).
122  void CreateHTML(const char* dir = "/");
123  // Generate HTML files for defined UI commands
124 
125  private:
126  void AddWorkerCommand(G4UIcommand * newCommand);
127  void RemoveWorkerCommand(G4UIcommand * aCommand);
128 
129  public:
130  void LoopS(const char* valueList);
131  void ForeachS(const char* valueList);
132  // These methods are used by G4UIcontrolMessenger to use Loop() and Foreach() methods.
133  virtual G4bool Notify(G4ApplicationState requestedState);
134  // This method is exclusively invoked by G4StateManager and the user
135  // must not use this method.
136 
137  private:
138  void PauseSession(const char* msg);
139  void CreateMessenger();
140  G4UIcommandTree* FindDirectory(const char* dirName);
141 
142  //public:
143  // following three methods will be removed quite soon.
144  // void Interact();
145  // void Interact(const char * promptCharacters);
146 
147  private:
160  std::ofstream historyFile;
162  std::vector<G4String> histVec;
168  std::vector<G4String> searchDirs;
169 
170  public: // with description
171  G4String GetCurrentStringValue(const char * aCommand,
172  G4int parameterNumber=1, G4bool reGet=true);
173  G4int GetCurrentIntValue(const char * aCommand,
174  G4int parameterNumber=1, G4bool reGet=true);
175  G4double GetCurrentDoubleValue(const char * aCommand,
176  G4int parameterNumber=1, G4bool reGet=true);
177  G4String GetCurrentStringValue(const char * aCommand,
178  const char * aParameterName, G4bool reGet=true);
179  G4int GetCurrentIntValue(const char * aCommand,
180  const char * aParameterName, G4bool reGet=true);
181  G4double GetCurrentDoubleValue(const char * aCommand,
182  const char * aParameterName, G4bool reGet=true);
183  // These six methods returns the current value of a parameter of the
184  // given command. For the first three methods, the ordering number of
185  // the parameter (1 is the first parameter) can be given, whereas,
186  // other three methods can give the parameter name.
187  // If "reGet" is true, actual request of returning the current value
188  // will be sent to the corresponding messenger, while, if it is false,
189  // the value stored in G4Umanager will be used. The later case is valid
190  // for the sequential invokation for the same command.
191 
193  { pauseAtBeginOfEvent = vl; }
195  { return pauseAtBeginOfEvent; }
196  inline void SetPauseAtEndOfEvent(G4bool vl)
197  { pauseAtEndOfEvent = vl; }
199  { return pauseAtEndOfEvent; }
200  // If the boolean flags are true, Pause() method of G4StateManager is invoked
201  // at the very begining (before generating a G4Event object) or at the end of
202  // each event. So that, in case a (G)UI session is defined, the user can interact.
203 
204 
205  public:
206  inline G4UIcommandTree * GetTree() const
207  { return treeTop; }
208  inline G4UIsession * GetSession() const
209  { return session; }
210  inline G4UIsession * GetG4UIWindow() const
211  { return g4UIWindow; }
212  public: // with description
213  inline void SetSession(G4UIsession *const value)
214  { session = value; }
215  inline void SetG4UIWindow(G4UIsession *const value)
216  { g4UIWindow = value; }
217  // This method defines the active (G)UI session.
218  void SetCoutDestination(G4UIsession *const value);
219  // This method defines the destination of G4cout/G4cerr stream.
220  // For usual cases, this method will be invoked by a concrete
221  // (G)UI session class object and thus the user needs not to invoke
222  // this method by him(her)self.
223 
224  public:
225  inline void SetVerboseLevel(G4int val)
226  { verboseLevel = val; }
227  inline G4int GetVerboseLevel() const
228  { return verboseLevel; }
229  inline G4int GetNumberOfHistory() const
230  { return histVec.size(); }
232  {
233  G4String st;
234  if(i>=0 && i<G4int(histVec.size()))
235  { st = histVec[i]; }
236  return st;
237  }
238  inline void SetMaxHistSize(G4int mx)
239  { maxHistSize = mx; }
240  inline G4int GetMaxHistSize() const
241  { return maxHistSize; }
242 
243  inline void SetMacroSearchPath(const G4String& path)
244  { searchPath = path; }
245  inline const G4String& GetMacroSearchPath() const
246  { return searchPath; }
247  void ParseMacroSearchPath();
248  G4String FindMacroPath(const G4String& fname) const;
249 
250  private:
252  std::vector<G4UIbridge*>* bridges;
255  std::vector<G4String>* commandStack;
256 
257  public:
258  inline void SetMasterUIManager(G4bool val)
259  {
260  isMaster = val;
261  //ignoreCmdNotFound = val;
262  stackCommandsForBroadcast = val;
263  if(val&&!bridges)
264  {
265  bridges = new std::vector<G4UIbridge*>;
266  fMasterUImanager = this;
267  }
268  }
269  inline void SetIgnoreCmdNotFound(G4bool val)
270  { ignoreCmdNotFound = val; }
271 
272  std::vector<G4String>* GetCommandStack();
273  void RegisterBridge(G4UIbridge* brg);
274 
275  void SetUpForAThread(G4int tId);
276  //Setups as before but for a non-worker thread (e.g. vis)
277  void SetUpForSpecialThread(G4String aPrefix);
278 
279  inline G4int GetThreadID() const
280  { return threadID; }
281 
282  private:
286 
287  public:
288  void SetCoutFileName(const G4String& fileN = "G4cout.txt", G4bool ifAppend = true);
289  void SetCerrFileName(const G4String& fileN = "G4cerr.txt", G4bool ifAppend = true);
290  void SetThreadPrefixString(const G4String& s = "W");
291  void SetThreadUseBuffer(G4bool flg = true);
292  void SetThreadIgnore(G4int tid = 0);
293  void SetThreadIgnoreInit(G4bool flg = true);
295 
296 };
297 
298 #endif
void SetMacroSearchPath(const G4String &path)
Definition: G4UImanager.hh:243
void ForeachS(const char *valueList)
Definition: G4UImanager.cc:331
void ExecuteMacroFile(const char *fileName)
Definition: G4UImanager.cc:278
static G4int igThreadID
Definition: G4UImanager.hh:285
void Foreach(const char *macroFile, const char *variableName, const char *candidates)
Definition: G4UImanager.cc:360
void RemoveAlias(const char *aliasName)
Definition: G4UImanager.cc:629
G4int operator==(const G4UImanager &right) const
Definition: G4UImanager.cc:151
static G4ThreadLocal G4UImanager * fUImanager
Definition: G4UImanager.hh:148
void SetThreadPrefixString(const G4String &s="W")
Definition: G4UImanager.cc:761
G4int GetNumberOfHistory() const
Definition: G4UImanager.hh:229
G4MTcoutDestination * GetThreadCout()
Definition: G4UImanager.hh:294
void SetAlias(const char *aliasLine)
Definition: G4UImanager.cc:610
G4UIsession * GetSession() const
Definition: G4UImanager.hh:208
G4int GetThreadID() const
Definition: G4UImanager.hh:279
G4UIcommand * savedCommand
Definition: G4UImanager.hh:158
void SetUpForAThread(G4int tId)
Definition: G4UImanager.cc:713
G4bool isMaster
Definition: G4UImanager.hh:251
G4LocalThreadCoutMessenger * CoutMessenger
Definition: G4UImanager.hh:156
G4String GetPreviousCommand(G4int i) const
Definition: G4UImanager.hh:231
G4String GetCurrentStringValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
Definition: G4UImanager.cc:168
void SetCoutFileName(const G4String &fileN="G4cout.txt", G4bool ifAppend=true)
Definition: G4UImanager.cc:731
static G4UImanager * GetMasterUIpointer()
Definition: G4UImanager.cc:71
void RegisterBridge(G4UIbridge *brg)
Definition: G4UImanager.cc:702
G4int verboseLevel
Definition: G4UImanager.hh:159
G4UIcontrolMessenger * UImessenger
Definition: G4UImanager.hh:154
void CreateMessenger()
Definition: G4UImanager.cc:98
void SetIgnoreCmdNotFound(G4bool val)
Definition: G4UImanager.hh:269
G4String savedParameters
Definition: G4UImanager.hh:157
G4UIcommandTree * treeTop
Definition: G4UImanager.hh:151
std::ofstream historyFile
Definition: G4UImanager.hh:160
static G4UImanager * fMasterUImanager
Definition: G4UImanager.hh:150
void SetThreadUseBuffer(G4bool flg=true)
Definition: G4UImanager.cc:768
G4int maxHistSize
Definition: G4UImanager.hh:164
G4bool stackCommandsForBroadcast
Definition: G4UImanager.hh:254
#define G4ThreadLocal
Definition: tls.hh:89
G4int GetVerboseLevel() const
Definition: G4UImanager.hh:227
void SetSession(G4UIsession *const value)
Definition: G4UImanager.hh:213
void RemoveWorkerCommand(G4UIcommand *aCommand)
Definition: G4UImanager.cc:273
int G4int
Definition: G4Types.hh:78
std::vector< G4String > * GetCommandStack()
Definition: G4UImanager.cc:695
void SetG4UIWindow(G4UIsession *const value)
Definition: G4UImanager.hh:215
void SetVerboseLevel(G4int val)
Definition: G4UImanager.hh:225
G4bool saveHistory
Definition: G4UImanager.hh:161
void SetCerrFileName(const G4String &fileN="G4cerr.txt", G4bool ifAppend=true)
Definition: G4UImanager.cc:746
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
void ParseMacroSearchPath()
Definition: G4UImanager.cc:650
static const double s
Definition: G4SIunits.hh:150
std::vector< G4String > searchDirs
Definition: G4UImanager.hh:168
void SetThreadIgnoreInit(G4bool flg=true)
Definition: G4UImanager.cc:786
G4UIaliasList * aliasList
Definition: G4UImanager.hh:163
void Loop(const char *macroFile, const char *variableName, G4double initialValue, G4double finalValue, G4double stepSize=1.0)
Definition: G4UImanager.cc:307
bool G4bool
Definition: G4Types.hh:79
G4MTcoutDestination * threadCout
Definition: G4UImanager.hh:284
std::vector< G4UIbridge * > * bridges
Definition: G4UImanager.hh:252
G4bool GetPauseAtBeginOfEvent() const
Definition: G4UImanager.hh:194
void RemoveCommand(G4UIcommand *aCommand)
Definition: G4UImanager.cc:266
G4UIsession * g4UIWindow
Definition: G4UImanager.hh:153
G4int GetCurrentIntValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
Definition: G4UImanager.cc:218
G4UnitsMessenger * UnitsMessenger
Definition: G4UImanager.hh:155
G4bool GetPauseAtEndOfEvent() const
Definition: G4UImanager.hh:198
G4String GetCurrentValues(const char *aCommand)
Definition: G4UImanager.cc:156
void SetMaxHistSize(G4int mx)
Definition: G4UImanager.hh:238
void ListCommands(const char *direc)
Definition: G4UImanager.cc:537
void PauseSession(const char *msg)
Definition: G4UImanager.cc:532
std::vector< G4String > histVec
Definition: G4UImanager.hh:162
G4int threadID
Definition: G4UImanager.hh:283
G4bool pauseAtEndOfEvent
Definition: G4UImanager.hh:166
G4bool ignoreCmdNotFound
Definition: G4UImanager.hh:253
G4UIcommandTree * GetTree() const
Definition: G4UImanager.hh:206
std::vector< G4String > * commandStack
Definition: G4UImanager.hh:255
void AddNewCommand(G4UIcommand *newCommand)
Definition: G4UImanager.cc:254
void SetPauseAtEndOfEvent(G4bool vl)
Definition: G4UImanager.hh:196
G4String searchPath
Definition: G4UImanager.hh:167
void SetCoutDestination(G4UIsession *const value)
Definition: G4UImanager.cc:604
G4UIsession * GetG4UIWindow() const
Definition: G4UImanager.hh:210
G4String SolveAlias(const char *aCmd)
Definition: G4UImanager.cc:377
const G4String & GetMacroSearchPath() const
Definition: G4UImanager.hh:245
void SetPauseAtBeginOfEvent(G4bool vl)
Definition: G4UImanager.hh:192
G4UIsession * session
Definition: G4UImanager.hh:152
void ListAlias()
Definition: G4UImanager.cc:636
static G4ThreadLocal G4bool fUImanagerHasBeenKilled
Definition: G4UImanager.hh:149
void LoopS(const char *valueList)
Definition: G4UImanager.cc:287
const G4UImanager & operator=(const G4UImanager &right)
Definition: G4UImanager.cc:149
virtual G4bool Notify(G4ApplicationState requestedState)
Definition: G4UImanager.cc:568
void AddWorkerCommand(G4UIcommand *newCommand)
Definition: G4UImanager.cc:261
G4double GetCurrentDoubleValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
Definition: G4UImanager.cc:242
double G4double
Definition: G4Types.hh:76
void SetUpForSpecialThread(G4String aPrefix)
Definition: G4UImanager.cc:721
void SetThreadIgnore(G4int tid=0)
Definition: G4UImanager.cc:775
void CreateHTML(const char *dir="/")
Definition: G4UImanager.cc:641
void StoreHistory(const char *fileName="G4history.macro")
Definition: G4UImanager.cc:512
G4String FindMacroPath(const G4String &fname) const
Definition: G4UImanager.cc:680
G4bool pauseAtBeginOfEvent
Definition: G4UImanager.hh:165
void SetMasterUIManager(G4bool val)
Definition: G4UImanager.hh:258
G4ApplicationState
G4UIcommandTree * FindDirectory(const char *dirName)
Definition: G4UImanager.cc:546
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:432
G4int GetMaxHistSize() const
Definition: G4UImanager.hh:240
G4int operator!=(const G4UImanager &right) const
Definition: G4UImanager.cc:153