ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
SGTools
src
TestStore.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
// $Id$
12
13
14
#include "
SGTools/TestStore.h
"
15
#include "
AthenaKernel/DataBucketBase.h
"
16
#include <iostream>
17
#include <algorithm>
18
19
20
namespace
SGTest
{
21
22
23
TestStore
store
;
24
25
26
std::vector<const SG::DataProxy*>
TestStore::proxies
()
const
27
{
28
std::cout <<
"proxies\n"
; std::abort();
29
}
30
31
32
const
std::string*
TestStore::keyToString
(
sgkey_t
key)
const
33
{
34
return
m_stringPool.keyToString (key);
35
}
36
37
38
void
TestStore::registerKey
(
sgkey_t
/*key*/
,
39
const
std::string&
/*str*/
,
40
CLID
/*clid*/
)
41
{
42
std::cout <<
"registerKey\n"
; std::abort();
43
}
44
45
46
SG::DataProxy
*
TestStore::recordObject
(
SG::DataObjectSharedPtr<DataObject>
obj,
47
const
std::string& key,
48
bool
allowMods,
49
bool
returnExisting)
50
{
51
lock_t
lock
(
m_mutex
);
52
const
void
* raw_ptr = obj.get();
53
if
(
DataBucketBase
* bucket =
dynamic_cast<
DataBucketBase
*
>
(obj.get())) {
54
raw_ptr = bucket->object();
55
}
56
57
CLID
clid = obj->clID();
58
SG::DataProxy
*
proxy
= this->
proxy
(lock, clid, key);
59
if
(
proxy
) {
60
if
(returnExisting)
61
return
proxy
;
62
else
63
return
nullptr
;
64
}
65
66
proxy
= this->
proxy
(lock, raw_ptr);
67
if
(
proxy
) {
68
sgkey_t
sgkey = m_stringPool.stringToKey (key, obj->clID());
69
if
(!returnExisting)
70
return
nullptr
;
71
if
(obj->clID() ==
proxy
->clID()) {
72
// Alias?
73
m_kmap
[sgkey] =
proxy
;
74
proxy
->addRef();
75
proxy
->setAlias (key);
76
return
proxy
;
77
}
78
if
(key ==
proxy
->name()) {
79
// Symlink?
80
m_kmap
[sgkey] =
proxy
;
81
proxy
->addRef();
82
proxy
->setTransientID (obj->clID());
83
return
proxy
;
84
}
85
86
// Error.
87
return
nullptr
;
88
}
89
90
proxy
=
record1
(
lock
, raw_ptr, obj.get(), clid, key);
91
if
(!allowMods)
92
proxy
->setConst();
93
return
proxy
;
94
}
95
96
97
const
std::string&
TestStore::name
()
const
98
{
99
static
const
std::string nm =
"TestStore"
;
100
return
nm;
101
}
102
103
104
SG::DataProxy
*
TestStore::proxy
(
const
void
*
const
pTransient)
const
105
{
106
lock_t
lock
(
m_mutex
);
107
return
proxy
(
lock
, pTransient);
108
}
109
110
111
SG::DataProxy
*
112
TestStore::proxy
(
lock_t
&,
const
void
*
const
pTransient)
const
113
{
114
tmap_t::const_iterator i =
m_tmap
.find (pTransient);
115
if
(i !=
m_tmap
.end())
116
return
i->second;
117
return
0;
118
}
119
120
121
SG::DataProxy
*
TestStore::proxy
(
const
CLID
&
id
,
const
std::string& key)
const
122
{
123
lock_t
lock
(
m_mutex
);
124
return
proxy
(
lock
,
id
, key);
125
}
126
127
128
SG::DataProxy
*
129
TestStore::proxy
(
lock_t
&,
const
CLID
&
id
,
const
std::string& key)
const
130
{
131
sgkey_t
sgkey = m_stringPool.stringToKey (key,
id
);
132
kmap_t::const_iterator i =
m_kmap
.find (sgkey);
133
if
(i !=
m_kmap
.end())
134
return
i->second;
135
m_missedProxies.emplace_back (
id
, key);
136
return
0;
137
}
138
139
140
SG::DataProxy
*
TestStore::proxy_exact
(
SG::sgkey_t
sgkey)
const
141
{
142
lock_t
lock
(
m_mutex
);
143
kmap_t::const_iterator i =
m_kmap
.find (sgkey);
144
if
(i !=
m_kmap
.end())
145
return
i->second;
146
return
0;
147
}
148
149
150
sgkey_t
TestStore::stringToKey
(
const
std::string&
str
,
CLID
clid)
151
{
152
lock_t
lock
(
m_mutex
);
153
return
m_stringPool.stringToKey (
str
, clid);
154
}
155
156
157
const
std::string*
TestStore::keyToString
(
sgkey_t
key,
CLID
& clid)
const
158
{
159
lock_t
lock
(
m_mutex
);
160
return
m_stringPool.keyToString (key, clid);
161
}
162
163
164
bool
TestStore::tryELRemap
(
sgkey_t
sgkey_in,
size_t
index_in,
165
sgkey_t
& sgkey_out,
size_t
& index_out)
166
{
167
lock_t
lock
(
m_mutex
);
168
remap_t::iterator i =
m_remap
.find (
TestStoreRemap
(sgkey_in, index_in));
169
if
(i ==
m_remap
.end())
return
false
;
170
sgkey_out = i->second.key;
171
index_out = i->second.index;
172
return
true
;
173
}
174
175
176
StatusCode
TestStore::addToStore
(
CLID
/*id*/
,
SG::DataProxy
*
proxy
)
177
{
178
lock_t
lock
(
m_mutex
);
179
proxy
->setStore (
this
);
180
m_kmap
[
proxy
->sgkey()] =
proxy
;
181
proxy
->addRef();
182
return
StatusCode::SUCCESS;
183
}
184
185
186
void
TestStore::boundHandle
(
IResetable
* handle)
187
{
188
lock_t
lock
(
m_mutex
);
189
m_boundHandles
.push_back (handle);
190
}
191
192
193
void
TestStore::unboundHandle
(
IResetable
* handle)
194
{
195
lock_t
lock
(
m_mutex
);
196
std::vector<IResetable*>::iterator it =
197
std::find (
m_boundHandles
.begin(),
m_boundHandles
.end(), handle);
198
if
(it !=
m_boundHandles
.end())
199
m_boundHandles
.erase (it);
200
}
201
202
203
SG::DataProxy
*
TestStore::record1
(
lock_t
&,
const
void
* p, DataObject* obj,
204
CLID
clid,
const
std::string& key)
205
{
206
sgkey_t
sgkey = m_stringPool.stringToKey (key, clid);
207
if
(
m_kmap
.find (sgkey) !=
m_kmap
.end()) {
208
SG::DataProxy
* dp =
m_kmap
[sgkey];
209
dp->setObject (obj);
210
if
(dp->clID() == CLID_NULL)
211
dp->setID (clid, key);
212
m_tmap
[p] = dp;
213
return
dp;
214
}
215
216
SG::DataProxy
* dp =
new
SG::DataProxy
(obj,
SG::TransientAddress
(clid, key));
217
dp->setStore (
this
);
218
m_tmap
[p] = dp;
219
220
m_kmap
[sgkey] = dp;
221
dp->addRef();
222
dp->setSGKey (sgkey);
223
return
dp;
224
}
225
226
227
void
TestStore::remap
(
sgkey_t
sgkey_in,
sgkey_t
sgkey_out,
228
size_t
index_in,
size_t
index_out)
229
{
230
lock_t
lock
(
m_mutex
);
231
m_remap
[
TestStoreRemap
(sgkey_in, index_in)] =
232
TestStoreRemap
(sgkey_out, index_out);
233
}
234
235
236
void
TestStore::alias
(
SG::DataProxy
*
proxy
,
237
const
std::string& newKey)
238
{
239
lock_t
lock
(
m_mutex
);
240
sgkey_t
sgkey = m_stringPool.stringToKey (newKey,
proxy
->clID());
241
m_kmap
[sgkey] =
proxy
;
242
proxy
->addRef();
243
proxy
->setAlias (newKey);
244
}
245
246
247
void
initTestStore
ATLAS_NOT_THREAD_SAFE
()
248
{
249
SG::CurrentEventStore::setStore (&
store
);
250
}
251
252
253
std::unique_ptr<TestStore>
getTestStore
()
254
{
255
auto
store
= std::make_unique<TestStore>();
256
SG::CurrentEventStore::setStore (
store
.get());
257
return
store
;
258
}
259
260
261
}
// namespace SGTest
DataBucketBase.h
CLID
uint32_t CLID
The Class ID type.
Definition
Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
lock
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
TestStore.h
Dummy event store, for regression tests.
DataBucketBase
A non-templated base class for DataBucket, allows to access the transient object address as a void*.
Definition
DataBucketBase.h:24
IResetable
a resetable object (e.g.
Definition
IResetable.h:15
SGTest::TestStore
Definition
TestStore.h:52
SGTest::TestStore::boundHandle
virtual void boundHandle(IResetable *handle) override
Definition
TestStore.cxx:186
SGTest::TestStore::m_boundHandles
std::vector< IResetable * > m_boundHandles
Definition
TestStore.h:129
SGTest::TestStore::m_mutex
mutex_t m_mutex
Definition
TestStore.h:136
SGTest::TestStore::keyToString
virtual const std::string * keyToString(sgkey_t) const override
Definition
TestStore.cxx:32
SGTest::TestStore::registerKey
virtual void registerKey(sgkey_t, const std::string &, CLID) override
Definition
TestStore.cxx:38
SGTest::TestStore::recordObject
virtual SG::DataProxy * recordObject(SG::DataObjectSharedPtr< DataObject > obj, const std::string &key, bool allowMods, bool returnExisting) override
Definition
TestStore.cxx:46
SGTest::TestStore::tryELRemap
virtual bool tryELRemap(sgkey_t sgkey_in, size_t index_in, sgkey_t &sgkey_out, size_t &index_out) override
Definition
TestStore.cxx:164
SGTest::TestStore::stringToKey
virtual sgkey_t stringToKey(const std::string &str, CLID clid) override
Definition
TestStore.cxx:150
SGTest::TestStore::m_kmap
kmap_t m_kmap
Definition
TestStore.h:122
SGTest::TestStore::alias
void alias(SG::DataProxy *proxy, const std::string &newKey)
Definition
TestStore.cxx:236
SGTest::TestStore::name
virtual const std::string & name() const override
Definition
TestStore.cxx:97
SGTest::TestStore::proxy
virtual SG::DataProxy * proxy(const void *const pTransient) const override
Definition
TestStore.cxx:104
SGTest::TestStore::record1
SG::DataProxy * record1(lock_t &, const void *p, DataObject *obj, CLID clid, const std::string &key)
Definition
TestStore.cxx:203
SGTest::TestStore::proxy_exact
virtual SG::DataProxy * proxy_exact(SG::sgkey_t sgkey) const override
Definition
TestStore.cxx:140
SGTest::TestStore::remap
void remap(sgkey_t sgkey_in, sgkey_t sgkey_out, size_t index_in=0, size_t index_out=0)
Definition
TestStore.cxx:227
SGTest::TestStore::proxies
virtual std::vector< const SG::DataProxy * > proxies() const override
Definition
TestStore.cxx:26
SGTest::TestStore::m_remap
remap_t m_remap
Definition
TestStore.h:125
SGTest::TestStore::unboundHandle
virtual void unboundHandle(IResetable *handle) override
Definition
TestStore.cxx:193
SGTest::TestStore::m_tmap
tmap_t m_tmap
Definition
TestStore.h:119
SGTest::TestStore::addToStore
virtual StatusCode addToStore(CLID, SG::DataProxy *proxy) override
Definition
TestStore.cxx:176
SGTest::TestStore::lock_t
std::lock_guard< mutex_t > lock_t
Definition
TestStore.h:135
SG::DataProxy
Definition
DataProxy.h:45
SG::TransientAddress
Definition
TransientAddress.h:34
SGTest
Definition
TestStore.h:26
SGTest::store
TestStore store
Definition
TestStore.cxx:23
SGTest::ATLAS_NOT_THREAD_SAFE
void initTestStore ATLAS_NOT_THREAD_SAFE()
Definition
TestStore.cxx:247
SGTest::getTestStore
std::unique_ptr< TestStore > getTestStore()
Definition
TestStore.cxx:253
SGTest::sgkey_t
SG::sgkey_t sgkey_t
Definition
TestStore.h:29
SG::DataObjectSharedPtr
CxxUtils::RefCountedPtr< T > DataObjectSharedPtr
Definition
DataObjectSharedPtr.h:27
SG::sgkey_t
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition
sgkey_t.h:32
str
Definition
BTagTrackIpAccessor.cxx:11
SGTest::TestStoreRemap
Definition
TestStore.h:33
Generated on
for ATLAS Offline Software by
1.17.0