2 * Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration.
5 * @file AthContainers/tools/JaggedVecVectorFactory.icc
6 * @author scott snyder <snyder@bnl.gov>
8 * @brief Factory object that creates vectors using @c AuxTypeVector,
9 * specialized for JaggedVec.
13#include "AthContainers/tools/AuxTypeVector.h"
14#include "AthContainers/AuxTypeRegistry.h"
15#include "AthContainers/exceptions.h"
21namespace JaggedVecVectorFactoryFuncs {
24using Shift = JaggedVecEltBase::Shift;
28 * @brief Copy elements between vectors: out-of-line portion.
29 * @param auxid The aux data item being operated on.
30 * @param dst Container for the destination vector.
31 * @param dst_index Index of the first destination element in the vector.
32 * @param src Container for the source vector.
33 * @param src_index Index of the first source element in the vector.
34 * @param n Number of elements to copy.
35 * @param for_output If true, then need to use copyForOutput on the
36 * payload, to update links due to thinning.
38 * @c dst and @ src can be either the same or different.
40void copyImpl (SG::auxid_t auxid,
43 const AuxVectorData& src,
50 * @brief Swap elements between vectors.
51 * @param auxid The aux data item being operated on.
52 * @param a Container for the first vector.
53 * @param aindex Index of the first element in the first vector.
54 * @param b Container for the second vector.
55 * @param bindex Index of the first element in the second vector.
56 * @param n Number of elements to swap.
58 * @c a and @ b can be either the same or different.
59 * However, the ranges should not overlap.
61void swap (SG::auxid_t auxid,
62 AuxVectorData& a, size_t aindex,
63 AuxVectorData& b, size_t bindex,
68 * @brief Clear a range of elements within a vector.
69 * @param v Pointer to the vector being operated on.
70 * @param auxid The aux data item being operated on.
71 * @param dst Container holding the element
72 * @param dst_index Index of the first element in the vector.
73 * @param n Number of elements to clear.
75void clear (JaggedVecEltBase* v,
82} // namespace JaggedVecVectorFactoryFuncs
86 * @brief Create a vector object of this type.
87 * @param auxid ID for the variable being created.
88 * @param size Initial size of the new vector.
89 * @param capacity Initial capacity of the new vector.
90 * @param isLinked True if this variable is linked from another one.
93template <class T, class ALLOC>
94std::unique_ptr<IAuxTypeVector>
95JaggedVecVectorFactory<T, ALLOC>::create (SG::auxid_t auxid,
96 size_t size, size_t capacity,
97 [[maybe_unused]] bool isLinked) const
100 const AuxTypeRegistry& r = AuxTypeRegistry::instance();
101 auxid_t linked_id = r.linkedVariable (auxid);
103 using linkedAlloc = typename std::allocator_traits<ALLOC>::template rebind_alloc<T>;
105 std::make_unique<AuxTypeVector<T, linkedAlloc> > (linked_id, 0, 0, true);
106 return std::make_unique<AuxTypeVector_t> (auxid, size, capacity,
107 std::move (linkedVec));
112 * @brief Create a vector object of this type from a data blob.
113 * @param auxid ID for the variable being created.
114 * @param data The vector object.
115 * @param linkedVector The interface for another variable linked to this one.
116 * (We do not take ownership.)
117 * @param isPacked If true, @c data is a @c PackedContainer.
118 * @param ownFlag If true, the newly-created IAuxTypeVector object
119 * will take ownership of @c data.
120 * @param isLinked True if this variable is linked from another one.
122 * @c data should be a pointer to a
123 * std::vector<SG::JaggedVec<CONT>, ALLOC<...> > object obtained with new.
124 * For this method, isPacked and isLinked must both be false.
126template <class CONT, class ALLOC>
127std::unique_ptr<IAuxTypeVector>
128JaggedVecVectorFactory<CONT, ALLOC>::createFromData (SG::auxid_t auxid,
130 IAuxTypeVector* linkedVector,
131 [[maybe_unused]] bool isPacked,
133 [[maybe_unused]] bool isLinked) const
135 assert (!isPacked && !isLinked && linkedVector != nullptr);
136 using Holder = SG::JaggedVecVectorHolder<CONT, ALLOC>;
137 using vector_type = typename Holder::vector_type;
138 return std::make_unique<Holder>
139 (auxid, reinterpret_cast<vector_type*>(data), linkedVector, ownFlag);
144 * @brief Copy elements between vectors.
145 * @param auxid The aux data item being operated on.
146 * @param dst Container for the destination vector.
147 * @param dst_index Index of the first destination element in the vector.
148 * @param src Container for the source vector.
149 * @param src_index Index of the first source element in the vector.
150 * @param n Number of elements to copy.
152 * @c dst and @ src can be either the same or different.
154template <class T, class ALLOC>
155void JaggedVecVectorFactory<T, ALLOC>::copy (SG::auxid_t auxid,
158 const AuxVectorData& src,
163 JaggedVecVectorFactoryFuncs::copyImpl (auxid, dst, dst_index, src, src_index, n, false);
168 * @brief Copy elements between vectors, possibly applying thinning.
169 * @param auxid The aux data item being operated on.
170 * @param dst Container for the destination vector.
171 * @param dst_index Index of the first destination element in the vector.
172 * @param src Container for the source vector.
173 * @param src_index Index of source element in the vector.
174 * @param src_index Index of the first source element in the vector.
175 * @param n Number of elements to copy.
177 * @c dst and @ src can be either the same or different.
179template <class CONT, class ALLOC>
180void JaggedVecVectorFactory<CONT, ALLOC>::copyForOutput
182 AuxVectorData& dst, size_t dst_index,
183 const AuxVectorData& src, size_t src_index,
187 JaggedVecVectorFactoryFuncs::copyImpl (auxid, dst, dst_index, src, src_index, n, true);
192 * @brief Swap elements between vectors.
193 * @param auxid The aux data item being operated on.
194 * @param a Container for the first vector.
195 * @param aindex Index of the first element in the first vector.
196 * @param b Container for the second vector.
197 * @param bindex Index of the first element in the second vector.
198 * @param n Number of elements to swap.
200 * @c a and @ b can be either the same or different.
201 * However, the ranges should not overlap.
203template <class T, class ALLOC>
204void JaggedVecVectorFactory<T, ALLOC>::swap (SG::auxid_t auxid,
205 AuxVectorData& a, size_t aindex,
206 AuxVectorData& b, size_t bindex,
210 JaggedVecVectorFactoryFuncs::swap (auxid, a, aindex, b, bindex, n);
215 * @brief Clear a range of elements within a vector.
216 * @param auxid The aux data item being operated on.
217 * @param dst Container holding the element
218 * @param dst_index Index of the first element in the vector.
219 * @param n Number of elements to clear.
221template <class T, class ALLOC>
222void JaggedVecVectorFactory<T, ALLOC>::clear (SG::auxid_t auxid,
229 vector_value_type* v = reinterpret_cast<vector_value_type*> (dst.getDataArray (auxid));
230 JaggedVecVectorFactoryFuncs::clear (v, auxid, dst, dst_index, n);