Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support arbitrary path names in the TriggerResultsFilter in HLTPathStatus mode [12.2.x] #36733

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions HLTrigger/HLTcore/interface/TriggerExpressionConstant.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ namespace triggerExpression {

bool operator()(const Data& data) const override { return m_value; }

void init(const Data& data) override {}

void dump(std::ostream& out) const override { out << (m_value ? "TRUE" : "FALSE"); }

private:
Expand Down
4 changes: 2 additions & 2 deletions HLTrigger/HLTcore/interface/TriggerExpressionData.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace triggerExpression {
m_hltUpdated(false),
// event values
m_eventNumber() {
if (not m_hltResultsTag.label().empty() && not m_usePathStatus)
if (not m_hltResultsTag.label().empty() and not m_usePathStatus)
m_hltResultsToken = iC.consumes<edm::TriggerResults>(m_hltResultsTag);
if (not m_l1tResultsTag.label().empty())
m_l1tResultsToken = iC.consumes<GlobalAlgBlkBxCollection>(m_l1tResultsTag);
Expand Down Expand Up @@ -112,7 +112,7 @@ namespace triggerExpression {
m_hltUpdated(false),
// event values
m_eventNumber() {
if (not m_hltResultsTag.label().empty() && not m_usePathStatus)
if (not m_hltResultsTag.label().empty() and not m_usePathStatus)
m_hltResultsToken = iC.consumes<edm::TriggerResults>(m_hltResultsTag);
if (not m_l1tResultsTag.label().empty())
m_l1tResultsToken = iC.consumes<GlobalAlgBlkBxCollection>(m_l1tResultsTag);
Expand Down
15 changes: 10 additions & 5 deletions HLTrigger/HLTcore/interface/TriggerExpressionEvaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,31 @@
#define HLTrigger_HLTfilters_TriggerExpressionEvaluator_h

#include <iostream>
#include <string>
#include <vector>

namespace triggerExpression {

class Data;

class Evaluator {
public:
Evaluator() {}
Evaluator() = default;

// pure virtual, need a concrete implementation
// check if the data satisfies the logical expression
virtual bool operator()(const Data& data) const = 0;

// virtual function, do nothing unless overridden
// (re)initialise the logical expression
virtual void init(const Data& data) {}

// pure virtual, need a concrete implementation
// list CMSSW path patterns associated to the logical expression
virtual std::vector<std::string> patterns() const { return {}; }

// dump the logical expression to the output stream
virtual void dump(std::ostream& out) const = 0;

// virtual destructor
virtual ~Evaluator() {}
virtual ~Evaluator() = default;
};

inline std::ostream& operator<<(std::ostream& out, const Evaluator& eval) {
Expand Down
12 changes: 12 additions & 0 deletions HLTrigger/HLTcore/interface/TriggerExpressionOperators.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ namespace triggerExpression {
// initialize the depending modules
void init(const Data& data) override { m_arg->init(data); }

// return the patterns from the depending modules
std::vector<std::string> patterns() const override { return m_arg->patterns(); }

protected:
std::unique_ptr<Evaluator> m_arg;
};
Expand All @@ -29,6 +32,15 @@ namespace triggerExpression {
m_arg2->init(data);
}

// return the patterns from the depending modules
std::vector<std::string> patterns() const override {
std::vector<std::string> patterns = m_arg1->patterns();
auto patterns2 = m_arg2->patterns();
patterns.insert(
patterns.end(), std::make_move_iterator(patterns2.begin()), std::make_move_iterator(patterns2.end()));
return patterns;
}

protected:
std::unique_ptr<Evaluator> m_arg1;
std::unique_ptr<Evaluator> m_arg2;
Expand Down
2 changes: 2 additions & 0 deletions HLTrigger/HLTcore/interface/TriggerExpressionPathReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace triggerExpression {

void init(const Data& data) override;

std::vector<std::string> patterns() const override { return std::vector<std::string>{m_pattern}; }

void dump(std::ostream& out) const override;

private:
Expand Down
6 changes: 2 additions & 4 deletions HLTrigger/HLTcore/src/TriggerExpressionData.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
namespace triggerExpression {

void Data::setPathStatusToken(edm::BranchDescription const& branch, edm::ConsumesCollector&& iC) {
if (branch.branchType() == edm::InEvent && branch.className() == "edm::HLTPathStatus" &&
branch.moduleLabel().rfind("HLT_", 0) == 0)
m_pathStatusTokens[branch.moduleLabel()] = iC.consumes<edm::HLTPathStatus>(
edm::InputTag(branch.moduleLabel(), branch.productInstanceName(), branch.processName()));
m_pathStatusTokens[branch.moduleLabel()] = iC.consumes<edm::HLTPathStatus>(
edm::InputTag(branch.moduleLabel(), branch.productInstanceName(), branch.processName()));
}

bool Data::setEvent(const edm::Event& event, const edm::EventSetup& setup) {
Expand Down
45 changes: 32 additions & 13 deletions HLTrigger/HLTfilters/plugins/TriggerResultsFilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,57 @@
*
*/

#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <regex>
#include <vector>

#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/Common/interface/TriggerResults.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"

#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/Utilities/interface/RegexMatch.h"
#include "HLTrigger/HLTcore/interface/TriggerExpressionEvaluator.h"
#include "HLTrigger/HLTcore/interface/TriggerExpressionParser.h"

#include "TriggerResultsFilter.h"

//
// constructors and destructor
//
TriggerResultsFilter::TriggerResultsFilter(const edm::ParameterSet& config)
: m_expression(nullptr), m_eventCache(config, consumesCollector()) {
const std::vector<std::string>& expressions = config.getParameter<std::vector<std::string>>("triggerConditions");
std::vector<std::string> const& expressions = config.getParameter<std::vector<std::string>>("triggerConditions");
parse(expressions);
if (m_eventCache.usePathStatus())
callWhenNewProductsRegistered([this](const edm::BranchDescription& branch) {
this->m_eventCache.setPathStatusToken(branch, consumesCollector());
if (m_expression and m_eventCache.usePathStatus()) {
// if the expression was succesfully parsed, join all the patterns corresponding
// to the CMSSW paths in the logical expression into a single regex
std::vector<std::string> patterns = m_expression->patterns();
if (patterns.empty()) {
return;
}
std::string str;
for (auto const& pattern : patterns) {
str += edm::glob2reg(pattern);
str += '|';
}
str.pop_back();
std::regex regex(str, std::regex::extended);

// consume all matching paths
callWhenNewProductsRegistered([this, regex](edm::BranchDescription const& branch) {
if (branch.branchType() == edm::InEvent and branch.className() == "edm::HLTPathStatus" and
std::regex_match(branch.moduleLabel(), regex)) {
m_eventCache.setPathStatusToken(branch, consumesCollector());
}
});
}
}

TriggerResultsFilter::~TriggerResultsFilter() { delete m_expression; }

void TriggerResultsFilter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
// # use HLTPathStatus results
Expand Down Expand Up @@ -85,7 +104,7 @@ void TriggerResultsFilter::parse(const std::vector<std::string>& expressions) {

void TriggerResultsFilter::parse(const std::string& expression) {
// parse the logical expressions into functionals
m_expression = triggerExpression::parse(expression);
m_expression.reset(triggerExpression::parse(expression));

// check if the expressions were parsed correctly
if (not m_expression)
Expand Down
9 changes: 5 additions & 4 deletions HLTrigger/HLTfilters/plugins/TriggerResultsFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
*
*/

#include <vector>
#include <memory>
#include <string>
#include <vector>

#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/stream/EDFilter.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
Expand All @@ -39,7 +40,7 @@ namespace triggerExpression {
class TriggerResultsFilter : public edm::stream::EDFilter<> {
public:
explicit TriggerResultsFilter(const edm::ParameterSet &);
~TriggerResultsFilter() override;
~TriggerResultsFilter() override = default;
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
bool filter(edm::Event &, const edm::EventSetup &) override;

Expand All @@ -49,7 +50,7 @@ class TriggerResultsFilter : public edm::stream::EDFilter<> {
void parse(const std::vector<std::string> &expressions);

/// evaluator for the trigger condition
triggerExpression::Evaluator *m_expression;
std::unique_ptr<triggerExpression::Evaluator> m_expression;

/// cache some data from the Event for faster access by the m_expression
triggerExpression::Data m_eventCache;
Expand Down
5 changes: 5 additions & 0 deletions HLTrigger/HLTfilters/test/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- test the TriggerResultsFilter reading the CMSSW results from the TriggerResults object of a previous process -->
<test name="triggerResultsFilter_by_TriggerResults" command="cmsRun ${LOCALTOP}/src/HLTrigger/HLTfilters/test/triggerResultsFilter_producer.py; cmsRun ${LOCALTOP}/src/HLTrigger/HLTfilters/test/triggerResultsFilter_by_TriggerResults.py"/>

<!-- test the TriggerResultsFilter reading the CMSSW results from the HLTPathStatus objects of the current process -->
<test name="triggerResultsFilter_by_PathStatus" command="cmsRun ${LOCALTOP}/src/HLTrigger/HLTfilters/test/triggerResultsFilter_by_PathStatus.py"/>
Loading