ATLAS Offline Software
Loading...
Searching...
No Matches
EventContainers::InternalOfflineMap Class Referencefinal

#include <InternalOfflineMap.h>

Inheritance diagram for EventContainers::InternalOfflineMap:
Collaboration diagram for EventContainers::InternalOfflineMap:

Public Types

typedef EventContainers::hashPair< void > hashPair
typedef std::vector< hashPair >::const_iterator InternalConstItr
typedef void deleter_f(const void *p)

Public Member Functions

 InternalOfflineMap (size_t max)
virtual ~InternalOfflineMap ()=default
virtual InternalConstItr cbegin () const override
virtual InternalConstItr cend () const override
virtual InternalConstItr indexFind (IdentifierHash hashId) const override
virtual const std::vector< hashPair > & getAllHashPtrPair () const override
virtual bool tryAddFromCache (IdentifierHash hashId, EventContainers::IDC_WriteHandleBase &lock) override
virtual bool tryAddFromCache (IdentifierHash hashId) override
virtual void wait () const override
virtual std::vector< IdentifierHashgetAllCurrentHashes () const override
virtual size_t numberOfCollections () const override
virtual void cleanUp (deleter_f *deleter) noexcept override
virtual size_t fullSize () const noexcept override
virtual StatusCode fetchOrCreate (IdentifierHash hashId) override
virtual StatusCode fetchOrCreate (const std::vector< IdentifierHash > &hashIds) override
virtual bool insert (IdentifierHash hashId, const void *ptr) override
virtual const void * findIndexPtr (IdentifierHash hashId) const noexcept override
virtual StatusCode addLock (IdentifierHash hashId, const void *ptr) override
virtual void * removeCollection (IdentifierHash hashId) override
virtual void destructor (deleter_f *) noexcept override

Private Attributes

std::vector< I_InternalIDC::hashPair > m_map ATLAS_THREAD_SAFE
std::unordered_map< IdentifierHash::value_type, const void * > m_fullMap
std::mutex m_waitMutex ATLAS_THREAD_SAFE
std::atomic< bool > m_needsupdate ATLAS_THREAD_SAFE
const size_t m_maxsize

Detailed Description

Definition at line 20 of file InternalOfflineMap.h.

Member Typedef Documentation

◆ deleter_f

typedef void EventContainers::I_InternalIDC::deleter_f(const void *p)
inherited

Definition at line 14 of file I_InternalIDC.h.

◆ hashPair

Definition at line 37 of file I_InternalIDC.h.

◆ InternalConstItr

Definition at line 38 of file I_InternalIDC.h.

Constructor & Destructor Documentation

◆ InternalOfflineMap()

InternalOfflineMap::InternalOfflineMap ( size_t max)

Definition at line 11 of file InternalOfflineMap.cxx.

11: m_needsupdate(false), m_maxsize(max) {}
#define max(a, b)
Definition cfImp.cxx:41

◆ ~InternalOfflineMap()

virtual EventContainers::InternalOfflineMap::~InternalOfflineMap ( )
virtualdefault

Member Function Documentation

◆ addLock()

StatusCode InternalOfflineMap::addLock ( IdentifierHash hashId,
const void * ptr )
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 100 of file InternalOfflineMap.cxx.

100 {
101 bool added = insert(hashId, ptr);
102 if (!added) [[unlikely]] {
103 throw std::runtime_error("IDC WARNING Deletion shouldn't occur in addLock paradigm");
104 }
105 return StatusCode::SUCCESS;
106}
virtual bool insert(IdentifierHash hashId, const void *ptr) override
#define unlikely(x)

◆ cbegin()

InternalConstItr InternalOfflineMap::cbegin ( ) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 63 of file InternalOfflineMap.cxx.

63 {
64 if(m_needsupdate.load(std::memory_order_acquire)) wait();
65 return m_map.cbegin();
66}
virtual void wait() const override
IndexMap m_map
Map from objects to indices.

◆ cend()

InternalConstItr InternalOfflineMap::cend ( ) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 52 of file InternalOfflineMap.cxx.

52 {
53 if(m_needsupdate.load(std::memory_order_acquire)) wait();
54 return m_map.cend();
55}

◆ cleanUp()

void InternalOfflineMap::cleanUp ( deleter_f * deleter)
overridevirtualnoexcept

Implements EventContainers::I_InternalIDC.

Definition at line 79 of file InternalOfflineMap.cxx.

79 {
80 destructor(deleter);
81 m_map.clear();
82 m_fullMap.clear();
83 m_needsupdate.store(false, std::memory_order_release);
84}
std::unordered_map< IdentifierHash::value_type, const void * > m_fullMap
virtual void destructor(deleter_f *) noexcept override

◆ destructor()

void InternalOfflineMap::destructor ( deleter_f * deleter)
overridevirtualnoexcept

Implements EventContainers::I_InternalIDC.

Definition at line 125 of file InternalOfflineMap.cxx.

125 {
126 if(!m_needsupdate.load(std::memory_order_acquire)) for(const auto& x : m_map) deleter(x.second);
127 else {
128 for(const auto &pair : m_fullMap) { deleter(pair.second); }
129 }
130}
#define x
IPayloadDeleter & deleter()
Return a reference to the payload deleter object.

◆ fetchOrCreate() [1/2]

StatusCode InternalOfflineMap::fetchOrCreate ( const std::vector< IdentifierHash > & hashIds)
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 120 of file InternalOfflineMap.cxx.

121{
122 throw std::runtime_error("Not implemented in offline mode");
123}

◆ fetchOrCreate() [2/2]

StatusCode InternalOfflineMap::fetchOrCreate ( IdentifierHash hashId)
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 117 of file InternalOfflineMap.cxx.

117 {
118 throw std::runtime_error("Not implemented in offline mode");
119}

◆ findIndexPtr()

const void * InternalOfflineMap::findIndexPtr ( IdentifierHash hashId) const
overridevirtualnoexcept

Implements EventContainers::I_InternalIDC.

Definition at line 94 of file InternalOfflineMap.cxx.

94 {
95 auto search = m_fullMap.find(hashId);
96 if(search!=m_fullMap.cend()) return search->second;
97 return nullptr;
98}
void search(TDirectory *td, const std::string &s, std::string cwd, node *n)
recursive directory search for TH1 and TH2 and TProfiles
Definition hcg.cxx:743

◆ fullSize()

virtual size_t EventContainers::InternalOfflineMap::fullSize ( ) const
inlineoverridevirtualnoexcept

Implements EventContainers::I_InternalIDC.

Definition at line 34 of file InternalOfflineMap.h.

34{return m_maxsize;}

◆ getAllCurrentHashes()

std::vector< IdentifierHash > InternalOfflineMap::getAllCurrentHashes ( ) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 35 of file InternalOfflineMap.cxx.

35 {
36 std::vector<IdentifierHash> ids;
37 ids.reserve(m_fullMap.size());
38 if(m_needsupdate.load(std::memory_order_acquire) == true){
39 for(const auto &pair : m_fullMap){
40 ids.emplace_back(pair.first);
41 }
42 std::sort(ids.begin(), ids.end());
43 }else{
44 for(const auto &pair : m_map){
45 ids.emplace_back(pair.first);
46 }
47 }
48 return ids;
49}
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.

◆ getAllHashPtrPair()

const std::vector< I_InternalIDC::hashPair > & InternalOfflineMap::getAllHashPtrPair ( ) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 57 of file InternalOfflineMap.cxx.

57 {
58 if(m_needsupdate.load(std::memory_order_acquire)) wait();
59 return m_map;
60}

◆ indexFind()

InternalConstItr InternalOfflineMap::indexFind ( IdentifierHash hashId) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 68 of file InternalOfflineMap.cxx.

68 {
69 if(m_needsupdate.load(std::memory_order_acquire)) wait();
70 auto itr = std::lower_bound( m_map.cbegin(), m_map.cend(), hashId.value(), [](const hashPair &lhs, IdentifierHash::value_type rhs) -> bool { return lhs.first < rhs; } );
71 if(itr!= m_map.cend() && itr->first==hashId) return itr;
72 return m_map.cend();
73}
EventContainers::hashPair< void > hashPair
constexpr value_type value() const
unsigned int value_type

◆ insert()

bool InternalOfflineMap::insert ( IdentifierHash hashId,
const void * ptr )
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 86 of file InternalOfflineMap.cxx.

86 {
87 auto &mapptr = m_fullMap[hashId];
88 if(mapptr!=nullptr) return false; //already present
89 mapptr = ptr;
90 m_needsupdate.store(true, std::memory_order_relaxed);
91 return true;
92}
void * ptr(T *p)
Definition SGImplSvc.cxx:74

◆ numberOfCollections()

size_t InternalOfflineMap::numberOfCollections ( ) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 75 of file InternalOfflineMap.cxx.

75 {
76 return m_fullMap.size();
77}

◆ removeCollection()

void * InternalOfflineMap::removeCollection ( IdentifierHash hashId)
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 108 of file InternalOfflineMap.cxx.

108 {
109 auto search = m_fullMap.find(hashId);
110 if(search==m_fullMap.cend()) return nullptr;
111 void* ptr = const_cast< void* > (search->second);
112 m_fullMap.erase(search);
113 m_needsupdate.store(true, std::memory_order_relaxed);
114 return ptr;
115}

◆ tryAddFromCache() [1/2]

bool InternalOfflineMap::tryAddFromCache ( IdentifierHash hashId)
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 18 of file InternalOfflineMap.cxx.

19{
20 return m_fullMap.count(hash);
21}

◆ tryAddFromCache() [2/2]

bool InternalOfflineMap::tryAddFromCache ( IdentifierHash hashId,
EventContainers::IDC_WriteHandleBase & lock )
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 14 of file InternalOfflineMap.cxx.

14 {
15 return m_fullMap.count(hash);
16}

◆ wait()

void InternalOfflineMap::wait ( ) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 23 of file InternalOfflineMap.cxx.

23 {
24 std::scoped_lock lock (m_waitMutex);
25 if(m_needsupdate.load(std::memory_order_acquire) == false) return;
26 m_map.clear();
27 m_map.reserve(m_fullMap.size());
28 for(const auto &pair : m_fullMap){
29 m_map.emplace_back(pair.first, pair.second);
30 }
31 std::sort(m_map.begin(), m_map.end());
32 m_needsupdate.store(false, std::memory_order_release);
33}
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.

Member Data Documentation

◆ ATLAS_THREAD_SAFE [1/3]

std::atomic<bool> m_needsupdate EventContainers::InternalOfflineMap::ATLAS_THREAD_SAFE
mutableprivate

Definition at line 46 of file InternalOfflineMap.h.

◆ ATLAS_THREAD_SAFE [2/3]

std::mutex m_waitMutex EventContainers::InternalOfflineMap::ATLAS_THREAD_SAFE
mutableprivate

Definition at line 45 of file InternalOfflineMap.h.

◆ ATLAS_THREAD_SAFE [3/3]

std::vector<I_InternalIDC::hashPair> m_map EventContainers::InternalOfflineMap::ATLAS_THREAD_SAFE
mutableprivate

Definition at line 43 of file InternalOfflineMap.h.

◆ m_fullMap

std::unordered_map<IdentifierHash::value_type, const void*> EventContainers::InternalOfflineMap::m_fullMap
private

Definition at line 44 of file InternalOfflineMap.h.

◆ m_maxsize

const size_t EventContainers::InternalOfflineMap::m_maxsize
private

Definition at line 47 of file InternalOfflineMap.h.


The documentation for this class was generated from the following files: