CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/DataFormats/L1GlobalTrigger/interface/L1GtLogicParser.h

Go to the documentation of this file.
00001 #ifndef L1GlobalTrigger_L1GtLogicParser_h
00002 #define L1GlobalTrigger_L1GtLogicParser_h
00003 
00020 // system include files
00021 #include <string>
00022 #include <vector>
00023 #include <list>
00024 #include <map>
00025 
00026 #include <iosfwd>
00027 
00028 // user include files
00029 
00030 // forward declarations
00031 
00032 // class declaration
00033 class L1GtLogicParser
00034 {
00035 
00036 public:
00037 
00038     struct OperandToken
00039     {
00040         std::string tokenName;
00041         int tokenNumber;
00042         bool tokenResult;
00043     };
00044 
00045     enum OperationType {
00046         OP_NULL=1,
00047         OP_INVALID=2,
00048         OP_AND=4,
00049         OP_OR=8,
00050         OP_NOT=16,
00051         OP_OPERAND=32,
00052         OP_OPENBRACKET=64,
00053         OP_CLOSEBRACKET=128
00054     };
00055 
00056     struct TokenRPN
00057     {
00058         OperationType operation;             // type of operation: AND, OR, NOT or OPERAND
00059         std::string   operand;               // a possible operand
00060     };
00061 
00062     typedef std::vector<TokenRPN> RpnVector;
00063 
00064 public:
00065 
00067 
00069     L1GtLogicParser();
00070 
00074     L1GtLogicParser(const RpnVector&, const std::vector<OperandToken>&);
00075 
00078     L1GtLogicParser(const std::string& logicalExpressionVal);
00079 
00080     //   from a non-constant logical expression - add/remove spaces if needed
00081     //   numerical expression will be empty
00082     L1GtLogicParser(std::string& logicalExpressionVal);
00083 
00085     L1GtLogicParser(const std::string logicalExpressionVal,
00086                     const std::string numericalExpressionVal);
00087 
00090     L1GtLogicParser(const std::string& logicalExpressionVal,
00091                     const std::string& numericalExpressionVal,
00092                     const bool dummy);
00093 
00095     virtual ~L1GtLogicParser();
00096 
00097 public:
00098 
00100     inline std::string logicalExpression() const { return m_logicalExpression; }
00101 
00103     bool checkLogicalExpression(std::string&);
00104 
00106     inline std::string numericalExpression() const { return m_numericalExpression; }
00107 
00108 public:
00109 
00111     bool buildRpnVector(const std::string&);
00112 
00114     void clearRpnVector();
00115 
00117     inline RpnVector rpnVector() const { return m_rpnVector; }
00118 
00121     void buildOperandTokenVector();
00122 
00124     inline std::vector<OperandToken>& operandTokenVector() { return m_operandTokenVector; }
00125     inline const std::vector<OperandToken>& operandTokenVector() const { return m_operandTokenVector; }
00126 
00127 public:
00128 
00130     int operandIndex(const std::string& operandNameVal) const;
00131 
00133     std::string operandName(const int iOperand) const;
00134 
00137     bool operandResult(const std::string& operandNameVal) const;
00138 
00141     bool operandResult(const int tokenNumberVal) const;
00142 
00145     virtual const bool expressionResult() const;
00146 
00149     bool operandResultNumExp(const std::string& operandNameVal) const;
00150 
00153     bool operandResultNumExp(const int iOperand) const;
00154 
00157     void buildOperandTokenVectorNumExp();
00158 
00161     virtual const bool expressionResultNumExp() const;
00162 
00166     void convertNameToIntLogicalExpression(
00167         const std::map<std::string, int>& nameToIntMap);
00168 
00171 
00172     void convertIntToNameLogicalExpression(const std::map<int, std::string>& intToNameMap);
00173 
00176     std::vector<L1GtLogicParser::OperandToken> expressionSeedsOperandList();
00177 
00178 
00179 protected:
00180 
00181 
00182     struct OperationRule
00183     {
00184         const char* opString;
00185         int         opType;
00186         int         forbiddenLastOperation;    // int for bitmask of forbidden operations
00187     };
00188 
00189 
00190     virtual OperationType getOperation(const std::string& tokenString,
00191                                        OperationType lastOperation, TokenRPN& rpnToken) const;
00192 
00194     const OperationRule* getRuleFromType(OperationType t);
00195 
00196     static const struct OperationRule m_operationRules[];
00197 
00198 protected:
00199 
00201     void addBracketSpaces(const std::string&, std::string&);
00202 
00204     bool setLogicalExpression(const std::string&);
00205 
00209     bool setNumericalExpression(const std::string&);
00210 
00211 protected:
00212 
00214     std::string m_logicalExpression;
00215 
00218     std::string m_numericalExpression;
00219 
00221     RpnVector m_rpnVector;
00222 
00224     std::vector<OperandToken> m_operandTokenVector;
00225 
00226 
00227 };
00228 
00229 #endif /*L1GlobalTrigger_L1GtLogicParser_h*/