Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:53:45

0001 // -*- C++ -*-
0002 //
0003 // Package:    NMaxPerLumi
0004 // Class:      NMaxPerLumi
0005 //
0006 /**\class NMaxPerLumi NMaxPerLumi.cc WorkSpace/NMaxPerLumi/src/NMaxPerLumi.cc
0007 
0008  Description: [one line class summary]
0009 
0010  Implementation:
0011      [Notes on implementation]
0012 */
0013 //
0014 // Original Author:  Jean-Roch Vlimant,40 3-A28,+41227671209,
0015 //         Created:  Fri Apr  9 18:54:59 CEST 2010
0016 // $Id: NMaxPerLumi.cc,v 1.3 2010/10/03 10:15:07 elmer Exp $
0017 //
0018 //
0019 
0020 // system include files
0021 #include <memory>
0022 
0023 // user include files
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 #include "FWCore/Framework/interface/stream/EDFilter.h"
0026 
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/MakerMacros.h"
0029 
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031 
0032 //
0033 // class declaration
0034 //
0035 
0036 class NMaxPerLumi : public edm::stream::EDFilter<> {
0037 public:
0038   explicit NMaxPerLumi(const edm::ParameterSet&);
0039   ~NMaxPerLumi() override;
0040 
0041 private:
0042   bool filter(edm::Event&, const edm::EventSetup&) override;
0043 
0044   // ----------member data ---------------------------
0045   std::map<unsigned int, std::map<unsigned int, unsigned int> > counters;
0046   unsigned int nMaxPerLumi_;
0047 };
0048 
0049 //
0050 // constants, enums and typedefs
0051 //
0052 
0053 //
0054 // static data member definitions
0055 //
0056 
0057 //
0058 // constructors and destructor
0059 //
0060 NMaxPerLumi::NMaxPerLumi(const edm::ParameterSet& iConfig) {
0061   //now do what ever initialization is needed
0062 
0063   nMaxPerLumi_ = iConfig.getParameter<unsigned int>("nMaxPerLumi");
0064 }
0065 
0066 NMaxPerLumi::~NMaxPerLumi() {
0067   // do anything here that needs to be done at desctruction time
0068   // (e.g. close files, deallocate resources etc.)
0069 }
0070 
0071 //
0072 // member functions
0073 //
0074 
0075 // ------------ method called on each new Event  ------------
0076 bool NMaxPerLumi::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0077   const edm::EventID& id = iEvent.id();
0078 
0079   if (counters[id.run()][id.luminosityBlock()] >= nMaxPerLumi_)
0080     return false;
0081   else {
0082     counters[id.run()][id.luminosityBlock()]++;
0083     return true;
0084   }
0085 }
0086 
0087 //define this as a plug-in
0088 DEFINE_FWK_MODULE(NMaxPerLumi);