diff --git a/FastSimulation/TrackingRecHitProducer/interface/TrackerDetIdSelector.h b/FastSimulation/TrackingRecHitProducer/interface/TrackerDetIdSelector.h index 27e9d551b12de..2492192e4a580 100644 --- a/FastSimulation/TrackingRecHitProducer/interface/TrackerDetIdSelector.h +++ b/FastSimulation/TrackingRecHitProducer/interface/TrackerDetIdSelector.h @@ -5,13 +5,7 @@ #include "DataFormats/TrackerCommon/interface/TrackerTopology.h" #include "FWCore/Utilities/interface/Exception.h" -#include -#include -#include -#include -#include -#include -#include +#include #include #include @@ -110,7 +104,7 @@ class TrackerDetIdSelector { TrackerDetIdSelector(const DetId& detId, const TrackerTopology& trackerTopology) : _detId(detId), _trackerTopology(trackerTopology) {} - bool passSelection(std::string selectionStr) const; + bool passSelection(const std::string& selectionStr) const; }; class Accessor : public boost::static_visitor { @@ -214,69 +208,6 @@ struct WalkAST { } }; -template -struct TrackerDetIdSelectorGrammar : boost::spirit::qi::grammar > { - boost::spirit::qi::rule identifierFctRule; - - boost::spirit::qi::rule identifierRule, expressionRule; - - boost::spirit::qi:: - rule > - 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(std::string selectionStr) const { - std::string::const_iterator begin = selectionStr.cbegin(); - std::string::const_iterator end = selectionStr.cend(); - - TrackerDetIdSelectorGrammar 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<expr); } diff --git a/FastSimulation/TrackingRecHitProducer/src/TrackerDetIdSelector.cc b/FastSimulation/TrackingRecHitProducer/src/TrackerDetIdSelector.cc index 67a788a0948f4..8839f28e03b9f 100644 --- a/FastSimulation/TrackingRecHitProducer/src/TrackerDetIdSelector.cc +++ b/FastSimulation/TrackingRecHitProducer/src/TrackerDetIdSelector.cc @@ -2,6 +2,12 @@ #include "DataFormats/SiStripDetId/interface/StripSubdetector.h" +#include +#include +#include +#include +#include + #define DETIDFCT(NAME) NAME, [](const TrackerTopology& trackerTopology, const DetId& detId) -> int #define TOPOFCT(NAME) \ @@ -118,3 +124,66 @@ ExpressionAST& ExpressionAST::operator!() { expr = UnaryOP(UnaryOP::OP::NEG, expr); return *this; } + +template +struct TrackerDetIdSelectorGrammar : boost::spirit::qi::grammar > { + boost::spirit::qi::rule identifierFctRule; + + boost::spirit::qi::rule identifierRule, expressionRule; + + boost::spirit::qi:: + rule > + 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 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<