CMS 3D CMS Logo

TriggerExpressionParser.h
Go to the documentation of this file.
1 #ifndef HLTrigger_HLTfilters_TriggerExpressionParser_h
2 #define HLTrigger_HLTfilters_TriggerExpressionParser_h
3 
4 // Note: this requires Boost 1.41 or higher, for Spirit 2.1 or higher
5 #include <boost/spirit/include/phoenix.hpp>
6 #include <boost/spirit/include/qi.hpp>
7 
13 
14 namespace triggerExpression {
15 
16  namespace qi = boost::spirit::qi;
17  namespace ascii = boost::spirit::ascii;
18 
19  using boost::phoenix::new_;
20  using boost::spirit::unused_type;
21 
22  template <typename Iterator>
23  class Parser : public qi::grammar<Iterator, Evaluator *(), ascii::space_type> {
24  public:
25  Parser() : Parser::base_type(expression) {
26  token_l1algo %= qi::raw[qi::lexeme["L1_" >> +(qi::char_("a-zA-Z0-9_*?"))]];
27  token_path %= qi::raw[qi::lexeme[+(qi::char_("a-zA-Z0-9_*?"))]];
28 
29  token = (qi::lit("TRUE")[qi::_val = new_<Constant>(true)] | qi::lit("FALSE")[qi::_val = new_<Constant>(false)] |
30  token_l1algo[qi::_val = new_<L1uGTReader>(qi::_1)] | token_path[qi::_val = new_<PathReader>(qi::_1)]);
31 
32  parenthesis %= ('(' >> expression >> ')');
33 
34  element %= (token | parenthesis);
35 
36  prescale = (element >> '/' >> qi::uint_)[qi::_val = new_<Prescaler>(qi::_1, qi::_2)];
37 
38  operand %= (prescale | element);
39 
40  unary = (operand[qi::_val = qi::_1] | (qi::lit("NOT") >> operand)[qi::_val = new_<OperatorNot>(qi::_1)]);
41 
42  expression =
43  unary[qi::_val = qi::_1] >> *((qi::lit("AND") >> unary)[qi::_val = new_<OperatorAnd>(qi::_val, qi::_1)] |
44  (qi::lit("OR") >> unary)[qi::_val = new_<OperatorOr>(qi::_val, qi::_1)]);
45  }
46 
47  private:
48  typedef qi::rule<Iterator, std::string(), ascii::space_type> name_rule;
49  typedef qi::rule<Iterator, Evaluator *(), ascii::space_type> rule;
50 
53 
61  };
62 
63  // generic interface for string-like objects
64  template <class T>
65  Evaluator *parse(const T &text) {
66  typedef typename T::const_iterator Iterator;
68  Evaluator *evaluator = nullptr;
69 
70  Iterator begin = text.begin();
71  Iterator end = text.end();
72 
73  // the interface of qi::phrase_parse has changed between Boost 1.40 (Spirit 2.0) and Boost 1.41 (Spirit 2.1)
74  bool result = qi::phrase_parse(begin, end, parser, ascii::space, evaluator);
75 
76  if (not result or begin != end) {
77  delete evaluator;
78  return nullptr;
79  }
80 
81  return evaluator;
82  }
83 
84  // overloaded interface for null-terminated strings
85  inline Evaluator *parse(const char *text) {
87  Evaluator *evaluator = nullptr;
88 
89  const char *begin = text;
90  const char *end = text + strlen(text);
91 
92  // the interface of qi::phrase_parse has changed between Boost 1.40 (Spirit 2.0) and Boost 1.41 (Spirit 2.1)
93  bool result = qi::phrase_parse(begin, end, parser, ascii::space, evaluator);
94 
95  if (not result or begin != end) {
96  delete evaluator;
97  return nullptr;
98  }
99 
100  return evaluator;
101  }
102 
103 } // namespace triggerExpression
104 
105 #endif // HLTrigger_HLTfilters_TriggerExpressionParser_h
triggerExpression::Evaluator
Definition: TriggerExpressionEvaluator.h:10
triggerExpression::Parser::Parser
Parser()
Definition: TriggerExpressionParser.h:25
TriggerExpressionPrescaler.h
triggerExpression::Parser::expression
rule expression
Definition: TriggerExpressionParser.h:60
writedatasetfile.parser
parser
Definition: writedatasetfile.py:7
Iterator
Definition: DQMStoreStats.h:94
cms::Iterator
TGeoIterator Iterator
Definition: DDFilteredView.h:54
triggerExpression::Parser::token_l1algo
name_rule token_l1algo
Definition: TriggerExpressionParser.h:51
mps_fire.end
end
Definition: mps_fire.py:242
TriggerExpressionPathReader.h
triggerExpression::parse
Evaluator * parse(const T &text)
Definition: TriggerExpressionParser.h:65
triggerExpression::Parser::token
rule token
Definition: TriggerExpressionParser.h:54
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
triggerExpression::Parser::unary
rule unary
Definition: TriggerExpressionParser.h:59
triggerExpression::Parser::parenthesis
rule parenthesis
Definition: TriggerExpressionParser.h:55
triggerExpression::Parser::prescale
rule prescale
Definition: TriggerExpressionParser.h:57
TriggerExpressionL1uGTReader.h
prescale
Definition: PrescaleEventFilter.cc:32
triggerExpression::Parser::operand
rule operand
Definition: TriggerExpressionParser.h:58
T
long double T
Definition: Basic3DVectorLD.h:48
TriggerExpressionOperators.h
triggerExpression::Parser::name_rule
qi::rule< Iterator, std::string(), ascii::space_type > name_rule
Definition: TriggerExpressionParser.h:48
TriggerExpressionConstant.h
or
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
triggerExpression::Parser::element
rule element
Definition: TriggerExpressionParser.h:56
triggerExpression
Definition: TriggerExpressionConstant.h:6
triggerExpression::Parser::token_path
name_rule token_path
Definition: TriggerExpressionParser.h:52
triggerExpression::Parser::rule
qi::rule< Iterator, Evaluator *(), ascii::space_type > rule
Definition: TriggerExpressionParser.h:49
mps_fire.result
result
Definition: mps_fire.py:311
runonSM.text
text
Definition: runonSM.py:43
triggerExpression::Parser
Definition: TriggerExpressionParser.h:23