NMaxPerLumi

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
// -*- C++ -*-
//
// Package:    NMaxPerLumi
// Class:      NMaxPerLumi
//
/**\class NMaxPerLumi NMaxPerLumi.cc WorkSpace/NMaxPerLumi/src/NMaxPerLumi.cc

 Description: [one line class summary]

 Implementation:
     [Notes on implementation]
*/
//
// Original Author:  Jean-Roch Vlimant,40 3-A28,+41227671209,
//         Created:  Fri Apr  9 18:54:59 CEST 2010
// $Id: NMaxPerLumi.cc,v 1.3 2010/10/03 10:15:07 elmer Exp $
//
//

// system include files
#include <memory>

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/stream/EDFilter.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"

#include "FWCore/ParameterSet/interface/ParameterSet.h"

//
// class declaration
//

class NMaxPerLumi : public edm::stream::EDFilter<> {
public:
  explicit NMaxPerLumi(const edm::ParameterSet&);
  ~NMaxPerLumi() override;

private:
  bool filter(edm::Event&, const edm::EventSetup&) override;

  // ----------member data ---------------------------
  std::map<unsigned int, std::map<unsigned int, unsigned int> > counters;
  unsigned int nMaxPerLumi_;
};

//
// constants, enums and typedefs
//

//
// static data member definitions
//

//
// constructors and destructor
//
NMaxPerLumi::NMaxPerLumi(const edm::ParameterSet& iConfig) {
  //now do what ever initialization is needed

  nMaxPerLumi_ = iConfig.getParameter<unsigned int>("nMaxPerLumi");
}

NMaxPerLumi::~NMaxPerLumi() {
  // do anything here that needs to be done at desctruction time
  // (e.g. close files, deallocate resources etc.)
}

//
// member functions
//

// ------------ method called on each new Event  ------------
bool NMaxPerLumi::filter(edm::Event& iEvent, const edm::EventSetup& iSetup) {
  const edm::EventID& id = iEvent.id();

  if (counters[id.run()][id.luminosityBlock()] >= nMaxPerLumi_)
    return false;
  else {
    counters[id.run()][id.luminosityBlock()]++;
    return true;
  }
}

//define this as a plug-in
DEFINE_FWK_MODULE(NMaxPerLumi);