2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5 * @file AthenaKernel/CondCont.icc
6 * @author Vakho, Charles, Scott
8 * @brief Hold mappings of ranges to condition objects.
13 * @brief Return the CLID of the most-derived @c CondCont.
16 CLID CondContBase::clid() const
22 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
26 * @brief Return the key type for this container.
29 CondContBase::KeyType CondContBase::keyType() const
35 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
39 * @brief Return CLID/key corresponding to this container.
42 const DataObjID& CondContBase::id() const
48 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
52 * @brief Return the associated @c DataProxy, if any.
55 SG::DataProxy* CondContBase::proxy()
61 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
65 * @brief Return the associated @c DataProxy, if any.
68 const SG::DataProxy* CondContBase::proxy() const
74 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
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*.
82 * For the base class, we just return null.
85 const void* CondContBase::cast (CLID /*clid*/, const void* /*ptr*/) const
91 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
95 * @brief Make a run+lbn key from an EventIDBase.
96 * @param Event ID to convert.
99 CondContBase::key_type CondContBase::keyFromRunLBN (const EventIDBase& b)
101 return (static_cast<key_type> (b.run_number())<<32) + b.lumi_block();
105 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
109 * @brief Make a timestamp key from an EventIDBase.
110 * @param Event ID to convert.
113 CondContBase::key_type CondContBase::keyFromTimestamp (const EventIDBase& b)
115 return (static_cast<key_type> (b.time_stamp())*1000000000) + b.time_stamp_ns_offset();
119 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
123 * @brief Call @c func on each entry in the container.
124 * @param func Functional to call on each entry.
126 * @c func will be called on each container element
127 * (being passed const CondContSet::value_type&).
129 template <class FUNC>
130 void CondContBase::forEach (const FUNC& func) const
132 for (const typename CondContSet::value_type& ent : m_condSet.range()) {
138 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
142 * @brief Default constructor.
145 CondContBase::RangeKey::RangeKey()
152 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
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.
162 CondContBase::RangeKey::RangeKey (const EventIDRange& r,
172 ///////////////////////////////////////////////////////////////////////////
176 * @brief Test to see if a given IOV time is mapped in the container.
177 * @param t IOV time to check.
180 bool CondContSingleBase::valid (const EventIDBase& t) const
182 return findBase (t, nullptr) != nullptr;
186 ///////////////////////////////////////////////////////////////////////////
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.
198 CondCont<T>::CondCont (Athena::IRCUSvc& rcusvc,
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),
206 CondCont<T>::registerBaseInit();
210 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
216 template <typename T>
217 CondCont<T>::~CondCont()
222 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
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.
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.
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).
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()*/)
249 if (this->clid() != ClassID_traits<CondCont<T> >::ID()) {
250 this->insertError (ClassID_traits<CondCont<T> >::ID());
251 return StatusCode::FAILURE;
254 return Base::insertBase (r, std::move(t), ctx);
258 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
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.
267 * Returns true if the object was found; false otherwide.
269 template <typename T>
270 bool CondCont<T>::find (const EventIDBase& t,
272 EventIDRange const** r) const
274 const void* ptr = Base::findBase (t, r);
276 if (ClassID_traits<CondCont<T> >::ID() != this->clid()) {
277 ptr = doCast (ClassID_traits<CondCont<T> >::ID(), ptr);
280 obj = reinterpret_cast<const T*> (ptr);
281 return obj != nullptr;
285 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
289 * @brief Look up a conditions object for a given time.
290 * @param t IOV time to find.
292 * Returns the found object, or nullptr.
294 * This variant may be more convenient to call from python.
296 template <typename T>
297 const T* CondCont<T>::find (const EventIDBase& t) const
299 const T* obj = nullptr;
300 if (this->find (t, obj)) {
307 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
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*.
315 * Converts @c ptr from @c T* to a pointer to the type
316 * given by @c clid. Returns nullptr if the conversion
319 * This is a virtual function that calls @c cast from the most-derived class
322 template <typename T>
324 const void* CondCont<T>::doCast (CLID clid, const void* ptr) const
326 return cast (clid, ptr);
330 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
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.
342 template <typename T>
344 CondCont<T>::CondCont (Athena::IRCUSvc& rcusvc,
347 SG::DataProxy* proxy,
348 std::shared_ptr<typename CondContSet::IPayloadDeleter> payloadDeleter,
350 : Base (rcusvc, clid, id, proxy, payloadDeleter, capacity)
352 CondCont<T>::registerBaseInit();
356 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
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*.
364 * Converts @c ptr from @c T* to a pointer to the type
365 * given by @c clid. Returns nullptr if the conversion
368 template <typename T>
370 const void* CondCont<T>::cast (CLID clid, const void* ptr) const
372 if (clid == ClassID_traits<CondCont<T> >::ID())
374 return Base::cast (clid, static_cast<const typename Base::Payload*>
375 (reinterpret_cast<const T*> (ptr)));
379 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
383 * @brief Helper to ensure that the inheritance information for this class
387 void CondCont<T>::registerBaseInit()
389 static const SG::RegisterBaseInit<CondCont> rbi;
393 ///////////////////////////////////////////////////////////////////////////
397 * @brief Test to see if a given IOV time is mapped in the container.
398 * @param t IOV time to check.
401 bool CondContMixedBase::valid (const EventIDBase& t) const
403 return findMixed (t, nullptr) != nullptr;
407 ///////////////////////////////////////////////////////////////////////////
413 template <typename T>
414 CondContMixed<T>::~CondContMixed()
419 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
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.
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.
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).
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()*/)
444 if (this->clid() != ClassID_traits<CondCont<T> >::ID()) {
445 this->insertError (ClassID_traits<CondCont<T> >::ID());
446 return StatusCode::FAILURE;
449 return Base::insertMixed (r, std::move(t), ctx);
453 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
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.
462 * Returns true if the object was found; false otherwide.
464 template <typename T>
465 bool CondContMixed<T>::find (const EventIDBase& t,
467 EventIDRange const** r) const
469 const void* ptr = Base::findMixed (t, r);
471 if (ClassID_traits<CondCont<T> >::ID() != this->clid()) {
472 ptr = doCast (ClassID_traits<CondCont<T> >::ID(), ptr);
475 obj = reinterpret_cast<const T*> (ptr);
476 return obj != nullptr;
480 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
484 * @brief Look up a conditions object for a given time.
485 * @param t IOV time to find.
487 * Returns the found object, or nullptr.
489 * This variant may be more convenient to call from python.
491 template <typename T>
492 const T* CondContMixed<T>::find (const EventIDBase& t) const
494 const T* obj = nullptr;
495 if (this->find (t, obj)) {
501 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
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.
515 CondContMixed<T>::CondContMixed (Athena::IRCUSvc& rcusvc,
518 SG::DataProxy* proxy,
519 std::shared_ptr<typename CondContSet::IPayloadDeleter> payloadDeleter,
521 : Base (rcusvc, clid, id, proxy, payloadDeleter, capacity)
523 CondContMixed<T>::registerBaseInit();
527 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
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.
540 CondContMixed<T>::CondContMixed (Athena::IRCUSvc& rcusvc,
543 SG::DataProxy* proxy,
545 : CondContMixed<T> (rcusvc, clid, id, proxy,
546 std::make_shared<Athena::CondObjDeleter<T> > (rcusvc),
552 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
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*.
560 * Converts @c ptr from @c T* to a pointer to the type
561 * given by @c clid. Returns nullptr if the conversion
564 template <typename T>
566 const void* CondContMixed<T>::cast (CLID clid, const void* ptr) const
568 if (clid == ClassID_traits<CondCont<T> >::ID())
570 return Base::cast (clid, static_cast<const typename Base::Payload*>
571 (reinterpret_cast<const T*> (ptr)));
575 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
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*.
583 * Converts @c ptr from @c T* to a pointer to the type
584 * given by @c clid. Returns nullptr if the conversion
587 * This is a virtual function that calls @c cast from the most-derived class
590 template <typename T>
592 const void* CondContMixed<T>::doCast (CLID clid, const void* ptr) const
594 return cast (clid, ptr);
598 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
602 * @brief Helper to ensure that the inheritance information for this class
606 void CondContMixed<T>::registerBaseInit()
608 static const SG::RegisterBaseInit<CondContMixed> rbi;