Skip to content

Commit

Permalink
Backport: add modules to produce a boolean value, and filter based on…
Browse files Browse the repository at this point in the history
… it (cms-sw#31221)

Add two modules:
  - BooleanProducer reads a boolean value from the configuration, and "produces" it into the event;
  - BooleanFilter reads a boolean value from the event, and accepts or rejects the event based on it.

Together with a SwitchProducer, these modules allow recording in the events' TriggerResults which of the branches was taken.
  • Loading branch information
fwyzard committed Aug 25, 2020
1 parent 8f84dde commit e4696ec
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
32 changes: 32 additions & 0 deletions FWCore/Modules/src/BooleanFilter.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/global/EDFilter.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"

namespace edm {
class BooleanFilter : public global::EDFilter<> {
public:
explicit BooleanFilter(ParameterSet const& config)
: token_(consumes<bool>(config.getParameter<edm::InputTag>("src"))) {}

bool filter(StreamID sid, Event& event, EventSetup const& setup) const final { return event.get(token_); }

static void fillDescriptions(ConfigurationDescriptions& descriptions);

private:
const edm::EDGetTokenT<bool> token_;
};

void BooleanFilter::fillDescriptions(ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("src", edm::InputTag());
descriptions.addWithDefaultLabel(desc);
descriptions.setComment("This EDFilter accepts or rejects events based on the boolean value read from \"src\".");
}
} // namespace edm

#include "FWCore/Framework/interface/MakerMacros.h"
using edm::BooleanFilter;
DEFINE_FWK_MODULE(BooleanFilter);
33 changes: 33 additions & 0 deletions FWCore/Modules/src/BooleanProducer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"

namespace edm {
class BooleanProducer : public global::EDProducer<> {
public:
explicit BooleanProducer(ParameterSet const& config)
: value_(config.getParameter<bool>("value")), token_(produces<bool>()) {}

void produce(StreamID sid, Event& event, EventSetup const& setup) const final { event.emplace(token_, value_); }

static void fillDescriptions(ConfigurationDescriptions& descriptions);

private:
const bool value_;
const edm::EDPutTokenT<bool> token_;
};

void BooleanProducer::fillDescriptions(ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<bool>("value", false);
descriptions.addWithDefaultLabel(desc);
descriptions.setComment("This EDProducer produces a boolean value according to the \"value\" parameter.");
}
} // namespace edm

#include "FWCore/Framework/interface/MakerMacros.h"
using edm::BooleanProducer;
DEFINE_FWK_MODULE(BooleanProducer);

0 comments on commit e4696ec

Please sign in to comment.