Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:15:54

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 // G4UIcommand
0027 //
0028 // Class description:
0029 //
0030 // This G4UIcommand is the "concrete" base class which represents a command
0031 // used by Geant4 (G)UI. The user can use this class in case the parameter
0032 // arguments of a command are not suitable with respect to the derived command
0033 // classes.
0034 // Some methods defined in this base class are used by the derived classes
0035 
0036 // Author: Makoto Asai (SLAC), 1998
0037 // --------------------------------------------------------------------
0038 #ifndef G4UIcommand_hh
0039 #define G4UIcommand_hh 1
0040 
0041 #include "G4ApplicationState.hh"
0042 #include "G4ThreeVector.hh"
0043 #include "G4UIparameter.hh"
0044 #include "globals.hh"
0045 
0046 #include <vector>
0047 
0048 class G4UImessenger;
0049 
0050 class G4UIcommand
0051 {
0052   public:
0053     // Dummy default constructor
0054     G4UIcommand() = default;
0055 
0056     // Constructor. The command string with full path directory
0057     // and the pointer to the messenger must be given.
0058     // If tBB is set to false, this command won't be sent to worker threads.
0059     // This tBB parameter could be changed with SetToBeBroadcasted() method
0060     // except for G4UIdirectory
0061     G4UIcommand(const char* theCommandPath, G4UImessenger* theMessenger, G4bool tBB = true);
0062 
0063     virtual ~G4UIcommand();
0064 
0065     G4bool operator==(const G4UIcommand& right) const;
0066     G4bool operator!=(const G4UIcommand& right) const;
0067 
0068     virtual G4int DoIt(const G4String& parameterList);
0069 
0070     G4String GetCurrentValue();
0071 
0072     // These methods define the states where the command is available.
0073     // Once one of these commands is invoked, the command application will
0074     // be denied when Geant4 is NOT in the assigned states
0075     void AvailableForStates(G4ApplicationState s1);
0076     void AvailableForStates(G4ApplicationState s1, G4ApplicationState s2);
0077     void AvailableForStates(G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3);
0078     void AvailableForStates(G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3,
0079                             G4ApplicationState s4);
0080     void AvailableForStates(G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3,
0081                             G4ApplicationState s4, G4ApplicationState s5);
0082 
0083     G4bool IsAvailable();
0084 
0085     virtual void List();
0086 
0087     // Static methods for conversion from value(s) to a string.
0088     // These methods are to be used by GetCurrentValues() methods
0089     // of concrete messengers
0090     static G4String ConvertToString(G4bool boolVal);
0091     static G4String ConvertToString(G4int intValue);
0092     static G4String ConvertToString(G4long longValue);
0093     static G4String ConvertToString(G4double doubleValue);
0094     static G4String ConvertToString(G4double doubleValue, const char* unitName);
0095     static G4String ConvertToString(const G4ThreeVector& vec);
0096     static G4String ConvertToString(const G4ThreeVector& vec, const char* unitName);
0097 
0098     // Static methods for conversion from a string to a value of the returning
0099     // type. These methods are to be used directly by SetNewValues() methods
0100     // of concrete messengers, or GetNewXXXValue() of classes derived from
0101     // this G4UIcommand class
0102     static G4bool ConvertToBool(const char* st);
0103     static G4int ConvertToInt(const char* st);
0104     static G4long ConvertToLongInt(const char* st);
0105     static G4double ConvertToDouble(const char* st);
0106     static G4double ConvertToDimensionedDouble(const char* st);
0107     static G4ThreeVector ConvertTo3Vector(const char* st);
0108     static G4ThreeVector ConvertToDimensioned3Vector(const char* st);
0109 
0110     // Static methods for unit and its category
0111     static G4double ValueOf(const char* unitName);
0112     static G4String CategoryOf(const char* unitName);
0113     static G4String UnitsList(const char* unitCategory);
0114 
0115     // Defines the range the command parameter(s) can take.
0116     // The variable name(s) appear in the range expression must be the same
0117     // as the name(s) of the parameter(s).
0118     // All the C++ syntax of relational operators are allowed for the
0119     // range expression
0120     inline void SetRange(const char* rs) { rangeExpression = rs; }
0121 
0122     inline const G4String& GetRange() const { return rangeExpression; }
0123     inline std::size_t GetGuidanceEntries() const { return commandGuidance.size(); }
0124     inline const G4String& GetGuidanceLine(G4int i) const { return commandGuidance[i]; }
0125     inline const G4String& GetCommandPath() const { return commandPath; }
0126     inline const G4String& GetCommandName() const { return commandName; }
0127     inline std::size_t GetParameterEntries() const { return parameter.size(); }
0128     inline G4UIparameter* GetParameter(G4int i) const { return parameter[i]; }
0129     inline std::vector<G4ApplicationState>* GetStateList() { return &availabelStateList; }
0130     inline G4UImessenger* GetMessenger() const { return messenger; }
0131 
0132     // Defines a parameter. This method is used by the derived command
0133     // classes but the user can directly use this command when defining
0134     // a command, without using the derived class. For this case, the order
0135     // of the parameters is the order of invoking this method
0136     inline void SetParameter(G4UIparameter* const newParameter)
0137     {
0138       parameter.push_back(newParameter);
0139     }
0140 
0141     // Adds a guidance line. Unlimited times of invokation of this method is
0142     // allowed. The given lines of guidance will appear for the help.
0143     // The first line of the guidance will be used as the title of the
0144     // command, i.e. one line list of the commands
0145     inline void SetGuidance(const char* aGuidance) { commandGuidance.emplace_back(aGuidance); }
0146 
0147     inline const G4String GetTitle() const
0148     {
0149       return (commandGuidance.empty()) ? G4String("...Title not available...") : commandGuidance[0];
0150     }
0151 
0152     inline void SetToBeBroadcasted(G4bool val) { toBeBroadcasted = val; }
0153     inline G4bool ToBeBroadcasted() const { return toBeBroadcasted; }
0154     inline void SetToBeFlushed(G4bool val) { toBeFlushed = val; }
0155     inline G4bool ToBeFlushed() const { return toBeFlushed; }
0156     inline void SetWorkerThreadOnly(G4bool val = true) { workerThreadOnly = val; }
0157     inline G4bool IsWorkerThreadOnly() const { return workerThreadOnly; }
0158 
0159     inline void CommandFailed(G4int errCode, G4ExceptionDescription& ed)
0160     {
0161       commandFailureCode = errCode;
0162       failureDescription = ed.str();
0163     }
0164     inline void CommandFailed(G4ExceptionDescription& ed)
0165     {
0166       commandFailureCode = 1;
0167       failureDescription = ed.str();
0168     }
0169     inline G4int IfCommandFailed() { return commandFailureCode; }
0170     inline const G4String& GetFailureDescription() { return failureDescription; }
0171     inline void ResetFailure()
0172     {
0173       commandFailureCode = 0;
0174       failureDescription = "";
0175     }
0176 
0177   public:
0178     enum CommandType
0179     {
0180       BaseClassCmd,
0181       WithoutParameterCmd,
0182       WithABoolCmd,
0183       WithAnIntegerCmd,
0184       WithALongIntCmd,
0185       WithADoubleCmd,
0186       WithADoubleAndUnitCmd,
0187       With3VectorCmd,
0188       With3VectorAndUnitCmd,
0189       WithAStringCmd,
0190       CmdDirectory = -1
0191     };
0192 
0193     inline CommandType GetCommandType() const { return commandType; }
0194     void SetCommandType(CommandType);
0195 
0196     inline void SetDefaultSortFlag(G4bool val) { ifSort = val; }
0197 
0198   protected:
0199     G4int CheckNewValue(const char* newValue);
0200 
0201     G4bool toBeBroadcasted = false;
0202     G4bool toBeFlushed = false;
0203     G4bool workerThreadOnly = false;
0204 
0205     G4int commandFailureCode = 0;
0206     G4String failureDescription = "";
0207 
0208     G4bool ifSort = false;
0209 
0210   private:
0211     void G4UIcommandCommonConstructorCode(const char* theCommandPath);
0212 
0213   private:
0214     CommandType commandType = BaseClassCmd;
0215     G4UImessenger* messenger = nullptr;
0216     G4String commandPath;
0217     G4String commandName;
0218     G4String rangeExpression;
0219     std::vector<G4UIparameter*> parameter;
0220     std::vector<G4String> commandGuidance;
0221     std::vector<G4ApplicationState> availabelStateList;
0222 };
0223 
0224 #endif