2 * Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
5 * @file AthContainers/JaggedVecConstAccessor.icc
6 * @author scott snyder <snyder@bnl.gov>
8 * @brief Helper class to provide constant type-safe access to aux data.
12 #include "AthContainers/AuxElement.h"
13 #include "AthContainers/AuxTypeRegistry.h"
14 #include "AthContainers/exceptions.h"
22 * @param name Name of this aux variable.
24 * The name -> auxid lookup is done here.
26 template <class PAYLOAD_T, class ALLOC>
28 ConstAccessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::ConstAccessor (const std::string& name)
29 : ConstAccessor (name, "", AuxVarFlags::None)
36 * @param name Name of this aux variable.
37 * @param clsname The name of its associated class. May be blank.
39 * The name -> auxid lookup is done here.
41 template <class PAYLOAD_T, class ALLOC>
43 ConstAccessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::ConstAccessor
44 (const std::string& name, const std::string& clsname)
45 : ConstAccessor (name, clsname, AuxVarFlags::None)
47 // cppcheck-suppress missingReturn; false positive
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 ConstAccessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::ConstAccessor (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));
73 * @param name Name of this aux variable.
74 * @param clsname The name of its associated class. May be blank.
75 * @param flags Optional flags qualifying the type. See AuxTypeRegsitry.
77 * The name -> auxid lookup is done here.
79 template <class PAYLOAD_T, class ALLOC>
81 ConstAccessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::ConstAccessor
82 (const std::string& name,
83 const std::string& clsname,
84 const AuxVarFlags flags)
86 AuxTypeRegistry& r = AuxTypeRegistry::instance();
87 m_linkedAuxid = r.getAuxID<Payload_t, PayloadAlloc_t> (AuxTypeRegistry::linkedName (name),
89 flags | AuxVarFlags::Linked);
90 m_auxid = r.getAuxID<Elt_t, ALLOC> (name, clsname, flags, m_linkedAuxid);
96 * @param b Another accessor from which to copy the auxids.
98 template <class PAYLOAD_T, class ALLOC>
100 ConstAccessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::ConstAccessor (const detail::LinkedVarAccessorBase& b)
101 : detail::LinkedVarAccessorBase (b)
103 // cppcheck-suppress missingReturn; false positive
108 * @brief Fetch the variable for one element, as a const reference.
109 * @param e The element for which to fetch the variable.
111 template <class PAYLOAD_T, class ALLOC>
112 template <IsConstAuxElement ELT>
115 ConstAccessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::operator() (const ELT& e) const -> const element_type
117 const AuxVectorData* container = e.container();
118 assert (container != nullptr);
119 return (*this)(*container, e.index());
124 * @brief Fetch the variable for one element, as a const reference.
125 * @param container The container from which to fetch the variable.
126 * @param index The index of the desired element.
128 * This allows retrieving aux data by container / index.
130 template <class PAYLOAD_T, class ALLOC>
133 ConstAccessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::operator()
134 (const AuxVectorData& container, size_t index) const -> const element_type
136 const Elt_t& jelt = container.template getData<Elt_t> (m_auxid, index);
137 if (jelt.end() == 0) return element_type();
138 const Payload_t* payload = this->getPayloadArray (container);
139 return element_type (payload+jelt.begin (index), payload+jelt.end());
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 ConstAccessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::getEltArray (const AuxVectorData& container) const
153 return reinterpret_cast<const Elt_t*> (container.getDataArray (m_auxid));
158 * @brief Get a pointer to the start of the payload array.
159 * @param container The container from which to fetch the variable.
161 template <class PAYLOAD_T, class ALLOC>
164 ConstAccessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::getPayloadArray (const AuxVectorData& container) const
167 return reinterpret_cast<const Payload_t*>
168 (container.getDataArray (m_linkedAuxid));
173 * @brief Get a span over the array of @c JaggedVecElt objects.
174 * @param container The container from which to fetch the variable.
176 template <class PAYLOAD_T, class ALLOC>
179 ConstAccessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::getEltSpan (const AuxVectorData& container) const
182 auto beg = reinterpret_cast<const Elt_t*> (container.getDataArray (m_auxid));
183 return const_Elt_span (beg, container.size_v());
188 * @brief Get a span over the payload vector.
189 * @param container The container from which to fetch the variable.
191 template <class PAYLOAD_T, class ALLOC>
194 ConstAccessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::getPayloadSpan (const AuxVectorData& container) const
195 -> const_Payload_span
197 const SG::AuxDataSpanBase* sp = container.getDataSpan (m_linkedAuxid);
198 return const_Payload_span (reinterpret_cast<const Payload_t*>(sp->beg),
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 ConstAccessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::getDataSpan (const AuxVectorData& container) const
213 const_Elt_span elt_span = getEltSpan (container);
214 return const_span (elt_span,
215 ConstConverter_t (elt_span.data(),
216 *container.getDataSpan (m_linkedAuxid)));