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 
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 {
25 public:
26  Parser() :
27  Parser::base_type(expression)
28  {
29  token_l1algo %= qi::raw[qi::lexeme["L1_" >> +(qi::char_("a-zA-Z0-9_*?"))]];
30  token_path %= qi::raw[qi::lexeme[ +(qi::char_("a-zA-Z0-9_*?"))]];
31 
32  token = ( qi::lit("TRUE") [qi::_val = new_<Constant>(true)]
33  | qi::lit("FALSE") [qi::_val = new_<Constant>(false)]
34  | token_l1algo [qi::_val = new_<L1uGTReader>(qi::_1)]
35  | token_path [qi::_val = new_<PathReader>(qi::_1)]
36  );
37 
38  parenthesis %= ('(' >> expression >> ')');
39 
40  element %= (token | parenthesis);
41 
42  prescale = (element >> '/' >> qi::uint_) [qi::_val = new_<Prescaler> (qi::_1, qi::_2)];
43 
44  operand %= (prescale | element);
45 
46  unary = ( operand [qi::_val = qi::_1]
47  | (qi::lit("NOT") >> operand) [qi::_val = new_<OperatorNot> (qi::_1)]
48  );
49 
50  expression = unary [qi::_val = qi::_1]
51  >> *(
52  (qi::lit("AND") >> unary) [qi::_val = new_<OperatorAnd> (qi::_val, qi::_1)]
53  | (qi::lit("OR") >> unary) [qi::_val = new_<OperatorOr> (qi::_val, qi::_1)]
54  );
55  }
56 
57 private:
58  typedef qi::rule<Iterator, std::string(), ascii::space_type> name_rule;
59  typedef qi::rule<Iterator, Evaluator*(), ascii::space_type> rule;
60 
63 
71 };
72 
73 
74 // generic interface for string-like objects
75 template <class T>
76 Evaluator * parse(const T & text) {
77  typedef typename T::const_iterator Iterator;
79  Evaluator * evaluator = 0;
80 
81  Iterator begin = text.begin();
82  Iterator end = text.end();
83 
84  // the interface of qi::phrase_parse has changed between Boost 1.40 (Spirit 2.0) and Boost 1.41 (Spirit 2.1)
85  bool result = qi::phrase_parse( begin, end, parser, ascii::space, evaluator );
86 
87  if (not result or begin != end) {
88  delete evaluator;
89  return 0;
90  }
91 
92  return evaluator;
93 }
94 
95 // overloaded interface for null-terminated strings
96 inline Evaluator * parse(const char * text) {
98  Evaluator * evaluator = 0;
99 
100  const char * begin = text;
101  const char * end = text + strlen(text);
102 
103  // the interface of qi::phrase_parse has changed between Boost 1.40 (Spirit 2.0) and Boost 1.41 (Spirit 2.1)
104  bool result = qi::phrase_parse( begin, end, parser, ascii::space, evaluator );
105 
106  if (not result or begin != end) {
107  delete evaluator;
108  return 0;
109  }
110 
111  return evaluator;
112 }
113 
114 } // namespace triggerExpression
115 
116 #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:84
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