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