ATLAS Offline Software
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
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. More...
 
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. More...
 
virtual void set (void *obj)
 Replace the managed object. More...
 
virtual void * getAs (const std::type_info &tid, ::Bool_t silent=kFALSE) const
 Return the object as a specific pointer. More...
 
virtual const void * getAsConst (const std::type_info &tid, ::Bool_t silent=kFALSE) const
 Return the object as a specific, constant pointer. More...
 
const void * get () const
 Return a typeless const pointer to the held object. More...
 
void * get ()
 Return a typeless pointer to the held object. More...
 
void ** getPtr ()
 Return a typeless pointer to the held object's pointer. More...
 
::Bool_t isOwner () const
 Check whether the holder owns its object. More...
 
void setOwner (::Bool_t state=kTRUE)
 Set whether the holder should own its object. More...
 
::Bool_t isConst () const
 Check if the object is const. More...
 
void setConst ()
 Mark the object as const. More...
 
void renew ()
 Renew the object in memory. More...
 
TypeKind typeKind () const
 Return the type of the object held by this one. More...
 
const ::TClass * getClass () const
 
::TClass * getClass ()
 
const std::type_info * getTypeInfo () const
 
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. More...
 
void * getImpl (const std::type_info &tid, ::Bool_t silent=kFALSE) const
 Internal function to get an object. More...
 

Protected Attributes

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

Private Attributes

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

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,
106  AUXELEMENT
107  }; // enum TypeKind

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 437 of file THolder.cxx.

437  {
438 
439  // Check if we even have an object:
440  if( ! m_object ) {
441  return;
442  }
443 
444  // Delete the object then:
445  if( m_type ) {
446  if( m_type->IsLoaded() ) {
447  m_type->Destructor( m_object );
448  }
449  // In certain situations it can happen that the memory cleanup for a
450  // particular TEvent object happens after ROOT already started to
451  // unload libraries from memory. In this case, since the application
452  // is anyway on its final leg, let's not bother the user with
453  // additional warnings about not being able to clean up after the
454  // managed object.
455  } else if( m_typeInfo ) {
456  const TVirtualDestructor* d =
458  if( d ) {
459  d->destruct( m_object );
460  } else {
461  ::Error( "xAOD::THolder::deleteObject",
462  XAOD_MESSAGE( "Couldn't delete managed object" ) );
463  }
464  } else {
465  ::Error( "xAOD::THolder::deleteObject",
466  XAOD_MESSAGE( "Couldn't delete managed object" ) );
467  }
468 
469  return;
470  }

◆ get() [1/2]

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

Return a typeless pointer to the held object.

Definition at line 220 of file THolder.cxx.

220  {
221 
222  return m_object;
223  }

◆ get() [2/2]

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

Return a typeless const pointer to the held object.

Definition at line 215 of file THolder.cxx.

215  {
216 
217  return m_object;
218  }

◆ 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 406 of file THolder.cxx.

406  {
407 
408  return m_type;
409  }

◆ getClass() [2/2]

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

Return the concrete type of the object

Definition at line 401 of file THolder.cxx.

401  {
402 
403  return m_type;
404  }

◆ 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 296 of file THolder.cxx.

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

◆ getPtr()

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

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

Definition at line 225 of file THolder.cxx.

225  {
226 
227  return &m_object;
228  }

◆ getTypeInfo()

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

Definition at line 411 of file THolder.cxx.

411  {
412 
413  return m_typeInfo;
414  }

◆ isConst()

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

Check if the object is const.

Definition at line 279 of file THolder.cxx.

279  {
280 
281  return m_const;
282  }

◆ isOwner()

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

Check whether the holder owns its object.

Definition at line 252 of file THolder.cxx.

252  {
253 
254  return m_owner;
255  }

◆ 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 420 of file THolder.cxx.

420  {
421 
422  // Delete the object using its dictionary:
423  if( m_object && m_owner &&
424  ( ! Internal::THolderCache::instance().decRef( m_object ) ) ) {
425  deleteObject();
426  }
427 
428  // Create a new object:
429  m_owner = kTRUE;
430  m_object = m_type->New();
432 
433  // Return gracefuly:
434  return;
435  }

◆ 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 284 of file THolder.cxx.

284  {
285 
286  m_const = kTRUE;
287  }

◆ setOwner()

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

Set whether the holder should own its object.

Definition at line 257 of file THolder.cxx.

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

◆ 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  }

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:
xAOD::THolder::OTHER
@ OTHER
Some non-specified type.
Definition: THolder.h:104
xAOD::THolder::AUXELEMENT
@ AUXELEMENT
A type inheriting from SG::AuxElement.
Definition: THolder.h:106
xAOD::THolder::m_owner
::Bool_t m_owner
A flag for whether the object owns what it points to.
Definition: THolder.h:129
SG::normalizedTypeinfoName
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...
Definition: normalizedTypeinfoName.cxx:120
hist_file_dump.d
d
Definition: hist_file_dump.py:137
xAOD::THolder::DATAVECTOR
@ DATAVECTOR
A DataVector container.
Definition: THolder.h:105
xAOD::THolder::deleteObject
void deleteObject()
Internal function used to delete the managed object from memory.
Definition: THolder.cxx:437
XAOD_MESSAGE
#define XAOD_MESSAGE(MESSAGE)
Simple macro for printing error/verbose messages.
Definition: Control/xAODRootAccess/xAODRootAccess/tools/Message.h:19
xAOD::Internal::THolderCache::addClass
void addClass(const std::type_info &ti, ::TClass *cl)
Add the dictionary for a given type.
Definition: THolderCache.cxx:49
xAOD::Internal::THolderCache::getClass
std::pair< bool, ::TClass * > getClass(const std::type_info &ti) const
Get the dictionary for a given type info.
Definition: THolderCache.cxx:35
xAOD::THolder::m_typeKind
TypeKind m_typeKind
Type of the object held.
Definition: THolder.h:131
xAOD::THolder::m_const
::Bool_t m_const
Is the held object const?
Definition: THolder.h:133
xAOD::THolder::m_object
void * m_object
Typeless pointer to the object in memory.
Definition: THolder.h:123
xAOD::TDestructorRegistry::instance
static TDestructorRegistry & instance()
Function accessing the singleton instance of this type.
Definition: TDestructorRegistry.cxx:16
xAOD::THolder::m_type
::TClass * m_type
Concrete type of the object being held on to.
Definition: THolder.h:125
xAOD::Internal::THolderCache::instance
static THolderCache & instance()
Singleton accessor.
Definition: THolderCache.cxx:29
xAOD::Internal::THolderCache::incRef
int incRef(void *ptr)
Increment the reference count of an object in memory.
Definition: THolderCache.cxx:72
python.trfDecorators.silent
def silent(func)
Redirect stdout/err to /dev/null Useful wrapper to get rid of ROOT verbosity...
Definition: trfDecorators.py:24
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
xAOD::THolder::m_typeInfo
const std::type_info * m_typeInfo
Concrete type of the object, if it doesn't have a dictionary.
Definition: THolder.h:127
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
xAOD::TDestructorRegistry::get
const TVirtualDestructor * get(const std::type_info &ti) const
Get the destructor for a given type.
Definition: TDestructorRegistry.cxx:23