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 <algorithm>
16#include <iostream>
17
18
19namespace SGTest {
20
21
23
24
25std::vector<const SG::DataProxy*> TestStore::proxies() const
26{
27 std::cout << "proxies\n"; std::abort();
28}
29
30
31const std::string* TestStore::keyToString (sgkey_t key) const
32{
33 return m_stringPool.keyToString (key);
34}
35
36
38 const std::string& /*str*/,
39 CLID /*clid*/)
40{
41 std::cout << "registerKey\n"; std::abort();
42}
43
44
46 const std::string& key,
47 bool allowMods,
48 bool returnExisting)
49{
51 const void* raw_ptr = obj.get();
52 if (DataBucketBase* bucket = dynamic_cast<DataBucketBase*> (obj.get())) {
53 raw_ptr = bucket->object();
54 }
55
56 CLID clid = obj->clID();
57 SG::DataProxy* proxy = this->proxy (lock, clid, key);
58 if (proxy) {
59 if (returnExisting)
60 return proxy;
61 else
62 return nullptr;
63 }
64
65 proxy = this->proxy (lock, raw_ptr);
66 if (proxy) {
67 sgkey_t sgkey = m_stringPool.stringToKey (key, obj->clID());
68 if (!returnExisting)
69 return nullptr;
70 if (obj->clID() == proxy->clID()) {
71 // Alias?
72 m_kmap[sgkey] = proxy;
73 proxy->addRef();
74 proxy->setAlias (key);
75 return proxy;
76 }
77 if (key == proxy->name()) {
78 // Symlink?
79 m_kmap[sgkey] = proxy;
80 proxy->addRef();
81 proxy->setTransientID (obj->clID());
82 return proxy;
83 }
84
85 // Error.
86 return nullptr;
87 }
88
89 proxy = record1 (lock, raw_ptr, obj.get(), clid, key);
90 if (!allowMods)
91 proxy->setConst();
92 return proxy;
93}
94
95
96const std::string& TestStore::name() const
97{
98 static const std::string nm = "TestStore";
99 return nm;
100}
101
102
103SG::DataProxy* TestStore::proxy(const void* const pTransient) const
104{
106 return proxy (lock, pTransient);
107}
108
109
111TestStore::proxy(lock_t&, const void* const pTransient) const
112{
113 tmap_t::const_iterator i = m_tmap.find (pTransient);
114 if (i != m_tmap.end())
115 return i->second;
116 return 0;
117}
118
119
120SG::DataProxy* TestStore::proxy(const CLID& id, const std::string& key) const
121{
123 return proxy (lock, id, key);
124}
125
126
128TestStore::proxy(lock_t&, const CLID& id, const std::string& key) const
129{
130 sgkey_t sgkey = m_stringPool.stringToKey (key, id);
131 kmap_t::const_iterator i = m_kmap.find (sgkey);
132 if (i != m_kmap.end())
133 return i->second;
134 m_missedProxies.emplace_back (id, key);
135 return 0;
136}
137
138
140{
142 kmap_t::const_iterator i = m_kmap.find (sgkey);
143 if (i != m_kmap.end())
144 return i->second;
145 return 0;
146}
147
148
149sgkey_t TestStore::stringToKey (const std::string& str, CLID clid)
150{
152 return m_stringPool.stringToKey (str, clid);
153}
154
155
156const std::string* TestStore::keyToString (sgkey_t key, CLID& clid) const
157{
159 return m_stringPool.keyToString (key, clid);
160}
161
162
163bool TestStore::tryELRemap (sgkey_t sgkey_in, size_t index_in,
164 sgkey_t& sgkey_out, size_t& index_out)
165{
167 remap_t::iterator i = m_remap.find (TestStoreRemap (sgkey_in, index_in));
168 if (i == m_remap.end()) return false;
169 sgkey_out = i->second.key;
170 index_out = i->second.index;
171 return true;
172}
173
174
176{
178 proxy->setStore (this);
179 m_kmap[proxy->sgkey()] = proxy;
180 proxy->addRef();
181 return StatusCode::SUCCESS;
182}
183
184
186{
188 m_boundHandles.push_back (handle);
189}
190
191
193{
195 std::vector<IResetable*>::iterator it =
196 std::find (m_boundHandles.begin(), m_boundHandles.end(), handle);
197 if (it != m_boundHandles.end())
198 m_boundHandles.erase (it);
199}
200
201
202SG::DataProxy* TestStore::record1 (lock_t&, const void* p, DataObject* obj,
203 CLID clid, const std::string& key)
204{
205 sgkey_t sgkey = m_stringPool.stringToKey (key, clid);
206 if (m_kmap.find (sgkey) != m_kmap.end()) {
207 SG::DataProxy* dp = m_kmap[sgkey];
208 dp->setObject (obj);
209 if (dp->clID() == CLID_NULL)
210 dp->setID (clid, key);
211 m_tmap[p] = dp;
212 return dp;
213 }
214
215 SG::DataProxy* dp = new SG::DataProxy(obj, SG::TransientAddress(clid, key));
216 dp->setStore (this);
217 m_tmap[p] = dp;
218
219 m_kmap[sgkey] = dp;
220 dp->addRef();
221 dp->setSGKey (sgkey);
222 return dp;
223}
224
225
226void TestStore::remap (sgkey_t sgkey_in, sgkey_t sgkey_out,
227 size_t index_in, size_t index_out)
228{
230 m_remap[TestStoreRemap(sgkey_in, index_in)] =
231 TestStoreRemap(sgkey_out, index_out);
232}
233
234
236 const std::string& newKey)
237{
239 sgkey_t sgkey = m_stringPool.stringToKey (newKey, proxy->clID());
240 m_kmap[sgkey] = proxy;
241 proxy->addRef();
242 proxy->setAlias (newKey);
243}
244
245
246void initTestStore ATLAS_NOT_THREAD_SAFE ()
247{
248 SG::CurrentEventStore::setStore (&store);
250}
251
252
253std::unique_ptr<TestStore> getTestStore()
254{
255 auto store = std::make_unique<TestStore>();
256 SG::CurrentEventStore::setStore (store.get());
258 return store;
259}
260
261
262} // 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:129
virtual const std::string * keyToString(sgkey_t) const override
Definition TestStore.cxx:31
virtual void registerKey(sgkey_t, const std::string &, CLID) override
Definition TestStore.cxx:37
virtual SG::DataProxy * recordObject(SG::DataObjectSharedPtr< DataObject > obj, const std::string &key, bool allowMods, bool returnExisting) override
Definition TestStore.cxx:45
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
void alias(SG::DataProxy *proxy, const std::string &newKey)
virtual const std::string & name() const override
Definition TestStore.cxx:96
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:25
virtual void unboundHandle(IResetable *handle) override
virtual StatusCode addToStore(CLID, SG::DataProxy *proxy) override
std::lock_guard< mutex_t > lock_t
Definition TestStore.h:135
void setProxyDictInEventContext(IProxyDict *sg)
Update the IProxyDict in the current EventContext.
TestStore store
Definition TestStore.cxx:22
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.