File indexing completed on 2024-04-06 12:04:28
0001 #ifndef L1GlobalTrigger_L1GtLogicParser_h
0002 #define L1GlobalTrigger_L1GtLogicParser_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #include <string>
0020 #include <vector>
0021 #include <list>
0022 #include <map>
0023
0024 #include <iosfwd>
0025
0026
0027
0028
0029
0030
0031 class L1GtLogicParser {
0032 public:
0033 struct OperandToken {
0034 std::string tokenName;
0035 int tokenNumber;
0036 bool tokenResult;
0037 };
0038
0039 enum OperationType {
0040 OP_NULL = 1,
0041 OP_INVALID = 2,
0042 OP_AND = 4,
0043 OP_OR = 8,
0044 OP_NOT = 16,
0045 OP_OPERAND = 32,
0046 OP_OPENBRACKET = 64,
0047 OP_CLOSEBRACKET = 128
0048 };
0049
0050 struct TokenRPN {
0051 OperationType operation;
0052 std::string operand;
0053 };
0054
0055 typedef std::vector<TokenRPN> RpnVector;
0056
0057 public:
0058
0059
0060
0061 L1GtLogicParser();
0062
0063
0064
0065
0066 L1GtLogicParser(const RpnVector&, const std::vector<OperandToken>&);
0067
0068
0069
0070 L1GtLogicParser(const std::string& logicalExpressionVal);
0071
0072
0073
0074 L1GtLogicParser(std::string& logicalExpressionVal);
0075
0076
0077 L1GtLogicParser(const std::string logicalExpressionVal, const std::string numericalExpressionVal);
0078
0079
0080
0081 L1GtLogicParser(const std::string& logicalExpressionVal, const std::string& numericalExpressionVal, const bool dummy);
0082
0083
0084 virtual ~L1GtLogicParser();
0085
0086 public:
0087
0088 inline std::string logicalExpression() const { return m_logicalExpression; }
0089
0090
0091 bool checkLogicalExpression(std::string&);
0092
0093
0094 inline std::string numericalExpression() const { return m_numericalExpression; }
0095
0096 public:
0097
0098 bool buildRpnVector(const std::string&);
0099
0100
0101 void clearRpnVector();
0102
0103
0104 inline RpnVector rpnVector() const { return m_rpnVector; }
0105
0106
0107
0108 void buildOperandTokenVector();
0109
0110
0111 inline std::vector<OperandToken>& operandTokenVector() { return m_operandTokenVector; }
0112 inline const std::vector<OperandToken>& operandTokenVector() const { return m_operandTokenVector; }
0113
0114 public:
0115
0116 int operandIndex(const std::string& operandNameVal) const;
0117
0118
0119 std::string operandName(const int iOperand) const;
0120
0121
0122
0123 bool operandResult(const std::string& operandNameVal) const;
0124
0125
0126
0127 bool operandResult(const int tokenNumberVal) const;
0128
0129
0130
0131 virtual const bool expressionResult() const;
0132
0133
0134
0135 bool operandResultNumExp(const std::string& operandNameVal) const;
0136
0137
0138
0139 bool operandResultNumExp(const int iOperand) const;
0140
0141
0142
0143 void buildOperandTokenVectorNumExp();
0144
0145
0146
0147 virtual const bool expressionResultNumExp() const;
0148
0149
0150
0151
0152 void convertNameToIntLogicalExpression(const std::map<std::string, int>& nameToIntMap);
0153
0154
0155
0156
0157 void convertIntToNameLogicalExpression(const std::map<int, std::string>& intToNameMap);
0158
0159
0160
0161 std::vector<L1GtLogicParser::OperandToken> expressionSeedsOperandList();
0162
0163 protected:
0164 struct OperationRule {
0165 const char* opString;
0166 int opType;
0167 int forbiddenLastOperation;
0168 };
0169
0170 virtual OperationType getOperation(const std::string& tokenString,
0171 OperationType lastOperation,
0172 TokenRPN& rpnToken) const;
0173
0174
0175 const OperationRule* getRuleFromType(OperationType t);
0176
0177 static const struct OperationRule m_operationRules[];
0178
0179 protected:
0180
0181 void addBracketSpaces(const std::string&, std::string&);
0182
0183
0184 bool setLogicalExpression(const std::string&);
0185
0186
0187
0188
0189 bool setNumericalExpression(const std::string&);
0190
0191 protected:
0192
0193 std::string m_logicalExpression;
0194
0195
0196
0197 std::string m_numericalExpression;
0198
0199
0200 RpnVector m_rpnVector;
0201
0202
0203 std::vector<OperandToken> m_operandTokenVector;
0204 };
0205
0206 #endif