ATLAS Offline Software
InternalOffline.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 InternalOffline::InternalOffline(size_t max) : m_maximumSize(max) {
13  //Check optimization assumptions
18 }
19 
20 
22  return indexFind(hash) != m_map.cend();//No Cache in offline mode
23 }
24 
26 {
27  return indexFind(hash) != m_map.cend();//No Cache in offline mode
28 }
29 
30 void InternalOffline::wait() const {
31  //No need to wait in offline, deliberately empty method
32 }
33 
34 std::vector<IdentifierHash> InternalOffline::getAllCurrentHashes() const {
35  std::vector<IdentifierHash> ids;
36  ids.reserve(m_map.size());
37  for(auto &x : m_map) {
38  ids.emplace_back(x.first);
39  }
40  return ids;
41 }
42 
45  return m_map.cend();
46 }
47 
48 const std::vector < I_InternalIDC::hashPair >& InternalOffline::getAllHashPtrPair() const{ return m_map; }
49 
52  return m_map.cbegin();
53 }
54 
55 InternalConstItr InternalOffline::indexFind( IdentifierHash hashId ) const{
56  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; } );
57  if(itr!= m_map.cend() && itr->first==hashId) return itr;
58  return m_map.cend();
59 // return std::find_if(m_map.begin(), m_map.end(), [hashId](const hashPair &lhs) -> bool { return lhs.first == hashId; });
60 }
61 
63  return m_map.size();
64 }
65 
66 void InternalOffline::cleanUp(deleter_f* deleter) noexcept {
67  for(const auto& x : m_map) deleter(x.second);
68  m_map.clear();
69 }
70 
71 bool InternalOffline::insert(IdentifierHash hashId, const void* ptr) {
72  if(m_map.empty() || m_map.back().first < hashId){
73  m_map.emplace_back(hashId, ptr);
74  return true;
75  }
76  auto itr = std::lower_bound( m_map.begin(), m_map.end(), hashId.value(), [](const hashPair &lhs, IdentifierHash::value_type rhs) -> bool { return lhs.first < rhs; } );
77  if(itr == std::end(m_map) || itr->first != hashId)
78  {
79  m_map.emplace(itr, hashId, ptr);
80  return true;
81  }
82  return false;
83 }
84 
85 const void* InternalOffline::findIndexPtr(IdentifierHash hashId) const noexcept{
86  auto itr = indexFind(hashId);
87  if(itr != m_map.end()) return itr->second;
88  return nullptr;
89 }
90 
91 StatusCode InternalOffline::addLock(IdentifierHash hashId, const void* ptr) {
92  bool added = insert(hashId, ptr);
93  if(ATH_UNLIKELY(!added)) {
94  throw std::runtime_error("IDC WARNING Deletion shouldn't occur in addLock paradigm");
95  }
96  return StatusCode::SUCCESS;
97 }
98 
99 void* InternalOffline::removeCollection( IdentifierHash hashId ) {
100  auto itr = std::lower_bound( m_map.begin(), m_map.end(), hashId.value(), [](hashPair &lhs, IdentifierHash::value_type rhs) -> bool { return lhs.first < rhs; } );
101  if(itr== m_map.end() || itr->first!=hashId) return nullptr;
102  void* ptr = const_cast< void* > (itr->second);
103  m_map.erase(itr);
104  return ptr;
105 }
106 
108  throw std::runtime_error("Not implemented in offline mode");
109 }
110 StatusCode InternalOffline::fetchOrCreate(const std::vector<IdentifierHash>&)
111 {
112  throw std::runtime_error("Not implemented in offline mode");
113 }
114 
115 void InternalOffline::destructor(deleter_f* deleter) noexcept {
116  for(const auto& x : m_map) deleter(x.second);
117 }
max
#define max(a, b)
Definition: cfImp.cxx:41
EventContainers::InternalOffline::cend
virtual InternalConstItr cend() const override
Definition: InternalOffline.cxx:44
EventContainers::InternalOffline::InternalOffline
InternalOffline(size_t max)
Definition: InternalOffline.cxx:12
InternalConstItr
I_InternalIDC::InternalConstItr InternalConstItr
Definition: InternalOffline.cxx:11
athena.value
value
Definition: athena.py:124
IdentifierHash::value_type
unsigned int value_type
Definition: IdentifierHash.h:27
InternalOffline.h
ATH_UNLIKELY
#define ATH_UNLIKELY(x)
Definition: AthUnlikelyMacros.h:17
EventContainers
Definition: T_AthenaPoolCreateFuncs.h:33
EventContainers::InternalOffline::fetchOrCreate
virtual StatusCode fetchOrCreate(IdentifierHash hashId) override
Definition: InternalOffline.cxx:107
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
EventContainers::hashPair
Definition: I_InternalIDC.h:25
x
#define x
EventContainers::InternalOffline::destructor
virtual void destructor(deleter_f *) noexcept override
Definition: InternalOffline.cxx:115
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
EventContainers::InternalOffline::numberOfCollections
virtual size_t numberOfCollections() const override
Definition: InternalOffline.cxx:62
EventContainers::InternalOffline::tryAddFromCache
virtual bool tryAddFromCache(IdentifierHash hashId, EventContainers::IDC_WriteHandleBase &lock) override
Definition: InternalOffline.cxx:21
AthUnlikelyMacros.h
EventContainers::InternalOffline::insert
virtual bool insert(IdentifierHash hashId, const void *ptr) override
Definition: InternalOffline.cxx:71
EventContainers::InternalOffline::cleanUp
virtual void cleanUp(deleter_f *deleter) noexcept override
Definition: InternalOffline.cxx:66
EventContainers::InternalOffline::addLock
virtual StatusCode addLock(IdentifierHash hashId, const void *ptr) override
Definition: InternalOffline.cxx:91
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::InternalOffline::getAllCurrentHashes
virtual std::vector< IdentifierHash > getAllCurrentHashes() const override
Definition: InternalOffline.cxx:34
EventContainers::InternalOffline::wait
virtual void wait() const override
Definition: InternalOffline.cxx:30
EventContainers::InternalOffline::findIndexPtr
virtual const void * findIndexPtr(IdentifierHash hashId) const noexcept override
Definition: InternalOffline.cxx:85
EventContainers::InternalOffline::getAllHashPtrPair
virtual const std::vector< hashPair > & getAllHashPtrPair() const override
Definition: InternalOffline.cxx:48
EventContainers::InternalOffline::removeCollection
virtual void * removeCollection(IdentifierHash hashId) override
Definition: InternalOffline.cxx:99
EventContainers::InternalOffline::indexFind
virtual InternalConstItr indexFind(IdentifierHash hashId) const override
Definition: InternalOffline.cxx:55
python.subdetectors.mmg.ids
ids
Definition: mmg.py:8
EventContainers::InternalOffline::cbegin
virtual InternalConstItr cbegin() const override
Definition: InternalOffline.cxx:51
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
EventContainers::IDC_WriteHandleBase
Definition: IDC_WriteHandleBase.h:27
EventContainers::InternalOffline::m_map
std::vector< I_InternalIDC::hashPair > m_map
Definition: InternalOffline.h:41
EventContainers::I_InternalIDC::InternalConstItr
std::vector< hashPair >::const_iterator InternalConstItr
Definition: I_InternalIDC.h:37