ATLAS Offline Software
AuxElement.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
16 
17 
18 
19 namespace SG {
20 
21 
29  : public AuxVectorData
30 {
31 public:
32  virtual size_t size_v() const { return 1; }
33  virtual size_t capacity_v() const { return 1; }
34 };
35 
36 
44  : public AuxElementData
45 {
46 public:
48  {
49  this->setStore (&m_store);
50  }
51 
52 
53 private:
55 };
56 
57 
64  : public AuxElementData
65 {
66 public:
68 };
69 
70 
71 //************************************************************************
72 
73 
80 {
81  if (havePrivateData()) {
82  delete m_container;
83  }
84 }
85 
86 
97  const SG::AuxVectorData* container)
98 {
99  if (hadPrivateData()) {
100  // We had a private store, but it was released because we were added
101  // to a container.
102 
103  if (container == 0) {
104  // We're being moved out of the container. Make a new private
105  // store, copy the data, and switch to it.
106  auto privateData = new SG::AuxElementPrivateData;
107  AuxElement to (privateData, 0);
108  to.copyAux (*this);
111  m_container = privateData;
112  return true;
113  }
114  }
115  else if (havePrivateData() &&
116  typeid(*m_container) == typeid(AuxElementPrivateData))
117  {
118  // We currently have a private store.
119 
120  if (container != 0 && container != m_container) {
121  // We're being added to a container.
122  // Aux data has already been copied.
123  // Release private store.
126  delete m_container;
128  return false;
129  }
130  }
131  else {
132  // We have a standalone store.
133  throw SG::ExcBadPrivateStore ("Attempt to add/remove a standalone object "
134  "from a container.");
135  }
136 
139  return false;
140 }
141 
142 
153 {
154  if (havePrivateData())
155  return m_container->getConstStore()->getAuxIDs();
156  if (container())
157  return container()->getAuxIDs();
158  static const SG::auxid_set_t null_set;
159  return null_set;
160 }
161 
162 
163 //************************************************************************
164 
165 
173 {
174  if (m_container) {
175  throw SG::ExcBadPrivateStore ("store already exists");
176  }
177 
181 }
182 
183 
191 {
192  if (hadPrivateData()) {
193  // We had a private store, but it was released because this object
194  // was added to a container. Just forget about it.
196  return;
197  }
198 
199  if (!havePrivateData() ||
200  !m_container ||
201  typeid(*m_container) != typeid(AuxElementPrivateData))
202  {
203  throw SG::ExcBadPrivateStore ("no private store exists");
204  }
205 
208  delete m_container;
209  m_container = 0;
210 }
211 
212 
222 {
224  if (store)
225  data->setStore (store);
226 }
227 
228 
238 {
240  if (store)
241  data->setStore (store);
242 }
243 
244 
250 {
252  if (store)
253  data->setStore (store);
254 }
255 
256 
261 {
262  return havePrivateData() &&
263  typeid(*m_container) == typeid(AuxElementPrivateData);
264 }
265 
266 
271 {
272  return havePrivateData() &&
273  typeid(*m_container) == typeid(AuxElementStandaloneData);
274 }
275 
276 
285 {
286  if (havePrivateData()) {
287  return m_container->getConstStore();
288  }
289  return 0;
290 }
291 
292 
300 {
301  if (havePrivateData()) {
302 #ifdef ATHCONTAINERS_R21_COMPAT
304 #else
305  SG::AuxVectorData* container_nc ATLAS_THREAD_SAFE = const_cast<SG::AuxVectorData*>(container());
306 #endif
307  return container_nc->getStore();
308  }
309  return 0;
310 }
311 
312 
320 {
321  if (container())
322  container()->clearCache();
323 }
324 
325 
336 {
337 #ifdef ATHCONTAINERS_R21_COMPAT
338  if (havePrivateData())
339  return m_container->getConstStore()->getAuxIDs();
340  if (container())
341  return container()->getAuxIDs();
342  static const SG::auxid_set_t null_set;
343  return null_set;
344 #else
346 #endif
347 }
348 
349 
356 {
357  if (havePrivateData())
358  return m_container->hasStore();
359  return false;
360 }
361 
362 
369 {
370  if (havePrivateData())
371  return m_container->hasNonConstStore();
372  return false;
373 }
374 
375 
386 {
387  if (havePrivateData())
388  return m_container->clearDecorations();
389  return false;
390 }
391 
392 
399 {
400 #ifdef ATHCONTAINERS_R21_COMPAT
401  if (havePrivateData()) {
402  delete m_container;
403  }
404 #else
406 #endif
407 }
408 
409 
419 {
420  if (store) {
421  // Want this object be standalone.
422  if (!m_container) {
423  // Not in a container (and no private store). Make a new object.
426  m_container = data;
427  return data;
428  }
429  if (usingStandaloneStore()) {
430  // Standalone --- return existing object.
431  return static_cast<AuxElementStandaloneData*> (container());
432  }
433  // Otherwise, it's an error.
434  throw ExcBadPrivateStore ("Attempt to attach a standalone store to an "
435  "object in a container or with a private store.");
436  }
437 
438  else {
439  // Getting rid of a standalone store.
440  if (usingStandaloneStore()) {
442  delete m_container;
443  m_container = 0;
444  }
445  else if (m_container != 0)
446  throw ExcBadPrivateStore ("Attempt to remove a standalone store from an "
447  "object in a container or with a private store.");
448  return 0;
449  }
450 }
451 
452 
463 {
464 #ifdef ATHCONTAINERS_R21_COMPAT
465  if (hadPrivateData()) {
466  // We had a private store, but it was released because we were added
467  // to a container.
468 
469  if (container == 0) {
470  // We're being moved out of the container. Make a new private
471  // store, copy the data, and switch to it.
472  auto privateData = new SG::AuxElementPrivateData;
473  AuxElement to (privateData, 0);
474  to.copyAux (*this);
477  m_container = privateData;
478  return true;
479  }
480  }
481  else if (havePrivateData() &&
482  typeid(*m_container) == typeid(AuxElementPrivateData))
483  {
484  // We currently have a private store.
485 
486  if (container != 0 && container != m_container) {
487  // We're being added to a container.
488  // Aux data has already been copied.
489  // Release private store.
492  delete m_container;
494  return false;
495  }
496  }
497  else {
498  // We have a standalone store.
499  throw SG::ExcBadPrivateStore ("Attempt to add/remove a standalone object "
500  "from a container.");
501  }
502 
505  return false;
506 #else
508 #endif
509 }
510 
511 
522 {
524  if (other)
525  this->copyAux (*other);
526 }
527 
528 
536 {
537  if (!m_container) return;
538  if (!m_container->hasStore()) return;
540  throw SG::ExcConstAuxData ("clearAux", SG::null_auxid);
541 
543  for (SG::auxid_t auxid : m_container->getWritableAuxIDs()) {
544  r.clear (auxid, *container(), index(), 1);
545  }
546 }
547 
548 
562 {
563  if (!m_container) return;
564  if (!m_container->hasStore()) return;
566  throw SG::ExcConstAuxData ("copyAux");
567 
568  const SG::AuxVectorData* ocont = other.container();
569 
570  if (!ocont || !ocont->hasStore()) {
571  this->clearAux();
572  return;
573  }
574 
575  size_t oindex = other.index();
576  SG::auxid_set_t other_ids = ocont->getAuxIDs();
577 
579 
580  SG::AuxVectorData& cont = *container();
581  for (SG::auxid_t auxid : other_ids) {
582  if (!r.isLinked (auxid)) {
583  r.copy (auxid, cont, index(), *ocont, oindex, 1);
584  }
585  }
586 
587  for (SG::auxid_t auxid : m_container->getWritableAuxIDs()) {
588  if (!other_ids.test (auxid)) {
589  r.clear (auxid, cont, index(), 1);
590  }
591  }
592 }
593 
594 
595 #ifdef ATHCONTAINERS_R21_COMPAT
596 
609 {
610  if (!m_container) return;
611  if (!m_container->hasStore()) return;
613  throw SG::ExcConstAuxData ("copyAux");
614 
615  const SG::AuxVectorData* ocont = other.container();
616 
617  if (!ocont || !ocont->hasStore()) {
618  this->clearAux();
619  return;
620  }
621 
622  size_t oindex = other.index();
623  SG::auxid_set_t other_ids = ocont->getAuxIDs();
624 
626 
627  AuxVectorData& cont = *container();
628  for (SG::auxid_t auxid : other_ids) {
629  if (!r.isLinked (auxid)) {
630  r.copy (auxid, cont, index(), *ocont, oindex, 1);
631  }
632  }
633 
634  for (SG::auxid_t auxid : m_container->getWritableAuxIDs()) {
635  if (!other_ids.test (auxid)) {
636  r.clear (auxid, cont, index(), 1);
637  }
638  }
639 }
640 #endif
641 
642 
643 } // namespace SG
644 
645 
SG::AuxVectorData::getConstStore
const SG::IConstAuxStore * getConstStore() const
Return the current store, as a const interface.
beamspotman.r
def r
Definition: beamspotman.py:676
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:71
SG::ConstAuxElement::getAuxIDs
const SG::auxid_set_t & getAuxIDs() const
Return a set of identifiers for existing data items for this object.
Definition: AuxElement.cxx:152
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
SG::AuxTypeRegistry::instance
static AuxTypeRegistry & instance()
Return the singleton registry instance.
Definition: AuxTypeRegistry.cxx:640
SG::ConstAuxElement::container
const SG::AuxVectorData * container() const
Return the container holding this element.
SG::AuxVectorData::getWritableAuxIDs
const SG::auxid_set_t & getWritableAuxIDs() const
Return a set of identifiers for writable data items in this store.
Definition: AuxVectorData.cxx:231
index
Definition: index.py:1
SG::AuxElement
Base class for elements of a container that can have aux data.
Definition: AuxElement.h:472
SG::AuxElement::copyAux
void copyAux(const ConstAuxElement &other)
Copy aux data from another object.
Definition: AuxElement.cxx:561
SG::ConstAuxElement::m_container
const SG::AuxVectorData * m_container
The container of which this object is an element.
Definition: AuxElement.h:324
exceptions.h
Exceptions that can be thrown from AthContainers.
SG::AuxVectorData::hasNonConstStore
bool hasNonConstStore() const
Return true if this object has an associated non-const store.
SG::AuxElement::hasNonConstStore
bool hasNonConstStore() const
Return true if this object has an associated non-const store.
Definition: AuxElement.cxx:368
SG::AuxElement::usingStandaloneStore
bool usingStandaloneStore() const
Test to see if this object is currently using a standalone store.
Definition: AuxElement.cxx:270
SG::ConstAuxElement::setIndexPrivate
bool setIndexPrivate(size_t index, const SG::AuxVectorData *container)
Set the index/container for this element.
Definition: AuxElement.cxx:96
SG::ExcConstAuxData
Exception — Non-const operation performed on const aux data.
Definition: Control/AthContainers/AthContainers/exceptions.h:77
SG::AuxElementData::capacity_v
virtual size_t capacity_v() const
Return the capacity of the container.
Definition: AuxElement.cxx:33
SG::IAuxElement::setNoPrivateData
void setNoPrivateData()
Record that this element does not have private data.
SG::AuxElement::getStore
SG::IAuxStore * getStore() const
Return the current store, as a non-const interface.
Definition: AuxElement.cxx:299
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::AuxTypeRegistry
Handle mappings between names and auxid_t.
Definition: AuxTypeRegistry.h:61
SG::AuxElementData::size_v
virtual size_t size_v() const
Return the size of the container.
Definition: AuxElement.cxx:32
SG::AuxVectorData::setStore
void setStore(SG::IAuxStore *store)
Set the store associated with this object.
Definition: AuxVectorData.cxx:116
SG::IAuxElement::index
size_t index() const
Return the index of this element within its container.
SG::IAuxElement::setHadPrivateData
void setHadPrivateData()
Record that this element used to have private data.
SG::AuxElement::releasePrivateStoreForDtor
void releasePrivateStoreForDtor()
Out-of-line portion of destructor.
Definition: AuxElement.cxx:398
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition: AuxTypes.h:27
SG::AuxElementPrivateData::m_store
AuxStoreStandalone m_store
Definition: AuxElement.cxx:54
SG::AuxElement::setStore
void setStore(const SG::IConstAuxStore *store)
Set the store associated with this object.
Definition: AuxElement.cxx:221
SG::AuxElement::clearAux
void clearAux()
Clear all aux data associated with this element.
Definition: AuxElement.cxx:535
SG::IAuxElement::havePrivateData
bool havePrivateData() const
True if this element currently has private data.
SG::AuxElement::usingPrivateStore
bool usingPrivateStore() const
Test to see if this object is currently using a private store.
Definition: AuxElement.cxx:260
SG::AuxVectorData::getStore
SG::IAuxStore * getStore()
Return the current store, as a non-const interface.
SG::AuxElement::setIndexPrivate
bool setIndexPrivate(size_t index, SG::AuxVectorData *container)
Set the index/container for this element.
Definition: AuxElement.cxx:462
SG::AuxElement::makePrivateStore1
void makePrivateStore1(const void *)
Create a new private store for this object and copy aux data.
SG::AuxElementData
Internal data container.
Definition: AuxElement.cxx:30
SG::AuxElement::releasePrivateStore
void releasePrivateStore()
Release and free any private store associated with this object.
Definition: AuxElement.cxx:190
SG::AuxStoreStandalone
Auxiliary data store for standalone objects.
Definition: AuxStoreStandalone.h:41
SG::AuxElementPrivateData
Internal data container for private store.
Definition: AuxElement.cxx:45
SG::AuxElement::clearDecorations
bool clearDecorations() const
Clear all decorations.
Definition: AuxElement.cxx:385
SG::AuxElement::getAuxIDs
const SG::auxid_set_t & getAuxIDs() const
Return a set of identifiers for existing data items for this object.
Definition: AuxElement.cxx:335
SG::AuxVectorData::hasStore
bool hasStore() const
Return true if this object has an associated store.
SG::ConstAuxElement
Const part of AuxElement.
Definition: AuxElement.h:71
SG::AuxElement::clearCache
void clearCache()
Clear the cached aux data pointers.
Definition: AuxElement.cxx:319
SG::IAuxElement::setHavePrivateData
void setHavePrivateData()
Record that this element currently has private data.
SG::AuxVectorData::clearCache
void clearCache()
Clear the cached aux data pointers.
SG::AuxElement::makePrivateStore
void makePrivateStore()
Create a new (empty) private store for this object.
Definition: AuxElement.cxx:172
SG::AuxElementStandaloneData
Internal data container for standalone store.
Definition: AuxElement.cxx:65
SG::AuxElement::getConstStore
const SG::IConstAuxStore * getConstStore() const
Return the current store, as a const interface.
Definition: AuxElement.cxx:284
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
SG::AuxElement::hasStore
bool hasStore() const
Return true if this object has an associated store.
Definition: AuxElement.cxx:355
SG::IAuxElement::setIndex
void setIndex(size_t index)
Set the index of this element within its container.
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
SG::AuxElementPrivateData::AuxElementPrivateData
AuxElementPrivateData()
Definition: AuxElement.cxx:47
SG::AuxVectorData::clearDecorations
bool clearDecorations() const
Clear all decorations.
Definition: AuxVectorData.cxx:653
AuxStoreStandalone.h
Auxiliary data store for standalone objects.
SG::ExcBadPrivateStore
Exception — Bad use of private store.
Definition: Control/AthContainers/AthContainers/exceptions.h:113
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
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
SG::ConstAuxElement::releasePrivateStoreForDtor
void releasePrivateStoreForDtor()
Out-of-line portion of destructor.
Definition: AuxElement.cxx:79
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
checker_macros.h
Define macros for attributes used to control the static checker.
SG::IAuxElement::hadPrivateData
bool hadPrivateData() const
True if this element had private data before it was added to its current container.
SG::IConstAuxStore::getAuxIDs
virtual const SG::auxid_set_t & getAuxIDs() const =0
Return a set of identifiers for existing data items in this store.
SG::AuxElement::setStore1
AuxElementStandaloneData * setStore1(const SG::IConstAuxStore *store)
Set the store associated with this object.
Definition: AuxElement.cxx:418
AuxElement.h
Base class for elements of a container that can have aux data.