CMS 3D CMS Logo

EventWithHistory.cc
Go to the documentation of this file.
1 #include <map>
8 
10 
12 
14  : TinyEvent(event, orbit, bx), _prevse() {}
15 
16 EventWithHistory::EventWithHistory(const edm::EventNumber_t event, const unsigned int orbit, const int bx)
17  : TinyEvent(event, orbit, bx), _prevse() {}
18 
20 
21 EventWithHistory::EventWithHistory(const std::vector<edm::EventAuxiliary>& veaux)
22  : TinyEvent((!veaux.empty()) ? veaux[veaux.size() - 1] : TinyEvent()), _prevse() {
23  for (std::vector<edm::EventAuxiliary>::const_reverse_iterator eaux = veaux.rbegin(); eaux != veaux.rend(); eaux++) {
24  if (eaux != veaux.rbegin()) {
25  _prevse.push_back(*eaux);
26  }
27  }
28 }
29 
31  const L1AcceptBunchCrossingCollection& l1abcc,
32  const long long orbitoffset,
33  const int bxoffset)
34  : TinyEvent(), _prevse() {
35  std::map<int, TinyEvent> tmpmap;
36 
37  for (L1AcceptBunchCrossingCollection::const_iterator l1abc = l1abcc.begin(); l1abc != l1abcc.end(); ++l1abc) {
38  if (event.id().event() > (edm::EventNumber_t)(-1 * l1abc->l1AcceptOffset())) {
39  edm::EventNumber_t evnumb = event.id().event() + l1abc->l1AcceptOffset();
40  if (orbitoffset < (long long)l1abc->orbitNumber()) {
41  unsigned int neworbit = l1abc->orbitNumber() - orbitoffset;
42  int newbx = l1abc->bunchCrossing() - bxoffset;
43 
44  /*
45  the lines below assumes that the BX number is between 0 and 3563. If this is not the case it will jump to 0 and to the next orbit in case of
46  evets with BX=3564
47  */
48  while (newbx > 3563) {
49  ++neworbit;
50  newbx -= 3564;
51  }
52  while (newbx < 0) {
53  --neworbit;
54  newbx += 3564;
55  }
56 
57  if (l1abc->eventType() != 0) {
58  TinyEvent tmpse(evnumb, neworbit, newbx);
59  tmpmap[l1abc->l1AcceptOffset()] = tmpse;
60  } else {
61  edm::LogWarning("L1AcceptBunchCrossingNoType") << "L1AcceptBunchCrossing with no type found: ";
62  for (L1AcceptBunchCrossingCollection::const_iterator debu = l1abcc.begin(); debu != l1abcc.end(); ++debu) {
63  edm::LogPrint("L1AcceptBunchCrossingNoType") << *debu;
64  }
65  }
66  } else {
67  edm::LogError("L1AcceptBunchCrossingOffsetTooLarge")
68  << " Too large orbit offset " << orbitoffset << " " << l1abc->orbitNumber();
69  }
70  } else {
71  edm::LogInfo("L1AcceptBunchCrossingNegativeEvent") << "L1AcceptBunchCrossing with negative event: ";
72  for (L1AcceptBunchCrossingCollection::const_iterator debu = l1abcc.begin(); debu != l1abcc.end(); ++debu) {
73  edm::LogVerbatim("L1AcceptBunchCrossingNegativeEvent") << *debu;
74  }
75  }
76  }
77  // look for the event itself
78  if (tmpmap.find(0) != tmpmap.end()) {
79  TinyEvent::operator=(tmpmap[0]);
80 
81  // loop on the rest of the map and stop when it is missing
82  // check that the events are in the right order and break if not
83 
84  int counter = -1;
85  while (tmpmap.find(counter) != tmpmap.end()) {
86  if (tmpmap[counter + 1].deltaBX(tmpmap[counter]) > 0) {
87  _prevse.push_back(tmpmap[counter]);
88  --counter;
89  } else {
90  edm::LogWarning("L1AcceptBunchCrossingNotInOrder")
91  << "L1AcceptBunchCrossing not in order: orbit " << event.orbitNumber() << " BX " << event.bunchCrossing()
92  << " orbit offset " << orbitoffset << " bx offset " << bxoffset << " :";
93  for (L1AcceptBunchCrossingCollection::const_iterator debu = l1abcc.begin(); debu != l1abcc.end(); ++debu) {
94  edm::LogPrint("L1AcceptBunchCrossingNotInOrder") << *debu;
95  }
96  break;
97  }
98  }
99  } else {
101  edm::LogWarning("L1AcceptBunchCrossingNoCollection") << " L1AcceptBunchCrossing with offset=0 not found "
102  << " likely L1ABCCollection is empty ";
103  }
104 }
105 
107  const TCDSRecord& tcdsRecord,
108  const long long orbitoffset,
109  const int bxoffset)
110  : TinyEvent(), _prevse() {
111  std::map<int, TinyEvent> tmpmap;
112 
113  // loop on the history
114  auto l1aHistory = tcdsRecord.getFullL1aHistory();
115  const L1aInfo infoForIndex0 = L1aInfo(0, tcdsRecord.getOrbitNr(), tcdsRecord.getBXID(), tcdsRecord.getEventType());
116  l1aHistory.push_back(infoForIndex0);
117 
118  for (auto l1a : l1aHistory) {
119  int l1AcceptOffset(l1a.getIndex());
120 
121  if (event.id().event() > (edm::EventNumber_t)(-1 * l1AcceptOffset)) {
122  edm::EventNumber_t evnumb = event.id().event() + l1AcceptOffset;
123  if (orbitoffset < (long long)l1a.getOrbitNr()) {
124  unsigned int neworbit = l1a.getOrbitNr() - orbitoffset;
125  int newbx = l1a.getBXID() - bxoffset;
126 
127  /*
128  the lines below assumes that the BX number is between 0 and 3563. If this is not the case it will jump to 0 and to the next orbit in case of
129  evets with BX=3564
130  */
131 
132  while (newbx > 3563) {
133  ++neworbit;
134  newbx -= 3564;
135  }
136  while (newbx < 0) {
137  --neworbit;
138  newbx += 3564;
139  }
140 
141  if (tcdsRecord.getEventType() != 0) {
142  TinyEvent tmpse(evnumb, neworbit, newbx);
143  tmpmap[l1AcceptOffset] = tmpse;
144  } else {
145  edm::LogWarning("L1AcceptBunchCrossingNoType") << "L1AcceptBunchCrossing with no type found: ";
146  edm::LogPrint("L1AcceptBunchCrossingNoType") << &tcdsRecord;
147  }
148  } else {
149  edm::LogError("L1AcceptBunchCrossingOffsetTooLarge")
150  << " Too large orbit offset " << orbitoffset << " " << tcdsRecord.getOrbitNr();
151  }
152  } else {
153  edm::LogInfo("L1AcceptBunchCrossingNegativeEvent") << "L1AcceptBunchCrossing with negative event: ";
154  edm::LogVerbatim("L1AcceptBunchCrossingNegativeEvent") << &tcdsRecord;
155  }
156  }
157 
158  // look for the event itself
159  if (tmpmap.find(0) != tmpmap.end()) {
160  TinyEvent::operator=(tmpmap[0]);
161 
162  // loop on the rest of the map and stop when it is missing
163  // check that the events are in the right order and break if not
164 
165  int counter = -1;
166  while (tmpmap.find(counter) != tmpmap.end()) {
167  if (tmpmap[counter + 1].deltaBX(tmpmap[counter]) > 0) {
168  _prevse.push_back(tmpmap[counter]);
169  --counter;
170  } else {
171  edm::LogWarning("L1AcceptBunchCrossingNotInOrder")
172  << "L1AcceptBunchCrossing not in order: orbit " << event.orbitNumber() << " BX " << event.bunchCrossing()
173  << " orbit offset " << orbitoffset << " bx offset " << bxoffset << " :";
174  edm::LogPrint("L1AcceptBunchCrossingNotInOrder") << &tcdsRecord;
175  break;
176  }
177  }
178  } else {
180  edm::LogWarning("L1AcceptBunchCrossingNoCollection") << " L1AcceptBunchCrossing with offset=0 not found "
181  << " likely TCDSRecord is empty ";
182  }
183 }
184 
186 
188  if (this != &he) {
190  _prevse = he._prevse;
191  }
192  return *this;
193 }
194 
195 // int EventWithHistory::operator<(const EventWithHistory& other) const { return TinyEvent::operator<(other); }
196 
199 
200  // depth is not checked anymore
201 
202  // equal = equal && (depth() == other.depth());
203 
204  if (equal) {
205  for (unsigned int i = 0; i < ((depth() < other.depth()) ? depth() : other.depth()); i++) {
206  equal = equal && (_prevse[i] == other._prevse[i]);
207  }
208  }
209 
210  return equal;
211 }
212 
213 int EventWithHistory::add(const EventWithHistory& he, const int idepth) {
214  if (!add((const TinyEvent&)he, idepth))
215  return 0;
216 
217  for (std::vector<TinyEvent>::const_iterator ev = he._prevse.begin(); ev != he._prevse.end(); ev++) {
218  if (!add(*ev, idepth))
219  return 0;
220  }
221  return 1;
222 }
223 
224 int EventWithHistory::add(const TinyEvent& se, const int idepth) {
225  bool isfuture = (idepth < 0);
226  const unsigned int adepth = abs(idepth);
227 
228  // protect against the possibility of filling with past and future history
229 
230  if (depth() > 0 && ((isfuture && !isFutureHistory()) || (!isfuture && isFutureHistory())))
231  return 0;
232 
233  if (adepth == 0)
234  return 0;
235  if (_prevse.size() >= adepth)
236  return 0;
237 
238  if (_prevse.empty()) {
239  if ((!isfuture && isNextOf(se)) || (isfuture && se.isNextOf(*this))) {
240  _prevse.push_back(se);
241  return 1;
242  } else {
243  return 0;
244  }
245  } else {
246  if ((!isfuture && _prevse[_prevse.size() - 1].isNextOf(se)) ||
247  (isfuture && se.isNextOf(_prevse[_prevse.size() - 1]))) {
248  _prevse.push_back(se);
249  return 1;
250  } else {
251  return 0;
252  }
253  }
254  return 0;
255 }
256 
258 const unsigned int EventWithHistory::orbit() const { return TinyEvent::_orbit; }
259 const int EventWithHistory::bx() const { return TinyEvent::_bx; }
260 
261 const TinyEvent* EventWithHistory::get(const unsigned int ev) const {
262  if (ev == 0)
263  return this;
264  if (ev <= _prevse.size())
265  return &_prevse[ev - 1];
266  return nullptr;
267 }
268 
269 unsigned int EventWithHistory::depth() const { return _prevse.size(); }
270 
271 bool EventWithHistory::isFutureHistory() const { return (depth() > 0 && _prevse[0].isNextOf(*this)); }
272 
273 long long EventWithHistory::deltaBX(const unsigned int ev2, const unsigned int ev1) const {
274  if (ev2 == ev1)
275  return 0;
276 
277  if (ev2 < ev1 && ev1 <= _prevse.size()) {
278  if (ev2 == 0)
279  return TinyEvent::deltaBX(_prevse[ev1 - 1]);
280  return _prevse[ev2 - 1].deltaBX(_prevse[ev1 - 1]);
281  }
282 
283  return -1;
284 }
285 
286 long long EventWithHistory::deltaBX(const unsigned int ev1) const { return deltaBX(0, ev1); }
287 
288 long long EventWithHistory::deltaBX() const { return deltaBX(0, 1); }
289 
290 long long EventWithHistory::deltaBX(const TinyEvent& se) const { return TinyEvent::deltaBX(se); }
291 
292 long long EventWithHistory::absoluteBX(const unsigned int ev1) const {
293  if (ev1 == 0)
294  return TinyEvent::absoluteBX();
295  if (ev1 <= _prevse.size())
296  return _prevse[ev1 - 1].absoluteBX();
297 
298  return -1;
299 }
300 
302 
303 long long EventWithHistory::absoluteBXinCycle(const unsigned int ev1, const int bx0) const {
304  if (ev1 == 0)
305  return TinyEvent::absoluteBXinCycle(bx0);
306  if (ev1 <= _prevse.size())
307  return _prevse[ev1 - 1].absoluteBXinCycle(bx0);
308 
309  return -1;
310 }
311 
312 long long EventWithHistory::absoluteBXinCycle(const int bx0) const { return TinyEvent::absoluteBXinCycle(bx0); }
313 
314 long long EventWithHistory::deltaBXinCycle(const unsigned int ev2, const unsigned int ev1, const int bx0) const {
315  if (ev2 == ev1 && ev1 <= _prevse.size()) {
316  if (ev2 == 0)
317  return TinyEvent::deltaBXinCycle(*this, bx0);
318  return _prevse[ev2 - 1].deltaBXinCycle(_prevse[ev1 - 1], bx0);
319  }
320 
321  if (ev2 < ev1 && ev1 <= _prevse.size()) {
322  if (ev2 == 0)
323  return TinyEvent::deltaBXinCycle(_prevse[ev1 - 1], bx0);
324  return _prevse[ev2 - 1].deltaBXinCycle(_prevse[ev1 - 1], bx0);
325  }
326 
327  return -1;
328 }
329 
330 long long EventWithHistory::deltaBXinCycle(const unsigned int ev1, const int bx0) const {
331  return deltaBXinCycle(0, ev1, bx0);
332 }
333 
334 long long EventWithHistory::deltaBXinCycle(const int bx0) const { return deltaBXinCycle(0, 1, bx0); }
335 
336 long long EventWithHistory::deltaBXinCycle(const TinyEvent& se, const int bx0) const {
337  return TinyEvent::deltaBXinCycle(se, bx0);
338 }
EventWithHistory::_prevse
std::vector< TinyEvent > _prevse
Definition: EventWithHistory.h:68
counter
Definition: counter.py:1
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
TCDSRecord::getBXID
uint16_t getBXID() const
Definition: TCDSRecord.h:85
simpleEdmComparison.ev2
ev2
Definition: simpleEdmComparison.py:153
edm::LogInfo
Definition: MessageLogger.h:254
l1GtPatternGenerator_cfi.bx
bx
Definition: l1GtPatternGenerator_cfi.py:18
TinyEvent::_event
edm::EventNumber_t _event
Definition: TinyEvent.h:64
L1AcceptBunchCrossing.h
TinyEvent::deltaBXinCycle
long long deltaBXinCycle(const TinyEvent &se, const int bx0) const
Definition: TinyEvent.h:58
EventWithHistory.h
EventWithHistory::operator==
int operator==(const EventWithHistory &other) const
Definition: EventWithHistory.cc:197
TinyEvent::_orbit
unsigned int _orbit
Definition: TinyEvent.h:65
TCDSRecord::getOrbitNr
uint64_t getOrbitNr() const
Definition: TCDSRecord.h:88
TinyEvent::isNextOf
int isNextOf(const TinyEvent &se) const
Definition: TinyEvent.h:43
EventWithHistory::depth
unsigned int depth() const
Definition: EventWithHistory.cc:269
EventWithHistory::isFutureHistory
bool isFutureHistory() const
Definition: EventWithHistory.cc:271
TinyEvent::absoluteBX
long long absoluteBX() const
Definition: TinyEvent.h:45
TCDSRecord.h
TinyEvent::deltaBX
long long deltaBX(const TinyEvent &se) const
Definition: TinyEvent.h:49
L1AcceptBunchCrossingCollection
std::vector< L1AcceptBunchCrossing > L1AcceptBunchCrossingCollection
Definition: L1AcceptBunchCrossing.h:83
trackingPlots.other
other
Definition: trackingPlots.py:1465
edm::EventNumber_t
unsigned long long EventNumber_t
Definition: RunLumiEventNumber.h:12
TCDSRecord::getFullL1aHistory
const L1aHistory & getFullL1aHistory() const
Definition: TCDSRecord.h:108
edm::LogWarning
Definition: MessageLogger.h:141
edm::LogError
Definition: MessageLogger.h:183
EventWithHistory::EventWithHistory
EventWithHistory()
Definition: EventWithHistory.cc:9
Event.h
TCDSRecord::getEventType
uint16_t getEventType() const
Definition: TCDSRecord.h:74
EventWithHistory::get
const TinyEvent * get(const unsigned int ev) const
Definition: EventWithHistory.cc:261
EventWithHistory::operator=
EventWithHistory & operator=(const EventWithHistory &he)
Definition: EventWithHistory.cc:187
EventWithHistory::deltaBX
long long deltaBX() const
Definition: EventWithHistory.cc:288
EventWithHistory::orbit
const unsigned int orbit() const
Definition: EventWithHistory.cc:258
edm::LogVerbatim
Definition: MessageLogger.h:297
L1aInfo
Class to contain L1 accept history information from TCDS FED.
Definition: L1aInfo.h:16
edm::LogPrint
Definition: MessageLogger.h:342
counter
static std::atomic< unsigned int > counter
Definition: SharedResourceNames.cc:15
EventWithHistory::event
const edm::EventNumber_t event() const
Definition: EventWithHistory.cc:257
EventWithHistory
Definition: EventWithHistory.h:17
EventWithHistory::deltaBXinCycle
long long deltaBXinCycle(const unsigned int ev2, const unsigned int ev1, const int bx0) const
Definition: EventWithHistory.cc:314
TinyEvent::_bx
unsigned int _bx
Definition: TinyEvent.h:66
EventWithHistory::absoluteBX
long long absoluteBX() const
Definition: EventWithHistory.cc:301
simpleEdmComparison.ev1
ev1
Definition: simpleEdmComparison.py:153
TinyEvent::operator==
int operator==(const TinyEvent &other) const
Definition: TinyEvent.h:39
TinyEvent
Definition: TinyEvent.h:13
TinyEvent::absoluteBXinCycle
long long absoluteBXinCycle(const int bx0) const
Definition: TinyEvent.h:47
hcalSimParameters_cfi.he
he
Definition: hcalSimParameters_cfi.py:75
EventWithHistory::bx
const int bx() const
Definition: EventWithHistory.cc:259
TCDSRecord
Class to contain information from TCDS FED.
Definition: TCDSRecord.h:19
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
EventAuxiliary.h
ev
bool ev
Definition: Hydjet2Hadronizer.cc:95
EventWithHistory::absoluteBXinCycle
long long absoluteBXinCycle(const unsigned int ev1, const int bx0) const
Definition: EventWithHistory.cc:303
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
event
Definition: event.py:1
EcalDumpRaw_cfi.l1aHistory
l1aHistory
Definition: EcalDumpRaw_cfi.py:11
edm::Event
Definition: Event.h:73
cond::serialization::equal
bool equal(const T &first, const T &second)
Definition: Equal.h:32
EventWithHistory::add
int add(const EventWithHistory &he, const int idepth)
Definition: EventWithHistory.cc:213
TinyEvent::operator=
TinyEvent & operator=(const TinyEvent &se)
Definition: TinyEvent.h:27
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443