ATLAS Offline Software
Public Types | Public Member Functions | Public Attributes | List of all members
SGTest::TestStore Class Reference

#include <TestStore.h>

Inheritance diagram for SGTest::TestStore:
Collaboration diagram for SGTest::TestStore:

Public Types

typedef std::unordered_map< const void *, SG::DataProxy * > tmap_t
 
typedef SG::SGKeyMap< SG::DataProxy * > kmap_t
 
typedef std::unordered_map< TestStoreRemap, TestStoreRemap, TestStoreRemapHashremap_t
 
typedef std::mutex mutex_t
 
typedef std::lock_guard< mutex_tlock_t
 

Public Member Functions

virtual std::vector< const SG::DataProxy * > proxies () const override
 
virtual const std::string * keyToString (sgkey_t) const override
 
virtual void registerKey (sgkey_t, const std::string &, CLID) override
 
virtual const std::string & name () const override
 
virtual SG::DataProxyproxy (const void *const pTransient) const override
 
virtual SG::DataProxyproxy (const CLID &id, const std::string &key) const override
 
virtual SG::DataProxyproxy_exact (SG::sgkey_t sgkey) const override
 
virtual sgkey_t stringToKey (const std::string &str, CLID clid) override
 
virtual const std::string * keyToString (sgkey_t key, CLID &clid) const override
 
virtual bool tryELRemap (sgkey_t sgkey_in, size_t index_in, sgkey_t &sgkey_out, size_t &index_out) override
 
virtual StatusCode addToStore (CLID, SG::DataProxy *proxy) override
 
virtual void boundHandle (IResetable *handle) override
 
virtual void unboundHandle (IResetable *handle) override
 
virtual SG::DataProxyrecordObject (SG::DataObjectSharedPtr< DataObject > obj, const std::string &key, bool allowMods, bool returnExisting) override
 
template<class T >
void record (const T *p, const std::string &key)
 
template<class T >
void record (std::unique_ptr< T > up, const std::string &key)
 
void remap (sgkey_t sgkey_in, sgkey_t sgkey_out, size_t index_in=0, size_t index_out=0)
 
template<class T >
void remap (const std::string &key_in, const std::string &key_out, size_t index_in=0, size_t index_out=0)
 
void alias (SG::DataProxy *proxy, const std::string &newKey)
 
SG::DataProxyproxy (lock_t &, const void *const pTransient) const
 
SG::DataProxyproxy (lock_t &, const CLID &id, const std::string &key) const
 
SG::DataProxyrecord1 (lock_t &, const void *p, DataObject *obj, CLID clid, const std::string &key)
 

Public Attributes

tmap_t m_tmap
 
kmap_t m_kmap
 
remap_t m_remap
 
SG::StringPool m_stringPool ATLAS_THREAD_SAFE
 
std::vector< IResetable * > m_boundHandles
 
std::vector< std::pair< CLID, std::string > > m_missedProxies ATLAS_THREAD_SAFE
 
mutex_t m_mutex
 

Detailed Description

Definition at line 50 of file TestStore.h.

Member Typedef Documentation

◆ kmap_t

Definition at line 121 of file TestStore.h.

◆ lock_t

typedef std::lock_guard<mutex_t> SGTest::TestStore::lock_t

Definition at line 135 of file TestStore.h.

◆ mutex_t

typedef std::mutex SGTest::TestStore::mutex_t

Definition at line 134 of file TestStore.h.

◆ remap_t

Definition at line 124 of file TestStore.h.

◆ tmap_t

typedef std::unordered_map<const void*, SG::DataProxy*> SGTest::TestStore::tmap_t

Definition at line 118 of file TestStore.h.

Member Function Documentation

◆ addToStore()

StatusCode SGTest::TestStore::addToStore ( CLID  ,
SG::DataProxy proxy 
)
overridevirtual

Definition at line 176 of file TestStore.cxx.

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 }

◆ alias()

void SGTest::TestStore::alias ( SG::DataProxy proxy,
const std::string &  newKey 
)

Definition at line 236 of file TestStore.cxx.

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 }

◆ boundHandle()

void SGTest::TestStore::boundHandle ( IResetable handle)
overridevirtual

Definition at line 186 of file TestStore.cxx.

187 {
188  lock_t lock (m_mutex);
189  m_boundHandles.push_back (handle);
190 }

◆ keyToString() [1/2]

const std::string * SGTest::TestStore::keyToString ( sgkey_t  key,
CLID clid 
) const
overridevirtual

Definition at line 157 of file TestStore.cxx.

158 {
159  lock_t lock (m_mutex);
160  return m_stringPool.keyToString (key, clid);
161 }

◆ keyToString() [2/2]

const std::string * SGTest::TestStore::keyToString ( sgkey_t  key) const
overridevirtual

Definition at line 32 of file TestStore.cxx.

33 {
34  return m_stringPool.keyToString (key);
35 }

◆ name()

const std::string & SGTest::TestStore::name ( ) const
overridevirtual

Definition at line 97 of file TestStore.cxx.

98 {
99  static const std::string nm = "TestStore";
100  return nm;
101 }

◆ proxies()

std::vector< const SG::DataProxy * > SGTest::TestStore::proxies ( ) const
overridevirtual

Definition at line 26 of file TestStore.cxx.

27 {
28  std::cout << "proxies\n"; std::abort();
29 }

◆ proxy() [1/4]

SG::DataProxy * SGTest::TestStore::proxy ( const CLID id,
const std::string &  key 
) const
overridevirtual

Definition at line 121 of file TestStore.cxx.

122 {
123  lock_t lock (m_mutex);
124  return proxy (lock, id, key);
125 }

◆ proxy() [2/4]

SG::DataProxy * SGTest::TestStore::proxy ( const void *const  pTransient) const
overridevirtual

Definition at line 104 of file TestStore.cxx.

105 {
106  lock_t lock (m_mutex);
107  return proxy (lock, pTransient);
108 }

◆ proxy() [3/4]

SG::DataProxy * SGTest::TestStore::proxy ( lock_t ,
const CLID id,
const std::string &  key 
) const

Definition at line 129 of file TestStore.cxx.

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 }

◆ proxy() [4/4]

SG::DataProxy * SGTest::TestStore::proxy ( lock_t ,
const void *const  pTransient 
) const

Definition at line 112 of file TestStore.cxx.

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 }

◆ proxy_exact()

SG::DataProxy * SGTest::TestStore::proxy_exact ( SG::sgkey_t  sgkey) const
overridevirtual

Definition at line 140 of file TestStore.cxx.

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 }

◆ record() [1/2]

template<class T >
void SGTest::TestStore::record ( const T *  p,
const std::string &  key 
)
inline

Definition at line 81 of file TestStore.h.

82  {
83  lock_t lock (m_mutex);
84  T* p_nc ATLAS_THREAD_SAFE = const_cast<T*>(p);
85  DataObject* obj = SG::asStorable<T>(p_nc);
86  CLID clid = ClassID_traits<T>::ID();
87  record1 (lock, p, obj, clid, key);
88  }

◆ record() [2/2]

template<class T >
void SGTest::TestStore::record ( std::unique_ptr< T >  up,
const std::string &  key 
)
inline

Definition at line 92 of file TestStore.h.

93  {
94  lock_t lock (m_mutex);
95  T* p = up.get();
96  DataObject* obj = SG::asStorable<T>(std::move (up));
97  CLID clid = ClassID_traits<T>::ID();
98  record1 (lock, p, obj, clid, key);
99  }

◆ record1()

SG::DataProxy * SGTest::TestStore::record1 ( lock_t ,
const void *  p,
DataObject *  obj,
CLID  clid,
const std::string &  key 
)

Definition at line 203 of file TestStore.cxx.

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 }

◆ recordObject()

SG::DataProxy * SGTest::TestStore::recordObject ( SG::DataObjectSharedPtr< DataObject >  obj,
const std::string &  key,
bool  allowMods,
bool  returnExisting 
)
overridevirtual

Definition at line 46 of file TestStore.cxx.

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 }

◆ registerKey()

void SGTest::TestStore::registerKey ( sgkey_t  ,
const std::string &  ,
CLID   
)
overridevirtual

Definition at line 38 of file TestStore.cxx.

41 {
42  std::cout << "registerKey\n"; std::abort();
43 }

◆ remap() [1/2]

template<class T >
void SGTest::TestStore::remap ( const std::string &  key_in,
const std::string &  key_out,
size_t  index_in = 0,
size_t  index_out = 0 
)
inline

Definition at line 107 of file TestStore.h.

109  {
110  CLID clid = ClassID_traits<T>::ID();
111  sgkey_t sgkey_in = stringToKey (key_in, clid);
112  sgkey_t sgkey_out = stringToKey (key_out, clid);
113  remap (sgkey_in, sgkey_out, index_in, index_out);
114  }

◆ remap() [2/2]

void SGTest::TestStore::remap ( sgkey_t  sgkey_in,
sgkey_t  sgkey_out,
size_t  index_in = 0,
size_t  index_out = 0 
)

Definition at line 227 of file TestStore.cxx.

229 {
230  lock_t lock (m_mutex);
231  m_remap[TestStoreRemap(sgkey_in, index_in)] =
232  TestStoreRemap(sgkey_out, index_out);
233 }

◆ stringToKey()

sgkey_t SGTest::TestStore::stringToKey ( const std::string &  str,
CLID  clid 
)
overridevirtual

Definition at line 150 of file TestStore.cxx.

151 {
152  lock_t lock (m_mutex);
153  return m_stringPool.stringToKey (str, clid);
154 }

◆ tryELRemap()

bool SGTest::TestStore::tryELRemap ( sgkey_t  sgkey_in,
size_t  index_in,
sgkey_t sgkey_out,
size_t &  index_out 
)
overridevirtual

Definition at line 164 of file TestStore.cxx.

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 }

◆ unboundHandle()

void SGTest::TestStore::unboundHandle ( IResetable handle)
overridevirtual

Definition at line 193 of file TestStore.cxx.

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 }

Member Data Documentation

◆ ATLAS_THREAD_SAFE [1/2]

SG::StringPool m_stringPool SGTest::TestStore::ATLAS_THREAD_SAFE
mutable

Definition at line 127 of file TestStore.h.

◆ ATLAS_THREAD_SAFE [2/2]

std::vector<std::pair<CLID, std::string> > m_missedProxies SGTest::TestStore::ATLAS_THREAD_SAFE
mutable

Definition at line 132 of file TestStore.h.

◆ m_boundHandles

std::vector<IResetable*> SGTest::TestStore::m_boundHandles

Definition at line 129 of file TestStore.h.

◆ m_kmap

kmap_t SGTest::TestStore::m_kmap

Definition at line 122 of file TestStore.h.

◆ m_mutex

mutex_t SGTest::TestStore::m_mutex
mutable

Definition at line 136 of file TestStore.h.

◆ m_remap

remap_t SGTest::TestStore::m_remap

Definition at line 125 of file TestStore.h.

◆ m_tmap

tmap_t SGTest::TestStore::m_tmap

Definition at line 119 of file TestStore.h.


The documentation for this class was generated from the following files:
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
common.sgkey
def sgkey(tool)
Definition: common.py:1028
TileDCSDataPlotter.dp
dp
Definition: TileDCSDataPlotter.py:840
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
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
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
SG::DataProxy::setStore
void setStore(IProxyDict *store)
Set the store of which we're a part.
SGTest::TestStore::proxy
virtual SG::DataProxy * proxy(const void *const pTransient) const override
Definition: TestStore.cxx:104
ClassID_traits::ID
static const CLID & ID()
the CLID of T
Definition: Control/AthenaKernel/AthenaKernel/ClassID_traits.h:50
SGTest::TestStore::m_mutex
mutex_t m_mutex
Definition: TestStore.h:136
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
lumiFormat.i
int i
Definition: lumiFormat.py:85
SGTest::TestStore::m_boundHandles
std::vector< IResetable * > m_boundHandles
Definition: TestStore.h:129
SGTest::sgkey_t
SG::sgkey_t sgkey_t
Definition: TestStore.h:29
CalibCoolCompareRT.up
up
Definition: CalibCoolCompareRT.py:109
SGTest::TestStore::m_tmap
tmap_t m_tmap
Definition: TestStore.h:119
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.
SG::DataProxy::addRef
virtual unsigned long addRef() override final
Add reference to object.
Definition: DataProxy.cxx:313
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::ATLAS_THREAD_SAFE
SG::StringPool m_stringPool ATLAS_THREAD_SAFE
Definition: TestStore.h:127
SG::DataProxy::setConst
void setConst()
Mark this object as const.
Definition: DataProxy.cxx:204
SGTest::TestStore::m_kmap
kmap_t m_kmap
Definition: TestStore.h:122
str
Definition: BTagTrackIpAccessor.cxx:11
python.PyAthena.obj
obj
Definition: PyAthena.py:132
SG::DataProxy
Definition: DataProxy.h:45
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37