ATLAS Offline Software
AuxVectorBase.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // $Id$
15 
16 
17 namespace SG {
18 
19 
30  : m_trackIndices (false)
31 {
32 }
33 
34 
40  : AuxVectorData (std::move (rhs)),
41  m_trackIndices (rhs.m_trackIndices)
42 {
43 }
44 
45 
51 {
52  if (this != &rhs) {
53  AuxVectorData::operator= (std::move (rhs));
54  m_trackIndices = rhs.m_trackIndices;
55  }
56  return *this;
57 }
58 
59 
64 {
65 }
66 
67 
79 {
80  if (store && !m_trackIndices)
83 }
84 
85 
97 {
98  if (store && !m_trackIndices)
101 }
102 
103 
115 {
116  if (!m_trackIndices)
117  throw SG::ExcUntrackedSetStore();
119 }
120 
121 
131 void
132 AuxVectorBase::initAuxVectorBase1 (const std::false_type&,
133  SG::OwnershipPolicy /*ownPolicy*/,
134  SG::IndexTrackingPolicy /*indexTrackingPolicy*/)
135 {
136  m_trackIndices = false;
137  if (this->hasStore())
138  throw SG::ExcUntrackedSetStore();
139 }
140 
141 
151 void
152 AuxVectorBase::initAuxVectorBase1 (const std::true_type&,
153  SG::OwnershipPolicy ownPolicy,
154  SG::IndexTrackingPolicy indexTrackingPolicy)
155 {
156  if (indexTrackingPolicy == SG::ALWAYS_TRACK_INDICES)
157  m_trackIndices = true;
158  else if (indexTrackingPolicy == SG::NEVER_TRACK_INDICES)
159  m_trackIndices = false;
160  else if (ownPolicy == SG::OWN_ELEMENTS)
161  m_trackIndices = true;
162  else
163  m_trackIndices = false;
164 
165  if (!m_trackIndices && this->hasStore())
166  throw SG::ExcUntrackedSetStore();
167 }
168 
169 
176 void AuxVectorBase::resize1 (const std::true_type&, size_t size)
177 {
178  if (this->hasNonConstStore()) {
179  if (!this->getStore()->resize (size)) {
180  // Only clear the cache if iterators have been invalidated.
181  clearCache();
182  }
183  }
184  else if (this->hasStore())
185  throw SG::ExcConstAuxData ("resize");
186 }
187 
188 
195 void AuxVectorBase::reserve1 (const std::true_type&, size_t size)
196 {
197  if (this->hasNonConstStore()) {
198  this->getStore()->reserve (size);
199  clearCache();
200  }
201  else if (this->hasStore())
202  throw SG::ExcConstAuxData ("reserve");
203 }
204 
205 
222 void
224  bool clear /*= false*/,
225  bool skipDestClear /*= false*/)
226 {
227  if (!m_trackIndices)
228  return;
229 
230  SG::AuxElement to (this, index);
231  if (!p) {
232  if (!skipDestClear) to.clearAux();
233  return;
234  }
235 
236  if (p->hasStore() || !skipDestClear)
237  to.copyAux (*p);
238  if (clear)
239  p->clearAux();
240  p->setIndex (index, this);
241 }
242 
243 
257 void AuxVectorBase::swapElementsAux (size_t aindex,
258  size_t bindex,
259  SG::AuxElement* a,
260  SG::AuxElement* b,
261  AuxVectorBase* bcont)
262 {
263  AuxVectorBase* acont = this;
264 
265  // If one of the elements is null, then this is just a @c moveAux.
266  if (!b) {
267  if (!a) return;
268  acont->moveAux (aindex, a, true);
269  return;
270  }
271  if (!a) {
272  bcont->moveAux (bindex, b, true);
273  return;
274  }
275 
276  // Reset indices.
277  if (b && bcont->trackIndices())
278  b->setIndex (bindex, bcont);
279  if (a && acont->trackIndices())
280  a->setIndex (aindex, acont);
281 
282  // Check stores.
283  if (!this->hasNonConstStore()) {
284  if (this->hasStore()) {
285  throw SG::ExcConstAuxData ("swapElementsAux");
286  }
287  return;
288  }
289 
290  // Swap aux data.
291 
293 
294  SG::auxid_set_t a_ids = acont->getAuxIDs();
295  for (SG::auxid_t auxid : a_ids) {
296  r.swap (auxid, *acont, aindex, *bcont, bindex, 1);
297  }
298  for (SG::auxid_t auxid : bcont->getAuxIDs()) {
299  if (!a_ids.test (auxid)) {
300  r.swap (auxid, *acont, aindex, *bcont, bindex, 1);
301  }
302  }
303 }
304 
305 
313  size_t index,
315  : m_vec (vec),
316  m_index (index),
317  m_imap (sz),
318  m_rmap (sz)
319 {
320  for (size_t i = 0; i < sz; i++)
321  m_imap[i] = m_rmap[i] = i;
322 
323  const SG::auxid_set_t& auxid_set = vec.getAuxIDs();
324  size_t naux = auxid_set.size();
325  m_auxdata.reserve (naux);
326  m_auxids.reserve (naux);
327  for (SG::auxid_t auxid : auxid_set) {
328  m_auxdata.push_back (vec.getDataArrayForResort (auxid));
329  m_auxids.push_back (auxid);
330  }
331 }
332 
333 
339 void
341 {
342  // V
343  // x: 9 8 7 6 5 0 1 2 3 4
344  // m_index: 0 1 2 3 4 0 1 2 3 4
345  // imap 9 8 7 6 5 4 3 2 1 0
346  // rmap 9 8 7 6 5 4 3 2 1 0
347  // aux 19 18 17 16 15 14 13 12 11 10
348  //
349  // imap[i] tells in which slot the auxdata originally in slot
350  // i is currently located.
351  // rmap[i] gives the original location of the auxdata
352  // currently in slot i.
353  //
354  // each time through the loop, looking at index i:
355  // -- look at the index that was set.
356  // we want to move the aux data originally at
357  // auxindex=v[i]->index() here.
358  // -- that data is currently at slot ii1 = imap[auxindex]
359  // -- swap auxdata between slots i and ii1
360  // -- swap rmap between slots i and ii1
361  // -- swap imap entries rmap[i] and rmap[ii1]
362  // -- set v[i]->index() to index.
363  // but need to remember to take into account any offset between
364  // the beginning of the range we're given and the beginning
365  // of the container (i.e., index was nonzero on entry).
366  //
367  // ??? can this be made more efficient? do we need so much
368  // working storage??? xxx
369 
370  size_t index = m_index;
371  size_t auxindex = elt->index();
372  ATHCONTAINERS_ASSERT (auxindex-index < m_imap.size());
373  size_t ii1 = m_imap[auxindex-index];
374  if (ii1 != idx) {
375  ATHCONTAINERS_ASSERT (ii1 > idx);
376  // swap between auxdata slots dx+index, ii1+index
378  size_t naux = m_auxids.size();
379  SG::AuxVectorData& cont = *elt->container();
380  for (size_t iid = 0; iid < naux; iid++) {
381  r.swap (m_auxids[iid], cont, idx+index, cont, ii1+index, 1);
382  }
383  std::swap (m_rmap[idx], m_rmap[ii1]);
384  std::swap (m_imap[m_rmap[idx]], m_imap[m_rmap[ii1]]);
385  }
386 
387  m_vec.setIndexForResort (elt, index+idx);
388 }
389 
390 
391 } // namespace SG
SGTest::store
TestStore store
Definition: TestStore.cxx:23
beamspotman.r
def r
Definition: beamspotman.py:676
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:639
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::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:96
vec
std::vector< size_t > vec
Definition: CombinationsGeneratorTest.cxx:12
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:63
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:257
ATHCONTAINERS_ASSERT
#define ATHCONTAINERS_ASSERT(X)
Definition: ATHCONTAINERS_ASSERT.h:31
SG::AuxVectorBase::operator=
AuxVectorBase & operator=(AuxVectorBase &&rhs)
Move assignment.
Definition: AuxVectorBase.cxx:50
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:210
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:132
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
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:340
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:223
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:364
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:29
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:168
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::IAuxStore::reserve
virtual void reserve(size_t sz)=0
Change the capacity of all aux data vectors.