Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4UImanager 26 // G4UImanager 27 // 27 // 28 // Class description: 28 // Class description: 29 // 29 // 30 // This is a singleton class which controls th 30 // This is a singleton class which controls the command manipulation 31 // and the user interface(s) 31 // and the user interface(s) 32 32 33 // Author: Makoto Asai, 1997 33 // Author: Makoto Asai, 1997 34 // ------------------------------------------- 34 // -------------------------------------------------------------------- 35 #ifndef G4UImanager_hh 35 #ifndef G4UImanager_hh 36 #define G4UImanager_hh 1 36 #define G4UImanager_hh 1 37 37 38 #include "G4UIcommandStatus.hh" 38 #include "G4UIcommandStatus.hh" 39 #include "G4VStateDependent.hh" 39 #include "G4VStateDependent.hh" 40 #include "globals.hh" 40 #include "globals.hh" 41 41 42 #include "icomsdefs.hh" 42 #include "icomsdefs.hh" 43 43 44 #include <fstream> 44 #include <fstream> 45 #include <vector> 45 #include <vector> 46 46 47 class G4UIcommandTree; 47 class G4UIcommandTree; 48 class G4UIcommand; 48 class G4UIcommand; 49 class G4UIsession; 49 class G4UIsession; 50 class G4UIcontrolMessenger; 50 class G4UIcontrolMessenger; 51 class G4UnitsMessenger; 51 class G4UnitsMessenger; 52 class G4LocalThreadCoutMessenger; 52 class G4LocalThreadCoutMessenger; 53 class G4UIaliasList; 53 class G4UIaliasList; 54 class G4MTcoutDestination; 54 class G4MTcoutDestination; 55 class G4UIbridge; 55 class G4UIbridge; >> 56 class G4ProfilerMessenger; 56 57 57 class G4UImanager : public G4VStateDependent 58 class G4UImanager : public G4VStateDependent 58 { 59 { 59 public: 60 public: 60 // A static method to get the pointer to t 61 // A static method to get the pointer to the only existing object 61 // of this class 62 // of this class 62 static G4UImanager* GetUIpointer(); 63 static G4UImanager* GetUIpointer(); 63 static G4UImanager* GetMasterUIpointer(); 64 static G4UImanager* GetMasterUIpointer(); 64 65 65 ~G4UImanager() override; 66 ~G4UImanager() override; 66 67 67 G4UImanager(const G4UImanager&) = delete; 68 G4UImanager(const G4UImanager&) = delete; 68 const G4UImanager& operator=(const G4UIman 69 const G4UImanager& operator=(const G4UImanager&) = delete; 69 G4bool operator==(const G4UImanager&) cons 70 G4bool operator==(const G4UImanager&) const = delete; 70 G4bool operator!=(const G4UImanager&) cons 71 G4bool operator!=(const G4UImanager&) const = delete; 71 72 72 // This method returns a string which repr 73 // This method returns a string which represents the current value(s) 73 // of the parameter(s) of the specified co 74 // of the parameter(s) of the specified command. Null string will be 74 // returned if the given command is not de 75 // returned if the given command is not defined or the command does 75 // not support the GetCurrentValues() meth 76 // not support the GetCurrentValues() method 76 G4String GetCurrentValues(const char* aCom 77 G4String GetCurrentValues(const char* aCommand); 77 78 78 // This method register a new command 79 // This method register a new command 79 void AddNewCommand(G4UIcommand* newCommand 80 void AddNewCommand(G4UIcommand* newCommand); 80 81 81 // This command removes the registered com 82 // This command removes the registered command. After invokation of this 82 // command, that particular command cannot 83 // command, that particular command cannot be applied 83 void RemoveCommand(G4UIcommand* aCommand); 84 void RemoveCommand(G4UIcommand* aCommand); 84 85 85 // A macro file defined by the argument wi 86 // A macro file defined by the argument will be read by G4UIbatch object 86 void ExecuteMacroFile(const char* fileName 87 void ExecuteMacroFile(const char* fileName); 87 88 88 // Execute a macro file more than once wit 89 // Execute a macro file more than once with a loop counter 89 void Loop(const char* macroFile, const cha 90 void Loop(const char* macroFile, const char* variableName, G4double initialValue, 90 G4double finalValue, G4double st 91 G4double finalValue, G4double stepSize = 1.0); 91 92 92 // Execute a macro file more than once wit 93 // Execute a macro file more than once with an aliased variable which 93 // takes a value in the candidate list 94 // takes a value in the candidate list 94 void Foreach(const char* macroFile, const 95 void Foreach(const char* macroFile, const char* variableName, const char* candidates); 95 96 96 // A command (and parameter(s)) given 97 // A command (and parameter(s)) given 97 // by the method's argument will be applie 98 // by the method's argument will be applied. Zero will be returned in 98 // case the command is successfully execut 99 // case the command is successfully executed. Positive non-zero value 99 // will be returned if the command cannot 100 // will be returned if the command cannot be executed. The meaning of 100 // this non-zero value is the following: 101 // this non-zero value is the following: 101 // The returned number : xyy 102 // The returned number : xyy 102 // x00 : G4CommandStatus.hh enumera 103 // x00 : G4CommandStatus.hh enumeration 103 // yy : the problematic parameter 104 // yy : the problematic parameter (first found) 104 G4int ApplyCommand(const char* aCommand); 105 G4int ApplyCommand(const char* aCommand); 105 G4int ApplyCommand(const G4String& aComman 106 G4int ApplyCommand(const G4String& aCommand); 106 107 107 // Find the G4UIcommand object. Null point 108 // Find the G4UIcommand object. Null pointer is returned if command 108 // is not found. 109 // is not found. 109 // Please note that each thread returns di 110 // Please note that each thread returns different objects if this 110 // method is used in multi-threaded mode. 111 // method is used in multi-threaded mode. 111 G4UIcommand* FindCommand(const char* aComm 112 G4UIcommand* FindCommand(const char* aCommand); 112 G4UIcommand* FindCommand(const G4String& a 113 G4UIcommand* FindCommand(const G4String& aCommand); 113 114 114 // The executed commands will be stored in 115 // The executed commands will be stored in the defined file. If 115 // "historySwitch" is false, saving will b 116 // "historySwitch" is false, saving will be suspended 116 void StoreHistory(const char* fileName = " 117 void StoreHistory(const char* fileName = "G4history.macro"); 117 void StoreHistory(G4bool historySwitch, co 118 void StoreHistory(G4bool historySwitch, const char* fileName = "G4history.macro"); 118 119 119 // All commands registered under the given 120 // All commands registered under the given directory will be listed to 120 // standard output 121 // standard output 121 void ListCommands(const char* direc); 122 void ListCommands(const char* direc); 122 123 123 // Define an alias. The first word of "ali 124 // Define an alias. The first word of "aliasLine" string is the 124 // alias name and the remaining word(s) is 125 // alias name and the remaining word(s) is(are) string value 125 // to be aliased 126 // to be aliased 126 void SetAlias(const char* aliasLine); 127 void SetAlias(const char* aliasLine); 127 128 128 // Remove the defined alias 129 // Remove the defined alias 129 void RemoveAlias(const char* aliasName); 130 void RemoveAlias(const char* aliasName); 130 131 131 // Print all aliases 132 // Print all aliases 132 void ListAlias(); 133 void ListAlias(); 133 134 134 // Convert a command string which contains 135 // Convert a command string which contains alias(es) 135 G4String SolveAlias(const char* aCmd); 136 G4String SolveAlias(const char* aCmd); 136 137 137 // Generate HTML files for defined UI comm 138 // Generate HTML files for defined UI commands 138 void CreateHTML(const char* dir = "/"); 139 void CreateHTML(const char* dir = "/"); 139 140 140 // These methods are used by G4UIcontrolMe 141 // These methods are used by G4UIcontrolMessenger to use Loop() 141 // and Foreach() methods 142 // and Foreach() methods 142 void LoopS(const char* valueList); 143 void LoopS(const char* valueList); 143 void ForeachS(const char* valueList); 144 void ForeachS(const char* valueList); 144 145 145 // This method is exclusively invoked by G 146 // This method is exclusively invoked by G4StateManager 146 G4bool Notify(G4ApplicationState requested 147 G4bool Notify(G4ApplicationState requestedState) override; 147 148 148 // These six methods return the current va 149 // These six methods return the current value of a parameter of the 149 // given command. For the first three meth 150 // given command. For the first three methods, the ordering number of 150 // the parameter (1 is the first parameter 151 // the parameter (1 is the first parameter) can be given, whereas, 151 // other three methods can give the parame 152 // other three methods can give the parameter name. 152 // If "reGet" is true, actual request of r 153 // If "reGet" is true, actual request of returning the current value 153 // will be sent to the corresponding messe 154 // will be sent to the corresponding messenger, while, if it is false, 154 // the value stored in G4Umanager will be 155 // the value stored in G4Umanager will be used. The later case is valid 155 // for the sequential invokation for the s 156 // for the sequential invokation for the same command 156 G4String GetCurrentStringValue(const char* 157 G4String GetCurrentStringValue(const char* aCommand, G4int parameterNumber = 1, 157 G4bool reGe 158 G4bool reGet = true); 158 G4int GetCurrentIntValue(const char* aComm 159 G4int GetCurrentIntValue(const char* aCommand, G4int parameterNumber = 1, G4bool reGet = true); 159 G4double GetCurrentDoubleValue(const char* 160 G4double GetCurrentDoubleValue(const char* aCommand, G4int parameterNumber = 1, 160 G4bool reGe 161 G4bool reGet = true); 161 G4String GetCurrentStringValue(const char* 162 G4String GetCurrentStringValue(const char* aCommand, const char* aParameterName, 162 G4bool reGe 163 G4bool reGet = true); 163 G4int GetCurrentIntValue(const char* aComm 164 G4int GetCurrentIntValue(const char* aCommand, const char* aParameterName, G4bool reGet = true); 164 G4double GetCurrentDoubleValue(const char* 165 G4double GetCurrentDoubleValue(const char* aCommand, const char* aParameterName, 165 G4bool reGe 166 G4bool reGet = true); 166 167 167 // If the Boolean flags are true, Pause() 168 // If the Boolean flags are true, Pause() method of G4StateManager is 168 // invoked at the very beginning (before g 169 // invoked at the very beginning (before generating a G4Event object) 169 // or at the end of each event. So that, i 170 // or at the end of each event. So that, in case a (G)UI session is 170 // defined, the user can interact 171 // defined, the user can interact 171 inline void SetPauseAtBeginOfEvent(G4bool 172 inline void SetPauseAtBeginOfEvent(G4bool vl) { pauseAtBeginOfEvent = vl; } 172 inline G4bool GetPauseAtBeginOfEvent() con 173 inline G4bool GetPauseAtBeginOfEvent() const { return pauseAtBeginOfEvent; } 173 inline void SetPauseAtEndOfEvent(G4bool vl 174 inline void SetPauseAtEndOfEvent(G4bool vl) { pauseAtEndOfEvent = vl; } 174 inline G4bool GetPauseAtEndOfEvent() const 175 inline G4bool GetPauseAtEndOfEvent() const { return pauseAtEndOfEvent; } 175 176 176 inline G4UIcommandTree* GetTree() const { 177 inline G4UIcommandTree* GetTree() const { return treeTop; } 177 inline G4UIsession* GetSession() const { r 178 inline G4UIsession* GetSession() const { return session; } 178 inline G4UIsession* GetG4UIWindow() const 179 inline G4UIsession* GetG4UIWindow() const { return g4UIWindow; } 179 // Find base session in a hierarchy of ses 180 // Find base session in a hierarchy of sessions 180 G4UIsession* GetBaseSession() const; 181 G4UIsession* GetBaseSession() const; 181 182 182 // These methods define the active (G)UI s 183 // These methods define the active (G)UI session 183 inline void SetSession(G4UIsession* const 184 inline void SetSession(G4UIsession* const value) { session = value; } 184 inline void SetG4UIWindow(G4UIsession* con 185 inline void SetG4UIWindow(G4UIsession* const value) { g4UIWindow = value; } 185 186 186 // This method defines the destination of 187 // This method defines the destination of G4cout/G4cerr stream. 187 // For usual cases, this method will be in 188 // For usual cases, this method will be invoked by a concrete 188 // (G)UI session class object and thus the 189 // (G)UI session class object and thus the user needs not to invoke this 189 void SetCoutDestination(G4UIsession* const 190 void SetCoutDestination(G4UIsession* const value); 190 191 191 inline void SetVerboseLevel(G4int val) { v 192 inline void SetVerboseLevel(G4int val) { verboseLevel = val; } 192 inline G4int GetVerboseLevel() const { ret 193 inline G4int GetVerboseLevel() const { return verboseLevel; } 193 inline G4int GetNumberOfHistory() const { 194 inline G4int GetNumberOfHistory() const { return G4int(histVec.size()); } 194 inline G4String GetPreviousCommand(G4int i 195 inline G4String GetPreviousCommand(G4int i) const 195 { 196 { 196 G4String st; 197 G4String st; 197 if (i >= 0 && i < G4int(histVec.size())) 198 if (i >= 0 && i < G4int(histVec.size())) { 198 st = histVec[i]; 199 st = histVec[i]; 199 } 200 } 200 return st; 201 return st; 201 } 202 } 202 inline void SetMaxHistSize(G4int mx) { max 203 inline void SetMaxHistSize(G4int mx) { maxHistSize = mx; } 203 inline G4int GetMaxHistSize() const { retu 204 inline G4int GetMaxHistSize() const { return maxHistSize; } 204 205 205 inline void SetMacroSearchPath(const G4Str 206 inline void SetMacroSearchPath(const G4String& path) { searchPath = path; } 206 inline const G4String& GetMacroSearchPath( 207 inline const G4String& GetMacroSearchPath() const { return searchPath; } 207 void ParseMacroSearchPath(); 208 void ParseMacroSearchPath(); 208 G4String FindMacroPath(const G4String& fna 209 G4String FindMacroPath(const G4String& fname) const; 209 210 210 inline void SetMasterUIManager(G4bool val) 211 inline void SetMasterUIManager(G4bool val) 211 { 212 { 212 isMaster = val; 213 isMaster = val; 213 stackCommandsForBroadcast = val; 214 stackCommandsForBroadcast = val; 214 if (val && (bridges == nullptr)) { 215 if (val && (bridges == nullptr)) { 215 bridges = new std::vector<G4UIbridge*> 216 bridges = new std::vector<G4UIbridge*>; 216 fMasterUImanager() = this; 217 fMasterUImanager() = this; 217 } 218 } 218 } 219 } 219 inline void SetIgnoreCmdNotFound(G4bool va 220 inline void SetIgnoreCmdNotFound(G4bool val) { ignoreCmdNotFound = val; } 220 221 221 std::vector<G4String>* GetCommandStack(); 222 std::vector<G4String>* GetCommandStack(); 222 void RegisterBridge(G4UIbridge* brg); 223 void RegisterBridge(G4UIbridge* brg); 223 224 224 // Setups as above but for a non-worker th 225 // Setups as above but for a non-worker thread (e.g. vis) 225 void SetUpForAThread(G4int tId); 226 void SetUpForAThread(G4int tId); 226 227 227 void SetUpForSpecialThread(const G4String& 228 void SetUpForSpecialThread(const G4String& aPrefix); 228 229 229 inline G4int GetThreadID() const { return 230 inline G4int GetThreadID() const { return threadID; } 230 231 231 void SetCoutFileName(const G4String& fileN 232 void SetCoutFileName(const G4String& fileN = "G4cout.txt", G4bool ifAppend = true); 232 void SetCerrFileName(const G4String& fileN 233 void SetCerrFileName(const G4String& fileN = "G4cerr.txt", G4bool ifAppend = true); 233 void SetThreadPrefixString(const G4String& 234 void SetThreadPrefixString(const G4String& prefix = "W"); 234 void SetThreadUseBuffer(G4bool flg = true) 235 void SetThreadUseBuffer(G4bool flg = true); 235 void SetThreadIgnore(G4int tid = 0); 236 void SetThreadIgnore(G4int tid = 0); 236 void SetThreadIgnoreInit(G4bool flg = true 237 void SetThreadIgnoreInit(G4bool flg = true); 237 inline G4MTcoutDestination* GetThreadCout( 238 inline G4MTcoutDestination* GetThreadCout() { return threadCout; } 238 239 239 static void UseDoublePrecisionStr(G4bool v 240 static void UseDoublePrecisionStr(G4bool val); 240 static G4bool DoublePrecisionStr(); 241 static G4bool DoublePrecisionStr(); 241 242 242 inline G4int GetLastReturnCode() const { r 243 inline G4int GetLastReturnCode() const { return lastRC; } 243 244 244 inline bool IsLastCommandOutputTreated() { 245 inline bool IsLastCommandOutputTreated() { return fLastCommandOutputTreated; } 245 inline void SetLastCommandOutputTreated() 246 inline void SetLastCommandOutputTreated() { fLastCommandOutputTreated = true; } 246 247 247 protected: 248 protected: 248 G4UImanager(); 249 G4UImanager(); 249 250 250 private: 251 private: 251 void AddWorkerCommand(G4UIcommand* newComm 252 void AddWorkerCommand(G4UIcommand* newCommand); 252 void RemoveWorkerCommand(G4UIcommand* aCom 253 void RemoveWorkerCommand(G4UIcommand* aCommand); 253 254 254 void PauseSession(const char* msg); 255 void PauseSession(const char* msg); 255 void CreateMessenger(); 256 void CreateMessenger(); 256 G4UIcommandTree* FindDirectory(const char* 257 G4UIcommandTree* FindDirectory(const char* dirName); 257 258 258 private: 259 private: 259 G4ICOMS_DLL static G4UImanager*& fUImanage 260 G4ICOMS_DLL static G4UImanager*& fUImanager(); // thread-local 260 G4ICOMS_DLL static G4bool& fUImanagerHasBe 261 G4ICOMS_DLL static G4bool& fUImanagerHasBeenKilled(); // thread-local 261 G4ICOMS_DLL static G4UImanager*& fMasterUI 262 G4ICOMS_DLL static G4UImanager*& fMasterUImanager(); 262 G4UIcommandTree* treeTop = nullptr; 263 G4UIcommandTree* treeTop = nullptr; 263 G4UIsession* session = nullptr; 264 G4UIsession* session = nullptr; 264 G4UIsession* g4UIWindow = nullptr; 265 G4UIsession* g4UIWindow = nullptr; 265 G4UIcontrolMessenger* UImessenger = nullpt 266 G4UIcontrolMessenger* UImessenger = nullptr; 266 G4UnitsMessenger* UnitsMessenger = nullptr 267 G4UnitsMessenger* UnitsMessenger = nullptr; 267 G4LocalThreadCoutMessenger* CoutMessenger 268 G4LocalThreadCoutMessenger* CoutMessenger = nullptr; >> 269 G4ProfilerMessenger* ProfileMessenger = nullptr; 268 G4String savedParameters; 270 G4String savedParameters; 269 G4UIcommand* savedCommand = nullptr; 271 G4UIcommand* savedCommand = nullptr; 270 G4int verboseLevel = 0; 272 G4int verboseLevel = 0; 271 std::ofstream historyFile; 273 std::ofstream historyFile; 272 G4bool saveHistory = false; 274 G4bool saveHistory = false; 273 std::vector<G4String> histVec; 275 std::vector<G4String> histVec; 274 G4UIaliasList* aliasList = nullptr; 276 G4UIaliasList* aliasList = nullptr; 275 G4int maxHistSize = 20; 277 G4int maxHistSize = 20; 276 G4bool pauseAtBeginOfEvent = false; 278 G4bool pauseAtBeginOfEvent = false; 277 G4bool pauseAtEndOfEvent = false; 279 G4bool pauseAtEndOfEvent = false; 278 G4String searchPath = ""; 280 G4String searchPath = ""; 279 std::vector<G4String> searchDirs; 281 std::vector<G4String> searchDirs; 280 282 281 G4bool isMaster = false; 283 G4bool isMaster = false; 282 std::vector<G4UIbridge*>* bridges = nullpt 284 std::vector<G4UIbridge*>* bridges = nullptr; 283 G4bool ignoreCmdNotFound = false; 285 G4bool ignoreCmdNotFound = false; 284 G4bool stackCommandsForBroadcast = false; 286 G4bool stackCommandsForBroadcast = false; 285 std::vector<G4String>* commandStack = null 287 std::vector<G4String>* commandStack = nullptr; 286 288 287 G4int threadID = -1; 289 G4int threadID = -1; 288 G4MTcoutDestination* threadCout = nullptr; 290 G4MTcoutDestination* threadCout = nullptr; 289 G4ICOMS_DLL static G4int igThreadID; 291 G4ICOMS_DLL static G4int igThreadID; 290 292 291 G4ICOMS_DLL static G4bool doublePrecisionS 293 G4ICOMS_DLL static G4bool doublePrecisionStr; 292 294 293 G4int lastRC = 0; 295 G4int lastRC = 0; 294 296 295 G4bool fLastCommandOutputTreated = true; 297 G4bool fLastCommandOutputTreated = true; 296 }; 298 }; 297 299 298 #endif 300 #endif 299 301