ATLAS Offline Software
TestStore.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 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 unsigned long TestStore::addRef()
27 {
28  std::cout << "addRef\n"; std::abort();
29 }
30 
31 
32 unsigned long TestStore::release()
33 {
34  std::cout << "release\n"; std::abort();
35 }
36 
37 
38 StatusCode TestStore::queryInterface(const InterfaceID &/*ti*/, void** /*pp*/)
39 {
40  std::cout << "queryInterface\n"; std::abort();
41 }
42 
43 
44 std::vector<const SG::DataProxy*> TestStore::proxies() const
45 {
46  std::cout << "proxies\n"; std::abort();
47 }
48 
49 
50 const std::string* TestStore::keyToString (sgkey_t key) const
51 {
52  return m_stringPool.keyToString (key);
53 }
54 
55 
57  const std::string& /*str*/,
58  CLID /*clid*/)
59 {
60  std::cout << "registerKey\n"; std::abort();
61 }
62 
63 
65  const std::string& key,
66  bool allowMods,
67  bool returnExisting)
68 {
69  lock_t lock (m_mutex);
70  const void* raw_ptr = obj.get();
71  if (DataBucketBase* bucket = dynamic_cast<DataBucketBase*> (obj.get())) {
72  raw_ptr = bucket->object();
73  }
74 
75  CLID clid = obj->clID();
76  SG::DataProxy* proxy = this->proxy (lock, clid, key);
77  if (proxy) {
78  if (returnExisting)
79  return proxy;
80  else
81  return nullptr;
82  }
83 
84  proxy = this->proxy (lock, raw_ptr);
85  if (proxy) {
86  sgkey_t sgkey = m_stringPool.stringToKey (key, obj->clID());
87  if (!returnExisting)
88  return nullptr;
89  if (obj->clID() == proxy->clID()) {
90  // Alias?
91  m_kmap[sgkey] = proxy;
92  proxy->addRef();
93  proxy->setAlias (key);
94  return proxy;
95  }
96  if (key == proxy->name()) {
97  // Symlink?
98  m_kmap[sgkey] = proxy;
99  proxy->addRef();
100  proxy->setTransientID (obj->clID());
101  return proxy;
102  }
103 
104  // Error.
105  return nullptr;
106  }
107 
108  proxy = record1 (lock, raw_ptr, obj.get(), clid, key);
109  if (!allowMods)
110  proxy->setConst();
111  return proxy;
112 }
113 
114 
115 const std::string& TestStore::name() const
116 {
117  static const std::string nm = "TestStore";
118  return nm;
119 }
120 
121 
122 SG::DataProxy* TestStore::proxy(const void* const pTransient) const
123 {
124  lock_t lock (m_mutex);
125  return proxy (lock, pTransient);
126 }
127 
128 
130 TestStore::proxy(lock_t&, const void* const pTransient) const
131 {
132  tmap_t::const_iterator i = m_tmap.find (pTransient);
133  if (i != m_tmap.end())
134  return i->second;
135  return 0;
136 }
137 
138 
139 SG::DataProxy* TestStore::proxy(const CLID& id, const std::string& key) const
140 {
141  lock_t lock (m_mutex);
142  return proxy (lock, id, key);
143 }
144 
145 
147 TestStore::proxy(lock_t&, const CLID& id, const std::string& key) const
148 {
149  sgkey_t sgkey = m_stringPool.stringToKey (key, id);
150  kmap_t::const_iterator i = m_kmap.find (sgkey);
151  if (i != m_kmap.end())
152  return i->second;
153  m_missedProxies.emplace_back (id, key);
154  return 0;
155 }
156 
157 
159 {
160  lock_t lock (m_mutex);
161  kmap_t::const_iterator i = m_kmap.find (sgkey);
162  if (i != m_kmap.end())
163  return i->second;
164  return 0;
165 }
166 
167 
168 sgkey_t TestStore::stringToKey (const std::string& str, CLID clid)
169 {
170  lock_t lock (m_mutex);
171  return m_stringPool.stringToKey (str, clid);
172 }
173 
174 
175 const std::string* TestStore::keyToString (sgkey_t key, CLID& clid) const
176 {
177  lock_t lock (m_mutex);
178  return m_stringPool.keyToString (key, clid);
179 }
180 
181 
182 bool TestStore::tryELRemap (sgkey_t sgkey_in, size_t index_in,
183  sgkey_t& sgkey_out, size_t& index_out)
184 {
185  lock_t lock (m_mutex);
186  remap_t::iterator i = m_remap.find (TestStoreRemap (sgkey_in, index_in));
187  if (i == m_remap.end()) return false;
188  sgkey_out = i->second.key;
189  index_out = i->second.index;
190  return true;
191 }
192 
193 
195 {
196  lock_t lock (m_mutex);
197  proxy->setStore (this);
198  m_kmap[proxy->sgkey()] = proxy;
199  proxy->addRef();
200  return StatusCode::SUCCESS;
201 }
202 
203 
205 {
206  lock_t lock (m_mutex);
207  m_boundHandles.push_back (handle);
208 }
209 
210 
212 {
213  lock_t lock (m_mutex);
215  std::find (m_boundHandles.begin(), m_boundHandles.end(), handle);
216  if (it != m_boundHandles.end())
217  m_boundHandles.erase (it);
218 }
219 
220 
221 SG::DataProxy* TestStore::record1 (lock_t&, const void* p, DataObject* obj,
222  CLID clid, const std::string& key)
223 {
224  sgkey_t sgkey = m_stringPool.stringToKey (key, clid);
225  if (m_kmap.find (sgkey) != m_kmap.end()) {
227  dp->setObject (obj);
228  if (dp->clID() == CLID_NULL)
229  dp->setID (clid, key);
230  m_tmap[p] = dp;
231  return dp;
232  }
233 
235  dp->setStore (this);
236  m_tmap[p] = dp;
237 
238  m_kmap[sgkey] = dp;
239  dp->addRef();
240  dp->setSGKey (sgkey);
241  return dp;
242 }
243 
244 
245 void TestStore::remap (sgkey_t sgkey_in, sgkey_t sgkey_out,
246  size_t index_in, size_t index_out)
247 {
248  lock_t lock (m_mutex);
249  m_remap[TestStoreRemap(sgkey_in, index_in)] =
250  TestStoreRemap(sgkey_out, index_out);
251 }
252 
253 
255  const std::string& newKey)
256 {
257  lock_t lock (m_mutex);
258  sgkey_t sgkey = m_stringPool.stringToKey (newKey, proxy->clID());
259  m_kmap[sgkey] = proxy;
260  proxy->addRef();
261  proxy->setAlias (newKey);
262 }
263 
264 
265 void initTestStore ATLAS_NOT_THREAD_SAFE ()
266 {
268 }
269 
270 
271 std::unique_ptr<TestStore> getTestStore()
272 {
273  auto store = std::make_unique<TestStore>();
275  return store;
276 }
277 
278 
279 } // 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
SGTest::TestStore::release
virtual unsigned long release() override
Definition: TestStore.cxx:32
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:392
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
SGTest::TestStore::boundHandle
virtual void boundHandle(IResetable *handle) override
Tell the store that a handle has been bound to a proxy.
Definition: TestStore.cxx:204
SGTest::TestStore::record1
SG::DataProxy * record1(lock_t &, const void *p, DataObject *obj, CLID clid, const std::string &key)
Definition: TestStore.cxx:221
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:139
SGTest::TestStore::m_remap
remap_t m_remap
Definition: TestStore.h:129
skel.it
it
Definition: skel.GENtoEVGEN.py:423
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
Get proxy given a hashed key+clid.
Definition: TestStore.cxx:158
SGTest::TestStore::tryELRemap
virtual bool tryELRemap(sgkey_t sgkey_in, size_t index_in, sgkey_t &sgkey_out, size_t &index_out) override
Test to see if the target of an ElementLink has moved.
Definition: TestStore.cxx:182
SGTest::TestStore::stringToKey
virtual sgkey_t stringToKey(const std::string &str, CLID clid) override
Find the key for a string/CLID pair.
Definition: TestStore.cxx:168
IStringPool::sgkey_t
SG::sgkey_t sgkey_t
Type of the keys.
Definition: IStringPool.h:34
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:245
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
Add a new proxy to the store.
Definition: TestStore.cxx:194
SGTest::TestStore::proxy
virtual SG::DataProxy * proxy(const void *const pTransient) const override
Get a proxy referencing a given transient object.
Definition: TestStore.cxx:122
SGTest::TestStore::m_mutex
mutex_t m_mutex
Definition: TestStore.h:140
IResetable
a resetable object (e.g. a SG DataHandle)
Definition: IResetable.h:15
SGTest::TestStore::addRef
virtual unsigned long addRef() override
Definition: TestStore.cxx:26
lumiFormat.i
int i
Definition: lumiFormat.py:92
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:133
SGTest::TestStore::proxies
virtual std::vector< const SG::DataProxy * > proxies() const override
Return the list of all current proxies in store.
Definition: TestStore.cxx:44
SGTest::TestStore::m_tmap
tmap_t m_tmap
Definition: TestStore.h:123
SGTest::TestStore::name
virtual const std::string & name() const override
Definition: TestStore.cxx:115
SGTest::TestStore::unboundHandle
virtual void unboundHandle(IResetable *handle) override
Tell the store that a handle has been unbound from a proxy.
Definition: TestStore.cxx:211
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:265
SGTest::TestStore::keyToString
virtual const std::string * keyToString(sgkey_t) const override
Find the string corresponding to a given key.
Definition: TestStore.cxx:50
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
Remember an additional mapping from key to string/CLID.
Definition: TestStore.cxx:56
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
SGTest::TestStore::queryInterface
virtual StatusCode queryInterface(const InterfaceID &, void **) override
Definition: TestStore.cxx:38
SG::DataProxy::setConst
void setConst()
Mark this object as const.
Definition: DataProxy.cxx:204
SGTest::getTestStore
std::unique_ptr< TestStore > getTestStore()
Definition: TestStore.cxx:271
SGTest::TestStore::m_kmap
kmap_t m_kmap
Definition: TestStore.h:126
SGTest::TestStore::recordObject
virtual SG::DataProxy * recordObject(SG::DataObjectSharedPtr< DataObject > obj, const std::string &key, bool allowMods, bool returnExisting) override
Record an object in the store.
Definition: TestStore.cxx:64
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:135
SG::DataProxy
Definition: DataProxy.h:44
SGTest::TestStore::alias
void alias(SG::DataProxy *proxy, const std::string &newKey)
Definition: TestStore.cxx:254
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37