EventWithHistoryProducer

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 89 90 91 92 93 94 95 96 97
// -*- C++ -*-
//
// Package:    EventWithHistoryProducer
// Class:      EventWithHistoryProducer
//
/**\class EventWithHistoryProducer EventWithHistoryProducer.cc DPGAnalysis/SiStripTools/plugins/EventWithHistoryProducer.cc

 Description: EDProducer of EventWithHistory which rely on the presence of the previous event in the analyzed dataset

 Implementation:
     
*/
//
// Original Author:  Andrea Venturi
//         Created:  Sun Nov 30 19:05:41 CET 2008
// $Id: EventWithHistoryProducer.cc,v 1.2 2010/01/12 09:13:04 venturia Exp $
//
//

// system include files
#include <memory>

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

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

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

//#include "DPGAnalysis/SiStripTools/interface/TinyEvent.h"
#include "DPGAnalysis/SiStripTools/interface/EventWithHistory.h"

//
// class decleration
//

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

private:
  void produce(edm::Event&, const edm::EventSetup&) override;

  // ----------member data ---------------------------

  const unsigned int _depth;
  EventWithHistory _prevHE;
};

//
// constants, enums and typedefs
//

//
// static data member definitions
//

//
// constructors and destructor
//
EventWithHistoryProducer::EventWithHistoryProducer(const edm::ParameterSet& iConfig)
    : _depth(iConfig.getUntrackedParameter<unsigned int>("historyDepth")), _prevHE() {
  produces<EventWithHistory>();

  //now do what ever other initialization is needed
}

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

//
// member functions
//

// ------------ method called to produce the data  ------------
void EventWithHistoryProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
  using namespace edm;

  std::unique_ptr<EventWithHistory> heOut(
      new EventWithHistory(iEvent.id().event(), iEvent.orbitNumber(), iEvent.bunchCrossing()));
  heOut->add(_prevHE, _depth);

  if (*heOut < _prevHE)
    edm::LogInfo("EventsNotInOrder") << " Events not in order " << _prevHE._event;

  _prevHE = *heOut;
  iEvent.put(std::move(heOut));
}

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