ATLAS Offline Software
IdentifiableCacheBase.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 /*
4  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 #ifndef EVENTCONTAINERS_IDENTIFIABLECACHEBASE_H
8 #define EVENTCONTAINERS_IDENTIFIABLECACHEBASE_H
9 
10 
12 #include <memory>
13 #include <mutex>
14 #include <atomic>
16 
17 
18 namespace EventContainers {
19 
20 
21 
23 {
24 
25 public:
26 //here for access from other classes
27 static constexpr uintptr_t INVALIDflag = UINTPTR_MAX;
28 static constexpr uintptr_t ABORTEDflag = UINTPTR_MAX-1;
29 
30 
31 typedef std::true_type thread_safe;
32 
34 
35  struct IMaker
36  {
37  bool m_IsReEntrant = false;
38  virtual ~IMaker() {}
39  virtual void_unique_ptr typelessMake (IdentifierHash hash) const = 0; // unique_ptr<T>??
40  };
41 
43  const void* find (IdentifierHash hash) noexcept;
45  const void* findWait (IdentifierHash hash);
46 
48  const void* get (IdentifierHash hash);
49 
51  std::vector<IdentifierHash> ids();
52 
53  std::pair<bool, const void*> add (IdentifierHash hash, const void* p) noexcept;
54 
55  // addLock is same as method above except we check for invalid state first,
56  // more optimal for calling using writehandle lock method
57  std::pair<bool, const void*> addLock (IdentifierHash hash, const void* p) noexcept;
58  std::pair<bool, const void*> addLock (IdentifierHash hash, void_unique_ptr p) noexcept;
59  std::pair<bool, const void*> add (IdentifierHash hash, void_unique_ptr p) noexcept;
60 
61  bool IMakerPresent() const { return m_maker!=nullptr; }
62 
67  int tryLock(IdentifierHash, IDC_WriteHandleBase &, std::vector<IdentifierHash>&);
68 
71 
74 
76  const void* waitFor(IdentifierHash);
77 
79  void createSet (const std::vector<IdentifierHash>& hashes, std::vector<bool> &mask);
80 
81  size_t fullSize() const { return m_vec.size(); }
83  size_t numberOfHashes();
84 
85 protected:
86  IdentifiableCacheBase (IdentifierHash maxHash, const IMaker* maker);
88  void clear (deleter_f* deleter);
89  void cleanUp(deleter_f* deleter);//Call once before destruction
91 private:
92  std::vector<std::atomic<const void*> > m_vec;
93  friend class InternalOnline;
94  const IMaker* m_maker;
95 
97  typedef std::scoped_lock<mutex_t> lock_t;
98  typedef std::unique_lock<mutex_t> uniqueLock;
101  std::atomic<size_t> m_currentHashes;
102 };
103 
104 
105 } // namespace EventContainers
106 
107 
108 #endif // not EVENTCONTAINERS_IDENTIFIABLECACHEBASE_H
python.root_lsr_rank.hashes
hashes
Definition: root_lsr_rank.py:34
EventContainers::IdentifiableCacheBase::findWait
const void * findWait(IdentifierHash hash)
Retrieve ptr, will wait if there is something in progress.
Definition: IdentifiableCacheBase.cxx:123
EventContainers::InternalOnline
Definition: InternalOnline.h:26
EventContainers::IdentifiableCacheBase
Definition: IdentifiableCacheBase.h:23
EventContainers::IdentifiableCacheBase::get
const void * get(IdentifierHash hash)
Try to make payload if not there.
Definition: IdentifiableCacheBase.cxx:136
EventContainers::IdentifiableCacheBase::ABORTEDflag
static constexpr uintptr_t ABORTEDflag
Definition: IdentifiableCacheBase.h:28
EventContainers::IdentifiableCacheBase::IMaker::m_IsReEntrant
bool m_IsReEntrant
Definition: IdentifiableCacheBase.h:37
EventContainers::IdentifiableCacheBase::numberOfHashes
size_t numberOfHashes()
In a concurrent situation this number isn't necessarily perfectly synchronised with ids()....
Definition: IdentifiableCacheBase.cxx:185
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
EventContainers::IdentifiableCacheBase::m_mutex
mutex_t m_mutex
Definition: IdentifiableCacheBase.h:99
EventContainers::IdentifiableCacheBase::mutex_t
std::mutex mutex_t
Definition: IdentifiableCacheBase.h:96
EventContainers::IdentifiableCacheBase::m_maker
const IMaker * m_maker
Definition: IdentifiableCacheBase.h:94
EventContainers::IdentifiableCacheBase::lock_t
std::scoped_lock< mutex_t > lock_t
Definition: IdentifiableCacheBase.h:97
EventContainers
Definition: T_AthenaPoolCreateFuncs.h:33
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:459
EventContainers::IdentifiableCacheBase::~IdentifiableCacheBase
~IdentifiableCacheBase()
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
EventContainers::IdentifiableCacheBase::thread_safe
std::true_type thread_safe
Definition: IdentifiableCacheBase.h:31
deleter_f
void deleter_f(const void *p)
Definition: deleter.h:12
IDC_WriteHandleBase.h
EventContainers::IdentifiableCacheBase::IdentifiableCacheBase
IdentifiableCacheBase(IdentifierHash maxHash, const IMaker *maker)
Definition: IdentifiableCacheBase.cxx:28
EventContainers::IdentifiableCacheBase::tryLock
int tryLock(IdentifierHash, IDC_WriteHandleBase &, std::vector< IdentifierHash > &)
Checks if the item is completed if it is not started it extablishes lock (returns 0),...
Definition: IdentifiableCacheBase.cxx:39
EventContainers::IdentifiableCacheBase::fullSize
size_t fullSize() const
Definition: IdentifiableCacheBase.h:81
EventContainers::IdentifiableCacheBase::uniqueLock
std::unique_lock< mutex_t > uniqueLock
Definition: IdentifiableCacheBase.h:98
EventContainers::IdentifiableCacheBase::IMakerPresent
bool IMakerPresent() const
Definition: IdentifiableCacheBase.h:61
EventContainers::IdentifiableCacheBase::clear
void clear(deleter_f *deleter)
Definition: IdentifiableCacheBase.cxx:59
EventContainers::IdentifiableCacheBase::itemAborted
int itemAborted(IdentifierHash)
Returns 1 is the item has been aborted otherwise 0.
Definition: IdentifiableCacheBase.cxx:90
IdentifierHash.h
EventContainers::IdentifiableCacheBase::notifyHash
void notifyHash(IdentifierHash hash)
Definition: IdentifiableCacheBase.cxx:131
EventContainers::IdentifiableCacheBase::m_currentHashes
std::atomic< size_t > m_currentHashes
Holds the number of valid hashes in container, in concurrent use it is not guaranteed to be up to dat...
Definition: IdentifiableCacheBase.h:101
EventContainers::IdentifiableCacheBase::m_vec
std::vector< std::atomic< const void * > > m_vec
Definition: IdentifiableCacheBase.h:92
EventContainers::IdentifiableCacheBase::createSet
void createSet(const std::vector< IdentifierHash > &hashes, std::vector< bool > &mask)
Create a set of hashes, updates an IDC mask as appropriate.
Definition: IdentifiableCacheBase.cxx:176
void_unique_ptr
Definition: deleter.h:16
EventContainers::IdentifiableCacheBase::IMaker::typelessMake
virtual void_unique_ptr typelessMake(IdentifierHash hash) const =0
EventContainers::IdentifiableCacheBase::itemInProgress
int itemInProgress(IdentifierHash)
Returns 1 is the item is inprogress otherwise 0.
Definition: IdentifiableCacheBase.cxx:96
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:108
EventContainers::IdentifiableCacheBase::find
const void * find(IdentifierHash hash) noexcept
Return payload if there, null if not there.
Definition: IdentifiableCacheBase.cxx:102
EventContainers::IdentifiableCacheBase::waitFor
const void * waitFor(IdentifierHash)
Halts the thread until the require hash is completed or aborted.
Definition: IdentifiableCacheBase.cxx:111
EventContainers::IdentifiableCacheBase::add
std::pair< bool, const void * > add(IdentifierHash hash, const void *p) noexcept
Definition: IdentifiableCacheBase.cxx:204
EventContainers::IdentifiableCacheBase::ids
std::vector< IdentifierHash > ids()
In a threaded situation this collection will be valid but will not container hashes later added.
Definition: IdentifiableCacheBase.cxx:190
EventContainers::IDC_WriteHandleBase
Definition: IDC_WriteHandleBase.h:13
EventContainers::IdentifiableCacheBase::IMaker
Definition: IdentifiableCacheBase.h:36
deleter.h
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
EventContainers::IdentifiableCacheBase::IMaker::~IMaker
virtual ~IMaker()
Definition: IdentifiableCacheBase.h:38
EventContainers::IdentifiableCacheBase::INVALIDflag
static constexpr uintptr_t INVALIDflag
Definition: IdentifiableCacheBase.h:27
EventContainers::IdentifiableCacheBase::addLock
std::pair< bool, const void * > addLock(IdentifierHash hash, const void *p) noexcept
Definition: IdentifiableCacheBase.cxx:223
EventContainers::IdentifiableCacheBase::cleanUp
void cleanUp(deleter_f *deleter)
Definition: IdentifiableCacheBase.cxx:78