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 
18 // system include files
19 #include <string>
20 #include <vector>
21 #include <list>
22 #include <map>
23 
24 #include <iosfwd>
25 
26 // user include files
27 
28 // forward declarations
29 
30 // class declaration
32 {
33 
34 public:
35 
36  struct OperandToken
37  {
41  };
42 
46  OP_AND=4,
47  OP_OR=8,
48  OP_NOT=16,
52  };
53 
54  struct TokenRPN
55  {
56  OperationType operation; // type of operation: AND, OR, NOT or OPERAND
57  std::string operand; // a possible operand
58  };
59 
60  typedef std::vector<TokenRPN> RpnVector;
61 
62 public:
63 
65 
68 
72  L1GtLogicParser(const RpnVector&, const std::vector<OperandToken>&);
73 
76  L1GtLogicParser(const std::string& logicalExpressionVal);
77 
78  // from a non-constant logical expression - add/remove spaces if needed
79  // numerical expression will be empty
80  L1GtLogicParser(std::string& logicalExpressionVal);
81 
83  L1GtLogicParser(const std::string logicalExpressionVal,
84  const std::string numericalExpressionVal);
85 
88  L1GtLogicParser(const std::string& logicalExpressionVal,
89  const std::string& numericalExpressionVal,
90  const bool dummy);
91 
93  virtual ~L1GtLogicParser();
94 
95 public:
96 
99 
102 
105 
106 public:
107 
109  bool buildRpnVector(const std::string&);
110 
112  void clearRpnVector();
113 
115  inline RpnVector rpnVector() const { return m_rpnVector; }
116 
120 
122  inline std::vector<OperandToken>& operandTokenVector() { return m_operandTokenVector; }
123  inline const std::vector<OperandToken>& operandTokenVector() const { return m_operandTokenVector; }
124 
125 public:
126 
128  int operandIndex(const std::string& operandNameVal) const;
129 
131  std::string operandName(const int iOperand) const;
132 
135  bool operandResult(const std::string& operandNameVal) const;
136 
139  bool operandResult(const int tokenNumberVal) const;
140 
143  virtual const bool expressionResult() const;
144 
147  bool operandResultNumExp(const std::string& operandNameVal) const;
148 
151  bool operandResultNumExp(const int iOperand) const;
152 
156 
159  virtual const bool expressionResultNumExp() const;
160 
165  const std::map<std::string, int>& nameToIntMap);
166 
169 
170  void convertIntToNameLogicalExpression(const std::map<int, std::string>& intToNameMap);
171 
174  std::vector<L1GtLogicParser::OperandToken> expressionSeedsOperandList();
175 
176 
177 protected:
178 
179 
181  {
182  const char* opString;
183  int opType;
184  int forbiddenLastOperation; // int for bitmask of forbidden operations
185  };
186 
187 
188  virtual OperationType getOperation(const std::string& tokenString,
189  OperationType lastOperation, TokenRPN& rpnToken) const;
190 
193 
194  static const struct OperationRule m_operationRules[];
195 
196 protected:
197 
200 
202  bool setLogicalExpression(const std::string&);
203 
207  bool setNumericalExpression(const std::string&);
208 
209 protected:
210 
213 
217 
220 
222  std::vector<OperandToken> m_operandTokenVector;
223 
224 
225 };
226 
227 #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