Geant4 10.7.0
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
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 void StoreHistory(const char* fileName = "G4history.macro");
111 void StoreHistory(G4bool historySwitch,
112 const char* fileName = "G4history.macro");
113 // The executed commands will be stored in the defined file. If
114 // "historySwitch" is false, saving will be suspended
115
116 void ListCommands(const char* direc);
117 // All commands registered under the given directory will be listed to
118 // standard output
119
120 void SetAlias(const char* aliasLine);
121 // Define an alias. The first word of "aliasLine" string is the
122 // alias name and the remaining word(s) is(are) string value
123 // to be aliased
124
125 void RemoveAlias(const char* aliasName);
126 // Remove the defined alias
127
128 void ListAlias();
129 // Print all aliases
130
131 G4String SolveAlias(const char* aCmd);
132 // Convert a command string which contains alias(es)
133
134 void CreateHTML(const char* dir = "/");
135 // Generate HTML files for defined UI commands
136
137 void LoopS(const char* valueList);
138 void ForeachS(const char* valueList);
139 // These methods are used by G4UIcontrolMessenger to use Loop()
140 // and Foreach() methods
141
142 virtual G4bool Notify(G4ApplicationState requestedState);
143 // This method is exclusively invoked by G4StateManager
144
145 G4String GetCurrentStringValue(const char* aCommand,
146 G4int parameterNumber = 1,
147 G4bool reGet = true);
148 G4int GetCurrentIntValue(const char* aCommand, G4int parameterNumber = 1,
149 G4bool reGet = true);
150 G4double GetCurrentDoubleValue(const char* aCommand,
151 G4int parameterNumber = 1,
152 G4bool reGet = true);
153 G4String GetCurrentStringValue(const char* aCommand,
154 const char* aParameterName,
155 G4bool reGet = true);
156 G4int GetCurrentIntValue(const char* aCommand, const char* aParameterName,
157 G4bool reGet = true);
158 G4double GetCurrentDoubleValue(const char* aCommand,
159 const char* aParameterName,
160 G4bool reGet = true);
161 // These six methods return the current value of a parameter of the
162 // given command. For the first three methods, the ordering number of
163 // the parameter (1 is the first parameter) can be given, whereas,
164 // other three methods can give the parameter name.
165 // If "reGet" is true, actual request of returning the current value
166 // will be sent to the corresponding messenger, while, if it is false,
167 // the value stored in G4Umanager will be used. The later case is valid
168 // for the sequential invokation for the same command
169
170 inline void SetPauseAtBeginOfEvent(G4bool vl) { pauseAtBeginOfEvent = vl; }
171 inline G4bool GetPauseAtBeginOfEvent() const { return pauseAtBeginOfEvent; }
172 inline void SetPauseAtEndOfEvent(G4bool vl) { pauseAtEndOfEvent = vl; }
173 inline G4bool GetPauseAtEndOfEvent() const { return pauseAtEndOfEvent; }
174 // If the Boolean flags are true, Pause() method of G4StateManager is
175 // invoked at the very beginning (before generating a G4Event object)
176 // or at the end of each event. So that, in case a (G)UI session is
177 // defined, the user can interact
178
179 inline G4UIcommandTree* GetTree() const { return treeTop; }
180 inline G4UIsession* GetSession() const { return session; }
181 inline G4UIsession* GetG4UIWindow() const { return g4UIWindow; }
182
183 inline void SetSession(G4UIsession* const value) { session = value; }
184 inline void SetG4UIWindow(G4UIsession* const value) { g4UIWindow = value; }
185 // These methods define the active (G)UI session
186
187 void SetCoutDestination(G4UIsession* const value);
188 // This method defines the destination of G4cout/G4cerr stream.
189 // For usual cases, this method will be invoked by a concrete
190 // (G)UI session class object and thus the user needs not to invoke this
191
192 inline void SetVerboseLevel(G4int val) { verboseLevel = val; }
193 inline G4int GetVerboseLevel() const { return verboseLevel; }
194 inline G4int GetNumberOfHistory() const { return G4int(histVec.size()); }
196 {
197 G4String st;
198 if(i >= 0 && i < G4int(histVec.size()))
199 {
200 st = histVec[i];
201 }
202 return st;
203 }
204 inline void SetMaxHistSize(G4int mx) { maxHistSize = mx; }
205 inline G4int GetMaxHistSize() const { return maxHistSize; }
206
207 inline void SetMacroSearchPath(const G4String& path) { searchPath = path; }
208 inline const G4String& GetMacroSearchPath() const { return searchPath; }
210 G4String FindMacroPath(const G4String& fname) const;
211
212 inline void SetMasterUIManager(G4bool val)
213 {
214 isMaster = val;
215 stackCommandsForBroadcast = val;
216 if(val && !bridges)
217 {
218 bridges = new std::vector<G4UIbridge*>;
219 fMasterUImanager() = this;
220 }
221 }
222 inline void SetIgnoreCmdNotFound(G4bool val) { ignoreCmdNotFound = val; }
223
224 std::vector<G4String>* GetCommandStack();
225 void RegisterBridge(G4UIbridge* brg);
226
227 void SetUpForAThread(G4int tId);
228 // Setups as above but for a non-worker thread (e.g. vis)
229
230 void SetUpForSpecialThread(G4String aPrefix);
231
232 inline G4int GetThreadID() const { return threadID; }
233
234 void SetCoutFileName(const G4String& fileN = "G4cout.txt",
235 G4bool ifAppend = true);
236 void SetCerrFileName(const G4String& fileN = "G4cerr.txt",
237 G4bool ifAppend = true);
238 void SetThreadPrefixString(const G4String& s = "W");
239 void SetThreadUseBuffer(G4bool flg = true);
240 void SetThreadIgnore(G4int tid = 0);
241 void SetThreadIgnoreInit(G4bool flg = true);
242 inline G4MTcoutDestination* GetThreadCout() { return threadCout; }
243
244 static void UseDoublePrecisionStr(G4bool val);
245 static G4bool DoublePrecisionStr();
246
247 inline G4int GetLastReturnCode() const { return lastRC; }
248
249 protected:
250
251 G4UImanager();
252
253 private:
254
255 void AddWorkerCommand(G4UIcommand* newCommand);
256 void RemoveWorkerCommand(G4UIcommand* aCommand);
257
258 void PauseSession(const char* msg);
259 void CreateMessenger();
260 G4UIcommandTree* FindDirectory(const char* dirName);
261
262 private:
263
264 G4ICOMS_DLL static G4UImanager*& fUImanager(); // thread-local
265 G4ICOMS_DLL static G4bool& fUImanagerHasBeenKilled(); // thread-local
266 G4ICOMS_DLL static G4UImanager*& fMasterUImanager();
267 G4UIcommandTree* treeTop = nullptr;
268 G4UIsession* session = nullptr;
269 G4UIsession* g4UIWindow = nullptr;
270 G4UIcontrolMessenger* UImessenger = nullptr;
271 G4UnitsMessenger* UnitsMessenger = nullptr;
272 G4LocalThreadCoutMessenger* CoutMessenger = nullptr;
273 G4ProfilerMessenger* ProfileMessenger = nullptr;
274 G4String savedParameters;
275 G4UIcommand* savedCommand = nullptr;
276 G4int verboseLevel = 0;
277 std::ofstream historyFile;
278 G4bool saveHistory = false;
279 std::vector<G4String> histVec;
280 G4UIaliasList* aliasList = nullptr;
281 G4int maxHistSize = 20;
282 G4bool pauseAtBeginOfEvent = false;
283 G4bool pauseAtEndOfEvent = false;
284 G4String searchPath = "";
285 std::vector<G4String> searchDirs;
286
287 G4bool isMaster = false;
288 std::vector<G4UIbridge*>* bridges = nullptr;
289 G4bool ignoreCmdNotFound = false;
290 G4bool stackCommandsForBroadcast = false;
291 std::vector<G4String>* commandStack = nullptr;
292
293 G4int threadID = -1;
294 G4MTcoutDestination* threadCout = nullptr;
295 G4ICOMS_DLL static G4int igThreadID;
296
297 G4ICOMS_DLL static G4bool doublePrecisionStr;
298
299 G4int lastRC = 0;
300};
301
302#endif
G4ApplicationState
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
static G4bool DoublePrecisionStr()
Definition: G4UImanager.cc:158
void SetCerrFileName(const G4String &fileN="G4cerr.txt", G4bool ifAppend=true)
Definition: G4UImanager.cc:871
void SetCoutDestination(G4UIsession *const value)
Definition: G4UImanager.cc:699
static void UseDoublePrecisionStr(G4bool val)
Definition: G4UImanager.cc:152
const G4String & GetMacroSearchPath() const
Definition: G4UImanager.hh:208
void SetIgnoreCmdNotFound(G4bool val)
Definition: G4UImanager.hh:222
void ForeachS(const char *valueList)
Definition: G4UImanager.cc:365
G4UIcommandTree * GetTree() const
Definition: G4UImanager.hh:179
void SetUpForAThread(G4int tId)
Definition: G4UImanager.cc:832
std::vector< G4String > * GetCommandStack()
Definition: G4UImanager.cc:810
void Foreach(const char *macroFile, const char *variableName, const char *candidates)
Definition: G4UImanager.cc:399
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:485
void SetThreadIgnoreInit(G4bool flg=true)
Definition: G4UImanager.cc:920
G4int GetNumberOfHistory() const
Definition: G4UImanager.hh:194
void CreateHTML(const char *dir="/")
Definition: G4UImanager.cc:744
void Loop(const char *macroFile, const char *variableName, G4double initialValue, G4double finalValue, G4double stepSize=1.0)
Definition: G4UImanager.cc:336
G4int GetCurrentIntValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
Definition: G4UImanager.cc:231
G4String GetPreviousCommand(G4int i) const
Definition: G4UImanager.hh:195
void LoopS(const char *valueList)
Definition: G4UImanager.cc:315
void SetMasterUIManager(G4bool val)
Definition: G4UImanager.hh:212
G4bool GetPauseAtBeginOfEvent() const
Definition: G4UImanager.hh:171
void StoreHistory(const char *fileName="G4history.macro")
Definition: G4UImanager.cc:599
void ListCommands(const char *direc)
Definition: G4UImanager.cc:632
G4double GetCurrentDoubleValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
Definition: G4UImanager.cc:258
void ExecuteMacroFile(const char *fileName)
Definition: G4UImanager.cc:303
void SetMacroSearchPath(const G4String &path)
Definition: G4UImanager.hh:207
void SetCoutFileName(const G4String &fileN="G4cout.txt", G4bool ifAppend=true)
Definition: G4UImanager.cc:852
static G4UImanager * GetMasterUIpointer()
Definition: G4UImanager.cc:91
G4String GetCurrentStringValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
Definition: G4UImanager.cc:177
void SetUpForSpecialThread(G4String aPrefix)
Definition: G4UImanager.cc:841
void SetMaxHistSize(G4int mx)
Definition: G4UImanager.hh:204
G4int GetVerboseLevel() const
Definition: G4UImanager.hh:193
G4UIsession * GetSession() const
Definition: G4UImanager.hh:180
G4bool GetPauseAtEndOfEvent() const
Definition: G4UImanager.hh:173
G4int GetLastReturnCode() const
Definition: G4UImanager.hh:247
void SetPauseAtBeginOfEvent(G4bool vl)
Definition: G4UImanager.hh:170
void AddNewCommand(G4UIcommand *newCommand)
Definition: G4UImanager.cc:271
G4String GetCurrentValues(const char *aCommand)
Definition: G4UImanager.cc:164
virtual G4bool Notify(G4ApplicationState requestedState)
Definition: G4UImanager.cc:675
void SetThreadIgnore(G4int tid=0)
Definition: G4UImanager.cc:908
void SetAlias(const char *aliasLine)
Definition: G4UImanager.cc:706
void SetThreadPrefixString(const G4String &s="W")
Definition: G4UImanager.cc:890
G4String FindMacroPath(const G4String &fname) const
Definition: G4UImanager.cc:793
void RemoveAlias(const char *aliasName)
Definition: G4UImanager.cc:730
G4String SolveAlias(const char *aCmd)
Definition: G4UImanager.cc:424
const G4UImanager & operator=(const G4UImanager &)=delete
G4bool operator==(const G4UImanager &) const =delete
void ListAlias()
Definition: G4UImanager.cc:738
void RemoveCommand(G4UIcommand *aCommand)
Definition: G4UImanager.cc:287
G4UIsession * GetG4UIWindow() const
Definition: G4UImanager.hh:181
void ParseMacroSearchPath()
Definition: G4UImanager.cc:758
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77
void RegisterBridge(G4UIbridge *brg)
Definition: G4UImanager.cc:818
G4MTcoutDestination * GetThreadCout()
Definition: G4UImanager.hh:242
void SetSession(G4UIsession *const value)
Definition: G4UImanager.hh:183
G4UImanager(const G4UImanager &)=delete
void SetG4UIWindow(G4UIsession *const value)
Definition: G4UImanager.hh:184
void SetPauseAtEndOfEvent(G4bool vl)
Definition: G4UImanager.hh:172
void SetThreadUseBuffer(G4bool flg=true)
Definition: G4UImanager.cc:899
G4int GetThreadID() const
Definition: G4UImanager.hh:232
G4int GetMaxHistSize() const
Definition: G4UImanager.hh:205
G4bool operator!=(const G4UImanager &) const =delete
void SetVerboseLevel(G4int val)
Definition: G4UImanager.hh:192
#define G4ICOMS_DLL
Definition: icomsdefs.hh:45