2 * Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
6 * @author scott snyder <snyder@bnl.gov>
8 * @brief Helper class to provide type-safe access to aux data.
12 #include "AthContainers/AuxTypeRegistry.h"
13 #include "AthContainers/exceptions.h"
21 * @param name Name of this aux variable.
23 * The name -> auxid lookup is done here.
25 template <class T, class ALLOC>
27 Accessor<T, ALLOC>::Accessor (const std::string& name)
28 : ConstAccessor<T, ALLOC> (name)
35 * @param name Name of this aux variable.
36 * @param clsname The name of its associated class. May be blank.
38 * The name -> auxid lookup is done here.
40 template <class T, class ALLOC>
42 Accessor<T, ALLOC>::Accessor (const std::string& name,
43 const std::string& clsname)
44 : ConstAccessor<T, ALLOC> (name, clsname)
50 * @brief Constructor taking an auxid directly.
51 * @param auxid ID for this auxiliary variable.
53 * Will throw @c SG::ExcAuxTypeMismatch if the types don't match.
55 template <class T, class ALLOC>
57 Accessor<T, ALLOC>::Accessor (const SG::auxid_t auxid)
58 : ConstAccessor<T, ALLOC> (auxid)
64 * @brief Fetch the variable for one element, as a non-const reference.
65 * @param e The element for which to fetch the variable.
67 template <class T, class ALLOC>
69 ATH_REQUIRES( IsAuxElement<ELT> )
71 typename Accessor<T, ALLOC>::reference_type
72 Accessor<T, ALLOC>::operator() (ELT& e) const
74 assert (e.container() != 0);
75 return e.container()->template getData<T> (this->m_auxid, e.index());
80 * @brief Fetch the variable for one element, as a non-const reference.
81 * @param container The container from which to fetch the variable.
82 * @param index The index of the desired element.
84 * This allows retrieving aux data by container / index.
85 * Looping over the index via this method will be faster then
86 * looping over the elements of the container.
88 template <class T, class ALLOC>
90 typename Accessor<T, ALLOC>::reference_type
91 Accessor<T, ALLOC>::operator() (AuxVectorData& container,
94 return container.template getData<T> (this->m_auxid, index);
99 * @brief Set the variable for one element.
100 * @param e The element for which to fetch the variable.
101 * @param x The variable value to set.
103 template <class T, class ALLOC>
105 ATH_REQUIRES( IsAuxElement<ELT> )
107 void Accessor<T, ALLOC>::set (ELT& e, const element_type& x) const
114 * @brief Get a pointer to the start of the auxiliary data array.
115 * @param container The container from which to fetch the variable.
117 template <class T, class ALLOC>
119 typename Accessor<T, ALLOC>::container_pointer_type
120 Accessor<T, ALLOC>::getDataArray (AuxVectorData& container) const
122 return reinterpret_cast<container_pointer_type>
123 (container.getDataArray (this->m_auxid));
128 * @brief Get a span over the auxilary data array.
129 * @param container The container from which to fetch the variable.
131 template <class T, class ALLOC>
133 typename Accessor<T, ALLOC>::span
134 Accessor<T, ALLOC>::getDataSpan (AuxVectorData& container) const
136 auto beg = reinterpret_cast<container_pointer_type>
137 (container.getDataArray (this->m_auxid));
138 return span (beg, container.size_v());
143 * @brief Test to see if this variable exists in the store and is writable.
144 * @param e An element of the container which to test the variable.
146 template <class T, class ALLOC>
148 ATH_REQUIRES( IsAuxElement<ELT> )
151 Accessor<T, ALLOC>::isAvailableWritable (ELT& e) const
153 return e.container() && e.container()->isAvailableWritable (this->m_auxid);