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