Skip to content

Commit

Permalink
disallow "MASKING TRUE", rework mask and dump methods
Browse files Browse the repository at this point in the history
  • Loading branch information
missirol committed Sep 1, 2022
1 parent db67eeb commit 626c61c
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 158 deletions.
8 changes: 4 additions & 4 deletions HLTrigger/HLTcore/interface/TriggerExpressionConstant.h
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -13,12 +13,12 @@ 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;
};

} // namespace triggerExpression

#endif // HLTrigger_HLTfilters_TriggerExpressionConstant_h
#endif // HLTrigger_HLTcore_TriggerExpressionConstant_h
6 changes: 3 additions & 3 deletions HLTrigger/HLTcore/interface/TriggerExpressionData.h
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -220,4 +220,4 @@ namespace triggerExpression {

} // namespace triggerExpression

#endif // HLTrigger_HLTfilters_TriggerExpressionData_h
#endif // HLTrigger_HLTcore_TriggerExpressionData_h
26 changes: 19 additions & 7 deletions HLTrigger/HLTcore/interface/TriggerExpressionEvaluator.h
Original file line number Diff line number Diff line change
@@ -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 <iostream>
#include <string>
#include <vector>
#include <utility>

namespace triggerExpression {

Expand All @@ -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;

Expand All @@ -22,14 +26,22 @@ namespace triggerExpression {
// list CMSSW path patterns associated to the logical expression
virtual std::vector<std::string> patterns() const { return {}; }

// list of triggers associated to the Evaluator (filled only for certain derived classes)
virtual std::vector<std::pair<std::string, unsigned int>> 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) {
Expand All @@ -39,4 +51,4 @@ namespace triggerExpression {

} // namespace triggerExpression

#endif // HLTrigger_HLTfilters_TriggerExpressionEvaluator_h
#endif // HLTrigger_HLTcore_TriggerExpressionEvaluator_h
28 changes: 7 additions & 21 deletions HLTrigger/HLTcore/interface/TriggerExpressionL1uGTReader.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#ifndef HLTrigger_HLTfilters_TriggerExpressionL1uGTReader_h
#define HLTrigger_HLTfilters_TriggerExpressionL1uGTReader_h

#include <vector>
#include <string>
#ifndef HLTrigger_HLTcore_TriggerExpressionL1uGTReader_h
#define HLTrigger_HLTcore_TriggerExpressionL1uGTReader_h

#include "HLTrigger/HLTcore/interface/TriggerExpressionEvaluator.h"

Expand All @@ -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<std::pair<std::string, unsigned int>> triggers() const { return m_triggers; }
std::vector<std::pair<std::string, unsigned int>> triggers() const override { return m_triggers; }
std::vector<std::pair<std::string, unsigned int>> 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<std::pair<std::string, unsigned int>> m_triggers;
std::vector<std::pair<std::string, unsigned int>> m_triggersAfterMasking;
bool m_initialised;
bool m_useTriggersAfterMasking;
};

} // namespace triggerExpression

#endif // HLTrigger_HLTfilters_TriggerExpressionL1uGTReader_h
#endif // HLTrigger_HLTcore_TriggerExpressionL1uGTReader_h
47 changes: 24 additions & 23 deletions HLTrigger/HLTcore/interface/TriggerExpressionOperators.h
Original file line number Diff line number Diff line change
@@ -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 <memory>

Expand All @@ -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<std::string> patterns() const override { return m_arg->patterns(); }
Expand All @@ -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);
}
Expand All @@ -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 << ')';
}
};
Expand All @@ -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 << ')';
}
};
Expand All @@ -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 << ')';
}
};
Expand All @@ -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 << ')';
}
};
Expand All @@ -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
39 changes: 25 additions & 14 deletions HLTrigger/HLTcore/interface/TriggerExpressionParser.h
Original file line number Diff line number Diff line change
@@ -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 <boost/phoenix.hpp>
Expand All @@ -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_<Constant>(true)] | // TRUE
token_false[qi::_val = new_<Constant>(false)] | // FALSE
token_l1algo[qi::_val = new_<L1uGTReader>(qi::_1)] | // L1_*
token_path[qi::_val = new_<PathReader>(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_<Constant>(true)] | token_false[qi::_val = new_<Constant>(false)] |
token_l1algo[qi::_val = new_<L1uGTReader>(qi::_1)] | token_path[qi::_val = new_<PathReader>(qi::_1)]);

parenthesis %= ('(' >> expression >> ')');

Expand All @@ -52,8 +57,13 @@ namespace triggerExpression {

unary = ((operand_not >> unary)[qi::_val = new_<OperatorNot>(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_<Constant>(false)] | token_l1algo[qi::_val = new_<L1uGTReader>(qi::_1)] |
token_path[qi::_val = new_<PathReader>(qi::_1)]);

argument_masking %= (token_masking | ('(' >> argument_masking >> ')'));

expression = unary[qi::_val = qi::_1] >>
*((operand_and >> unary)[qi::_val = new_<OperatorAnd>(qi::_val, qi::_1)] |
Expand Down Expand Up @@ -83,6 +93,7 @@ namespace triggerExpression {
rule prescale;
rule operand;
rule unary;
rule token_masking;
rule argument_masking;
rule expression;
};
Expand Down Expand Up @@ -129,4 +140,4 @@ namespace triggerExpression {

} // namespace triggerExpression

#endif // HLTrigger_HLTfilters_TriggerExpressionParser_h
#endif // HLTrigger_HLTcore_TriggerExpressionParser_h
30 changes: 8 additions & 22 deletions HLTrigger/HLTcore/interface/TriggerExpressionPathReader.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#ifndef HLTrigger_HLTfilters_TriggerExpressionPathReader_h
#define HLTrigger_HLTfilters_TriggerExpressionPathReader_h

#include <vector>
#include <string>
#ifndef HLTrigger_HLTcore_TriggerExpressionPathReader_h
#define HLTrigger_HLTcore_TriggerExpressionPathReader_h

#include "HLTrigger/HLTcore/interface/TriggerExpressionEvaluator.h"

Expand All @@ -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<std::string> patterns() const override { return std::vector<std::string>{m_pattern}; }
std::vector<std::string> 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<std::pair<std::string, unsigned int>> triggers() const { return m_triggers; }
std::vector<std::pair<std::string, unsigned int>> triggers() const override { return m_triggers; }
std::vector<std::pair<std::string, unsigned int>> 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<std::pair<std::string, unsigned int>> m_triggers;
std::vector<std::pair<std::string, unsigned int>> m_triggersAfterMasking;
bool m_initialised;
bool m_useTriggersAfterMasking;
};

} // namespace triggerExpression

#endif // HLTrigger_HLTfilters_TriggerExpressionPathReader_h
#endif // HLTrigger_HLTcore_TriggerExpressionPathReader_h
Loading

0 comments on commit 626c61c

Please sign in to comment.