ATLAS Offline Software
InternalOnline.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include <algorithm>
11 
12 using namespace EventContainers;
14 
15 
17  m_mask(cache->fullSize(), false), m_waitNeeded(false) {}
18 
19 const std::vector < I_InternalIDC::hashPair >& InternalOnline::getAllHashPtrPair() const{
20  if(m_waitNeeded.load(std::memory_order_acquire)) wait();
21  return m_map;
22 }
23 
24 
27  if(m_waitNeeded.load(std::memory_order_acquire)) wait();
28  return m_map.cend();
29 }
30 
33  if(m_waitNeeded.load(std::memory_order_acquire)) wait();
34  return m_map.cbegin();
35 }
36 
37 InternalConstItr InternalOnline::indexFind( IdentifierHash hashId ) const{
38  if(m_waitNeeded.load(std::memory_order_acquire)) wait();
39  auto itr = std::lower_bound( m_map.begin(), m_map.end(), hashId.value(), [](hashPair &lhs, IdentifierHash::value_type rhs) -> bool { return lhs.first < rhs; } );
40  if(itr!= m_map.end() && itr->first==hashId) return itr;
41  return m_map.end();
42 }
43 
44 void InternalOnline::wait() const {
45  //lockguard to protect m_waitlist from multiple wait calls
46  std::scoped_lock lock (m_waitMutex);
47  if(m_waitNeeded.load(std::memory_order_acquire) == false) return;
48  using namespace EventContainers;
49  const void* ABORTstate = reinterpret_cast<const void*>(IdentifiableCacheBase::ABORTEDflag);
50  while(!m_waitlist.empty()) {
51  IdentifierHash hash = m_waitlist.back();
53  const void* ptr = cacheLink->waitFor(hash);
54  if(ptr == ABORTstate) {
55  m_mask[hash] = false;
56  }
57  m_waitlist.pop_back();
58  }
59  m_map.clear();
60  for(size_t i =0;i<m_mask.size();i++){
61  if(m_mask[i]) m_map.emplace_back(i, m_cacheLink->m_vec[i].load(std::memory_order_relaxed));//acquire sync is done by m_waitNeeded
62  }
63  m_waitNeeded.store(false, std::memory_order_release);
64 }
65 
67  int flag = m_cacheLink->tryLock(hashId, lock, m_waitlist);
68  //Relaxed since this should not be running in threaded situation.
69  if(!m_waitlist.empty()) m_waitNeeded.store(true, std::memory_order_relaxed);
70  if(flag > 0) {
71  if(flag!=3){
72  m_mask[hashId] = true;
73  m_waitNeeded.store(true, std::memory_order_relaxed);
74  }
75  return true;
76  }
77  return false;
78 }
79 
80 bool InternalOnline::tryAddFromCache(IdentifierHash hashId)
81 {
82  auto ptr = m_cacheLink->find(hashId);
83  if(ptr==nullptr) {
84  return false;
85  }
86  m_mask[hashId] = true;
87  m_waitNeeded.store(true, std::memory_order_relaxed);
88  return true;
89 }
90 
91 std::vector<IdentifierHash> InternalOnline::getAllCurrentHashes() const {
92  if(m_waitNeeded.load(std::memory_order_acquire)) wait();
93  std::vector<IdentifierHash> ids;
94  ids.reserve(m_map.size());
95  for(auto &x : m_map) {
96  ids.emplace_back(x.first);
97  }
98  return ids;
99 }
100 
102  if(m_waitNeeded.load(std::memory_order_acquire)) wait();
103  return m_map.size();
104 }
105 
107  if(m_waitNeeded.load(std::memory_order_relaxed)) wait();
108  m_mask.assign(m_cacheLink->fullSize(), false);
109  m_map.clear();
110  m_waitNeeded.store(true, std::memory_order_relaxed);
111 }
112 
114  if(ATH_UNLIKELY(!m_cacheLink->IMakerPresent())) return StatusCode::FAILURE;
115  auto ptr = m_cacheLink->get(hashId);
116  if(ptr) { m_mask[hashId] =true; m_waitNeeded.store(true, std::memory_order_relaxed); }
117  return StatusCode::SUCCESS;
118 }
119 
120 StatusCode InternalOnline::fetchOrCreate(const std::vector<IdentifierHash> &/*hashIds*/) {
121  throw std::runtime_error("Not implemented");
122 // if(ATH_UNLIKELY(!m_cacheLink->IMakerPresent())) return StatusCode::FAILURE;
123 // m_cacheLink->createSet(hashIds, m_mask);
124 // return StatusCode::SUCCESS;
125 }
126 
127 
128 bool InternalOnline::insert(IdentifierHash hashId, const void* ptr) {
129  std::pair<bool, const void*> cacheinserted = m_cacheLink->add(hashId, ptr);
130  m_mask[hashId] = true; //it wasn't added it is already present therefore mask could be true
131  m_waitNeeded.store(true, std::memory_order_relaxed);
132  return ptr == cacheinserted.second;
133 }
134 
135 const void* InternalOnline::findIndexPtr(IdentifierHash hashId) const noexcept {
136  if(hashId < m_mask.size() and m_mask[hashId]) {
138  return cacheLink->findWait(hashId);
139  }
140  return nullptr;
141 }
142 
143 StatusCode InternalOnline::addLock(IdentifierHash hashId, const void* ptr) {
144  std::pair<bool, const void*> added = m_cacheLink->addLock(hashId, ptr);
145  if(ATH_UNLIKELY(!added.first)) {
146  throw std::runtime_error("IDC WARNING Deletion shouldn't occur in addLock paradigm");
147  }
148  m_mask[hashId] = true; //it wasn't added it is already present therefore mask could be true
149  m_waitNeeded.store(true, std::memory_order_relaxed);
150  return StatusCode::SUCCESS;
151 }
152 
153 void* InternalOnline::removeCollection( IdentifierHash ) {
154  throw std::runtime_error("Do not remove things from an online IDC");
155 }
156 
158  //deliberately empty
159 }
160 
162  resetMask();
163 }
IdentifiableCacheBase.h
InternalOnline.h
EventContainers::IdentifiableCacheBase::findWait
const void * findWait(IdentifierHash hash)
Retrieve ptr, will wait if there is something in progress.
Definition: IdentifiableCacheBase.cxx:158
EventContainers::IdentifiableCacheBase
Definition: IdentifiableCacheBase.h:26
EventContainers::IdentifiableCacheBase::get
const void * get(IdentifierHash hash)
Try to make payload if not there.
Definition: IdentifiableCacheBase.cxx:179
EventContainers::IdentifiableCacheBase::ABORTEDflag
static constexpr uintptr_t ABORTEDflag
Definition: IdentifiableCacheBase.h:31
InternalConstItr
I_InternalIDC::InternalConstItr InternalConstItr
Definition: InternalOffline.cxx:11
EventContainers::InternalOnline::findIndexPtr
virtual const void * findIndexPtr(IdentifierHash hashId) const noexcept override
Definition: InternalOnline.cxx:135
IdentifierHash::value_type
unsigned int value_type
Definition: IdentifierHash.h:27
ATH_UNLIKELY
#define ATH_UNLIKELY(x)
Definition: AthUnlikelyMacros.h:17
EventContainers::InternalOnline::cend
virtual InternalConstItr cend() const override
Definition: InternalOnline.cxx:26
EventContainers::InternalOnline::wait
virtual void wait() const override
Definition: InternalOnline.cxx:44
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
EventContainers::InternalOnline::cleanUp
virtual void cleanUp(deleter_f *) noexcept override
Definition: InternalOnline.cxx:161
AthUnlikelyMacros.h
InternalConstItr
I_InternalIDC::InternalConstItr InternalConstItr
Definition: InternalOnline.cxx:13
EventContainers::InternalOnline::getAllHashPtrPair
virtual const std::vector< hashPair > & getAllHashPtrPair() const override
Definition: InternalOnline.cxx:19
lumiFormat.i
int i
Definition: lumiFormat.py:85
EventContainers::InternalOnline::destructor
virtual void destructor(deleter_f *) noexcept override
Definition: InternalOnline.cxx:157
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
EventContainers::InternalOnline::resetMask
void resetMask()
Definition: InternalOnline.cxx:106
master.flag
bool flag
Definition: master.py:29
deleter_f
void deleter_f(const void *p)
Definition: deleter.h:12
EventContainers::InternalOnline::cbegin
virtual InternalConstItr cbegin() const override
Definition: InternalOnline.cxx:32
IDC_WriteHandleBase.h
EventContainers::IdentifiableCacheBase::tryLock
int tryLock(IdentifierHash, IDC_WriteHandleBase &, std::vector< IdentifierHash > &)
Checks if the item is completed if it is not started it extablishes lock (returns 0),...
Definition: IdentifiableCacheBase.cxx:57
EventContainers::IdentifiableCacheBase::fullSize
size_t fullSize() const
Definition: IdentifiableCacheBase.h:89
EventContainers::IdentifiableCacheBase::IMakerPresent
bool IMakerPresent() const
Definition: IdentifiableCacheBase.h:69
python.subdetectors.mmg.ids
ids
Definition: mmg.py:8
EventContainers::InternalOnline::fetchOrCreate
virtual StatusCode fetchOrCreate(IdentifierHash hashId) override
Definition: InternalOnline.cxx:113
EventContainers::IdentifiableCacheBase::m_vec
std::vector< std::atomic< const void * > > m_vec
Definition: IdentifiableCacheBase.h:103
EventContainers::InternalOnline::m_cacheLink
EventContainers::IdentifiableCacheBase * m_cacheLink
Definition: InternalOnline.h:50
EventContainers::InternalOnline::indexFind
virtual InternalConstItr indexFind(IdentifierHash hashId) const override
Definition: InternalOnline.cxx:37
EventContainers::InternalOnline::tryAddFromCache
virtual bool tryAddFromCache(IdentifierHash hashId, EventContainers::IDC_WriteHandleBase &lock) override
Definition: InternalOnline.cxx:66
EventContainers::InternalOnline::addLock
virtual StatusCode addLock(IdentifierHash hashId, const void *ptr) override
Definition: InternalOnline.cxx:143
EventContainers::InternalOnline::ATLAS_THREAD_SAFE
std::vector< IdentifierHash > m_waitlist ATLAS_THREAD_SAFE
Definition: InternalOnline.h:51
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
EventContainers::IdentifiableCacheBase::find
const void * find(IdentifierHash hash) noexcept
Return payload if there, null if not there.
Definition: IdentifiableCacheBase.cxx:126
EventContainers::IdentifiableCacheBase::add
std::pair< bool, const void * > add(IdentifierHash hash, const void *p) noexcept
Definition: IdentifiableCacheBase.cxx:247
EventContainers::InternalOnline::removeCollection
virtual void * removeCollection(IdentifierHash hashId) override
Definition: InternalOnline.cxx:153
EventContainers::InternalOnline::insert
virtual bool insert(IdentifierHash hashId, const void *ptr) override
Definition: InternalOnline.cxx:128
EventContainers::InternalOnline::InternalOnline
InternalOnline(EventContainers::IdentifiableCacheBase *cache)
Definition: InternalOnline.cxx:16
EventContainers::IDC_WriteHandleBase
Definition: IDC_WriteHandleBase.h:27
EventContainers::InternalOnline::numberOfCollections
virtual size_t numberOfCollections() const override
Definition: InternalOnline.cxx:101
EventContainers::InternalOnline::getAllCurrentHashes
virtual std::vector< IdentifierHash > getAllCurrentHashes() const override
Definition: InternalOnline.cxx:91
checker_macros.h
Define macros for attributes used to control the static checker.
EventContainers::I_InternalIDC::InternalConstItr
std::vector< hashPair >::const_iterator InternalConstItr
Definition: I_InternalIDC.h:37
EventContainers::IdentifiableCacheBase::addLock
std::pair< bool, const void * > addLock(IdentifierHash hash, const void *p) noexcept
Definition: IdentifiableCacheBase.cxx:266