ATLAS Offline Software
Loading...
Searching...
No Matches
AuxVectorBase.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
10
11
13
14
15namespace SG {
16
17
31
32
42
43
49{
50 if (this != &rhs) {
51 AuxVectorData::operator= (std::move (rhs));
52 m_trackIndices = rhs.m_trackIndices;
53 }
54 return *this;
55}
56
57
64
65
77{
78 if (store && !m_trackIndices)
81}
82
83
100
101
118
119
129void
130AuxVectorBase::initAuxVectorBase1 (const std::false_type&,
131 SG::OwnershipPolicy /*ownPolicy*/,
132 SG::IndexTrackingPolicy /*indexTrackingPolicy*/)
133{
134 m_trackIndices = false;
135 if (this->hasStore())
137}
138
139
149void
151 SG::OwnershipPolicy ownPolicy,
152 SG::IndexTrackingPolicy indexTrackingPolicy)
153{
154 if (indexTrackingPolicy == SG::ALWAYS_TRACK_INDICES)
155 m_trackIndices = true;
156 else if (indexTrackingPolicy == SG::NEVER_TRACK_INDICES)
157 m_trackIndices = false;
158 else if (ownPolicy == SG::OWN_ELEMENTS)
159 m_trackIndices = true;
160 else
161 m_trackIndices = false;
162
163 if (!m_trackIndices && this->hasStore())
165}
166
167
174void AuxVectorBase::resize1 (const std::true_type&, size_t size)
175{
176 if (this->hasNonConstStore()) {
177 if (!this->getStore()->resize (size)) {
178 // Only clear the cache if iterators have been invalidated.
179 clearCache();
180 }
181 }
182 else if (this->hasStore())
183 throw SG::ExcConstAuxData ("resize");
184}
185
186
193void AuxVectorBase::reserve1 (const std::true_type&, size_t size)
194{
195 if (this->hasNonConstStore()) {
196 this->getStore()->reserve (size);
197 clearCache();
198 }
199 else if (this->hasStore())
200 throw SG::ExcConstAuxData ("reserve");
201}
202
203
220void
222 bool clear /*= false*/,
223 bool skipDestClear /*= false*/)
224{
225 if (!m_trackIndices)
226 return;
227
228 SG::AuxElement to (this, index);
229 if (!p) {
230 if (!skipDestClear) {
232 }
233 return;
234 }
235
236 if (p->hasStore() || !skipDestClear) {
237 AuxElement::copyAuxHelper (*this, index, *p, false);
238 }
239 if (clear)
240 p->clearAux();
241 p->setIndex (index, this);
242}
243
244
259 size_t bindex,
262 AuxVectorBase* bcont)
263{
264 AuxVectorBase* acont = this;
265
266 // If one of the elements is null, then this is just a @c moveAux.
267 if (!b) {
268 if (!a) return;
269 acont->moveAux (aindex, a, true);
270 return;
271 }
272 if (!a) {
273 bcont->moveAux (bindex, b, true);
274 return;
275 }
276
277 // Reset indices.
278 if (b && bcont->trackIndices())
279 b->setIndex (bindex, bcont);
280 if (a && acont->trackIndices())
281 a->setIndex (aindex, acont);
282
283 // Check stores.
284 if (!this->hasNonConstStore()) {
285 if (this->hasStore()) {
286 throw SG::ExcConstAuxData ("swapElementsAux");
287 }
288 return;
289 }
290
291 // Swap aux data.
292
294
295 SG::auxid_set_t a_ids = acont->getAuxIDs();
296 for (SG::auxid_t auxid : a_ids) {
297 r.swap (auxid, *acont, aindex, *bcont, bindex, 1);
298 }
299 for (SG::auxid_t auxid : bcont->getAuxIDs()) {
300 if (!a_ids.test (auxid)) {
301 r.swap (auxid, *acont, aindex, *bcont, bindex, 1);
302 }
303 }
304}
305
306
314 size_t index,
316 : m_vec (vec),
317 m_index (index),
318 m_imap (sz),
319 m_rmap (sz)
320{
321 for (size_t i = 0; i < sz; i++)
322 m_imap[i] = m_rmap[i] = i;
323
324 const SG::auxid_set_t& auxid_set = vec.getAuxIDs();
325 size_t naux = auxid_set.size();
326 m_auxdata.reserve (naux);
327 m_auxids.reserve (naux);
328 for (SG::auxid_t auxid : auxid_set) {
329 m_auxdata.push_back (vec.getDataArrayForResort (auxid));
330 m_auxids.push_back (auxid);
331 }
332}
333
334
340void
342{
343 // V
344 // x: 9 8 7 6 5 0 1 2 3 4
345 // m_index: 0 1 2 3 4 0 1 2 3 4
346 // imap 9 8 7 6 5 4 3 2 1 0
347 // rmap 9 8 7 6 5 4 3 2 1 0
348 // aux 19 18 17 16 15 14 13 12 11 10
349 //
350 // imap[i] tells in which slot the auxdata originally in slot
351 // i is currently located.
352 // rmap[i] gives the original location of the auxdata
353 // currently in slot i.
354 //
355 // each time through the loop, looking at index i:
356 // -- look at the index that was set.
357 // we want to move the aux data originally at
358 // auxindex=v[i]->index() here.
359 // -- that data is currently at slot ii1 = imap[auxindex]
360 // -- swap auxdata between slots i and ii1
361 // -- swap rmap between slots i and ii1
362 // -- swap imap entries rmap[i] and rmap[ii1]
363 // -- set v[i]->index() to index.
364 // but need to remember to take into account any offset between
365 // the beginning of the range we're given and the beginning
366 // of the container (i.e., index was nonzero on entry).
367 //
368 // ??? can this be made more efficient? do we need so much
369 // working storage??? xxx
370
371 size_t index = m_index;
372 size_t auxindex = elt->index();
373 ATHCONTAINERS_ASSERT (auxindex-index < m_imap.size());
374 size_t ii1 = m_imap[auxindex-index];
375 if (ii1 != idx) {
376 ATHCONTAINERS_ASSERT (ii1 > idx);
377 // swap between auxdata slots dx+index, ii1+index
379 size_t naux = m_auxids.size();
380 SG::AuxVectorData& cont = *elt->container();
381 for (size_t iid = 0; iid < naux; iid++) {
382 r.swap (m_auxids[iid], cont, idx+index, cont, ii1+index, 1);
383 }
384 std::swap (m_rmap[idx], m_rmap[ii1]);
385 std::swap (m_imap[m_rmap[idx]], m_imap[m_rmap[ii1]]);
386 }
387
388 m_vec.setIndexForResort (elt, index+idx);
389}
390
391
392} // namespace SG
#define ATHCONTAINERS_ASSERT(X)
Manage index tracking and synchronization of auxiliary data.
std::vector< size_t > vec
static Double_t sz
static Double_t a
bool test(bit_t bit) const
Test to see if a bit is set.
bit_t size() const
Count the number of 1 bits in the set.
Base class for elements of a container that can have aux data.
Definition AuxElement.h:483
static void clearAuxHelper(AuxVectorData &container, size_t index)
Clear all aux data associated with an element.
static void copyAuxHelper(AuxVectorData &container, size_t index, const ConstAuxElement &other, bool warnUnlocked)
Copy aux data from another object.
const SG::AuxVectorData * container() const
Return the container holding this element.
size_t index() const
Return the index of this element within its container.
Handle mappings between names and auxid_t.
static AuxTypeRegistry & instance()
Return the singleton registry instance.
std::vector< SG::auxid_t > m_auxids
void resortElement(size_t idx, SG::AuxElement *elt)
AuxVectorBase()
Default constructor.
void moveAux(size_t index, SG::AuxElement *p, bool clear=false, bool skipDestClear=false)
Set index on an element and copy auxiliary data.
void initAuxVectorBase1(const std::false_type &, SG::OwnershipPolicy, SG::IndexTrackingPolicy)
Initialize index tracking mode — no-auxdata specialization.
void swapElementsAux(size_t aindex, size_t bindex, SG::AuxElement *a, SG::AuxElement *b, AuxVectorBase *bcont)
Swap indices and auxiliary data between two elements.
bool m_trackIndices
Flag if index tracking is enabled.
void resize(size_t size)
Resize the aux data associated with this container.
void setStore(SG::IAuxStore *store)
Set the store associated with this object.
void resize1(const std::false_type &, size_t size)
Resize the aux data associated with this container.
virtual ~AuxVectorBase()
Destructor.
AuxVectorBase & operator=(AuxVectorBase &&rhs)
Move assignment.
void reserve1(const std::false_type &, size_t size)
Change the capacity of the aux data associated with this container.
bool trackIndices() const
Return true if index tracking is enabled for this container.
Manage lookup of vectors of auxiliary data.
const SG::auxid_set_t & getAuxIDs() const
Return a set of identifiers for existing data items in store associated with this object.
void setStore(SG::IAuxStore *store)
Set the store associated with this object.
bool hasNonConstStore() const
Return true if this object has an associated non-const store.
AuxVectorData & operator=(AuxVectorData &&rhs)
Move assignment.
void clearCache()
Clear the cached aux data pointers.
AuxVectorData()
Constructor.
SG::IAuxStore * getStore()
Return the current store, as a non-const interface.
bool hasStore() const
Return true if this object has an associated store.
Exception — Non-const operation performed on const aux data.
Exception — Attempt to set aux data store on container that doesn't track indices,...
Interface for non-const operations on an auxiliary store.
Definition IAuxStore.h:48
virtual void reserve(size_t sz)=0
Change the capacity of all aux data vectors.
Interface for const operations on an auxiliary store.
A set of aux data identifiers.
Definition AuxTypes.h:47
int r
Definition globals.cxx:22
Forward declaration.
@ ALWAYS_TRACK_INDICES
Always track indices, regardless of the setting of the ownership policy.
@ NEVER_TRACK_INDICES
Never track indices, regardless of the setting of the ownership policy.
OwnershipPolicy
@ OWN_ELEMENTS
this data object owns its elements
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
Definition index.py:1
STL namespace.
void swap(ElementLinkVector< DOBJ > &lhs, ElementLinkVector< DOBJ > &rhs)