EventAuxiliaryHistoryProducer

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
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/Framework/interface/one/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "DataFormats/Provenance/interface/EventAuxiliary.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Utilities/interface/EDPutToken.h"
#include <deque>

namespace edm {

  class EventAuxiliaryHistoryProducer : public one::EDProducer<> {
  public:
    explicit EventAuxiliaryHistoryProducer(ParameterSet const&);

    static void fillDescriptions(ConfigurationDescriptions& descriptions);
    void produce(Event& e, EventSetup const& c) override;
    void endJob() override;

  private:
    unsigned int depth_;
    std::deque<EventAuxiliary> history_;
    EDPutTokenT<std::vector<EventAuxiliary>> token_;
  };

  EventAuxiliaryHistoryProducer::EventAuxiliaryHistoryProducer(ParameterSet const& ps)
      : depth_(ps.getParameter<unsigned int>("historyDepth")),
        history_(),
        token_{produces<std::vector<EventAuxiliary>>()} {}

  void EventAuxiliaryHistoryProducer::produce(Event& e, EventSetup const&) {
    EventAuxiliary aux(e.id(),
                       "",
                       e.time(),
                       e.isRealData(),
                       e.experimentType(),
                       e.bunchCrossing(),
                       EventAuxiliary::invalidStoreNumber,
                       e.orbitNumber());
    //EventAuxiliary const& aux = e.auxiliary(); // when available
    if (!history_.empty()) {
      if (history_.back().id().next(aux.luminosityBlock()) != aux.id())
        history_.clear();
      if (history_.size() >= depth_)
        history_.pop_front();
    }

    history_.push_back(aux);

    e.emplace(token_, history_.begin(), history_.end());
  }

  void EventAuxiliaryHistoryProducer::endJob() {}

  void EventAuxiliaryHistoryProducer::fillDescriptions(ConfigurationDescriptions& descriptions) {
    ParameterSetDescription desc;
    desc.add<unsigned int>("historyDepth");
    descriptions.add("eventAuxiliaryHistory", desc);
  }
}  // namespace edm

using edm::EventAuxiliaryHistoryProducer;
DEFINE_FWK_MODULE(EventAuxiliaryHistoryProducer);