Go to the documentation of this file.00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <memory>
00022 #include <map>
00023
00024
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDProducer.h"
00027
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/Run.h"
00030 #include "FWCore/Framework/interface/MakerMacros.h"
00031
00032 #include "FWCore/Utilities/interface/InputTag.h"
00033
00034 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00035 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00036
00037 #include "DataFormats/Scalers/interface/L1AcceptBunchCrossing.h"
00038 #include "DPGAnalysis/SiStripTools/interface/EventWithHistory.h"
00039
00040
00041
00042
00043 class EventWithHistoryProducerFromL1ABC : public edm::EDProducer {
00044 public:
00045 explicit EventWithHistoryProducerFromL1ABC(const edm::ParameterSet&);
00046 ~EventWithHistoryProducerFromL1ABC();
00047
00048 private:
00049 virtual void beginJob() ;
00050 virtual void beginRun(edm::Run&, const edm::EventSetup&) ;
00051 virtual void produce(edm::Event&, const edm::EventSetup&);
00052 virtual void endRun(edm::Run&, const edm::EventSetup&) ;
00053 virtual void endJob() ;
00054
00055
00056
00057 edm::InputTag _l1abccollection;
00058 std::map<unsigned int, long long> _offsets;
00059 long long _curroffset;
00060 unsigned int _curroffevent;
00061 };
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 EventWithHistoryProducerFromL1ABC::EventWithHistoryProducerFromL1ABC(const edm::ParameterSet& iConfig):
00076 _l1abccollection(iConfig.getParameter<edm::InputTag>("l1ABCCollection")),
00077 _offsets(), _curroffset(0), _curroffevent(0)
00078 {
00079 produces<EventWithHistory>();
00080
00081
00082
00083 }
00084
00085
00086 EventWithHistoryProducerFromL1ABC::~EventWithHistoryProducerFromL1ABC()
00087 {
00088
00089
00090
00091
00092 }
00093
00094
00095
00096
00097
00098
00099
00100 void
00101 EventWithHistoryProducerFromL1ABC::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00102 {
00103 using namespace edm;
00104
00105 if(iEvent.run() < 110878 ) {
00106
00107 std::auto_ptr<EventWithHistory> pOut(new EventWithHistory(iEvent));
00108 iEvent.put(pOut);
00109
00110 }
00111 else {
00112
00113 Handle<L1AcceptBunchCrossingCollection > pIn;
00114 iEvent.getByLabel(_l1abccollection,pIn);
00115
00116
00117
00118 long long orbitoffset = 0;
00119 int bxoffset = 0;
00120 for(L1AcceptBunchCrossingCollection::const_iterator l1abc=pIn->begin();l1abc!=pIn->end();++l1abc) {
00121 if(l1abc->l1AcceptOffset()==0) {
00122 orbitoffset = (long long)l1abc->orbitNumber() - (long long)iEvent.orbitNumber();
00123 bxoffset = l1abc->bunchCrossing() - iEvent.bunchCrossing();
00124 }
00125 }
00126
00127
00128 std::auto_ptr<EventWithHistory> pOut(new EventWithHistory(iEvent,*pIn,orbitoffset,bxoffset));
00129 iEvent.put(pOut);
00130
00131
00132
00133 long long absbxoffset = orbitoffset*3564 + bxoffset;
00134
00135 if(_offsets.size()==0) {
00136 _curroffset = absbxoffset;
00137 _curroffevent = iEvent.id().event();
00138 _offsets[iEvent.id().event()] = absbxoffset;
00139 }
00140 else {
00141 if(_curroffset != absbxoffset || iEvent.id().event() < _curroffevent ) {
00142
00143 if( _curroffset != absbxoffset) {
00144 edm::LogInfo("AbsoluteBXOffsetChanged") << "Absolute BX offset changed from "
00145 << _curroffset << " to "
00146 << absbxoffset << " at orbit "
00147 << iEvent.orbitNumber() << " and BX "
00148 << iEvent.bunchCrossing();
00149 for(L1AcceptBunchCrossingCollection::const_iterator l1abc=pIn->begin();l1abc!=pIn->end();++l1abc) {
00150 edm::LogVerbatim("AbsoluteBXOffsetChanged") << *l1abc;
00151 }
00152 }
00153
00154 _curroffset = absbxoffset;
00155 _curroffevent = iEvent.id().event();
00156 _offsets[iEvent.id().event()] = absbxoffset;
00157 }
00158 }
00159 }
00160 }
00161
00162
00163 void
00164 EventWithHistoryProducerFromL1ABC::beginJob()
00165 {
00166 }
00167
00168 void
00169 EventWithHistoryProducerFromL1ABC::beginRun(edm::Run&, const edm::EventSetup&)
00170 {
00171
00172
00173 _offsets.clear();
00174 edm::LogInfo("AbsoluteBXOffsetReset") << "Absolute BX offset map reset";
00175
00176 }
00177
00178 void
00179 EventWithHistoryProducerFromL1ABC::endRun(edm::Run&, const edm::EventSetup&)
00180 {
00181
00182
00183 edm::LogInfo("AbsoluteBXOffsetSummary") << "Absolute BX offset summary:";
00184 for(std::map<unsigned int, long long>::const_iterator offset=_offsets.begin();offset!=_offsets.end();++offset) {
00185 edm::LogVerbatim("AbsoluteBXOffsetSummary") << offset->first << " " << offset->second;
00186 }
00187
00188 }
00189
00190
00191 void
00192 EventWithHistoryProducerFromL1ABC::endJob() {
00193 }
00194
00195
00196 DEFINE_FWK_MODULE(EventWithHistoryProducerFromL1ABC);