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

Add modules to produce a boolean value, and filter based on it #31222

Merged
merged 1 commit into from Aug 25, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions FWCore/Modules/src/BooleanFilter.cc
@@ -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
@@ -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);