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