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_hlt %= qi::raw[qi::lexeme["HLT_" >> +(qi::char_("a-zA-Z0-9_*?"))]];
31  token_alca %= qi::raw[qi::lexeme["AlCa_" >> +(qi::char_("a-zA-Z0-9_*?"))]];
32  token_dqm %= qi::raw[qi::lexeme["DQM_" >> +(qi::char_("a-zA-Z0-9_*?"))]];
33  token_dst %= qi::raw[qi::lexeme["DST_" >> +(qi::char_("a-zA-Z0-9_*?"))]];
34  token_step %= qi::raw[qi::lexeme["generation_step"]];
35  token_l1 %= qi::raw[qi::lexeme["L1_" >> +(qi::char_("a-zA-Z0-9_*?"))]];
36  token_l1tech %= qi::raw[qi::lexeme["L1Tech_" >> +(qi::char_("a-zA-Z0-9_*?"))]];
37 
38  token = ( token_hlt [qi::_val = new_<HLTReader>(qi::_1)]
39  | token_alca [qi::_val = new_<HLTReader>(qi::_1)]
40  | token_dqm [qi::_val = new_<HLTReader>(qi::_1)]
41  | token_dst [qi::_val = new_<HLTReader>(qi::_1)]
42  | token_step [qi::_val = new_<HLTReader>(qi::_1)]
43  | token_l1 [qi::_val = new_<L1Reader>(qi::_1)]
44  | token_l1tech [qi::_val = new_<L1TechReader>(qi::_1)]
45  | qi::lit("TRUE") [qi::_val = new_<Constant>(true)]
46  | qi::lit("FALSE") [qi::_val = new_<Constant>(false)]
47  );
48 
49  parenthesis %= ('(' >> expression >> ')');
50 
51  element %= (token | parenthesis);
52 
53  prescale = (element >> '/' >> qi::uint_) [qi::_val = new_<Prescaler> (qi::_1, qi::_2)];
54 
55  operand %= (prescale | element);
56 
57  unary = ( operand [qi::_val = qi::_1]
58  | (qi::lit("NOT") >> operand) [qi::_val = new_<OperatorNot> (qi::_1)]
59  );
60 
61  expression = unary [qi::_val = qi::_1]
62  >> *(
63  (qi::lit("AND") >> unary) [qi::_val = new_<OperatorAnd> (qi::_val, qi::_1)]
64  | (qi::lit("OR") >> unary) [qi::_val = new_<OperatorOr> (qi::_val, qi::_1)]
65  );
66  }
67 
68 private:
69  typedef qi::rule<Iterator, unused_type(), ascii::space_type> void_rule;
70  typedef qi::rule<Iterator, std::string(), ascii::space_type> name_rule;
71  typedef qi::rule<Iterator, Evaluator*(), ascii::space_type> rule;
72 
80 
88 };
89 
90 
91 // generic interface for string-like objects
92 template <class T>
93 Evaluator * parse(const T & text) {
94  typedef typename T::const_iterator Iterator;
96  Evaluator * evaluator = 0;
97 
98  Iterator begin = text.begin();
99  Iterator end = text.end();
100 
101  // the interface of qi::phrase_parse has changed between Boost 1.40 (Spirit 2.0) and Boost 1.41 (Spirit 2.1)
102  bool result = qi::phrase_parse( begin, end, parser, ascii::space, evaluator );
103 
104  if (not result or begin != end) {
105  delete evaluator;
106  return 0;
107  }
108 
109  return evaluator;
110 }
111 
112 // overloaded interface for null-terminated strings
113 inline Evaluator * parse(const char * text) {
115  Evaluator * evaluator = 0;
116 
117  const char * begin = text;
118  const char * end = text + strlen(text);
119 
120  // the interface of qi::phrase_parse has changed between Boost 1.40 (Spirit 2.0) and Boost 1.41 (Spirit 2.1)
121  bool result = qi::phrase_parse( begin, end, parser, ascii::space, evaluator );
122 
123  if (not result or begin != end) {
124  delete evaluator;
125  return 0;
126  }
127 
128  return evaluator;
129 }
130 
131 } // namespace triggerExpression
132 
133 #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
qi::rule< Iterator, unused_type(), ascii::space_type > void_rule
Evaluator * parse(const T &text)
tuple result
Definition: query.py:137
tuple text
Definition: runonSM.py:42
#define end
Definition: vmac.h:38
qi::rule< Iterator, std::string(), ascii::space_type > name_rule
#define begin
Definition: vmac.h:31
long double T
qi::rule< Iterator, Evaluator *(), ascii::space_type > rule