2 * Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
5 * @file AthContainers/JaggedVecDecorator.icc
6 * @author scott snyder <snyder@bnl.gov>
8 * @brief Helper class to provide type-safe access to aux data,
9 * specialized for @c JaggedVecElt.
13 #include "AthContainers/AuxElement.h"
14 #include "AthContainers/AuxTypeRegistry.h"
15 #include "AthContainers/exceptions.h"
23 * @param name Name of this aux variable.
25 * The name -> auxid lookup is done here.
27 template <class PAYLOAD_T, class ALLOC>
29 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::Decorator (const std::string& name)
30 : Decorator (name, "", SG::AuxVarFlags::None)
37 * @param name Name of this aux variable.
38 * @param clsname The name of its associated class. May be blank.
40 * The name -> auxid lookup is done here.
42 template <class PAYLOAD_T, class ALLOC>
44 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::Decorator (const std::string& name,
45 const std::string& clsname)
46 : Decorator (name, clsname, SG::AuxVarFlags::None)
52 * @brief Constructor taking an auxid directly.
53 * @param auxid ID for this auxiliary variable.
55 * Will throw @c SG::ExcAuxTypeMismatch if the types don't match.
57 template <class PAYLOAD_T, class ALLOC>
59 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::Decorator (const SG::auxid_t auxid)
61 AuxTypeRegistry& r = AuxTypeRegistry::instance();
62 this->m_auxid = auxid;
63 r.checkAuxID<Elt_t, ALLOC> (this->m_auxid);
64 this->m_linkedAuxid = r.linkedVariable (this->m_auxid);
65 if (this->m_linkedAuxid == static_cast<uint32_t>(null_auxid)) {
66 throw SG::ExcNoLinkedVar (auxid, typeid (Payload_t));
67 // cppcheck-suppress missingReturn
74 * @param name Name of this aux variable.
75 * @param clsname The name of its associated class. May be blank.
76 * @param flags Optional flags qualifying the type. See AuxTypeRegsitry.
78 * The name -> auxid lookup is done here.
80 template <class PAYLOAD_T, class ALLOC>
82 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::Decorator
83 (const std::string& name,
84 const std::string& clsname,
85 const SG::AuxVarFlags flags)
87 AuxTypeRegistry& r = AuxTypeRegistry::instance();
88 this->m_linkedAuxid = r.getAuxID<Payload_t, PayloadAlloc_t> (AuxTypeRegistry::linkedName (name),
90 flags | AuxVarFlags::Linked);
91 this->m_auxid = r.getAuxID<Elt_t, ALLOC> (name, clsname, flags, m_linkedAuxid);
96 * @brief Fetch the variable for one element, as a non-const reference.
97 * @param e The element for which to fetch the variable.
99 * Will return a proxy object, which will allow treating this
100 * jagged vector element as a vector.
102 * If the container is locked, this will allow fetching only variables
103 * that do not yet exist (in which case they will be marked as decorations)
104 * or variables already marked as decorations.
106 template <class PAYLOAD_T, class ALLOC>
107 template <IsConstAuxElement ELT>
110 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::operator() (const ELT& e) const
113 assert (e.container() != 0);
114 return (*this) (*e.container(), e.index());
119 * @brief Fetch the variable for one element, as a non-const reference.
120 * @param container The container from which to fetch the variable.
121 * @param index The index of the desired element.
123 * This allows retrieving aux data by container / index.
125 * Will return a proxy object, which will allow treating this
126 * jagged vector element as a vector.
128 * If the container is locked, this will allow fetching only variables
129 * that do not yet exist (in which case they will be marked as decorations)
130 * or variables already marked as decorations.
132 template <class PAYLOAD_T, class ALLOC>
135 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::operator() (const AuxVectorData& container,
139 (void)this->getEltDecorArray (container); // const/locking checks
140 AuxVectorData& container_nc ATLAS_THREAD_SAFE =
141 const_cast<AuxVectorData&> (container);
142 return JVecProxy (index,
143 *container.getDataSpan (this->m_linkedAuxid),
144 *container.getDataSpan (this->m_auxid),
151 * @brief Set the variable for one element.
152 * @param e The element for which to fetch the variable.
153 * @param x The variable value to set.
155 template <class PAYLOAD_T, class ALLOC>
156 template <IsConstAuxElement ELT,
157 CxxUtils::InputRangeOverT<PAYLOAD_T> RANGE>
159 void Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::set (const ELT& e,
160 const RANGE& x) const
162 set (*e.container(), e.index(), x);
167 * @brief Set the variable for one element.
168 * @param container The container from which to fetch the variable.
169 * @param index The index of the desired element.
170 * @param x The variable value to set.
172 template <class PAYLOAD_T, class ALLOC>
173 template <CxxUtils::InputRangeOverT<PAYLOAD_T> RANGE>
175 void Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::set (const AuxVectorData& container,
177 const RANGE& x) const
179 (*this) (container, index) = x;
184 * @brief Get a pointer to the start of the array of @c JaggedVecElt objects.
185 * @param container The container from which to fetch the variable.
187 template <class PAYLOAD_T, class ALLOC>
190 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::getEltArray (const AuxVectorData& container) const
193 return reinterpret_cast<const Elt_t*>
194 (container.getDataArray (m_auxid));
199 * @brief Get a pointer to the start of the payload array.
200 * @param container The container from which to fetch the variable.
202 template <class PAYLOAD_T, class ALLOC>
205 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::getPayloadArray (const AuxVectorData& container) const
208 return reinterpret_cast<const Payload_t*>
209 (container.getDataArray (m_linkedAuxid));
214 * @brief Get a pointer to the start of the array of @c JaggedVecElt objects,
216 * @param container The container from which to fetch the variable.
218 * If the container is locked, this will allow fetching only variables
219 * that do not yet exist (in which case they will be marked as decorations)
220 * or variables already marked as decorations.
222 template <class PAYLOAD_T, class ALLOC>
225 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::getEltDecorArray (const AuxVectorData& container) const
228 return reinterpret_cast<Elt_t*>
229 (container.getDecorationArray (m_auxid));
234 * @brief Get a pointer to the start of the payload array,
236 * @param container The container from which to fetch the variable.
238 * If the container is locked, this will allow fetching only variables
239 * that do not yet exist (in which case they will be marked as decorations)
240 * or variables already marked as decorations.
242 template <class PAYLOAD_T, class ALLOC>
245 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::getPayloadDecorArray (const AuxVectorData& container) const
248 return reinterpret_cast<Payload_t*>
249 (container.getDecorationArray (m_linkedAuxid));
254 * @brief Get a span over the array of @c JaggedVecElt objects.
255 * @param container The container from which to fetch the variable.
257 template <class PAYLOAD_T, class ALLOC>
260 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::getEltSpan (const AuxVectorData& container) const
263 auto beg = reinterpret_cast<const Elt_t*>(container.getDataArray (m_auxid));
264 return const_Elt_span (beg, container.size_v());
269 * @brief Get a span over the payload vector.
270 * @param container The container from which to fetch the variable.
272 template <class PAYLOAD_T, class ALLOC>
275 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::getPayloadSpan (const AuxVectorData& container) const
276 -> const_Payload_span
278 const AuxDataSpanBase* sp = container.getDataSpan (m_linkedAuxid);
279 return const_Payload_span (reinterpret_cast<const Payload_t*>(sp->beg),
285 * @brief Get a span over spans representing the jagged vector.
286 * @param container The container from which to fetch the variable.
288 template <class PAYLOAD_T, class ALLOC>
291 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::getDataSpan (const AuxVectorData& container) const
294 const_Elt_span elt_span = getEltSpan (container);
295 return const_span (elt_span,
296 ConstConverter_t (elt_span.data(),
297 *container.getDataSpan (m_linkedAuxid)));
302 * @brief Get a span over the array of @c JaggedVecElt objects,
304 * @param container The container from which to fetch the variable.
306 * If the container is locked, this will allow fetching only variables
307 * that do not yet exist (in which case they will be marked as decorations)
308 * or variables already marked as decorations.
310 template <class PAYLOAD_T, class ALLOC>
313 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::getEltDecorSpan (const AuxVectorData& container) const
316 auto beg = reinterpret_cast<Elt_t*>
317 (container.getDecorationArray (this->m_auxid));
318 return Elt_span (beg, container.size_v());
323 * @brief Get a span over the payload vector,
325 * @param container The container from which to fetch the variable.
327 * If the container is locked, this will allow fetching only variables
328 * that do not yet exist (in which case they will be marked as decorations)
329 * or variables already marked as decorations.
331 template <class PAYLOAD_T, class ALLOC>
334 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::getPayloadDecorSpan (const AuxVectorData& container) const
337 (void)container.getDecorationArray (this->m_linkedAuxid); // check for locking
338 const AuxDataSpanBase* sp = container.getDataSpan (m_linkedAuxid);
339 return Payload_span (reinterpret_cast<Payload_t*>(sp->beg), sp->size);
344 * @brief Get a span over spans representing the jagged vector,
346 * @param container The container from which to fetch the variable.
348 * If the container is locked, this will allow fetching only variables
349 * that do not yet exist (in which case they will be marked as decorations)
350 * or variables already marked as decorations.
352 template <class PAYLOAD_T, class ALLOC>
355 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::getDecorationSpan (const AuxVectorData& container) const
358 Elt_span elt_span = getEltDecorSpan(container);
359 AuxVectorData& container_nc ATLAS_THREAD_SAFE = const_cast<AuxVectorData&> (container);
360 return span (elt_span,
361 Converter_t (container_nc, this->auxid(), this->linkedAuxid()));
366 * @brief Test to see if this variable exists in the store and is writable.
367 * @param e An element of the container om which to test the variable.
369 template <class PAYLOAD_T, class ALLOC>
370 template <IsConstAuxElement ELT>
373 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::isAvailableWritable (const ELT& e) const
375 return e.container() &&
376 e.container()->isAvailableWritableAsDecoration (m_auxid) &&
377 e.container()->isAvailableWritableAsDecoration (m_linkedAuxid);
382 * @brief Test to see if this variable exists in the store and is writable.
383 * @param c The container in which to test the variable.
385 template <class PAYLOAD_T, class ALLOC>
388 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::isAvailableWritable (const AuxVectorData& c) const
390 return c.isAvailableWritableAsDecoration (m_auxid) &&
391 c.isAvailableWritableAsDecoration (m_linkedAuxid);