ATLAS Offline Software
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 
10 using namespace EventContainers;
12 InternalOfflineMap::InternalOfflineMap(size_t max) : m_needsupdate(false), m_maxsize(max) {}
13 
14 
16  return m_fullMap.count(hash);
17 }
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 
36 std::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 
58 const 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 
69 InternalConstItr InternalOfflineMap::indexFind( IdentifierHash hashId ) const{
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 
80 void 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 
87 bool 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 
95 const 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 
101 StatusCode 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 
109 void* InternalOfflineMap::removeCollection( IdentifierHash hashId ) {
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 }
121 StatusCode InternalOfflineMap::fetchOrCreate(const std::vector<IdentifierHash>&)
122 {
123  throw std::runtime_error("Not implemented in offline mode");
124 }
125 
126 void InternalOfflineMap::destructor(deleter_f* deleter) noexcept {
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 }
EventContainers::InternalOfflineMap::cend
virtual InternalConstItr cend() const override
Definition: InternalOfflineMap.cxx:53
InternalOfflineMap.h
EventContainers::InternalOfflineMap::wait
virtual void wait() const override
Definition: InternalOfflineMap.cxx:24
max
#define max(a, b)
Definition: cfImp.cxx:41
InternalConstItr
I_InternalIDC::InternalConstItr InternalConstItr
Definition: InternalOffline.cxx:11
EventContainers::InternalOfflineMap::removeCollection
virtual void * removeCollection(IdentifierHash hashId) override
Definition: InternalOfflineMap.cxx:109
EventContainers::InternalOfflineMap::InternalOfflineMap
InternalOfflineMap(size_t max)
Definition: InternalOfflineMap.cxx:12
IdentifierHash::value_type
unsigned int value_type
Definition: IdentifierHash.h:27
EventContainers::InternalOfflineMap::tryAddFromCache
virtual bool tryAddFromCache(IdentifierHash hashId, EventContainers::IDC_WriteHandleBase &lock) override
Definition: InternalOfflineMap.cxx:15
ATH_UNLIKELY
#define ATH_UNLIKELY(x)
Definition: AthUnlikelyMacros.h:17
EventContainers
Definition: T_AthenaPoolCreateFuncs.h:33
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
EventContainers::hashPair
Definition: I_InternalIDC.h:25
x
#define x
search
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:738
EventContainers::InternalOfflineMap::insert
virtual bool insert(IdentifierHash hashId, const void *ptr) override
Definition: InternalOfflineMap.cxx:87
AthUnlikelyMacros.h
EventContainers::InternalOfflineMap::m_fullMap
std::unordered_map< IdentifierHash::value_type, const void * > m_fullMap
Definition: InternalOfflineMap.h:44
EventContainers::InternalOfflineMap::numberOfCollections
virtual size_t numberOfCollections() const override
Definition: InternalOfflineMap.cxx:76
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
deleter_f
void deleter_f(const void *p)
Definition: deleter.h:12
EventContainers::InternalOfflineMap::getAllHashPtrPair
virtual const std::vector< hashPair > & getAllHashPtrPair() const override
Definition: InternalOfflineMap.cxx:58
IDC_WriteHandleBase.h
EventContainers::InternalOfflineMap::destructor
virtual void destructor(deleter_f *) noexcept override
Definition: InternalOfflineMap.cxx:126
EventContainers::InternalOfflineMap::fetchOrCreate
virtual StatusCode fetchOrCreate(IdentifierHash hashId) override
Definition: InternalOfflineMap.cxx:118
EventContainers::InternalOfflineMap::addLock
virtual StatusCode addLock(IdentifierHash hashId, const void *ptr) override
Definition: InternalOfflineMap.cxx:101
python.subdetectors.mmg.ids
ids
Definition: mmg.py:8
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
EventContainers::InternalOfflineMap::cbegin
virtual InternalConstItr cbegin() const override
Definition: InternalOfflineMap.cxx:64
EventContainers::IDC_WriteHandleBase
Definition: IDC_WriteHandleBase.h:27
EventContainers::InternalOfflineMap::getAllCurrentHashes
virtual std::vector< IdentifierHash > getAllCurrentHashes() const override
Definition: InternalOfflineMap.cxx:36
EventContainers::InternalOfflineMap::indexFind
virtual InternalConstItr indexFind(IdentifierHash hashId) const override
Definition: InternalOfflineMap.cxx:69
EventContainers::I_InternalIDC::InternalConstItr
std::vector< hashPair >::const_iterator InternalConstItr
Definition: I_InternalIDC.h:37
EventContainers::InternalOfflineMap::findIndexPtr
virtual const void * findIndexPtr(IdentifierHash hashId) const noexcept override
Definition: InternalOfflineMap.cxx:95
InternalConstItr
I_InternalIDC::InternalConstItr InternalConstItr
Definition: InternalOfflineMap.cxx:11
EventContainers::InternalOfflineMap::cleanUp
virtual void cleanUp(deleter_f *deleter) noexcept override
Definition: InternalOfflineMap.cxx:80