Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-25 04:55:06

0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 #include "FWCore/Framework/interface/stream/EDFilter.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0006 
0007 class SimpleEventFilter : public edm::stream::EDFilter<> {
0008 public:
0009   SimpleEventFilter(const edm::ParameterSet &);
0010   ~SimpleEventFilter() override;
0011 
0012   static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
0013 
0014 private:
0015   bool filter(edm::Event &, edm::EventSetup const &) override;
0016   int nEvent_;
0017   int nInterval_;
0018   bool verbose_;
0019 };
0020 
0021 //
0022 // -- Constructor
0023 //
0024 SimpleEventFilter::SimpleEventFilter(const edm::ParameterSet &pset) {
0025   nInterval_ = pset.getUntrackedParameter<int>("EventsToSkip", 10);
0026   verbose_ = pset.getUntrackedParameter<bool>("DebugOn", false);
0027   nEvent_ = 0;
0028 }
0029 
0030 //
0031 // -- Destructor
0032 //
0033 SimpleEventFilter::~SimpleEventFilter() = default;
0034 
0035 bool SimpleEventFilter::filter(edm::Event &, edm::EventSetup const &) {
0036   nEvent_++;
0037   bool ret = true;
0038   if (nEvent_ % nInterval_ != 0)
0039     ret = false;
0040   //if (verbose_ && !ret)
0041   if (!ret)
0042     edm::LogInfo("SimpleEventFilter") << ">>> filtering event" << nEvent_ << std::endl;
0043   return ret;
0044 }
0045 
0046 // ------------ method fills 'descriptions' with the allowed parameters for the module  ------------
0047 void SimpleEventFilter::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0048   edm::ParameterSetDescription desc;
0049   desc.setComment("filters one event every N");
0050   desc.addUntracked<bool>("DebugOn", false)->setComment("activates debugging");
0051   desc.addUntracked<int>("EventsToSkip", 10)->setComment("events to skip");
0052   descriptions.add("_simpleEventFilter", desc);
0053 }
0054 
0055 #include "FWCore/Framework/interface/MakerMacros.h"
0056 DEFINE_FWK_MODULE(SimpleEventFilter);