ATLAS Offline Software
Loading...
Searching...
No Matches
xAOD::TPyStore Class Reference

Python interface to xAOD::TStore. More...

#include <TPyStore.h>

Inheritance diagram for xAOD::TPyStore:
Collaboration diagram for xAOD::TPyStore:

Public Member Functions

bool pyContains (const std::string &key, const std::string &type) const
 Function checking if an object with a given key and type is available.
bool pyIsConst (const std::string &key, const std::string &type) const
 Function checking if an object with a given key and type is constant.
StatusCode pyRecord (void *obj, const std::string &key, const std::string &type)
 Record an object into the store in a typeless way.
void dump () const
 Print the contents of the store using a Python friendly function.
 TStore ()
 Inherit the constructor(s) of xAOD::TStore.
 TStore (const TStore &)=delete
 Inherit the constructor(s) of xAOD::TStore.
void setActive ()
 Set this as the active transient store in the application.
void print () const
 Print the current contents of the transient store.
Transient data accessor/modifier functions
template<typename T>
::Bool_t contains (const std::string &key) const
 Function checking if an object is available from the store.
template<typename T>
::Bool_t isConst (const std::string &key) const
 Function checking if an object with a given type is constant.
template<typename T>
StatusCode retrieve (const T *&obj, const std::string &key) const
 Retrieve either a constant or non-constant object from the store.
template<typename T>
StatusCode retrieve (T *&obj, const std::string &key) const
 Retrieve a non-constant object from the store.
template<typename T>
StatusCode record (T *obj, const std::string &key)
 Add an object to the store.
template<typename T>
StatusCode record (std::unique_ptr< T > obj, const std::string &key)
 Add an object to the store, explicitly taking ownership of it.
template<typename T>
StatusCode record (const T *obj, const std::string &key)
 Add a const object to the store.
template<typename T>
StatusCode record (std::unique_ptr< const T > obj, const std::string &key)
 Add a const object to the store, explicitly taking ownership of it.
template<typename T>
void keys (std::vector< std::string > &vkeys) const
 provide a list of keys associated with a type
const THolderholder (const std::string &key) const
 return holder for key
StatusCode remove (const std::string &key)
 Remove an object from the store by name.
StatusCode remove (void *ptr)
 Remove an object from the store by pointer.
void clear ()
 Clear the store of all of its contents.

Protected Types

typedef std::map< std::string, THolder * > Objects_t
 Type of the internal container storing all the objects.
typedef SG::SGKeyMap< std::string > HashedKeys_t
 Type of the internal storage for the hashed keys of the object names.

Protected Member Functions

::Bool_t contains (const std::string &key, const std::type_info &ti) const
 Non-templated function implementing the containment check.
::Bool_t isConst (const std::string &key, const std::type_info &ti) const
 Non-templated function implementing the const-ness check.
StatusCode record (void *obj, const std::string &key, const std::string &classname, ::Bool_t isOwner, ::Bool_t isConst)
 Function recording an object that has a dictionary available.
StatusCode record (void *obj, const std::string &key, const std::type_info &ti, ::Bool_t isOwner, ::Bool_t isConst)
 Function recording an object that has no dictionary.
template<class T>
StatusCode record (ConstDataVector< T > *obj, const std::string &key, const std::type_info &ti, ::Bool_t isOwner, ::Bool_t isConst)
 Function doing the first step of recording a ConstDataVector object.
StatusCode record (THolder *hldr, const std::string &key)
 Function doing the second step of recording a ConstDataVector object.
void * getObject (const std::string &key, const std::type_info &ti) const
 Function retrieving a non-const object in a non-template way.
const void * getConstObject (const std::string &key, const std::type_info &ti) const
 Function retrieving a const object in a non-template way.
Functions mostly used by TEvent in the TVirtualEvent functions
::Bool_t contains (SG::sgkey_t hash) const
 Check if an object with a given hash is managed by the store.
::Bool_t contains (const void *ptr) const
 Check if an object with a given pointer is managed by the store.
const std::string & getName (SG::sgkey_t hash) const
 Get the name corresponding to a hashed key.
const std::string & getName (const void *ptr) const
 Get the name of a managed object.
void getNames (const std::string &targetClassName, std::vector< std::string > &vkeys) const
 Function determining the list keys associated with a type name.

Protected Attributes

Objects_t m_objects
 The object storage.
HashedKeys_t m_keys
 The key map.

Private Member Functions

template<typename T>
StatusCode record_impl (T *obj, const std::string &key, ::Bool_t isOwner, ::Bool_t isConst)
 Internal implementation of the templated record method.

Detailed Description

Python interface to xAOD::TStore.

In order to make it possible to record objects that are created in Python, into an xAOD::TStore object (to be able to pass it to some tools that expect the object to be in the event for instance), this class extends the xAOD::TStore object with some non-template functions. Functions that are inconvenient to use from C++, but which allow for much more flexibility in PyROOT.

Author
Attila Krasznahorkay Attil.nosp@m.a.Kr.nosp@m.aszna.nosp@m.hork.nosp@m.ay@ce.nosp@m.rn.c.nosp@m.h

Definition at line 27 of file TPyStore.h.

Member Typedef Documentation

◆ HashedKeys_t

typedef SG::SGKeyMap< std::string > xAOD::TStore::HashedKeys_t
protectedinherited

Type of the internal storage for the hashed keys of the object names.

Definition at line 166 of file TStore.h.

◆ Objects_t

typedef std::map< std::string, THolder* > xAOD::TStore::Objects_t
protectedinherited

Type of the internal container storing all the objects.

Definition at line 164 of file TStore.h.

Member Function Documentation

◆ clear()

void xAOD::TStore::clear ( )
inherited

Clear the store of all of its contents.

Definition at line 105 of file TStore.cxx.

105 {
106
107 // Delete all the managed objects:
108 Objects_t::iterator itr = m_objects.begin();
109 Objects_t::iterator end = m_objects.end();
110 for( ; itr != end; ++itr ) {
111 delete itr->second;
112 }
113
114 // And clear the maps:
115 m_objects.clear();
116 m_keys.clear();
117
118 return;
119 }
HashedKeys_t m_keys
The key map.
Definition TStore.h:171
Objects_t m_objects
The object storage.
Definition TStore.h:169

◆ contains() [1/4]

template<typename T>
::Bool_t xAOD::TStore::contains ( const std::string & key) const
inherited

Function checking if an object is available from the store.

◆ contains() [2/4]

Bool_t xAOD::TStore::contains ( const std::string & key,
const std::type_info & ti ) const
protectedinherited

Non-templated function implementing the containment check.

Definition at line 152 of file TStore.cxx.

153 {
154
155 // Look up this object:
156 Objects_t::const_iterator itr = m_objects.find( key );
157 if( itr == m_objects.end() ) {
158 return kFALSE;
159 }
160
161 // Check if the object is of the right type:
162 return itr->second->getAsConst( ti, kTRUE );
163 }

◆ contains() [3/4]

Bool_t xAOD::TStore::contains ( const void * ptr) const
protectedinherited

Check if an object with a given pointer is managed by the store.

This is a quite slow function.

It needs to check each managed object to possibly find which one of them has this pointer.

Parameters
ptrPointer to the object that may or may not be in the store
Returns
kTRUE if the object is managed by the store, or kFALSE if it isn't

Definition at line 343 of file TStore.cxx.

343 {
344
345 // Loop over all the managed objects:
346 Objects_t::const_iterator itr = m_objects.begin();
347 Objects_t::const_iterator end = m_objects.end();
348 for( ; itr != end; ++itr ) {
349 // Check if this is the right object:
350 if( itr->second->get() == ptr ) {
351 return kTRUE;
352 }
353 }
354
355 // We didn't find it:
356 return kFALSE;
357 }

◆ contains() [4/4]

Bool_t xAOD::TStore::contains ( SG::sgkey_t hash) const
protectedinherited

Check if an object with a given hash is managed by the store.

This is a reasonably fast function.

It checks whether an object with the specified hashed key is managed by the store.

Parameters
hashThe hashed key of the object that we are looking for
Returns
kTRUE if the object is managed by the store, or kFALSE if it is not

Definition at line 330 of file TStore.cxx.

330 {
331
332 // Do the check quickly:
333 return ( m_keys.find( hash ) != m_keys.end() );
334 }

◆ dump()

void xAOD::TPyStore::dump ( ) const

Print the contents of the store using a Python friendly function.

This is just a convenience function, to make it easier to print the contents of such objects in Python.

Since the base class's print() function has a special meaning in Python.

Definition at line 121 of file TPyStore.cxx.

121 {
122
123 print();
124 return;
125}
void print() const
Print the current contents of the transient store.
Definition TStore.cxx:124

◆ getConstObject()

const void * xAOD::TStore::getConstObject ( const std::string & key,
const std::type_info & ti ) const
protectedinherited

Function retrieving a const object in a non-template way.

Definition at line 211 of file TStore.cxx.

212 {
213
214 // Look up this object:
215 Objects_t::const_iterator itr = m_objects.find( key );
216 if( itr == m_objects.end() ) {
217 return 0;
218 }
219
220 // Try to retrieve it as the requested type:
221 return itr->second->getAsConst( ti );
222 }

◆ getName() [1/2]

const std::string & xAOD::TStore::getName ( const void * ptr) const
protectedinherited

Get the name of a managed object.

This is just as slow as the previous contains function.

It needs to look at all the managed objects one by one to find under what name it is managed.

Parameters
ptrPointer to the object that we want to know the name of
Returns
The name with which this object was recorded into the store. Or an empty string of the object is not known to the store.

Definition at line 390 of file TStore.cxx.

390 {
391
392 // Loop over all the managed objects:
393 Objects_t::const_iterator itr = m_objects.begin();
394 Objects_t::const_iterator end = m_objects.end();
395 for( ; itr != end; ++itr ) {
396 // Check if this is the right object:
397 if( itr->second->get() == ptr ) {
398 return itr->first;
399 }
400 }
401
402 // We didn't find the object:
403 ::Warning( "xAOD::TStore::getName", "Object %p is not held by the store",
404 ptr );
405 static const std::string dummy( "" );
406 return dummy;
407 }

◆ getName() [2/2]

const std::string & xAOD::TStore::getName ( SG::sgkey_t hash) const
protectedinherited

Get the name corresponding to a hashed key.

This is a fairly fast function.

Used by ElementLinks that point to objects in this store.

Parameters
hashThe hashed key for which we want to find the string key
Returns
The name corresponding to this hashed key if the hashed key is known, or an empty string if it isn't.

Definition at line 366 of file TStore.cxx.

366 {
367
368 // Try to find the name associated with this key:
369 HashedKeys_t::const_iterator itr = m_keys.find( hash );
370 if( itr != m_keys.end() ) {
371 // We found it:
372 return itr->second;
373 }
374
375 // We didn't find it:
376 ::Warning( "xAOD::TStore::getName", "Key 0x%08x not known by the store",
377 hash );
378 static const std::string dummy( "" );
379 return dummy;
380 }

◆ getNames()

void xAOD::TStore::getNames ( const std::string & targetClassName,
std::vector< std::string > & vkeys ) const
protectedinherited

Function determining the list keys associated with a type name.

Definition at line 409 of file TStore.cxx.

410 {
411 std::set< std::string > keys;
412
413 for ( const auto& pair : m_objects ) {
414 const std::string& key = pair.first;
415 const ::TClass* cl = pair.second->getClass();
416 const std::type_info* ti = pair.second->getTypeInfo();
417 std::string typeName;
418 if (cl)
419 typeName = cl->GetName();
420 else if (ti)
422
423 if (!typeName.empty() && typeName == targetTypeName)
424 keys.insert( key );
425 }
426
427 vkeys.insert( vkeys.end(), keys.begin(), keys.end() );
428 }
void keys(std::vector< std::string > &vkeys) const
provide a list of keys associated with a type
std::string normalizedTypeinfoName(const std::type_info &info)
Convert a type_info to a normalized string representation (matching the names used in the root dictio...
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]

◆ getObject()

void * xAOD::TStore::getObject ( const std::string & key,
const std::type_info & ti ) const
protectedinherited

Function retrieving a non-const object in a non-template way.

Definition at line 191 of file TStore.cxx.

192 {
193
194 // Look up this object:
195 Objects_t::const_iterator itr = m_objects.find( key );
196 if( itr == m_objects.end() ) {
197 return 0;
198 }
199
200 if( itr->second->isConst() ) {
201 ::Error( "xAOD::TStore::getObject",
202 XAOD_MESSAGE( "Cannot retrieve object with key \"%s\" of type %s as non-const" ),
203 key.c_str(), SG::normalizedTypeinfoName( ti ).c_str() );
204 return nullptr;
205 }
206
207 // Try to retrieve it as the requested type:
208 return itr->second->getAs( ti );
209 }
#define XAOD_MESSAGE(MESSAGE)
Simple macro for printing error/verbose messages.

◆ holder()

const THolder * xAOD::TStore::holder ( const std::string & key) const
inherited

return holder for key

Definition at line 50 of file TStore.cxx.

50 {
51 // Look up this object:
52 Objects_t::const_iterator itr = m_objects.find( key );
53 return (itr != m_objects.end() ? itr->second : nullptr);
54 }

◆ isConst() [1/2]

template<typename T>
::Bool_t xAOD::TStore::isConst ( const std::string & key) const
inherited

Function checking if an object with a given type is constant.

◆ isConst() [2/2]

Bool_t xAOD::TStore::isConst ( const std::string & key,
const std::type_info & ti ) const
protectedinherited

Non-templated function implementing the const-ness check.

Definition at line 165 of file TStore.cxx.

166 {
167
168 // Look up this object:
169 Objects_t::const_iterator itr = m_objects.find( key );
170 if( itr == m_objects.end() ) {
171 ::Warning( "xAOD::TStore::isConst",
172 "Object with key \"%s\" not available in store",
173 key.c_str() );
174 return kFALSE;
175 }
176
177 // Check if it can even be retrieved as a constant object of this type:
178 if( ! itr->second->getAsConst( ti, kTRUE ) ) {
179 const std::string typeName = SG::normalizedTypeinfoName( ti );
180 ::Warning( "xAOD::TStore::isConst",
181 "Object with key \"%s\" can't be retrieved as type: %s",
182 key.c_str(), typeName.c_str() );
183 return kFALSE;
184 }
185
186 // Now the question is just whether it can be retrieved as a non-const
187 // object as well:
188 return ( ! itr->second->getAs( ti, kTRUE ) );
189 }

◆ keys()

template<typename T>
void xAOD::TStore::keys ( std::vector< std::string > & vkeys) const
inherited

provide a list of keys associated with a type

◆ print()

void xAOD::TStore::print ( ) const
inherited

Print the current contents of the transient store.

This is really just meant for debugging an analysis code, to see what's going on in it.

Behaves a bit similar to StoreGateSvc::dump().

Definition at line 124 of file TStore.cxx.

124 {
125
126 ::Info( "xAOD::TStore::print", "Contents of transient store:" );
127 Objects_t::const_iterator itr = m_objects.begin();
128 Objects_t::const_iterator end = m_objects.end();
129 for( ; itr != end; ++itr ) {
130 ::Info( "xAOD::TStore::print", "-----------------------------------" );
131 ::Info( "xAOD::TStore::print", " Name: %s", itr->first.c_str() );
132 const ::TClass* cl = itr->second->getClass();
133 const std::type_info* ti = itr->second->getTypeInfo();
134 ::Info( "xAOD::TStore::print", " Type: %s",
135 ( cl ? cl->GetName() :
136 ( ti ? SG::normalizedTypeinfoName( *ti ).c_str() :
137 "Unknown" ) ) );
138 ::Info( "xAOD::TStore::print", " Pointer: %p",
139 itr->second->get() );
140 ::Info( "xAOD::TStore::print", " IsOwner: %s",
141 ( itr->second->isOwner() ? "Yes" : "No" ) );
142 ::Info( "xAOD::TStore::print", " IsConst: %s",
143 ( itr->second->isConst() ? "Yes" : "No" ) );
144 ::Info( "xAOD::TStore::print", " HasDictionary: %s",
145 ( cl ? "Yes" : "No" ) );
146 }
147 ::Info( "xAOD::TStore::print", "-----------------------------------" );
148
149 return;
150 }

◆ pyContains()

bool xAOD::TPyStore::pyContains ( const std::string & key,
const std::string & type ) const

Function checking if an object with a given key and type is available.

This function can be used in the same manner as TStore::contains<...>(...), but instead of providing a type, one gives it a type name.

Note that only types that have a proper ROOT dictionary can be used. Unlike C++, which allows one to insert any type of object into TStore.

Parameters
keyThe key of the object that we're looking for
typeThe type name of the object we're trying to access
Returns
true if the object is acessible, false otherwise

Definition at line 28 of file TPyStore.cxx.

29 {
30
31 // Try to access the dictionary of this type.
32 ::TClass* cl = ::TClass::GetClass(type.c_str());
33 if (cl == nullptr) {
34 ::Warning("xAOD::TPyStore::pyContains", "Type name \"%s\" not known",
35 type.c_str());
36 return false;
37 }
38
39 // Check if the dictionary can return a type_info.
40 const std::type_info* ti = cl->GetTypeInfo();
41 if (!ti) {
42 ::Warning("xAOD::TPyStore::pyContains",
43 "Type \"%s\" doesn't have a proper dictionary", type.c_str());
44 return false;
45 }
46
47 // Use the base class to answer the question.
48 return TStore::contains(key, *ti);
49}
::Bool_t contains(const std::string &key) const
Function checking if an object is available from the store.

◆ pyIsConst()

bool xAOD::TPyStore::pyIsConst ( const std::string & key,
const std::string & type ) const

Function checking if an object with a given key and type is constant.

This function can be used in the same manner as TStore::isConst<...>(...), but instead of providing a type, one gives it a type name.

Note that only types that have a proper ROOT dictionary can be used. Unlike C++, which allows one to insert any type of object into TStore.

Parameters
keyThe key of the object that we're looking for
typeThe type name of the object we're trying to access
Returns
true if the object is acessible, false otherwise

Definition at line 63 of file TPyStore.cxx.

64 {
65
66 // Try to access the dictionary of this type.
67 ::TClass* cl = ::TClass::GetClass(type.c_str());
68 if (cl == nullptr) {
69 ::Warning("xAOD::TPyStore::pyIsConst", "Type name \"%s\" not known",
70 type.c_str());
71 return false;
72 }
73
74 // Check if the dictionary can return a type_info.
75 const std::type_info* ti = cl->GetTypeInfo();
76 if (ti == nullptr) {
77 ::Warning("xAOD::TPyStore::pyIsConst",
78 "Type \"%s\" doesn't have a proper dictionary", type.c_str());
79 return false;
80 }
81
82 // Use the base class to answer the question.
83 return TStore::isConst(key, *ti);
84}
::Bool_t isConst(const std::string &key) const
Function checking if an object with a given type is constant.

◆ pyRecord()

StatusCode xAOD::TPyStore::pyRecord ( void * obj,
const std::string & key,
const std::string & type )

Record an object into the store in a typeless way.

This function can be used in the same manner as TStore::record<...>(...), but instead of providing a type, one gives it a type name and a typeless pointer.

Note that only types that have a proper ROOT dictionary can be used. Unlike C++, which allows one to insert any type of object into TStore.

Also note that this function doesn't take ownership of the recorded object. In Python all the objects created by the interpreter are managed by the interpreter. So this code is not supposed to delete them, otherwise all hell breaks loose.

Parameters
objPointer to the object to be put into the store
keyKey of the object in the store
typeThe type name of the object we are inserting
Returns
The usual StatusCode types

Definition at line 103 of file TPyStore.cxx.

104 {
105
106 // Simply forward the call to the appropriate function from the base
107 // class.
108 static constexpr bool IS_OWNER = true;
109 static constexpr bool IS_CONST = false;
110 RETURN_CHECK("xAOD::TPyStore::pyRecord",
111 TStore::record(obj, key, type, IS_OWNER, IS_CONST));
112
113 // Return gracefully:
114 return StatusCode::SUCCESS;
115}
#define RETURN_CHECK(CONTEXT, EXP)
Helper macro for checking return codes in a compact form in the code.
Definition ReturnCheck.h:26
StatusCode record(T *obj, const std::string &key)
Add an object to the store.

◆ record() [1/8]

template<typename T>
StatusCode xAOD::TStore::record ( const T * obj,
const std::string & key )
inherited

Add a const object to the store.

◆ record() [2/8]

template<class T>
StatusCode xAOD::TStore::record ( ConstDataVector< T > * obj,
const std::string & key,
const std::type_info & ti,
::Bool_t isOwner,
::Bool_t isConst )
protectedinherited

Function doing the first step of recording a ConstDataVector object.

◆ record() [3/8]

template<typename T>
StatusCode xAOD::TStore::record ( std::unique_ptr< const T > obj,
const std::string & key )
inherited

Add a const object to the store, explicitly taking ownership of it.

◆ record() [4/8]

template<typename T>
StatusCode xAOD::TStore::record ( std::unique_ptr< T > obj,
const std::string & key )
inherited

Add an object to the store, explicitly taking ownership of it.

◆ record() [5/8]

template<typename T>
StatusCode xAOD::TStore::record ( T * obj,
const std::string & key )
inherited

Add an object to the store.

◆ record() [6/8]

StatusCode xAOD::TStore::record ( THolder * hldr,
const std::string & key )
protectedinherited

Function doing the second step of recording a ConstDataVector object.

Definition at line 303 of file TStore.cxx.

303 {
304
305 // Make sure that the key is not yet taken:
306 if( m_objects.find( key ) != m_objects.end() ) {
307 ::Error( "xAOD::TStore::record",
308 XAOD_MESSAGE( "Trying to overwrite object with key \"%s\"" ),
309 key.c_str() );
310 // We delete the holder object at this point. It's quite ugly in terms
311 // of code readibility, but it results in fewer characters in the
312 // template code...
313 delete hldr;
314 return StatusCode::FAILURE;
315 }
316
317 // Register the new object:
318 m_objects[ key ] = hldr;
319 m_keys[ Utils::hash( key ) ] = key;
320 return StatusCode::SUCCESS;
321 }
SG::sgkey_t hash(const std::string &name)
This function provides a hashed version of the key (branch) names used in the xAOD file,...

◆ record() [7/8]

StatusCode xAOD::TStore::record ( void * obj,
const std::string & key,
const std::string & classname,
::Bool_t isOwner,
::Bool_t isConst )
protectedinherited

Function recording an object that has a dictionary available.

This internal function does the heavy lifting of recording objects into the store that have a proper ROOT dictionary.

Parameters
objTypeless pointer to the object being recorded
keyKey to record the object with
classnameThe type name of the object being recorded
isOwnerIf kTRUE, the store takes ownership of the object, otherwise it doesn't
Returns
The usual StatusCode types

Definition at line 234 of file TStore.cxx.

236 {
237
238 // Cache
239 using clCache_t = CxxUtils::ConcurrentStrMap<::TClass*, CxxUtils::SimpleUpdater>;
240 static clCache_t clMap ATLAS_THREAD_SAFE {clCache_t::Updater_t()};
241
242 // First check if we have this dictionary cached already:
243 ::TClass* cl = 0;
244 auto clItr = clMap.find( classname );
245 if( clItr != clMap.end() ) {
246 // If the cached value doesn't work, then bail now:
247 if( ( ! clItr->second ) || ( ! clItr->second->IsLoaded() ) ) {
248 return StatusCode::RECOVERABLE;
249 }
250 // Otherwise we're done:
251 cl = clItr->second;
252 }
253
254 // If it's not cached, ask ROOT for it:
255 if( ! cl ) {
256 cl = ::TClass::GetClass( classname.c_str(), kTRUE, kTRUE );
257 clMap.emplace( classname, cl );
258 }
259 if( ( ! cl ) || ( ! cl->IsLoaded() ) ) {
260 return StatusCode::RECOVERABLE;
261 }
262
263 // Make sure that the key is not yet taken:
264 if( m_objects.find( key ) != m_objects.end() ) {
265 ::Error( "xAOD::TStore::record",
266 XAOD_MESSAGE( "Trying to overwrite object with key \"%s\"" ),
267 key.c_str() );
268 return StatusCode::FAILURE;
269 }
270
271 // Register the new object:
272 if( isConst )
273 m_objects[ key ] = new THolder( const_cast<const void*>(obj), cl, isOwner );
274 else
275 m_objects[ key ] = new THolder( obj, cl, isOwner);
276
277 m_keys[ Utils::hash( key ) ] = key;
278 return StatusCode::SUCCESS;
279 }
#define ATLAS_THREAD_SAFE

◆ record() [8/8]

StatusCode xAOD::TStore::record ( void * obj,
const std::string & key,
const std::type_info & ti,
::Bool_t isOwner,
::Bool_t isConst )
protectedinherited

Function recording an object that has no dictionary.

Definition at line 281 of file TStore.cxx.

283 {
284
285 // Make sure that the key is not yet taken:
286 if( m_objects.find( key ) != m_objects.end() ) {
287 ::Error( "xAOD::TStore::record",
288 XAOD_MESSAGE( "Trying to overwrite object with key \"%s\"" ),
289 key.c_str() );
290 return StatusCode::FAILURE;
291 }
292
293 // Register the new object:
294 if( isConst )
295 m_objects[ key ] = new THolder( const_cast<const void*>(obj), ti, isOwner );
296 else
297 m_objects[ key ] = new THolder( obj, ti, isOwner );
298
299 m_keys[ Utils::hash( key ) ] = key;
300 return StatusCode::SUCCESS;
301 }

◆ record_impl()

template<typename T>
StatusCode xAOD::TStore::record_impl ( T * obj,
const std::string & key,
::Bool_t isOwner,
::Bool_t isConst )
privateinherited

Internal implementation of the templated record method.

◆ remove() [1/2]

StatusCode xAOD::TStore::remove ( const std::string & key)
inherited

Remove an object from the store by name.

Definition at line 57 of file TStore.cxx.

57 {
58
59 // Look up this object:
60 Objects_t::iterator itr = m_objects.find( key );
61 if( itr == m_objects.end() ) {
62 ::Warning( "xAOD::TStore::remove",
63 "Couldn't find object with key \"%s\"",
64 key.c_str() );
65 return StatusCode::RECOVERABLE;
66 }
67
68 // Delete the hoder object:
69 delete itr->second;
70
71 // Now remove this element from the maps:
72 m_objects.erase( itr );
73 m_keys.erase( Utils::hash( key ) );
74
75 // We were successful:
76 return StatusCode::SUCCESS;
77 }

◆ remove() [2/2]

StatusCode xAOD::TStore::remove ( void * ptr)
inherited

Remove an object from the store by pointer.

Definition at line 79 of file TStore.cxx.

79 {
80
81 // Look for this object:
82 Objects_t::iterator itr = m_objects.begin();
83 Objects_t::iterator end = m_objects.end();
84 for( ; itr != end; ++itr ) {
85
86 // Check if this is the object in question:
87 if( itr->second->get() != ptr ) {
88 continue;
89 }
90
91 // Yes, it is...
92 delete itr->second;
93 m_keys.erase( Utils::hash( itr->first ) );
94 m_objects.erase( itr );
95 return StatusCode::SUCCESS;
96 }
97
98 // We didn't find the object in the store:
99 ::Warning( "xAOD::TStore::remove",
100 "Couldn't find object with pointer %p",
101 ptr );
102 return StatusCode::RECOVERABLE;
103 }

◆ retrieve() [1/2]

template<typename T>
StatusCode xAOD::TStore::retrieve ( const T *& obj,
const std::string & key ) const
inherited

Retrieve either a constant or non-constant object from the store.

◆ retrieve() [2/2]

template<typename T>
StatusCode xAOD::TStore::retrieve ( T *& obj,
const std::string & key ) const
inherited

Retrieve a non-constant object from the store.

◆ setActive()

void xAOD::TStore::setActive ( )
inherited

Set this as the active transient store in the application.

Definition at line 43 of file TStore.cxx.

43 {
44
46 return;
47 }
static void setStore(TStore *ptr)
Set the active store pointer.

◆ TStore() [1/2]

xAOD::TStore::TStore ( )

Inherit the constructor(s) of xAOD::TStore.

Definition at line 53 of file TStore.cxx.

25 : m_objects(), m_keys() {
26
27 setActive();
28 }
void setActive()
Set this as the active transient store in the application.
Definition TStore.cxx:43

◆ TStore() [2/2]

xAOD::TStore::TStore ( const TStore & )
delete

Inherit the constructor(s) of xAOD::TStore.

Member Data Documentation

◆ m_keys

HashedKeys_t xAOD::TStore::m_keys
protectedinherited

The key map.

Definition at line 171 of file TStore.h.

◆ m_objects

Objects_t xAOD::TStore::m_objects
protectedinherited

The object storage.

Definition at line 169 of file TStore.h.


The documentation for this class was generated from the following files: