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

#include <InternalOfflineMap.h>

Inheritance diagram for EventContainers::InternalOfflineMap:
Collaboration diagram for EventContainers::InternalOfflineMap:

Public Types

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

Public Member Functions

 InternalOfflineMap (size_t max)
 
virtual ~InternalOfflineMap ()=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::unordered_map< IdentifierHash::value_type, const void * > m_fullMap
 
std::mutex m_waitMutex ATLAS_THREAD_SAFE
 
std::atomic< bool > m_needsupdate ATLAS_THREAD_SAFE
 
const size_t m_maxsize
 

Detailed Description

Definition at line 20 of file InternalOfflineMap.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

◆ InternalOfflineMap()

InternalOfflineMap::InternalOfflineMap ( size_t  max)

Definition at line 12 of file InternalOfflineMap.cxx.

12 : m_needsupdate(false), m_maxsize(max) {}

◆ ~InternalOfflineMap()

virtual EventContainers::InternalOfflineMap::~InternalOfflineMap ( )
virtualdefault

Member Function Documentation

◆ addLock()

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

Implements EventContainers::I_InternalIDC.

Definition at line 101 of file InternalOfflineMap.cxx.

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

◆ cbegin()

InternalConstItr InternalOfflineMap::cbegin ( ) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 64 of file InternalOfflineMap.cxx.

64  {
65  if(m_needsupdate.load(std::memory_order_acquire)) wait();
66  return m_map.cbegin();
67 }

◆ cend()

InternalConstItr InternalOfflineMap::cend ( ) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 53 of file InternalOfflineMap.cxx.

53  {
54  if(m_needsupdate.load(std::memory_order_acquire)) wait();
55  return m_map.cend();
56 }

◆ cleanUp()

void InternalOfflineMap::cleanUp ( deleter_f deleter)
overridevirtualnoexcept

Implements EventContainers::I_InternalIDC.

Definition at line 80 of file InternalOfflineMap.cxx.

80  {
81  destructor(deleter);
82  m_map.clear();
83  m_fullMap.clear();
84  m_needsupdate.store(false, std::memory_order_release);
85 }

◆ destructor()

void InternalOfflineMap::destructor ( deleter_f deleter)
overridevirtualnoexcept

Implements EventContainers::I_InternalIDC.

Definition at line 126 of file InternalOfflineMap.cxx.

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

◆ fetchOrCreate() [1/2]

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

Implements EventContainers::I_InternalIDC.

Definition at line 121 of file InternalOfflineMap.cxx.

122 {
123  throw std::runtime_error("Not implemented in offline mode");
124 }

◆ fetchOrCreate() [2/2]

StatusCode InternalOfflineMap::fetchOrCreate ( IdentifierHash  hashId)
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 118 of file InternalOfflineMap.cxx.

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

◆ findIndexPtr()

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

Implements EventContainers::I_InternalIDC.

Definition at line 95 of file InternalOfflineMap.cxx.

95  {
96  auto search = m_fullMap.find(hashId);
97  if(search!=m_fullMap.cend()) return search->second;
98  return nullptr;
99 }

◆ fullSize()

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

Implements EventContainers::I_InternalIDC.

Definition at line 34 of file InternalOfflineMap.h.

34 {return m_maxsize;}

◆ getAllCurrentHashes()

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

Implements EventContainers::I_InternalIDC.

Definition at line 36 of file InternalOfflineMap.cxx.

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

◆ getAllHashPtrPair()

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

Implements EventContainers::I_InternalIDC.

Definition at line 58 of file InternalOfflineMap.cxx.

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

◆ indexFind()

InternalConstItr InternalOfflineMap::indexFind ( IdentifierHash  hashId) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 69 of file InternalOfflineMap.cxx.

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

◆ insert()

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

Implements EventContainers::I_InternalIDC.

Definition at line 87 of file InternalOfflineMap.cxx.

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

◆ numberOfCollections()

size_t InternalOfflineMap::numberOfCollections ( ) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 76 of file InternalOfflineMap.cxx.

76  {
77  return m_fullMap.size();
78 }

◆ removeCollection()

void * InternalOfflineMap::removeCollection ( IdentifierHash  hashId)
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 109 of file InternalOfflineMap.cxx.

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

◆ tryAddFromCache() [1/2]

bool InternalOfflineMap::tryAddFromCache ( IdentifierHash  hashId)
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 19 of file InternalOfflineMap.cxx.

20 {
21  return m_fullMap.count(hash);
22 }

◆ tryAddFromCache() [2/2]

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

Implements EventContainers::I_InternalIDC.

Definition at line 15 of file InternalOfflineMap.cxx.

15  {
16  return m_fullMap.count(hash);
17 }

◆ wait()

void InternalOfflineMap::wait ( ) const
overridevirtual

Implements EventContainers::I_InternalIDC.

Definition at line 24 of file InternalOfflineMap.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  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 }

Member Data Documentation

◆ ATLAS_THREAD_SAFE [1/3]

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

Definition at line 43 of file InternalOfflineMap.h.

◆ ATLAS_THREAD_SAFE [2/3]

std::mutex m_waitMutex EventContainers::InternalOfflineMap::ATLAS_THREAD_SAFE
mutableprivate

Definition at line 45 of file InternalOfflineMap.h.

◆ ATLAS_THREAD_SAFE [3/3]

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

Definition at line 46 of file InternalOfflineMap.h.

◆ m_fullMap

std::unordered_map<IdentifierHash::value_type, const void*> EventContainers::InternalOfflineMap::m_fullMap
private

Definition at line 44 of file InternalOfflineMap.h.

◆ m_maxsize

const size_t EventContainers::InternalOfflineMap::m_maxsize
private

Definition at line 47 of file InternalOfflineMap.h.


The documentation for this class was generated from the following files:
EventContainers::InternalOfflineMap::wait
virtual void wait() const override
Definition: InternalOfflineMap.cxx:24
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
IdentifierHash::value_type
unsigned int value_type
Definition: IdentifierHash.h:27
ATH_UNLIKELY
#define ATH_UNLIKELY(x)
Definition: AthUnlikelyMacros.h:17
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
EventContainers::InternalOfflineMap::m_fullMap
std::unordered_map< IdentifierHash::value_type, const void * > m_fullMap
Definition: InternalOfflineMap.h:44
EventContainers::InternalOfflineMap::destructor
virtual void destructor(deleter_f *) noexcept override
Definition: InternalOfflineMap.cxx:126
EventContainers::InternalOfflineMap::m_maxsize
const size_t m_maxsize
Definition: InternalOfflineMap.h:47
python.subdetectors.mmg.ids
ids
Definition: mmg.py:8
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
std::sort
void sort(typename std::reverse_iterator< DataModel_detail::iterator< DVL > > beg, typename std::reverse_iterator< DataModel_detail::iterator< DVL > > end, const Compare &comp)
Specialization of sort for DataVector/List.
Definition: DVL_algorithms.h:623