Geant4-11
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 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 virtual G4bool Notify(G4ApplicationState requestedState);
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
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;
223 if(val && !bridges)
224 {
225 bridges = new std::vector<G4UIbridge*>;
226 fMasterUImanager() = this;
227 }
228 }
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(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);
250
251 static void UseDoublePrecisionStr(G4bool val);
252 static G4bool DoublePrecisionStr();
253
254 inline G4int GetLastReturnCode() const { return lastRC; }
255
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
287 std::ofstream historyFile;
289 std::vector<G4String> histVec;
295 std::vector<G4String> searchDirs;
296
298 std::vector<G4UIbridge*>* bridges = nullptr;
301 std::vector<G4String>* commandStack = nullptr;
302
306
308
310
312};
313
314#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
G4ProfilerMessenger * ProfileMessenger
Definition: G4UImanager.hh:283
G4int verboseLevel
Definition: G4UImanager.hh:286
void RemoveWorkerCommand(G4UIcommand *aCommand)
Definition: G4UImanager.cc:297
void SetCerrFileName(const G4String &fileN="G4cerr.txt", G4bool ifAppend=true)
Definition: G4UImanager.cc:899
void SetCoutDestination(G4UIsession *const value)
Definition: G4UImanager.cc:727
static void UseDoublePrecisionStr(G4bool val)
Definition: G4UImanager.cc:152
G4bool ignoreCmdNotFound
Definition: G4UImanager.hh:299
const G4String & GetMacroSearchPath() const
Definition: G4UImanager.hh:215
G4UIaliasList * aliasList
Definition: G4UImanager.hh:290
void SetIgnoreCmdNotFound(G4bool val)
Definition: G4UImanager.hh:229
static G4ICOMS_DLL G4int igThreadID
Definition: G4UImanager.hh:305
G4bool fLastCommandOutputTreated
Definition: G4UImanager.hh:311
void ForeachS(const char *valueList)
Definition: G4UImanager.cc:365
G4UIcommandTree * GetTree() const
Definition: G4UImanager.hh:186
void SetUpForAThread(G4int tId)
Definition: G4UImanager.cc:860
std::vector< G4String > * GetCommandStack()
Definition: G4UImanager.cc:838
void Foreach(const char *macroFile, const char *variableName, const char *candidates)
Definition: G4UImanager.cc:399
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:485
static G4ICOMS_DLL G4UImanager *& fMasterUImanager()
Definition: G4UImanager.cc:70
void SetThreadIgnoreInit(G4bool flg=true)
Definition: G4UImanager.cc:948
G4int GetNumberOfHistory() const
Definition: G4UImanager.hh:201
G4bool pauseAtEndOfEvent
Definition: G4UImanager.hh:293
void CreateHTML(const char *dir="/")
Definition: G4UImanager.cc:772
void AddWorkerCommand(G4UIcommand *newCommand)
Definition: G4UImanager.cc:281
void Loop(const char *macroFile, const char *variableName, G4double initialValue, G4double finalValue, G4double stepSize=1.0)
Definition: G4UImanager.cc:336
std::vector< G4String > * commandStack
Definition: G4UImanager.hh:301
void CreateMessenger()
Definition: G4UImanager.cc:107
G4int GetCurrentIntValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
Definition: G4UImanager.cc:231
std::vector< G4String > searchDirs
Definition: G4UImanager.hh:295
bool IsLastCommandOutputTreated()
Definition: G4UImanager.hh:256
G4String GetPreviousCommand(G4int i) const
Definition: G4UImanager.hh:202
void SetThreadPrefixString(const G4String &prefix="W")
Definition: G4UImanager.cc:918
void LoopS(const char *valueList)
Definition: G4UImanager.cc:315
void SetMasterUIManager(G4bool val)
Definition: G4UImanager.hh:219
G4UIcommandTree * treeTop
Definition: G4UImanager.hh:277
G4bool GetPauseAtBeginOfEvent() const
Definition: G4UImanager.hh:178
void StoreHistory(const char *fileName="G4history.macro")
Definition: G4UImanager.cc:627
G4int maxHistSize
Definition: G4UImanager.hh:291
void ListCommands(const char *direc)
Definition: G4UImanager.cc:660
G4bool isMaster
Definition: G4UImanager.hh:297
G4double GetCurrentDoubleValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
Definition: G4UImanager.cc:258
void PauseSession(const char *msg)
Definition: G4UImanager.cc:653
G4UIcommand * savedCommand
Definition: G4UImanager.hh:285
void ExecuteMacroFile(const char *fileName)
Definition: G4UImanager.cc:303
void SetMacroSearchPath(const G4String &path)
Definition: G4UImanager.hh:214
void SetCoutFileName(const G4String &fileN="G4cout.txt", G4bool ifAppend=true)
Definition: G4UImanager.cc:880
G4UnitsMessenger * UnitsMessenger
Definition: G4UImanager.hh:281
std::vector< G4UIbridge * > * bridges
Definition: G4UImanager.hh:298
static G4UImanager * GetMasterUIpointer()
Definition: G4UImanager.cc:91
G4String savedParameters
Definition: G4UImanager.hh:284
std::ofstream historyFile
Definition: G4UImanager.hh:287
G4String GetCurrentStringValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
Definition: G4UImanager.cc:177
void SetUpForSpecialThread(G4String aPrefix)
Definition: G4UImanager.cc:869
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 SetPauseAtBeginOfEvent(G4bool vl)
Definition: G4UImanager.hh:177
void AddNewCommand(G4UIcommand *newCommand)
Definition: G4UImanager.cc:271
G4bool saveHistory
Definition: G4UImanager.hh:288
G4String GetCurrentValues(const char *aCommand)
Definition: G4UImanager.cc:164
virtual G4bool Notify(G4ApplicationState requestedState)
Definition: G4UImanager.cc:703
void SetThreadIgnore(G4int tid=0)
Definition: G4UImanager.cc:936
void SetAlias(const char *aliasLine)
Definition: G4UImanager.cc:734
std::vector< G4String > histVec
Definition: G4UImanager.hh:289
G4String FindMacroPath(const G4String &fname) const
Definition: G4UImanager.cc:821
G4int threadID
Definition: G4UImanager.hh:303
static G4ICOMS_DLL G4bool doublePrecisionStr
Definition: G4UImanager.hh:307
void RemoveAlias(const char *aliasName)
Definition: G4UImanager.cc:758
G4String SolveAlias(const char *aCmd)
Definition: G4UImanager.cc:424
const G4UImanager & operator=(const G4UImanager &)=delete
static G4ICOMS_DLL G4UImanager *& fUImanager()
Definition: G4UImanager.cc:56
G4bool operator==(const G4UImanager &) const =delete
G4LocalThreadCoutMessenger * CoutMessenger
Definition: G4UImanager.hh:282
void ListAlias()
Definition: G4UImanager.cc:766
void RemoveCommand(G4UIcommand *aCommand)
Definition: G4UImanager.cc:287
G4UIcommandTree * FindDirectory(const char *dirName)
Definition: G4UImanager.cc:674
G4UIsession * GetG4UIWindow() const
Definition: G4UImanager.hh:188
G4MTcoutDestination * threadCout
Definition: G4UImanager.hh:304
G4bool stackCommandsForBroadcast
Definition: G4UImanager.hh:300
G4UIcommand * FindCommand(const char *aCommand)
Definition: G4UImanager.cc:609
void ParseMacroSearchPath()
Definition: G4UImanager.cc:786
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77
G4UIcontrolMessenger * UImessenger
Definition: G4UImanager.hh:280
G4UIsession * g4UIWindow
Definition: G4UImanager.hh:279
void RegisterBridge(G4UIbridge *brg)
Definition: G4UImanager.cc:846
G4MTcoutDestination * GetThreadCout()
Definition: G4UImanager.hh:249
void SetSession(G4UIsession *const value)
Definition: G4UImanager.hh:190
G4String searchPath
Definition: G4UImanager.hh:294
G4UImanager(const G4UImanager &)=delete
void SetG4UIWindow(G4UIsession *const value)
Definition: G4UImanager.hh:191
void SetPauseAtEndOfEvent(G4bool vl)
Definition: G4UImanager.hh:179
G4bool pauseAtBeginOfEvent
Definition: G4UImanager.hh:292
void SetThreadUseBuffer(G4bool flg=true)
Definition: G4UImanager.cc:927
G4int GetThreadID() const
Definition: G4UImanager.hh:239
G4int GetMaxHistSize() const
Definition: G4UImanager.hh:212
static G4ICOMS_DLL G4bool & fUImanagerHasBeenKilled()
Definition: G4UImanager.cc:63
void SetLastCommandOutputTreated()
Definition: G4UImanager.hh:257
G4UIsession * session
Definition: G4UImanager.hh:278
G4bool operator!=(const G4UImanager &) const =delete
void SetVerboseLevel(G4int val)
Definition: G4UImanager.hh:199
#define G4ICOMS_DLL
Definition: icomsdefs.hh:45
string fname
Definition: test.py:308