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 
21 #include "AthLinks/DataLink.h"
22 #ifndef XAOD_STANDALONE
23 # include "AthenaKernel/ILockable.h"
24 #endif // not XAOD_STANDALONE
25 #include <vector>
26 #include <utility>
27 #include <cstdlib>
28 
33 
34 
35 namespace SG {
36 
37 
38 class AuxElement;
39 class IAuxStore;
40 class AuxDataOption;
41 
42 
164 #ifndef XAOD_STANDALONE
165  : public ILockable
166 #endif // not XAOD_STANDALONE
167 {
168 public:
170  AuxVectorData();
171 
172 
178 
179 
185 
186 
188  virtual ~AuxVectorData();
189 
190 
196  virtual size_t size_v() const = 0;
197 
198 
204  virtual size_t capacity_v() const = 0;
205 
206 
207  //========================================================================
210 
211 
219 
220 
228 
229 
236 
237 
243  const SG::IAuxStore* getStore() const;
244 
245 
249  bool hasStore() const;
250 
251 
255  bool hasNonConstStore() const;
256 
257 
267  bool setOption (auxid_t id, const AuxDataOption& option);
268 
269 
279  bool setOption (const std::string& name,
280  const AuxDataOption& option);
281 
282 
293  bool setOption (const std::string& name,
294  const std::string& clsname,
295  const AuxDataOption& option);
296 
297 
308  template <class T>
309  bool setOption (auxid_t id, const std::string& optname, T arg);
310 
311 
322  bool setOption (const std::string& name,
323  const std::string& optname,
324  int arg);
325  bool setOption (const std::string& name,
326  const std::string& optname,
327  float arg);
328  bool setOption (const std::string& name,
329  const std::string& optname,
330  double arg);
331 
332 
344  template <class T>
345  bool setOption (const std::string& name,
346  const std::string& clsname,
347  const std::string& optname,
348  T arg);
349 
350 
351 
352 protected:
353  // These are protected. They shouldn't be called directly but
354  // instead from @c setStore methods in derived classes, which do
355  // extra consistency checking.
356 
357 
368  void setStore (SG::IAuxStore* store);
369 
370 
378  void setStore (const SG::IConstAuxStore* store);
379 
380 
389 
390 
403 
404 
406  //========================================================================
409 public:
410 
411 
420  const SG::auxid_set_t& getAuxIDs() const;
421 
422 
431  const SG::auxid_set_t& getWritableAuxIDs() const;
432 
433 
438  bool isAvailable (auxid_t id) const;
439 
440 
446 
447 
453 
454 
455  // Versions of isAvailable* that take a name rather than an ID are
456  // in the derived class AuxVectorBase.
457 
458 
471  template <class T>
473  getData (SG::auxid_t auxid, size_t ndx);
474 
475 
487  template <class T>
489  getData (SG::auxid_t auxid, size_t ndx) const;
490 
491 
511  template <class T>
513  getDecoration (SG::auxid_t auxid, size_t ndx) const;
514 
515 
524  const void* getDataArray (SG::auxid_t auxid) const;
525 
526 
535  const void* getDataArrayAllowMissing (SG::auxid_t auxid) const;
536 
537 
552  void* getDecorationArray (SG::auxid_t auxid) const;
553 
554 
563  void* getDataArray (SG::auxid_t auxid);
564 
565 
566 
567 
568 protected:
571  static size_t s_minCacheLen ATLAS_THREAD_SAFE;
572 
573 
575  //========================================================================
578 public:
579 
580 
586 
587 
594  void clearCache();
595 
596 
604  void clearDecorCache (SG::auxid_t auxid);
605 
606 
613 #ifndef XAOD_STANDALONE
614  virtual
615 #endif // not XAOD_STANDALONE
616  void lock()
617 #ifndef XAOD_STANDALONE
618  override
619 #endif // not XAOD_STANDALONE
620  ;
621 
622 
632  bool clearDecorations() const;
633 
634 
635 protected:
645  void setCache (SG::auxid_t auxid, void* ptr);
646 
647 
657  void setCache (SG::auxid_t auxid, const void* ptr);
658 
659 
661 
662 
663 
664 private:
671  class Cache
672  {
673  public:
677  Cache();
678 
679 
684  Cache (Cache&& rhs);
685 
686 
691  Cache& operator= (Cache&& rhs);
692 
693 
697  ~Cache();
698 
699 
704  void* cachePtr (SG::auxid_t auxid);
705 
706 
717 
718 
728  const void* getDataArray (SG::auxid_t auxid, const AuxVectorData& parent);
729 
730 
741  const AuxVectorData& parent);
742 
743 
760 
761 
766  void swap (Cache& other);
767 
768 
772  void clear();
773 
774 
782  void clear (SG::auxid_t auxid);
783 
784 
790  void store (SG::auxid_t auxid, void* ptr);
791 
792 
796  void** m_cache[2];
797 
799  size_t m_cache_len;
800 
802  // See the thread-safety discussion in the file header above.
803  // Could be a vector of unique_ptr, but we want to avoid
804  // relying on c++11 for now.
805  std::vector<void**> m_allcache;
806 
807 
808  private:
809  Cache (const Cache&);
811  };
812 
813  friend class Cache;
814 
815 
819 
820  // Needed for access to getDataArray
821  friend class SG::AuxElement;
822 
823 
828  bool isAvailableOol (auxid_t id) const;
829 
830 
836 
837 
843 
844 
855  void* getDataOol (SG::auxid_t auxid, bool allowMissing);
856 
857 
868  const void* getDataOol (SG::auxid_t auxid, bool allowMissing) const;
869 
870 
885  void* getDecorationOol (SG::auxid_t auxid) const;
886 
887 
889  mutable Cache m_cache ATLAS_THREAD_SAFE;
890 
892  mutable Cache m_constCache ATLAS_THREAD_SAFE;
893 
895  mutable Cache m_decorCache ATLAS_THREAD_SAFE;
896 
897 
900 
901 
904 
905 
908 
909 
912  typedef AthContainers_detail::lock_guard<mutex_t> guard_t;
913  mutable mutex_t m_mutex;
914 
917 };
918 
919 
920 } // namespace SG
921 
922 
924 
925 
926 #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:229
store
StoreGateSvc * store
Definition: fbtTestBasics.cxx:69
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:573
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::getDataOol
void * getDataOol(SG::auxid_t auxid, bool allowMissing)
Out-of-line portion of data access.
Definition: AuxVectorData.cxx:294
SG::AuxVectorData::m_constStoreLink
DataLink< SG::IConstAuxStore > m_constStoreLink
Associated store link, const.
Definition: AuxVectorData.h:907
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:571
SG::AuxVectorData::clearDecorCache
void clearDecorCache(SG::auxid_t auxid)
Clear the cached decoration pointer for a single variable.
Definition: AuxVectorData.cxx:560
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:217
SG::AuxVectorData::guard_t
AthContainers_detail::lock_guard< mutex_t > guard_t
Definition: AuxVectorData.h:912
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:446
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:376
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:796
SG::AuxVectorData::hasNonConstStore
bool hasNonConstStore() const
Return true if this object has an associated non-const store.
SG::AuxVectorData::operator=
AuxVectorData & operator=(AuxVectorData &&rhs)
Move assignment.
Definition: AuxVectorData.cxx:65
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:805
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
Manage cache of pointers to aux element vectors.
Definition: AuxVectorData.h:672
SG::AuxVectorData::Cache::Cache
Cache()
Cache manager constructor.
Definition: AuxVectorData.cxx:416
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:268
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:889
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:201
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:903
SG::AuxVectorData::setStore
void setStore(SG::IAuxStore *store)
Set the store associated with this object.
Definition: AuxVectorData.cxx:114
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:86
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:916
SG::AuxVectorData::Cache::m_cache_len
size_t m_cache_len
Length of the cache vector.
Definition: AuxVectorData.h:799
SG::AuxVectorData::mutex_t
AthContainers_detail::mutex mutex_t
Mutex used to synchronize modifications to the cache vector.
Definition: AuxVectorData.h:911
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:913
SG::AuxVectorData::Cache::operator=
Cache & operator=(Cache &&rhs)
Cache manager move assignment.
Definition: AuxVectorData.cxx:443
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:892
SG::AuxDataOption
Hold information about an option setting request.
Definition: AuxDataOption.h:37
assume.h
Macro to provide hints for optimization.
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
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:484
threading.h
Threading definitions.
SG::AuxVectorData::m_store
SG::IAuxStore * m_store
Associated store, non-const.
Definition: AuxVectorData.h:899
SG::AuxVectorData::ATLAS_THREAD_SAFE
Cache m_decorCache ATLAS_THREAD_SAFE
Cached pointers to the start of aux data vectors, decorations.
Definition: AuxVectorData.h:895
AuxTypes.h
Basic definitions for auxiliary types.
SG::IAuxStore
Interface for non-const operations on an auxiliary store.
Definition: IAuxStore.h:51
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
SG::AuxVectorData::clearDecorations
bool clearDecorations() const
Clear all decorations.
Definition: AuxVectorData.cxx:593
SG::AuxVectorData::Cache::swap
void swap(Cache &other)
Swap this cache object with another.
Definition: AuxVectorData.cxx:473
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:463
SG::AuxVectorData::Cache::store
void store(SG::auxid_t auxid, void *ptr)
Store a pointer for auxid in the cache.
Definition: AuxVectorData.cxx:518
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:256
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:167
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:148
SG::AuxVectorData::setOption
bool setOption(const std::string &name, const std::string &optname, double arg)