ATLAS Offline Software
Public Types | Public Member Functions | Private Attributes | List of all members
EventContainers::InternalOfflineFast Class Referencefinal

#include <InternalOfflineFast.h>

Inheritance diagram for EventContainers::InternalOfflineFast:
Collaboration diagram for EventContainers::InternalOfflineFast:

Public Types

typedef EventContainers::hashPair< void > hashPair
 
typedef std::vector< hashPair >::const_iterator InternalConstItr
 

Public Member Functions

 InternalOfflineFast (size_t max)
 
virtual ~InternalOfflineFast ()=default
 
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 bool tryAddFromCache (IdentifierHash hashId, EventContainers::IDC_WriteHandleBase &lock) override
 
virtual bool tryAddFromCache (IdentifierHash hashId) override
 
virtual void wait () const override
 
virtual std::vector< IdentifierHashgetAllCurrentHashes () const override
 
virtual size_t numberOfCollections () const override
 
virtual void cleanUp (deleter_f *deleter) noexcept override
 
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
 

Private Attributes

std::vector< I_InternalIDC::hashPair > m_map ATLAS_THREAD_SAFE
 
std::vector< const void * > m_fullMap
 
std::mutex m_waitMutex ATLAS_THREAD_SAFE
 
std::atomic< bool > m_needsupdate ATLAS_THREAD_SAFE
 

Detailed Description

Definition at line 19 of file InternalOfflineFast.h.

Member Typedef Documentation

◆ hashPair

Definition at line 36 of file I_InternalIDC.h.

◆ InternalConstItr

typedef std::vector< hashPair >::const_iterator EventContainers::I_InternalIDC::InternalConstItr
inherited

Definition at line 37 of file I_InternalIDC.h.

Constructor & Destructor Documentation

◆ InternalOfflineFast()

InternalOfflineFast::InternalOfflineFast ( size_t  max)

Definition at line 12 of file InternalOfflineFast.cxx.

12 : m_fullMap(max, nullptr), m_needsupdate(false) {}

◆ ~InternalOfflineFast()

virtual EventContainers::InternalOfflineFast::~InternalOfflineFast ( )
virtualdefault

Member Function Documentation

◆ addLock()

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

Implements EventContainers::I_InternalIDC.

Definition at line 99 of file InternalOfflineFast.cxx.

99  {
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 }

◆ cbegin()

InternalConstItr InternalOfflineFast::cbegin ( ) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 57 of file InternalOfflineFast.cxx.

57  {
58  if(m_needsupdate.load(std::memory_order_acquire)) wait();
59  return m_map.cbegin();
60 }

◆ cend()

InternalConstItr InternalOfflineFast::cend ( ) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 46 of file InternalOfflineFast.cxx.

46  {
47  if(m_needsupdate.load(std::memory_order_acquire)) wait();
48  return m_map.cend();
49 }

◆ cleanUp()

void InternalOfflineFast::cleanUp ( deleter_f deleter)
overridevirtualnoexcept

Implements EventContainers::I_InternalIDC.

Definition at line 74 of file InternalOfflineFast.cxx.

74  {
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 }

◆ destructor()

void InternalOfflineFast::destructor ( deleter_f deleter)
overridevirtualnoexcept

Implements EventContainers::I_InternalIDC.

Definition at line 122 of file InternalOfflineFast.cxx.

122  {
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 }

◆ fetchOrCreate() [1/2]

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

Implements EventContainers::I_InternalIDC.

Definition at line 117 of file InternalOfflineFast.cxx.

118 {
119  throw std::runtime_error("Not implemented in offline mode");
120 }

◆ fetchOrCreate() [2/2]

StatusCode InternalOfflineFast::fetchOrCreate ( IdentifierHash  hashId)
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 114 of file InternalOfflineFast.cxx.

114  {
115  throw std::runtime_error("Not implemented in offline mode");
116 }

◆ findIndexPtr()

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

Implements EventContainers::I_InternalIDC.

Definition at line 94 of file InternalOfflineFast.cxx.

94  {
95  if(hashId >= m_fullMap.size()) return nullptr;
96  return m_fullMap[hashId];
97 }

◆ fullSize()

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

Implements EventContainers::I_InternalIDC.

Definition at line 33 of file InternalOfflineFast.h.

33 {return m_fullMap.size();}

◆ getAllCurrentHashes()

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

Implements EventContainers::I_InternalIDC.

Definition at line 35 of file InternalOfflineFast.cxx.

35  {
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 }

◆ getAllHashPtrPair()

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

Implements EventContainers::I_InternalIDC.

Definition at line 51 of file InternalOfflineFast.cxx.

51  {
52  if(m_needsupdate.load(std::memory_order_acquire)) wait();
53  return m_map;
54 }

◆ indexFind()

InternalConstItr InternalOfflineFast::indexFind ( IdentifierHash  hashId) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 62 of file InternalOfflineFast.cxx.

62  {
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 }

◆ insert()

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

Implements EventContainers::I_InternalIDC.

Definition at line 87 of file InternalOfflineFast.cxx.

87  {
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 }

◆ numberOfCollections()

size_t InternalOfflineFast::numberOfCollections ( ) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 69 of file InternalOfflineFast.cxx.

69  {
70  if(m_needsupdate.load(std::memory_order_acquire)) wait();
71  return m_map.size();
72 }

◆ removeCollection()

void * InternalOfflineFast::removeCollection ( IdentifierHash  hashId)
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 107 of file InternalOfflineFast.cxx.

107  {
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 }

◆ tryAddFromCache() [1/2]

bool InternalOfflineFast::tryAddFromCache ( IdentifierHash  hashId)
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 19 of file InternalOfflineFast.cxx.

20 {
21  return m_fullMap[hash] != nullptr;
22 }

◆ tryAddFromCache() [2/2]

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

Implements EventContainers::I_InternalIDC.

Definition at line 15 of file InternalOfflineFast.cxx.

15  {
16  return m_fullMap[hash] != nullptr;
17 }

◆ wait()

void InternalOfflineFast::wait ( ) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 24 of file InternalOfflineFast.cxx.

24  {
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 }

Member Data Documentation

◆ ATLAS_THREAD_SAFE [1/3]

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

Definition at line 42 of file InternalOfflineFast.h.

◆ ATLAS_THREAD_SAFE [2/3]

std::mutex m_waitMutex EventContainers::InternalOfflineFast::ATLAS_THREAD_SAFE
mutableprivate

Definition at line 44 of file InternalOfflineFast.h.

◆ ATLAS_THREAD_SAFE [3/3]

std::atomic<bool> m_needsupdate EventContainers::InternalOfflineFast::ATLAS_THREAD_SAFE
mutableprivate

Definition at line 45 of file InternalOfflineFast.h.

◆ m_fullMap

std::vector<const void*> EventContainers::InternalOfflineFast::m_fullMap
private

Definition at line 43 of file InternalOfflineFast.h.


The documentation for this class was generated from the following files:
EventContainers::InternalOfflineFast::m_fullMap
std::vector< const void * > m_fullMap
Definition: InternalOfflineFast.h:43
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
IdentifierHash::value_type
unsigned int value_type
Definition: IdentifierHash.h:27
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
lumiFormat.i
int i
Definition: lumiFormat.py:85
python.subdetectors.mmg.ids
ids
Definition: mmg.py:8
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::InternalOfflineFast::ATLAS_THREAD_SAFE
std::vector< I_InternalIDC::hashPair > m_map ATLAS_THREAD_SAFE
Definition: InternalOfflineFast.h:42