2 * Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
5 * @file AthContainers/JaggedVecAccessor.h
6 * @author scott snyder <snyder@bnl.gov>
8 * @brief Helper class to provide type-safe access to aux data. xxx
12 #include "AthContainers/AuxElement.h"
13 #include "AthContainers/AuxTypeRegistry.h"
14 #include "AthContainers/tools/AuxVectorInterface.h"
15 #include "AthContainers/exceptions.h"
16 #include "CxxUtils/checker_macros.h"
24 * @param name Name of this aux variable.
26 * The name -> auxid lookup is done here.
28 template <class PAYLOAD_T, class ALLOC>
30 Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::Accessor (const std::string& name)
38 * @param name Name of this aux variable.
39 * @param clsname The name of its associated class. May be blank.
41 * The name -> auxid lookup is done here.
43 template <class PAYLOAD_T, class ALLOC>
45 Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::Accessor (const std::string& name,
46 const std::string& clsname)
47 : Base (name, clsname)
53 * @brief Constructor taking an auxid directly.
54 * @param auxid ID for this auxiliary variable.
56 * Will throw @c SG::ExcAuxTypeMismatch if the types don't match.
58 template <class PAYLOAD_T, class ALLOC>
60 Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::Accessor (const SG::auxid_t auxid)
63 // cppcheck-suppress missingReturn; false positive
68 * @brief Fetch the variable for one element, as a non-const reference.
69 * @param e The element for which to fetch the variable.
71 * Will return a proxy object, which will allow treating this
72 * jagged vector element as a vector.
74 template <class PAYLOAD_T, class ALLOC>
75 template <IsAuxElement ELT>
78 Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::operator() (ELT& e) const
81 assert (e.container() != 0);
82 return (*this) (*e.container(), e.index());
87 * @brief Fetch the variable for one element, as a non-const reference.
88 * @param container The container from which to fetch the variable.
89 * @param index The index of the desired element.
91 * This allows retrieving aux data by container / index.
93 * Will return a proxy object, which will allow treating this
94 * jagged vector element as a vector.
96 template <class PAYLOAD_T, class ALLOC>
99 Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::operator() (AuxVectorData& container,
103 (void)this->getEltArray (container); // const/locking checks
104 return reference_type (index,
105 *container.getDataSpan (this->m_linkedAuxid),
106 *container.getDataSpan (this->m_auxid),
113 * @brief Set the variable for one element.
114 * @param e The element for which to fetch the variable.
115 * @param x The variable value to set.
117 template <class PAYLOAD_T, class ALLOC>
118 template <CxxUtils::InputRangeOverT<PAYLOAD_T> RANGE>
120 void Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::set (AuxElement& e,
121 const RANGE& x) const
123 (*this) (*e.container(), e.index()) = x;
128 * @brief Set the variable for one element.
129 * @param container The container from which to fetch the variable.
130 * @param index The index of the desired element.
131 * @param x The variable value to set.
133 template <class PAYLOAD_T, class ALLOC>
134 template <CxxUtils::InputRangeOverT<PAYLOAD_T> RANGE>
135 void Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::set (AuxVectorData& container,
137 const RANGE& x) const
139 (*this) (container, index) = x;
144 * @brief Get a pointer to the start of the array of @c JaggedVecElt objects.
145 * @param container The container from which to fetch the variable.
147 template <class PAYLOAD_T, class ALLOC>
150 Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::getEltArray (AuxVectorData& container) const
153 return reinterpret_cast<Elt_t*>
154 (container.getDataArray (this->m_auxid));
159 * @brief Get a pointer to the start of the payload array.
160 * @param container The container from which to fetch the variable.
162 template <class PAYLOAD_T, class ALLOC>
165 Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::getPayloadArray (AuxVectorData& container) const
168 return reinterpret_cast<Payload_t*>
169 (container.getDataArray (this->m_linkedAuxid));
174 * @brief Get a span over the array of @c JaggedVecElt objects.
175 * @param container The container from which to fetch the variable.
177 template <class PAYLOAD_T, class ALLOC>
180 Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::getEltSpan (AuxVectorData& container) const
183 auto beg = reinterpret_cast<Elt_t*> (container.getDataArray (this->m_auxid));
184 return Elt_span (beg, container.size_v());
189 * @brief Get a span over the payload vector.
190 * @param container The container from which to fetch the variable.
192 template <class PAYLOAD_T, class ALLOC>
195 Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::getPayloadSpan (AuxVectorData& container) const
198 const AuxDataSpanBase* sp = container.getDataSpan (this->m_linkedAuxid);
199 return Payload_span (reinterpret_cast<Payload_t*>(sp->beg), sp->size);
204 * @brief Get a span over spans representing the jagged vector.
205 * @param container The container from which to fetch the variable.
207 template <class PAYLOAD_T, class ALLOC>
210 Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::getDataSpan (AuxVectorData& container) const
213 return span (getEltSpan(container),
214 Converter_t (container, this->auxid(), this->linkedAuxid()));
219 * @brief Test to see if this variable exists in the store and is writable.
220 * @param e An element of the container in which to test the variable.
222 template <class PAYLOAD_T, class ALLOC>
225 Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::isAvailableWritable (AuxElement& e) const
227 return e.container() &&
228 e.container()->isAvailableWritable (this->m_auxid) &&
229 e.container()->isAvailableWritable (this->m_linkedAuxid);
234 * @brief Test to see if this variable exists in the store and is writable.
235 * @param c The container in which to test the variable.
237 template <class PAYLOAD_T, class ALLOC>
240 Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::isAvailableWritable (AuxVectorData& c) const
242 return c.isAvailableWritable (this->m_auxid) &&
243 c.isAvailableWritable (this->m_linkedAuxid);