2 * Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration.
5 * @file AthContainers/PackedLinkConstAccessor.icc
6 * @author scott snyder <snyder@bnl.gov>
8 * @brief Helper class to provide constant type-safe access to aux data,
9 * specialized for @c PackedLink.
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.
27template <class CONT, class ALLOC>
29ConstAccessor<PackedLink<CONT>, ALLOC>::ConstAccessor (const std::string& name)
30 : ConstAccessor (name, "", 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.
42template <class CONT, class ALLOC>
44ConstAccessor<PackedLink<CONT>, ALLOC>::ConstAccessor
45 (const std::string& name, const std::string& clsname)
46 : ConstAccessor (name, clsname, AuxVarFlags::None)
48 // cppcheck-suppress missingReturn; false positive
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.
58template <class CONT, class ALLOC>
60ConstAccessor<PackedLink<CONT>, ALLOC>::ConstAccessor (const SG::auxid_t auxid)
62 AuxTypeRegistry& r = AuxTypeRegistry::instance();
64 r.checkAuxID<PLink_t, ALLOC> (m_auxid);
65 m_linkedAuxid = r.linkedVariable (m_auxid);
66 if (m_linkedAuxid == static_cast<uint32_t>(null_auxid)) {
67 throw SG::ExcNoLinkedVar (auxid, typeid (CONT));
68 // cppcheck-suppress missingReturn; false positive
75 * @param name Name of this aux variable.
76 * @param clsname The name of its associated class. May be blank.
77 * @param flags Optional flags qualifying the type. See AuxTypeRegistry.
79 * The name -> auxid lookup is done here.
81template <class CONT, class ALLOC>
83ConstAccessor<PackedLink<CONT>, ALLOC>::ConstAccessor
84 (const std::string& name,
85 const std::string& clsname,
86 const AuxVarFlags flags)
88 AuxTypeRegistry& r = AuxTypeRegistry::instance();
89 m_linkedAuxid = r.getAuxID<DLink_t, DLinkAlloc_t> (AuxTypeRegistry::linkedName (name),
91 flags | AuxVarFlags::Linked);
92 m_auxid = r.getAuxID<PLink_t, ALLOC> (name, clsname, flags, m_linkedAuxid);
97 * @brief Fetch the variable for one element.
98 * @param e The element for which to fetch the variable.
100template <class CONT, class ALLOC>
101template <IsConstAuxElement ELT>
104ConstAccessor<PackedLink<CONT>, ALLOC>::operator()
105 (const ELT& e) const -> const Link_t
107 assert (e.container() != nullptr);
108 return resolveLink (*e.container(), e.index());
114 * @brief Fetch the variable for one element.
115 * @param container The container from which to fetch the variable.
116 * @param index The index of the desired element.
118 * This allows retrieving aux data by container / index.
120template <class CONT, class ALLOC>
123ConstAccessor<PackedLink<CONT>, ALLOC>::operator()
124 (const AuxVectorData& container, size_t index) const -> const Link_t
126 return resolveLink (container, index);
131 * @brief Get a pointer to the start of the array of @c PackedLinks
132 * @param container The container from which to fetch the variable.
134template <class CONT, class ALLOC>
137ConstAccessor<PackedLink<CONT>, ALLOC>::getPackedLinkArray (const AuxVectorData& container) const
140 return reinterpret_cast<const PLink_t*>
141 (container.getDataArray (m_auxid));
146 * @brief Get a pointer to the start of the linked array of @c DataLinks.
147 * @param container The container from which to fetch the variable.
149template <class CONT, class ALLOC>
152ConstAccessor<PackedLink<CONT>, ALLOC>::getDataLinkArray (const AuxVectorData& container) const
155 return reinterpret_cast<const DLink_t*>
156 (container.getDataArray (m_linkedAuxid));
161 * @brief Get a span over the array of @c PackedLinks.
162 * @param container The container from which to fetch the variable.
164template <class CONT, class ALLOC>
167ConstAccessor<PackedLink<CONT>, ALLOC>::getPackedLinkSpan (const AuxVectorData& container) const
168 -> const_PackedLink_span
170 const SG::AuxDataSpanBase sp = *container.getDataSpan (m_auxid);
171 return const_PackedLink_span (reinterpret_cast<const PLink_t*>(sp.beg),
177 * @brief Get a span over the array of @c DataLinks.
178 * @param container The container from which to fetch the variable.
180template <class CONT, class ALLOC>
183ConstAccessor<PackedLink<CONT>, ALLOC>::getDataLinkSpan (const AuxVectorData& container) const
184 -> const_DataLink_span
186 const SG::AuxDataSpanBase sp = *container.getDataSpan (m_linkedAuxid);
187 return const_DataLink_span (reinterpret_cast<const DLink_t*>(sp.beg),
193 * @brief Get a span of @c ElementLinks.
194 * @param container The container from which to fetch the variable.
196template <class CONT, class ALLOC>
199ConstAccessor<PackedLink<CONT>, ALLOC>::getDataSpan (const AuxVectorData& container) const
202 const_PackedLink_span pspan = getPackedLinkSpan(container);
203 typename ConstConverter_t::const_DataLink_span dlinks
204 (*container.getDataSpan (m_linkedAuxid));
205 return const_span (pspan, dlinks);
210 * @brief Helper to resolve a @c PackedLink to an @c ElementLink.
211 * @param container The container from which to fetch the variable.
212 * @param index The index of the desired element.
214template <class CONT, class ALLOC>
217ConstAccessor<PackedLink<CONT>, ALLOC>::resolveLink (const AuxVectorData& container,
221 const auto& l = container.template getData<PLink_t> (m_auxid, index);
222 return ConstConverter_t (*container.getDataSpan (m_linkedAuxid)) (l);
226//************************************************************************
229// To make the declarations a bit more readable.
230#define CONSTACCESSOR ConstAccessor<std::vector<PackedLink<CONT>, VALLOC>, ALLOC>
234 * @brief Constructor.
235 * @param name Name of this aux variable.
237 * The name -> auxid lookup is done here.
239template <class CONT, class ALLOC, class VALLOC>
241CONSTACCESSOR::ConstAccessor (const std::string& name)
242 : ConstAccessor (name, "", AuxVarFlags::None)
248 * @brief Constructor.
249 * @param name Name of this aux variable.
250 * @param clsname The name of its associated class. May be blank.
252 * The name -> auxid lookup is done here.
254template <class CONT, class ALLOC, class VALLOC>
256CONSTACCESSOR::ConstAccessor
257 (const std::string& name, const std::string& clsname)
258 : ConstAccessor (name, clsname, AuxVarFlags::None)
264 * @brief Constructor taking an auxid directly.
265 * @param auxid ID for this auxiliary variable.
267 * Will throw @c SG::ExcAuxTypeMismatch if the types don't match.
269template <class CONT, class ALLOC, class VALLOC>
271CONSTACCESSOR::ConstAccessor (const SG::auxid_t auxid)
273 AuxTypeRegistry& r = AuxTypeRegistry::instance();
275 r.checkAuxID<VElt_t, ALLOC> (m_auxid);
276 m_linkedAuxid = r.linkedVariable (m_auxid);
277 if (m_linkedAuxid == static_cast<uint32_t>(null_auxid)) {
278 throw SG::ExcNoLinkedVar (auxid, typeid (CONT));
284 * @brief Constructor.
285 * @param name Name of this aux variable.
286 * @param clsname The name of its associated class. May be blank.
287 * @param flags Optional flags qualifying the type. See AuxTypeRegistry.
289 * The name -> auxid lookup is done here.
291template <class CONT, class ALLOC, class VALLOC>
293CONSTACCESSOR::ConstAccessor
294 (const std::string& name,
295 const std::string& clsname,
296 const AuxVarFlags flags)
298 AuxTypeRegistry& r = AuxTypeRegistry::instance();
299 m_linkedAuxid = r.getAuxID<DLink_t, DLinkAlloc_t> (AuxTypeRegistry::linkedName (name),
301 flags | AuxVarFlags::Linked);
302 m_auxid = r.getAuxID<VElt_t, ALLOC> (name, clsname, flags, m_linkedAuxid);
307 * @brief Fetch the variable for one element.
308 * @param e The element for which to fetch the variable.
310 * This will return a range of @c ElementLinks.
312template <class CONT, class ALLOC, class VALLOC>
313template <IsConstAuxElement ELT>
316CONSTACCESSOR::operator() (const ELT& e) const -> const_elt_span
318 const_PackedLink_span pspan = getPackedLinkSpan(e);
319 typename ConstVectorTransform_t::const_DataLink_span xform
320 (*e.container()->getDataSpan (m_linkedAuxid));
321 return const_elt_span (pspan, xform);
325 * @brief Fetch the variable for one element.
326 * @param container The container from which to fetch the variable.
327 * @param index The index of the desired element.
329 * This allows retrieving aux data by container / index.
331 * This will return a range of @c ElementLinks.
333template <class CONT, class ALLOC, class VALLOC>
336CONSTACCESSOR::operator()
337 (const AuxVectorData& container, size_t index) const -> const_elt_span
339 const_PackedLink_span pspan = getPackedLinkSpan(container, index);
340 typename ConstVectorTransform_t::const_DataLink_span xform
341 (*container.getDataSpan (m_linkedAuxid));
342 return const_elt_span (pspan, xform);
347 * @brief Get a pointer to the start of the array of vectors of @c PackedLinks.
348 * @param container The container from which to fetch the variable.
350template <class CONT, class ALLOC, class VALLOC>
353CONSTACCESSOR::getPackedLinkVectorArray (const AuxVectorData& container) const
356 return reinterpret_cast<const VElt_t*>
357 (container.getDataArray (m_auxid));
362 * @brief Get a pointer to the start of the linked array of @c DataLinks.
363 * @param container The container from which to fetch the variable.
365template <class CONT, class ALLOC, class VALLOC>
368CONSTACCESSOR::getDataLinkArray (const AuxVectorData& container) const
371 return reinterpret_cast<const DLink_t*>
372 (container.getDataArray (this->m_linkedAuxid));
377 * @brief Get a span over the vector of @c PackedLinks for a given element.
378 * @param e The element for which to fetch the variable.
380template <class CONT, class ALLOC, class VALLOC>
381template <IsConstAuxElement ELT>
383auto CONSTACCESSOR::getPackedLinkSpan (const ELT& e) const
384 -> const_PackedLink_span
386 auto elt = reinterpret_cast<const VElt_t*>
387 (e.container()->getDataArray (m_auxid)) + e.index();
388 return const_PackedLink_span (elt->data(), elt->size());
393 * @brief Get a span over the vector of @c PackedLinks for a given element.
394 * @param container The container from which to fetch the variable.
395 * @param index The index of the desired element.
397template <class CONT, class ALLOC, class VALLOC>
400CONSTACCESSOR::getPackedLinkSpan (const AuxVectorData& container,
402 -> const_PackedLink_span
404 auto elt = reinterpret_cast<const VElt_t*>
405 (container.getDataArray (this->m_auxid)) + index;
406 return const_PackedLink_span (elt->data(), elt->size());
411 * @brief Get a span over the vectors of @c PackedLinks.
412 * @param container The container from which to fetch the variable.
414template <class CONT, class ALLOC, class VALLOC>
417CONSTACCESSOR::getPackedLinkVectorSpan (const AuxVectorData& container) const
418 -> const_PackedLinkVector_span
420 auto beg = reinterpret_cast<const VElt_t*>
421 (container.getDataArray (m_auxid));
422 return const_PackedLinkVector_span (beg, container.size_v());
427 * @brief Get a span over the array of @c DataLinks.
428 * @param container The container from which to fetch the variable.
430template <class CONT, class ALLOC, class VALLOC>
432CONSTACCESSOR::getDataLinkSpan (const AuxVectorData& container) const
433 -> const_DataLink_span
435 const SG::AuxDataSpanBase* sp = container.getDataSpan (m_linkedAuxid);
436 return const_DataLink_span (reinterpret_cast<const DLink_t*>(sp->beg),
442 * @brief Get a span over spans of @c ElementLinks.
443 * @param container The container from which to fetch the variable.
445template <class CONT, class ALLOC, class VALLOC>
448CONSTACCESSOR::getDataSpan (const AuxVectorData& container) const
451 const_PackedLinkVector_span pspan = getPackedLinkVectorSpan(container);
452 typename ConstVectorTransform_t::const_DataLink_span xform
453 (*container.getDataSpan (m_linkedAuxid));
454 return const_span (pspan, xform);