File indexing completed on 2024-04-06 12:11:25
0001 #include "FastSimulation/TrackingRecHitProducer/interface/TrackerDetIdSelector.h"
0002
0003 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0004
0005 #include <boost/config/warning_disable.hpp>
0006 #include <boost/spirit/include/qi.hpp>
0007 #include <boost/spirit/include/qi_rule.hpp>
0008 #include <boost/spirit/include/qi_grammar.hpp>
0009 #include <boost/phoenix.hpp>
0010
0011 #define DETIDFCT(NAME) NAME, [](const TrackerTopology& trackerTopology, const DetId& detId) -> int
0012
0013 #define TOPOFCT(NAME) \
0014 #NAME, [](const TrackerTopology& trackerTopology, const DetId& detId) -> int { return trackerTopology.NAME(detId); }
0015
0016 const TrackerDetIdSelector::StringFunctionMap TrackerDetIdSelector::functionTable = {
0017
0018 {DETIDFCT("subdetId"){return (uint32_t)detId.subdetId();
0019 }
0020 }
0021 ,
0022
0023 {DETIDFCT("BPX"){return PixelSubdetector::PixelBarrel;
0024 }
0025 }
0026 , {DETIDFCT("FPX"){return PixelSubdetector::PixelEndcap;
0027 }
0028 }
0029 , {DETIDFCT("TIB"){return StripSubdetector::TIB;
0030 }
0031 }
0032 , {DETIDFCT("TID"){return StripSubdetector::TID;
0033 }
0034 }
0035 , {DETIDFCT("TOB"){return StripSubdetector::TOB;
0036 }
0037 }
0038 , {DETIDFCT("TEC"){return StripSubdetector::TEC;
0039 }
0040 }
0041 ,
0042
0043 {DETIDFCT("BARREL"){return 0;
0044 }
0045 }
0046 , {DETIDFCT("ZMINUS"){return 1;
0047 }
0048 }
0049 , {DETIDFCT("ZPLUS"){return 2;
0050 }
0051 }
0052 ,
0053
0054 {TOPOFCT(layer)}, {TOPOFCT(module)}, {TOPOFCT(side)},
0055
0056 {TOPOFCT(pxbLadder)}, {TOPOFCT(pxbLayer)}, {TOPOFCT(pxbModule)},
0057
0058 {TOPOFCT(pxfBlade)}, {TOPOFCT(pxfDisk)}, {TOPOFCT(pxfModule)}, {TOPOFCT(pxfPanel)}, {TOPOFCT(pxfSide)},
0059
0060 {TOPOFCT(tibGlued)}, {TOPOFCT(tibIsDoubleSide)}, {TOPOFCT(tibIsExternalString)}, {TOPOFCT(tibIsInternalString)},
0061 {TOPOFCT(tibIsRPhi)}, {TOPOFCT(tibIsStereo)}, {TOPOFCT(tibIsZMinusSide)}, {TOPOFCT(tibIsZPlusSide)},
0062 {TOPOFCT(tibLayer)}, {TOPOFCT(tibModule)}, {TOPOFCT(tibOrder)}, {TOPOFCT(tibSide)}, {TOPOFCT(tibStereo)},
0063 {TOPOFCT(tibString)},
0064
0065 {TOPOFCT(tidGlued)}, {TOPOFCT(tidIsBackRing)}, {TOPOFCT(tidIsDoubleSide)}, {TOPOFCT(tidIsFrontRing)},
0066 {TOPOFCT(tidIsRPhi)}, {TOPOFCT(tidIsStereo)}, {TOPOFCT(tidIsZMinusSide)}, {TOPOFCT(tidIsZPlusSide)},
0067 {TOPOFCT(tidModule)}, {TOPOFCT(tidOrder)}, {TOPOFCT(tidRing)}, {TOPOFCT(tidSide)}, {TOPOFCT(tidStereo)},
0068 {TOPOFCT(tidWheel)},
0069
0070 {TOPOFCT(tobGlued)}, {TOPOFCT(tobIsDoubleSide)}, {TOPOFCT(tobIsRPhi)}, {TOPOFCT(tobIsStereo)},
0071 {TOPOFCT(tobIsZMinusSide)}, {TOPOFCT(tobIsZPlusSide)}, {TOPOFCT(tobLayer)}, {TOPOFCT(tobModule)}, {TOPOFCT(tobRod)},
0072 {TOPOFCT(tobSide)}, {TOPOFCT(tobStereo)},
0073
0074 {TOPOFCT(tecGlued)}, {TOPOFCT(tecIsBackPetal)}, {TOPOFCT(tecIsDoubleSide)}, {TOPOFCT(tecIsFrontPetal)},
0075 {TOPOFCT(tecIsRPhi)}, {TOPOFCT(tecIsStereo)}, {TOPOFCT(tecIsZMinusSide)}, {TOPOFCT(tecIsZPlusSide)},
0076 {TOPOFCT(tecModule)}, {TOPOFCT(tecOrder)}, {TOPOFCT(tecPetalNumber)}, {TOPOFCT(tecRing)}, {TOPOFCT(tecSide)},
0077 {TOPOFCT(tecStereo)}, {
0078 TOPOFCT(tecWheel)
0079 }
0080 }
0081 ;
0082
0083 namespace detail {
0084 ExpressionAST opGreater(ExpressionAST const& lhs, ExpressionAST const& rhs) {
0085 return BinaryOP(BinaryOP::OP::GREATER, lhs, rhs);
0086 }
0087
0088 ExpressionAST opGreaterEq(ExpressionAST const& lhs, ExpressionAST const& rhs) {
0089 return BinaryOP(BinaryOP::OP::GREATER_EQUAL, lhs, rhs);
0090 }
0091
0092 ExpressionAST opEq(ExpressionAST const& lhs, ExpressionAST const& rhs) {
0093 return BinaryOP(BinaryOP::OP::EQUAL, lhs, rhs);
0094 }
0095
0096 ExpressionAST opLesserEq(ExpressionAST const& lhs, ExpressionAST const& rhs) {
0097 return BinaryOP(BinaryOP::OP::LESS_EQUAL, lhs, rhs);
0098 }
0099
0100 ExpressionAST opLesser(ExpressionAST const& lhs, ExpressionAST const& rhs) {
0101 return BinaryOP(::BinaryOP::OP::LESS, lhs, rhs);
0102 }
0103
0104 ExpressionAST opNotEq(ExpressionAST const& lhs, ExpressionAST const& rhs) {
0105 return BinaryOP(BinaryOP::OP::NOT_EQUAL, lhs, rhs);
0106 }
0107
0108 ExpressionAST opAnd(ExpressionAST const& lhs, ExpressionAST const& rhs) {
0109 return BinaryOP(BinaryOP::OP::AND, lhs, rhs);
0110 }
0111
0112 ExpressionAST opOr(ExpressionAST const& lhs, ExpressionAST const& rhs) {
0113 return BinaryOP(BinaryOP::OP::OR, lhs, rhs);
0114 }
0115
0116 }
0117 ExpressionAST& ExpressionAST::operator!() {
0118 expr = UnaryOP(UnaryOP::OP::NEG, expr);
0119 return *this;
0120 }
0121
0122 template <typename ITERATOR>
0123 struct TrackerDetIdSelectorGrammar : boost::spirit::qi::grammar<ITERATOR,
0124 ExpressionAST(),
0125 boost::spirit::ascii::space_type,
0126 boost::spirit::qi::locals<ExpressionAST> > {
0127 boost::spirit::qi::rule<ITERATOR, std::string(), boost::spirit::ascii::space_type> identifierFctRule;
0128
0129 boost::spirit::qi::rule<ITERATOR, ExpressionAST(), boost::spirit::ascii::space_type> identifierRule, expressionRule;
0130
0131 boost::spirit::qi::
0132 rule<ITERATOR, ExpressionAST(), boost::spirit::ascii::space_type, boost::spirit::qi::locals<ExpressionAST> >
0133 comboRule;
0134
0135 TrackerDetIdSelectorGrammar() : TrackerDetIdSelectorGrammar::base_type(comboRule) {
0136 namespace qi = boost::spirit::qi;
0137 namespace ascii = boost::spirit::ascii;
0138 namespace phoenix = boost::phoenix;
0139
0140 identifierFctRule = qi::lexeme[+qi::alpha[qi::_val += qi::_1]];
0141
0142 identifierRule = (qi::true_[qi::_val = 1] | qi::false_[qi::_val = 0]) | (qi::int_[qi::_val = qi::_1]) |
0143 identifierFctRule[qi::_val = qi::_1];
0144
0145 comboRule = (expressionRule[qi::_a = qi::_1] >>
0146 *((qi::lit("&&") >> expressionRule[qi::_a = qi::_a && qi::_1]) |
0147 (qi::lit("||") >> expressionRule[qi::_a = qi::_a || qi::_1])))[qi::_val = qi::_a];
0148
0149 expressionRule = qi::lit("(") >> comboRule[qi::_val = qi::_1] >> qi::lit(")") |
0150 (identifierRule >> qi::lit(">") >> identifierRule)[qi::_val = qi::_1 > qi::_2] |
0151 (identifierRule >> qi::lit(">=") >> identifierRule)[qi::_val = qi::_1 >= qi::_2] |
0152 (identifierRule >> qi::lit("<") >> identifierRule)[qi::_val = qi::_1 < qi::_2] |
0153 (identifierRule >> qi::lit("<=") >> identifierRule)[qi::_val = qi::_1 <= qi::_2] |
0154 (identifierRule >> qi::lit("==") >> identifierRule)[qi::_val = qi::_1 == qi::_2] |
0155 (identifierRule >> qi::lit("!=") >> identifierRule)[qi::_val = qi::_1 != qi::_2] |
0156 identifierRule[qi::_val = qi::_1];
0157 }
0158 };
0159
0160 bool TrackerDetIdSelector::passSelection(const std::string& selectionStr) const {
0161 std::string::const_iterator begin = selectionStr.cbegin();
0162 std::string::const_iterator end = selectionStr.cend();
0163
0164 TrackerDetIdSelectorGrammar<std::string::const_iterator> grammar;
0165 ExpressionAST exprAST;
0166
0167 bool success = boost::spirit::qi::phrase_parse(begin, end, grammar, boost::spirit::ascii::space, exprAST);
0168 if (begin != end) {
0169 throw cms::Exception("FastSimulation/TrackingRecHitProducer/TrackerDetIdSelector",
0170 "parsing selection '" + selectionStr + "' failed at " +
0171 std::string(selectionStr.cbegin(), begin) + "^^^" + std::string(begin, end));
0172 }
0173 if (!success) {
0174 throw cms::Exception("FastSimulation/TrackingRecHitProducer/TrackerDetIdSelector",
0175 "parsing selection '" + selectionStr + "' failed.");
0176 }
0177
0178
0179
0180
0181
0182 return exprAST.evaluate(_detId, _trackerTopology);
0183 }