CMS 3D CMS Logo

TrackerDetIdSelector.cc
Go to the documentation of this file.
2 
4 
5 #include <boost/config/warning_disable.hpp>
6 #include <boost/spirit/include/qi.hpp>
7 #include <boost/spirit/include/qi_rule.hpp>
8 #include <boost/spirit/include/qi_grammar.hpp>
9 #include <boost/phoenix.hpp>
10 
11 #define DETIDFCT(NAME) NAME, [](const TrackerTopology& trackerTopology, const DetId& detId) -> int
12 
13 #define TOPOFCT(NAME) \
14  #NAME, [](const TrackerTopology& trackerTopology, const DetId& detId) -> int { return trackerTopology.NAME(detId); }
15 
17 
18  {DETIDFCT("subdetId"){return (uint32_t)detId.subdetId();
19 }
20 }
21 ,
22 
24 }
25 }
27 }
28 }
29 , {DETIDFCT("TIB"){return StripSubdetector::TIB;
30 }
31 }
32 , {DETIDFCT("TID"){return StripSubdetector::TID;
33 }
34 }
35 , {DETIDFCT("TOB"){return StripSubdetector::TOB;
36 }
37 }
38 , {DETIDFCT("TEC"){return StripSubdetector::TEC;
39 }
40 }
41 ,
42 
43  {DETIDFCT("BARREL"){return 0;
44 }
45 }
46 , {DETIDFCT("ZMINUS"){return 1;
47 }
48 }
49 , {DETIDFCT("ZPLUS"){return 2;
50 }
51 }
52 ,
53 
54  {TOPOFCT(layer)}, {TOPOFCT(module)}, {TOPOFCT(side)},
55 
56  {TOPOFCT(pxbLadder)}, {TOPOFCT(pxbLayer)}, {TOPOFCT(pxbModule)},
57 
58  {TOPOFCT(pxfBlade)}, {TOPOFCT(pxfDisk)}, {TOPOFCT(pxfModule)}, {TOPOFCT(pxfPanel)}, {TOPOFCT(pxfSide)},
59 
60  {TOPOFCT(tibGlued)}, {TOPOFCT(tibIsDoubleSide)}, {TOPOFCT(tibIsExternalString)}, {TOPOFCT(tibIsInternalString)},
61  {TOPOFCT(tibIsRPhi)}, {TOPOFCT(tibIsStereo)}, {TOPOFCT(tibIsZMinusSide)}, {TOPOFCT(tibIsZPlusSide)},
62  {TOPOFCT(tibLayer)}, {TOPOFCT(tibModule)}, {TOPOFCT(tibOrder)}, {TOPOFCT(tibSide)}, {TOPOFCT(tibStereo)},
63  {TOPOFCT(tibString)},
64 
65  {TOPOFCT(tidGlued)}, {TOPOFCT(tidIsBackRing)}, {TOPOFCT(tidIsDoubleSide)}, {TOPOFCT(tidIsFrontRing)},
66  {TOPOFCT(tidIsRPhi)}, {TOPOFCT(tidIsStereo)}, {TOPOFCT(tidIsZMinusSide)}, {TOPOFCT(tidIsZPlusSide)},
67  {TOPOFCT(tidModule)}, {TOPOFCT(tidOrder)}, {TOPOFCT(tidRing)}, {TOPOFCT(tidSide)}, {TOPOFCT(tidStereo)},
68  {TOPOFCT(tidWheel)},
69 
70  {TOPOFCT(tobGlued)}, {TOPOFCT(tobIsDoubleSide)}, {TOPOFCT(tobIsRPhi)}, {TOPOFCT(tobIsStereo)},
71  {TOPOFCT(tobIsZMinusSide)}, {TOPOFCT(tobIsZPlusSide)}, {TOPOFCT(tobLayer)}, {TOPOFCT(tobModule)}, {TOPOFCT(tobRod)},
72  {TOPOFCT(tobSide)}, {TOPOFCT(tobStereo)},
73 
74  {TOPOFCT(tecGlued)}, {TOPOFCT(tecIsBackPetal)}, {TOPOFCT(tecIsDoubleSide)}, {TOPOFCT(tecIsFrontPetal)},
75  {TOPOFCT(tecIsRPhi)}, {TOPOFCT(tecIsStereo)}, {TOPOFCT(tecIsZMinusSide)}, {TOPOFCT(tecIsZPlusSide)},
76  {TOPOFCT(tecModule)}, {TOPOFCT(tecOrder)}, {TOPOFCT(tecPetalNumber)}, {TOPOFCT(tecRing)}, {TOPOFCT(tecSide)},
77  {TOPOFCT(tecStereo)}, {
78  TOPOFCT(tecWheel)
79 }
80 }
81 ;
82 
83 namespace detail {
85  return BinaryOP(BinaryOP::OP::GREATER, lhs, rhs);
86  }
87 
89  return BinaryOP(BinaryOP::OP::GREATER_EQUAL, lhs, rhs);
90  }
91 
92  ExpressionAST opEq(ExpressionAST const& lhs, ExpressionAST const& rhs) {
93  return BinaryOP(BinaryOP::OP::EQUAL, lhs, rhs);
94  }
95 
97  return BinaryOP(BinaryOP::OP::LESS_EQUAL, lhs, rhs);
98  }
99 
101  return BinaryOP(::BinaryOP::OP::LESS, lhs, rhs);
102  }
103 
105  return BinaryOP(BinaryOP::OP::NOT_EQUAL, lhs, rhs);
106  }
107 
108  ExpressionAST opAnd(ExpressionAST const& lhs, ExpressionAST const& rhs) {
109  return BinaryOP(BinaryOP::OP::AND, lhs, rhs);
110  }
111 
112  ExpressionAST opOr(ExpressionAST const& lhs, ExpressionAST const& rhs) {
113  return BinaryOP(BinaryOP::OP::OR, lhs, rhs);
114  }
115 
116 } // namespace detail
119  return *this;
120 }
121 
122 template <typename ITERATOR>
123 struct TrackerDetIdSelectorGrammar : boost::spirit::qi::grammar<ITERATOR,
124  ExpressionAST(),
125  boost::spirit::ascii::space_type,
126  boost::spirit::qi::locals<ExpressionAST> > {
127  boost::spirit::qi::rule<ITERATOR, std::string(), boost::spirit::ascii::space_type> identifierFctRule;
128 
129  boost::spirit::qi::rule<ITERATOR, ExpressionAST(), boost::spirit::ascii::space_type> identifierRule, expressionRule;
130 
131  boost::spirit::qi::
132  rule<ITERATOR, ExpressionAST(), boost::spirit::ascii::space_type, boost::spirit::qi::locals<ExpressionAST> >
134 
136  namespace qi = boost::spirit::qi;
137  namespace ascii = boost::spirit::ascii;
138  namespace phoenix = boost::phoenix;
139 
140  identifierFctRule = qi::lexeme[+qi::alpha[qi::_val += qi::_1]];
141 
142  identifierRule = (qi::true_[qi::_val = 1] | qi::false_[qi::_val = 0]) | (qi::int_[qi::_val = qi::_1]) |
143  identifierFctRule[qi::_val = qi::_1];
144 
145  comboRule = (expressionRule[qi::_a = qi::_1] >>
146  *((qi::lit("&&") >> expressionRule[qi::_a = qi::_a && qi::_1]) |
147  (qi::lit("||") >> expressionRule[qi::_a = qi::_a || qi::_1])))[qi::_val = qi::_a];
148 
149  expressionRule = qi::lit("(") >> comboRule[qi::_val = qi::_1] >> qi::lit(")") |
150  (identifierRule >> qi::lit(">") >> identifierRule)[qi::_val = qi::_1 > qi::_2] |
151  (identifierRule >> qi::lit(">=") >> identifierRule)[qi::_val = qi::_1 >= qi::_2] |
152  (identifierRule >> qi::lit("<") >> identifierRule)[qi::_val = qi::_1 < qi::_2] |
153  (identifierRule >> qi::lit("<=") >> identifierRule)[qi::_val = qi::_1 <= qi::_2] |
154  (identifierRule >> qi::lit("==") >> identifierRule)[qi::_val = qi::_1 == qi::_2] |
155  (identifierRule >> qi::lit("!=") >> identifierRule)[qi::_val = qi::_1 != qi::_2] |
156  identifierRule[qi::_val = qi::_1];
157  }
158 };
159 
161  std::string::const_iterator begin = selectionStr.cbegin();
162  std::string::const_iterator end = selectionStr.cend();
163 
165  ExpressionAST exprAST;
166 
167  bool success = boost::spirit::qi::phrase_parse(begin, end, grammar, boost::spirit::ascii::space, exprAST);
168  if (begin != end) {
169  throw cms::Exception("FastSimulation/TrackingRecHitProducer/TrackerDetIdSelector",
170  "parsing selection '" + selectionStr + "' failed at " +
171  std::string(selectionStr.cbegin(), begin) + "^^^" + std::string(begin, end));
172  }
173  if (!success) {
174  throw cms::Exception("FastSimulation/TrackingRecHitProducer/TrackerDetIdSelector",
175  "parsing selection '" + selectionStr + "' failed.");
176  }
177  /* Comment out for debugging
178  WalkAST walker(_detId,_trackerTopology);
179  walker(exprAST);
180  std::cout<<std::endl;
181  */
182  return exprAST.evaluate(_detId, _trackerTopology);
183 }
ExpressionAST opGreaterEq(ExpressionAST const &lhs, ExpressionAST const &rhs)
static constexpr auto TEC
bool passSelection(const std::string &selectionStr) const
ExpressionAST opLesserEq(ExpressionAST const &lhs, ExpressionAST const &rhs)
boost::spirit::qi::rule< ITERATOR, ExpressionAST(), boost::spirit::ascii::space_type > expressionRule
#define DETIDFCT(NAME)
ExpressionAST & operator!()
static const StringFunctionMap functionTable
#define TOPOFCT(NAME)
boost::spirit::qi::rule< ITERATOR, ExpressionAST(), boost::spirit::ascii::space_type, boost::spirit::qi::locals< ExpressionAST > > comboRule
const TrackerTopology & _trackerTopology
std::unordered_map< std::string, DetIdFunction > StringFunctionMap
ExpressionAST opOr(ExpressionAST const &lhs, ExpressionAST const &rhs)
static constexpr auto TOB
ExpressionAST opAnd(ExpressionAST const &lhs, ExpressionAST const &rhs)
ExpressionAST opLesser(ExpressionAST const &lhs, ExpressionAST const &rhs)
boost::spirit::qi::rule< ITERATOR, ExpressionAST(), boost::spirit::ascii::space_type > identifierRule
static constexpr auto TIB
int evaluate(const DetId &detId, const TrackerTopology &trackerTopology) const
boost::spirit::qi::rule< ITERATOR, std::string(), boost::spirit::ascii::space_type > identifierFctRule
ExpressionAST opNotEq(ExpressionAST const &lhs, ExpressionAST const &rhs)
static constexpr auto TID
ExpressionAST opEq(ExpressionAST const &lhs, ExpressionAST const &rhs)
ExpressionAST opGreater(ExpressionAST const &lhs, ExpressionAST const &rhs)