CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L1GtLogicParser.h
Go to the documentation of this file.
1 #ifndef L1GlobalTrigger_L1GtLogicParser_h
2 #define L1GlobalTrigger_L1GtLogicParser_h
3 
20 // system include files
21 #include <string>
22 #include <vector>
23 #include <list>
24 #include <map>
25 
26 #include <iosfwd>
27 
28 // user include files
29 
30 // forward declarations
31 
32 // class declaration
34 {
35 
36 public:
37 
38  struct OperandToken
39  {
40  std::string tokenName;
43  };
44 
48  OP_AND=4,
49  OP_OR=8,
50  OP_NOT=16,
54  };
55 
56  struct TokenRPN
57  {
58  OperationType operation; // type of operation: AND, OR, NOT or OPERAND
59  std::string operand; // a possible operand
60  };
61 
62  typedef std::vector<TokenRPN> RpnVector;
63 
64 public:
65 
67 
70 
74  L1GtLogicParser(const RpnVector&, const std::vector<OperandToken>&);
75 
78  L1GtLogicParser(const std::string& logicalExpressionVal);
79 
80  // from a non-constant logical expression - add/remove spaces if needed
81  // numerical expression will be empty
82  L1GtLogicParser(std::string& logicalExpressionVal);
83 
85  L1GtLogicParser(const std::string logicalExpressionVal,
86  const std::string numericalExpressionVal);
87 
90  L1GtLogicParser(const std::string& logicalExpressionVal,
91  const std::string& numericalExpressionVal,
92  const bool dummy);
93 
95  virtual ~L1GtLogicParser();
96 
97 public:
98 
100  inline std::string logicalExpression() const { return m_logicalExpression; }
101 
103  bool checkLogicalExpression(std::string&);
104 
106  inline std::string numericalExpression() const { return m_numericalExpression; }
107 
108 public:
109 
111  bool buildRpnVector(const std::string&);
112 
114  void clearRpnVector();
115 
117  inline RpnVector rpnVector() const { return m_rpnVector; }
118 
122 
124  inline std::vector<OperandToken>& operandTokenVector() { return m_operandTokenVector; }
125  inline const std::vector<OperandToken>& operandTokenVector() const { return m_operandTokenVector; }
126 
127 public:
128 
130  int operandIndex(const std::string& operandNameVal) const;
131 
133  std::string operandName(const int iOperand) const;
134 
137  bool operandResult(const std::string& operandNameVal) const;
138 
141  bool operandResult(const int tokenNumberVal) const;
142 
145  virtual const bool expressionResult() const;
146 
149  bool operandResultNumExp(const std::string& operandNameVal) const;
150 
153  bool operandResultNumExp(const int iOperand) const;
154 
158 
161  virtual const bool expressionResultNumExp() const;
162 
167  const std::map<std::string, int>& nameToIntMap);
168 
171 
172  void convertIntToNameLogicalExpression(const std::map<int, std::string>& intToNameMap);
173 
176  std::vector<L1GtLogicParser::OperandToken> expressionSeedsOperandList();
177 
178 
179 protected:
180 
181 
183  {
184  const char* opString;
185  int opType;
186  int forbiddenLastOperation; // int for bitmask of forbidden operations
187  };
188 
189 
190  virtual OperationType getOperation(const std::string& tokenString,
191  OperationType lastOperation, TokenRPN& rpnToken) const;
192 
195 
196  static const struct OperationRule m_operationRules[];
197 
198 protected:
199 
201  void addBracketSpaces(const std::string&, std::string&);
202 
204  bool setLogicalExpression(const std::string&);
205 
209  bool setNumericalExpression(const std::string&);
210 
211 protected:
212 
214  std::string m_logicalExpression;
215 
219 
222 
224  std::vector<OperandToken> m_operandTokenVector;
225 
226 
227 };
228 
229 #endif /*L1GlobalTrigger_L1GtLogicParser_h*/
std::vector< L1GtLogicParser::OperandToken > expressionSeedsOperandList()
std::string logicalExpression() const
return the logical expression
static struct OperationRule m_operationRules[]
void clearRpnVector()
clear possible old rpn vector
void convertNameToIntLogicalExpression(const std::map< std::string, int > &nameToIntMap)
bool buildRpnVector(const std::string &)
build the rpn vector
void buildOperandTokenVectorNumExp()
RpnVector rpnVector() const
return the RPN vector
void addBracketSpaces(const std::string &, std::string &)
add spaces before and after parantheses
L1GtLogicParser()
constructor(s)
bool operandResultNumExp(const std::string &operandNameVal) const
void convertIntToNameLogicalExpression(const std::map< int, std::string > &intToNameMap)
std::vector< OperandToken > m_operandTokenVector
vector of operand tokens
const OperationRule * getRuleFromType(OperationType t)
get the rule entry to an operation type
std::vector< OperandToken > & operandTokenVector()
return the vector of operand tokens
bool setNumericalExpression(const std::string &)
std::string numericalExpression() const
return the numerical expression
bool operandResult(const std::string &operandNameVal) const
std::string m_logicalExpression
logical expression to be parsed
const std::vector< OperandToken > & operandTokenVector() const
RpnVector m_rpnVector
RPN vector - equivalent to the logical expression.
virtual ~L1GtLogicParser()
destructor
std::string m_numericalExpression
bool checkLogicalExpression(std::string &)
check a logical expression for correctness - add/remove spaces if needed
std::vector< TokenRPN > RpnVector
void buildOperandTokenVector()
std::string operandName(const int iOperand) const
return the name of the (iOperand)th operand in the logical expression
bool setLogicalExpression(const std::string &)
set the logical expression - check for correctness the input string
virtual OperationType getOperation(const std::string &tokenString, OperationType lastOperation, TokenRPN &rpnToken) const
int operandIndex(const std::string &operandNameVal) const
return the position index of the operand in the logical expression
virtual const bool expressionResultNumExp() const
virtual const bool expressionResult() const