ATLAS Offline Software
CondCont.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 /**
5  * @file AthenaKernel/CondCont.icc
6  * @author Vakho, Charles, Scott
7  * @date 2017
8  * @brief Hold mappings of ranges to condition objects.
9  */
10 
11 
12 /**
13  * @brief Return the CLID of the most-derived @c CondCont.
14  */
15 inline
16 CLID CondContBase::clid() const
17 {
18  return m_clid;
19 }
20 
21 
22 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
23 
24 
25 /**
26  * @brief Return the key type for this container.
27  */
28 inline
29 CondContBase::KeyType CondContBase::keyType() const
30 {
31  return m_keyType;
32 }
33 
34 
35 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
36 
37 
38 /**
39  * @brief Return CLID/key corresponding to this container.
40  */
41 inline
42 const DataObjID& CondContBase::id() const
43 {
44  return m_id;
45 }
46 
47 
48 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
49 
50 
51 /**
52  * @brief Return the associated @c DataProxy, if any.
53  */
54 inline
55 SG::DataProxy* CondContBase::proxy()
56 {
57  return m_proxy;
58 }
59 
60 
61 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
62 
63 
64 /**
65  * @brief Return the associated @c DataProxy, if any.
66  */
67 inline
68 const SG::DataProxy* CondContBase::proxy() const
69 {
70  return m_proxy;
71 }
72 
73 
74 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
75 
76 
77 /**
78  * @brief Do pointer conversion for the payload type.
79  * @param clid CLID for the desired pointer type.
80  * @param ptr Pointer of type @c T*.
81  *
82  * For the base class, we just return null.
83  */
84 inline
85 const void* CondContBase::cast (CLID /*clid*/, const void* /*ptr*/) const
86 {
87  return nullptr;
88 }
89 
90 
91 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
92 
93 
94 /**
95  * @brief Make a run+lbn key from an EventIDBase.
96  * @param Event ID to convert.
97  */
98 inline
99 CondContBase::key_type CondContBase::keyFromRunLBN (const EventIDBase& b)
100 {
101  return (static_cast<key_type> (b.run_number())<<32) + b.lumi_block();
102 }
103 
104 
105 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
106 
107 
108 /**
109  * @brief Make a timestamp key from an EventIDBase.
110  * @param Event ID to convert.
111  */
112 inline
113 CondContBase::key_type CondContBase::keyFromTimestamp (const EventIDBase& b)
114 {
115  return (static_cast<key_type> (b.time_stamp())*1000000000) + b.time_stamp_ns_offset();
116 }
117 
118 
119 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
120 
121 
122 /**
123  * @brief Call @c func on each entry in the container.
124  * @param func Functional to call on each entry.
125  *
126  * @c func will be called on each container element
127  * (being passed const CondContSet::value_type&).
128  */
129 template <class FUNC>
130 void CondContBase::forEach (const FUNC& func) const
131 {
132  for (const typename CondContSet::value_type& ent : m_condSet.range()) {
133  func (ent);
134  }
135 }
136 
137 
138 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
139 
140 
141 /**
142  * @brief Default constructor.
143  */
144 inline
145 CondContBase::RangeKey::RangeKey()
146  : m_start(0),
147  m_stop(0)
148 {
149 }
150 
151 
152 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
153 
154 
155 /**
156  * @brief Constructor from range+start/stop.
157  * @param r The range to store.
158  * @param start Packed start time.
159  * @param stop Packed stop time.
160  */
161 inline
162 CondContBase::RangeKey::RangeKey (const EventIDRange& r,
163  key_type start,
164  key_type stop)
165  : m_start (start),
166  m_stop (stop),
167  m_range (r)
168 {
169 }
170 
171 
172 ///////////////////////////////////////////////////////////////////////////
173 
174 
175 /**
176  * @brief Test to see if a given IOV time is mapped in the container.
177  * @param t IOV time to check.
178  */
179 inline
180 bool CondContSingleBase::valid (const EventIDBase& t) const
181 {
182  return findBase (t, nullptr) != nullptr;
183 }
184 
185 
186 ///////////////////////////////////////////////////////////////////////////
187 
188 
189 /**
190  * @brief Constructor.
191  * @param rcusvc RCU service instance.
192  * @param id CLID+key for this object.
193  * @param proxy @c DataProxy for this object.
194  * @param capacity Initial capacity of the container.
195  */
196 template <class T>
197 inline
198 CondCont<T>::CondCont (Athena::IRCUSvc& rcusvc,
199  const DataObjID& id,
200  SG::DataProxy* proxy /*=nullptr*/,
201  size_t capacity /*= 16*/)
202  : Base (rcusvc, ClassID_traits<CondCont<T> >::ID(), id, proxy,
203  std::make_shared<Athena::CondObjDeleter<T> > (rcusvc),
204  capacity)
205 {
206  CondCont<T>::registerBaseInit();
207 }
208 
209 
210 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
211 
212 
213 /**
214  * @brief Destructor.
215  */
216 template <typename T>
217 CondCont<T>::~CondCont()
218 {
219 }
220 
221 
222 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
223 
224 
225 /**
226  * @brief Insert a new conditions object.
227  * @param r Range of validity of this object.
228  * @param t Pointer to the object being inserted.
229  * @param ctx Event context for the current thread.
230  *
231  * @c t must point to an object of type @c T.
232  * This will give an error if this is not called
233  * on the most-derived @c CondCont.
234  *
235  * Returns SUCCESS if the object was successfully inserted;
236  * EXTENDED if the last existing range in the container was extended
237  * to match the new range;
238  * OVERLAP if the object was inserted but the range partially overlaps
239  * with an existing one;
240  * DUPLICATE if the object wasn't inserted because the range
241  * duplicates an existing one, and FAILURE otherwise
242  * (ownership of the object will be taken in any case).
243  */
244 template <typename T>
245 StatusCode CondCont<T>::insert (const EventIDRange& r,
246  std::unique_ptr<T> t,
247  const EventContext& ctx /*= Gaudi::Hive::currentContext()*/)
248 {
249  if (this->clid() != ClassID_traits<CondCont<T> >::ID()) {
250  this->insertError (ClassID_traits<CondCont<T> >::ID());
251  return StatusCode::FAILURE;
252  }
253 
254  return Base::insertBase (r, std::move(t), ctx);
255 }
256 
257 
258 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
259 
260 
261 /**
262  * @brief Look up a conditions object for a given time.
263  * @param t IOV time to find.
264  * @param obj[out] Object found.
265  * @param r If non-null, copy validity range of the object here.
266  *
267  * Returns true if the object was found; false otherwide.
268  */
269 template <typename T>
270 bool CondCont<T>::find (const EventIDBase& t,
271  T const *& obj,
272  EventIDRange const** r) const
273 {
274  const void* ptr = Base::findBase (t, r);
275 
276  if (ClassID_traits<CondCont<T> >::ID() != this->clid()) {
277  ptr = doCast (ClassID_traits<CondCont<T> >::ID(), ptr);
278  }
279 
280  obj = reinterpret_cast<const T*> (ptr);
281  return obj != nullptr;
282 }
283 
284 
285 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
286 
287 
288 /**
289  * @brief Look up a conditions object for a given time.
290  * @param t IOV time to find.
291  *
292  * Returns the found object, or nullptr.
293  *
294  * This variant may be more convenient to call from python.
295  */
296 template <typename T>
297 const T* CondCont<T>::find (const EventIDBase& t) const
298 {
299  const T* obj = nullptr;
300  if (this->find (t, obj)) {
301  return obj;
302  }
303  return nullptr;
304 }
305 
306 
307 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
308 
309 
310 /**
311  * @brief Do pointer conversion for the payload type.
312  * @param clid CLID for the desired pointer type.
313  * @param ptr Pointer of type @c T*.
314  *
315  * Converts @c ptr from @c T* to a pointer to the type
316  * given by @c clid. Returns nullptr if the conversion
317  * is not possible.
318  *
319  * This is a virtual function that calls @c cast from the most-derived class
320  * of the hierarchy.
321  */
322 template <typename T>
323 inline
324 const void* CondCont<T>::doCast (CLID clid, const void* ptr) const
325 {
326  return cast (clid, ptr);
327 }
328 
329 
330 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
331 
332 
333 /**
334  * @brief Internal constructor.
335  * @param rcusvc RCU service instance.
336  * @param CLID of the most-derived @c CondCont.
337  * @param id CLID+key for this object.
338  * @param proxy @c DataProxy for this object.
339  * @param payloadDeleter Object for deleting payload objects.
340  * @param capacity Initial capacity of the container.
341  */
342 template <typename T>
343 inline
344 CondCont<T>::CondCont (Athena::IRCUSvc& rcusvc,
345  CLID clid,
346  const DataObjID& id,
347  SG::DataProxy* proxy,
348  std::shared_ptr<typename CondContSet::IPayloadDeleter> payloadDeleter,
349  size_t capacity)
350  : Base (rcusvc, clid, id, proxy, payloadDeleter, capacity)
351 {
352  CondCont<T>::registerBaseInit();
353 }
354 
355 
356 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
357 
358 
359 /**
360  * @brief Do pointer conversion for the payload type.
361  * @param clid CLID for the desired pointer type.
362  * @param ptr Pointer of type @c T*.
363  *
364  * Converts @c ptr from @c T* to a pointer to the type
365  * given by @c clid. Returns nullptr if the conversion
366  * is not possible.
367  */
368 template <typename T>
369 inline
370 const void* CondCont<T>::cast (CLID clid, const void* ptr) const
371 {
372  if (clid == ClassID_traits<CondCont<T> >::ID())
373  return ptr;
374  return Base::cast (clid, static_cast<const typename Base::Payload*>
375  (reinterpret_cast<const T*> (ptr)));
376 }
377 
378 
379 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
380 
381 
382 /**
383  * @brief Helper to ensure that the inheritance information for this class
384  * gets initialized.
385  */
386 template <class T>
387 void CondCont<T>::registerBaseInit()
388 {
389  static const SG::RegisterBaseInit<CondCont> rbi;
390 }
391 
392 
393 ///////////////////////////////////////////////////////////////////////////
394 
395 
396 /**
397  * @brief Test to see if a given IOV time is mapped in the container.
398  * @param t IOV time to check.
399  */
400 inline
401 bool CondContMixedBase::valid (const EventIDBase& t) const
402 {
403  return findMixed (t, nullptr) != nullptr;
404 }
405 
406 
407 ///////////////////////////////////////////////////////////////////////////
408 
409 
410 /**
411  * @brief Destructor.
412  */
413 template <typename T>
414 CondContMixed<T>::~CondContMixed()
415 {
416 }
417 
418 
419 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
420 
421 
422 /**
423  * @brief Insert a new conditions object.
424  * @param r Range of validity of this object.
425  * @param t Pointer to the object being inserted.
426  * @param ctx Event context for the current thread.
427  *
428  * @c t must point to an object of type @c T.
429  * This will give an error if this is not called
430  * on the most-derived @c CondCont.
431  *
432  * Returns SUCCESS if the object was successfully inserted;
433  * OVERLAP if the object was inserted but the range partially overlaps
434  * with an existing one;
435  * DUPLICATE if the object wasn't inserted because the range
436  * duplicates an existing one, and FAILURE otherwise
437  * (ownership of the object will be taken in any case).
438  */
439 template <typename T>
440 StatusCode CondContMixed<T>::insert (const EventIDRange& r,
441  std::unique_ptr<T> t,
442  const EventContext& ctx /*= Gaudi::Hive::currentContext()*/)
443 {
444  if (this->clid() != ClassID_traits<CondCont<T> >::ID()) {
445  this->insertError (ClassID_traits<CondCont<T> >::ID());
446  return StatusCode::FAILURE;
447  }
448 
449  return Base::insertMixed (r, std::move(t), ctx);
450 }
451 
452 
453 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
454 
455 
456 /**
457  * @brief Look up a conditions object for a given time.
458  * @param t IOV time to find.
459  * @param obj[out] Object found.
460  * @param r If non-null, copy validity range of the object here.
461  *
462  * Returns true if the object was found; false otherwide.
463  */
464 template <typename T>
465 bool CondContMixed<T>::find (const EventIDBase& t,
466  T const *& obj,
467  EventIDRange const** r) const
468 {
469  const void* ptr = Base::findMixed (t, r);
470 
471  if (ClassID_traits<CondCont<T> >::ID() != this->clid()) {
472  ptr = doCast (ClassID_traits<CondCont<T> >::ID(), ptr);
473  }
474 
475  obj = reinterpret_cast<const T*> (ptr);
476  return obj != nullptr;
477 }
478 
479 
480 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
481 
482 
483 /**
484  * @brief Look up a conditions object for a given time.
485  * @param t IOV time to find.
486  *
487  * Returns the found object, or nullptr.
488  *
489  * This variant may be more convenient to call from python.
490  */
491 template <typename T>
492 const T* CondContMixed<T>::find (const EventIDBase& t) const
493 {
494  const T* obj = nullptr;
495  if (this->find (t, obj)) {
496  return obj;
497  }
498  return nullptr;
499 }
500 
501 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
502 
503 
504 /**
505  * @brief Internal constructor.
506  * @param rcusvc RCU service instance.
507  * @param CLID of the most-derived @c CondCont.
508  * @param id CLID+key for this object.
509  * @param proxy @c DataProxy for this object.
510  * @param payloadDeleter Object for deleting actual payload objects.
511  * @param capacity Initial capacity of the container.
512  */
513 template <class T>
514 inline
515 CondContMixed<T>::CondContMixed (Athena::IRCUSvc& rcusvc,
516  CLID clid,
517  const DataObjID& id,
518  SG::DataProxy* proxy,
519  std::shared_ptr<typename CondContSet::IPayloadDeleter> payloadDeleter,
520  size_t capacity)
521  : Base (rcusvc, clid, id, proxy, payloadDeleter, capacity)
522 {
523  CondContMixed<T>::registerBaseInit();
524 }
525 
526 
527 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
528 
529 
530 /**
531  * @brief Internal constructor.
532  * @param rcusvc RCU service instance.
533  * @param CLID of the most-derived @c CondCont.
534  * @param id CLID+key for this object.
535  * @param proxy @c DataProxy for this object.
536  * @param capacity Initial capacity of the container.
537  */
538 template <class T>
539 inline
540 CondContMixed<T>::CondContMixed (Athena::IRCUSvc& rcusvc,
541  CLID clid,
542  const DataObjID& id,
543  SG::DataProxy* proxy,
544  size_t capacity)
545  : CondContMixed<T> (rcusvc, clid, id, proxy,
546  std::make_shared<Athena::CondObjDeleter<T> > (rcusvc),
547  capacity)
548 {
549 }
550 
551 
552 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
553 
554 
555 /**
556  * @brief Do pointer conversion for the payload type.
557  * @param clid CLID for the desired pointer type.
558  * @param ptr Pointer of type @c T*.
559  *
560  * Converts @c ptr from @c T* to a pointer to the type
561  * given by @c clid. Returns nullptr if the conversion
562  * is not possible.
563  */
564 template <typename T>
565 inline
566 const void* CondContMixed<T>::cast (CLID clid, const void* ptr) const
567 {
568  if (clid == ClassID_traits<CondCont<T> >::ID())
569  return ptr;
570  return Base::cast (clid, static_cast<const typename Base::Payload*>
571  (reinterpret_cast<const T*> (ptr)));
572 }
573 
574 
575 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
576 
577 
578 /**
579  * @brief Do pointer conversion for the payload type.
580  * @param clid CLID for the desired pointer type.
581  * @param ptr Pointer of type @c T*.
582  *
583  * Converts @c ptr from @c T* to a pointer to the type
584  * given by @c clid. Returns nullptr if the conversion
585  * is not possible.
586  *
587  * This is a virtual function that calls @c cast from the most-derived class
588  * of the hierarchy.
589  */
590 template <typename T>
591 inline
592 const void* CondContMixed<T>::doCast (CLID clid, const void* ptr) const
593 {
594  return cast (clid, ptr);
595 }
596 
597 
598 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
599 
600 
601 /**
602  * @brief Helper to ensure that the inheritance information for this class
603  * gets initialized.
604  */
605 template <class T>
606 void CondContMixed<T>::registerBaseInit()
607 {
608  static const SG::RegisterBaseInit<CondContMixed> rbi;
609 }
610 
611