ATLAS Offline Software
AuxVectorData.h
Go to the documentation of this file.
1 // This file's extension implies that it's C, but it's really -*- C++ -*-.
2 /*
3  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 */
13 #ifndef ATHCONTAINERS_AUXVECTORDATA_H
14 #define ATHCONTAINERS_AUXVECTORDATA_H
15 
16 
22 #include "AthLinks/DataLink.h"
23 #ifndef XAOD_STANDALONE
24 # include "AthenaKernel/ILockable.h"
25 #endif // not XAOD_STANDALONE
26 #include <vector>
27 #include <utility>
28 #include <cstdlib>
29 
34 
35 
36 namespace SG {
37 
38 
39 class AuxElement;
40 class IAuxStore;
41 class AuxDataOption;
42 
43 
165 #ifndef XAOD_STANDALONE
166  : public ILockable
167 #endif // not XAOD_STANDALONE
168 {
169 public:
171  AuxVectorData();
172 
173 
179 
180 
186 
187 
189  virtual ~AuxVectorData();
190 
191 
197  virtual size_t size_v() const = 0;
198 
199 
205  virtual size_t capacity_v() const = 0;
206 
207 
208  //========================================================================
211 
212 
220 
221 
229 
230 
237 
238 
244  const SG::IAuxStore* getStore() const;
245 
246 
250  bool hasStore() const;
251 
252 
256  bool hasNonConstStore() const;
257 
258 
268  bool setOption (auxid_t id, const AuxDataOption& option);
269 
270 
280  bool setOption (const std::string& name,
281  const AuxDataOption& option);
282 
283 
294  bool setOption (const std::string& name,
295  const std::string& clsname,
296  const AuxDataOption& option);
297 
298 
309  template <class T>
310  bool setOption (auxid_t id, const std::string& optname, T arg);
311 
312 
323  bool setOption (const std::string& name,
324  const std::string& optname,
325  int arg);
326  bool setOption (const std::string& name,
327  const std::string& optname,
328  float arg);
329  bool setOption (const std::string& name,
330  const std::string& optname,
331  double arg);
332 
333 
345  template <class T>
346  bool setOption (const std::string& name,
347  const std::string& clsname,
348  const std::string& optname,
349  T arg);
350 
351 
352 
353 protected:
354  // These are protected. They shouldn't be called directly but
355  // instead from @c setStore methods in derived classes, which do
356  // extra consistency checking.
357 
358 
369  void setStore (SG::IAuxStore* store);
370 
371 
379  void setStore (const SG::IConstAuxStore* store);
380 
381 
390 
391 
404 
405 
407  //========================================================================
410 public:
411 
412 
421  const SG::auxid_set_t& getAuxIDs() const;
422 
423 
427  const SG::auxid_set_t& getDecorIDs() const;
428 
429 
438  const SG::auxid_set_t& getWritableAuxIDs() const;
439 
440 
445  bool isAvailable (auxid_t id) const;
446 
447 
453 
454 
460 
461 
462  // Versions of isAvailable* that take a name rather than an ID are
463  // in the derived class AuxVectorBase.
464 
465 
478  template <class T>
480  getData (SG::auxid_t auxid, size_t ndx);
481 
482 
494  template <class T>
496  getData (SG::auxid_t auxid, size_t ndx) const;
497 
498 
518  template <class T>
520  getDecoration (SG::auxid_t auxid, size_t ndx) const;
521 
522 
531  const void* getDataArray (SG::auxid_t auxid) const;
532 
533 
542  const void* getDataArrayAllowMissing (SG::auxid_t auxid) const;
543 
544 
559  void* getDecorationArray (SG::auxid_t auxid) const;
560 
561 
570  void* getDataArray (SG::auxid_t auxid);
571 
572 
588 
589 
590 protected:
593  static size_t s_minCacheLen ATLAS_THREAD_SAFE;
594 
595 
597  //========================================================================
600 public:
601 
602 
608 
609 
616  void clearCache();
617 
618 
626  void clearCache (SG::auxid_t auxid);
627 
628 
637 
638 
645 #ifndef XAOD_STANDALONE
646  virtual
647 #endif // not XAOD_STANDALONE
648  void lock()
649 #ifndef XAOD_STANDALONE
650  override
651 #endif // not XAOD_STANDALONE
652  ;
653 
654 
664  bool clearDecorations() const;
665 
666 
675  void lockDecoration (SG::auxid_t auxid);
676 
677 
683  const SG::IConstAuxStore* getConstStoreOol() const;
684 
685 
686 protected:
696  void setCache (SG::auxid_t auxid, void* ptr);
697 
698 
708  void setCache (SG::auxid_t auxid, const void* ptr);
709 
710 
712 
713 
714 
715 private:
722  class Cache
723  {
724  public:
728  Cache();
729 
730 
735  Cache (Cache&& rhs);
736 
737 
742  Cache& operator= (Cache&& rhs);
743 
744 
748  ~Cache();
749 
750 
755  void* cachePtr (SG::auxid_t auxid);
756 
757 
768 
769 
779  const void* getDataArray (SG::auxid_t auxid, const AuxVectorData& parent);
780 
781 
792  const AuxVectorData& parent);
793 
794 
811 
812 
818  const AuxVectorData& parent);
819 
820 
825  void swap (Cache& other);
826 
827 
831  void clear();
832 
833 
841  void clear (SG::auxid_t auxid);
842 
843 
849  void store (SG::auxid_t auxid, void* ptr);
850 
851 
855  void** m_cache[2];
856 
858  size_t m_cache_len;
859 
861  // See the thread-safety discussion in the file header above.
862  // Could be a vector of unique_ptr, but we want to avoid
863  // relying on c++11 for now.
864  std::vector<void**> m_allcache;
865 
866 
867  private:
868  Cache (const Cache&);
870  };
871 
872  friend class Cache;
873 
874 
878 
879  // Needed for access to getDataArray
880  friend class SG::AuxElement;
881 
882 
887  bool isAvailableOol (auxid_t id) const;
888 
889 
895 
896 
902 
903 
914  void* getDataOol (SG::auxid_t auxid, bool allowMissing);
915 
916 
927  const void* getDataOol (SG::auxid_t auxid, bool allowMissing) const;
928 
929 
944  void* getDecorationOol (SG::auxid_t auxid) const;
945 
946 
959  auxid, bool allowMissing) const /*__attribute__((const))*/;
960 
961 
963  mutable Cache m_cache ATLAS_THREAD_SAFE;
964 
966  mutable Cache m_constCache ATLAS_THREAD_SAFE;
967 
969  mutable Cache m_decorCache ATLAS_THREAD_SAFE;
970 
972  mutable Cache m_spanCache ATLAS_THREAD_SAFE;
973 
974 
977 
978 
981 
982 
985 
986 
989  typedef AthContainers_detail::lock_guard<mutex_t> guard_t;
990  mutable mutex_t m_mutex;
991 
994 };
995 
996 
997 } // namespace SG
998 
999 
1001 
1002 
1003 #endif // not ATHCONTAINERS_AUXVECTORDATA_H
SG::AuxVectorData::getStore
const SG::IAuxStore * getStore() const
Return the current store, as a non-const interface.
SG::AuxVectorData::setOption
bool setOption(const std::string &name, const std::string &optname, float arg)
SG::AuxVectorData::getConstStore
const SG::IConstAuxStore * getConstStore() const
Return the current store, as a const interface.
SG::AuxVectorData::isAvailableOol
bool isAvailableOol(auxid_t id) const
Out-of-line portion of isAvailable.
Definition: AuxVectorData.cxx:243
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:71
SG::AuxDataTraits::reference_type
element_type & reference_type
Reference types returned by aux data accessors.
Definition: AuxDataTraits.h:46
SG::AuxVectorData::setOption
bool setOption(auxid_t id, const std::string &optname, T arg)
Set an option for an auxiliary data variable.
SG::AuxVectorData::getDataArray
const void * getDataArray(SG::auxid_t auxid) const
Return a const pointer to the start of an aux data vector.
SG::AuxVectorData::lock
virtual void lock() override
Lock the container.
Definition: AuxVectorData.cxx:633
SG::AuxVectorData::Cache::getDataArray
const void * getDataArray(SG::auxid_t auxid, const AuxVectorData &parent)
Return a const pointer to the start of an aux data vector.
SG::AuxVectorData::getDataSpan
const AuxDataSpanBase * getDataSpan(SG::auxid_t auxid) const
Return a reference to a description of this vector's start+size.
SG::AuxVectorData::getDataOol
void * getDataOol(SG::auxid_t auxid, bool allowMissing)
Out-of-line portion of data access.
Definition: AuxVectorData.cxx:308
SG::AuxVectorData::m_constStoreLink
DataLink< SG::IConstAuxStore > m_constStoreLink
Associated store link, const.
Definition: AuxVectorData.h:984
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
SG::AuxVectorData::ATLAS_THREAD_SAFE
static size_t s_minCacheLen ATLAS_THREAD_SAFE
Minimum length to use for the cache vector.
Definition: AuxVectorData.h:593
SG::AuxVectorData::clearDecorCache
void clearDecorCache(SG::auxid_t auxid)
Clear the cached decoration pointer for a single variable.
SG::AuxVectorData::getDecorIDs
const SG::auxid_set_t & getDecorIDs() const
Return a set of identifiers for decorations for this object.
Definition: AuxVectorData.cxx:215
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
SG::AuxVectorData::guard_t
AthContainers_detail::lock_guard< mutex_t > guard_t
Definition: AuxVectorData.h:989
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
SG::AuxElement
Base class for elements of a container that can have aux data.
Definition: AuxElement.h:472
SG::AuxDataTraits::const_reference_type
const element_type & const_reference_type
Definition: AuxDataTraits.h:47
SG::AuxVectorData::getDecorationOol
void * getDecorationOol(SG::auxid_t auxid) const
Out-of-line portion of data access (decorator version).
Definition: AuxVectorData.cxx:397
SG::AuxVectorData::getDataSpanOol
const AuxDataSpanBase * getDataSpanOol(SG::auxid_t auxid, bool allowMissing) const
Return a reference to a description of this vector's start+size, out-of-line portion.
Definition: AuxVectorData.cxx:456
ILockable.h
Interface to allow an object to lock itself when made const in SG.
SG::AuxVectorData::Cache::m_cache
void ** m_cache[2]
Pointer to the cache vector.
Definition: AuxVectorData.h:855
SG::AuxVectorData::hasNonConstStore
bool hasNonConstStore() const
Return true if this object has an associated non-const store.
AuxDataSpan.h
Describe a range over an auxiliary variable, for low-overhead access.
SG::AuxVectorData::operator=
AuxVectorData & operator=(AuxVectorData &&rhs)
Move assignment.
Definition: AuxVectorData.cxx:66
SG::AuxVectorData::Cache::cachePtr
void * cachePtr(SG::auxid_t auxid)
Test to see if auxid is valid in the cache.
SG::AuxVectorData::Cache::m_allcache
std::vector< void ** > m_allcache
All cache vectors that have been allocated.
Definition: AuxVectorData.h:864
SG::AuxVectorData::Cache::getDataArray
void * getDataArray(SG::auxid_t auxid, AuxVectorData &parent)
Return a pointer to the start of an aux data vector.
SG::AuxVectorData::Cache::getDataSpan
const AuxDataSpanBase * getDataSpan(SG::auxid_t auxid, const AuxVectorData &parent)
Return a reference to a description of this vector's start+size.
SG::AuxVectorData::Cache
Manage cache of pointers to aux element vectors.
Definition: AuxVectorData.h:723
SG::AuxVectorData::getConstStoreOol
const SG::IConstAuxStore * getConstStoreOol() const
Same as getConstStore.
Definition: AuxVectorData.cxx:704
SG::AuxVectorData::Cache::Cache
Cache()
Cache manager constructor.
Definition: AuxVectorData.cxx:490
SG::AuxVectorData::lockDecoration
void lockDecoration(SG::auxid_t auxid)
Explicitly lock a decoration.
Definition: AuxVectorData.cxx:687
likely.h
Define likely/unlikely macros for branch prediction.
SG::AuxVectorData::swap
void swap(AuxVectorData &other)
Swap this instance with another.
SG::AuxVectorData::isAvailableWritableAsDecorationOol
bool isAvailableWritableAsDecorationOol(auxid_t id) const
Out-of-line portion of isAvailableWritableAsDecoration.
Definition: AuxVectorData.cxx:282
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
SG::AuxVectorData::isAvailableWritable
bool isAvailableWritable(auxid_t id)
Test to see if a variable is available for writing.
SG::AuxVectorData::ATLAS_THREAD_SAFE
Cache m_cache ATLAS_THREAD_SAFE
Cached pointers to the start of aux data vectors, non-const.
Definition: AuxVectorData.h:963
SG::AuxVectorData::getDecorationArray
void * getDecorationArray(SG::auxid_t auxid) const
Return a pointer to the start of an aux data vector for a decoration.
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
AuxDataOption.h
Hold information about an option setting request.
SG::AuxVectorData::isAvailable
bool isAvailable(auxid_t id) const
Test to see if a variable exists in the store.
SG::AuxVectorData::m_constStore
const SG::IConstAuxStore * m_constStore
Associated store, const.
Definition: AuxVectorData.h:980
SG::AuxVectorData::setStore
void setStore(SG::IAuxStore *store)
Set the store associated with this object.
Definition: AuxVectorData.cxx:116
SG::AuxVectorData::clearCache
void clearCache(SG::auxid_t auxid)
Clear the cached aux data pointers for a single variable.
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition: AuxTypes.h:27
SG::AuxVectorData::setNonConstStore
void setNonConstStore(SG::IAuxStore *store)
Set the store associated with this object.
SG::AuxVectorData::~AuxVectorData
virtual ~AuxVectorData()
Destructor.
Definition: AuxVectorData.cxx:88
SG::AuxVectorData::s_emptySet
static const SG::auxid_set_t s_emptySet
Empty auxid set, used for a return value when we have no associated store.
Definition: AuxVectorData.h:993
SG::AuxVectorData::Cache::m_cache_len
size_t m_cache_len
Length of the cache vector.
Definition: AuxVectorData.h:858
SG::AuxVectorData::mutex_t
AthContainers_detail::mutex mutex_t
Mutex used to synchronize modifications to the cache vector.
Definition: AuxVectorData.h:988
SG::AuxVectorData::getData
AuxDataTraits< T >::reference_type getData(SG::auxid_t auxid, size_t ndx)
Return reference to an aux data item.
SG::AuxVectorData::Cache::Cache
Cache(const Cache &)
SG::AuxVectorData::setCache
void setCache(SG::auxid_t auxid, void *ptr)
Explicitly set a cache pointer.
SG::AuxVectorData::m_mutex
mutex_t m_mutex
Definition: AuxVectorData.h:990
SG::AuxVectorData::Cache::operator=
Cache & operator=(Cache &&rhs)
Cache manager move assignment.
Definition: AuxVectorData.cxx:517
AuxVectorData.icc
SG::AuxVectorData::getStore
SG::IAuxStore * getStore()
Return the current store, as a non-const interface.
SG::AuxVectorData::getDecoration
AuxDataTraits< T >::reference_type getDecoration(SG::auxid_t auxid, size_t ndx) const
Return reference to an aux decoration item.
test_pyathena.parent
parent
Definition: test_pyathena.py:15
AuxDataTraits.h
Allow customizing how aux data types are treated.
SG::AuxVectorData::getDataArrayAllowMissing
const void * getDataArrayAllowMissing(SG::auxid_t auxid) const
Return a const pointer to the start of an aux data vector.
SG::AuxVectorData::hasStore
bool hasStore() const
Return true if this object has an associated store.
SG::AuxVectorData::AuxVectorData
AuxVectorData()
Constructor.
Definition: AuxVectorData.cxx:36
create_dcsc_inputs_sqlite.arg
list arg
Definition: create_dcsc_inputs_sqlite.py:48
SG::AuxVectorData::ATLAS_THREAD_SAFE
Cache m_constCache ATLAS_THREAD_SAFE
Cached pointers to the start of aux data vectors, const.
Definition: AuxVectorData.h:966
SG::AuxDataOption
Hold information about an option setting request.
Definition: AuxDataOption.h:37
assume.h
Macro to provide hints for optimization.
SG::AuxDataSpanBase
Minimal span-like object describing the range of an auxiliary variable.
Definition: AuxDataSpan.h:39
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
SG::AuxVectorData::Cache::getDecorationArray
void * getDecorationArray(SG::auxid_t auxid, const AuxVectorData &parent)
Return a pointer to the start of an aux decoration vector.
SG::AuxVectorData::clearCache
void clearCache()
Clear the cached aux data pointers.
SG::AuxVectorData::Cache::getDataArrayAllowMissing
const void * getDataArrayAllowMissing(SG::auxid_t auxid, const AuxVectorData &parent)
Return a const pointer to the start of an aux data vector.
SG::AuxVectorData::Cache::clear
void clear()
Clear the cache (and free any old cache vectors).
Definition: AuxVectorData.cxx:558
threading.h
Threading definitions.
SG::AuxVectorData::m_store
SG::IAuxStore * m_store
Associated store, non-const.
Definition: AuxVectorData.h:976
SG::AuxVectorData::ATLAS_THREAD_SAFE
Cache m_decorCache ATLAS_THREAD_SAFE
Cached pointers to the start of aux data vectors, decorations.
Definition: AuxVectorData.h:969
AuxTypes.h
Basic definitions for auxiliary types.
SG::IAuxStore
Interface for non-const operations on an auxiliary store.
Definition: IAuxStore.h:48
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
SG::AuxVectorData::clearDecorations
bool clearDecorations() const
Clear all decorations.
Definition: AuxVectorData.cxx:653
SG::AuxVectorData::ATLAS_THREAD_SAFE
Cache m_spanCache ATLAS_THREAD_SAFE
Cached pointers to span descriptors.
Definition: AuxVectorData.h:972
SG::AuxVectorData::Cache::swap
void swap(Cache &other)
Swap this cache object with another.
Definition: AuxVectorData.cxx:547
SG::AuxVectorData::getData
AuxDataTraits< T >::const_reference_type getData(SG::auxid_t auxid, size_t ndx) const
Return const reference to an aux data item.
SG::AuxVectorData::setOption
bool setOption(const std::string &name, const std::string &optname, int arg)
Set an option for an auxiliary data variable.
SG::AuxVectorData::Cache::~Cache
~Cache()
Cache manager destructor.
Definition: AuxVectorData.cxx:537
SG::AuxVectorData::Cache::store
void store(SG::auxid_t auxid, void *ptr)
Store a pointer for auxid in the cache.
Definition: AuxVectorData.cxx:592
SG::AuxVectorData::getDataArray
void * getDataArray(SG::auxid_t auxid)
Return a pointer to the start of an aux data vector.
SG::AuxVectorData::getConstStoreLink
const DataLink< SG::IConstAuxStore > getConstStoreLink() const
Return the data link to the current store, as a const interface.
ILockable
Interface to allow an object to lock itself when made const in SG.
Definition: ILockable.h:32
SG::AuxVectorData::isAvailableWritableOol
bool isAvailableWritableOol(auxid_t id)
Out-of-line portion of isAvailableWritable.
Definition: AuxVectorData.cxx:270
SG::auxid_set_t
A set of aux data identifiers.
Definition: AuxTypes.h:47
SG::AuxVectorData::isAvailableWritableAsDecoration
bool isAvailableWritableAsDecoration(auxid_t id) const
Test to see if a variable is available for writing as a decoration.
SG::AuxVectorData
Manage lookup of vectors of auxiliary data.
Definition: AuxVectorData.h:168
SG::AuxVectorData::setOption
bool setOption(const std::string &name, const std::string &clsname, const std::string &optname, T arg)
Set an option for an auxiliary data variable.
SG::AuxVectorData::AuxVectorData
AuxVectorData(const AuxVectorData &)
Copy not allowed.
IConstAuxStore.h
Interface for const operations on an auxiliary store.
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::AuxVectorData::setCache
void setCache(SG::auxid_t auxid, const void *ptr)
Explicitly set a cache pointer.
SG::AuxVectorData::capacity_v
virtual size_t capacity_v() const =0
Return the capacity of the container.
SG::AuxVectorData::size_v
virtual size_t size_v() const =0
Return the size of the container.
SG::AuxVectorData::setOption
bool setOption(auxid_t id, const AuxDataOption &option)
Set an option for an auxiliary data variable.
Definition: AuxVectorData.cxx:150
SG::AuxVectorData::setOption
bool setOption(const std::string &name, const std::string &optname, double arg)