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