ATLAS Offline Software
IdentifiableContTemp.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 #ifndef EVENTCONTAINERS_IDENTIFIABLETEMP_H
7 #define EVENTCONTAINERS_IDENTIFIABLETEMP_H
8 //This is a dummy version of the identifiable container.
9 //Do not use with storegate
10 //Do not use multithreadedly
11 
14 #include <vector>
15 namespace EventContainers {
16 template < class T>
18 
19  std::vector< std::pair<IdentifierHash, const T* > > m_usedhashes;
20  std::vector< const T* > m_randomcont;
21 
24  IdentifiableContTemp(size_t size, IdentifiableContainerMT< T > *extcache) : m_randomcont(size, nullptr), m_extIDC(extcache) {
25  m_hasExternalCache = m_extIDC && m_extIDC->hasExternalCache();
26  }
27 public:
29 
30  IdentifiableContTemp(IdentifiableContainerMT< T > *extcache = nullptr) : IdentifiableContTemp(extcache->fullSize(), extcache) { }
34 
36  for(auto &x : m_usedhashes){
37  delete x.second;
38  }
39  }
40 
41  virtual const T* indexFindPtr( IdentifierHash hashId ) const override{
42  if(hashId >= m_randomcont.size()) return nullptr;
43  return m_randomcont[hashId];
44  }
45 
46  virtual std::vector<IdentifierHash> GetAllCurrentHashes() const override{
47  std::vector<IdentifierHash> out;
48  out.reserve(m_usedhashes.size());
49  for(auto x : m_usedhashes) out.push_back(x.first);
50  return out;
51  }
52 
53  virtual StatusCode addCollection(const T* coll, IdentifierHash hashId) override{
54  if(hashId >= m_randomcont.size()) return StatusCode::FAILURE;
55  m_usedhashes.emplace_back(hashId, coll);
56  m_randomcont[hashId] = coll;
57  return StatusCode::SUCCESS;
58  }
59 
60 
61  virtual StatusCode addOrDelete(std::unique_ptr<T> ptr, IdentifierHash hashId) override{
62  if(hashId >= m_randomcont.size()) return StatusCode::FAILURE;
63  if(m_randomcont[hashId] == nullptr){
64  return addCollection(ptr.release(), hashId);
65  }
66  ptr.reset();
67  return StatusCode::SUCCESS;
68  }
69 
70  virtual StatusCode addOrDelete(std::unique_ptr<const T> ptr, IdentifierHash hashId) override{
71  if(hashId >= m_randomcont.size()) return StatusCode::FAILURE;
72  if(m_randomcont[hashId] == nullptr){
73  return addCollection(ptr.release(), hashId);
74  }
75  ptr.reset();
76  return StatusCode::SUCCESS;
77  }
78 
79  virtual size_t fullSize() const override{
80  return m_randomcont.size();
81  }
82 
83  virtual size_t numberOfCollections() const override{
84  return m_usedhashes.size();
85  }
86 
87  virtual bool tryAddFromCache(IdentifierHash hashId) override{
88  if(m_extIDC){
89  return m_extIDC->tryAddFromCache(hashId);
90  }
91  return false;
92  }
93 
94  virtual bool hasExternalCache() const override{
95  return m_hasExternalCache;
96  }
97 
98  virtual StatusCode naughtyRetrieve ATLAS_NOT_THREAD_SAFE (IdentifierHash hashId, T* &collToRetrieve) const override{
99  if(hashId >= m_randomcont.size()) return StatusCode::FAILURE;
100  collToRetrieve = const_cast<T*>( m_randomcont[hashId]);
101  return StatusCode::SUCCESS;
102  }
103 
105  for(auto &x : m_usedhashes){
106  auto ptr = std::unique_ptr<const T>(x.second);
107  auto sc = real->addOrDelete(std::move(ptr), x.first);
108  if(sc.isFailure()) { return StatusCode::FAILURE; }
109  m_randomcont[x.first] = nullptr;
110  }
111  m_usedhashes.clear();
112  return StatusCode::SUCCESS;
113  }
114 
115  virtual void cleanup() override{
116  for(auto &x : m_usedhashes){
117  delete x.second;
118  }
119  m_usedhashes.clear();
120  m_randomcont.assign(m_randomcont.size(), nullptr);
121  }
122 
123 };
124 
125 }
126 #endif
127 
EventContainers::IdentifiableContTemp::indexFindPtr
virtual const T * indexFindPtr(IdentifierHash hashId) const override
Definition: IdentifiableContTemp.h:41
EventContainers::IdentifiableContTemp::addOrDelete
virtual StatusCode addOrDelete(std::unique_ptr< const T > ptr, IdentifierHash hashId) override
Definition: IdentifiableContTemp.h:70
EventContainers::IdentifiableContTemp::m_usedhashes
std::vector< std::pair< IdentifierHash, const T * > > m_usedhashes
Definition: IdentifiableContTemp.h:19
EventContainers::IdentifiableContTemp::IdentifiableContTemp
IdentifiableContTemp(size_t size)
Definition: IdentifiableContTemp.h:28
IIdentifiableCont.h
EventContainers::IdentifiableContTemp::~IdentifiableContTemp
virtual ~IdentifiableContTemp()
Definition: IdentifiableContTemp.h:35
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
EventContainers
Definition: T_AthenaPoolCreateFuncs.h:33
EventContainers::IdentifiableContTemp::m_extIDC
IdentifiableContainerMT< T > * m_extIDC
Definition: IdentifiableContTemp.h:22
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
x
#define x
EventContainers::IIdentifiableCont::addOrDelete
virtual StatusCode addOrDelete(std::unique_ptr< T > ptr, IdentifierHash hashId)=0
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
EventContainers::IIdentifiableCont
Definition: IIdentifiableCont.h:13
EventContainers::IdentifiableContTemp::IdentifiableContTemp
IdentifiableContTemp(const IdentifiableContTemp &that)=delete
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
EventContainers::IdentifiableContTemp
Definition: IdentifiableContTemp.h:17
EventContainers::IdentifiableContTemp::MergeToRealContainer
StatusCode MergeToRealContainer(IIdentifiableCont< T > *real)
Definition: IdentifiableContTemp.h:104
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
EventContainers::IdentifiableContTemp::IdentifiableContTemp
IdentifiableContTemp(IdentifiableContainerMT< T > *extcache=nullptr)
Definition: IdentifiableContTemp.h:30
EventContainers::IdentifiableContTemp::GetAllCurrentHashes
virtual std::vector< IdentifierHash > GetAllCurrentHashes() const override
Definition: IdentifiableContTemp.h:46
EventContainers::IdentifiableContTemp::m_hasExternalCache
bool m_hasExternalCache
Definition: IdentifiableContTemp.h:23
EventContainers::IdentifiableContTemp::numberOfCollections
virtual size_t numberOfCollections() const override
Definition: IdentifiableContTemp.h:83
EventContainers::IdentifiableContTemp::hasExternalCache
virtual bool hasExternalCache() const override
Definition: IdentifiableContTemp.h:94
EventContainers::IIdentifiableCont::naughtyRetrieve
virtual StatusCode naughtyRetrieve(IdentifierHash hashId, T *&collToRetrieve) const =0
EventContainers::IdentifiableContTemp::addCollection
virtual StatusCode addCollection(const T *coll, IdentifierHash hashId) override
Definition: IdentifiableContTemp.h:53
EventContainers::IdentifiableContTemp::IdentifiableContTemp
IdentifiableContTemp(size_t size, IdentifiableContainerMT< T > *extcache)
Definition: IdentifiableContTemp.h:24
EventContainers::IdentifiableContTemp::addOrDelete
virtual StatusCode addOrDelete(std::unique_ptr< T > ptr, IdentifierHash hashId) override
Definition: IdentifiableContTemp.h:61
EventContainers::IdentifiableContTemp::fullSize
virtual size_t fullSize() const override
Definition: IdentifiableContTemp.h:79
EventContainers::IdentifiableContTemp::ATLAS_NOT_THREAD_SAFE
virtual StatusCode naughtyRetrieve ATLAS_NOT_THREAD_SAFE(IdentifierHash hashId, T *&collToRetrieve) const override
Definition: IdentifiableContTemp.h:98
IdentifiableContainerMT
Definition: IdentifiableContainerMT.h:30
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
EventContainers::IdentifiableContTemp::m_randomcont
std::vector< const T * > m_randomcont
Definition: IdentifiableContTemp.h:20
IdentifiableContainerMT.h
EventContainers::IdentifiableContTemp::tryAddFromCache
virtual bool tryAddFromCache(IdentifierHash hashId) override
Definition: IdentifiableContTemp.h:87
EventContainers::IdentifiableContTemp::IdentifiableContTemp
IdentifiableContTemp()=delete
EventContainers::IdentifiableContTemp::operator=
IdentifiableContTemp & operator=(const IdentifiableContTemp &)=delete
EventContainers::IdentifiableContTemp::cleanup
virtual void cleanup() override
Definition: IdentifiableContTemp.h:115