ATLAS Offline Software
InternalOfflineMap.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef EVENTCONTAINERS_InternalOfflineMap_H
6 #define EVENTCONTAINERS_InternalOfflineMap_H
9 #include <atomic>
10 #include <mutex>
11 #include <unordered_map>
12 
13 namespace EventContainers{
14 /*
15 This class implements the IdentifiableContainer code for the offline case.
16 This class balances speed against memory usage by using an unordered_map
17 
18 Moderately fast random access, fast iteration, moderate memory usage.
19 */
20 class InternalOfflineMap final : public I_InternalIDC {
21 public:
22  InternalOfflineMap(size_t max);
23  virtual ~InternalOfflineMap()=default;
24  virtual InternalConstItr cbegin() const override;
25  virtual InternalConstItr cend() const override;
26  virtual InternalConstItr indexFind( IdentifierHash hashId ) const override;
27  virtual const std::vector < hashPair >& getAllHashPtrPair() const override;
28  virtual bool tryAddFromCache(IdentifierHash hashId, EventContainers::IDC_WriteHandleBase &lock) override;
29  virtual bool tryAddFromCache(IdentifierHash hashId) override;
30  virtual void wait() const override;
31  virtual std::vector<IdentifierHash> getAllCurrentHashes() const override;
32  virtual size_t numberOfCollections() const override;
33  virtual void cleanUp(deleter_f* deleter) noexcept override;
34  virtual size_t fullSize() const noexcept override {return m_maxsize;}
35  virtual StatusCode fetchOrCreate(IdentifierHash hashId) override;
36  virtual StatusCode fetchOrCreate(const std::vector<IdentifierHash> &hashIds) override;
37  virtual bool insert(IdentifierHash hashId, const void* ptr) override;
38  virtual const void* findIndexPtr(IdentifierHash hashId) const noexcept override;
39  virtual StatusCode addLock(IdentifierHash hashId, const void* ptr) override;
40  virtual void* removeCollection( IdentifierHash hashId ) override;
41  virtual void destructor(deleter_f*) noexcept override;
42 private:
43  mutable std::vector<I_InternalIDC::hashPair> m_map ATLAS_THREAD_SAFE;
44  std::unordered_map<IdentifierHash::value_type, const void*> m_fullMap;
45  mutable std::mutex m_waitMutex ATLAS_THREAD_SAFE;
46  mutable std::atomic<bool> m_needsupdate ATLAS_THREAD_SAFE; //These mutables are carefully thought out, do not change
47  const size_t m_maxsize;
48 };
49 
50 }
51 #endif
EventContainers::InternalOfflineMap::cend
virtual InternalConstItr cend() const override
Definition: InternalOfflineMap.cxx:53
EventContainers::InternalOfflineMap::wait
virtual void wait() const override
Definition: InternalOfflineMap.cxx:24
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
EventContainers::InternalOfflineMap::removeCollection
virtual void * removeCollection(IdentifierHash hashId) override
Definition: InternalOfflineMap.cxx:109
EventContainers::InternalOfflineMap::InternalOfflineMap
InternalOfflineMap(size_t max)
Definition: InternalOfflineMap.cxx:12
EventContainers::InternalOfflineMap::ATLAS_THREAD_SAFE
std::atomic< bool > m_needsupdate ATLAS_THREAD_SAFE
Definition: InternalOfflineMap.h:46
EventContainers::InternalOfflineMap::tryAddFromCache
virtual bool tryAddFromCache(IdentifierHash hashId, EventContainers::IDC_WriteHandleBase &lock) override
Definition: InternalOfflineMap.cxx:15
EventContainers
Definition: T_AthenaPoolCreateFuncs.h:33
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
EventContainers::InternalOfflineMap::fullSize
virtual size_t fullSize() const noexcept override
Definition: InternalOfflineMap.h:34
EventContainers::I_InternalIDC
Definition: I_InternalIDC.h:34
EventContainers::InternalOfflineMap::insert
virtual bool insert(IdentifierHash hashId, const void *ptr) override
Definition: InternalOfflineMap.cxx:87
EventContainers::InternalOfflineMap::m_fullMap
std::unordered_map< IdentifierHash::value_type, const void * > m_fullMap
Definition: InternalOfflineMap.h:44
EventContainers::InternalOfflineMap::ATLAS_THREAD_SAFE
std::mutex m_waitMutex ATLAS_THREAD_SAFE
Definition: InternalOfflineMap.h:45
EventContainers::InternalOfflineMap::numberOfCollections
virtual size_t numberOfCollections() const override
Definition: InternalOfflineMap.cxx:76
EventContainers::InternalOfflineMap::~InternalOfflineMap
virtual ~InternalOfflineMap()=default
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
EventContainers::InternalOfflineMap
Definition: InternalOfflineMap.h:20
deleter_f
void deleter_f(const void *p)
Definition: deleter.h:12
EventContainers::InternalOfflineMap::getAllHashPtrPair
virtual const std::vector< hashPair > & getAllHashPtrPair() const override
Definition: InternalOfflineMap.cxx:58
EventContainers::InternalOfflineMap::destructor
virtual void destructor(deleter_f *) noexcept override
Definition: InternalOfflineMap.cxx:126
EventContainers::InternalOfflineMap::fetchOrCreate
virtual StatusCode fetchOrCreate(IdentifierHash hashId) override
Definition: InternalOfflineMap.cxx:118
EventContainers::InternalOfflineMap::m_maxsize
const size_t m_maxsize
Definition: InternalOfflineMap.h:47
EventContainers::InternalOfflineMap::addLock
virtual StatusCode addLock(IdentifierHash hashId, const void *ptr) override
Definition: InternalOfflineMap.cxx:101
EventContainers::InternalOfflineMap::cbegin
virtual InternalConstItr cbegin() const override
Definition: InternalOfflineMap.cxx:64
EventContainers::IDC_WriteHandleBase
Definition: IDC_WriteHandleBase.h:13
EventContainers::InternalOfflineMap::ATLAS_THREAD_SAFE
std::vector< I_InternalIDC::hashPair > m_map ATLAS_THREAD_SAFE
Definition: InternalOfflineMap.h:43
I_InternalIDC.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
checker_macros.h
Define macros for attributes used to control the static checker.
EventContainers::InternalOfflineMap::getAllCurrentHashes
virtual std::vector< IdentifierHash > getAllCurrentHashes() const override
Definition: InternalOfflineMap.cxx:36
EventContainers::InternalOfflineMap::indexFind
virtual InternalConstItr indexFind(IdentifierHash hashId) const override
Definition: InternalOfflineMap.cxx:69
EventContainers::I_InternalIDC::InternalConstItr
std::vector< hashPair >::const_iterator InternalConstItr
Definition: I_InternalIDC.h:37
EventContainers::InternalOfflineMap::findIndexPtr
virtual const void * findIndexPtr(IdentifierHash hashId) const noexcept override
Definition: InternalOfflineMap.cxx:95
EventContainers::InternalOfflineMap::cleanUp
virtual void cleanUp(deleter_f *deleter) noexcept override
Definition: InternalOfflineMap.cxx:80