ATLAS Offline Software
Loading...
Searching...
No Matches
InternalOfflineMap.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;
12InternalOfflineMap::InternalOfflineMap(size_t max) : m_needsupdate(false), m_maxsize(max) {}
13
14
18
20{
21 return m_fullMap.count(hash);
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 m_map.reserve(m_fullMap.size());
29 for(const auto &pair : m_fullMap){
30 m_map.emplace_back(pair.first, pair.second);
31 }
32 std::sort(m_map.begin(), m_map.end());
33 m_needsupdate.store(false, std::memory_order_release);
34}
35
36std::vector<IdentifierHash> InternalOfflineMap::getAllCurrentHashes() const {
37 std::vector<IdentifierHash> ids;
38 ids.reserve(m_fullMap.size());
39 if(m_needsupdate.load(std::memory_order_acquire) == true){
40 for(const auto &pair : m_fullMap){
41 ids.emplace_back(pair.first);
42 }
43 std::sort(ids.begin(), ids.end());
44 }else{
45 for(const auto &pair : m_map){
46 ids.emplace_back(pair.first);
47 }
48 }
49 return ids;
50}
51
54 if(m_needsupdate.load(std::memory_order_acquire)) wait();
55 return m_map.cend();
56}
57
58const std::vector < I_InternalIDC::hashPair >& InternalOfflineMap::getAllHashPtrPair() const{
59 if(m_needsupdate.load(std::memory_order_acquire)) wait();
60 return m_map;
61}
62
65 if(m_needsupdate.load(std::memory_order_acquire)) wait();
66 return m_map.cbegin();
67}
68
70 if(m_needsupdate.load(std::memory_order_acquire)) wait();
71 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; } );
72 if(itr!= m_map.cend() && itr->first==hashId) return itr;
73 return m_map.cend();
74}
75
77 return m_fullMap.size();
78}
79
80void InternalOfflineMap::cleanUp(deleter_f* deleter) noexcept {
81 destructor(deleter);
82 m_map.clear();
83 m_fullMap.clear();
84 m_needsupdate.store(false, std::memory_order_release);
85}
86
87bool InternalOfflineMap::insert(IdentifierHash hashId, const void* ptr) {
88 auto &mapptr = m_fullMap[hashId];
89 if(mapptr!=nullptr) return false; //already present
90 mapptr = ptr;
91 m_needsupdate.store(true, std::memory_order_relaxed);
92 return true;
93}
94
95const void* InternalOfflineMap::findIndexPtr(IdentifierHash hashId) const noexcept{
96 auto search = m_fullMap.find(hashId);
97 if(search!=m_fullMap.cend()) return search->second;
98 return nullptr;
99}
100
101StatusCode InternalOfflineMap::addLock(IdentifierHash hashId, const void* ptr) {
102 bool added = insert(hashId, ptr);
103 if(ATH_UNLIKELY(!added)) {
104 throw std::runtime_error("IDC WARNING Deletion shouldn't occur in addLock paradigm");
105 }
106 return StatusCode::SUCCESS;
107}
108
110 auto search = m_fullMap.find(hashId);
111 if(search==m_fullMap.cend()) return nullptr;
112 void* ptr = const_cast< void* > (search->second);
113 m_fullMap.erase(search);
114 m_needsupdate.store(true, std::memory_order_relaxed);
115 return ptr;
116}
117
119 throw std::runtime_error("Not implemented in offline mode");
120}
121StatusCode InternalOfflineMap::fetchOrCreate(const std::vector<IdentifierHash>&)
122{
123 throw std::runtime_error("Not implemented in offline mode");
124}
125
127 if(!m_needsupdate.load(std::memory_order_acquire)) for(const auto& x : m_map) deleter(x.second);
128 else {
129 for(const auto &pair : m_fullMap) { deleter(pair.second); }
130 }
131}
#define ATH_UNLIKELY(x)
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.
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:739
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.