ATLAS Offline Software
Loading...
Searching...
No Matches
SG::SlotSpecificObj< T, InvalidSlot > Class Template Reference

Maintain a set of objects, one per slot. More...

#include <SlotSpecificObj.h>

Collaboration diagram for SG::SlotSpecificObj< T, InvalidSlot >:

Public Types

typedef std::vector< T >::iterator iterator
typedef std::vector< T >::const_iterator const_iterator
typedef std::vector< T >::value_type value_type

Public Member Functions

 SlotSpecificObj ()
 Constructor.
 SlotSpecificObj (size_t nslots)
 Constructor, with number of slots specified explicitly.
T * get (const EventContext &ctx)
 Return pointer to the object for slot given by ctx.
T * get ()
 Return pointer to the object for the current slot.
const T * get (const EventContext &ctx) const
 Return pointer to the object for slot given by ctx.
const T * get () const
 Return pointer to the object for the current slot.
T & operator* ()
 Dereference the pointer.
const T & operator* () const
 Dereference the pointer.
T * operator-> ()
 Dereference the pointer.
const T * operator-> () const
 Dereference the pointer.
iterator begin ()
 Begin iterator.
const_iterator begin () const
 Const begin iterator.
iterator end ()
 End iterator.
const_iterator end () const
 Const end iterator.

Private Attributes

std::vector< T > m_slots
 Set of per-slot objects.

Detailed Description

template<class T, InvalidSlot = InvalidSlot::Disabled>
class SG::SlotSpecificObj< T, InvalidSlot >

Maintain a set of objects, one per slot.

The payload T must be default-constructable. One such instance of T will be made for each event slot.

The usual pointer operators may be used to access the object, as well as get(). get() also takes an optional event context argument, to allow specifying the slot explicitly, rather than looking it up in a thread-local global. The access to the object is range-checked and a std::out_of_range exception is thrown in case a non-existent slot is used.

By default only objects for a valid EventContext can be stored/retrieved. To simplify use also outside of the event loop, the storage of an extra object for the invalid EventContext can be enabled by the InvalidSlot template parameter. When iterating over the objects, the extra object will be the last one.

This class does not do anything itself to protect the contents of the payload objects against simultaneous access from different threads. Especially if the owner is a service or a reentrant algorithm, multiple threads may be executing simultaneously for the same slot. In such cases, T must be safe against simultaneous access from multiple threads, possibly with an internal lock or using std::atomic.

This is similiar to ContextSpecificPtr from Gaudi, but with some important differences:

  • The payload objects are managed and owned by this class.
  • Rather than using an unordered_map with locking, we just use a vector, indexed by slot. We thus don't need any locking. The price of this is that we need to know the number of slots when we're constructed.
  • We allow requesting a given slot explicitly, via an EventContext argument.
  • We optionally support an extra object for the invalid EventContext.

Definition at line 83 of file AthenaKernel/AthenaKernel/SlotSpecificObj.h.

Member Typedef Documentation

◆ const_iterator

template<class T, InvalidSlot = InvalidSlot::Disabled>
typedef std::vector<T>::const_iterator SG::SlotSpecificObj< T, InvalidSlot >::const_iterator

Definition at line 169 of file AthenaKernel/AthenaKernel/SlotSpecificObj.h.

◆ iterator

template<class T, InvalidSlot = InvalidSlot::Disabled>
typedef std::vector<T>::iterator SG::SlotSpecificObj< T, InvalidSlot >::iterator

Definition at line 168 of file AthenaKernel/AthenaKernel/SlotSpecificObj.h.

◆ value_type

template<class T, InvalidSlot = InvalidSlot::Disabled>
typedef std::vector<T>::value_type SG::SlotSpecificObj< T, InvalidSlot >::value_type

Definition at line 170 of file AthenaKernel/AthenaKernel/SlotSpecificObj.h.

Constructor & Destructor Documentation

◆ SlotSpecificObj() [1/2]

template<class T, InvalidSlot = InvalidSlot::Disabled>
SG::SlotSpecificObj< T, InvalidSlot >::SlotSpecificObj ( )

Constructor.

The number of slots will be found by calling getNSlots().

◆ SlotSpecificObj() [2/2]

template<class T, InvalidSlot = InvalidSlot::Disabled>
SG::SlotSpecificObj< T, InvalidSlot >::SlotSpecificObj ( size_t nslots)
explicit

Constructor, with number of slots specified explicitly.

Parameters
nslotsThe number of event slots.

Member Function Documentation

◆ begin() [1/2]

template<class T, InvalidSlot = InvalidSlot::Disabled>
iterator SG::SlotSpecificObj< T, InvalidSlot >::begin ( )

Begin iterator.

◆ begin() [2/2]

template<class T, InvalidSlot = InvalidSlot::Disabled>
const_iterator SG::SlotSpecificObj< T, InvalidSlot >::begin ( ) const

Const begin iterator.

◆ end() [1/2]

template<class T, InvalidSlot = InvalidSlot::Disabled>
iterator SG::SlotSpecificObj< T, InvalidSlot >::end ( )

End iterator.

◆ end() [2/2]

template<class T, InvalidSlot = InvalidSlot::Disabled>
const_iterator SG::SlotSpecificObj< T, InvalidSlot >::end ( ) const

Const end iterator.

◆ get() [1/4]

template<class T, InvalidSlot = InvalidSlot::Disabled>
T * SG::SlotSpecificObj< T, InvalidSlot >::get ( )

Return pointer to the object for the current slot.

The slot number is found by retrieving the global current context.

◆ get() [2/4]

template<class T, InvalidSlot = InvalidSlot::Disabled>
const T * SG::SlotSpecificObj< T, InvalidSlot >::get ( ) const

Return pointer to the object for the current slot.

The slot number is found by retrieving the global current context.

◆ get() [3/4]

template<class T, InvalidSlot = InvalidSlot::Disabled>
T * SG::SlotSpecificObj< T, InvalidSlot >::get ( const EventContext & ctx)

Return pointer to the object for slot given by ctx.

Parameters
ctxEvent context giving the desired slot.

◆ get() [4/4]

template<class T, InvalidSlot = InvalidSlot::Disabled>
const T * SG::SlotSpecificObj< T, InvalidSlot >::get ( const EventContext & ctx) const

Return pointer to the object for slot given by ctx.

Parameters
ctxEvent context giving the desired slot.

◆ operator*() [1/2]

template<class T, InvalidSlot = InvalidSlot::Disabled>
T & SG::SlotSpecificObj< T, InvalidSlot >::operator* ( )

Dereference the pointer.

The slot number is found by retrieving the global current context.

◆ operator*() [2/2]

template<class T, InvalidSlot = InvalidSlot::Disabled>
const T & SG::SlotSpecificObj< T, InvalidSlot >::operator* ( ) const

Dereference the pointer.

The slot number is found by retrieving the global current context.

◆ operator->() [1/2]

template<class T, InvalidSlot = InvalidSlot::Disabled>
T * SG::SlotSpecificObj< T, InvalidSlot >::operator-> ( )

Dereference the pointer.

The slot number is found by retrieving the global current context.

◆ operator->() [2/2]

template<class T, InvalidSlot = InvalidSlot::Disabled>
const T * SG::SlotSpecificObj< T, InvalidSlot >::operator-> ( ) const

Dereference the pointer.

The slot number is found by retrieving the global current context.

Member Data Documentation

◆ m_slots

template<class T, InvalidSlot = InvalidSlot::Disabled>
std::vector<T> SG::SlotSpecificObj< T, InvalidSlot >::m_slots
private

Set of per-slot objects.

Definition at line 199 of file AthenaKernel/AthenaKernel/SlotSpecificObj.h.


The documentation for this class was generated from the following file: