ATLAS Offline Software
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$
14 #include "SGTools/TestStore.h"
16 #include <iostream>
17 #include <algorithm>
18 
19 
20 namespace SGTest {
21 
22 
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 
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 
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 
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 
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 
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 
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);
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()) {
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 
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 
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 {
250 }
251 
252 
253 std::unique_ptr<TestStore> getTestStore()
254 {
255  auto store = std::make_unique<TestStore>();
257  return store;
258 }
259 
260 
261 } // namespace SGTest
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
SGTest::store
TestStore store
Definition: TestStore.cxx:23
common.sgkey
def sgkey(tool)
Definition: common.py:1028
TileDCSDataPlotter.dp
dp
Definition: TileDCSDataPlotter.py:840
SGTest
Definition: TestStore.h:26
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:392
SGTest::TestStore::boundHandle
virtual void boundHandle(IResetable *handle) override
Definition: TestStore.cxx:186
SGTest::TestStore::record1
SG::DataProxy * record1(lock_t &, const void *p, DataObject *obj, CLID clid, const std::string &key)
Definition: TestStore.cxx:203
SG::DataProxy::sgkey
sgkey_t sgkey() const
< Get the primary (hashed) SG key.
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
DataBucketBase
A non-templated base class for DataBucket, allows to access the transient object address as a void*.
Definition: DataBucketBase.h:24
DataBucketBase.h
SGTest::TestStore::lock_t
std::lock_guard< mutex_t > lock_t
Definition: TestStore.h:135
SGTest::TestStore::m_remap
remap_t m_remap
Definition: TestStore.h:125
skel.it
it
Definition: skel.GENtoEVGEN.py:396
SG::TransientAddress
Definition: TransientAddress.h:32
SG::CurrentEventStore::setStore
static IProxyDict * setStore(IProxyDict *store)
Set the current store.
Definition: CurrentEventStore.cxx:36
SGTest::TestStore::proxy_exact
virtual SG::DataProxy * proxy_exact(SG::sgkey_t sgkey) const override
Definition: TestStore.cxx:140
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::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
Definition: TestStore.h:52
SG::DataProxy::setStore
void setStore(IProxyDict *store)
Set the store of which we're a part.
SGTest::TestStore::addToStore
virtual StatusCode addToStore(CLID, SG::DataProxy *proxy) override
Definition: TestStore.cxx:176
SGTest::TestStore::proxy
virtual SG::DataProxy * proxy(const void *const pTransient) const override
Definition: TestStore.cxx:104
SGTest::TestStore::m_mutex
mutex_t m_mutex
Definition: TestStore.h:136
IResetable
a resetable object (e.g. a SG DataHandle)
Definition: IResetable.h:15
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SGTest::TestStore::m_boundHandles
std::vector< IResetable * > m_boundHandles
Definition: TestStore.h:129
SGTest::TestStore::proxies
virtual std::vector< const SG::DataProxy * > proxies() const override
Definition: TestStore.cxx:26
SGTest::sgkey_t
SG::sgkey_t sgkey_t
Definition: TestStore.h:29
SGTest::TestStore::m_tmap
tmap_t m_tmap
Definition: TestStore.h:119
SGTest::TestStore::name
virtual const std::string & name() const override
Definition: TestStore.cxx:97
SGTest::TestStore::unboundHandle
virtual void unboundHandle(IResetable *handle) override
Definition: TestStore.cxx:193
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
SG::DataProxy::clID
CLID clID() const
Retrieve clid.
TestStore.h
Dummy event store, for regression tests.
SGTest::ATLAS_NOT_THREAD_SAFE
void initTestStore ATLAS_NOT_THREAD_SAFE()
Definition: TestStore.cxx:247
SGTest::TestStore::keyToString
virtual const std::string * keyToString(sgkey_t) const override
Definition: TestStore.cxx:32
SG::DataProxy::addRef
virtual unsigned long addRef() override final
Add reference to object.
Definition: DataProxy.cxx:313
SGTest::TestStore::registerKey
virtual void registerKey(sgkey_t, const std::string &, CLID) override
Definition: TestStore.cxx:38
SG::sgkey_t
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition: CxxUtils/CxxUtils/sgkey_t.h:32
SG::DataProxy::name
virtual const name_type & name() const override final
Retrieve data object key == string.
SG::DataProxy::setAlias
void setAlias(const std::string &key)
Add a new proxy alias.
SG::DataProxy::setTransientID
void setTransientID(CLID id)
Add a new transient ID.
CalibCoolCompareRT.nm
nm
Definition: CalibCoolCompareRT.py:110
SG::DataProxy::setConst
void setConst()
Mark this object as const.
Definition: DataProxy.cxx:204
SGTest::getTestStore
std::unique_ptr< TestStore > getTestStore()
Definition: TestStore.cxx:253
SGTest::TestStore::m_kmap
kmap_t m_kmap
Definition: TestStore.h:122
SGTest::TestStore::recordObject
virtual SG::DataProxy * recordObject(SG::DataObjectSharedPtr< DataObject > obj, const std::string &key, bool allowMods, bool returnExisting) override
Definition: TestStore.cxx:46
str
Definition: BTagTrackIpAccessor.cxx:11
SGTest::TestStoreRemap
Definition: TestStore.h:33
SG::DataObjectSharedPtr
Smart pointer to manage DataObject reference counts.
Definition: DataObjectSharedPtr.h:46
python.PyAthena.obj
obj
Definition: PyAthena.py:132
SG::DataProxy
Definition: DataProxy.h:44
SGTest::TestStore::alias
void alias(SG::DataProxy *proxy, const std::string &newKey)
Definition: TestStore.cxx:236
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37