diff --git a/HLTrigger/HLTcore/interface/TriggerExpressionConstant.h b/HLTrigger/HLTcore/interface/TriggerExpressionConstant.h index 7636b96a1c17e..64d710aeffb3f 100644 --- a/HLTrigger/HLTcore/interface/TriggerExpressionConstant.h +++ b/HLTrigger/HLTcore/interface/TriggerExpressionConstant.h @@ -1,5 +1,5 @@ -#ifndef HLTrigger_HLTfilters_TriggerExpressionConstant_h -#define HLTrigger_HLTfilters_TriggerExpressionConstant_h +#ifndef HLTrigger_HLTcore_TriggerExpressionConstant_h +#define HLTrigger_HLTcore_TriggerExpressionConstant_h #include "HLTrigger/HLTcore/interface/TriggerExpressionEvaluator.h" @@ -13,7 +13,7 @@ namespace triggerExpression { bool operator()(const Data& data) const override { return m_value; } - void dump(std::ostream& out) const override { out << (m_value ? "TRUE" : "FALSE"); } + void dump(std::ostream& out, bool const ignoreMasks = false) const override { out << (m_value ? "TRUE" : "FALSE"); } private: bool m_value; @@ -21,4 +21,4 @@ namespace triggerExpression { } // namespace triggerExpression -#endif // HLTrigger_HLTfilters_TriggerExpressionConstant_h +#endif // HLTrigger_HLTcore_TriggerExpressionConstant_h diff --git a/HLTrigger/HLTcore/interface/TriggerExpressionData.h b/HLTrigger/HLTcore/interface/TriggerExpressionData.h index 918d4dc99a8d0..b4181e5bbcdd7 100644 --- a/HLTrigger/HLTcore/interface/TriggerExpressionData.h +++ b/HLTrigger/HLTcore/interface/TriggerExpressionData.h @@ -1,5 +1,5 @@ -#ifndef HLTrigger_HLTfilters_TriggerExpressionData_h -#define HLTrigger_HLTfilters_TriggerExpressionData_h +#ifndef HLTrigger_HLTcore_TriggerExpressionData_h +#define HLTrigger_HLTcore_TriggerExpressionData_h #include "FWCore/Framework/interface/ConsumesCollector.h" #include "FWCore/Utilities/interface/InputTag.h" @@ -220,4 +220,4 @@ namespace triggerExpression { } // namespace triggerExpression -#endif // HLTrigger_HLTfilters_TriggerExpressionData_h +#endif // HLTrigger_HLTcore_TriggerExpressionData_h diff --git a/HLTrigger/HLTcore/interface/TriggerExpressionEvaluator.h b/HLTrigger/HLTcore/interface/TriggerExpressionEvaluator.h index 1a8154ab34782..09ff7e3d2f2ad 100644 --- a/HLTrigger/HLTcore/interface/TriggerExpressionEvaluator.h +++ b/HLTrigger/HLTcore/interface/TriggerExpressionEvaluator.h @@ -1,9 +1,10 @@ -#ifndef HLTrigger_HLTfilters_TriggerExpressionEvaluator_h -#define HLTrigger_HLTfilters_TriggerExpressionEvaluator_h +#ifndef HLTrigger_HLTcore_TriggerExpressionEvaluator_h +#define HLTrigger_HLTcore_TriggerExpressionEvaluator_h #include #include #include +#include namespace triggerExpression { @@ -13,6 +14,9 @@ namespace triggerExpression { public: Evaluator() = default; + // virtual destructor + virtual ~Evaluator() = default; + // check if the data satisfies the logical expression virtual bool operator()(const Data& data) const = 0; @@ -22,14 +26,22 @@ namespace triggerExpression { // list CMSSW path patterns associated to the logical expression virtual std::vector patterns() const { return {}; } + // list of triggers associated to the Evaluator (filled only for certain derived classes) + virtual std::vector> triggers() const { return {}; } + // dump the logical expression to the output stream - virtual void dump(std::ostream& out) const = 0; + virtual void dump(std::ostream& out, bool const ignoreMasks = false) const = 0; // apply masks based on another Evaluator - virtual void mask(Evaluator*) {} + virtual void mask(Evaluator const&) {} - // virtual destructor - virtual ~Evaluator() = default; + // methods to control m_masksEnabled boolean + virtual bool masksEnabled() const { return m_masksEnabled; } + virtual void enableMasks() { m_masksEnabled = true; } + virtual void disableMasks() { m_masksEnabled = false; } + + private: + bool m_masksEnabled = false; }; inline std::ostream& operator<<(std::ostream& out, const Evaluator& eval) { @@ -39,4 +51,4 @@ namespace triggerExpression { } // namespace triggerExpression -#endif // HLTrigger_HLTfilters_TriggerExpressionEvaluator_h +#endif // HLTrigger_HLTcore_TriggerExpressionEvaluator_h diff --git a/HLTrigger/HLTcore/interface/TriggerExpressionL1uGTReader.h b/HLTrigger/HLTcore/interface/TriggerExpressionL1uGTReader.h index 1306de609525f..2f98e7424c5c2 100644 --- a/HLTrigger/HLTcore/interface/TriggerExpressionL1uGTReader.h +++ b/HLTrigger/HLTcore/interface/TriggerExpressionL1uGTReader.h @@ -1,8 +1,5 @@ -#ifndef HLTrigger_HLTfilters_TriggerExpressionL1uGTReader_h -#define HLTrigger_HLTfilters_TriggerExpressionL1uGTReader_h - -#include -#include +#ifndef HLTrigger_HLTcore_TriggerExpressionL1uGTReader_h +#define HLTrigger_HLTcore_TriggerExpressionL1uGTReader_h #include "HLTrigger/HLTcore/interface/TriggerExpressionEvaluator.h" @@ -11,37 +8,26 @@ namespace triggerExpression { class L1uGTReader : public Evaluator { public: L1uGTReader(const std::string& pattern) - : m_pattern{pattern}, - m_triggers{}, - m_triggersAfterMasking{}, - m_initialised{false}, - m_useTriggersAfterMasking{false} {} + : m_pattern{pattern}, m_triggers{}, m_triggersAfterMasking{}, m_initialised{false} {} bool operator()(const Data& data) const override; void init(const Data& data) override; - void dump(std::ostream& out) const override; - void dump(std::ostream& out, bool const) const; + void dump(std::ostream& out, bool const ignoreMasks = false) const override; - void mask(Evaluator* eval) override; + void mask(Evaluator const& eval) override; - std::vector> triggers() const { return m_triggers; } + std::vector> triggers() const override { return m_triggers; } std::vector> triggersAfterMasking() const { return m_triggersAfterMasking; } - void maskTriggers(L1uGTReader const&); - - bool useTriggersAfterMasking() const { return m_useTriggersAfterMasking; } - void setUseTriggersAfterMasking(bool const foo) { m_useTriggersAfterMasking = foo; } - private: std::string m_pattern; std::vector> m_triggers; std::vector> m_triggersAfterMasking; bool m_initialised; - bool m_useTriggersAfterMasking; }; } // namespace triggerExpression -#endif // HLTrigger_HLTfilters_TriggerExpressionL1uGTReader_h +#endif // HLTrigger_HLTcore_TriggerExpressionL1uGTReader_h diff --git a/HLTrigger/HLTcore/interface/TriggerExpressionOperators.h b/HLTrigger/HLTcore/interface/TriggerExpressionOperators.h index 2bdeb15a8285a..094f4882d73e2 100644 --- a/HLTrigger/HLTcore/interface/TriggerExpressionOperators.h +++ b/HLTrigger/HLTcore/interface/TriggerExpressionOperators.h @@ -1,5 +1,5 @@ -#ifndef HLTrigger_HLTfilters_TriggerExpressionOperators_h -#define HLTrigger_HLTfilters_TriggerExpressionOperators_h +#ifndef HLTrigger_HLTcore_TriggerExpressionOperators_h +#define HLTrigger_HLTcore_TriggerExpressionOperators_h #include @@ -16,7 +16,7 @@ namespace triggerExpression { void init(const Data& data) override { m_arg->init(data); } // apply mask(s) to the Evaluator - void mask(Evaluator* arg) override { m_arg->mask(arg); } + void mask(Evaluator const& arg) override { m_arg->mask(arg); } // return the patterns from the depending modules std::vector patterns() const override { return m_arg->patterns(); } @@ -37,7 +37,7 @@ namespace triggerExpression { } // apply mask(s) to the Evaluators - void mask(Evaluator* arg) override { + void mask(Evaluator const& arg) override { m_arg1->mask(arg); m_arg2->mask(arg); } @@ -64,10 +64,10 @@ namespace triggerExpression { bool operator()(const Data& data) const override { return not(*m_arg)(data); } - void dump(std::ostream& out) const override { + void dump(std::ostream& out, bool const ignoreMasks = false) const override { out << '('; out << "NOT "; - m_arg->dump(out); + m_arg->dump(out, ignoreMasks); out << ')'; } }; @@ -83,11 +83,11 @@ namespace triggerExpression { return r1 and r2; } - void dump(std::ostream& out) const override { + void dump(std::ostream& out, bool const ignoreMasks = false) const override { out << '('; - m_arg1->dump(out); + m_arg1->dump(out, ignoreMasks); out << " AND "; - m_arg2->dump(out); + m_arg2->dump(out, ignoreMasks); out << ')'; } }; @@ -103,11 +103,11 @@ namespace triggerExpression { return r1 or r2; } - void dump(std::ostream& out) const override { + void dump(std::ostream& out, bool const ignoreMasks = false) const override { out << '('; - m_arg1->dump(out); + m_arg1->dump(out, ignoreMasks); out << " OR "; - m_arg2->dump(out); + m_arg2->dump(out, ignoreMasks); out << ')'; } }; @@ -123,11 +123,11 @@ namespace triggerExpression { return r1 xor r2; } - void dump(std::ostream& out) const override { + void dump(std::ostream& out, bool const ignoreMasks = false) const override { out << '('; - m_arg1->dump(out); + m_arg1->dump(out, ignoreMasks); out << " XOR "; - m_arg2->dump(out); + m_arg2->dump(out, ignoreMasks); out << ')'; } }; @@ -141,22 +141,23 @@ namespace triggerExpression { void init(const Data& data) override { m_arg1->init(data); m_arg2->init(data); - m_arg1->mask(m_arg2.get()); + m_arg1->mask(*m_arg2); } - // apply mask(s) to the first Evaluator - // (the 2nd Evaluator is not used anyway in the decision of OperatorMasking) - void mask(Evaluator* arg) override { m_arg1->mask(arg); } + // apply mask(s) only to the first Evaluator + // (the second Evaluator is not used in the decision of OperatorMasking) + void mask(Evaluator const& arg) override { m_arg1->mask(arg); } - void dump(std::ostream& out) const override { + void dump(std::ostream& out, bool const ignoreMasks = false) const override { out << '('; - m_arg1->dump(out); + // ignore masks on the first Evaluator to dump the full logic expression + m_arg1->dump(out, true); out << " MASKING "; - m_arg2->dump(out); + m_arg2->dump(out, ignoreMasks); out << ')'; } }; } // namespace triggerExpression -#endif // HLTrigger_HLTfilters_TriggerExpressionOperators_h +#endif // HLTrigger_HLTcore_TriggerExpressionOperators_h diff --git a/HLTrigger/HLTcore/interface/TriggerExpressionParser.h b/HLTrigger/HLTcore/interface/TriggerExpressionParser.h index 492d2b09fa2a2..ac81d2d21d7ad 100644 --- a/HLTrigger/HLTcore/interface/TriggerExpressionParser.h +++ b/HLTrigger/HLTcore/interface/TriggerExpressionParser.h @@ -1,5 +1,5 @@ -#ifndef HLTrigger_HLTfilters_TriggerExpressionParser_h -#define HLTrigger_HLTfilters_TriggerExpressionParser_h +#ifndef HLTrigger_HLTcore_TriggerExpressionParser_h +#define HLTrigger_HLTcore_TriggerExpressionParser_h // Note: this requires Boost 1.41 or higher, for Spirit 2.1 or higher #include @@ -25,22 +25,27 @@ namespace triggerExpression { Parser() : Parser::base_type(expression) { auto delimiter = qi::copy(qi::eoi | !qi::char_("a-zA-Z0-9_*?")); - token_true = qi::lexeme[qi::lit("TRUE") >> delimiter]; - token_false = qi::lexeme[qi::lit("FALSE") >> delimiter]; - operand_not = qi::lexeme[qi::lit("NOT") >> delimiter]; operand_and = qi::lexeme[qi::lit("AND") >> delimiter]; operand_or = qi::lexeme[qi::lit("OR") >> delimiter]; operand_masking = qi::lexeme[qi::lit("MASKING") >> delimiter]; + // "TRUE": keyword to accept all events + token_true = qi::lexeme[qi::lit("TRUE") >> delimiter]; + + // "FALSE": keyword to reject all events + token_false = qi::lexeme[qi::lit("FALSE") >> delimiter]; + + // Level-1 Global Trigger decisions: must begin with characters "L1_" token_l1algo %= qi::raw[qi::lexeme["L1_" >> +(qi::char_("a-zA-Z0-9_*?"))]]; - token_path %= - qi::raw[qi::lexeme[+(qi::char_("a-zA-Z0-9_*?"))] - operand_not - operand_and - operand_or - operand_masking]; - token = (token_true[qi::_val = new_(true)] | // TRUE - token_false[qi::_val = new_(false)] | // FALSE - token_l1algo[qi::_val = new_(qi::_1)] | // L1_* - token_path[qi::_val = new_(qi::_1)]); // * (except for "NOT", "AND", "OR", and "MASKING") + // Decisions of Paths in the CMSSW configuration (e.g. high-level triggers): + // any alphanumeric pattern except for "TRUE", "FALSE", "NOT", "AND", "OR", and "MASKING" + token_path %= qi::raw[qi::lexeme[+(qi::char_("a-zA-Z0-9_*?"))] - token_true - token_false - operand_not - + operand_and - operand_or - operand_masking]; + + token = (token_true[qi::_val = new_(true)] | token_false[qi::_val = new_(false)] | + token_l1algo[qi::_val = new_(qi::_1)] | token_path[qi::_val = new_(qi::_1)]); parenthesis %= ('(' >> expression >> ')'); @@ -52,8 +57,13 @@ namespace triggerExpression { unary = ((operand_not >> unary)[qi::_val = new_(qi::_1)] | operand[qi::_val = qi::_1]); - // argument_masking is used to restrict "masking" to Constant, L1uGTReader and PathReader - argument_masking %= (token | ('(' >> argument_masking >> ')')); + // token_masking is used to restrict the argument (rhs) of the "MASKING" + // operation to Constant[FALSE], L1uGTReader and PathReader evaluators + token_masking = + (token_false[qi::_val = new_(false)] | token_l1algo[qi::_val = new_(qi::_1)] | + token_path[qi::_val = new_(qi::_1)]); + + argument_masking %= (token_masking | ('(' >> argument_masking >> ')')); expression = unary[qi::_val = qi::_1] >> *((operand_and >> unary)[qi::_val = new_(qi::_val, qi::_1)] | @@ -83,6 +93,7 @@ namespace triggerExpression { rule prescale; rule operand; rule unary; + rule token_masking; rule argument_masking; rule expression; }; @@ -129,4 +140,4 @@ namespace triggerExpression { } // namespace triggerExpression -#endif // HLTrigger_HLTfilters_TriggerExpressionParser_h +#endif // HLTrigger_HLTcore_TriggerExpressionParser_h diff --git a/HLTrigger/HLTcore/interface/TriggerExpressionPathReader.h b/HLTrigger/HLTcore/interface/TriggerExpressionPathReader.h index 51ec0a3aea90b..9ea681307a41e 100644 --- a/HLTrigger/HLTcore/interface/TriggerExpressionPathReader.h +++ b/HLTrigger/HLTcore/interface/TriggerExpressionPathReader.h @@ -1,8 +1,5 @@ -#ifndef HLTrigger_HLTfilters_TriggerExpressionPathReader_h -#define HLTrigger_HLTfilters_TriggerExpressionPathReader_h - -#include -#include +#ifndef HLTrigger_HLTcore_TriggerExpressionPathReader_h +#define HLTrigger_HLTcore_TriggerExpressionPathReader_h #include "HLTrigger/HLTcore/interface/TriggerExpressionEvaluator.h" @@ -11,39 +8,28 @@ namespace triggerExpression { class PathReader : public Evaluator { public: PathReader(const std::string& pattern) - : m_pattern{pattern}, - m_triggers{}, - m_triggersAfterMasking{}, - m_initialised{false}, - m_useTriggersAfterMasking{false} {} + : m_pattern{pattern}, m_triggers{}, m_triggersAfterMasking{}, m_initialised{false} {} bool operator()(const Data& data) const override; void init(const Data& data) override; - std::vector patterns() const override { return std::vector{m_pattern}; } + std::vector patterns() const override { return {m_pattern}; } - void dump(std::ostream& out) const override; - void dump(std::ostream& out, bool const) const; + void dump(std::ostream& out, bool const ignoreMasks = false) const override; - void mask(Evaluator* eval) override; + void mask(Evaluator const& eval) override; - std::vector> triggers() const { return m_triggers; } + std::vector> triggers() const override { return m_triggers; } std::vector> triggersAfterMasking() const { return m_triggersAfterMasking; } - void maskTriggers(PathReader const&); - - bool useTriggersAfterMasking() const { return m_useTriggersAfterMasking; } - void setUseTriggersAfterMasking(bool const foo) { m_useTriggersAfterMasking = foo; } - private: std::string m_pattern; std::vector> m_triggers; std::vector> m_triggersAfterMasking; bool m_initialised; - bool m_useTriggersAfterMasking; }; } // namespace triggerExpression -#endif // HLTrigger_HLTfilters_TriggerExpressionPathReader_h +#endif // HLTrigger_HLTcore_TriggerExpressionPathReader_h diff --git a/HLTrigger/HLTcore/interface/TriggerExpressionPrescaler.h b/HLTrigger/HLTcore/interface/TriggerExpressionPrescaler.h index cc8e6d8294c2d..c7d65e86f3c06 100644 --- a/HLTrigger/HLTcore/interface/TriggerExpressionPrescaler.h +++ b/HLTrigger/HLTcore/interface/TriggerExpressionPrescaler.h @@ -1,8 +1,7 @@ -#ifndef HLTrigger_HLTfilters_TriggerExpressionPrescaler_h -#define HLTrigger_HLTfilters_TriggerExpressionPrescaler_h +#ifndef HLTrigger_HLTcore_TriggerExpressionPrescaler_h +#define HLTrigger_HLTcore_TriggerExpressionPrescaler_h #include "HLTrigger/HLTcore/interface/TriggerExpressionOperators.h" -#include "HLTrigger/HLTcore/interface/TriggerExpressionData.h" namespace triggerExpression { @@ -14,7 +13,11 @@ namespace triggerExpression { void init(const Data& data) override; - void dump(std::ostream& out) const override { out << "(" << (*m_arg) << " / " << m_prescale << ")"; } + void dump(std::ostream& out, bool const ignoreMasks = false) const override { + out << '('; + m_arg->dump(out, ignoreMasks); + out << " / " << m_prescale << ')'; + } private: unsigned int m_prescale; @@ -23,4 +26,4 @@ namespace triggerExpression { } // namespace triggerExpression -#endif // HLTrigger_HLTfilters_TriggerExpressionPrescaler_h +#endif // HLTrigger_HLTcore_TriggerExpressionPrescaler_h diff --git a/HLTrigger/HLTcore/src/TriggerExpressionL1uGTReader.cc b/HLTrigger/HLTcore/src/TriggerExpressionL1uGTReader.cc index de47f55d12df5..557864e010261 100644 --- a/HLTrigger/HLTcore/src/TriggerExpressionL1uGTReader.cc +++ b/HLTrigger/HLTcore/src/TriggerExpressionL1uGTReader.cc @@ -19,7 +19,7 @@ namespace triggerExpression { if (word.empty()) return false; - auto const& triggers = m_useTriggersAfterMasking ? m_triggersAfterMasking : m_triggers; + auto const& triggers = masksEnabled() ? m_triggersAfterMasking : m_triggers; for (auto const& trigger : triggers) if (trigger.second < word.size() and word[trigger.second]) @@ -28,20 +28,13 @@ namespace triggerExpression { return false; } - void L1uGTReader::dump(std::ostream& out) const { - // in the dump() method inherited from the Evaluator base class, - // show the full list of triggers (useTriggersAfterMasking == false), - // so that the dump of the masking operator is explicit, i.e. "A MASKING B" - dump(out, false); - } - - void L1uGTReader::dump(std::ostream& out, bool const useTriggersAfterMasking) const { + void L1uGTReader::dump(std::ostream& out, bool const ignoreMasks) const { if (not m_initialised) { out << "Uninitialised_L1_Expression"; return; } - auto const& triggers = useTriggersAfterMasking ? m_triggersAfterMasking : m_triggers; + auto const& triggers = ignoreMasks or not masksEnabled() ? m_triggers : m_triggersAfterMasking; if (triggers.empty()) { out << "FALSE"; @@ -106,31 +99,26 @@ namespace triggerExpression { m_initialised = true; } - void L1uGTReader::mask(Evaluator* eval) { - if (eval == nullptr) + void L1uGTReader::mask(Evaluator const& eval) { + auto const& triggersToMask = eval.triggers(); + + if (triggersToMask.empty()) { + edm::LogInfo("NoTriggersToMask") << "\tL1uGTReader[\"" << *this << "\"]::mask(arg = \"" << eval << "\")" + << " failed: arg.triggers() is empty"; return; + } - L1uGTReader* l1ugtReader = dynamic_cast(eval); - if (l1ugtReader == nullptr) { - Constant* constantEval = dynamic_cast(eval); - if (constantEval == nullptr) { - edm::LogInfo("InvalidArgumentForMasking") - << "\tL1uGTReader::mask(eval) call is a no-op:" - << " failed to cast Evaluator* to L1uGTReader* (*eval = \"" << *eval << "\")"; - } else { - edm::LogWarning("InvalidArgumentForMasking") - << "\tL1uGTReader::mask(eval) call is a no-op:" - << " failed to cast Evaluator* to L1uGTReader* (*eval = \"" << *eval << "\")"; - } + // patterns() is always empty for a L1uGTReader, and not empty for PathReader; + // here, PathReader evaluators are skipped as they shouldn't be used to mask a L1uGTReader + if (not eval.patterns().empty()) { + edm::LogWarning("InvalidArgumentForMasking") + << "\tL1uGTReader[\"" << *this << "\"]::mask(arg = \"" << eval << "\")" + << " failed: arg.patterns() is not empty (arg is not a L1uGTReader)"; return; } - maskTriggers(*l1ugtReader); - } + enableMasks(); - void L1uGTReader::maskTriggers(L1uGTReader const& l1ugtReader) { - m_useTriggersAfterMasking = true; - auto const& triggersToMask = l1ugtReader.triggers(); // clang-format off m_triggersAfterMasking.erase( std::remove_if( diff --git a/HLTrigger/HLTcore/src/TriggerExpressionPathReader.cc b/HLTrigger/HLTcore/src/TriggerExpressionPathReader.cc index e48434dd25e4a..71254f9f514d6 100644 --- a/HLTrigger/HLTcore/src/TriggerExpressionPathReader.cc +++ b/HLTrigger/HLTcore/src/TriggerExpressionPathReader.cc @@ -5,7 +5,6 @@ #include "FWCore/MessageLogger/interface/MessageLogger.h" #include "HLTrigger/HLTcore/interface/TriggerExpressionData.h" #include "HLTrigger/HLTcore/interface/TriggerExpressionPathReader.h" -#include "HLTrigger/HLTcore/interface/TriggerExpressionConstant.h" namespace triggerExpression { @@ -14,7 +13,7 @@ namespace triggerExpression { if (not data.hasHLT() && not data.usePathStatus()) return false; - auto const& triggers = m_useTriggersAfterMasking ? m_triggersAfterMasking : m_triggers; + auto const& triggers = masksEnabled() ? m_triggersAfterMasking : m_triggers; for (auto const& trigger : triggers) if (data.passHLT(trigger.second)) @@ -23,20 +22,13 @@ namespace triggerExpression { return false; } - void PathReader::dump(std::ostream& out) const { - // in the dump() method inherited from the Evaluator base class, - // show the full list of triggers (useTriggersAfterMasking == false), - // so that the dump of the masking operator is explicit, i.e. "A MASKING B" - dump(out, false); - } - - void PathReader::dump(std::ostream& out, bool const useTriggersAfterMasking) const { + void PathReader::dump(std::ostream& out, bool const ignoreMasks) const { if (not m_initialised) { out << "Uninitialised_Path_Expression"; return; } - auto const& triggers = useTriggersAfterMasking ? m_triggersAfterMasking : m_triggers; + auto const& triggers = ignoreMasks or not masksEnabled() ? m_triggers : m_triggersAfterMasking; if (triggers.empty()) { out << "FALSE"; @@ -105,31 +97,26 @@ namespace triggerExpression { m_initialised = true; } - void PathReader::mask(Evaluator* eval) { - if (eval == nullptr) + void PathReader::mask(Evaluator const& eval) { + auto const& triggersToMask = eval.triggers(); + + if (triggersToMask.empty()) { + edm::LogInfo("NoTriggersToMask") << "\tPathReader[\"" << *this << "\"]::mask(arg = \"" << eval << "\")" + << " failed: arg.triggers() is empty"; return; + } - PathReader* pathReader = dynamic_cast(eval); - if (pathReader == nullptr) { - Constant* constantEval = dynamic_cast(eval); - if (constantEval != nullptr) { - edm::LogInfo("InvalidArgumentForMasking") - << "\tPathReader::mask(eval) call is a no-op:" - << " failed to cast Evaluator* to PathReader* (*eval = \"" << *eval << "\")"; - } else { - edm::LogWarning("InvalidArgumentForMasking") - << "\tPathReader::mask(eval) call is a no-op:" - << " failed to cast Evaluator* to PathReader* (*eval = \"" << *eval << "\")"; - } + // patterns() is always empty for a L1uGTReader, and not empty for PathReader; + // here, L1uGTReader evaluators are skipped as they shouldn't be used to mask a PathReader + if (eval.patterns().empty()) { + edm::LogWarning("InvalidArgumentForMasking") + << "\tPathReader[\"" << *this << "\"]::mask(arg = \"" << eval << "\")" + << " failed: arg.patterns() is empty (arg is not a PathReader)"; return; } - maskTriggers(*pathReader); - } + enableMasks(); - void PathReader::maskTriggers(PathReader const& pathReader) { - m_useTriggersAfterMasking = true; - auto const& triggersToMask = pathReader.triggers(); // clang-format off m_triggersAfterMasking.erase( std::remove_if( diff --git a/HLTrigger/HLTcore/src/TriggerExpressionPrescaler.cc b/HLTrigger/HLTcore/src/TriggerExpressionPrescaler.cc index fe6e99b2d19bf..dd4bdb3e9a7fb 100644 --- a/HLTrigger/HLTcore/src/TriggerExpressionPrescaler.cc +++ b/HLTrigger/HLTcore/src/TriggerExpressionPrescaler.cc @@ -1,4 +1,5 @@ #include "HLTrigger/HLTcore/interface/TriggerExpressionPrescaler.h" +#include "HLTrigger/HLTcore/interface/TriggerExpressionData.h" namespace triggerExpression { diff --git a/HLTrigger/HLTcore/test/test_catch2_TriggerExpressionParser.cc b/HLTrigger/HLTcore/test/test_catch2_TriggerExpressionParser.cc index bdb398e24f2b7..0b7d5c5d666b9 100644 --- a/HLTrigger/HLTcore/test/test_catch2_TriggerExpressionParser.cc +++ b/HLTrigger/HLTcore/test/test_catch2_TriggerExpressionParser.cc @@ -106,6 +106,7 @@ TEST_CASE("Test TriggerExpressionParser", "[TriggerExpressionParser]") { REQUIRE(not testExpression("Path_? AND MASKING Path_2")); REQUIRE(not testExpression("MASKING Path_1 AND Path_?")); REQUIRE(not testExpression("EXPR_1 MASKING (Path_1 OR Path_2)")); + REQUIRE(not testExpression("EXPR_1 MASKING TRUE")); REQUIRE(not testExpression("EXPR_1 MASKING (NOT Path_1)")); REQUIRE(not testExpression("EXPR_1 MASKING (Path_1 / 15)")); REQUIRE(not testExpression("EXPR_1 MASKING (Path*_* MASKING Path1_*)"));