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 // 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 "G4UItokenNum.hh"
0045 #include "globals.hh"
0046 
0047 #include <vector>
0048 
0049 class G4UImessenger;
0050 
0051 class G4UIcommand
0052 {
0053   public:
0054     // Dummy default constructor
0055     G4UIcommand() = default;
0056 
0057     // Constructor. The command string with full path directory
0058     // and the pointer to the messenger must be given.
0059     // If tBB is set to false, this command won't be sent to worker threads.
0060     // This tBB parameter could be changed with SetToBeBroadcasted() method
0061     // except for G4UIdirectory
0062     G4UIcommand(const char* theCommandPath, G4UImessenger* theMessenger, G4bool tBB = true);
0063 
0064     virtual ~G4UIcommand();
0065 
0066     G4bool operator==(const G4UIcommand& right) const;
0067     G4bool operator!=(const G4UIcommand& right) const;
0068 
0069     virtual G4int DoIt(G4String parameterList);
0070 
0071     G4String GetCurrentValue();
0072 
0073     // These methods define the states where the command is available.
0074     // Once one of these commands is invoked, the command application will
0075     // be denied when Geant4 is NOT in the assigned states
0076     void AvailableForStates(G4ApplicationState s1);
0077     void AvailableForStates(G4ApplicationState s1, G4ApplicationState s2);
0078     void AvailableForStates(G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3);
0079     void AvailableForStates(G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3,
0080                             G4ApplicationState s4);
0081     void AvailableForStates(G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3,
0082                             G4ApplicationState s4, G4ApplicationState s5);
0083 
0084     G4bool IsAvailable();
0085 
0086     virtual void List();
0087 
0088     // Static methods for conversion from value(s) to a string.
0089     // These methods are to be used by GetCurrentValues() methods
0090     // of concrete messengers
0091     static G4String ConvertToString(G4bool boolVal);
0092     static G4String ConvertToString(G4int intValue);
0093     static G4String ConvertToString(G4long longValue);
0094     static G4String ConvertToString(G4double doubleValue);
0095     static G4String ConvertToString(G4double doubleValue, const char* unitName);
0096     static G4String ConvertToString(const G4ThreeVector& vec);
0097     static G4String ConvertToString(const G4ThreeVector& vec, const char* unitName);
0098 
0099     // Static methods for conversion from a string to a value of the returning
0100     // type. These methods are to be used directly by SetNewValues() methods
0101     // of concrete messengers, or GetNewXXXValue() of classes derived from
0102     // this G4UIcommand class
0103     static G4bool ConvertToBool(const char* st);
0104     static G4int ConvertToInt(const char* st);
0105     static G4long ConvertToLongInt(const char* st);
0106     static G4double ConvertToDouble(const char* st);
0107     static G4double ConvertToDimensionedDouble(const char* st);
0108     static G4ThreeVector ConvertTo3Vector(const char* st);
0109     static G4ThreeVector ConvertToDimensioned3Vector(const char* st);
0110 
0111     // Static methods for unit and its category
0112     static G4double ValueOf(const char* unitName);
0113     static G4String CategoryOf(const char* unitName);
0114     static G4String UnitsList(const char* unitCategory);
0115 
0116     // Defines the range the command parameter(s) can take.
0117     // The variable name(s) appear in the range expression must be the same
0118     // as the name(s) of the parameter(s).
0119     // All the C++ syntax of relational operators are allowed for the
0120     // range expression
0121     inline void SetRange(const char* rs) { rangeExpression = rs; }
0122 
0123     inline const G4String& GetRange() const { return rangeExpression; }
0124     inline std::size_t GetGuidanceEntries() const { return commandGuidance.size(); }
0125     inline const G4String& GetGuidanceLine(G4int i) const { return commandGuidance[i]; }
0126     inline const G4String& GetCommandPath() const { return commandPath; }
0127     inline const G4String& GetCommandName() const { return commandName; }
0128     inline std::size_t GetParameterEntries() const { return parameter.size(); }
0129     inline G4UIparameter* GetParameter(G4int i) const { return parameter[i]; }
0130     inline std::vector<G4ApplicationState>* GetStateList() { return &availabelStateList; }
0131     inline G4UImessenger* GetMessenger() const { return messenger; }
0132 
0133     // Defines a parameter. This method is used by the derived command
0134     // classes but the user can directly use this command when defining
0135     // a command, without using the derived class. For this case, the order
0136     // of the parameters is the order of invoking this method
0137     inline void SetParameter(G4UIparameter* const newParameter)
0138     {
0139       parameter.push_back(newParameter);
0140       newVal.resize(parameter.size());
0141     }
0142 
0143     // Adds a guidance line. Unlimited times of invokation of this method is
0144     // allowed. The given lines of guidance will appear for the help.
0145     // The first line of the guidance will be used as the title of the
0146     // command, i.e. one line list of the commands
0147     inline void SetGuidance(const char* aGuidance) { commandGuidance.emplace_back(aGuidance); }
0148 
0149     inline const G4String GetTitle() const
0150     {
0151       return (commandGuidance.empty()) ? G4String("...Title not available...") : commandGuidance[0];
0152     }
0153 
0154     inline void SetToBeBroadcasted(G4bool val) { toBeBroadcasted = val; }
0155     inline G4bool ToBeBroadcasted() const { return toBeBroadcasted; }
0156     inline void SetToBeFlushed(G4bool val) { toBeFlushed = val; }
0157     inline G4bool ToBeFlushed() const { return toBeFlushed; }
0158     inline void SetWorkerThreadOnly(G4bool val = true) { workerThreadOnly = val; }
0159     inline G4bool IsWorkerThreadOnly() const { return workerThreadOnly; }
0160 
0161     inline void CommandFailed(G4int errCode, G4ExceptionDescription& ed)
0162     {
0163       commandFailureCode = errCode;
0164       failureDescription = ed.str();
0165     }
0166     inline void CommandFailed(G4ExceptionDescription& ed)
0167     {
0168       commandFailureCode = 1;
0169       failureDescription = ed.str();
0170     }
0171     inline G4int IfCommandFailed() { return commandFailureCode; }
0172     inline const G4String& GetFailureDescription() { return failureDescription; }
0173     inline void ResetFailure()
0174     {
0175       commandFailureCode = 0;
0176       failureDescription = "";
0177     }
0178 
0179   public:
0180     enum CommandType
0181     {
0182       BaseClassCmd,
0183       WithoutParameterCmd,
0184       WithABoolCmd,
0185       WithAnIntegerCmd,
0186       WithALongIntCmd,
0187       WithADoubleCmd,
0188       WithADoubleAndUnitCmd,
0189       With3VectorCmd,
0190       With3VectorAndUnitCmd,
0191       WithAStringCmd,
0192       CmdDirectory = -1
0193     };
0194 
0195     inline CommandType GetCommandType() const { return commandType; }
0196     void SetCommandType(CommandType);
0197 
0198     inline void SetDefaultSortFlag(G4bool val) { ifSort = val; }
0199 
0200   protected:
0201     // --- the following is used by CheckNewValue() --------
0202     using yystype = G4UItokenNum::yystype;
0203     using tokenNum = G4UItokenNum::tokenNum;
0204 
0205     G4int CheckNewValue(const char* newValue);
0206 
0207     G4bool toBeBroadcasted = false;
0208     G4bool toBeFlushed = false;
0209     G4bool workerThreadOnly = false;
0210 
0211     G4int commandFailureCode = 0;
0212     G4String failureDescription = "";
0213 
0214     G4bool ifSort = false;
0215 
0216   private:
0217     void G4UIcommandCommonConstructorCode(const char* theCommandPath);
0218 
0219     G4bool RangeCheck(const char* t);
0220 
0221     //  syntax nodes
0222     yystype Expression();
0223     yystype LogicalORExpression();
0224     yystype LogicalANDExpression();
0225     yystype EqualityExpression();
0226     yystype RelationalExpression();
0227     yystype AdditiveExpression();
0228     yystype MultiplicativeExpression();
0229     yystype UnaryExpression();
0230     yystype PrimaryExpression();
0231     //  semantics routines
0232     G4int Eval2(const yystype& arg1, G4int op, const yystype& arg2);
0233     //  utility
0234     tokenNum Yylex();  // returns next token
0235     unsigned IndexOf(const char*);  // returns the index of the var name
0236     unsigned IsParameter(const char*);  // returns 1 or 0
0237     G4int G4UIpGetc();  // read one char from rangeBuf
0238     G4int G4UIpUngetc(G4int c);  // put back
0239     G4int Backslash(G4int c);
0240     G4int Follow(G4int expect, G4int ifyes, G4int ifno);
0241 
0242     // Data -----------------------------------------------------------
0243 
0244   private:
0245     CommandType commandType = BaseClassCmd;
0246     G4UImessenger* messenger = nullptr;
0247     G4String commandPath;
0248     G4String commandName;
0249     G4String rangeExpression;
0250     std::vector<G4UIparameter*> parameter;
0251     std::vector<G4String> commandGuidance;
0252     std::vector<G4ApplicationState> availabelStateList;
0253 
0254     G4int bp = 0;  // current index into rangeExpression
0255     tokenNum token = G4UItokenNum::IDENTIFIER;
0256     yystype yylval;
0257     std::vector<yystype> newVal;
0258     G4int paramERR = 0;
0259 };
0260 
0261 #endif