ATLAS Offline Software
Loading...
Searching...
No Matches
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"
16#include <iostream>
17#include <algorithm>
18
19
20namespace SGTest {
21
22
24
25
26std::vector<const SG::DataProxy*> TestStore::proxies() const
27{
28 std::cout << "proxies\n"; std::abort();
29}
30
31
32const std::string* TestStore::keyToString (sgkey_t key) const
33{
34 return m_stringPool.keyToString (key);
35}
36
37
39 const std::string& /*str*/,
40 CLID /*clid*/)
41{
42 std::cout << "registerKey\n"; std::abort();
43}
44
45
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
97const std::string& TestStore::name() const
98{
99 static const std::string nm = "TestStore";
100 return nm;
101}
102
103
104SG::DataProxy* TestStore::proxy(const void* const pTransient) const
105{
106 lock_t lock (m_mutex);
107 return proxy (lock, pTransient);
108}
109
110
112TestStore::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
121SG::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
129TestStore::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
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
150sgkey_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
157const 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
164bool 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
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
187{
188 lock_t lock (m_mutex);
189 m_boundHandles.push_back (handle);
190}
191
192
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
203SG::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
227void 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
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
247void initTestStore ATLAS_NOT_THREAD_SAFE ()
248{
250}
251
252
253std::unique_ptr<TestStore> getTestStore()
254{
255 auto store = std::make_unique<TestStore>();
257 return store;
258}
259
260
261} // namespace SGTest
uint32_t CLID
The Class ID type.
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:32
virtual void registerKey(sgkey_t, const std::string &, CLID) override
Definition TestStore.cxx:38
virtual SG::DataProxy * recordObject(SG::DataObjectSharedPtr< DataObject > obj, const std::string &key, bool allowMods, bool returnExisting) override
Definition TestStore.cxx:46
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:97
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:26
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
static IProxyDict * setStore(IProxyDict *store)
Set the current store.
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