File indexing completed on 2024-04-06 12:12:49
0001
0002 #include <atomic>
0003 #include "FWCore/Framework/interface/global/EDFilter.h"
0004 #include "FWCore/Framework/interface/MakerMacros.h"
0005 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0008
0009 namespace edm {
0010 class Prescaler : public global::EDFilter<> {
0011 public:
0012 explicit Prescaler(ParameterSet const&);
0013 ~Prescaler() override;
0014
0015 static void fillDescriptions(ConfigurationDescriptions& descriptions);
0016 bool filter(StreamID, Event& e, EventSetup const& c) const final;
0017
0018 private:
0019 mutable std::atomic<int> count_;
0020 int n_;
0021 int offset_;
0022 };
0023
0024 Prescaler::Prescaler(ParameterSet const& ps)
0025 : count_(), n_(ps.getParameter<int>("prescaleFactor")), offset_(ps.getParameter<int>("prescaleOffset")) {}
0026
0027 Prescaler::~Prescaler() {}
0028
0029 bool Prescaler::filter(StreamID, Event&, EventSetup const&) const {
0030
0031 int count = ++count_;
0032 return count % n_ == offset_ ? true : false;
0033 }
0034
0035 void Prescaler::fillDescriptions(ConfigurationDescriptions& descriptions) {
0036 ParameterSetDescription desc;
0037 desc.add<int>("prescaleFactor")->setComment("Accept one event every N events");
0038 desc.add<int>("prescaleOffset")
0039 ->setComment(
0040 "The first event to accept should be the Mth one. Choose 'prescaleFactor'=1 to accept the first event from "
0041 "the source.");
0042 descriptions.add("preScaler", desc);
0043 }
0044 }
0045
0046 using edm::Prescaler;
0047 DEFINE_FWK_MODULE(Prescaler);