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