ATLAS Offline Software
AuxVectorBase.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
13 
14 
15 namespace SG {
16 
17 
28  : m_trackIndices (false)
29 {
30 }
31 
32 
38  : AuxVectorData (std::move (rhs)),
39  m_trackIndices (rhs.m_trackIndices)
40 {
41 }
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 
62 {
63 }
64 
65 
77 {
78  if (store && !m_trackIndices)
81 }
82 
83 
95 {
96  if (store && !m_trackIndices)
99 }
100 
101 
113 {
114  if (!m_trackIndices)
115  throw SG::ExcUntrackedSetStore();
117 }
118 
119 
129 void
130 AuxVectorBase::initAuxVectorBase1 (const std::false_type&,
131  SG::OwnershipPolicy /*ownPolicy*/,
132  SG::IndexTrackingPolicy /*indexTrackingPolicy*/)
133 {
134  m_trackIndices = false;
135  if (this->hasStore())
136  throw SG::ExcUntrackedSetStore();
137 }
138 
139 
149 void
150 AuxVectorBase::initAuxVectorBase1 (const std::true_type&,
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())
164  throw SG::ExcUntrackedSetStore();
165 }
166 
167 
174 void 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 
193 void 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 
220 void
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 
258 void AuxVectorBase::swapElementsAux (size_t aindex,
259  size_t bindex,
260  SG::AuxElement* a,
261  SG::AuxElement* b,
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 
340 void
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
SGTest::store
TestStore store
Definition: TestStore.cxx:23
beamspotman.r
def r
Definition: beamspotman.py:672
fitman.sz
sz
Definition: fitman.py:527
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
SG::AuxVectorBase::ResortAuxHelper::m_imap
std::vector< size_t > m_imap
Definition: AuxVectorBase.h:853
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:640
SG::ExcUntrackedSetStore
Exception — Attempt to set aux data store on container that doesn't track indices,...
Definition: Control/AthContainers/AthContainers/exceptions.h:95
SG::AuxVectorBase::ResortAuxHelper::m_auxids
std::vector< SG::auxid_t > m_auxids
Definition: AuxVectorBase.h:856
index
Definition: index.py:1
SG::AuxElement
Base class for elements of a container that can have aux data.
Definition: AuxElement.h:483
SG::NEVER_TRACK_INDICES
@ NEVER_TRACK_INDICES
Never track indices, regardless of the setting of the ownership policy.
Definition: IndexTrackingPolicy.h:46
SG::AuxVectorBase::ResortAuxHelper::m_auxdata
std::vector< void * > m_auxdata
Definition: AuxVectorBase.h:855
SG::AuxElement::clearAuxHelper
static void clearAuxHelper(AuxVectorData &container, size_t index)
Clear all aux data associated with an element.
Definition: AuxElement.cxx:639
SG::AuxVectorData::hasNonConstStore
bool hasNonConstStore() const
Return true if this object has an associated non-const store.
SG::ALWAYS_TRACK_INDICES
@ ALWAYS_TRACK_INDICES
Always track indices, regardless of the setting of the ownership policy.
Definition: IndexTrackingPolicy.h:43
SG::AuxVectorData::operator=
AuxVectorData & operator=(AuxVectorData &&rhs)
Move assignment.
Definition: AuxVectorData.cxx:66
SG::AuxVectorBase::setStore
void setStore(SG::IAuxStore *store)
Set the store associated with this object.
Definition: AuxVectorBase.cxx:94
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:9
SG::AuxVectorBase::ResortAuxHelper::ResortAuxHelper
ResortAuxHelper()
SG::AuxVectorBase::ResortAuxHelper::m_rmap
std::vector< size_t > m_rmap
Definition: AuxVectorBase.h:854
SG::ExcConstAuxData
Exception — Non-const operation performed on const aux data.
Definition: Control/AthContainers/AthContainers/exceptions.h:77
SG::AuxVectorBase::~AuxVectorBase
virtual ~AuxVectorBase()
Destructor.
Definition: AuxVectorBase.cxx:61
AuxVectorBase.h
Manage index tracking and synchronization of auxiliary data.
SG::AuxVectorBase
Manage index tracking and synchronization of auxiliary data.
Definition: AuxVectorBase.h:98
SG::AuxVectorData::getAuxIDs
const SG::auxid_set_t & getAuxIDs() const
Return a set of identifiers for existing data items in store associated with this object.
Definition: AuxVectorData.cxx:203
SG::OwnershipPolicy
OwnershipPolicy
describes the possible element ownership policies (see e.g. DataVector)
Definition: OwnershipPolicy.h:16
SG::AuxTypeRegistry
Handle mappings between names and auxid_t.
Definition: AuxTypeRegistry.h:61
SG::AuxVectorBase::swapElementsAux
void swapElementsAux(size_t aindex, size_t bindex, SG::AuxElement *a, SG::AuxElement *b, AuxVectorBase *bcont)
Swap indices and auxiliary data between two elements.
Definition: AuxVectorBase.cxx:258
ATHCONTAINERS_ASSERT
#define ATHCONTAINERS_ASSERT(X)
Definition: ATHCONTAINERS_ASSERT.h:31
SG::AuxVectorBase::operator=
AuxVectorBase & operator=(AuxVectorBase &&rhs)
Move assignment.
Definition: AuxVectorBase.cxx:48
SG::AuxVectorBase::resize
void resize(size_t size)
Resize the aux data associated with this container.
SG::AuxVectorData::setStore
void setStore(SG::IAuxStore *store)
Set the store associated with this object.
Definition: AuxVectorData.cxx:116
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition: AuxTypes.h:27
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
CxxUtils::ConcurrentBitset::size
bit_t size() const
Count the number of 1 bits in the set.
lumiFormat.i
int i
Definition: lumiFormat.py:85
SG::OWN_ELEMENTS
@ OWN_ELEMENTS
this data object owns its elements
Definition: OwnershipPolicy.h:17
SG::AuxVectorData::getStore
SG::IAuxStore * getStore()
Return the current store, as a non-const interface.
SG::AuxElement::index
size_t index() const
Return the index of this element within its container.
SG::AuxVectorData::hasStore
bool hasStore() const
Return true if this object has an associated store.
WriteCalibToCool.swap
swap
Definition: WriteCalibToCool.py:94
SG::AuxVectorBase::reserve1
void reserve1(const std::false_type &, size_t size)
Change the capacity of the aux data associated with this container.
SG::AuxVectorBase::resize1
void resize1(const std::false_type &, size_t size)
Resize the aux data associated with this container.
SG::AuxVectorBase::m_trackIndices
bool m_trackIndices
Flag if index tracking is enabled.
Definition: AuxVectorBase.h:866
SG::AuxVectorBase::initAuxVectorBase1
void initAuxVectorBase1(const std::false_type &, SG::OwnershipPolicy, SG::IndexTrackingPolicy)
Initialize index tracking mode — no-auxdata specialization.
Definition: AuxVectorBase.cxx:130
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:76
SG::AuxVectorData::clearCache
void clearCache()
Clear the cached aux data pointers.
SG::AuxVectorBase::ResortAuxHelper::resortElement
void resortElement(size_t idx, SG::AuxElement *elt)
Definition: AuxVectorBase.cxx:341
SG::AuxVectorBase::moveAux
void moveAux(size_t index, SG::AuxElement *p, bool clear=false, bool skipDestClear=false)
Set index on an element and copy auxiliary data.
Definition: AuxVectorBase.cxx:221
CxxUtils::to
CONT to(RANGE &&r)
Definition: ranges.h:39
SG::IAuxStore
Interface for non-const operations on an auxiliary store.
Definition: IAuxStore.h:48
DeMoScan.index
string index
Definition: DeMoScan.py:362
a
TList * a
Definition: liststreamerinfos.cxx:10
VKalVrtAthena::varHolder_detail::clear
void clear(T &var)
Definition: NtupleVars.h:48
SG::AuxVectorBase::AuxVectorBase
AuxVectorBase()
Default constructor.
Definition: AuxVectorBase.cxx:27
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
SG::auxid_set_t
A set of aux data identifiers.
Definition: AuxTypes.h:47
SG::AuxVectorData
Manage lookup of vectors of auxiliary data.
Definition: AuxVectorData.h:164
SG::AuxElement::container
const SG::AuxVectorData * container() const
Return the container holding this element.
SG::IConstAuxStore
Interface for const operations on an auxiliary store.
Definition: IConstAuxStore.h:64
SG::AuxVectorBase::trackIndices
bool trackIndices() const
Return true if index tracking is enabled for this container.
SG::IndexTrackingPolicy
IndexTrackingPolicy
Definition: IndexTrackingPolicy.h:37
SG::AuxElement::copyAuxHelper
static void copyAuxHelper(AuxVectorData &container, size_t index, const ConstAuxElement &other, bool warnUnlocked)
Copy aux data from another object.
Definition: AuxElement.cxx:667
SG::IAuxStore::reserve
virtual void reserve(size_t sz)=0
Change the capacity of all aux data vectors.