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 #ifndef __CPPCHECK__ // cppcheck gets parse errors on this
133 template <class PAYLOAD_T, class ALLOC>
136 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::operator() (const AuxVectorData& container,
140 (void)this->getEltDecorArray (container); // const/locking checks
141 AuxVectorData& container_nc ATLAS_THREAD_SAFE =
142 const_cast<AuxVectorData&> (container);
143 return JVecProxy (index,
144 *container.getDataSpan (this->m_linkedAuxid),
145 *container.getDataSpan (this->m_auxid),
149 #endif // not __CPPCHECK__
153 * @brief Set the variable for one element.
154 * @param e The element for which to fetch the variable.
155 * @param x The variable value to set.
157 template <class PAYLOAD_T, class ALLOC>
158 template <IsConstAuxElement ELT,
159 CxxUtils::InputRangeOverT<PAYLOAD_T> RANGE>
161 void Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::set (const ELT& e,
162 const RANGE& x) const
164 set (*e.container(), e.index(), x);
169 * @brief Set the variable for one element.
170 * @param container The container from which to fetch the variable.
171 * @param index The index of the desired element.
172 * @param x The variable value to set.
174 template <class PAYLOAD_T, class ALLOC>
175 template <CxxUtils::InputRangeOverT<PAYLOAD_T> RANGE>
177 void Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::set (const AuxVectorData& container,
179 const RANGE& x) const
181 (*this) (container, index) = x;
186 * @brief Get a pointer to the start of the array of @c JaggedVecElt objects.
187 * @param container The container from which to fetch the variable.
189 template <class PAYLOAD_T, class ALLOC>
192 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::getEltArray (const AuxVectorData& container) const
195 return reinterpret_cast<const Elt_t*>
196 (container.getDataArray (m_auxid));
201 * @brief Get a pointer to the start of the payload array.
202 * @param container The container from which to fetch the variable.
204 template <class PAYLOAD_T, class ALLOC>
207 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::getPayloadArray (const AuxVectorData& container) const
210 return reinterpret_cast<const Payload_t*>
211 (container.getDataArray (m_linkedAuxid));
216 * @brief Get a pointer to the start of the array of @c JaggedVecElt objects,
218 * @param container The container from which to fetch the variable.
220 * If the container is locked, this will allow fetching only variables
221 * that do not yet exist (in which case they will be marked as decorations)
222 * or variables already marked as decorations.
224 template <class PAYLOAD_T, class ALLOC>
227 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::getEltDecorArray (const AuxVectorData& container) const
230 return reinterpret_cast<Elt_t*>
231 (container.getDecorationArray (m_auxid));
236 * @brief Get a pointer to the start of the payload array,
238 * @param container The container from which to fetch the variable.
240 * If the container is locked, this will allow fetching only variables
241 * that do not yet exist (in which case they will be marked as decorations)
242 * or variables already marked as decorations.
244 template <class PAYLOAD_T, class ALLOC>
247 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::getPayloadDecorArray (const AuxVectorData& container) const
250 return reinterpret_cast<Payload_t*>
251 (container.getDecorationArray (m_linkedAuxid));
256 * @brief Get a span over the array of @c JaggedVecElt objects.
257 * @param container The container from which to fetch the variable.
259 template <class PAYLOAD_T, class ALLOC>
262 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::getEltSpan (const AuxVectorData& container) const
265 auto beg = reinterpret_cast<const Elt_t*>(container.getDataArray (m_auxid));
266 return const_Elt_span (beg, container.size_v());
271 * @brief Get a span over the payload vector.
272 * @param container The container from which to fetch the variable.
274 template <class PAYLOAD_T, class ALLOC>
277 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::getPayloadSpan (const AuxVectorData& container) const
278 -> const_Payload_span
280 const AuxDataSpanBase* sp = container.getDataSpan (m_linkedAuxid);
281 return const_Payload_span (reinterpret_cast<const Payload_t*>(sp->beg),
287 * @brief Get a span over spans representing the jagged vector.
288 * @param container The container from which to fetch the variable.
290 template <class PAYLOAD_T, class ALLOC>
293 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::getDataSpan (const AuxVectorData& container) const
296 const_Elt_span elt_span = getEltSpan (container);
297 return const_span (elt_span,
298 ConstConverter_t (elt_span.data(),
299 *container.getDataSpan (m_linkedAuxid)));
304 * @brief Get a span over the array of @c JaggedVecElt objects,
306 * @param container The container from which to fetch the variable.
308 * If the container is locked, this will allow fetching only variables
309 * that do not yet exist (in which case they will be marked as decorations)
310 * or variables already marked as decorations.
312 template <class PAYLOAD_T, class ALLOC>
315 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::getEltDecorSpan (const AuxVectorData& container) const
318 auto beg = reinterpret_cast<Elt_t*>
319 (container.getDecorationArray (this->m_auxid));
320 return Elt_span (beg, container.size_v());
325 * @brief Get a span over the payload vector,
327 * @param container The container from which to fetch the variable.
329 * If the container is locked, this will allow fetching only variables
330 * that do not yet exist (in which case they will be marked as decorations)
331 * or variables already marked as decorations.
333 template <class PAYLOAD_T, class ALLOC>
336 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::getPayloadDecorSpan (const AuxVectorData& container) const
339 (void)container.getDecorationArray (this->m_linkedAuxid); // check for locking
340 const AuxDataSpanBase* sp = container.getDataSpan (m_linkedAuxid);
341 return Payload_span (reinterpret_cast<Payload_t*>(sp->beg), sp->size);
346 * @brief Get a span over spans representing the jagged vector,
348 * @param container The container from which to fetch the variable.
350 * If the container is locked, this will allow fetching only variables
351 * that do not yet exist (in which case they will be marked as decorations)
352 * or variables already marked as decorations.
354 template <class PAYLOAD_T, class ALLOC>
357 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::getDecorationSpan (const AuxVectorData& container) const
360 Elt_span elt_span = getEltDecorSpan(container);
361 AuxVectorData& container_nc ATLAS_THREAD_SAFE = const_cast<AuxVectorData&> (container);
362 return span (elt_span,
363 Converter_t (container_nc, this->auxid(), this->linkedAuxid()));
368 * @brief Test to see if this variable exists in the store and is writable.
369 * @param e An element of the container om which to test the variable.
371 template <class PAYLOAD_T, class ALLOC>
372 template <IsConstAuxElement ELT>
375 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::isAvailableWritable (const ELT& e) const
377 return e.container() &&
378 e.container()->isAvailableWritableAsDecoration (m_auxid) &&
379 e.container()->isAvailableWritableAsDecoration (m_linkedAuxid);
384 * @brief Test to see if this variable exists in the store and is writable.
385 * @param c The container in which to test the variable.
387 template <class PAYLOAD_T, class ALLOC>
390 Decorator<JaggedVecElt<PAYLOAD_T>, ALLOC>::isAvailableWritable (const AuxVectorData& c) const
392 return c.isAvailableWritableAsDecoration (m_auxid) &&
393 c.isAvailableWritableAsDecoration (m_linkedAuxid);