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 // cppcheck-suppress uninitDerivedMemberVar; false positive
44 ConstAccessor<JaggedVecElt<PAYLOAD_T>, 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.
58 template <class PAYLOAD_T, class ALLOC>
60 ConstAccessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::ConstAccessor (const SG::auxid_t auxid)
62 AuxTypeRegistry& r = AuxTypeRegistry::instance();
63 this->m_auxid = auxid;
64 r.checkAuxID<Elt_t, ALLOC> (this->m_auxid);
65 this->m_linkedAuxid = r.linkedVariable (this->m_auxid);
66 if (this->m_linkedAuxid == static_cast<uint32_t>(null_auxid)) {
67 throw SG::ExcNoLinkedVar (auxid, typeid (Payload_t));
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 ConstAccessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::ConstAccessor
83 (const std::string& name,
84 const std::string& clsname,
85 const AuxVarFlags flags)
87 AuxTypeRegistry& r = AuxTypeRegistry::instance();
88 m_linkedAuxid = r.getAuxID<Payload_t, PayloadAlloc_t> (AuxTypeRegistry::linkedName (name),
90 flags | AuxVarFlags::Linked);
91 m_auxid = r.getAuxID<Elt_t, ALLOC> (name, clsname, flags, m_linkedAuxid);
97 * @param b Another accessor from which to copy the auxids.
99 template <class PAYLOAD_T, class ALLOC>
101 ConstAccessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::ConstAccessor (const detail::LinkedVarAccessorBase& b)
102 : detail::LinkedVarAccessorBase (b)
104 // cppcheck-suppress missingReturn; false positive
109 * @brief Fetch the variable for one element, as a const reference.
110 * @param e The element for which to fetch the variable.
112 template <class PAYLOAD_T, class ALLOC>
113 template <IsConstAuxElement ELT>
116 ConstAccessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::operator() (const ELT& e) const -> const element_type
118 const AuxVectorData* container = e.container();
119 assert (container != nullptr);
120 return (*this)(*container, e.index());
125 * @brief Fetch the variable for one element, as a const reference.
126 * @param container The container from which to fetch the variable.
127 * @param index The index of the desired element.
129 * This allows retrieving aux data by container / index.
131 template <class PAYLOAD_T, class ALLOC>
134 ConstAccessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::operator()
135 (const AuxVectorData& container, size_t index) const -> const element_type
137 const Elt_t& jelt = container.template getData<Elt_t> (m_auxid, index);
138 if (jelt.end() == 0) return element_type();
139 const Payload_t* payload = this->getPayloadArray (container);
140 return element_type (payload+jelt.begin (index), payload+jelt.end());
145 * @brief Get a pointer to the start of the array of @c JaggedVecElt objects.
146 * @param container The container from which to fetch the variable.
148 template <class PAYLOAD_T, class ALLOC>
151 ConstAccessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::getEltArray (const AuxVectorData& container) const
154 return reinterpret_cast<const Elt_t*> (container.getDataArray (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 ConstAccessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::getPayloadArray (const AuxVectorData& container) const
168 return reinterpret_cast<const Payload_t*>
169 (container.getDataArray (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 ConstAccessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::getEltSpan (const AuxVectorData& container) const
183 auto beg = reinterpret_cast<const Elt_t*> (container.getDataArray (m_auxid));
184 return const_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 ConstAccessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::getPayloadSpan (const AuxVectorData& container) const
196 -> const_Payload_span
198 const SG::AuxDataSpanBase* sp = container.getDataSpan (m_linkedAuxid);
199 return const_Payload_span (reinterpret_cast<const Payload_t*>(sp->beg),
205 * @brief Get a span over spans representing the jagged vector.
206 * @param container The container from which to fetch the variable.
208 template <class PAYLOAD_T, class ALLOC>
211 ConstAccessor<JaggedVecElt<PAYLOAD_T>, ALLOC>::getDataSpan (const AuxVectorData& container) const
214 const_Elt_span elt_span = getEltSpan (container);
215 return const_span (elt_span,
216 ConstConverter_t (elt_span.data(),
217 *container.getDataSpan (m_linkedAuxid)));