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 #ifndef __CPPCHECK__ // cppcheck gets parse errors on this
97 template <class PAYLOAD_T, class ALLOC>
100 Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::operator() (AuxVectorData& container,
104 (void)this->getEltArray (container); // const/locking checks
105 return reference_type (index,
106 *container.getDataSpan (this->m_linkedAuxid),
107 *container.getDataSpan (this->m_auxid),
111 #endif // not __CPPCHECK__
115 * @brief Set the variable for one element.
116 * @param e The element for which to fetch the variable.
117 * @param x The variable value to set.
119 template <class PAYLOAD_T, class ALLOC>
120 template <CxxUtils::InputRangeOverT<PAYLOAD_T> RANGE>
122 void Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::set (AuxElement& e,
123 const RANGE& x) const
125 (*this) (*e.container(), e.index()) = x;
130 * @brief Set the variable for one element.
131 * @param container The container from which to fetch the variable.
132 * @param index The index of the desired element.
133 * @param x The variable value to set.
135 template <class PAYLOAD_T, class ALLOC>
136 template <CxxUtils::InputRangeOverT<PAYLOAD_T> RANGE>
137 void Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::set (AuxVectorData& container,
139 const RANGE& x) const
141 (*this) (container, index) = x;
146 * @brief Get a pointer to the start of the array of @c JaggedVecElt objects.
147 * @param container The container from which to fetch the variable.
149 template <class PAYLOAD_T, class ALLOC>
152 Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::getEltArray (AuxVectorData& container) const
155 return reinterpret_cast<Elt_t*>
156 (container.getDataArray (this->m_auxid));
161 * @brief Get a pointer to the start of the payload array.
162 * @param container The container from which to fetch the variable.
164 template <class PAYLOAD_T, class ALLOC>
167 Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::getPayloadArray (AuxVectorData& container) const
170 return reinterpret_cast<Payload_t*>
171 (container.getDataArray (this->m_linkedAuxid));
176 * @brief Get a span over the array of @c JaggedVecElt objects.
177 * @param container The container from which to fetch the variable.
179 template <class PAYLOAD_T, class ALLOC>
182 Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::getEltSpan (AuxVectorData& container) const
185 auto beg = reinterpret_cast<Elt_t*> (container.getDataArray (this->m_auxid));
186 return Elt_span (beg, container.size_v());
191 * @brief Get a span over the payload vector.
192 * @param container The container from which to fetch the variable.
194 template <class PAYLOAD_T, class ALLOC>
197 Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::getPayloadSpan (AuxVectorData& container) const
200 const AuxDataSpanBase* sp = container.getDataSpan (this->m_linkedAuxid);
201 return Payload_span (reinterpret_cast<Payload_t*>(sp->beg), sp->size);
206 * @brief Get a span over spans representing the jagged vector.
207 * @param container The container from which to fetch the variable.
209 template <class PAYLOAD_T, class ALLOC>
212 Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::getDataSpan (AuxVectorData& container) const
215 return span (getEltSpan(container),
216 Converter_t (container, this->auxid(), this->linkedAuxid()));
221 * @brief Test to see if this variable exists in the store and is writable.
222 * @param e An element of the container in which to test the variable.
224 template <class PAYLOAD_T, class ALLOC>
227 Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::isAvailableWritable (AuxElement& e) const
229 return e.container() &&
230 e.container()->isAvailableWritable (this->m_auxid) &&
231 e.container()->isAvailableWritable (this->m_linkedAuxid);
236 * @brief Test to see if this variable exists in the store and is writable.
237 * @param c The container in which to test the variable.
239 template <class PAYLOAD_T, class ALLOC>
242 Accessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::isAvailableWritable (AuxVectorData& c) const
244 return c.isAvailableWritable (this->m_auxid) &&
245 c.isAvailableWritable (this->m_linkedAuxid);