CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/FWCore/Modules/src/Prescaler.cc

Go to the documentation of this file.
00001 
00002 #include "FWCore/Framework/interface/EDFilter.h"
00003 #include "FWCore/Framework/interface/MakerMacros.h"
00004 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
00005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00006 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
00007 
00008 namespace edm {
00009   class Prescaler : public EDFilter {
00010   public:
00011     explicit Prescaler(ParameterSet const&);
00012     virtual ~Prescaler();
00013 
00014     static void fillDescriptions(ConfigurationDescriptions& descriptions);
00015     virtual bool filter(Event& e, EventSetup const& c);
00016     void endJob();
00017 
00018   private:
00019     int count_;
00020     int n_; // accept one in n
00021     int offset_; // with offset, ie. sequence of events does not have to start at first event
00022   };
00023 
00024   Prescaler::Prescaler(ParameterSet const& ps) :
00025     count_(),
00026     n_(ps.getParameter<int>("prescaleFactor")),
00027     offset_(ps.getParameter<int>("prescaleOffset")) {
00028   }
00029 
00030   Prescaler::~Prescaler() {
00031   }
00032 
00033   bool Prescaler::filter(Event&, EventSetup const&) {
00034     ++count_;
00035     return count_ % n_ == offset_ ? true : false;
00036   }
00037 
00038   void Prescaler::endJob() {
00039   }
00040 
00041   void
00042   Prescaler::fillDescriptions(ConfigurationDescriptions& descriptions) {
00043     ParameterSetDescription desc;
00044     desc.add<int>("prescaleFactor");
00045     desc.add<int>("prescaleOffset");
00046     descriptions.add("preScaler", desc);
00047   }
00048 }
00049 
00050 using edm::Prescaler;
00051 DEFINE_FWK_MODULE(Prescaler);