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

Helper class to provide type-safe access to aux data. More...

#include <Accessor.h>

Inheritance diagram for SG::Accessor< T, ALLOC >:
Collaboration diagram for SG::Accessor< T, ALLOC >:

Public Types

using reference_type = typename AuxDataTraits<T, ALLOC>::reference_type
 Type referencing an item.
using element_type = typename AuxDataTraits<T, ALLOC>::element_type
 Type the user sees.
using container_pointer_type
 Pointer into the container holding this item.
using span = typename AuxDataTraits<T, ALLOC>::span
 A span over elements in the container.
using const_reference_type
 Type referencing an item.
using const_container_pointer_type
 Pointer into the container holding this item.
using const_span = typename AuxDataTraits<T, ALLOC>::const_span
 A span over elements in the container.

Public Member Functions

 Accessor (const std::string &name)
 Constructor.
 Accessor (const std::string &name, const std::string &clsname)
 Constructor.
 Accessor (const SG::auxid_t auxid)
 Constructor taking an auxid directly.
template<IsAuxElement ELT>
reference_type operator() (ELT &e) const
 Fetch the variable for one element, as a non-const reference.
reference_type operator() (AuxVectorData &container, size_t index) const
 Fetch the variable for one element, as a non-const reference.
template<IsAuxElement ELT>
void set (ELT &e, const element_type &x) const
 Set the variable for one element.
container_pointer_type getDataArray (AuxVectorData &container) const
 Get a pointer to the start of the auxiliary data array.
span getDataSpan (AuxVectorData &container) const
 Get a span over the auxilary data array.
template<IsAuxElement ELT>
bool isAvailableWritable (ELT &e) const
 Test to see if this variable exists in the store and is writable.
bool isAvailableWritable (AuxVectorData &c) const
 Test to see if this variable exists in the store and is writable.
template<IsConstAuxElement ELT>
const_reference_type operator() (const ELT &e) const
 Fetch the variable for one element, as a const reference.
const_reference_type operator() (const AuxVectorData &container, size_t index) const
 Fetch the variable for one element, as a const reference.
template<IsConstAuxElement ELT>
const_reference_type withDefault (const ELT &e, const T &deflt) const
 Fetch the variable for one element, as a const reference, with a default.
const_reference_type withDefault (const AuxVectorData &container, size_t index, const T &deflt) const
 Fetch the variable for one element, as a const reference.
const_container_pointer_type getDataArray (const AuxVectorData &container) const
 Get a pointer to the start of the auxiliary data array.
const_span getDataSpan (const AuxVectorData &container) const
 Get a span over the auxilary data array.
template<IsConstAuxElement ELT>
bool isAvailable (const ELT &e) const
 Test to see if this variable exists in the store.
bool isAvailable (const AuxVectorData &c) const
 Test to see if this variable exists in the store.
SG::auxid_t auxid () const
 Return the aux id for this variable.

Protected Attributes

SG::auxid_t m_auxid
 The cached auxid.

Detailed Description

template<class T, class ALLOC = AuxAllocator_t<T>>
class SG::Accessor< T, ALLOC >

Helper class to provide type-safe access to aux data.

This is written as a separate class in order to be able to cache the name -> auxid lookup.

You might use this something like this:

// Only need to do this once.
static const SG::Accessor<int> vint1 ("myInt");
...
DataVector<MyClass>* v = ...;
Myclass* m = v->at(2);
int x = ...;
vint1 (*m) = x;
#define x
Helper class to provide type-safe access to aux data.

You can also use this to define getters/setters in your class:

class Myclass {
...
int get_x() const
{ const static SG::ConstAccessor<int> acc ("x");
return acc (*this); }
int& get_x()
{ const static SG::Accessor<int> acc ("x");
return acc (*this); }
Helper class to provide constant type-safe access to aux data.

Definition at line 66 of file Control/AthContainers/AthContainers/Accessor.h.

Member Typedef Documentation

◆ const_container_pointer_type

template<class T, class ALLOC = AuxAllocator_t<T>>
using SG::ConstAccessor< T, ALLOC >::const_container_pointer_type
inherited
Initial value:
typename vector_type::const_pointer const_container_pointer_type

Pointer into the container holding this item.

Definition at line 65 of file ConstAccessor.h.

◆ const_reference_type

template<class T, class ALLOC = AuxAllocator_t<T>>
using SG::ConstAccessor< T, ALLOC >::const_reference_type
inherited
Initial value:

Type referencing an item.

Definition at line 61 of file ConstAccessor.h.

◆ const_span

template<class T, class ALLOC = AuxAllocator_t<T>>
using SG::ConstAccessor< T, ALLOC >::const_span = typename AuxDataTraits<T, ALLOC>::const_span
inherited

A span over elements in the container.

Definition at line 69 of file ConstAccessor.h.

◆ container_pointer_type

template<class T, class ALLOC = AuxAllocator_t<T>>
using SG::Accessor< T, ALLOC >::container_pointer_type
Initial value:
typename vector_type::pointer container_pointer_type
Pointers to the data within the container.

Pointer into the container holding this item.

Definition at line 77 of file Control/AthContainers/AthContainers/Accessor.h.

◆ element_type

template<class T, class ALLOC = AuxAllocator_t<T>>
using SG::Accessor< T, ALLOC >::element_type = typename AuxDataTraits<T, ALLOC>::element_type

Type the user sees.

Definition at line 74 of file Control/AthContainers/AthContainers/Accessor.h.

◆ reference_type

template<class T, class ALLOC = AuxAllocator_t<T>>
using SG::Accessor< T, ALLOC >::reference_type = typename AuxDataTraits<T, ALLOC>::reference_type

Type referencing an item.

Definition at line 71 of file Control/AthContainers/AthContainers/Accessor.h.

◆ span

template<class T, class ALLOC = AuxAllocator_t<T>>
using SG::Accessor< T, ALLOC >::span = typename AuxDataTraits<T, ALLOC>::span

A span over elements in the container.

Definition at line 81 of file Control/AthContainers/AthContainers/Accessor.h.

Constructor & Destructor Documentation

◆ Accessor() [1/3]

template<class T, class ALLOC = AuxAllocator_t<T>>
SG::Accessor< T, ALLOC >::Accessor ( const std::string & name)

Constructor.

Parameters
nameName of this aux variable.

The name -> auxid lookup is done here.

◆ Accessor() [2/3]

template<class T, class ALLOC = AuxAllocator_t<T>>
SG::Accessor< T, ALLOC >::Accessor ( const std::string & name,
const std::string & clsname )

Constructor.

Parameters
nameName of this aux variable.
clsnameThe name of its associated class. May be blank.

The name -> auxid lookup is done here.

◆ Accessor() [3/3]

template<class T, class ALLOC = AuxAllocator_t<T>>
SG::Accessor< T, ALLOC >::Accessor ( const SG::auxid_t auxid)

Constructor taking an auxid directly.

Parameters
auxidID for this auxiliary variable.

Will throw SG::ExcAuxTypeMismatch if the types don't match.

Member Function Documentation

◆ auxid()

template<class T, class ALLOC = AuxAllocator_t<T>>
SG::auxid_t SG::ConstAccessor< T, ALLOC >::auxid ( ) const
inherited

Return the aux id for this variable.

◆ getDataArray() [1/2]

template<class T, class ALLOC = AuxAllocator_t<T>>
container_pointer_type SG::Accessor< T, ALLOC >::getDataArray ( AuxVectorData & container) const

Get a pointer to the start of the auxiliary data array.

Parameters
containerThe container from which to fetch the variable.

◆ getDataArray() [2/2]

template<class T, class ALLOC = AuxAllocator_t<T>>
const_container_pointer_type SG::ConstAccessor< T, ALLOC >::getDataArray ( const AuxVectorData & container) const
inherited

Get a pointer to the start of the auxiliary data array.

Parameters
containerThe container from which to fetch the variable.

◆ getDataSpan() [1/2]

template<class T, class ALLOC = AuxAllocator_t<T>>
span SG::Accessor< T, ALLOC >::getDataSpan ( AuxVectorData & container) const

Get a span over the auxilary data array.

Parameters
containerThe container from which to fetch the variable.

◆ getDataSpan() [2/2]

template<class T, class ALLOC = AuxAllocator_t<T>>
const_span SG::ConstAccessor< T, ALLOC >::getDataSpan ( const AuxVectorData & container) const
inherited

Get a span over the auxilary data array.

Parameters
containerThe container from which to fetch the variable.

◆ isAvailable() [1/2]

template<class T, class ALLOC = AuxAllocator_t<T>>
bool SG::ConstAccessor< T, ALLOC >::isAvailable ( const AuxVectorData & c) const
inherited

Test to see if this variable exists in the store.

Parameters
cThe container in which to test the variable.

◆ isAvailable() [2/2]

template<class T, class ALLOC = AuxAllocator_t<T>>
template<IsConstAuxElement ELT>
bool SG::ConstAccessor< T, ALLOC >::isAvailable ( const ELT & e) const
inherited

Test to see if this variable exists in the store.

Parameters
eAn element of the container in which to test the variable.

◆ isAvailableWritable() [1/2]

template<class T, class ALLOC = AuxAllocator_t<T>>
bool SG::Accessor< T, ALLOC >::isAvailableWritable ( AuxVectorData & c) const

Test to see if this variable exists in the store and is writable.

Parameters
cThe container in which to test the variable.

◆ isAvailableWritable() [2/2]

template<class T, class ALLOC = AuxAllocator_t<T>>
template<IsAuxElement ELT>
bool SG::Accessor< T, ALLOC >::isAvailableWritable ( ELT & e) const

Test to see if this variable exists in the store and is writable.

Parameters
eAn element of the container in which to test the variable.

◆ operator()() [1/4]

template<class T, class ALLOC = AuxAllocator_t<T>>
reference_type SG::Accessor< T, ALLOC >::operator() ( AuxVectorData & container,
size_t index ) const

Fetch the variable for one element, as a non-const reference.

Parameters
containerThe container from which to fetch the variable.
indexThe index of the desired element.

This allows retrieving aux data by container / index. Looping over the index via this method will be faster then looping over the elements of the container.

◆ operator()() [2/4]

template<class T, class ALLOC = AuxAllocator_t<T>>
template<IsAuxElement ELT>
reference_type SG::Accessor< T, ALLOC >::operator() ( ELT & e) const

Fetch the variable for one element, as a non-const reference.

Parameters
eThe element for which to fetch the variable.

◆ operator()() [3/4]

template<class T, class ALLOC = AuxAllocator_t<T>>
const_reference_type SG::ConstAccessor< T, ALLOC >::operator() ( const AuxVectorData & container,
size_t index ) const
inherited

Fetch the variable for one element, as a const reference.

Parameters
containerThe container from which to fetch the variable.
indexThe index of the desired element.

This allows retrieving aux data by container / index. Looping over the index via this method will be faster then looping over the elements of the container.

◆ operator()() [4/4]

template<class T, class ALLOC = AuxAllocator_t<T>>
template<IsConstAuxElement ELT>
const_reference_type SG::ConstAccessor< T, ALLOC >::operator() ( const ELT & e) const
inherited

Fetch the variable for one element, as a const reference.

Parameters
eThe element for which to fetch the variable.

◆ set()

template<class T, class ALLOC = AuxAllocator_t<T>>
template<IsAuxElement ELT>
void SG::Accessor< T, ALLOC >::set ( ELT & e,
const element_type & x ) const

Set the variable for one element.

Parameters
eThe element for which to fetch the variable.
xThe variable value to set.

◆ withDefault() [1/2]

template<class T, class ALLOC = AuxAllocator_t<T>>
const_reference_type SG::ConstAccessor< T, ALLOC >::withDefault ( const AuxVectorData & container,
size_t index,
const T & deflt ) const
inherited

Fetch the variable for one element, as a const reference.

Parameters
containerThe container from which to fetch the variable.
indexThe index of the desired element.
defltDefault value.

This allows retrieving aux data by container / index. Looping over the index via this method will be faster then looping over the elements of the container. If this variable is not available, then return deflt instead.

◆ withDefault() [2/2]

template<class T, class ALLOC = AuxAllocator_t<T>>
template<IsConstAuxElement ELT>
const_reference_type SG::ConstAccessor< T, ALLOC >::withDefault ( const ELT & e,
const T & deflt ) const
inherited

Fetch the variable for one element, as a const reference, with a default.

Parameters
eThe element for which to fetch the variable.
defltDefault value.

If this variable is not available, then return deflt instead.

Member Data Documentation

◆ m_auxid

template<class T, class ALLOC = AuxAllocator_t<T>>
SG::auxid_t SG::ConstAccessor< T, ALLOC >::m_auxid
protectedinherited

The cached auxid.

Definition at line 211 of file ConstAccessor.h.


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