CMS 3D CMS Logo

EventWithHistoryProducerFromL1ABC.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EventWithHistoryProducerFromL1ABC
4 // Class: EventWithHistoryProducerFromL1ABC
5 //
13 //
14 // Original Author: Andrea Venturi
15 // Created: Tue Jun 30 15:26:20 CET 2009
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 #include <map>
22 
23 // user include files
26 
30 
32 
35 
38 //
39 // class decleration
40 //
41 
43 public:
46 
47 private:
48  void beginRun(const edm::Run&, const edm::EventSetup&) override;
49  void produce(edm::Event&, const edm::EventSetup&) override;
50  void endRun(const edm::Run&, const edm::EventSetup&) override;
51 
52  // ----------member data ---------------------------
53 
55  const bool _forceNoOffset;
56  std::map<edm::EventNumber_t, long long> _offsets;
57  long long _curroffset;
59 };
60 
61 //
62 // constants, enums and typedefs
63 //
64 
65 //
66 // static data member definitions
67 //
68 
69 //
70 // constructors and destructor
71 //
74  mayConsume<L1AcceptBunchCrossingCollection>(iConfig.getParameter<edm::InputTag>("l1ABCCollection"))),
75  _forceNoOffset(iConfig.getUntrackedParameter<bool>("forceNoOffset", false)),
76  _offsets(),
77  _curroffset(0),
78  _curroffevent(0) {
79  if (_forceNoOffset)
80  edm::LogWarning("NoOffsetComputation") << "Orbit and BX offset will NOT be computed: Be careful!";
81 
82  produces<EventWithHistory>();
83 
84  //now do what ever other initialization is needed
85 }
86 
88  // do anything here that needs to be done at desctruction time
89  // (e.g. close files, deallocate resources etc.)
90 }
91 
92 //
93 // member functions
94 //
95 
96 // ------------ method called to produce the data ------------
98  using namespace edm;
99 
100  if (iEvent.run() < 110878) {
101  std::unique_ptr<EventWithHistory> pOut(new EventWithHistory(iEvent));
102  iEvent.put(std::move(pOut));
103 
104  } else {
106  iEvent.getByToken(_l1abccollectionToken, pIn);
107 
108  // offset computation
109 
110  long long orbitoffset = 0;
111  int bxoffset = 0;
112  if (!_forceNoOffset) {
113  for (L1AcceptBunchCrossingCollection::const_iterator l1abc = pIn->begin(); l1abc != pIn->end(); ++l1abc) {
114  if (l1abc->l1AcceptOffset() == 0) {
115  orbitoffset = (long long)l1abc->orbitNumber() - (long long)iEvent.orbitNumber();
116  bxoffset = l1abc->bunchCrossing() - iEvent.bunchCrossing();
117  }
118  }
119  }
120 
121  std::unique_ptr<EventWithHistory> pOut(new EventWithHistory(iEvent, *pIn, orbitoffset, bxoffset));
122  iEvent.put(std::move(pOut));
123 
124  // monitor offset
125 
126  long long absbxoffset = orbitoffset * 3564 + bxoffset;
127 
128  if (_offsets.empty()) {
129  _curroffset = absbxoffset;
130  _curroffevent = iEvent.id().event();
131  _offsets[iEvent.id().event()] = absbxoffset;
132  } else {
133  if (_curroffset != absbxoffset || iEvent.id().event() < _curroffevent) {
134  if (_curroffset != absbxoffset) {
135  edm::LogInfo("AbsoluteBXOffsetChanged")
136  << "Absolute BX offset changed from " << _curroffset << " to " << absbxoffset << " at orbit "
137  << iEvent.orbitNumber() << " and BX " << iEvent.bunchCrossing();
138  for (L1AcceptBunchCrossingCollection::const_iterator l1abc = pIn->begin(); l1abc != pIn->end(); ++l1abc) {
139  edm::LogVerbatim("AbsoluteBXOffsetChanged") << *l1abc;
140  }
141  }
142 
143  _curroffset = absbxoffset;
144  _curroffevent = iEvent.id().event();
145  _offsets[iEvent.id().event()] = absbxoffset;
146  }
147  }
148  }
149 }
150 
152  // reset offset vector
153 
154  _offsets.clear();
155  edm::LogInfo("AbsoluteBXOffsetReset") << "Absolute BX offset map reset";
156 }
157 
159  // summary of absolute bx offset vector
160 
161  edm::LogInfo("AbsoluteBXOffsetSummary") << "Absolute BX offset summary:";
162  for (std::map<edm::EventNumber_t, long long>::const_iterator offset = _offsets.begin(); offset != _offsets.end();
163  ++offset) {
164  edm::LogVerbatim("AbsoluteBXOffsetSummary") << offset->first << " " << offset->second;
165  }
166 }
167 
168 //define this as a plug-in
EventNumber_t event() const
Definition: EventID.h:40
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
int bunchCrossing() const
Definition: EventBase.h:64
unsigned long long EventNumber_t
EventWithHistoryProducerFromL1ABC(const edm::ParameterSet &)
std::map< edm::EventNumber_t, long long > _offsets
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void endRun(const edm::Run &, const edm::EventSetup &) override
RunNumber_t run() const
Definition: Event.h:107
void beginRun(const edm::Run &, const edm::EventSetup &) override
std::vector< L1AcceptBunchCrossing > L1AcceptBunchCrossingCollection
int orbitNumber() const
Definition: EventBase.h:65
void produce(edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< L1AcceptBunchCrossingCollection > _l1abccollectionToken
edm::EventID id() const
Definition: EventBase.h:59
HLT enums.
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45