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_l1 %= qi::raw[qi::lexeme["L1_" >> +(qi::char_("a-zA-Z0-9_*?"))]];
33  token_l1tech %= qi::raw[qi::lexeme["L1Tech_" >> +(qi::char_("a-zA-Z0-9_*?"))]];
34 
35  token = ( token_hlt [qi::_val = new_<HLTReader>(qi::_1)]
36  | token_alca [qi::_val = new_<HLTReader>(qi::_1)]
37  | token_l1 [qi::_val = new_<L1Reader>(qi::_1)]
38  | token_l1tech [qi::_val = new_<L1TechReader>(qi::_1)]
39  | qi::lit("TRUE") [qi::_val = new_<Constant>(true)]
40  | qi::lit("FALSE") [qi::_val = new_<Constant>(false)]
41  );
42 
43  parenthesis %= ('(' >> expression >> ')');
44 
45  element %= (token | parenthesis);
46 
47  prescale = (element >> '/' >> qi::uint_) [qi::_val = new_<Prescaler> (qi::_1, qi::_2)];
48 
49  operand %= (prescale | element);
50 
51  unary = ( operand [qi::_val = qi::_1]
52  | (qi::lit("NOT") >> operand) [qi::_val = new_<OperatorNot> (qi::_1)]
53  );
54 
55  expression = unary [qi::_val = qi::_1]
56  >> *(
57  (qi::lit("AND") >> unary) [qi::_val = new_<OperatorAnd> (qi::_val, qi::_1)]
58  | (qi::lit("OR") >> unary) [qi::_val = new_<OperatorOr> (qi::_val, qi::_1)]
59  );
60  }
61 
62 private:
63  typedef qi::rule<Iterator, unused_type(), ascii::space_type> void_rule;
64  typedef qi::rule<Iterator, std::string(), ascii::space_type> name_rule;
65  typedef qi::rule<Iterator, Evaluator*(), ascii::space_type> rule;
66 
71 
79 };
80 
81 
82 // generic interface for string-like objects
83 template <class T>
84 Evaluator * parse(const T & text) {
85  typedef typename T::const_iterator Iterator;
87  Evaluator * evaluator = 0;
88 
89  Iterator begin = text.begin();
90  Iterator end = text.end();
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 0;
98  }
99 
100  return evaluator;
101 }
102 
103 // overloaded interface for null-terminated strings
104 inline Evaluator * parse(const char * text) {
106  Evaluator * evaluator = 0;
107 
108  const char * begin = text;
109  const char * end = text + strlen(text);
110 
111  // the interface of qi::phrase_parse has changed between Boost 1.40 (Spirit 2.0) and Boost 1.41 (Spirit 2.1)
112  bool result = qi::phrase_parse( begin, end, parser, ascii::space, evaluator );
113 
114  if (not result or begin != end) {
115  delete evaluator;
116  return 0;
117  }
118 
119  return evaluator;
120 }
121 
122 } // namespace triggerExpression
123 
124 #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