ATLAS Offline Software
Loading...
Searching...
No Matches
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-2025 CERN for the benefit of the ATLAS collaboration
4*/
11
12
13#ifndef ATHCONTAINERS_AUXVECTORDATA_H
14#define ATHCONTAINERS_AUXVECTORDATA_H
15
16
22#include "AthLinks/DataLink.h"
23#include "SGCore/ILockable.h"
24
25#include <vector>
26#include <utility>
27#include <cstdlib>
28
33
34
35namespace SG {
36
37
38class AuxElement;
39class IAuxStore;
40class AuxDataOption;
41
42
163class AuxVectorData : public ILockable
164{
165public:
168
169
175
176
182
183
185 virtual ~AuxVectorData();
186
187
193 virtual size_t size_v() const = 0;
194
195
201 virtual size_t capacity_v() const = 0;
202
203
204 //========================================================================
207
208
215 const SG::IConstAuxStore* getConstStore() const;
216
217
225
226
233
234
240 const SG::IAuxStore* getStore() const;
241
242
246 bool hasStore() const;
247
248
252 bool hasNonConstStore() const;
253
254
264 bool setOption (auxid_t id, const AuxDataOption& option);
265
266
276 bool setOption (const std::string& name,
277 const AuxDataOption& option);
278
279
290 bool setOption (const std::string& name,
291 const std::string& clsname,
292 const AuxDataOption& option);
293
294
305 template <class T>
306 bool setOption (auxid_t id, const std::string& optname, T arg);
307
308
319 bool setOption (const std::string& name,
320 const std::string& optname,
321 int arg);
322 bool setOption (const std::string& name,
323 const std::string& optname,
324 float arg);
325 bool setOption (const std::string& name,
326 const std::string& optname,
327 double arg);
328
329
341 template <class T>
342 bool setOption (const std::string& name,
343 const std::string& clsname,
344 const std::string& optname,
345 T arg);
346
347
348
349protected:
350 // These are protected. They shouldn't be called directly but
351 // instead from @c setStore methods in derived classes, which do
352 // extra consistency checking.
353
354
365 void setStore (SG::IAuxStore* store);
366
367
375 void setStore (const SG::IConstAuxStore* store);
376
377
385 void setStore (const DataLink< SG::IConstAuxStore >& store);
386
387
400
401
403 //========================================================================
406public:
407
408
417 const SG::auxid_set_t& getAuxIDs() const;
418
419
423 const SG::auxid_set_t& getDecorIDs() const;
424
425
434 SG::auxid_set_t getCopyIDs (bool warnUnlocked = false) const;
435
436
445 const SG::auxid_set_t& getWritableAuxIDs() const;
446
447
452 bool isAvailable (auxid_t id) const;
453
454
460
461
467
468
469 // Versions of isAvailable* that take a name rather than an ID are
470 // in the derived class AuxVectorBase.
471
472
485 template <class T>
487 getData (SG::auxid_t auxid, size_t ndx);
488
489
501 template <class T>
503 getData (SG::auxid_t auxid, size_t ndx) const;
504
505
525 template <class T>
527 getDecoration (SG::auxid_t auxid, size_t ndx) const;
528
529
538 const void* getDataArray (SG::auxid_t auxid) const;
539
540
550
551
567
568
578
579
595
596
597protected:
600 static size_t s_minCacheLen ATLAS_THREAD_SAFE;
601
602
604 //========================================================================
607public:
608
609
614 void swap (AuxVectorData& other);
615
616
624
625
634
635
644
645
652#ifndef XAOD_STANDALONE
653 virtual
654#endif // not XAOD_STANDALONE
655 void lock()
656#ifndef XAOD_STANDALONE
657 override
658#endif // not XAOD_STANDALONE
659 ;
660
661
671 bool clearDecorations() const;
672
673
683
684
690 const SG::IConstAuxStore* getConstStoreOol() const;
691
692
693protected:
703 void setCache (SG::auxid_t auxid, void* ptr);
704
705
715 void setCache (SG::auxid_t auxid, const void* ptr);
716
717
719
720
721
722public:
729 class Cache
730 {
731 public:
735 Cache();
736
737
742 Cache (Cache&& rhs);
743
744
749 Cache& operator= (Cache&& rhs);
750
751
755 ~Cache();
756
757
763
764
775
776
786 const void* getDataArray (SG::auxid_t auxid, const AuxVectorData& parent);
787
788
799 const AuxVectorData& parent);
800
801
818
819
825 const AuxVectorData& parent);
826
827
832 void swap (Cache& other);
833
834
838 void clear();
839
840
848 void clear (SG::auxid_t auxid);
849
850
856 void store (SG::auxid_t auxid, void* ptr);
857
858
862 void** m_cache[2];
863
866
868 // See the thread-safety discussion in the file header above.
869 // Could be a vector of unique_ptr, but we want to avoid
870 // relying on c++11 for now.
871 std::vector<void**> m_allcache;
872
873
874 private:
875 Cache (const Cache&);
877 };
878
879 friend class Cache;
880
881
882private:
886
887 // Needed for access to getDataArray
888 friend class SG::AuxElement;
889
890
895 bool isAvailableOol (auxid_t id) const;
896
897
903
904
910
911
922 void* getDataOol (SG::auxid_t auxid, bool allowMissing);
923
924
935 const void* getDataOol (SG::auxid_t auxid, bool allowMissing) const;
936
937
952 void* getDecorationOol (SG::auxid_t auxid) const;
953
954
967 auxid, bool allowMissing) const /*__attribute__((const))*/;
968
969
971 mutable Cache m_cache ATLAS_THREAD_SAFE;
972
974 mutable Cache m_constCache ATLAS_THREAD_SAFE;
975
977 mutable Cache m_decorCache ATLAS_THREAD_SAFE;
978
980 mutable Cache m_spanCache ATLAS_THREAD_SAFE;
981
982
985
986
988 const SG::IConstAuxStore* m_constStore;
989
990
993
994
996 typedef AthContainers_detail::mutex mutex_t;
997 typedef AthContainers_detail::lock_guard<mutex_t> guard_t;
999
1002};
1003
1004
1005} // namespace SG
1006
1007
1009
1010
1011#endif // not ATHCONTAINERS_AUXVECTORDATA_H
Hold information about an option setting request.
Describe a range over an auxiliary variable, for low-overhead access.
Allow customizing how aux data types are treated.
Basic definitions for auxiliary types.
Interface for const operations on an auxiliary store.
Macro to provide hints for optimization.
Define macros for attributes used to control the static checker.
Hold information about an option setting request.
element_type & reference_type
Reference types returned by aux data accessors.
const element_type & const_reference_type
Manage cache of pointers to aux element vectors.
void ** m_cache[2]
Pointer to the cache vector.
std::vector< void ** > m_allcache
All cache vectors that have been allocated.
void * getDecorationArray(SG::auxid_t auxid, const AuxVectorData &parent)
Return a pointer to the start of an aux decoration vector.
const void * getDataArrayAllowMissing(SG::auxid_t auxid, const AuxVectorData &parent)
Return a const pointer to the start of an aux data vector.
size_t m_cache_len
Length of the cache vector.
const AuxDataSpanBase * getDataSpan(SG::auxid_t auxid, const AuxVectorData &parent)
Return a reference to a description of this vector's start+size.
void swap(Cache &other)
Swap this cache object with another.
void * getDataArray(SG::auxid_t auxid, AuxVectorData &parent)
Return a pointer to the start of an aux data vector.
void * cachePtr(SG::auxid_t auxid)
Test to see if auxid is valid in the cache.
Cache()
Cache manager constructor.
const void * getDataArray(SG::auxid_t auxid, const AuxVectorData &parent)
Return a const pointer to the start of an aux data vector.
Cache & operator=(Cache &&rhs)
Cache manager move assignment.
void clear()
Clear the cache (and free any old cache vectors).
void store(SG::auxid_t auxid, void *ptr)
Store a pointer for auxid in the cache.
~Cache()
Cache manager destructor.
bool clearDecorations() const
Clear all decorations.
const SG::auxid_set_t & getAuxIDs() const
Return a set of identifiers for existing data items in store associated with this object.
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.
bool isAvailableOol(auxid_t id) const
Out-of-line portion of isAvailable.
const SG::IConstAuxStore * getConstStoreOol() const
Same as getConstStore.
SG::auxid_set_t getCopyIDs(bool warnUnlocked=false) const
Return the set of variables to copy in a deep copy.
static size_t s_minCacheLen ATLAS_THREAD_SAFE
Minimum length to use for the cache vector.
void setStore(SG::IAuxStore *store)
Set the store associated with this object.
const SG::auxid_set_t & getDecorIDs() const
Return a set of identifiers for decorations for this object.
bool hasNonConstStore() const
Return true if this object has an associated non-const store.
DataLink< SG::IConstAuxStore > m_constStoreLink
Associated store link, const.
void * getDataOol(SG::auxid_t auxid, bool allowMissing)
Out-of-line portion of data access.
void * getDecorationArray(SG::auxid_t auxid) const
Return a pointer to the start of an aux data vector for a decoration.
AuxDataTraits< T >::const_reference_type getData(SG::auxid_t auxid, size_t ndx) const
Return const reference to an aux data item.
void setCache(SG::auxid_t auxid, const void *ptr)
Explicitly set a cache pointer.
bool setOption(auxid_t id, const std::string &optname, T arg)
Set an option for an auxiliary data variable.
void lockDecoration(SG::auxid_t auxid)
Explicitly lock a decoration.
const SG::IAuxStore * getStore() const
Return the current store, as a non-const interface.
AuxVectorData & operator=(AuxVectorData &&rhs)
Move assignment.
bool isAvailableWritableAsDecoration(auxid_t id) const
Test to see if a variable is available for writing as a decoration.
bool setOption(const std::string &name, const std::string &clsname, const std::string &optname, T arg)
Set an option for an auxiliary data variable.
bool setOption(const std::string &name, const std::string &optname, int arg)
Set an option for an auxiliary data variable.
SG::IAuxStore * m_store
Associated store, non-const.
void clearDecorCache(SG::auxid_t auxid)
Clear the cached decoration pointer for a single variable.
void clearCache()
Clear the cached aux data pointers.
AuxDataTraits< T >::reference_type getDecoration(SG::auxid_t auxid, size_t ndx) const
Return reference to an aux decoration item.
void * getDecorationOol(SG::auxid_t auxid) const
Out-of-line portion of data access (decorator version).
bool isAvailable(auxid_t id) const
Test to see if a variable exists in the store.
virtual size_t size_v() const =0
Return the size of the container.
static const SG::auxid_set_t s_emptySet
Empty auxid set, used for a return value when we have no associated store.
AuxDataTraits< T >::reference_type getData(SG::auxid_t auxid, size_t ndx)
Return reference to an aux data item.
bool setOption(const std::string &name, const std::string &optname, double arg)
void * getDataArray(SG::auxid_t auxid)
Return a pointer to the start of an aux data vector.
virtual size_t capacity_v() const =0
Return the capacity of the container.
AuxVectorData(const AuxVectorData &)
Copy not allowed.
AthContainers_detail::mutex mutex_t
Mutex used to synchronize modifications to the cache vector.
const DataLink< SG::IConstAuxStore > getConstStoreLink() const
Return the data link to the current store, as a const interface.
AthContainers_detail::lock_guard< mutex_t > guard_t
const AuxDataSpanBase * getDataSpan(SG::auxid_t auxid) const
Return a reference to a description of this vector's start+size.
const SG::IConstAuxStore * m_constStore
Associated store, const.
bool isAvailableWritableOol(auxid_t id)
Out-of-line portion of isAvailableWritable.
void setNonConstStore(SG::IAuxStore *store)
Set the store associated with this object.
AuxVectorData()
Constructor.
const void * getDataArray(SG::auxid_t auxid) const
Return a const pointer to the start of an aux data vector.
bool isAvailableWritableAsDecorationOol(auxid_t id) const
Out-of-line portion of isAvailableWritableAsDecoration.
const void * getDataArrayAllowMissing(SG::auxid_t auxid) const
Return a const pointer to the start of an aux data vector.
SG::IAuxStore * getStore()
Return the current store, as a non-const interface.
virtual ~AuxVectorData()
Destructor.
void setCache(SG::auxid_t auxid, void *ptr)
Explicitly set a cache pointer.
bool setOption(auxid_t id, const AuxDataOption &option)
Set an option for an auxiliary data variable.
const SG::auxid_set_t & getWritableAuxIDs() const
Return a set of identifiers for writable data items in this store.
bool setOption(const std::string &name, const std::string &optname, float arg)
void swap(AuxVectorData &other)
Swap this instance with another.
const SG::IConstAuxStore * getConstStore() const
Return the current store, as a const interface.
virtual void lock() override
Lock the container.
bool isAvailableWritable(auxid_t id)
Test to see if a variable is available for writing.
void clearCache(SG::auxid_t auxid)
Clear the cached aux data pointers for a single variable.
bool hasStore() const
Return true if this object has an associated store.
Interface for non-const operations on an auxiliary store.
Definition IAuxStore.h:51
A set of aux data identifiers.
Definition AuxTypes.h:47
Define likely/unlikely macros for branch prediction.
Forward declaration.
AuxElement(SG::AuxVectorData *container, size_t index)
Base class for elements of a container that can have aux data.
SG::auxid_t auxid() const
Return the aux id for this variable.
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
Minimal span-like object describing the range of an auxiliary variable.
Definition AuxDataSpan.h:40
Threading definitions.