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