Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:16

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