ATLAS Offline Software
Loading...
Searching...
No Matches
xAOD::TCDVHolderT< T > Class Template Reference

Class managing ConstDataVector objects in transient memory. More...

#include <TCDVHolderT.h>

Inheritance diagram for xAOD::TCDVHolderT< T >:
Collaboration diagram for xAOD::TCDVHolderT< T >:

Public Types

typedef ConstDataVector< T > Object_t
 Type of the managed object.
enum  TypeKind { OTHER , DATAVECTOR , AUXELEMENT }
 Type of the object held by this one. More...

Public Member Functions

 TCDVHolderT (ConstDataVector< T > *object, const std::type_info &type, ::Bool_t owner=kTRUE)
 Constructor with the object, and its type.
virtual void set (void *obj)
 Replace the managed object.
virtual void * getAs (const std::type_info &tid, ::Bool_t silent=kFALSE) const
 Return the object as a specific pointer.
virtual const void * getAsConst (const std::type_info &tid, ::Bool_t silent=kFALSE) const
 Return the object as a specific, constant pointer.
const void * get () const
 Return a typeless const pointer to the held object.
void * get ()
 Return a typeless pointer to the held object.
void ** getPtr ()
 Return a typeless pointer to the held object's pointer.
::Bool_t isOwner () const
 Check whether the holder owns its object.
void setOwner (::Bool_t state=kTRUE)
 Set whether the holder should own its object.
::Bool_t isConst () const
 Check if the object is const.
void setConst ()
 Mark the object as const.
void renew ()
 Renew the object in memory.
TypeKind typeKind () const
 Return the type of the object held by this one.
const ::TClass * getClass () const
::TClass * getClass ()
const std::type_info * getTypeInfo () const

Protected Member Functions

void deleteObject ()
 Internal function used to delete the managed object from memory.
void * getImpl (const std::type_info &tid, ::Bool_t silent=kFALSE) const
 Internal function to get an object.

Protected Attributes

void * m_object
 Typeless pointer to the object in memory.
::TClass * m_type
 Concrete type of the object being held on to.
const std::type_info * m_typeInfo
 Concrete type of the object, if it doesn't have a dictionary.
::Bool_t m_owner
 A flag for whether the object owns what it points to.
TypeKind m_typeKind
 Type of the object held.
::Bool_t m_const
 Is the held object const?

Private Attributes

ConstDataVector< T > * m_cdvObject
 Type specific pointer to the managed object.
THolder m_holderHelper
 Helper object managing the inheritance tree of the underlying DataVector type.

Detailed Description

template<class T>
class xAOD::TCDVHolderT< T >

Class managing ConstDataVector objects in transient memory.

In order to be able to record ConstDataVector objects into the transient store, and be able to retrieve them as "const DataVector", we need to use a specialised holder type. Very much like how we use a specialised SG::DataBucket for this type in Athena's StoreGate.

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 28 of file TCDVHolderT.h.

Member Typedef Documentation

◆ Object_t

template<class T>
typedef ConstDataVector< T > xAOD::TCDVHolderT< T >::Object_t

Type of the managed object.

Definition at line 32 of file TCDVHolderT.h.

Member Enumeration Documentation

◆ TypeKind

enum xAOD::THolder::TypeKind
inherited

Type of the object held by this one.

Enumerator
OTHER 

Some non-specified type.

DATAVECTOR 

A DataVector container.

AUXELEMENT 

A type inheriting from SG::AuxElement.

Definition at line 103 of file THolder.h.

103 {
104 OTHER,
105 DATAVECTOR,
107 }; // enum TypeKind
@ DATAVECTOR
A DataVector container.
Definition THolder.h:105
@ AUXELEMENT
A type inheriting from SG::AuxElement.
Definition THolder.h:106
@ OTHER
Some non-specified type.
Definition THolder.h:104

Constructor & Destructor Documentation

◆ TCDVHolderT()

template<class T>
xAOD::TCDVHolderT< T >::TCDVHolderT ( ConstDataVector< T > * object,
const std::type_info & type,
::Bool_t owner = kTRUE )

Constructor with the object, and its type.

Member Function Documentation

◆ deleteObject()

void xAOD::THolder::deleteObject ( )
protectedinherited

Internal function used to delete the managed object from memory.

Definition at line 438 of file THolder.cxx.

438 {
439
440 // Check if we even have an object:
441 if( ! m_object ) {
442 return;
443 }
444
445 // Delete the object then:
446 if( m_type ) {
447 if( m_type->IsLoaded() ) {
448 m_type->Destructor( m_object );
449 }
450 // In certain situations it can happen that the memory cleanup for a
451 // particular TEvent object happens after ROOT already started to
452 // unload libraries from memory. In this case, since the application
453 // is anyway on its final leg, let's not bother the user with
454 // additional warnings about not being able to clean up after the
455 // managed object.
456 } else if( m_typeInfo ) {
457 const TVirtualDestructor* d =
459 if( d ) {
460 d->destruct( m_object );
461 } else {
462 ::Error( "xAOD::THolder::deleteObject",
463 XAOD_MESSAGE( "Couldn't delete managed object" ) );
464 }
465 } else {
466 ::Error( "xAOD::THolder::deleteObject",
467 XAOD_MESSAGE( "Couldn't delete managed object" ) );
468 }
469
470 return;
471 }
#define XAOD_MESSAGE(MESSAGE)
Simple macro for printing error/verbose messages.
const TVirtualDestructor * get(const std::type_info &ti) const
Get the destructor for a given type.
static TDestructorRegistry & instance()
Function accessing the singleton instance of this type.
void * m_object
Typeless pointer to the object in memory.
Definition THolder.h:123
::TClass * m_type
Concrete type of the object being held on to.
Definition THolder.h:125
const std::type_info * m_typeInfo
Concrete type of the object, if it doesn't have a dictionary.
Definition THolder.h:127

◆ get() [1/2]

void * xAOD::THolder::get ( )
inherited

Return a typeless pointer to the held object.

Definition at line 221 of file THolder.cxx.

221 {
222
223 return m_object;
224 }

◆ get() [2/2]

const void * xAOD::THolder::get ( ) const
inherited

Return a typeless const pointer to the held object.

Definition at line 216 of file THolder.cxx.

216 {
217
218 return m_object;
219 }

◆ getAs()

template<class T>
virtual void * xAOD::TCDVHolderT< T >::getAs ( const std::type_info & tid,
::Bool_t silent = kFALSE ) const
virtual

Return the object as a specific pointer.

Reimplemented from xAOD::THolder.

◆ getAsConst()

template<class T>
virtual const void * xAOD::TCDVHolderT< T >::getAsConst ( const std::type_info & tid,
::Bool_t silent = kFALSE ) const
virtual

Return the object as a specific, constant pointer.

Reimplemented from xAOD::THolder.

◆ getClass() [1/2]

TClass * xAOD::THolder::getClass ( )
inherited

Definition at line 407 of file THolder.cxx.

407 {
408
409 return m_type;
410 }

◆ getClass() [2/2]

const::TClass * xAOD::THolder::getClass ( ) const
inherited

Return the concrete type of the object

Definition at line 402 of file THolder.cxx.

402 {
403
404 return m_type;
405 }

◆ getImpl()

void * xAOD::THolder::getImpl ( const std::type_info & tid,
::Bool_t silent = kFALSE ) const
protectedinherited

Internal function to get an object.

Internal helper or getAs and getAsConst.

Parameters
tidThe type as which the object is to be retrieved
silentWhen kTRUE, the call will fail silently when unsuccessful
Returns
A pointer that can be cast to the requested type

Definition at line 297 of file THolder.cxx.

298 {
299
300 // If there is no dictionary for the object, then the logic is pretty
301 // simple:
302 if( ! m_type ) {
303 // Check if the user asked for the right type. Remember that in this
304 // case we can't return an object as its base type.
305 if( tid != *m_typeInfo ) {
306 if( ! silent ) {
307 const std::string heldType =
309 const std::string reqType =
311 ::Warning( "xAOD::THolder::getAs",
312 "Trying to retrieve %s object with a %s pointer",
313 heldType.c_str(), reqType.c_str() );
314 }
315 return 0;
316 }
317 // The user did ask for the correct type:
318 return m_object;
319 }
320
321 // Check if we already know about this type:
322 auto userClass = Internal::THolderCache::instance().getClass( tid );
323 // If not, look for it now:
324 if( ! userClass.first ) {
325 userClass.second = ::TClass::GetClass( tid );
326 Internal::THolderCache::instance().addClass( tid, userClass.second );
327 }
328
329 // If we still don't have a dictionary, that's an issue:
330 if( ! userClass.second ) {
331 if( ! silent ) {
332 ::Error( "xAOD::THolder::getAs",
333 XAOD_MESSAGE( "Couldn't access the dictionary for user "
334 "type: %s" ),
335 SG::normalizedTypeinfoName( tid ).c_str() );
336 }
337 return 0;
338 }
339
340 // Check if the user requested a valid base class for the held type.
341 //
342 // Calling GetBaseClassOffset is in general not thread-safe as it could
343 // trigger the loading and parsing of StreamerInfo. However, we assume
344 // that this has already been done once we get here.
345 TClass* cl ATLAS_THREAD_SAFE = m_type;
346 const Int_t offset = cl->GetBaseClassOffset( userClass.second );
347 if( offset < 0 ) {
348 if( ! silent ) {
349 ::Warning( "xAOD::THolder::getAs",
350 "User class \"%s\" is not a valid base "
351 "of \"%s\"",
352 SG::normalizedTypeinfoName( tid ).c_str(),
353 m_type->GetName() );
354 }
355 return 0;
356 }
357
358 // If all is fine, do the cast:
359 return ( static_cast< char* >( m_object ) + offset );
360 }
#define ATLAS_THREAD_SAFE
static THolderCache & instance()
Singleton accessor.
void addClass(const std::type_info &ti, ::TClass *cl)
Add the dictionary for a given type.
std::pair< bool, ::TClass * > getClass(const std::type_info &ti) const
Get the dictionary for a given type info.
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()) ]

◆ getPtr()

void ** xAOD::THolder::getPtr ( )
inherited

Return a typeless pointer to the held object's pointer.

Definition at line 226 of file THolder.cxx.

226 {
227
228 return &m_object;
229 }

◆ getTypeInfo()

const std::type_info * xAOD::THolder::getTypeInfo ( ) const
inherited

Definition at line 412 of file THolder.cxx.

412 {
413
414 return m_typeInfo;
415 }

◆ isConst()

Bool_t xAOD::THolder::isConst ( ) const
inherited

Check if the object is const.

Definition at line 280 of file THolder.cxx.

280 {
281
282 return m_const;
283 }
::Bool_t m_const
Is the held object const?
Definition THolder.h:133

◆ isOwner()

Bool_t xAOD::THolder::isOwner ( ) const
inherited

Check whether the holder owns its object.

Definition at line 253 of file THolder.cxx.

253 {
254
255 return m_owner;
256 }
::Bool_t m_owner
A flag for whether the object owns what it points to.
Definition THolder.h:129

◆ renew()

void xAOD::THolder::renew ( )
inherited

Renew the object in memory.

This function is mostly used in "Athena access mode", to delete the managed objects from memory between events, and recreate them from scratch.

Definition at line 421 of file THolder.cxx.

421 {
422
423 // Delete the object using its dictionary:
424 if( m_object && m_owner &&
425 ( ! Internal::THolderCache::instance().decRef( m_object ) ) ) {
426 deleteObject();
427 }
428
429 // Create a new object:
430 m_owner = kTRUE;
431 m_object = m_type->New();
433
434 // Return gracefuly:
435 return;
436 }
int incRef(void *ptr)
Increment the reference count of an object in memory.
void deleteObject()
Internal function used to delete the managed object from memory.
Definition THolder.cxx:438

◆ set()

template<class T>
virtual void xAOD::TCDVHolderT< T >::set ( void * obj)
virtual

Replace the managed object.

Reimplemented from xAOD::THolder.

◆ setConst()

void xAOD::THolder::setConst ( )
inherited

Mark the object as const.

Definition at line 285 of file THolder.cxx.

285 {
286
287 m_const = kTRUE;
288 }

◆ setOwner()

void xAOD::THolder::setOwner ( ::Bool_t state = kTRUE)
inherited

Set whether the holder should own its object.

Definition at line 258 of file THolder.cxx.

258 {
259
260 // Check if anything needs to be done:
261 if( state == m_owner ) return;
262
263 if( m_object && m_owner &&
264 ( ! Internal::THolderCache::instance().decRef( m_object ) ) ) {
265 ::Warning( "xAOD::THolder::setOwner",
266 "Deleting object %p no longer held by any owner",
267 m_object );
268 deleteObject();
269 }
270
271 m_owner = state;
272
273 if( m_object && m_owner ) {
275 }
276
277 return;
278 }

◆ typeKind()

TypeKind xAOD::THolder::typeKind ( ) const
inlineinherited

Return the type of the object held by this one.

Definition at line 110 of file THolder.h.

110 {
111 return m_typeKind;
112 }
TypeKind m_typeKind
Type of the object held.
Definition THolder.h:131

Member Data Documentation

◆ m_cdvObject

template<class T>
ConstDataVector< T >* xAOD::TCDVHolderT< T >::m_cdvObject
private

Type specific pointer to the managed object.

Definition at line 51 of file TCDVHolderT.h.

◆ m_const

::Bool_t xAOD::THolder::m_const
protectedinherited

Is the held object const?

Definition at line 133 of file THolder.h.

◆ m_holderHelper

template<class T>
THolder xAOD::TCDVHolderT< T >::m_holderHelper
private

Helper object managing the inheritance tree of the underlying DataVector type.

Definition at line 54 of file TCDVHolderT.h.

◆ m_object

void* xAOD::THolder::m_object
protectedinherited

Typeless pointer to the object in memory.

Definition at line 123 of file THolder.h.

◆ m_owner

::Bool_t xAOD::THolder::m_owner
protectedinherited

A flag for whether the object owns what it points to.

Definition at line 129 of file THolder.h.

◆ m_type

::TClass* xAOD::THolder::m_type
protectedinherited

Concrete type of the object being held on to.

Definition at line 125 of file THolder.h.

◆ m_typeInfo

const std::type_info* xAOD::THolder::m_typeInfo
protectedinherited

Concrete type of the object, if it doesn't have a dictionary.

Definition at line 127 of file THolder.h.

◆ m_typeKind

TypeKind xAOD::THolder::m_typeKind
protectedinherited

Type of the object held.

Definition at line 131 of file THolder.h.


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