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 << 27 // 26 // 28 // Class description: << 27 // $Id: G4UImanager.hh,v 1.21 2006/06/29 19:08:17 gunter Exp $ >> 28 // GEANT4 tag $Name: geant4-08-01-patch-01 $ 29 // 29 // 30 // This is a singleton class which controls th << 31 // and the user interface(s) << 32 30 33 // Author: Makoto Asai, 1997 << 31 #ifndef G4UImanager_h 34 // ------------------------------------------- << 32 #define G4UImanager_h 1 35 #ifndef G4UImanager_hh << 36 #define G4UImanager_hh 1 << 37 33 38 #include "G4UIcommandStatus.hh" << 39 #include "G4VStateDependent.hh" << 40 #include "globals.hh" 34 #include "globals.hh" 41 35 42 #include "icomsdefs.hh" << 43 << 44 #include <fstream> << 45 #include <vector> 36 #include <vector> 46 << 37 #include <fstream> >> 38 #include "G4VStateDependent.hh" >> 39 #include "G4UIcommandStatus.hh" 47 class G4UIcommandTree; 40 class G4UIcommandTree; 48 class G4UIcommand; 41 class G4UIcommand; 49 class G4UIsession; 42 class G4UIsession; 50 class G4UIcontrolMessenger; 43 class G4UIcontrolMessenger; 51 class G4UnitsMessenger; 44 class G4UnitsMessenger; 52 class G4LocalThreadCoutMessenger; << 53 class G4UIaliasList; 45 class G4UIaliasList; 54 class G4MTcoutDestination; << 46 55 class G4UIbridge; << 47 // class description: >> 48 // >> 49 // This is a singlton class which controls the command manipulation >> 50 // and the user interface(s). The constructor of this class MUST NOT >> 51 // invoked by the user. >> 52 // 56 53 57 class G4UImanager : public G4VStateDependent 54 class G4UImanager : public G4VStateDependent 58 { 55 { 59 public: << 56 public: // with description 60 // A static method to get the pointer to t << 57 static G4UImanager * GetUIpointer(); 61 // of this class << 58 // A static method to get the pointer to the only existing object 62 static G4UImanager* GetUIpointer(); << 59 // of this class. 63 static G4UImanager* GetMasterUIpointer(); << 64 << 65 ~G4UImanager() override; << 66 << 67 G4UImanager(const G4UImanager&) = delete; << 68 const G4UImanager& operator=(const G4UIman << 69 G4bool operator==(const G4UImanager&) cons << 70 G4bool operator!=(const G4UImanager&) cons << 71 << 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 << 77 << 78 // This method register a new command << 79 void AddNewCommand(G4UIcommand* newCommand << 80 << 81 // This command removes the registered com << 82 // command, that particular command cannot << 83 void RemoveCommand(G4UIcommand* aCommand); << 84 << 85 // A macro file defined by the argument wi << 86 void ExecuteMacroFile(const char* fileName << 87 << 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); << 105 G4int ApplyCommand(const G4String& aComman << 106 << 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 << 112 G4UIcommand* FindCommand(const G4String& a << 113 << 114 // The executed commands will be stored in << 115 // "historySwitch" is false, saving will b << 116 void StoreHistory(const char* fileName = " << 117 void StoreHistory(G4bool historySwitch, co << 118 << 119 // All commands registered under the given << 120 // standard output << 121 void ListCommands(const char* direc); << 122 << 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 << 128 // Remove the defined alias << 129 void RemoveAlias(const char* aliasName); << 130 << 131 // Print all aliases << 132 void ListAlias(); << 133 << 134 // Convert a command string which contains << 135 G4String SolveAlias(const char* aCmd); << 136 << 137 // Generate HTML files for defined UI comm << 138 void CreateHTML(const char* dir = "/"); << 139 << 140 // These methods are used by G4UIcontrolMe << 141 // and Foreach() methods << 142 void LoopS(const char* valueList); << 143 void ForeachS(const char* valueList); << 144 << 145 // This method is exclusively invoked by G << 146 G4bool Notify(G4ApplicationState requested << 147 << 148 // These six methods return the current va << 149 // given command. For the first three meth << 150 // the parameter (1 is the first parameter << 151 // other three methods can give the parame << 152 // If "reGet" is true, actual request of r << 153 // will be sent to the corresponding messe << 154 // the value stored in G4Umanager will be << 155 // for the sequential invokation for the s << 156 G4String GetCurrentStringValue(const char* << 157 G4bool reGe << 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 << 166 << 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 << 172 inline G4bool GetPauseAtBeginOfEvent() con << 173 inline void SetPauseAtEndOfEvent(G4bool vl << 174 inline G4bool GetPauseAtEndOfEvent() const << 175 << 176 inline G4UIcommandTree* GetTree() const { << 177 inline G4UIsession* GetSession() const { r << 178 inline G4UIsession* GetG4UIWindow() const << 179 // Find base session in a hierarchy of ses << 180 G4UIsession* GetBaseSession() const; << 181 << 182 // These methods define the active (G)UI s << 183 inline void SetSession(G4UIsession* const << 184 inline void SetG4UIWindow(G4UIsession* con << 185 << 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 << 190 << 191 inline void SetVerboseLevel(G4int val) { v << 192 inline G4int GetVerboseLevel() const { ret << 193 inline G4int GetNumberOfHistory() const { << 194 inline G4String GetPreviousCommand(G4int i << 195 { << 196 G4String st; << 197 if (i >= 0 && i < G4int(histVec.size())) << 198 st = histVec[i]; << 199 } << 200 return st; << 201 } << 202 inline void SetMaxHistSize(G4int mx) { max << 203 inline G4int GetMaxHistSize() const { retu << 204 << 205 inline void SetMacroSearchPath(const G4Str << 206 inline const G4String& GetMacroSearchPath( << 207 void ParseMacroSearchPath(); << 208 G4String FindMacroPath(const G4String& fna << 209 << 210 inline void SetMasterUIManager(G4bool val) << 211 { << 212 isMaster = val; << 213 stackCommandsForBroadcast = val; << 214 if (val && (bridges == nullptr)) { << 215 bridges = new std::vector<G4UIbridge*> << 216 fMasterUImanager() = this; << 217 } << 218 } << 219 inline void SetIgnoreCmdNotFound(G4bool va << 220 << 221 std::vector<G4String>* GetCommandStack(); << 222 void RegisterBridge(G4UIbridge* brg); << 223 << 224 // Setups as above but for a non-worker th << 225 void SetUpForAThread(G4int tId); << 226 << 227 void SetUpForSpecialThread(const G4String& << 228 << 229 inline G4int GetThreadID() const { return << 230 << 231 void SetCoutFileName(const G4String& fileN << 232 void SetCerrFileName(const G4String& fileN << 233 void SetThreadPrefixString(const G4String& << 234 void SetThreadUseBuffer(G4bool flg = true) << 235 void SetThreadIgnore(G4int tid = 0); << 236 void SetThreadIgnoreInit(G4bool flg = true << 237 inline G4MTcoutDestination* GetThreadCout( << 238 << 239 static void UseDoublePrecisionStr(G4bool v << 240 static G4bool DoublePrecisionStr(); << 241 << 242 inline G4int GetLastReturnCode() const { r << 243 << 244 inline bool IsLastCommandOutputTreated() { << 245 inline void SetLastCommandOutputTreated() << 246 60 247 protected: 61 protected: 248 G4UImanager(); << 62 G4UImanager(); 249 << 63 public: >> 64 ~G4UImanager(); 250 private: 65 private: 251 void AddWorkerCommand(G4UIcommand* newComm << 66 G4UImanager(const G4UImanager &right); 252 void RemoveWorkerCommand(G4UIcommand* aCom << 67 const G4UImanager & operator=(const G4UImanager &right); 253 << 68 G4int operator==(const G4UImanager &right) const; 254 void PauseSession(const char* msg); << 69 G4int operator!=(const G4UImanager &right) const; 255 void CreateMessenger(); << 70 256 G4UIcommandTree* FindDirectory(const char* << 71 public: // with description >> 72 G4String GetCurrentValues(const char * aCommand); >> 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 void AddNewCommand(G4UIcommand * newCommand); >> 78 // This method register a new command. >> 79 void RemoveCommand(G4UIcommand * aCommand); >> 80 // This command remove the registered command. After invokation of this >> 81 // command, that particular command cannot be applied. >> 82 void ExecuteMacroFile(const char * fileName); >> 83 // A macro file defined by the argument will be read by G4UIbatch object. >> 84 void Loop(const char * macroFile,const char * variableName, >> 85 G4double initialValue,G4double finalValue,G4double stepSize=1.0); >> 86 // Execute a macro file more than once with a loop counter. >> 87 void Foreach(const char * macroFile,const char * variableName, >> 88 const char * candidates); >> 89 // Execute a macro file more than once with an aliased variable which takes >> 90 // a value in the candidate list. >> 91 G4int ApplyCommand(const char * aCommand); >> 92 G4int ApplyCommand(G4String aCommand); >> 93 // A command (and parameter(s)) given >> 94 // by the method's argument will be applied. Zero will be returned in >> 95 // case the command is successfully executed. Positive non-zero value >> 96 // will be returned if the command couldn't be executed. The meaning of >> 97 // this non-zero value is the following. >> 98 // The returned number : xyy >> 99 // x00 : G4CommandStatus.hh enumeration >> 100 // yy : the problematic parameter (first found) >> 101 void StoreHistory(const char* fileName = "G4history.macro"); >> 102 void StoreHistory(G4bool historySwitch, >> 103 const char* fileName = "G4history.macro"); >> 104 // The executed commands will be stored in the defined file. If >> 105 // "historySwitch" is false, saving will be suspended. >> 106 void ListCommands(const char* direc); >> 107 // All commands registored under the given directory will be listed to >> 108 // G4cout. >> 109 void SetAlias(const char * aliasLine); >> 110 // Define an alias. The first word of "aliasLine" string is the >> 111 // alias name and the remaining word(s) is(are) string value >> 112 // to be aliased. >> 113 void RemoveAlias(const char * aliasName); >> 114 // Remove the defined alias. >> 115 void ListAlias(); >> 116 // Print all aliases. >> 117 G4String SolveAlias(const char* aCmd); >> 118 // Convert a command string which contains alias(es). >> 119 void CreateHTML(const char* dir = "/"); >> 120 // Generate HTML files for defined UI commands >> 121 >> 122 >> 123 public: >> 124 void LoopS(const char* valueList); >> 125 void ForeachS(const char* valueList); >> 126 // These methods are used by G4UIcontrolMessenger to use Loop() and Foreach() methods. >> 127 virtual G4bool Notify(G4ApplicationState requestedState); >> 128 // This method is exclusively invoked by G4StateManager and the user >> 129 // must not use this method. >> 130 >> 131 private: >> 132 void PauseSession(const char* msg); >> 133 void CreateMessenger(); >> 134 G4UIcommandTree* FindDirectory(const char* dirName); >> 135 >> 136 //public: >> 137 // following three methods will be removed quite soon. >> 138 // void Interact(); >> 139 // void Interact(const char * promptCharacters); 257 140 258 private: 141 private: 259 G4ICOMS_DLL static G4UImanager*& fUImanage << 142 static G4UImanager * fUImanager; 260 G4ICOMS_DLL static G4bool& fUImanagerHasBe << 143 static G4bool fUImanagerHasBeenKilled; 261 G4ICOMS_DLL static G4UImanager*& fMasterUI << 144 G4UIcommandTree * treeTop; 262 G4UIcommandTree* treeTop = nullptr; << 145 G4UIsession * session; 263 G4UIsession* session = nullptr; << 146 G4UIcontrolMessenger * UImessenger; 264 G4UIsession* g4UIWindow = nullptr; << 147 G4UnitsMessenger * UnitsMessenger; 265 G4UIcontrolMessenger* UImessenger = nullpt << 148 G4String savedParameters; 266 G4UnitsMessenger* UnitsMessenger = nullptr << 149 G4UIcommand * savedCommand; 267 G4LocalThreadCoutMessenger* CoutMessenger << 150 G4int verboseLevel; 268 G4String savedParameters; << 151 std::ofstream historyFile; 269 G4UIcommand* savedCommand = nullptr; << 152 G4bool saveHistory; 270 G4int verboseLevel = 0; << 153 std::vector<G4String> histVec; 271 std::ofstream historyFile; << 154 G4UIaliasList* aliasList; 272 G4bool saveHistory = false; << 155 G4int maxHistSize; 273 std::vector<G4String> histVec; << 156 G4bool pauseAtBeginOfEvent; 274 G4UIaliasList* aliasList = nullptr; << 157 G4bool pauseAtEndOfEvent; 275 G4int maxHistSize = 20; << 158 276 G4bool pauseAtBeginOfEvent = false; << 159 277 G4bool pauseAtEndOfEvent = false; << 160 public: // with description 278 G4String searchPath = ""; << 161 G4String GetCurrentStringValue(const char * aCommand, 279 std::vector<G4String> searchDirs; << 162 G4int parameterNumber=1, G4bool reGet=true); 280 << 163 G4int GetCurrentIntValue(const char * aCommand, 281 G4bool isMaster = false; << 164 G4int parameterNumber=1, G4bool reGet=true); 282 std::vector<G4UIbridge*>* bridges = nullpt << 165 G4double GetCurrentDoubleValue(const char * aCommand, 283 G4bool ignoreCmdNotFound = false; << 166 G4int parameterNumber=1, G4bool reGet=true); 284 G4bool stackCommandsForBroadcast = false; << 167 G4String GetCurrentStringValue(const char * aCommand, 285 std::vector<G4String>* commandStack = null << 168 const char * aParameterName, G4bool reGet=true); 286 << 169 G4int GetCurrentIntValue(const char * aCommand, 287 G4int threadID = -1; << 170 const char * aParameterName, G4bool reGet=true); 288 G4MTcoutDestination* threadCout = nullptr; << 171 G4double GetCurrentDoubleValue(const char * aCommand, 289 G4ICOMS_DLL static G4int igThreadID; << 172 const char * aParameterName, G4bool reGet=true); >> 173 // These six methods returns the current value of a parameter of the >> 174 // given command. For the first three methods, the ordering number of >> 175 // the parameter (1 is the first parameter) can be given, whereas, >> 176 // other three methods can give the parameter name. >> 177 // If "reGet" is true, actual request of returning the current value >> 178 // will be sent to the corresponding messenger, while, if it is false, >> 179 // the value stored in G4Umanager will be used. The later case is valid >> 180 // for the sequential invokation for the same command. >> 181 >> 182 inline void SetPauseAtBeginOfEvent(G4bool vl) >> 183 { pauseAtBeginOfEvent = vl; } >> 184 inline G4bool GetPauseAtBeginOfEvent() const >> 185 { return pauseAtBeginOfEvent; } >> 186 inline void SetPauseAtEndOfEvent(G4bool vl) >> 187 { pauseAtEndOfEvent = vl; } >> 188 inline G4bool GetPauseAtEndOfEvent() const >> 189 { return pauseAtEndOfEvent; } >> 190 // If the boolean flags are true, Pause() method of G4StateManager is invoked >> 191 // at the very begining (before generating a G4Event object) or at the end of >> 192 // each event. So that, in case a (G)UI session is defined, the user can interact. 290 193 291 G4ICOMS_DLL static G4bool doublePrecisionS << 292 194 293 G4int lastRC = 0; << 195 public: >> 196 inline G4UIcommandTree * GetTree() const >> 197 { return treeTop; } >> 198 inline G4UIsession * GetSession() const >> 199 { return session; } >> 200 public: // with description >> 201 inline void SetSession(G4UIsession *const value) >> 202 { session = value; } >> 203 // This method defines the active (G)UI session. >> 204 void SetCoutDestination(G4UIsession *const value); >> 205 // This method defines the destination of G4cout/G4cerr stream. >> 206 // For usual cases, this method will be invoked by a concrete >> 207 // (G)UI session class object and thus the user needs not to invoke >> 208 // this method by him(her)self. >> 209 >> 210 public: >> 211 inline void SetVerboseLevel(G4int val) >> 212 { verboseLevel = val; } >> 213 inline G4int GetVerboseLevel() const >> 214 { return verboseLevel; } >> 215 inline G4int GetNumberOfHistory() const >> 216 { return histVec.size(); } >> 217 inline G4String GetPreviousCommand(G4int i) const >> 218 { >> 219 G4String st; >> 220 if(i>=0 && i<G4int(histVec.size())) >> 221 { st = histVec[i]; } >> 222 return st; >> 223 } >> 224 inline void SetMaxHistSize(G4int mx) >> 225 { maxHistSize = mx; } >> 226 inline G4int GetMaxHistSize() const >> 227 { return maxHistSize; } >> 228 >> 229 // Old methods kept for backward compatibility >> 230 // inline G4UIcommandTree * GetTree() const >> 231 // { return treeTop; }; >> 232 // inline G4UIsession * GetSession() const >> 233 // { return session; }; >> 234 // inline void SetSession(G4UIsession *const value) >> 235 // { session = value; }; 294 236 295 G4bool fLastCommandOutputTreated = true; << 296 }; 237 }; 297 238 298 #endif 239 #endif >> 240 299 241