ATLAS Offline Software
IOVPayloadContainer.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
8 {
10  delete col;
11  }
12 }
13 
15 {
16  m_payloadVec.reserve(cont.m_payloadVec.size());
18  m_payloadVec.push_back(new CondAttrListCollection(*col));
19  }
20 }
21 
23 {
25  delete col;
26  }
27  m_payloadVec.clear();
28  m_payloadVec.reserve(cont.m_payloadVec.size());
30  m_payloadVec.push_back(new CondAttrListCollection(*col));
31  }
32  return *this;
33 }
34 
35 bool
37 {
38  // We insert new payload ordered by its minimal IOVRange start
39  // time. Duplicates are removed.
40  //
41  // Check for an IOV overlap of the incoming attrListColl with the
42  // previous one. If there is an overlap, then the previous one is
43  // deleted and the new one is kept.
44  //
46  iterator it = std::lower_bound(m_payloadVec.begin(),
47  m_payloadVec.end(),
48  attrListColl->minRange().start(),
50 
51  bool debug = true;
52  debug = false;
53  if (debug) {
54 
55  std::cout << "IOVPayloadContainer::merge - after lowerbound" << std::endl;
56 
57  if (m_payloadVec.begin() != m_payloadVec.end()) {
58  std::cout << "IOVPayloadContainer::merge - begin range "
59  << (*m_payloadVec.begin())->minRange()
60  << std::endl;
61  }
62  if (it != m_payloadVec.end()) {
63  std::cout << "IOVPayloadContainer::merge - it range "
64  << (*it)->minRange()
65  << std::endl;
66  }
67  std::cout << "IOVPayloadContainer::merge - attrList range "
68  << attrListColl->minRange()
69  << std::endl;
70  }
71 
72 
73  if (it != m_payloadVec.begin()) {
74  // Check to see if the new AttrListColl matches the one before
75  // the insertion point, ignoring the minRange. If they match,
76  // then we reject the new one, but use the new stop for the
77  // previous AttrListColl.
78  iterator itPrev = it;
79  --itPrev;
80 
81  if (debug) std::cout << "IOVPayloadContainer::merge - not begin " << std::endl;
82 
83  if ((*itPrev)->isSameButMinRange(*attrListColl)) {
84 
85  // New AttrListColl matches previous one.
86  // Reset IOV to earliest start and latest stop.
87  // Reject insertion of the new one.
88 
89  // We must save start/stop, reset, and set start/stop
90  const IOVTime startPrev = (*itPrev)->minRange().start();
91  const IOVTime stopPrev = (*itPrev)->minRange().stop();
92  const IOVTime startNew = attrListColl->minRange().start();
93  const IOVTime stopNew = attrListColl->minRange().stop();
94  IOVTime start = (startPrev < startNew) ? startPrev : startNew;
95  IOVTime stop = (stopPrev > stopNew) ? stopPrev : stopNew;
96  (*itPrev)->resetMinRange();
97  (*itPrev)->addNewStart(start);
98  (*itPrev)->addNewStop(stop);
99 
100  if (debug) std::cout << "IOVPayloadContainer::merge - isSameButMinRange " << (*itPrev)->minRange() << std::endl;
101 
102 
103  // Now delete or truncate all subsequent IOVs which overlap
104  for (; it != m_payloadVec.end(); ++it) {
105 
106  if (debug) std::cout << "IOVPayloadContainer::merge - isSameButMinRange, subsequent start/stop "
107  << (*it)->minRange().start() << " " << (*it)->minRange().stop()
108  << std::endl;
109 
110  if ((*it)->minRange().stop() <= stop) {
111  // remove attribute list collection
112  CondAttrListCollection* oldAttrListColl = (*it);
113  delete oldAttrListColl;
114  it = m_payloadVec.erase(it);
115  //we deleted the nth element, so that now 'it'
116  //points at the unchecked n+1th element
117 
118  if (debug) std::cout << "IOVPayloadContainer::merge - isSameButMinRange, remove payload "
119  << std::endl;
120 
121  if (it != m_payloadVec.end())
122  {
123  --it; //have to do this otherwise the check on this element will be skipped.
124  continue; // go to the next element
125  }
126  }
127  else if ((*it)->minRange().start() < stop) {
128  // Must truncate old IOV: reset old start to new stop
129  const IOVTime oldStop = (*it)->minRange().stop();
130  (*it)->resetMinRange();
131  (*it)->addNewStart(stop);
132  (*it)->addNewStop(oldStop);
133 
134  if (debug) std::cout << "IOVPayloadContainer::merge - isSameButMinRange, truncate start/stop "
135  << (*it)->minRange().start() << " " << (*it)->minRange().stop()
136  << std::endl;
137 
138  }
139  // we can now leave the loop
140  break;
141  }
142 
143  return false;
144  }
145 
146  if (debug) std::cout << "IOVPayloadContainer::merge - is NOT SameButMinRange - check stop " << (*itPrev)->minRange() << std::endl;
147 
148  if (attrListColl->minRange().start() < (*itPrev)->minRange().stop()) {
149  // Must truncate prev IOV: reset prev stop to new start
150 
151  // But we must first check to see if the current IOV lies
152  // completely within the previous one
153  CondAttrListCollection* prevColl = *itPrev;
154  if (attrListColl->minRange().stop() < prevColl->minRange().stop()) {
155  CondAttrListCollection* prevColl1 = new CondAttrListCollection(*prevColl);
156  prevColl1->addNewStart(attrListColl->minRange().stop());
157 
158  if (debug) std::cout << "IOVPayloadContainer::merge - attrListColl falls within prev IOV range: "
159  << prevColl->minRange().start() << " "
160  << prevColl->minRange().stop()
161  << std::endl;
162 
163  // Now insert the duplicated attribute list collection
164  // (DO NOT increment the iterator for the next
165  // insert!)
166  it = m_payloadVec.insert(it, prevColl1);
167 
168  if (debug) std::cout << "IOVPayloadContainer::merge - duplicated previous and insert "
169  << prevColl1->minRange().start() << " "
170  << prevColl1->minRange().stop()
171  << std::endl;
172  }
173 
174  const IOVTime oldStart = prevColl->minRange().start();
175  prevColl->resetMinRange();
176  prevColl->addNewStart(oldStart);
177  prevColl->addNewStop(attrListColl->minRange().start());
178 
179  if (debug) std::cout << "IOVPayloadContainer::merge - reset prev stop "
180  << prevColl->minRange().start() << " " << prevColl->minRange().stop()
181  << std::endl;
182  }
183  }
184 
185  bool checkOverlap = false;
186  iterator last = m_payloadVec.end();
187  if (it != last) {
188  // Return if duplicate
189  if ( (**it) == (*attrListColl) ) {
190 
191  if (debug) std::cout << "IOVPayloadContainer::merge - duplicate - reject new one " << std::endl;
192 
193  return false;
194  }
195  // Now check if there is a partial match - payload is the
196  // same, the starts are the same and the new stop is > old
197  // stop
198 
199  if (debug) std::cout << "IOVPayloadContainer::merge - isSameButMinRange - ignoreIOVs: " << (*it)->isSameButMinRange(*attrListColl, true) << std::endl;
200 
201  if ((*it)->isSameButMinRange(*attrListColl, true)) {
202 
203  // Payload is the same, ignoring the IOVs
204 
205  // Check that starts are the same, and if new stop is
206  // later keep the new one. And if the new stop is earlier
207  // reject the new one.
208 
209  if ((*it)->minRange().start() == attrListColl->minRange().start() &&
210  (*it)->minRange().stop() < attrListColl->minRange().stop()) {
211 
212  // New AttrListColl extends the max of the old
213  // one. Replace with the new one.
214 
216  delete old;
217  (*it) = attrListColl;
218  const IOVTime stop = attrListColl->minRange().stop();
219 
220  if (debug) std::cout << "IOVPayloadContainer::merge - isSameButMinRange with later stop -> replace " << (*it)->minRange() << std::endl;
221 
222  // Now delete or truncate all subsequent IOVs which overlap
223  ++it;
224  for (; it != m_payloadVec.end(); ++it) {
225 
226  if (debug) std::cout << "IOVPayloadContainer::merge - isSameButMinRange, subsequent start/stop "
227  << (*it)->minRange().start() << " " << (*it)->minRange().stop()
228  << std::endl;
229 
230  if ((*it)->minRange().stop() <= stop) {
231  // remove attribute list collection
232  CondAttrListCollection* oldAttrListColl = (*it);
233  delete oldAttrListColl;
234  it = m_payloadVec.erase(it);
235  //we deleted the nth element, so that now 'it'
236  //points at the unchecked n+1th element
237 
238 
239  if (debug) std::cout << "IOVPayloadContainer::merge - isSameButMinRange, remove payload "
240  << std::endl;
241 
242  if (it != m_payloadVec.end()) {
243  --it; //have to do this otherwise the check on this element will be skipped.
244  continue; // go to the next element
245  }
246  }
247  else if ((*it)->minRange().start() < stop) {
248  // Must truncate old IOV: reset old start to new stop
249  const IOVTime oldStop = (*it)->minRange().stop();
250  (*it)->resetMinRange();
251  (*it)->addNewStart(stop);
252  (*it)->addNewStop(oldStop);
253 
254  if (debug) std::cout << "IOVPayloadContainer::merge - isSameButMinRange, truncate start/stop "
255  << (*it)->minRange().start() << " " << (*it)->minRange().stop()
256  << std::endl;
257 
258  }
259  // we can now leave the loop
260  break;
261  }
262 
263  return true;
264  }
265  else if ((*it)->minRange().start() == attrListColl->minRange().start() &&
266  (*it)->minRange().stop() > attrListColl->minRange().stop()) {
267 
268  if (debug) std::cout << "IOVPayloadContainer::merge - isSameButMinRange, new stop is earlier - reject "
269  << (*it)->minRange().start() << " " << (*it)->minRange().stop()
270  << std::endl;
271  return false;
272  }
273 
274  }
275 
276  checkOverlap = true; // at least one existing AttrListColl
277  }
278 
279  if (checkOverlap) {
280  // AttrListColls differ in content
281  //
282  // Look for overlap of IOVs
283  //
284 
285  // Save start iterator, and new IOV
286  iterator itStart = it;
287  IOVTime newStart = attrListColl->minRange().start();
288  IOVTime newStop = attrListColl->minRange().stop();
289 
290  if (debug) std::cout << "IOVPayloadContainer::merge - checkOverlap, new start/stop "
291  << newStart << " " << newStop
292  << std::endl;
293 
294  // If the new stop is at MAX, then the stop is not correctly
295  // set. This may happen in online mode where the stop is
296  // open-ended.
297  // We treat this in one of two ways:
298  // 1) if new start and old start are the same => set new stop to old stop
299  // 2) if new start < old start => set new stop to old start
300  bool isAtMax = false;
301  if (newStop.isTimestamp()) isAtMax = newStop.timestamp() == IOVTime::MAXTIMESTAMP;
302  else isAtMax = newStop.re_time() == IOVTime::MAXRETIME;
303  if (isAtMax) {
304 
305  if (debug) std::cout << "IOVPayloadContainer::merge - new stop at max " << std::endl;
306 
307  if (newStart == (*it)->minRange().start()) {
308  // Set new stop to old stop
309  attrListColl->resetMinRange();
310  attrListColl->addNewStart(newStart);
311  newStop = (*it)->minRange().stop();
312  attrListColl->addNewStop(newStop);
313 
314  if (debug) std::cout << "IOVPayloadContainer::merge - set new stop to old stop " << std::endl;
315 
316  }
317  else { // newStart < oldStart
318  // Set new top to old start
319  attrListColl->resetMinRange();
320  attrListColl->addNewStart(newStart);
321  newStop = (*it)->minRange().start();
322  attrListColl->addNewStop(newStop);
323 
324  if (debug) std::cout << "IOVPayloadContainer::merge - set new stop to old start " << std::endl;
325 
326  }
327  }
328 
329  // Move back start iterator if we are past begin and the new
330  // start is less than the current start
331  if (it != m_payloadVec.begin() && newStart < (*it)->minRange().start()) {
332 
333  if (debug) std::cout << "IOVPayloadContainer::merge - move back "
334  << std::endl;
335 
336  --itStart;
337  }
338 
339  if (debug) std::cout << "IOVPayloadContainer::merge - checkOverlap, current start/stop "
340  << (*itStart)->minRange().start() << " " << (*itStart)->minRange().stop()
341  << std::endl;
342 
343  // If old start is less than new start, set the old stop to
344  // the new start (i.e. truncate the old IOV)
345  if ((*itStart)->minRange().start() < newStart && newStart < (*itStart)->minRange().stop() ) {
346 // if ((*itStart)->minRange().start() < newStart) {
347  const IOVTime oldStart = (*itStart)->minRange().start();
348  (*itStart)->resetMinRange();
349  (*itStart)->addNewStart(oldStart);
350  (*itStart)->addNewStop(newStart);
351 
352  if (debug) std::cout << "IOVPayloadContainer::merge - reset old stop "
353  << (*itStart)->minRange().start() << " " << (*itStart)->minRange().stop()
354  << " " << newStart
355  << std::endl;
356 
357  }
358 
359  // Now insert the new attribute list collection
360  it = m_payloadVec.insert(it, attrListColl);
361 
362  if (debug) std::cout << "IOVPayloadContainer::merge - insert payload "
363  << std::endl;
364 
365  // Move the iterator forward
366  ++it;
367 
368  // Now delete or truncate all subsequent IOVs which overlap
369  for (; it != m_payloadVec.end(); ++it) {
370 
371  if (debug) std::cout << "IOVPayloadContainer::merge - checkOverlap, subsequent start/stop "
372  << (*it)->minRange().start() << " " << (*it)->minRange().stop()
373  << std::endl;
374 
375  if ((*it)->minRange().stop() <= newStop) {
376  // remove attribute list collection
377  CondAttrListCollection* oldAttrListColl = (*it);
378  delete oldAttrListColl;
379  it = m_payloadVec.erase(it);
380 
381  if (debug) std::cout << "IOVPayloadContainer::merge - remove payload "
382  << std::endl;
383 
384  if (it != m_payloadVec.end()) {
385  --it; //have to do this otherwise the check on this element will be skipped.
386  continue; // go to the next element
387  }
388  }
389  else if ((*it)->minRange().start() < newStop) {
390  // Must truncate old IOV: reset old start to new stop
391  const IOVTime oldStop = (*it)->minRange().stop();
392  (*it)->resetMinRange();
393  (*it)->addNewStart(newStop);
394  (*it)->addNewStop(oldStop);
395 
396  if (debug) std::cout << "IOVPayloadContainer::merge - checkOverlap, truncate start/stop "
397  << (*it)->minRange().start() << " " << (*it)->minRange().stop()
398  << std::endl;
399 
400  }
401  // we can now leave the loop
402  break;
403  }
404 
405  return true;
406  }
407 
408  if (debug) std::cout << "IOVPayloadContainer::merge - no overlap, add in attrListColl " << std::endl;
409 
410  // no overlaps - add in attribute list
411  m_payloadVec.insert(it, attrListColl);
412 
413  return (true);
414 }
415 
416 
417 
418 
419 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
CondAttrListCollection::resetMinRange
void resetMinRange()
Reset minRange according to the IOVs of the contained channels.
Definition: CondAttrListCollection.h:529
IOVPayloadContainer.h
This class is a container for the payload of conditions data. It is intended to be used to store cond...
IOVTime::MAXRETIME
static constexpr uint64_t MAXRETIME
Definition: IOVTime.h:53
CondAttrListCollection::minRange
IOVRange minRange() const
Current minimal IOVRange.
Definition: CondAttrListCollection.h:438
CondAttrListCollection::addNewStop
void addNewStop(const IOVTime &stop)
Add new stop time to minRange - make sure that stop is <= to new stop
Definition: CondAttrListCollection.h:518
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
IOVRange::start
const IOVTime & start() const
Definition: IOVRange.h:38
IOVTime::timestamp
uint64_t timestamp() const noexcept
Definition: IOVTime.h:108
skel.it
it
Definition: skel.GENtoEVGEN.py:423
IOVTime::re_time
uint64_t re_time() const noexcept
Definition: IOVTime.h:107
CondAttrListCollection::addNewStart
void addNewStart(const IOVTime &start)
Add new start time to minRange - make sure that start is >= to new start.
Definition: CondAttrListCollection.h:508
PixelModuleFeMask_create_db.stop
int stop
Definition: PixelModuleFeMask_create_db.py:76
CondAttrListCollection
This class is a collection of AttributeLists where each one is associated with a channel number....
Definition: CondAttrListCollection.h:52
IOVPayloadContainer::IOVPayloadContainer
IOVPayloadContainer()
Definition: IOVPayloadContainer.h:102
IOVRange::stop
const IOVTime & stop() const
Definition: IOVRange.h:39
IOVPayloadContainer::operator=
IOVPayloadContainer & operator=(const IOVPayloadContainer &cont)
Definition: IOVPayloadContainer.cxx:22
IOVTime
Basic time unit for IOVSvc. Hold time as a combination of run and event numbers.
Definition: IOVTime.h:33
IOVPayloadContainer::~IOVPayloadContainer
~IOVPayloadContainer()
Definition: IOVPayloadContainer.cxx:7
IOVTime::MAXTIMESTAMP
static constexpr uint64_t MAXTIMESTAMP
Definition: IOVTime.h:58
IOVPayloadContainer::m_payloadVec
payloadVec m_payloadVec
Definition: IOVPayloadContainer.h:97
IOVTime::isTimestamp
bool isTimestamp() const noexcept
Definition: IOVTime.h:111
IOVPayloadContainer
This class is a container for the payload of conditions data. It is intended to be used to store cond...
Definition: IOVPayloadContainer.h:35
debug
const bool debug
Definition: MakeUncertaintyPlots.cxx:53
query_example.col
col
Definition: query_example.py:7
IOVPayloadContainer::AttrListCollSortStart
Definition: IOVPayloadContainer.h:85
CSV_InDetExporter.old
old
Definition: CSV_InDetExporter.py:145
IOVPayloadContainer::merge
bool merge(CondAttrListCollection *attrListColl)
Add in new payload, checking that it is not a duplicate.
Definition: IOVPayloadContainer.cxx:36