ATLAS Offline Software
Loading...
Searching...
No Matches
InternalOfflineMap.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;
11InternalOfflineMap::InternalOfflineMap(size_t max) : m_needsupdate(false), m_maxsize(max) {}
12
13
17
19{
20 return m_fullMap.count(hash);
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 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}
34
35std::vector<IdentifierHash> InternalOfflineMap::getAllCurrentHashes() const {
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}
50
53 if(m_needsupdate.load(std::memory_order_acquire)) wait();
54 return m_map.cend();
55}
56
57const std::vector < I_InternalIDC::hashPair >& InternalOfflineMap::getAllHashPtrPair() const{
58 if(m_needsupdate.load(std::memory_order_acquire)) wait();
59 return m_map;
60}
61
64 if(m_needsupdate.load(std::memory_order_acquire)) wait();
65 return m_map.cbegin();
66}
67
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}
74
76 return m_fullMap.size();
77}
78
79void InternalOfflineMap::cleanUp(deleter_f* deleter) noexcept {
80 destructor(deleter);
81 m_map.clear();
82 m_fullMap.clear();
83 m_needsupdate.store(false, std::memory_order_release);
84}
85
86bool InternalOfflineMap::insert(IdentifierHash hashId, const void* ptr) {
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}
93
94const void* InternalOfflineMap::findIndexPtr(IdentifierHash hashId) const noexcept{
95 auto search = m_fullMap.find(hashId);
96 if(search!=m_fullMap.cend()) return search->second;
97 return nullptr;
98}
99
100StatusCode InternalOfflineMap::addLock(IdentifierHash hashId, const void* ptr) {
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}
107
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}
116
118 throw std::runtime_error("Not implemented in offline mode");
119}
120StatusCode InternalOfflineMap::fetchOrCreate(const std::vector<IdentifierHash>&)
121{
122 throw std::runtime_error("Not implemented in offline mode");
123}
124
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}
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 InternalConstItr indexFind(IdentifierHash hashId) const override
virtual InternalConstItr cend() const override
virtual size_t numberOfCollections() const override
virtual void wait() const override
virtual void cleanUp(deleter_f *deleter) noexcept override
virtual void * removeCollection(IdentifierHash hashId) override
virtual bool tryAddFromCache(IdentifierHash hashId, EventContainers::IDC_WriteHandleBase &lock) override
std::unordered_map< IdentifierHash::value_type, const void * > m_fullMap
virtual std::vector< IdentifierHash > getAllCurrentHashes() const override
virtual const void * findIndexPtr(IdentifierHash hashId) const noexcept override
virtual void destructor(deleter_f *) noexcept override
virtual const std::vector< hashPair > & getAllHashPtrPair() const override
virtual InternalConstItr cbegin() const override
virtual bool insert(IdentifierHash hashId, const void *ptr) override
virtual StatusCode fetchOrCreate(IdentifierHash hashId) override
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
STL class.
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
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
#define unlikely(x)