Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:28:48

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_;       // accept one in n
0021     int offset_;  // with offset, ie. sequence of events does not have to start at first event
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     //have to capture the value here since it could change by the time we do the comparision
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 }  // namespace edm
0045 
0046 using edm::Prescaler;
0047 DEFINE_FWK_MODULE(Prescaler);