Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:49

0001 
0002 #include "FWCore/Framework/interface/global/EDFilter.h"
0003 #include "FWCore/Framework/interface/MakerMacros.h"
0004 #include "FWCore/Framework/interface/Event.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 ModuloEventIDFilter : public global::EDFilter<> {
0011   public:
0012     explicit ModuloEventIDFilter(ParameterSet const&);
0013 
0014     static void fillDescriptions(ConfigurationDescriptions& descriptions);
0015     bool filter(StreamID, Event& e, EventSetup const& c) const final;
0016 
0017   private:
0018     const unsigned int n_;       // accept one in n
0019     const unsigned int offset_;  // with offset, ie. sequence of events does not have to start at first event
0020   };
0021 
0022   ModuloEventIDFilter::ModuloEventIDFilter(ParameterSet const& ps)
0023       : n_(ps.getParameter<unsigned int>("modulo")), offset_(ps.getParameter<unsigned int>("offset")) {}
0024 
0025   bool ModuloEventIDFilter::filter(StreamID, Event& iEvent, EventSetup const&) const {
0026     return (iEvent.id().event() % n_ == offset_);
0027   }
0028 
0029   void ModuloEventIDFilter::fillDescriptions(ConfigurationDescriptions& descriptions) {
0030     ParameterSetDescription desc;
0031     desc.add<unsigned int>("modulo")->setComment("Accept event if (eventID % modulo) == offset.");
0032     desc.add<unsigned int>("offset")->setComment("Used to shift which value of modulo to accept.");
0033     descriptions.add("eventIDFilter", desc);
0034   }
0035 }  // namespace edm
0036 
0037 using edm::ModuloEventIDFilter;
0038 DEFINE_FWK_MODULE(ModuloEventIDFilter);