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/spirit/include/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 
85  return ast;
86 }
87 
90  return ast;
91 }
92 
95  return ast;
96 }
97 
100  return ast;
101 }
102 
104  ExpressionAST ast = BinaryOP(::BinaryOP::OP::LESS, lhs, rhs);
105  return ast;
106 }
107 
110  return ast;
111 }
112 
114  ExpressionAST ast = BinaryOP(BinaryOP::OP::AND, lhs, rhs);
115  return ast;
116 }
117 
119  ExpressionAST ast = BinaryOP(BinaryOP::OP::OR, lhs, rhs);
120  return ast;
121 }
122 
125  return *this;
126 }
127 
128 template <typename ITERATOR>
129 struct TrackerDetIdSelectorGrammar : boost::spirit::qi::grammar<ITERATOR,
130  ExpressionAST(),
131  boost::spirit::ascii::space_type,
132  boost::spirit::qi::locals<ExpressionAST> > {
133  boost::spirit::qi::rule<ITERATOR, std::string(), boost::spirit::ascii::space_type> identifierFctRule;
134 
135  boost::spirit::qi::rule<ITERATOR, ExpressionAST(), boost::spirit::ascii::space_type> identifierRule, expressionRule;
136 
137  boost::spirit::qi::
138  rule<ITERATOR, ExpressionAST(), boost::spirit::ascii::space_type, boost::spirit::qi::locals<ExpressionAST> >
140 
142  namespace qi = boost::spirit::qi;
143  namespace ascii = boost::spirit::ascii;
144  namespace phoenix = boost::phoenix;
145 
146  identifierFctRule = qi::lexeme[+qi::alpha[qi::_val += qi::_1]];
147 
148  identifierRule = (qi::true_[qi::_val = 1] | qi::false_[qi::_val = 0]) | (qi::int_[qi::_val = qi::_1]) |
149  identifierFctRule[qi::_val = qi::_1];
150 
151  comboRule = (expressionRule[qi::_a = qi::_1] >>
152  *((qi::lit("&&") >> expressionRule[qi::_a = qi::_a && qi::_1]) |
153  (qi::lit("||") >> expressionRule[qi::_a = qi::_a || qi::_1])))[qi::_val = qi::_a];
154 
155  expressionRule = qi::lit("(") >> comboRule[qi::_val = qi::_1] >> qi::lit(")") |
156  (identifierRule >> qi::lit(">") >> identifierRule)[qi::_val = qi::_1 > qi::_2] |
157  (identifierRule >> qi::lit(">=") >> identifierRule)[qi::_val = qi::_1 >= qi::_2] |
158  (identifierRule >> qi::lit("<") >> identifierRule)[qi::_val = qi::_1 < qi::_2] |
159  (identifierRule >> qi::lit("<=") >> identifierRule)[qi::_val = qi::_1 <= qi::_2] |
160  (identifierRule >> qi::lit("==") >> identifierRule)[qi::_val = qi::_1 == qi::_2] |
161  (identifierRule >> qi::lit("!=") >> identifierRule)[qi::_val = qi::_1 != qi::_2] |
162  identifierRule[qi::_val = qi::_1];
163  }
164 };
165 
167  std::string::const_iterator begin = selectionStr.cbegin();
168  std::string::const_iterator end = selectionStr.cend();
169 
171  ExpressionAST exprAST;
172 
173  bool success = boost::spirit::qi::phrase_parse(begin, end, grammar, boost::spirit::ascii::space, exprAST);
174  if (begin != end) {
175  throw cms::Exception("FastSimulation/TrackingRecHitProducer/TrackerDetIdSelector",
176  "parsing selection '" + selectionStr + "' failed at " +
177  std::string(selectionStr.cbegin(), begin) + "^^^" + std::string(begin, end));
178  }
179  if (!success) {
180  throw cms::Exception("FastSimulation/TrackingRecHitProducer/TrackerDetIdSelector",
181  "parsing selection '" + selectionStr + "' failed.");
182  }
183  /* Comment out for debugging
184  WalkAST walker(_detId,_trackerTopology);
185  walker(exprAST);
186  std::cout<<std::endl;
187  */
188  return exprAST.evaluate(_detId, _trackerTopology);
189 }
operator>
ExpressionAST operator>(ExpressionAST const &lhs, ExpressionAST const &rhs)
Definition: TrackerDetIdSelector.cc:83
BinaryOP::OP::LESS
ExpressionAST
Definition: TrackerDetIdSelector.h:20
PixelSubdetector::PixelEndcap
Definition: PixelSubdetector.h:11
PixelSubdetector::PixelBarrel
Definition: PixelSubdetector.h:11
TrackerDetIdSelector.h
TrackerDetIdSelectorGrammar::identifierRule
boost::spirit::qi::rule< ITERATOR, ExpressionAST(), boost::spirit::ascii::space_type > identifierRule
Definition: TrackerDetIdSelector.cc:135
operator==
ExpressionAST operator==(ExpressionAST const &lhs, ExpressionAST const &rhs)
Definition: TrackerDetIdSelector.cc:93
BinaryOP::OP::LESS_EQUAL
alpha
float alpha
Definition: AMPTWrapper.h:105
TrackerDetIdSelectorGrammar::TrackerDetIdSelectorGrammar
TrackerDetIdSelectorGrammar()
Definition: TrackerDetIdSelector.cc:141
ExpressionAST::evaluate
int evaluate(const DetId &detId, const TrackerTopology &trackerTopology) const
Definition: TrackerDetIdSelector.h:211
DETIDFCT
#define DETIDFCT(NAME)
Definition: TrackerDetIdSelector.cc:11
TrackerDetIdSelector::_trackerTopology
const TrackerTopology & _trackerTopology
Definition: TrackerDetIdSelector.h:97
trigObjTnPSource_cfi.selectionStr
selectionStr
Definition: trigObjTnPSource_cfi.py:69
TrackerDetIdSelectorGrammar::identifierFctRule
boost::spirit::qi::rule< ITERATOR, std::string(), boost::spirit::ascii::space_type > identifierFctRule
Definition: TrackerDetIdSelector.cc:133
operator>=
ExpressionAST operator>=(ExpressionAST const &lhs, ExpressionAST const &rhs)
Definition: TrackerDetIdSelector.cc:88
BinaryOP::OP::OR
BinaryOP::OP::AND
mps_fire.end
end
Definition: mps_fire.py:242
summarizeEdmComparisonLogfiles.success
success
Definition: summarizeEdmComparisonLogfiles.py:114
StripSubdetector::TIB
static constexpr auto TIB
Definition: StripSubdetector.h:16
UnaryOP
Definition: TrackerDetIdSelector.h:80
phase1PixelTopology::layer
constexpr std::array< uint8_t, layerIndexSize > layer
Definition: phase1PixelTopology.h:99
TrackerDetIdSelectorGrammar::expressionRule
boost::spirit::qi::rule< ITERATOR, ExpressionAST(), boost::spirit::ascii::space_type > expressionRule
Definition: TrackerDetIdSelector.cc:135
BinaryOP::OP::GREATER_EQUAL
operator||
ExpressionAST operator||(ExpressionAST const &lhs, ExpressionAST const &rhs)
Definition: TrackerDetIdSelector.cc:118
UnaryOP::OP::NEG
TOPOFCT
#define TOPOFCT(NAME)
Definition: TrackerDetIdSelector.cc:13
operator<=
ExpressionAST operator<=(ExpressionAST const &lhs, ExpressionAST const &rhs)
Definition: TrackerDetIdSelector.cc:98
operator!=
ExpressionAST operator!=(ExpressionAST const &lhs, ExpressionAST const &rhs)
Definition: TrackerDetIdSelector.cc:108
operator<
ExpressionAST operator<(ExpressionAST const &lhs, ExpressionAST const &rhs)
Definition: TrackerDetIdSelector.cc:103
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
callgraph.module
module
Definition: callgraph.py:61
BinaryOP::OP::GREATER
StripSubdetector::TEC
static constexpr auto TEC
Definition: StripSubdetector.h:19
TrackerDetIdSelector::passSelection
bool passSelection(const std::string &selectionStr) const
Definition: TrackerDetIdSelector.cc:166
ExpressionAST::operator!
ExpressionAST & operator!()
Definition: TrackerDetIdSelector.cc:123
Exception
Definition: hltDiff.cc:245
BinaryOP
Definition: TrackerDetIdSelector.h:50
StripSubdetector::TOB
static constexpr auto TOB
Definition: StripSubdetector.h:18
TrackerDetIdSelector::functionTable
const static StringFunctionMap functionTable
Definition: TrackerDetIdSelector.h:102
TrackerDetIdSelectorGrammar::comboRule
boost::spirit::qi::rule< ITERATOR, ExpressionAST(), boost::spirit::ascii::space_type, boost::spirit::qi::locals< ExpressionAST > > comboRule
Definition: TrackerDetIdSelector.cc:139
ExpressionAST::expr
Type expr
Definition: TrackerDetIdSelector.h:38
TrackerDetIdSelectorGrammar
Definition: TrackerDetIdSelector.cc:129
TrackerDetIdSelector::_detId
const DetId & _detId
Definition: TrackerDetIdSelector.h:96
BinaryOP::OP::NOT_EQUAL
StripSubdetector.h
TrackerDetIdSelector::StringFunctionMap
std::unordered_map< std::string, DetIdFunction > StringFunctionMap
Definition: TrackerDetIdSelector.h:101
StripSubdetector::TID
static constexpr auto TID
Definition: StripSubdetector.h:17
operator&&
ExpressionAST operator&&(ExpressionAST const &lhs, ExpressionAST const &rhs)
Definition: TrackerDetIdSelector.cc:113
BinaryOP::OP::EQUAL