Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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// G4UImanager
27//
28// Class description:
29//
30// This is a singleton class which controls the command manipulation
31// and the user interface(s)
32
33// Author: Makoto Asai, 1997
34// --------------------------------------------------------------------
35#ifndef G4UImanager_hh
36#define G4UImanager_hh 1
37
38#include <vector>
39#include <fstream>
40
41#include "globals.hh"
42#include "icomsdefs.hh"
43#include "G4VStateDependent.hh"
44#include "G4UIcommandStatus.hh"
45
46class G4UIcommandTree;
47class G4UIcommand;
48class G4UIsession;
52class G4UIaliasList;
54class G4UIbridge;
56
58{
59 public:
60
61 static G4UImanager* GetUIpointer();
63 // A static method to get the pointer to the only existing object
64 // of this class
65
66 ~G4UImanager() override;
67
68 G4UImanager(const G4UImanager&) = delete;
69 const G4UImanager& operator=(const G4UImanager&) = delete;
70 G4bool operator==(const G4UImanager&) const = delete;
71 G4bool operator!=(const G4UImanager&) const = delete;
72
73 G4String GetCurrentValues(const char* aCommand);
74 // This method returns a string which represents the current value(s)
75 // of the parameter(s) of the specified command. Null string will be
76 // returned if the given command is not defined or the command does
77 // not support the GetCurrentValues() method
78
79 void AddNewCommand(G4UIcommand* newCommand);
80 // This method register a new command
81
82 void RemoveCommand(G4UIcommand* aCommand);
83 // This command removes the registered command. After invokation of this
84 // command, that particular command cannot be applied
85
86 void ExecuteMacroFile(const char* fileName);
87 // A macro file defined by the argument will be read by G4UIbatch object
88
89 void Loop(const char* macroFile, const char* variableName,
90 G4double initialValue, G4double finalValue,
91 G4double stepSize = 1.0);
92 // Execute a macro file more than once with a loop counter
93
94 void Foreach(const char* macroFile, const char* variableName,
95 const char* candidates);
96 // Execute a macro file more than once with an aliased variable which
97 // takes a value in the candidate list
98
99 G4int ApplyCommand(const char* aCommand);
100 G4int ApplyCommand(const G4String& aCommand);
101 // A command (and parameter(s)) given
102 // by the method's argument will be applied. Zero will be returned in
103 // case the command is successfully executed. Positive non-zero value
104 // will be returned if the command cannot be executed. The meaning of
105 // this non-zero value is the following:
106 // The returned number : xyy
107 // x00 : G4CommandStatus.hh enumeration
108 // yy : the problematic parameter (first found)
109
110 G4UIcommand* FindCommand(const char* aCommand);
111 G4UIcommand* FindCommand(const G4String& aCommand);
112 // Find the G4UIcommand object. Null pointer is returned if command
113 // is not found.
114 // Please note that each thread returns different objects if this
115 // method is used in multi-threaded mode.
116
117 void StoreHistory(const char* fileName = "G4history.macro");
118 void StoreHistory(G4bool historySwitch,
119 const char* fileName = "G4history.macro");
120 // The executed commands will be stored in the defined file. If
121 // "historySwitch" is false, saving will be suspended
122
123 void ListCommands(const char* direc);
124 // All commands registered under the given directory will be listed to
125 // standard output
126
127 void SetAlias(const char* aliasLine);
128 // Define an alias. The first word of "aliasLine" string is the
129 // alias name and the remaining word(s) is(are) string value
130 // to be aliased
131
132 void RemoveAlias(const char* aliasName);
133 // Remove the defined alias
134
135 void ListAlias();
136 // Print all aliases
137
138 G4String SolveAlias(const char* aCmd);
139 // Convert a command string which contains alias(es)
140
141 void CreateHTML(const char* dir = "/");
142 // Generate HTML files for defined UI commands
143
144 void LoopS(const char* valueList);
145 void ForeachS(const char* valueList);
146 // These methods are used by G4UIcontrolMessenger to use Loop()
147 // and Foreach() methods
148
149 G4bool Notify(G4ApplicationState requestedState) override;
150 // This method is exclusively invoked by G4StateManager
151
152 G4String GetCurrentStringValue(const char* aCommand,
153 G4int parameterNumber = 1,
154 G4bool reGet = true);
155 G4int GetCurrentIntValue(const char* aCommand, G4int parameterNumber = 1,
156 G4bool reGet = true);
157 G4double GetCurrentDoubleValue(const char* aCommand,
158 G4int parameterNumber = 1,
159 G4bool reGet = true);
160 G4String GetCurrentStringValue(const char* aCommand,
161 const char* aParameterName,
162 G4bool reGet = true);
163 G4int GetCurrentIntValue(const char* aCommand, const char* aParameterName,
164 G4bool reGet = true);
165 G4double GetCurrentDoubleValue(const char* aCommand,
166 const char* aParameterName,
167 G4bool reGet = true);
168 // These six methods return the current value of a parameter of the
169 // given command. For the first three methods, the ordering number of
170 // the parameter (1 is the first parameter) can be given, whereas,
171 // other three methods can give the parameter name.
172 // If "reGet" is true, actual request of returning the current value
173 // will be sent to the corresponding messenger, while, if it is false,
174 // the value stored in G4Umanager will be used. The later case is valid
175 // for the sequential invokation for the same command
176
177 inline void SetPauseAtBeginOfEvent(G4bool vl) { pauseAtBeginOfEvent = vl; }
178 inline G4bool GetPauseAtBeginOfEvent() const { return pauseAtBeginOfEvent; }
179 inline void SetPauseAtEndOfEvent(G4bool vl) { pauseAtEndOfEvent = vl; }
180 inline G4bool GetPauseAtEndOfEvent() const { return pauseAtEndOfEvent; }
181 // If the Boolean flags are true, Pause() method of G4StateManager is
182 // invoked at the very beginning (before generating a G4Event object)
183 // or at the end of each event. So that, in case a (G)UI session is
184 // defined, the user can interact
185
186 inline G4UIcommandTree* GetTree() const { return treeTop; }
187 inline G4UIsession* GetSession() const { return session; }
188 inline G4UIsession* GetG4UIWindow() const { return g4UIWindow; }
189
190 inline void SetSession(G4UIsession* const value) { session = value; }
191 inline void SetG4UIWindow(G4UIsession* const value) { g4UIWindow = value; }
192 // These methods define the active (G)UI session
193
194 void SetCoutDestination(G4UIsession* const value);
195 // This method defines the destination of G4cout/G4cerr stream.
196 // For usual cases, this method will be invoked by a concrete
197 // (G)UI session class object and thus the user needs not to invoke this
198
199 inline void SetVerboseLevel(G4int val) { verboseLevel = val; }
200 inline G4int GetVerboseLevel() const { return verboseLevel; }
201 inline G4int GetNumberOfHistory() const { return G4int(histVec.size()); }
203 {
204 G4String st;
205 if(i >= 0 && i < G4int(histVec.size()))
206 {
207 st = histVec[i];
208 }
209 return st;
210 }
211 inline void SetMaxHistSize(G4int mx) { maxHistSize = mx; }
212 inline G4int GetMaxHistSize() const { return maxHistSize; }
213
214 inline void SetMacroSearchPath(const G4String& path) { searchPath = path; }
215 inline const G4String& GetMacroSearchPath() const { return searchPath; }
217 G4String FindMacroPath(const G4String& fname) const;
218
219 inline void SetMasterUIManager(G4bool val)
220 {
221 isMaster = val;
222 stackCommandsForBroadcast = val;
223 if(val && (bridges == nullptr))
224 {
225 bridges = new std::vector<G4UIbridge*>;
226 fMasterUImanager() = this;
227 }
228 }
229 inline void SetIgnoreCmdNotFound(G4bool val) { ignoreCmdNotFound = val; }
230
231 std::vector<G4String>* GetCommandStack();
232 void RegisterBridge(G4UIbridge* brg);
233
234 void SetUpForAThread(G4int tId);
235 // Setups as above but for a non-worker thread (e.g. vis)
236
237 void SetUpForSpecialThread(const G4String& aPrefix);
238
239 inline G4int GetThreadID() const { return threadID; }
240
241 void SetCoutFileName(const G4String& fileN = "G4cout.txt",
242 G4bool ifAppend = true);
243 void SetCerrFileName(const G4String& fileN = "G4cerr.txt",
244 G4bool ifAppend = true);
245 void SetThreadPrefixString(const G4String& prefix = "W");
246 void SetThreadUseBuffer(G4bool flg = true);
247 void SetThreadIgnore(G4int tid = 0);
248 void SetThreadIgnoreInit(G4bool flg = true);
249 inline G4MTcoutDestination* GetThreadCout() { return threadCout; }
250
251 static void UseDoublePrecisionStr(G4bool val);
252 static G4bool DoublePrecisionStr();
253
254 inline G4int GetLastReturnCode() const { return lastRC; }
255
256 inline bool IsLastCommandOutputTreated() { return fLastCommandOutputTreated; }
257 inline void SetLastCommandOutputTreated() { fLastCommandOutputTreated = true; }
258
259 protected:
260
261 G4UImanager();
262
263 private:
264
265 void AddWorkerCommand(G4UIcommand* newCommand);
266 void RemoveWorkerCommand(G4UIcommand* aCommand);
267
268 void PauseSession(const char* msg);
269 void CreateMessenger();
270 G4UIcommandTree* FindDirectory(const char* dirName);
271
272 private:
273
274 G4ICOMS_DLL static G4UImanager*& fUImanager(); // thread-local
275 G4ICOMS_DLL static G4bool& fUImanagerHasBeenKilled(); // thread-local
276 G4ICOMS_DLL static G4UImanager*& fMasterUImanager();
277 G4UIcommandTree* treeTop = nullptr;
278 G4UIsession* session = nullptr;
279 G4UIsession* g4UIWindow = nullptr;
280 G4UIcontrolMessenger* UImessenger = nullptr;
281 G4UnitsMessenger* UnitsMessenger = nullptr;
282 G4LocalThreadCoutMessenger* CoutMessenger = nullptr;
283 G4ProfilerMessenger* ProfileMessenger = nullptr;
284 G4String savedParameters;
285 G4UIcommand* savedCommand = nullptr;
286 G4int verboseLevel = 0;
287 std::ofstream historyFile;
288 G4bool saveHistory = false;
289 std::vector<G4String> histVec;
290 G4UIaliasList* aliasList = nullptr;
291 G4int maxHistSize = 20;
292 G4bool pauseAtBeginOfEvent = false;
293 G4bool pauseAtEndOfEvent = false;
294 G4String searchPath = "";
295 std::vector<G4String> searchDirs;
296
297 G4bool isMaster = false;
298 std::vector<G4UIbridge*>* bridges = nullptr;
299 G4bool ignoreCmdNotFound = false;
300 G4bool stackCommandsForBroadcast = false;
301 std::vector<G4String>* commandStack = nullptr;
302
303 G4int threadID = -1;
304 G4MTcoutDestination* threadCout = nullptr;
305 G4ICOMS_DLL static G4int igThreadID;
306
307 G4ICOMS_DLL static G4bool doublePrecisionStr;
308
309 G4int lastRC = 0;
310
311 G4bool fLastCommandOutputTreated = true;
312};
313
314#endif
G4ApplicationState
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
~G4UImanager() override
Definition: G4UImanager.cc:116
static G4bool DoublePrecisionStr()
Definition: G4UImanager.cc:160
void SetCerrFileName(const G4String &fileN="G4cerr.txt", G4bool ifAppend=true)
Definition: G4UImanager.cc:925
void SetCoutDestination(G4UIsession *const value)
Definition: G4UImanager.cc:747
static void UseDoublePrecisionStr(G4bool val)
Definition: G4UImanager.cc:154
const G4String & GetMacroSearchPath() const
Definition: G4UImanager.hh:215
void SetIgnoreCmdNotFound(G4bool val)
Definition: G4UImanager.hh:229
void ForeachS(const char *valueList)
Definition: G4UImanager.cc:371
G4UIcommandTree * GetTree() const
Definition: G4UImanager.hh:186
void SetUpForAThread(G4int tId)
Definition: G4UImanager.cc:884
std::vector< G4String > * GetCommandStack()
Definition: G4UImanager.cc:862
void Foreach(const char *macroFile, const char *variableName, const char *candidates)
Definition: G4UImanager.cc:405
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:495
void SetThreadIgnoreInit(G4bool flg=true)
Definition: G4UImanager.cc:980
G4int GetNumberOfHistory() const
Definition: G4UImanager.hh:201
void CreateHTML(const char *dir="/")
Definition: G4UImanager.cc:792
void Loop(const char *macroFile, const char *variableName, G4double initialValue, G4double finalValue, G4double stepSize=1.0)
Definition: G4UImanager.cc:342
G4int GetCurrentIntValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
Definition: G4UImanager.cc:237
bool IsLastCommandOutputTreated()
Definition: G4UImanager.hh:256
G4String GetPreviousCommand(G4int i) const
Definition: G4UImanager.hh:202
void SetThreadPrefixString(const G4String &prefix="W")
Definition: G4UImanager.cc:946
void LoopS(const char *valueList)
Definition: G4UImanager.cc:321
void SetMasterUIManager(G4bool val)
Definition: G4UImanager.hh:219
G4bool GetPauseAtBeginOfEvent() const
Definition: G4UImanager.hh:178
void StoreHistory(const char *fileName="G4history.macro")
Definition: G4UImanager.cc:645
void ListCommands(const char *direc)
Definition: G4UImanager.cc:680
G4double GetCurrentDoubleValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
Definition: G4UImanager.cc:264
void ExecuteMacroFile(const char *fileName)
Definition: G4UImanager.cc:309
void SetMacroSearchPath(const G4String &path)
Definition: G4UImanager.hh:214
void SetCoutFileName(const G4String &fileN="G4cout.txt", G4bool ifAppend=true)
Definition: G4UImanager.cc:904
static G4UImanager * GetMasterUIpointer()
Definition: G4UImanager.cc:91
G4String GetCurrentStringValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
Definition: G4UImanager.cc:179
void SetMaxHistSize(G4int mx)
Definition: G4UImanager.hh:211
G4int GetVerboseLevel() const
Definition: G4UImanager.hh:200
G4UIsession * GetSession() const
Definition: G4UImanager.hh:187
G4bool GetPauseAtEndOfEvent() const
Definition: G4UImanager.hh:180
G4int GetLastReturnCode() const
Definition: G4UImanager.hh:254
void SetUpForSpecialThread(const G4String &aPrefix)
Definition: G4UImanager.cc:893
void SetPauseAtBeginOfEvent(G4bool vl)
Definition: G4UImanager.hh:177
void AddNewCommand(G4UIcommand *newCommand)
Definition: G4UImanager.cc:277
G4String GetCurrentValues(const char *aCommand)
Definition: G4UImanager.cc:166
void SetThreadIgnore(G4int tid=0)
Definition: G4UImanager.cc:968
void SetAlias(const char *aliasLine)
Definition: G4UImanager.cc:754
G4String FindMacroPath(const G4String &fname) const
Definition: G4UImanager.cc:845
void RemoveAlias(const char *aliasName)
Definition: G4UImanager.cc:778
G4bool Notify(G4ApplicationState requestedState) override
Definition: G4UImanager.cc:723
G4String SolveAlias(const char *aCmd)
Definition: G4UImanager.cc:430
const G4UImanager & operator=(const G4UImanager &)=delete
G4bool operator==(const G4UImanager &) const =delete
void ListAlias()
Definition: G4UImanager.cc:786
void RemoveCommand(G4UIcommand *aCommand)
Definition: G4UImanager.cc:293
G4UIsession * GetG4UIWindow() const
Definition: G4UImanager.hh:188
G4UIcommand * FindCommand(const char *aCommand)
Definition: G4UImanager.cc:627
void ParseMacroSearchPath()
Definition: G4UImanager.cc:806
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77
void RegisterBridge(G4UIbridge *brg)
Definition: G4UImanager.cc:870
G4MTcoutDestination * GetThreadCout()
Definition: G4UImanager.hh:249
void SetSession(G4UIsession *const value)
Definition: G4UImanager.hh:190
G4UImanager(const G4UImanager &)=delete
void SetG4UIWindow(G4UIsession *const value)
Definition: G4UImanager.hh:191
void SetPauseAtEndOfEvent(G4bool vl)
Definition: G4UImanager.hh:179
void SetThreadUseBuffer(G4bool flg=true)
Definition: G4UImanager.cc:957
G4int GetThreadID() const
Definition: G4UImanager.hh:239
G4int GetMaxHistSize() const
Definition: G4UImanager.hh:212
void SetLastCommandOutputTreated()
Definition: G4UImanager.hh:257
G4bool operator!=(const G4UImanager &) const =delete
void SetVerboseLevel(G4int val)
Definition: G4UImanager.hh:199
#define G4ICOMS_DLL
Definition: icomsdefs.hh:45