2 * Copyright (C) 2002-2025 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)
60 // cppcheck-suppress missingReturn
65 * @brief Fetch the variable for one element, as a non-const reference.
66 * @param e The element for which to fetch the variable.
68 template <class T, class ALLOC>
69 template <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>
104 template <IsAuxElement ELT>
106 void Accessor<T, ALLOC>::set (ELT& e, const element_type& x) const
113 * @brief Get a pointer to the start of the auxiliary data array.
114 * @param container The container from which to fetch the variable.
116 template <class T, class ALLOC>
118 typename Accessor<T, ALLOC>::container_pointer_type
119 Accessor<T, ALLOC>::getDataArray (AuxVectorData& container) const
121 return reinterpret_cast<container_pointer_type>
122 (container.getDataArray (this->m_auxid));
127 * @brief Get a span over the auxilary data array.
128 * @param container The container from which to fetch the variable.
130 template <class T, class ALLOC>
132 typename Accessor<T, ALLOC>::span
133 Accessor<T, ALLOC>::getDataSpan (AuxVectorData& container) const
135 auto beg = reinterpret_cast<container_pointer_type>
136 (container.getDataArray (this->m_auxid));
137 return span (beg, container.size_v());
142 * @brief Test to see if this variable exists in the store and is writable.
143 * @param e An element of the container in which to test the variable.
145 template <class T, class ALLOC>
146 template <IsAuxElement ELT>
149 Accessor<T, ALLOC>::isAvailableWritable (ELT& e) const
151 return e.container() && e.container()->isAvailableWritable (this->m_auxid);
156 * @brief Test to see if this variable exists in the store and is writable.
157 * @param c The container in which to test the variable.
159 template <class T, class ALLOC>
162 Accessor<T, ALLOC>::isAvailableWritable (AuxVectorData& c) const
164 return c.isAvailableWritable (this->m_auxid);