28 #include <boost/spirit/include/qi.hpp> 37 #include <unordered_map> 44 namespace qi = boost::spirit::qi;
45 namespace ascii = boost::spirit::ascii;
55 virtual const char*
pathName()
const {
return ""; }
57 virtual void setLeft(std::unique_ptr<Evaluator>&&) {}
58 virtual void setRight(std::unique_ptr<Evaluator>&&) {}
103 template <
typename T>
180 std::unique_ptr<Evaluator>& backEvaluator =
operatorStack.back();
190 std::unique_ptr<Evaluator>& backEvaluator =
operatorStack.back();
199 std::unique_ptr<Evaluator>& backEvaluator =
operatorStack.back();
213 std::unique_ptr<Evaluator>& backEvaluator =
operatorStack.back();
229 std::unique_ptr<Evaluator>& backEvaluator =
operatorStack.back();
244 std::unique_ptr<Evaluator>& backEvaluator =
operatorStack.back();
248 throw cms::Exception(
"LogicError") <<
"Should be impossible to get this error. Contact a Framework developer";
259 throw cms::Exception(
"LogicError") <<
"Should be impossible to get this error. Contact a Framework developer";
275 template <
typename Iterator>
276 class Grammar :
public qi::grammar<Iterator, ascii::space_type> {
337 std::shared_ptr<std::unordered_map<std::string, unsigned int>> globalBeginRun(
edm::Run const&,
344 bool initialized_ =
false;
345 int bunchCrossingEmu_ = 0;
352 algoDesc.
add<
double>(
"prescale", 1);
353 algoDesc.
add<
double>(
"prescalePreview", 1);
354 algoDesc.
add<std::vector<unsigned int>>(
"bunchMask", {});
356 algoDesc.
add<std::vector<int>>(
"triggerTypes", {1});
357 algoDesc.
add<
bool>(
"veto",
false);
360 desc.addVPSet(
"algorithms", algoDesc);
366 : getterOfPassedReferences_(
edm::TypeMatch(), this) {
381 throw cms::Exception(
"Configuration") <<
"Syntax error in logical expression. Here is an example of how\n" 382 <<
"the syntax should look:\n" 383 <<
" \"path1 and not (path2 or not path3)\"\n" 384 <<
"The expression must contain alternating appearances of operands\n" 385 <<
"which are path names and binary operators which can be \'and\'\n" 386 <<
"or \'or\', with a path name at the beginning and end. There\n" 387 <<
"must be at least one path name. In addition to the alternating\n" 388 <<
"path names and binary operators, the unary operator \'not\' can\n" 389 <<
"be inserted before a path name or a begin parenthesis.\n" 390 <<
"Parentheses are allowed. Parentheses must come in matching pairs.\n" 391 <<
"Matching begin and end parentheses must contain a complete and\n" 392 <<
"syntactically correct logical expression. There must be at least\n" 393 <<
"one space or parenthesis between operators and path names. Extra\n" 394 <<
"space is ignored and OK. Path names can only contain upper and\n" 395 <<
"lower case letters, numbers, and underscores. A path name cannot\n" 396 <<
"be the same as an operator name.\n";
406 double dPrescale =
algoConfig.getParameter<
double>(
"prescale");
407 if ((dPrescale < 1. || dPrescale >=
std::pow(2, 24) / 100 - 1) && dPrescale != 0) {
409 <<
"Prescale value error. Expected prescale value between 1 and 2^24/100 - 1 or 0 got " << dPrescale <<
"." 413 definition.
prescale_ = std::round(dPrescale * 100);
415 double dPrescalePreview =
algoConfig.getParameter<
double>(
"prescalePreview");
416 if ((dPrescalePreview < 1. || dPrescalePreview >=
std::pow(2, 24) / 100 - 1) && dPrescalePreview != 0) {
418 <<
"PrescalePreview value error. Expected prescale value between 1 and 2^24/100 - 1 or 0 got " 419 << dPrescalePreview <<
"." << std::endl;
424 std::vector<unsigned int> vBunchMask =
algoConfig.getParameter<std::vector<unsigned int>>(
"bunchMask");
426 std::set<unsigned int>(std::make_move_iterator(vBunchMask.begin()), std::make_move_iterator(vBunchMask.end()));
439 <<
"Algorithm " << iter->first <<
" already exists. Algorithm names must be unique." << std::endl;
444 produces<P2GTAlgoBlockMap>();
458 if (
pset->existsAs<std::vector<std::string>>(
pathName)) {
462 const auto& modPSet =
pset->getParameterSet(
mod);
463 if (modPSet.getParameter<
std::string>(
"@module_edm_type") ==
"EDFilter") {
464 if (modPSet.getParameter<
std::string>(
"@module_type") ==
"L1GTSingleObjectCond") {
466 }
else if (modPSet.getParameter<
std::string>(
"@module_type") ==
"L1GTDoubleObjectCond") {
467 algoDef.filtModules_.insert(
469 algoDef.filtModules_.insert(
471 }
else if (modPSet.getParameter<
std::string>(
"@module_type") ==
"L1GTTripleObjectCond") {
472 algoDef.filtModules_.insert(
474 algoDef.filtModules_.insert(
476 algoDef.filtModules_.insert(
478 }
else if (modPSet.getParameter<
std::string>(
"@module_type") ==
"L1GTQuadObjectCond") {
479 algoDef.filtModules_.insert(
481 algoDef.filtModules_.insert(
483 algoDef.filtModules_.insert(
485 algoDef.filtModules_.insert(
499 return std::make_shared<std::unordered_map<std::string, unsigned int>>();
508 std::vector<edm::Handle<P2GTCandidateVectorRef>>
handles;
511 std::unique_ptr<P2GTAlgoBlockMap>
algoCollection = std::make_unique<P2GTAlgoBlockMap>();
513 std::unordered_map<std::string, unsigned int>& prescaleCounters = *runCache(
event.getRun().index());
515 int bunchCrossing =
event.isRealData() ?
event.bunchCrossing() :
bunchCrossingEmu_ + 1;
518 bool decisionBeforeBxAndPrescale = algoDef.evaluator_->evaluate(
event);
519 bool decisionBeforePrescale = decisionBeforeBxAndPrescale && algoDef.bunchMask_.count(bunchCrossing) == 0;
520 bool decisionFinal =
false;
521 bool decisionFinalPreview =
false;
523 if (algoDef.prescale_ != 0 && decisionBeforePrescale) {
524 if (prescaleCounters.count(
name) > 0) {
525 prescaleCounters[
name] += 100;
527 prescaleCounters[
name] = 100;
530 if (prescaleCounters[
name] >= algoDef.prescale_) {
531 decisionFinal =
true;
532 prescaleCounters[
name] -= algoDef.prescale_;
534 decisionFinal =
false;
538 if (algoDef.prescalePreview_ != 0 && decisionBeforePrescale) {
540 if (prescaleCounters.count(previewName) > 0) {
541 prescaleCounters[previewName] += 100;
543 prescaleCounters[previewName] = 100;
546 if (prescaleCounters[previewName] >= algoDef.prescalePreview_) {
547 decisionFinalPreview =
true;
548 prescaleCounters[previewName] -= algoDef.prescalePreview_;
550 decisionFinalPreview =
false;
561 if (algoDef.filtModules_.count({module, instance}) > 0) {
562 trigObjects.insert(trigObjects.end(),
handle->begin(),
handle->end());
569 decisionBeforePrescale,
571 decisionFinalPreview,
573 algoDef.triggerTypes_,
virtual bool evaluate(edm::Event const &event) const
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void callWhenNewProductsRegistered(std::function< void(BranchDescription const &)> const &func)
qi::rule< Iterator, ascii::space_type > expression
static void fillDescriptions(edm::ConfigurationDescriptions &)
bool getMapped(key_type const &k, value_type &result) const
std::vector< std::string > pathNames_
void setRight(std::unique_ptr< Evaluator > &&v) override
void moveBinaryOperator()
std::set< std::tuple< std::string, std::string > > filtModules_
void addPathName(std::vector< char > const &s)
static PFTauRenderPlugin instance
unsigned int prescalePreview_
virtual void setRight(std::unique_ptr< Evaluator > &&)
edm::propagate_const< std::unique_ptr< pathStatusExpression::Evaluator > > evaluator_
void init(edm::ConsumesCollector &iC) override
virtual void init(edm::ConsumesCollector &)
qi::rule< Iterator > binaryOperator
EvaluatorType type() const override
std::vector< std::unique_ptr< Evaluator > > operandStack
void produce(edm::Event &, const edm::EventSetup &) override
qi::rule< Iterator > unaryOperator
bool getConfigurationForProcess(std::string const &name, ProcessConfiguration &config) const
void print(std::ostream &out, unsigned int indentation) const override
std::map< std::string, AlgoDefinition > algoDefinitions_
void setLeft(std::unique_ptr< Evaluator > &&v) override
qi::rule< Iterator > afterOperator
edm::EDGetTokenT< edm::PathStatus > token_
edm::propagate_const< std::unique_ptr< Evaluator > > left_
bool evaluate(edm::Event const &event) const override
edm::propagate_const< std::unique_ptr< Evaluator > > right_
void init(edm::ConsumesCollector &iC) override
L1GTAlgoBlockProducer(const edm::ParameterSet &)
std::vector< BaseVolumeHandle * > handles
void print(std::ostream &out, unsigned int indentation) const override
EvaluatorType type() const override
edm::propagate_const< std::unique_ptr< Evaluator > > operand_
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
virtual EvaluatorType type() const =0
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
EvaluatorType type() const override
Operand(std::vector< char > const &pathName)
#define DEFINE_FWK_MODULE(type)
edm::GetterOfProducts< P2GTCandidateVectorRef > getterOfPassedReferences_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void init(const edm::ProcessHistory &)
virtual const char * pathName() const
def getProcessName(pdgGen, requiredNumberOfGeneratedObjects)
void fillHandles(ProductContainer const &productContainer, std::vector< edm::Handle< T >> &handles) const
void print(std::ostream &out, unsigned int indentation) const override
void addBeginParenthesis()
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
qi::rule< Iterator > pathName
std::vector< std::string > pathNames_
virtual void print(std::ostream &out, unsigned int indentation) const
bool evaluate(edm::Event const &event) const override
void init(edm::ConsumesCollector &iC) override
qi::rule< Iterator, ascii::space_type > binaryOperand
virtual void setLeft(std::unique_ptr< Evaluator > &&)
EvaluatorType type() const override
std::vector< P2GTCandidateRef > P2GTCandidateVectorRef
std::vector< std::unique_ptr< Evaluator > > operatorStack
bool evaluate(edm::Event const &event) const override
void setLeft(std::unique_ptr< Evaluator > &&v) override
std::shared_ptr< std::unordered_map< std::string, unsigned int > > globalBeginRun(edm::Run const &, edm::EventSetup const &) const override
const std::vector< std::string > & pathNames()
std::set< unsigned int > bunchMask_
qi::rule< Iterator > binaryOperatorTest
void globalEndRun(edm::Run const &, edm::EventSetup const &) override
T mod(const T &a, const T &b)
std::unique_ptr< Evaluator > finish()
Grammar(ShuntingYardAlgorithm *algorithm)
ShuntingYardAlgorithm * algorithm_
Power< A, B >::type pow(const A &a, const B &b)
static Registry * instance()