Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:28:47

0001 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0002 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0004 #include "FWCore/Framework/interface/one/EDProducer.h"
0005 #include "FWCore/Framework/interface/Event.h"
0006 #include "DataFormats/Provenance/interface/EventAuxiliary.h"
0007 #include "FWCore/Framework/interface/MakerMacros.h"
0008 #include "FWCore/Utilities/interface/EDPutToken.h"
0009 #include <deque>
0010 
0011 namespace edm {
0012 
0013   class EventAuxiliaryHistoryProducer : public one::EDProducer<> {
0014   public:
0015     explicit EventAuxiliaryHistoryProducer(ParameterSet const&);
0016 
0017     static void fillDescriptions(ConfigurationDescriptions& descriptions);
0018     void produce(Event& e, EventSetup const& c) override;
0019     void endJob() override;
0020 
0021   private:
0022     unsigned int depth_;
0023     std::deque<EventAuxiliary> history_;
0024     EDPutTokenT<std::vector<EventAuxiliary>> token_;
0025   };
0026 
0027   EventAuxiliaryHistoryProducer::EventAuxiliaryHistoryProducer(ParameterSet const& ps)
0028       : depth_(ps.getParameter<unsigned int>("historyDepth")),
0029         history_(),
0030         token_{produces<std::vector<EventAuxiliary>>()} {}
0031 
0032   void EventAuxiliaryHistoryProducer::produce(Event& e, EventSetup const&) {
0033     EventAuxiliary aux(e.id(),
0034                        "",
0035                        e.time(),
0036                        e.isRealData(),
0037                        e.experimentType(),
0038                        e.bunchCrossing(),
0039                        EventAuxiliary::invalidStoreNumber,
0040                        e.orbitNumber());
0041     //EventAuxiliary const& aux = e.auxiliary(); // when available
0042     if (!history_.empty()) {
0043       if (history_.back().id().next(aux.luminosityBlock()) != aux.id())
0044         history_.clear();
0045       if (history_.size() >= depth_)
0046         history_.pop_front();
0047     }
0048 
0049     history_.push_back(aux);
0050 
0051     e.emplace(token_, history_.begin(), history_.end());
0052   }
0053 
0054   void EventAuxiliaryHistoryProducer::endJob() {}
0055 
0056   void EventAuxiliaryHistoryProducer::fillDescriptions(ConfigurationDescriptions& descriptions) {
0057     ParameterSetDescription desc;
0058     desc.add<unsigned int>("historyDepth");
0059     descriptions.add("eventAuxiliaryHistory", desc);
0060   }
0061 }  // namespace edm
0062 
0063 using edm::EventAuxiliaryHistoryProducer;
0064 DEFINE_FWK_MODULE(EventAuxiliaryHistoryProducer);