ATLAS Offline Software
Loading...
Searching...
No Matches
InternalOfflineFast.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include <algorithm>
9
10using namespace EventContainers;
12InternalOfflineFast::InternalOfflineFast(size_t max) : m_fullMap(max, nullptr), m_needsupdate(false) {}
13
14
18
20{
21 return m_fullMap[hash] != nullptr;
22}
23
25 std::scoped_lock lock (m_waitMutex);
26 if(m_needsupdate.load(std::memory_order_acquire) == false) return;
27 m_map.clear();
28 for(size_t i=0 ;i < m_fullMap.size(); ++i){
29 if(m_fullMap[i]) m_map.emplace_back(i, m_fullMap[i]);
30 }
31 m_map.shrink_to_fit();
32 m_needsupdate.store(false, std::memory_order_release);
33}
34
35std::vector<IdentifierHash> InternalOfflineFast::getAllCurrentHashes() const {
36 if(m_needsupdate.load(std::memory_order_acquire)) wait();
37 std::vector<IdentifierHash> ids;
38 ids.reserve(m_map.size());
39 for(auto &x : m_map) {
40 ids.emplace_back(x.first);
41 }
42 return ids;
43}
44
47 if(m_needsupdate.load(std::memory_order_acquire)) wait();
48 return m_map.cend();
49}
50
51const std::vector < I_InternalIDC::hashPair >& InternalOfflineFast::getAllHashPtrPair() const{
52 if(m_needsupdate.load(std::memory_order_acquire)) wait();
53 return m_map;
54}
55
58 if(m_needsupdate.load(std::memory_order_acquire)) wait();
59 return m_map.cbegin();
60}
61
63 if(m_needsupdate.load(std::memory_order_acquire)) wait();
64 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; } );
65 if(itr!= m_map.cend() && itr->first==hashId) return itr;
66 return m_map.cend();
67}
68
70 if(m_needsupdate.load(std::memory_order_acquire)) wait();
71 return m_map.size();
72}
73
74void InternalOfflineFast::cleanUp(deleter_f* deleter) noexcept {
75 if(!m_needsupdate.load(std::memory_order_acquire)) {
76 for(const auto& x : m_map) { deleter(x.second); m_fullMap[x.first] = nullptr; }
77 if(!m_map.empty()) m_needsupdate.store(true, std::memory_order_relaxed);
78 }
79 else {
80 for(size_t i=0 ;i < m_fullMap.size(); ++i){
81 if(m_fullMap[i]) { deleter(m_fullMap[i]); m_fullMap[i] = nullptr; }
82 }
83 }
84 m_map.clear();
85}
86
87bool InternalOfflineFast::insert(IdentifierHash hashId, const void* ptr) {
88 if(m_fullMap[hashId]!= nullptr) return false; //already in
89 m_fullMap[hashId] = ptr;
90 m_needsupdate.store(true, std::memory_order_relaxed);
91 return true;
92}
93
94const void* InternalOfflineFast::findIndexPtr(IdentifierHash hashId) const noexcept{
95 if(hashId >= m_fullMap.size()) return nullptr;
96 return m_fullMap[hashId];
97}
98
99StatusCode InternalOfflineFast::addLock(IdentifierHash hashId, const void* ptr) {
100 bool added = insert(hashId, ptr);
101 if(!added) {
102 throw std::runtime_error("IDC WARNING Deletion shouldn't occur in addLock paradigm");
103 }
104 return StatusCode::SUCCESS;
105}
106
108 void* ptr ATLAS_THREAD_SAFE = const_cast< void* > (m_fullMap[hashId]);
109 m_fullMap[hashId] = nullptr;
110 m_needsupdate.store(true, std::memory_order_relaxed);
111 return ptr;
112}
113
115 throw std::runtime_error("Not implemented in offline mode");
116}
117StatusCode InternalOfflineFast::fetchOrCreate(const std::vector<IdentifierHash>&)
118{
119 throw std::runtime_error("Not implemented in offline mode");
120}
121
123 if(!m_needsupdate.load(std::memory_order_acquire)) for(const auto& x : m_map) deleter(x.second);
124 else {
125 for(size_t i=0 ;i < m_fullMap.size(); ++i){
126 if(m_fullMap[i]) deleter(m_fullMap[i]);
127 }
128 }
129}
I_InternalIDC::InternalConstItr InternalConstItr
#define x
#define max(a, b)
Definition cfImp.cxx:41
std::vector< hashPair >::const_iterator InternalConstItr
EventContainers::hashPair< void > hashPair
void deleter_f(const void *p)
virtual bool insert(IdentifierHash hashId, const void *ptr) override
virtual InternalConstItr cend() const override
virtual const std::vector< hashPair > & getAllHashPtrPair() const override
virtual const void * findIndexPtr(IdentifierHash hashId) const noexcept override
virtual std::vector< IdentifierHash > getAllCurrentHashes() const override
virtual StatusCode fetchOrCreate(IdentifierHash hashId) override
virtual bool tryAddFromCache(IdentifierHash hashId, EventContainers::IDC_WriteHandleBase &lock) override
virtual InternalConstItr cbegin() const override
virtual InternalConstItr indexFind(IdentifierHash hashId) const override
std::vector< const void * > m_fullMap
virtual void * removeCollection(IdentifierHash hashId) override
virtual void destructor(deleter_f *) noexcept override
virtual size_t numberOfCollections() const override
virtual void cleanUp(deleter_f *deleter) noexcept override
std::vector< I_InternalIDC::hashPair > m_map ATLAS_THREAD_SAFE
virtual StatusCode addLock(IdentifierHash hashId, const void *ptr) override
This is a "hash" representation of an Identifier.
value_type value() const
unsigned int value_type