CMS 3D CMS Logo

GlobalLogicParser.h
Go to the documentation of this file.
1 #ifndef L1TGlobal_GlobalLogicParser_h
2 #define L1TGlobal_GlobalLogicParser_h
3 
4 // system include files
5 #include <string>
6 #include <vector>
7 #include <list>
8 #include <map>
9 
10 #include <iosfwd>
11 
12 // user include files
13 
14 // forward declarations
15 
16 // class declaration
18 public:
19  struct OperandToken {
23  };
24 
26  OP_NULL = 1,
28  OP_AND = 4,
29  OP_OR = 8,
30  OP_NOT = 16,
31  OP_OPERAND = 32,
34  OP_XOR = 256
35  };
36 
37  struct TokenRPN {
38  OperationType operation; // type of operation: AND, OR, NOT or OPERAND
39  std::string operand; // a possible operand
40  };
41 
42  typedef std::vector<TokenRPN> RpnVector;
43 
44 public:
46 
49 
53  GlobalLogicParser(const RpnVector&, const std::vector<OperandToken>&);
54 
57  GlobalLogicParser(const std::string& logicalExpressionVal);
58 
59  // from a non-constant logical expression - add/remove spaces if needed
60  // numerical expression will be empty
61  GlobalLogicParser(std::string& logicalExpressionVal);
62 
64  GlobalLogicParser(const std::string logicalExpressionVal, const std::string numericalExpressionVal);
65 
68  GlobalLogicParser(const std::string& logicalExpressionVal,
69  const std::string& numericalExpressionVal,
70  const bool dummy);
71 
73  virtual ~GlobalLogicParser();
74 
75 public:
78 
81 
84 
85 public:
87  bool buildRpnVector(const std::string&);
88 
90  void clearRpnVector();
91 
93  inline RpnVector rpnVector() const { return m_rpnVector; }
94 
98 
100  inline std::vector<OperandToken>& operandTokenVector() { return m_operandTokenVector; }
101  inline const std::vector<OperandToken>& operandTokenVector() const { return m_operandTokenVector; }
102 
103 public:
105  int operandIndex(const std::string& operandNameVal) const;
106 
108  std::string operandName(const int iOperand) const;
109 
112  bool operandResult(const std::string& operandNameVal) const;
113 
116  bool operandResult(const int tokenNumberVal) const;
117 
120  virtual const bool expressionResult() const;
121 
124  bool operandResultNumExp(const std::string& operandNameVal) const;
125 
128  bool operandResultNumExp(const int iOperand) const;
129 
133 
136  virtual const bool expressionResultNumExp() const;
137 
141  void convertNameToIntLogicalExpression(const std::map<std::string, int>& nameToIntMap);
142 
145 
146  void convertIntToNameLogicalExpression(const std::map<int, std::string>& intToNameMap);
147 
150  std::vector<GlobalLogicParser::OperandToken> expressionSeedsOperandList();
151 
152 protected:
153  struct OperationRule {
154  const char* opString;
155  int opType;
156  int forbiddenLastOperation; // int for bitmask of forbidden operations
157  };
158 
159  virtual OperationType getOperation(const std::string& tokenString,
160  OperationType lastOperation,
161  TokenRPN& rpnToken) const;
162 
165 
166  static const struct OperationRule m_operationRules[];
167 
168 protected:
171 
173  bool setLogicalExpression(const std::string&);
174 
178  bool setNumericalExpression(const std::string&);
179 
180 protected:
183 
187 
190 
192  std::vector<OperandToken> m_operandTokenVector;
193 };
194 
195 #endif /*L1TGlobal_GtLogicParser_h*/
GlobalLogicParser::OperationType
OperationType
Definition: GlobalLogicParser.h:25
GlobalLogicParser::m_numericalExpression
std::string m_numericalExpression
Definition: GlobalLogicParser.h:186
GlobalLogicParser::setLogicalExpression
bool setLogicalExpression(const std::string &)
set the logical expression - check for correctness the input string
Definition: GlobalLogicParser.cc:1421
GlobalLogicParser::expressionResult
virtual const bool expressionResult() const
Definition: GlobalLogicParser.cc:593
GlobalLogicParser::OP_OPENBRACKET
Definition: GlobalLogicParser.h:32
GlobalLogicParser::clearRpnVector
void clearRpnVector()
clear possible old rpn vector
Definition: GlobalLogicParser.cc:374
GlobalLogicParser::OperationRule::opString
const char * opString
Definition: GlobalLogicParser.h:154
GlobalLogicParser::buildRpnVector
bool buildRpnVector(const std::string &)
build the rpn vector
Definition: GlobalLogicParser.cc:164
GlobalLogicParser::m_logicalExpression
std::string m_logicalExpression
logical expression to be parsed
Definition: GlobalLogicParser.h:182
GlobalLogicParser::setNumericalExpression
bool setNumericalExpression(const std::string &)
Definition: GlobalLogicParser.cc:1449
GlobalLogicParser::m_operationRules
static const struct OperationRule m_operationRules[]
Definition: GlobalLogicParser.h:166
GlobalLogicParser::operandResult
bool operandResult(const std::string &operandNameVal) const
Definition: GlobalLogicParser.cc:560
GlobalLogicParser::expressionSeedsOperandList
std::vector< GlobalLogicParser::OperandToken > expressionSeedsOperandList()
Definition: GlobalLogicParser.cc:1079
GlobalLogicParser::convertIntToNameLogicalExpression
void convertIntToNameLogicalExpression(const std::map< int, std::string > &intToNameMap)
Definition: GlobalLogicParser.cc:998
GlobalLogicParser::OP_XOR
Definition: GlobalLogicParser.h:34
GlobalLogicParser::OperationRule::opType
int opType
Definition: GlobalLogicParser.h:155
GlobalLogicParser::m_operandTokenVector
std::vector< OperandToken > m_operandTokenVector
vector of operand tokens
Definition: GlobalLogicParser.h:192
GlobalLogicParser::buildOperandTokenVectorNumExp
void buildOperandTokenVectorNumExp()
Definition: GlobalLogicParser.cc:770
GlobalLogicParser::expressionResultNumExp
virtual const bool expressionResultNumExp() const
Definition: GlobalLogicParser.cc:831
GlobalLogicParser::getOperation
virtual OperationType getOperation(const std::string &tokenString, OperationType lastOperation, TokenRPN &rpnToken) const
Definition: GlobalLogicParser.cc:1340
GlobalLogicParser::getRuleFromType
const OperationRule * getRuleFromType(OperationType t)
get the rule entry to an operation type
Definition: GlobalLogicParser.cc:1384
GlobalLogicParser::numericalExpression
std::string numericalExpression() const
return the numerical expression
Definition: GlobalLogicParser.h:83
GlobalLogicParser::checkLogicalExpression
bool checkLogicalExpression(std::string &)
check a logical expression for correctness - add/remove spaces if needed
Definition: GlobalLogicParser.cc:131
GlobalLogicParser::RpnVector
std::vector< TokenRPN > RpnVector
Definition: GlobalLogicParser.h:42
GlobalLogicParser::TokenRPN::operation
OperationType operation
Definition: GlobalLogicParser.h:38
GlobalLogicParser::OperationRule::forbiddenLastOperation
int forbiddenLastOperation
Definition: GlobalLogicParser.h:156
GlobalLogicParser::OP_OPERAND
Definition: GlobalLogicParser.h:31
GlobalLogicParser::OP_AND
Definition: GlobalLogicParser.h:28
GlobalLogicParser
Definition: GlobalLogicParser.h:17
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
GlobalLogicParser::operandIndex
int operandIndex(const std::string &operandNameVal) const
return the position index of the operand in the logical expression
Definition: GlobalLogicParser.cc:437
GlobalLogicParser::OperandToken::tokenNumber
int tokenNumber
Definition: GlobalLogicParser.h:21
GlobalLogicParser::OP_NULL
Definition: GlobalLogicParser.h:26
GlobalLogicParser::OperandToken::tokenResult
bool tokenResult
Definition: GlobalLogicParser.h:22
GlobalLogicParser::~GlobalLogicParser
virtual ~GlobalLogicParser()
destructor
Definition: GlobalLogicParser.cc:124
GlobalLogicParser::GlobalLogicParser
GlobalLogicParser()
constructor(s)
Definition: GlobalLogicParser.cc:36
GlobalLogicParser::rpnVector
RpnVector rpnVector() const
return the RPN vector
Definition: GlobalLogicParser.h:93
GlobalLogicParser::buildOperandTokenVector
void buildOperandTokenVector()
Definition: GlobalLogicParser.cc:378
GlobalLogicParser::OperationRule
Definition: GlobalLogicParser.h:153
GlobalLogicParser::addBracketSpaces
void addBracketSpaces(const std::string &, std::string &)
add spaces before and after parantheses
Definition: GlobalLogicParser.cc:1399
GlobalLogicParser::TokenRPN::operand
std::string operand
Definition: GlobalLogicParser.h:39
GlobalLogicParser::logicalExpression
std::string logicalExpression() const
return the logical expression
Definition: GlobalLogicParser.h:77
GlobalLogicParser::OP_NOT
Definition: GlobalLogicParser.h:30
GlobalLogicParser::operandTokenVector
std::vector< OperandToken > & operandTokenVector()
return the vector of operand tokens
Definition: GlobalLogicParser.h:100
GlobalLogicParser::operandTokenVector
const std::vector< OperandToken > & operandTokenVector() const
Definition: GlobalLogicParser.h:101
GlobalLogicParser::OP_INVALID
Definition: GlobalLogicParser.h:27
GlobalLogicParser::operandResultNumExp
bool operandResultNumExp(const std::string &operandNameVal) const
Definition: GlobalLogicParser.cc:675
GlobalLogicParser::OP_CLOSEBRACKET
Definition: GlobalLogicParser.h:33
GlobalLogicParser::OP_OR
Definition: GlobalLogicParser.h:29
GlobalLogicParser::convertNameToIntLogicalExpression
void convertNameToIntLogicalExpression(const std::map< std::string, int > &nameToIntMap)
Definition: GlobalLogicParser.cc:917
GlobalLogicParser::m_rpnVector
RpnVector m_rpnVector
RPN vector - equivalent to the logical expression.
Definition: GlobalLogicParser.h:189
dummy
Definition: DummySelector.h:38
GlobalLogicParser::TokenRPN
Definition: GlobalLogicParser.h:37
GlobalLogicParser::OperandToken
Definition: GlobalLogicParser.h:19
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
GlobalLogicParser::OperandToken::tokenName
std::string tokenName
Definition: GlobalLogicParser.h:20
GlobalLogicParser::operandName
std::string operandName(const int iOperand) const
return the name of the (iOperand)th operand in the logical expression
Definition: GlobalLogicParser.cc:498