ATLAS Offline Software
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 
10 using namespace EventContainers;
12 InternalOfflineFast::InternalOfflineFast(size_t max) : m_fullMap(max, nullptr), m_needsupdate(false) {}
13 
14 
16  return m_fullMap[hash] != nullptr;
17 }
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 
35 std::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 
51 const 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 
62 InternalConstItr InternalOfflineFast::indexFind( IdentifierHash hashId ) const{
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 
74 void 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 
87 bool 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 
94 const void* InternalOfflineFast::findIndexPtr(IdentifierHash hashId) const noexcept{
95  if(hashId >= m_fullMap.size()) return nullptr;
96  return m_fullMap[hashId];
97 }
98 
99 StatusCode 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 
107 void* InternalOfflineFast::removeCollection( IdentifierHash hashId ) {
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 }
117 StatusCode 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 }
EventContainers::InternalOfflineFast::m_fullMap
std::vector< const void * > m_fullMap
Definition: InternalOfflineFast.h:43
EventContainers::InternalOfflineFast::removeCollection
virtual void * removeCollection(IdentifierHash hashId) override
Definition: InternalOfflineFast.cxx:107
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
InternalConstItr
I_InternalIDC::InternalConstItr InternalConstItr
Definition: InternalOffline.cxx:11
EventContainers::InternalOfflineFast::cleanUp
virtual void cleanUp(deleter_f *deleter) noexcept override
Definition: InternalOfflineFast.cxx:74
InternalConstItr
I_InternalIDC::InternalConstItr InternalConstItr
Definition: InternalOfflineFast.cxx:11
InternalOfflineFast.h
EventContainers::InternalOfflineFast::indexFind
virtual InternalConstItr indexFind(IdentifierHash hashId) const override
Definition: InternalOfflineFast.cxx:62
EventContainers::InternalOfflineFast::addLock
virtual StatusCode addLock(IdentifierHash hashId, const void *ptr) override
Definition: InternalOfflineFast.cxx:99
IdentifierHash::value_type
unsigned int value_type
Definition: IdentifierHash.h:27
EventContainers
Definition: T_AthenaPoolCreateFuncs.h:33
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
EventContainers::InternalOfflineFast::wait
virtual void wait() const override
Definition: InternalOfflineFast.cxx:24
EventContainers::hashPair
Definition: I_InternalIDC.h:25
x
#define x
EventContainers::InternalOfflineFast::destructor
virtual void destructor(deleter_f *) noexcept override
Definition: InternalOfflineFast.cxx:122
EventContainers::InternalOfflineFast::cbegin
virtual InternalConstItr cbegin() const override
Definition: InternalOfflineFast.cxx:57
AthUnlikelyMacros.h
EventContainers::InternalOfflineFast::tryAddFromCache
virtual bool tryAddFromCache(IdentifierHash hashId, EventContainers::IDC_WriteHandleBase &lock) override
Definition: InternalOfflineFast.cxx:15
EventContainers::InternalOfflineFast::getAllCurrentHashes
virtual std::vector< IdentifierHash > getAllCurrentHashes() const override
Definition: InternalOfflineFast.cxx:35
EventContainers::InternalOfflineFast::cend
virtual InternalConstItr cend() const override
Definition: InternalOfflineFast.cxx:46
lumiFormat.i
int i
Definition: lumiFormat.py:85
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
IDC_WriteHandleBase.h
EventContainers::InternalOfflineFast::InternalOfflineFast
InternalOfflineFast(size_t max)
Definition: InternalOfflineFast.cxx:12
EventContainers::InternalOfflineFast::getAllHashPtrPair
virtual const std::vector< hashPair > & getAllHashPtrPair() const override
Definition: InternalOfflineFast.cxx:51
python.subdetectors.mmg.ids
ids
Definition: mmg.py:8
EventContainers::InternalOfflineFast::fetchOrCreate
virtual StatusCode fetchOrCreate(IdentifierHash hashId) override
Definition: InternalOfflineFast.cxx:114
EventContainers::InternalOfflineFast::insert
virtual bool insert(IdentifierHash hashId, const void *ptr) override
Definition: InternalOfflineFast.cxx:87
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
EventContainers::IDC_WriteHandleBase
Definition: IDC_WriteHandleBase.h:13
EventContainers::InternalOfflineFast::ATLAS_THREAD_SAFE
std::vector< I_InternalIDC::hashPair > m_map ATLAS_THREAD_SAFE
Definition: InternalOfflineFast.h:42
EventContainers::InternalOfflineFast::findIndexPtr
virtual const void * findIndexPtr(IdentifierHash hashId) const noexcept override
Definition: InternalOfflineFast.cxx:94
EventContainers::InternalOfflineFast::numberOfCollections
virtual size_t numberOfCollections() const override
Definition: InternalOfflineFast.cxx:69
EventContainers::I_InternalIDC::InternalConstItr
std::vector< hashPair >::const_iterator InternalConstItr
Definition: I_InternalIDC.h:37