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)
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>
70 ATH_REQUIRES( IsAuxElement<ELT> )
72 typename Accessor<T, ALLOC>::reference_type
73 Accessor<T, ALLOC>::operator() (ELT& e) const
75 assert (e.container() != 0);
76 return e.container()->template getData<T> (this->m_auxid, e.index());
81 * @brief Fetch the variable for one element, as a non-const reference.
82 * @param container The container from which to fetch the variable.
83 * @param index The index of the desired element.
85 * This allows retrieving aux data by container / index.
86 * Looping over the index via this method will be faster then
87 * looping over the elements of the container.
89 template <class T, class ALLOC>
91 typename Accessor<T, ALLOC>::reference_type
92 Accessor<T, ALLOC>::operator() (AuxVectorData& container,
95 return container.template getData<T> (this->m_auxid, index);
100 * @brief Set the variable for one element.
101 * @param e The element for which to fetch the variable.
102 * @param x The variable value to set.
104 template <class T, class ALLOC>
106 ATH_REQUIRES( IsAuxElement<ELT> )
108 void Accessor<T, ALLOC>::set (ELT& e, const element_type& x) const
115 * @brief Get a pointer to the start of the auxiliary data array.
116 * @param container The container from which to fetch the variable.
118 template <class T, class ALLOC>
120 typename Accessor<T, ALLOC>::container_pointer_type
121 Accessor<T, ALLOC>::getDataArray (AuxVectorData& container) const
123 return reinterpret_cast<container_pointer_type>
124 (container.getDataArray (this->m_auxid));
129 * @brief Get a span over the auxilary data array.
130 * @param container The container from which to fetch the variable.
132 template <class T, class ALLOC>
134 typename Accessor<T, ALLOC>::span
135 Accessor<T, ALLOC>::getDataSpan (AuxVectorData& container) const
137 auto beg = reinterpret_cast<container_pointer_type>
138 (container.getDataArray (this->m_auxid));
139 return span (beg, container.size_v());
144 * @brief Test to see if this variable exists in the store and is writable.
145 * @param e An element of the container in which to test the variable.
147 template <class T, class ALLOC>
149 ATH_REQUIRES( IsAuxElement<ELT> )
152 Accessor<T, ALLOC>::isAvailableWritable (ELT& e) const
154 return e.container() && e.container()->isAvailableWritable (this->m_auxid);
159 * @brief Test to see if this variable exists in the store and is writable.
160 * @param c The container in which to test the variable.
162 template <class T, class ALLOC>
165 Accessor<T, ALLOC>::isAvailableWritable (AuxVectorData& c) const
167 return c.isAvailableWritable (this->m_auxid);