ATLAS Offline Software
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
xAOD::TDVCollectionProxy Class Reference

A Root collection proxy for DataVector containers. More...

#include <TDVCollectionProxy.h>

Inheritance diagram for xAOD::TDVCollectionProxy:
Collaboration diagram for xAOD::TDVCollectionProxy:

Public Types

typedef TGenCollectionProxy::Sizing_t Sizing_t
 Make the definition of Sizing_t public. More...
 

Public Member Functions

 TDVCollectionProxy (const char *conttype)
 Constructor. More...
 
 TDVCollectionProxy (const TDVCollectionProxy &rhs)
 Copy constructor. More...
 
virtual void PushProxy (void *objstart)
 Start working with a new collection. More...
 
virtual TVirtualCollectionProxy * Generate () const
 Clone this object. More...
 
void SetResize (Sizing_t func)
 Set the resize(...) function used by the proxy. More...
 

Private Member Functions

virtual TGenCollectionProxy * InitializeEx (Bool_t silent)
 Function initialising the proxy just in time. More...
 
void FindOffsets (const char *elttype, const char *conttype)
 Initialize the cached pointer offsets. More...
 
TDVCollectionProxyoperator= (const TDVCollectionProxy &)
 

Private Attributes

TString fName
 Name of the container that this class proxies. More...
 
Bool_t fInitialized
 Flag for knowing whether the class was initialised already. More...
 
ptrdiff_t fContoff
 The offset of the underlying DataVector in the declared type. More...
 
ptrdiff_t fOffset
 Offset between the DV base pointer and the full DV pointer. More...
 
TClass * fEltBase
 The element type to which the DV representation points. More...
 
TClass * fEltType
 The declared element type of the DV. More...
 

Detailed Description

A Root collection proxy for DataVector containers.

In order for a container type to be treated properly by TTree::Draw and friends, Root must recognize that it is in fact a container type, and generate an appropriate proxy for it. This doesn't happen automatically, though. This class serves as an appropriate proxy for DataVector classes. Like the Root proxy classes, it's based on making a hard cast to a dummy DataVector type. But because DataVector's can inherit, we need to be careful about pointer conversions, something the Root proxy classes could ignore. We extend the Root environment buffer to cache information about the pointer offsets.

Author
Scott Snyder Scott.nosp@m..Sny.nosp@m.der@c.nosp@m.ern..nosp@m.ch
Attila Krasznahorkay Attil.nosp@m.a.Kr.nosp@m.aszna.nosp@m.hork.nosp@m.ay@ce.nosp@m.rn.c.nosp@m.h
Revision
687822
Date
2015-08-06 09:58:06 +0200 (Thu, 06 Aug 2015)

Definition at line 45 of file TDVCollectionProxy.h.

Member Typedef Documentation

◆ Sizing_t

typedef TGenCollectionProxy::Sizing_t xAOD::TDVCollectionProxy::Sizing_t

Make the definition of Sizing_t public.

Definition at line 50 of file TDVCollectionProxy.h.

Constructor & Destructor Documentation

◆ TDVCollectionProxy() [1/2]

xAOD::TDVCollectionProxy::TDVCollectionProxy ( const char conttype)

Constructor.

Parameters
conttypeThe name of the container type we're proxying. Note that this may be different from a DataVector of elttype for classes which derive from DataVector.

Definition at line 328 of file TDVCollectionProxy.cxx.

329  : TGenCollectionProxy( typeid( DataVector< TDVCollectionProxyDummy > ),
330  sizeof( char* ) ),
331  fName( conttype ), fInitialized( kFALSE ),
332  fContoff( 0 ), fOffset( 0 ), fEltBase( nullptr ), fEltType( nullptr ) {
333 
334  // Set up the element size. No offset, since this isn't a map.
335  fValDiff = sizeof( void* );
336  fValOffset = 0;
337 
338  // Set up the worker functions.
339  fSize.call = TDVCollectionFuncs::size;
340  fNext.call = TDVCollectionFuncs::next;
341  fFirst.call = TDVCollectionFuncs::first;
342  fClear.call = TDVCollectionFuncs::clear;
343  fCollect = TDVCollectionFuncs::collect;
344  fCreateEnv.call = TDVCollectionFuncs::create_env;
345  fResize = TDVCollectionFuncs::resize;
346  fConstruct = TDVCollectionFuncs::construct;
347  fDestruct = TDVCollectionFuncs::destruct;
348  fFeed = TDVCollectionFuncs::feed;
349 
350  // Make sure that TGenCollectionProxy knows that it's not
351  // fully set up yet:
352  if( fValue ) {
353  delete fValue.exchange( nullptr );
354  }
355  if( fVal ) {
356  delete fVal;
357  fVal = nullptr;
358  }
359 
360  // This container pretends to hold objects, not pointers:
361  fPointers = kFALSE;
362 
363  // Remember that we are not initialized yet:
364  fProperties = 0;
365  }

◆ TDVCollectionProxy() [2/2]

xAOD::TDVCollectionProxy::TDVCollectionProxy ( const TDVCollectionProxy rhs)

Copy constructor.

Parameters
rhsThe proxy to copy.

Definition at line 370 of file TDVCollectionProxy.cxx.

371  : TGenCollectionProxy( rhs ),
372  fName( rhs.fName ),
373  fInitialized( rhs.fInitialized ),
374  fContoff( rhs.fContoff ),
375  fOffset( rhs.fOffset ),
376  fEltBase( rhs.fEltBase ),
377  fEltType( rhs.fEltType ) {
378 
379  // If we're not initialised yet, make sure that the base class is
380  // on the same page...
381  if( ! fInitialized ) {
382  if( fValue ) {
383  delete fValue.exchange( nullptr );
384  }
385  if( fVal ) {
386  delete fVal;
387  fVal = nullptr;
388  }
389  }
390  }

Member Function Documentation

◆ FindOffsets()

void xAOD::TDVCollectionProxy::FindOffsets ( const char elttype,
const char conttype 
)
private

Initialize the cached pointer offsets.

Suppose we have D deriving from B, and thus DataVector<D> deriving from DataVector<B>. In general, inheritance may be multiple or virtual, so we need to adjust the pointer offsets.

Suppose we're setting up the proxy for DataVector<D>. Then fContoff will be set to the offset of the DataVector<B> base within DataVector<D> — this is the amount we need to shift the container pointer by before applying the proxy. Originally, we cached an offset for the element conversions as well. But that doesn't work for the case of virtual derivation. Instead, we save the Reflex types for the base and derived types, and use Reflex to convert. (We can get away with caching the offset for the container because we know what the fully-derived type will be. We don't know that for the elements.)

Parameters
elttypeThe name of the contained type (including a trailing '*').
conttypeThe name of the container type we're proxying. Note that this may be different from a DataVector of elttype for classes which derive from DataVector.

Definition at line 522 of file TDVCollectionProxy.cxx.

523  {
524 
525  // Start by assuming no offsets.
526  fContoff = 0;
527  fOffset = 0;
528 
529  // Find its TClass.
530  TClass* dvclass = TClass::GetClass( conttype );
531  if( ! dvclass ) {
532  ::Fatal( "xAOD::TDVCollectionProxy::FindOffsets",
533  "Cannot find class %s", conttype );
534  return;
535  }
536 
537  // Find the TClass for the base DataVector class.
538  TClass* dvbase = findDVBase( dvclass );
539  if( ! dvbase ) {
540  TClass* elclass = classFromDVClass( dvclass );
541  if( ! elclass ) {
542  ::Fatal( "xAOD::TDVCollectionProxy::FindOffsets",
543  "Couldn't find element type of %s",
544  dvclass->GetName() );
545  return;
546  }
547  fEltBase = elclass;
548  fEltType = fEltBase;
549 
550  // No inheritance --- offsets are zero.
551  return;
552  }
553 
554  // Find the container offset.
555  fContoff = safeGetBaseOffset( dvclass, dvbase );
556 
557  // Now, find the base and derived element classes.
558  std::string elttype2 = elttype;
559  if( elttype2[ elttype2.size() - 1 ] == '*' ) {
560  elttype2.erase( elttype2.size() - 1 );
561  }
562  fEltType = TClass::GetClass( elttype2.c_str() );
563  fEltBase = classFromDVClass( dvbase );
564 
565  if( ( ! fEltType ) || ( ! fEltBase ) ) {
566  ::Fatal( "xAOD::TDVCollectionProxy::FindOffsets",
567  "Couldn't find dictionaries for DV element "
568  "type(s) for %s", conttype );
569  return;
570  }
571 
572  // Get the offset needed for the pointer operations:
574 
575  return;
576  }

◆ Generate()

TVirtualCollectionProxy * xAOD::TDVCollectionProxy::Generate ( ) const
virtual

Clone this object.

Definition at line 428 of file TDVCollectionProxy.cxx.

428  {
429 
430  return new TDVCollectionProxy( *this );
431  }

◆ InitializeEx()

TGenCollectionProxy * xAOD::TDVCollectionProxy::InitializeEx ( Bool_t  silent)
privatevirtual

Function initialising the proxy just in time.

Definition at line 445 of file TDVCollectionProxy.cxx.

445  {
446 
447  // Check if we're initialised already:
448  if( fInitialized ) return this;
449 
450  // Check for the class's dictionary, and for its element type:
451  TClass* cl = TClass::GetClass( fName );
452  if( ! cl ) {
453  ::Fatal( "xAOD::TDVCollectionProxy::InitializeEx",
454  "Couldn't find dictionary for class %s",
455  fName.Data() );
456  return nullptr;
457  }
458 
459  // Check if it is a DataVector:
460  const std::string eltname = findDVElement( cl );
461  if( eltname.empty() ) {
462  ::Fatal( "xAOD::TDVCollectionProxy::InitializeEx",
463  "Class \"%s\" doesn't seem to be a DataVector",
464  cl->GetName() );
465  return nullptr;
466  }
467 
468  // Find the container and element offsets.
469  FindOffsets( eltname.c_str(), fName );
470 
471  // Set up the element size. No offset, since this isn't a map.
472  fValDiff = sizeof( void* );
473  fValOffset = 0;
474 
475  // Do the base class initialization.
476  CheckFunctions();
477  TGenCollectionProxy::InitializeEx( silent );
478  // xAODRootAccess/THolder relies on the setting below
479  // to be able to skip some inheritance tests.
480  fSTL_type = TClassEdit::kList;
481 
482  // Need to override what that set up for fValue and fVal.
483  if( fValue ) {
484  delete fValue.exchange( nullptr );
485  }
486  if( fVal ) delete fVal;
487  fValue = new TGenCollectionProxy::Value( eltname.c_str(), false );
488  fVal = new TGenCollectionProxy::Value( *fValue );
489  fClass = cl;
490 
491  // This container pretends to hold objects, not pointers:
492  fPointers = kFALSE;
493 
494  // Remember that the initialisation succeeded:
495  fInitialized = kTRUE;
496  return this;
497  }

◆ operator=()

TDVCollectionProxy& xAOD::TDVCollectionProxy::operator= ( const TDVCollectionProxy )
private

◆ PushProxy()

virtual void xAOD::TDVCollectionProxy::PushProxy ( void *  objstart)
virtual

Start working with a new collection.

Parameters
objstartThe address of the collection.

◆ SetResize()

void xAOD::TDVCollectionProxy::SetResize ( Sizing_t  func)

Set the resize(...) function used by the proxy.

The resize(...) functions need to be specific for the different classes.

This function is used to supply a specific resize(...) function for this proxy's class.

Parameters
funcThe function to use

Definition at line 439 of file TDVCollectionProxy.cxx.

439  {
440 
441  fResize = func;
442  return;
443  }

Member Data Documentation

◆ fContoff

ptrdiff_t xAOD::TDVCollectionProxy::fContoff
private

The offset of the underlying DataVector in the declared type.

Definition at line 85 of file TDVCollectionProxy.h.

◆ fEltBase

TClass* xAOD::TDVCollectionProxy::fEltBase
private

The element type to which the DV representation points.

Definition at line 90 of file TDVCollectionProxy.h.

◆ fEltType

TClass* xAOD::TDVCollectionProxy::fEltType
private

The declared element type of the DV.

Definition at line 92 of file TDVCollectionProxy.h.

◆ fInitialized

Bool_t xAOD::TDVCollectionProxy::fInitialized
private

Flag for knowing whether the class was initialised already.

Definition at line 82 of file TDVCollectionProxy.h.

◆ fName

TString xAOD::TDVCollectionProxy::fName
private

Name of the container that this class proxies.

Definition at line 80 of file TDVCollectionProxy.h.

◆ fOffset

ptrdiff_t xAOD::TDVCollectionProxy::fOffset
private

Offset between the DV base pointer and the full DV pointer.

Definition at line 87 of file TDVCollectionProxy.h.


The documentation for this class was generated from the following files:
xAOD::TDVCollectionFuncs::feed
static void * feed(void *, void *to, size_t size)
Definition: TDVCollectionProxy.cxx:295
xAOD::TDVCollectionFuncs::destruct
static void destruct(void *, size_t)
Not implemented for xAOD.
Definition: TDVCollectionProxy.cxx:290
xAOD::TDVCollectionFuncs::first
static void * first(void *env)
Return the first element of the container.
Definition: TDVCollectionProxy.cxx:211
xAOD::TDVCollectionProxy::TDVCollectionProxy
TDVCollectionProxy(const char *conttype)
Constructor.
Definition: TDVCollectionProxy.cxx:328
xAOD::TDVCollectionProxy::fInitialized
Bool_t fInitialized
Flag for knowing whether the class was initialised already.
Definition: TDVCollectionProxy.h:82
xAOD::TDVCollectionFuncs::create_env
static void * create_env()
Return a new environment structure.
Definition: TDVCollectionProxy.cxx:268
xAOD::TDVCollectionProxy::FindOffsets
void FindOffsets(const char *elttype, const char *conttype)
Initialize the cached pointer offsets.
Definition: TDVCollectionProxy.cxx:522
xAOD::TDVCollectionProxy::fName
TString fName
Name of the container that this class proxies.
Definition: TDVCollectionProxy.h:80
xAOD::TDVCollectionFuncs::next
static void * next(void *env)
Return a following element of the container.
Definition: TDVCollectionProxy.cxx:233
xAOD::TDVCollectionFuncs::resize
static void resize(void *, size_t)
Not implemented for xAOD.
Definition: TDVCollectionProxy.cxx:279
xAOD::findDVElement
std::string findDVElement(TClass *cl)
Find the element type of a DataVector class.
Definition: TDVCollectionProxy.cxx:112
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
xAOD::TDVCollectionFuncs::collect
static void * collect(void *, void *)
Not implemented for xAOD.
Definition: TDVCollectionProxy.cxx:315
xAOD::TDVCollectionProxy::fContoff
ptrdiff_t fContoff
The offset of the underlying DataVector in the declared type.
Definition: TDVCollectionProxy.h:85
xAOD::TDVCollectionProxy::fOffset
ptrdiff_t fOffset
Offset between the DV base pointer and the full DV pointer.
Definition: TDVCollectionProxy.h:87
xAOD::TDVCollectionProxy::fEltBase
TClass * fEltBase
The element type to which the DV representation points.
Definition: TDVCollectionProxy.h:90
xAOD::TDVCollectionProxy::fEltType
TClass * fEltType
The declared element type of the DV.
Definition: TDVCollectionProxy.h:92
python.trfDecorators.silent
def silent(func)
Redirect stdout/err to /dev/null Useful wrapper to get rid of ROOT verbosity...
Definition: trfDecorators.py:24
xAOD::TDVCollectionFuncs::clear
static void * clear(void *env)
Erase the container.
Definition: TDVCollectionProxy.cxx:261
xAOD::safeGetBaseOffset
int safeGetBaseOffset(TClass *cls, TClass *base)
Find base class offset using Reflex.
Definition: TDVCollectionProxy.cxx:40
xAOD::findDVBase
TClass * findDVBase(TClass *dvclass)
Find the unique base DataVector class.
Definition: TDVCollectionProxy.cxx:87
xAOD::TDVCollectionFuncs::size
static void * size(void *env)
Return the size of the container.
Definition: TDVCollectionProxy.cxx:251
xAOD::TDVCollectionFuncs::construct
static void * construct(void *, size_t)
Not implemented for xAOD.
Definition: TDVCollectionProxy.cxx:284
xAOD::classFromDVClass
TClass * classFromDVClass(TClass *dvclass)
Find the contained class in a DataVector.
Definition: TDVCollectionProxy.cxx:49
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26