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