ATLAS Offline Software
Loading...
Searching...
No Matches
EventContainers::InternalOnline Class Referencefinal

#include <InternalOnline.h>

Inheritance diagram for EventContainers::InternalOnline:
Collaboration diagram for EventContainers::InternalOnline:

Public Types

typedef EventContainers::hashPair< void > hashPair
typedef std::vector< hashPair >::const_iterator InternalConstItr
typedef void deleter_f(const void *p)

Public Member Functions

 InternalOnline (EventContainers::IdentifiableCacheBase *cache)
virtual InternalConstItr cbegin () const override
virtual InternalConstItr cend () const override
virtual InternalConstItr indexFind (IdentifierHash hashId) const override
virtual const std::vector< hashPair > & getAllHashPtrPair () const override
virtual ~InternalOnline ()=default
virtual void wait () const override
virtual bool tryAddFromCache (IdentifierHash hashId, EventContainers::IDC_WriteHandleBase &lock) override
virtual bool tryAddFromCache (IdentifierHash hashId) override
virtual std::vector< IdentifierHashgetAllCurrentHashes () const override
virtual size_t numberOfCollections () const override
void resetMask ()
virtual size_t fullSize () const noexcept override
virtual StatusCode fetchOrCreate (IdentifierHash hashId) override
virtual StatusCode fetchOrCreate (const std::vector< IdentifierHash > &hashIds) override
virtual bool insert (IdentifierHash hashId, const void *ptr) override
virtual const void * findIndexPtr (IdentifierHash hashId) const noexcept override
virtual StatusCode addLock (IdentifierHash hashId, const void *ptr) override
virtual void * removeCollection (IdentifierHash hashId) override
virtual void destructor (deleter_f *) noexcept override
virtual void cleanUp (deleter_f *) noexcept override

Private Attributes

EventContainers::IdentifiableCacheBasem_cacheLink
std::vector< IdentifierHash > m_waitlist ATLAS_THREAD_SAFE
std::vector< I_InternalIDC::hashPair > m_map ATLAS_THREAD_SAFE
std::mutex m_waitMutex ATLAS_THREAD_SAFE
IdentifierMask m_mask ATLAS_THREAD_SAFE
std::atomic< bool > m_waitNeeded ATLAS_THREAD_SAFE

Detailed Description

Definition at line 27 of file InternalOnline.h.

Member Typedef Documentation

◆ deleter_f

typedef void EventContainers::I_InternalIDC::deleter_f(const void *p)
inherited

Definition at line 14 of file I_InternalIDC.h.

◆ hashPair

Definition at line 37 of file I_InternalIDC.h.

◆ InternalConstItr

Definition at line 38 of file I_InternalIDC.h.

Constructor & Destructor Documentation

◆ InternalOnline()

InternalOnline::InternalOnline ( EventContainers::IdentifiableCacheBase * cache)

Definition at line 15 of file InternalOnline.cxx.

15 : m_cacheLink(cache),
16 m_mask(cache->fullSize()), m_waitNeeded(false) {}
EventContainers::IdentifiableCacheBase * m_cacheLink
const IIntersectionCache * cache() const
Retrieve the associated cache block, if it exists.

◆ ~InternalOnline()

virtual EventContainers::InternalOnline::~InternalOnline ( )
virtualdefault

Member Function Documentation

◆ addLock()

StatusCode InternalOnline::addLock ( IdentifierHash hashId,
const void * ptr )
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 145 of file InternalOnline.cxx.

145 {
146 std::pair<bool, const void*> added = m_cacheLink->addLock(hashId, ptr);
147 if (!added.first) [[unlikely]] {
148 throw std::runtime_error("IDC WARNING Deletion shouldn't occur in addLock paradigm");
149 }
150 m_mask.set(hashId); //it wasn't added it is already present therefore mask could be true
151 m_waitNeeded.store(true, std::memory_order_relaxed);
152 return StatusCode::SUCCESS;
153}
#define unlikely(x)

◆ cbegin()

InternalConstItr InternalOnline::cbegin ( ) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 31 of file InternalOnline.cxx.

31 {
32 if(m_waitNeeded.load(std::memory_order_acquire)) wait();
33 return m_map.cbegin();
34}
virtual void wait() const override
IndexMap m_map
Map from objects to indices.

◆ cend()

InternalConstItr InternalOnline::cend ( ) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 25 of file InternalOnline.cxx.

25 {
26 if(m_waitNeeded.load(std::memory_order_acquire)) wait();
27 return m_map.cend();
28}

◆ cleanUp()

void InternalOnline::cleanUp ( deleter_f * )
overridevirtualnoexcept

Implements EventContainers::I_InternalIDC.

Definition at line 163 of file InternalOnline.cxx.

◆ destructor()

void InternalOnline::destructor ( deleter_f * )
overridevirtualnoexcept

Implements EventContainers::I_InternalIDC.

Definition at line 159 of file InternalOnline.cxx.

159 {
160 //deliberately empty
161}

◆ fetchOrCreate() [1/2]

StatusCode InternalOnline::fetchOrCreate ( const std::vector< IdentifierHash > & hashIds)
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 122 of file InternalOnline.cxx.

122 {
123 throw std::runtime_error("Not implemented");
124// if (!m_cacheLink->IMakerPresent()) [[unlikely]] return StatusCode::FAILURE;
125// m_cacheLink->createSet(hashIds, m_mask);
126// return StatusCode::SUCCESS;
127}

◆ fetchOrCreate() [2/2]

StatusCode InternalOnline::fetchOrCreate ( IdentifierHash hashId)
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 115 of file InternalOnline.cxx.

115 {
116 if (!m_cacheLink->IMakerPresent()) [[unlikely]] return StatusCode::FAILURE;
117 auto ptr = m_cacheLink->get(hashId);
118 if(ptr) { m_mask.set(hashId); m_waitNeeded.store(true, std::memory_order_relaxed); }
119 return StatusCode::SUCCESS;
120}
void * ptr(T *p)
Definition SGImplSvc.cxx:74

◆ findIndexPtr()

const void * InternalOnline::findIndexPtr ( IdentifierHash hashId) const
overridevirtualnoexcept

Implements EventContainers::I_InternalIDC.

Definition at line 137 of file InternalOnline.cxx.

137 {
138 if(hashId < m_mask.size() and m_mask.test(hashId)) {
139 EventContainers::IdentifiableCacheBase* cacheLink ATLAS_THREAD_SAFE = m_cacheLink;
140 return cacheLink->findWait(hashId);
141 }
142 return nullptr;
143}
std::vector< IdentifierHash > m_waitlist ATLAS_THREAD_SAFE

◆ fullSize()

virtual size_t EventContainers::InternalOnline::fullSize ( ) const
inlineoverridevirtualnoexcept

Implements EventContainers::I_InternalIDC.

Definition at line 41 of file InternalOnline.h.

41{ return m_mask.size(); }

◆ getAllCurrentHashes()

std::vector< IdentifierHash > InternalOnline::getAllCurrentHashes ( ) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 93 of file InternalOnline.cxx.

93 {
94 if(m_waitNeeded.load(std::memory_order_acquire)) wait();
95 std::vector<IdentifierHash> ids;
96 ids.reserve(m_map.size());
97 for(auto &x : m_map) {
98 ids.emplace_back(x.first);
99 }
100 return ids;
101}
#define x

◆ getAllHashPtrPair()

const std::vector< I_InternalIDC::hashPair > & InternalOnline::getAllHashPtrPair ( ) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 18 of file InternalOnline.cxx.

18 {
19 if(m_waitNeeded.load(std::memory_order_acquire)) wait();
20 return m_map;
21}

◆ indexFind()

InternalConstItr InternalOnline::indexFind ( IdentifierHash hashId) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 36 of file InternalOnline.cxx.

36 {
37 if(m_waitNeeded.load(std::memory_order_acquire)) wait();
38 auto itr = std::lower_bound( m_map.begin(), m_map.end(), hashId.value(), [](hashPair &lhs, IdentifierHash::value_type rhs) -> bool { return lhs.first < rhs; } );
39 if(itr!= m_map.end() && itr->first==hashId) return itr;
40 return m_map.end();
41}
EventContainers::hashPair< void > hashPair
constexpr value_type value() const
unsigned int value_type

◆ insert()

bool InternalOnline::insert ( IdentifierHash hashId,
const void * ptr )
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 130 of file InternalOnline.cxx.

130 {
131 std::pair<bool, const void*> cacheinserted = m_cacheLink->add(hashId, ptr);
132 m_mask.set(hashId); //it wasn't added it is already present therefore mask could be true
133 m_waitNeeded.store(true, std::memory_order_relaxed);
134 return ptr == cacheinserted.second;
135}

◆ numberOfCollections()

size_t InternalOnline::numberOfCollections ( ) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 103 of file InternalOnline.cxx.

103 {
104 if(m_waitNeeded.load(std::memory_order_acquire)) wait();
105 return m_map.size();
106}

◆ removeCollection()

void * InternalOnline::removeCollection ( IdentifierHash hashId)
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 155 of file InternalOnline.cxx.

155 {
156 throw std::runtime_error("Do not remove things from an online IDC");
157}

◆ resetMask()

void InternalOnline::resetMask ( )

Definition at line 108 of file InternalOnline.cxx.

108 {
109 if(m_waitNeeded.load(std::memory_order_relaxed)) wait();
110 m_mask.clear();
111 m_map.clear();
112 m_waitNeeded.store(true, std::memory_order_relaxed);
113}

◆ tryAddFromCache() [1/2]

bool InternalOnline::tryAddFromCache ( IdentifierHash hashId)
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 82 of file InternalOnline.cxx.

83{
84 auto ptr = m_cacheLink->find(hashId);
85 if(ptr==nullptr) {
86 return false;
87 }
88 m_mask.set(hashId);
89 m_waitNeeded.store(true, std::memory_order_relaxed);
90 return true;
91}

◆ tryAddFromCache() [2/2]

bool InternalOnline::tryAddFromCache ( IdentifierHash hashId,
EventContainers::IDC_WriteHandleBase & lock )
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 68 of file InternalOnline.cxx.

68 {
69 int flag = m_cacheLink->tryLock(hashId, lock, m_waitlist);
70 //Relaxed since this should not be running in threaded situation.
71 if(!m_waitlist.empty()) m_waitNeeded.store(true, std::memory_order_relaxed);
72 if(flag > 0) {
73 if(flag!=3){
74 m_mask.set(hashId);
75 m_waitNeeded.store(true, std::memory_order_relaxed);
76 }
77 return true;
78 }
79 return false;
80}
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
bool flag
Definition master.py:29

◆ wait()

void InternalOnline::wait ( ) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 43 of file InternalOnline.cxx.

43 {
44 //lockguard to protect m_waitlist from multiple wait calls
45 std::scoped_lock lock (m_waitMutex);
46 if(m_waitNeeded.load(std::memory_order_acquire) == false) return;
47 using namespace EventContainers;
48 const void* ABORTstate = std::bit_cast<const void*>(IdentifiableCacheBase::ABORTEDflag);
49 while(!m_waitlist.empty()) {
50 IdentifierHash hash = m_waitlist.back();
51 EventContainers::IdentifiableCacheBase* cacheLink ATLAS_THREAD_SAFE = m_cacheLink;
52 const void* ptr = cacheLink->waitFor(hash);
53 if(ptr == ABORTstate) {
54 m_mask.unset(hash);
55 }
56 m_waitlist.pop_back();
57 }
58 m_map.clear();
59 m_mask.forEachSetBit([this](size_t index) {
60 const void* ptr = m_cacheLink->m_vec[index].load(std::memory_order_relaxed);//acquire sync is done by m_waitNeeded
61 m_map.emplace_back(index, ptr);
62 });
63 //Full sync to release m_map and acquire pointers retrieved
64 //Probably done by the lock descoping but this is easier to read.
65 m_waitNeeded.store(false, std::memory_order_seq_cst);
66}
str index
Definition DeMoScan.py:362

Member Data Documentation

◆ ATLAS_THREAD_SAFE [1/5]

std::atomic<bool> m_waitNeeded EventContainers::InternalOnline::ATLAS_THREAD_SAFE
mutableprivate

Definition at line 56 of file InternalOnline.h.

◆ ATLAS_THREAD_SAFE [2/5]

IdentifierMask m_mask EventContainers::InternalOnline::ATLAS_THREAD_SAFE
mutableprivate

Definition at line 55 of file InternalOnline.h.

◆ ATLAS_THREAD_SAFE [3/5]

std::mutex m_waitMutex EventContainers::InternalOnline::ATLAS_THREAD_SAFE
mutableprivate

Definition at line 54 of file InternalOnline.h.

◆ ATLAS_THREAD_SAFE [4/5]

std::vector<I_InternalIDC::hashPair> m_map EventContainers::InternalOnline::ATLAS_THREAD_SAFE
mutableprivate

Definition at line 53 of file InternalOnline.h.

◆ ATLAS_THREAD_SAFE [5/5]

std::vector< IdentifierHash > m_waitlist EventContainers::InternalOnline::ATLAS_THREAD_SAFE
mutableprivate

Definition at line 52 of file InternalOnline.h.

◆ m_cacheLink

EventContainers::IdentifiableCacheBase* EventContainers::InternalOnline::m_cacheLink
private

Definition at line 51 of file InternalOnline.h.


The documentation for this class was generated from the following files: