ATLAS Offline Software
Loading...
Searching...
No Matches
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>
15namespace EventContainers {
16template < 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 }
27public:
28 IdentifiableContTemp(size_t size) : IdentifiableContTemp(size, nullptr) { }
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
static Double_t sc
#define x
virtual StatusCode naughtyRetrieve(IdentifierHash hashId, InDetRawDataCollection< PixelRDORawData > *&collToRetrieve) const=0
virtual StatusCode addOrDelete(std::unique_ptr< T > ptr, IdentifierHash hashId)=0
virtual StatusCode naughtyRetrieve ATLAS_NOT_THREAD_SAFE(IdentifierHash hashId, T *&collToRetrieve) const override
virtual bool hasExternalCache() const override
std::vector< const InDetRawDataCollection< PixelRDORawData > * > m_randomcont
IdentifiableContTemp & operator=(const IdentifiableContTemp &)=delete
StatusCode MergeToRealContainer(IIdentifiableCont< T > *real)
IdentifiableContTemp(const IdentifiableContTemp &that)=delete
IdentifiableContTemp(size_t size, IdentifiableContainerMT< T > *extcache)
virtual StatusCode addOrDelete(std::unique_ptr< const T > ptr, IdentifierHash hashId) override
virtual bool tryAddFromCache(IdentifierHash hashId) override
IdentifiableContainerMT< InDetRawDataCollection< PixelRDORawData > > * m_extIDC
virtual size_t numberOfCollections() const override
virtual std::vector< IdentifierHash > GetAllCurrentHashes() const override
virtual StatusCode addOrDelete(std::unique_ptr< T > ptr, IdentifierHash hashId) override
virtual const T * indexFindPtr(IdentifierHash hashId) const override
IdentifiableContTemp(IdentifiableContainerMT< T > *extcache=nullptr)
std::vector< std::pair< IdentifierHash, const InDetRawDataCollection< PixelRDORawData > * > > m_usedhashes
virtual StatusCode addCollection(const T *coll, IdentifierHash hashId) override
This is a "hash" representation of an Identifier.