CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
14 
15 namespace triggerExpression {
16 
17 namespace qi = boost::spirit::qi;
18 namespace ascii = boost::spirit::ascii;
19 
20 using boost::phoenix::new_;
21 using boost::spirit::unused_type;
22 
23 template <typename Iterator>
24 class Parser : public qi::grammar<Iterator, Evaluator*(), ascii::space_type>
25 {
26 public:
27  Parser() :
28  Parser::base_type(expression)
29  {
30  token_l1algo %= qi::raw[qi::lexeme["L1_" >> +(qi::char_("a-zA-Z0-9_*?"))]];
31  token_l1tech %= qi::raw[qi::lexeme["L1Tech_" >> +(qi::char_("a-zA-Z0-9_*?"))]];
32  token_path %= qi::raw[qi::lexeme[ +(qi::char_("a-zA-Z0-9_*?"))]];
33 
34  token = ( qi::lit("TRUE") [qi::_val = new_<Constant>(true)]
35  | qi::lit("FALSE") [qi::_val = new_<Constant>(false)]
36  | token_l1algo [qi::_val = new_<L1AlgoReader>(qi::_1)]
37  | token_l1tech [qi::_val = new_<L1TechReader>(qi::_1)]
38  | token_path [qi::_val = new_<PathReader>(qi::_1)]
39  );
40 
41  parenthesis %= ('(' >> expression >> ')');
42 
43  element %= (token | parenthesis);
44 
45  prescale = (element >> '/' >> qi::uint_) [qi::_val = new_<Prescaler> (qi::_1, qi::_2)];
46 
47  operand %= (prescale | element);
48 
49  unary = ( operand [qi::_val = qi::_1]
50  | (qi::lit("NOT") >> operand) [qi::_val = new_<OperatorNot> (qi::_1)]
51  );
52 
53  expression = unary [qi::_val = qi::_1]
54  >> *(
55  (qi::lit("AND") >> unary) [qi::_val = new_<OperatorAnd> (qi::_val, qi::_1)]
56  | (qi::lit("OR") >> unary) [qi::_val = new_<OperatorOr> (qi::_val, qi::_1)]
57  );
58  }
59 
60 private:
61  typedef qi::rule<Iterator, std::string(), ascii::space_type> name_rule;
62  typedef qi::rule<Iterator, Evaluator*(), ascii::space_type> rule;
63 
67 
75 };
76 
77 
78 // generic interface for string-like objects
79 template <class T>
80 Evaluator * parse(const T & text) {
81  typedef typename T::const_iterator Iterator;
83  Evaluator * evaluator = 0;
84 
85  Iterator begin = text.begin();
86  Iterator end = text.end();
87 
88  // the interface of qi::phrase_parse has changed between Boost 1.40 (Spirit 2.0) and Boost 1.41 (Spirit 2.1)
89  bool result = qi::phrase_parse( begin, end, parser, ascii::space, evaluator );
90 
91  if (not result or begin != end) {
92  delete evaluator;
93  return 0;
94  }
95 
96  return evaluator;
97 }
98 
99 // overloaded interface for null-terminated strings
100 inline Evaluator * parse(const char * text) {
102  Evaluator * evaluator = 0;
103 
104  const char * begin = text;
105  const char * end = text + strlen(text);
106 
107  // the interface of qi::phrase_parse has changed between Boost 1.40 (Spirit 2.0) and Boost 1.41 (Spirit 2.1)
108  bool result = qi::phrase_parse( begin, end, parser, ascii::space, evaluator );
109 
110  if (not result or begin != end) {
111  delete evaluator;
112  return 0;
113  }
114 
115  return evaluator;
116 }
117 
118 } // namespace triggerExpression
119 
120 #endif // HLTrigger_HLTfilters_TriggerExpressionParser_h
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::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
Evaluator * parse(const T &text)
tuple result
Definition: mps_fire.py:95
tuple text
Definition: runonSM.py:42
#define end
Definition: vmac.h:37
qi::rule< Iterator, std::string(), ascii::space_type > name_rule
#define begin
Definition: vmac.h:30
long double T
qi::rule< Iterator, Evaluator *(), ascii::space_type > rule