Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:21:24

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // G4UImanager
0027 //
0028 // Class description:
0029 //
0030 // This is a singleton class which controls the command manipulation
0031 // and the user interface(s)
0032 
0033 // Author: Makoto Asai, 1997
0034 // --------------------------------------------------------------------
0035 #ifndef G4UImanager_hh
0036 #define G4UImanager_hh 1
0037 
0038 #include "G4UIcommandStatus.hh"
0039 #include "G4VStateDependent.hh"
0040 #include "globals.hh"
0041 
0042 #include "icomsdefs.hh"
0043 
0044 #include <fstream>
0045 #include <vector>
0046 
0047 class G4UIcommandTree;
0048 class G4UIcommand;
0049 class G4UIsession;
0050 class G4UIcontrolMessenger;
0051 class G4UnitsMessenger;
0052 class G4LocalThreadCoutMessenger;
0053 class G4UIaliasList;
0054 class G4MTcoutDestination;
0055 class G4UIbridge;
0056 
0057 class G4UImanager : public G4VStateDependent
0058 {
0059   public:
0060     // A static method to get the pointer to the only existing object
0061     // of this class
0062     static G4UImanager* GetUIpointer();
0063     static G4UImanager* GetMasterUIpointer();
0064 
0065     ~G4UImanager() override;
0066 
0067     G4UImanager(const G4UImanager&) = delete;
0068     const G4UImanager& operator=(const G4UImanager&) = delete;
0069     G4bool operator==(const G4UImanager&) const = delete;
0070     G4bool operator!=(const G4UImanager&) const = delete;
0071 
0072     // This method returns a string which represents the current value(s)
0073     // of the parameter(s) of the specified command. Null string will be
0074     // returned if the given command is not defined or the command does
0075     // not support the GetCurrentValues() method
0076     G4String GetCurrentValues(const char* aCommand);
0077 
0078     // This method register a new command
0079     void AddNewCommand(G4UIcommand* newCommand);
0080 
0081     // This command removes the registered command. After invokation of this
0082     // command, that particular command cannot be applied
0083     void RemoveCommand(G4UIcommand* aCommand);
0084 
0085     // A macro file defined by the argument will be read by G4UIbatch object
0086     void ExecuteMacroFile(const char* fileName);
0087 
0088     // Execute a macro file more than once with a loop counter
0089     void Loop(const char* macroFile, const char* variableName, G4double initialValue,
0090               G4double finalValue, G4double stepSize = 1.0);
0091 
0092     // Execute a macro file more than once with an aliased variable which
0093     // takes a value in the candidate list
0094     void Foreach(const char* macroFile, const char* variableName, const char* candidates);
0095 
0096     // A command (and parameter(s)) given
0097     // by the method's argument will be applied. Zero will be returned in
0098     // case the command is successfully executed. Positive non-zero value
0099     // will be returned if the command cannot be executed. The meaning of
0100     // this non-zero value is the following:
0101     //   The returned number : xyy
0102     //        x00 : G4CommandStatus.hh enumeration
0103     //         yy : the problematic parameter (first found)
0104     G4int ApplyCommand(const char* aCommand);
0105     G4int ApplyCommand(const G4String& aCommand);
0106 
0107     // Find the G4UIcommand object. Null pointer is returned if command
0108     // is not found.
0109     // Please note that each thread returns different objects if this
0110     // method is used in multi-threaded mode.
0111     G4UIcommand* FindCommand(const char* aCommand);
0112     G4UIcommand* FindCommand(const G4String& aCommand);
0113 
0114     // The executed commands will be stored in the defined file. If
0115     // "historySwitch" is false, saving will be suspended
0116     void StoreHistory(const char* fileName = "G4history.macro");
0117     void StoreHistory(G4bool historySwitch, const char* fileName = "G4history.macro");
0118 
0119     // All commands registered under the given directory will be listed to
0120     // standard output
0121     void ListCommands(const char* direc);
0122 
0123     // Define an alias. The first word of "aliasLine" string is the
0124     // alias name and the remaining word(s) is(are) string value
0125     // to be aliased
0126     void SetAlias(const char* aliasLine);
0127 
0128     // Remove the defined alias
0129     void RemoveAlias(const char* aliasName);
0130 
0131     // Print all aliases
0132     void ListAlias();
0133 
0134     // Convert a command string which contains alias(es)
0135     G4String SolveAlias(const char* aCmd);
0136 
0137     // Generate HTML files for defined UI commands
0138     void CreateHTML(const char* dir = "/");
0139 
0140     // These methods are used by G4UIcontrolMessenger to use Loop()
0141     // and Foreach() methods
0142     void LoopS(const char* valueList);
0143     void ForeachS(const char* valueList);
0144 
0145     // This method is exclusively invoked by G4StateManager
0146     G4bool Notify(G4ApplicationState requestedState) override;
0147 
0148     // These six methods return the current value of a parameter of the
0149     // given command. For the first three methods, the ordering number of
0150     // the parameter (1 is the first parameter) can be given, whereas,
0151     // other three methods can give the parameter name.
0152     // If "reGet" is true, actual request of returning the current value
0153     // will be sent to the corresponding messenger, while, if it is false,
0154     // the value stored in G4Umanager will be used. The later case is valid
0155     // for the sequential invokation for the same command
0156     G4String GetCurrentStringValue(const char* aCommand, G4int parameterNumber = 1,
0157                                    G4bool reGet = true);
0158     G4int GetCurrentIntValue(const char* aCommand, G4int parameterNumber = 1, G4bool reGet = true);
0159     G4double GetCurrentDoubleValue(const char* aCommand, G4int parameterNumber = 1,
0160                                    G4bool reGet = true);
0161     G4String GetCurrentStringValue(const char* aCommand, const char* aParameterName,
0162                                    G4bool reGet = true);
0163     G4int GetCurrentIntValue(const char* aCommand, const char* aParameterName, G4bool reGet = true);
0164     G4double GetCurrentDoubleValue(const char* aCommand, const char* aParameterName,
0165                                    G4bool reGet = true);
0166 
0167     // If the Boolean flags are true, Pause() method of G4StateManager is
0168     // invoked at the very beginning (before generating a G4Event object)
0169     // or at the end of each event. So that, in case a (G)UI session is
0170     // defined, the user can interact
0171     inline void SetPauseAtBeginOfEvent(G4bool vl) { pauseAtBeginOfEvent = vl; }
0172     inline G4bool GetPauseAtBeginOfEvent() const { return pauseAtBeginOfEvent; }
0173     inline void SetPauseAtEndOfEvent(G4bool vl) { pauseAtEndOfEvent = vl; }
0174     inline G4bool GetPauseAtEndOfEvent() const { return pauseAtEndOfEvent; }
0175 
0176     inline G4UIcommandTree* GetTree() const { return treeTop; }
0177     inline G4UIsession* GetSession() const { return session; }
0178     inline G4UIsession* GetG4UIWindow() const { return g4UIWindow; }
0179     // Find base session in a hierarchy of sessions
0180     G4UIsession* GetBaseSession() const;
0181 
0182     // These methods define the active (G)UI session
0183     inline void SetSession(G4UIsession* const value) { session = value; }
0184     inline void SetG4UIWindow(G4UIsession* const value) { g4UIWindow = value; }
0185 
0186     // This method defines the destination of G4cout/G4cerr stream.
0187     // For usual cases, this method will be invoked by a concrete
0188     // (G)UI session class object and thus the user needs not to invoke this
0189     void SetCoutDestination(G4UIsession* const value);
0190 
0191     inline void SetVerboseLevel(G4int val) { verboseLevel = val; }
0192     inline G4int GetVerboseLevel() const { return verboseLevel; }
0193     inline G4int GetNumberOfHistory() const { return G4int(histVec.size()); }
0194     inline G4String GetPreviousCommand(G4int i) const
0195     {
0196       G4String st;
0197       if (i >= 0 && i < G4int(histVec.size())) {
0198         st = histVec[i];
0199       }
0200       return st;
0201     }
0202     inline void SetMaxHistSize(G4int mx) { maxHistSize = mx; }
0203     inline G4int GetMaxHistSize() const { return maxHistSize; }
0204 
0205     inline void SetMacroSearchPath(const G4String& path) { searchPath = path; }
0206     inline const G4String& GetMacroSearchPath() const { return searchPath; }
0207     void ParseMacroSearchPath();
0208     G4String FindMacroPath(const G4String& fname) const;
0209 
0210     inline void SetMasterUIManager(G4bool val)
0211     {
0212       isMaster = val;
0213       stackCommandsForBroadcast = val;
0214       if (val && (bridges == nullptr)) {
0215         bridges = new std::vector<G4UIbridge*>;
0216         fMasterUImanager() = this;
0217       }
0218     }
0219     inline void SetIgnoreCmdNotFound(G4bool val) { ignoreCmdNotFound = val; }
0220 
0221     std::vector<G4String>* GetCommandStack();
0222     void RegisterBridge(G4UIbridge* brg);
0223 
0224     // Setups as above but for a non-worker thread (e.g. vis)
0225     void SetUpForAThread(G4int tId);
0226 
0227     void SetUpForSpecialThread(const G4String& aPrefix);
0228 
0229     inline G4int GetThreadID() const { return threadID; }
0230 
0231     void SetCoutFileName(const G4String& fileN = "G4cout.txt", G4bool ifAppend = true);
0232     void SetCerrFileName(const G4String& fileN = "G4cerr.txt", G4bool ifAppend = true);
0233     void SetThreadPrefixString(const G4String& prefix = "W");
0234     void SetThreadUseBuffer(G4bool flg = true);
0235     void SetThreadIgnore(G4int tid = 0);
0236     void SetThreadIgnoreInit(G4bool flg = true);
0237     inline G4MTcoutDestination* GetThreadCout() { return threadCout; }
0238 
0239     static void UseDoublePrecisionStr(G4bool val);
0240     static G4bool DoublePrecisionStr();
0241 
0242     inline G4int GetLastReturnCode() const { return lastRC; }
0243 
0244     inline bool IsLastCommandOutputTreated() { return fLastCommandOutputTreated; }
0245     inline void SetLastCommandOutputTreated() { fLastCommandOutputTreated = true; }
0246 
0247   protected:
0248     G4UImanager();
0249 
0250   private:
0251     void AddWorkerCommand(G4UIcommand* newCommand);
0252     void RemoveWorkerCommand(G4UIcommand* aCommand);
0253 
0254     void PauseSession(const char* msg);
0255     void CreateMessenger();
0256     G4UIcommandTree* FindDirectory(const char* dirName);
0257 
0258   private:
0259     G4ICOMS_DLL static G4UImanager*& fUImanager();  // thread-local
0260     G4ICOMS_DLL static G4bool& fUImanagerHasBeenKilled();  // thread-local
0261     G4ICOMS_DLL static G4UImanager*& fMasterUImanager();
0262     G4UIcommandTree* treeTop = nullptr;
0263     G4UIsession* session = nullptr;
0264     G4UIsession* g4UIWindow = nullptr;
0265     G4UIcontrolMessenger* UImessenger = nullptr;
0266     G4UnitsMessenger* UnitsMessenger = nullptr;
0267     G4LocalThreadCoutMessenger* CoutMessenger = nullptr;
0268     G4String savedParameters;
0269     G4UIcommand* savedCommand = nullptr;
0270     G4int verboseLevel = 0;
0271     std::ofstream historyFile;
0272     G4bool saveHistory = false;
0273     std::vector<G4String> histVec;
0274     G4UIaliasList* aliasList = nullptr;
0275     G4int maxHistSize = 20;
0276     G4bool pauseAtBeginOfEvent = false;
0277     G4bool pauseAtEndOfEvent = false;
0278     G4String searchPath = "";
0279     std::vector<G4String> searchDirs;
0280 
0281     G4bool isMaster = false;
0282     std::vector<G4UIbridge*>* bridges = nullptr;
0283     G4bool ignoreCmdNotFound = false;
0284     G4bool stackCommandsForBroadcast = false;
0285     std::vector<G4String>* commandStack = nullptr;
0286 
0287     G4int threadID = -1;
0288     G4MTcoutDestination* threadCout = nullptr;
0289     G4ICOMS_DLL static G4int igThreadID;
0290 
0291     G4ICOMS_DLL static G4bool doublePrecisionStr;
0292 
0293     G4int lastRC = 0;
0294 
0295     G4bool fLastCommandOutputTreated = true;
0296 };
0297 
0298 #endif