Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 102562 2017-02-09 08:27:31Z 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:
148  static G4ThreadLocal G4UImanager * fUImanager;
149  static G4ThreadLocal G4bool fUImanagerHasBeenKilled;
150  static G4UImanager * fMasterUImanager;
151  G4UIcommandTree * treeTop;
152  G4UIsession * session;
153  G4UIsession * g4UIWindow;
154  G4UIcontrolMessenger * UImessenger;
155  G4UnitsMessenger * UnitsMessenger;
156  G4LocalThreadCoutMessenger * CoutMessenger;
157  G4String savedParameters;
158  G4UIcommand * savedCommand;
159  G4int verboseLevel;
160  std::ofstream historyFile;
161  G4bool saveHistory;
162  std::vector<G4String> histVec;
163  G4UIaliasList* aliasList;
164  G4int maxHistSize;
165  G4bool pauseAtBeginOfEvent;
166  G4bool pauseAtEndOfEvent;
167  G4String searchPath;
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:
251  G4bool isMaster;
252  std::vector<G4UIbridge*>* bridges;
253  G4bool ignoreCmdNotFound;
254  G4bool stackCommandsForBroadcast;
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:
283  G4int threadID;
284  G4MTcoutDestination* threadCout;
285  static G4int igThreadID;
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);
294  inline G4MTcoutDestination* GetThreadCout() {return threadCout;};
295 
296  private:
297  static G4bool doublePrecisionStr;
298 
299  public:
300  inline static void UseDoublePrecisionStr(G4bool val) { doublePrecisionStr = val; }
301  inline static G4bool DoublePrecisionStr() { return doublePrecisionStr; }
302 
303 };
304 
305 #endif
void SetMacroSearchPath(const G4String &path)
Definition: G4UImanager.hh:243
void ForeachS(const char *valueList)
Definition: G4UImanager.cc:346
void ExecuteMacroFile(const char *fileName)
Definition: G4UImanager.cc:293
void Foreach(const char *macroFile, const char *variableName, const char *candidates)
Definition: G4UImanager.cc:375
void RemoveAlias(const char *aliasName)
Definition: G4UImanager.cc:644
void SetThreadPrefixString(const G4String &s="W")
Definition: G4UImanager.cc:776
G4int GetNumberOfHistory() const
Definition: G4UImanager.hh:229
G4MTcoutDestination * GetThreadCout()
Definition: G4UImanager.hh:294
void SetAlias(const char *aliasLine)
Definition: G4UImanager.cc:625
G4UIsession * GetSession() const
Definition: G4UImanager.hh:208
G4int GetThreadID() const
Definition: G4UImanager.hh:279
void SetUpForAThread(G4int tId)
Definition: G4UImanager.cc:728
G4String GetPreviousCommand(G4int i) const
Definition: G4UImanager.hh:231
G4String GetCurrentStringValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
Definition: G4UImanager.cc:183
void SetCoutFileName(const G4String &fileN="G4cout.txt", G4bool ifAppend=true)
Definition: G4UImanager.cc:746
static G4UImanager * GetMasterUIpointer()
Definition: G4UImanager.cc:72
void RegisterBridge(G4UIbridge *brg)
Definition: G4UImanager.cc:717
void SetIgnoreCmdNotFound(G4bool val)
Definition: G4UImanager.hh:269
void SetThreadUseBuffer(G4bool flg=true)
Definition: G4UImanager.cc:783
#define G4ThreadLocal
Definition: tls.hh:89
G4int GetVerboseLevel() const
Definition: G4UImanager.hh:227
void SetSession(G4UIsession *const value)
Definition: G4UImanager.hh:213
int G4int
Definition: G4Types.hh:78
std::vector< G4String > * GetCommandStack()
Definition: G4UImanager.cc:710
void SetG4UIWindow(G4UIsession *const value)
Definition: G4UImanager.hh:215
void SetVerboseLevel(G4int val)
Definition: G4UImanager.hh:225
void SetCerrFileName(const G4String &fileN="G4cerr.txt", G4bool ifAppend=true)
Definition: G4UImanager.cc:761
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:59
void ParseMacroSearchPath()
Definition: G4UImanager.cc:665
const XML_Char * s
Definition: expat.h:262
void SetThreadIgnoreInit(G4bool flg=true)
Definition: G4UImanager.cc:801
const XML_Char int const XML_Char * value
Definition: expat.h:331
void Loop(const char *macroFile, const char *variableName, G4double initialValue, G4double finalValue, G4double stepSize=1.0)
Definition: G4UImanager.cc:322
bool G4bool
Definition: G4Types.hh:79
G4bool GetPauseAtBeginOfEvent() const
Definition: G4UImanager.hh:194
void RemoveCommand(G4UIcommand *aCommand)
Definition: G4UImanager.cc:281
G4int GetCurrentIntValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
Definition: G4UImanager.cc:233
G4bool GetPauseAtEndOfEvent() const
Definition: G4UImanager.hh:198
G4String GetCurrentValues(const char *aCommand)
Definition: G4UImanager.cc:171
void SetMaxHistSize(G4int mx)
Definition: G4UImanager.hh:238
static G4bool DoublePrecisionStr()
Definition: G4UImanager.hh:301
void ListCommands(const char *direc)
Definition: G4UImanager.cc:552
G4UIcommandTree * GetTree() const
Definition: G4UImanager.hh:206
void AddNewCommand(G4UIcommand *newCommand)
Definition: G4UImanager.cc:269
void SetPauseAtEndOfEvent(G4bool vl)
Definition: G4UImanager.hh:196
void SetCoutDestination(G4UIsession *const value)
Definition: G4UImanager.cc:619
G4UIsession * GetG4UIWindow() const
Definition: G4UImanager.hh:210
G4String SolveAlias(const char *aCmd)
Definition: G4UImanager.cc:392
const G4String & GetMacroSearchPath() const
Definition: G4UImanager.hh:245
void SetPauseAtBeginOfEvent(G4bool vl)
Definition: G4UImanager.hh:192
void ListAlias()
Definition: G4UImanager.cc:651
void LoopS(const char *valueList)
Definition: G4UImanager.cc:302
string fname
Definition: test.py:308
virtual G4bool Notify(G4ApplicationState requestedState)
Definition: G4UImanager.cc:583
G4double GetCurrentDoubleValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
Definition: G4UImanager.cc:257
double G4double
Definition: G4Types.hh:76
static void UseDoublePrecisionStr(G4bool val)
Definition: G4UImanager.hh:300
void SetUpForSpecialThread(G4String aPrefix)
Definition: G4UImanager.cc:736
void SetThreadIgnore(G4int tid=0)
Definition: G4UImanager.cc:790
void CreateHTML(const char *dir="/")
Definition: G4UImanager.cc:656
void StoreHistory(const char *fileName="G4history.macro")
Definition: G4UImanager.cc:527
G4String FindMacroPath(const G4String &fname) const
Definition: G4UImanager.cc:695
void SetMasterUIManager(G4bool val)
Definition: G4UImanager.hh:258
G4ApplicationState
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:447
G4int GetMaxHistSize() const
Definition: G4UImanager.hh:240