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

Dynamic implementation of IAuxVectorFactory, relying on root's vector proxy. More...

#include <RootAuxVectorFactory.h>

Inheritance diagram for SG::RootAuxVectorFactory:
Collaboration diagram for SG::RootAuxVectorFactory:

Public Member Functions

 RootAuxVectorFactory (TClass *objClass)
 Constructor. More...
 
virtual ~RootAuxVectorFactory () override
 Destructor. More...
 
const RootUtils::TyperootType () const
 Return the ROOT type wrapper. More...
 
TClass *objClass ATLAS_NOT_CONST_THREAD_SAFE () const
 Return the TClass for the overall object. More...
 
TClass *vecClass ATLAS_NOT_CONST_THREAD_SAFE () const
 Return the TClass for the std::vector. More...
 
size_t offset () const
 Return the offset of the vector within the object. More...
 
virtual std::unique_ptr< SG::IAuxTypeVectorcreate (SG::auxid_t auxid, size_t size, size_t capacity, bool isLinked) const override
 Create a vector object of this type. More...
 
virtual std::unique_ptr< SG::IAuxTypeVectorcreateFromData (SG::auxid_t auxid, void *data, IAuxTypeVector *linkedVector, bool isPacked, bool ownFlag, bool isLinked) const override
 Create a vector object of this type from a data blob. More...
 
virtual void copy (SG::auxid_t auxid, AuxVectorData &dst, size_t dst_index, const AuxVectorData &src, size_t src_index, size_t n) const override
 Copy elements between vectors. More...
 
virtual void copyForOutput (SG::auxid_t auxid, AuxVectorData &dst, size_t dst_index, const AuxVectorData &src, size_t src_index, size_t n) const override
 Copy elements between vectors, possibly applying thinning. More...
 
virtual void swap (SG::auxid_t auxid, AuxVectorData &a, size_t aindex, AuxVectorData &b, size_t bindex, size_t n) const override
 Swap elements between vectors. More...
 
virtual void clear (SG::auxid_t auxid, AuxVectorData &dst, size_t dst_index, size_t n) const override
 Clear a range of elements within a vector. More...
 
virtual size_t getEltSize () const override
 Return the size of an element of this vector type. More...
 
virtual const std::type_info * tiVec () const override
 Return the type_info of the overall object. More...
 
virtual bool isDynamic () const override
 True if the vectors created by this factory work by dynamic emulation (via TVirtualCollectionProxy or similar); false if the std::vector code is used directly. More...
 
virtual const std::type_info * tiAlloc () const override
 Return the type_info of the vector allocator. More...
 
virtual std::string tiAllocName () const override
 Return the (demangled) name of the vector allocator. More...
 
void copy (SG::auxid_t auxid, AuxVectorData &&dst, size_t dst_index, const AuxVectorData &src, size_t src_index, size_t n) const
 Copy elements between vectors. More...
 

Private Types

enum  { NONE, ELEMENT_LINK, ELEMENT_LINK_VECTOR, ELEMENT_LINK_NONPOINTER }
 Flag to tell whether we need to do thinning. More...
 

Private Member Functions

char * copyImpl (SG::auxid_t auxid, AuxVectorData &dst, size_t dst_index, const AuxVectorData &src, size_t src_index, size_t n) const
 Helper for copy; returns a pointer to the first destination object, or nullptr if the destination was cleared rather than copied. More...
 

Private Attributes

TClass * m_objClass
 The TClass for the overall object. More...
 
TClass * m_vecClass
 The TClass for the std::vector. More...
 
size_t m_offset
 Offset of the STL vector within the overall object. More...
 
RootUtils::Type m_type
 Wrapper for the ROOT type of the element. More...
 
enum SG::RootAuxVectorFactory:: { ... }  m_isEL
 Flag to tell whether we need to do thinning. More...
 

Detailed Description

Dynamic implementation of IAuxVectorFactory, relying on root's vector proxy.

This is used for the case when we need to manipulate an aux data vector present in an input data file but we have neither a proper template instantiation for the factory (because the variable was never explicitly referenced), nor can we find a dictionary entry for the factory.j

This implementation works by relying entirely on the root dictionary information.

We may either be dealing directly with an STL vector class, or with embedded in another class (as for PackedContainer). Here, vecClass is the class of the STL vector and objClass is the overall object class. In the case of a direct STL vector, these are identical.

Definition at line 260 of file RootAuxVectorFactory.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private

Flag to tell whether we need to do thinning.

Enumerator
NONE 
ELEMENT_LINK 
ELEMENT_LINK_VECTOR 
ELEMENT_LINK_NONPOINTER 

Definition at line 472 of file RootAuxVectorFactory.h.

Constructor & Destructor Documentation

◆ RootAuxVectorFactory()

SG::RootAuxVectorFactory::RootAuxVectorFactory ( TClass *  objClass)

Constructor.

Parameters
vecClassThe TClass for the vector object.

Definition at line 345 of file RootAuxVectorFactory.cxx.

346  : m_objClass (objClass),
347  m_vecClass (objClass),
348  m_offset (0),
349  m_isEL (NONE)
350 {
351  TVirtualCollectionProxy* proxy = m_vecClass->GetCollectionProxy();
352 
353  if (!proxy) {
354  TClass* vecClass = lookupVectorType (objClass);
355  if (vecClass) {
356  m_vecClass = vecClass;
357  Int_t offs = objClass->GetBaseClassOffset (vecClass);
358  if (offs >= 0) {
359  m_offset = offs;
360  proxy = vecClass->GetCollectionProxy();
361  }
362  else {
363  ATHCONTAINERS_ERROR("RootAuxVectorFactory::RootAuxVectorFactory",
364  std::string("Can't find vector base class in ") +
365  objClass->GetName());
366  }
367  }
368  }
369 
370  if (!proxy) {
371  std::string err = "Can't find collection proxy for ";
372  err += m_vecClass->GetName();
373  throw std::runtime_error (err.c_str());
374  }
375 
376  if (m_vecClass->GetTypeInfo() == 0) {
377  ATHCONTAINERS_ERROR("RootAuxVectorFactory::RootAuxVectorFactory",
378  std::string("No type_info available for class ") +
379  m_vecClass->GetName() +
380  std::string(". There is probably a missing dictionary. We will likely crash further on."));
381  }
382 
383  TClass* eltClass = proxy->GetValueClass();
384  if (eltClass) {
385  m_type.init (eltClass);
386 
387  const std::type_info* ti = eltClass->GetTypeInfo();
388  if (ti) {
389 
390  static const CxxUtils::ClassName pat1 ("ElementLink<$T>");
391  static const CxxUtils::ClassName pat2 ("std::vector<ElementLink<$T> >");
392 
395  if (clname.match (pat1, matches)) {
397  if (eltClass->GetBaseClass ("ElementLinkBase") == nullptr) {
399  }
400  }
401  else if (clname.match (pat2, matches)) {
403 
404  TVirtualCollectionProxy* proxy2 = eltClass->GetCollectionProxy();
405  if (proxy2) {
406  TClass* innerEltClass = proxy2->GetValueClass();
407  if (innerEltClass) {
408  if (innerEltClass->GetBaseClass ("ElementLinkBase") == nullptr) {
410  }
411  }
412  }
413  }
414  }
415  }
416  else
417  m_type.init (proxy->GetType());
418 }

◆ ~RootAuxVectorFactory()

SG::RootAuxVectorFactory::~RootAuxVectorFactory ( )
overridevirtual

Destructor.

Definition at line 424 of file RootAuxVectorFactory.cxx.

425 {
426 }

Member Function Documentation

◆ ATLAS_NOT_CONST_THREAD_SAFE() [1/2]

TClass* objClass SG::RootAuxVectorFactory::ATLAS_NOT_CONST_THREAD_SAFE ( ) const
inline

Return the TClass for the overall object.

(Returning non-const TClass* ok here; TClass is internally thread-safe.)

Definition at line 288 of file RootAuxVectorFactory.h.

288 { return m_objClass; }

◆ ATLAS_NOT_CONST_THREAD_SAFE() [2/2]

TClass* vecClass SG::RootAuxVectorFactory::ATLAS_NOT_CONST_THREAD_SAFE ( ) const
inline

Return the TClass for the std::vector.

(Returning non-const TClass* ok here; TClass is internally thread-safe.)

Definition at line 296 of file RootAuxVectorFactory.h.

296 { return m_vecClass; }

◆ clear()

void SG::RootAuxVectorFactory::clear ( SG::auxid_t  auxid,
AuxVectorData dst,
size_t  dst_index,
size_t  n 
) const
overridevirtual

Clear a range of elements within a vector.

Parameters
auxidThe aux data item being operated on.
dstContainer holding the element
dst_indexIndex of the first element in the vector.
nNumber of elements to clear.

Implements SG::IAuxTypeVectorFactory.

Definition at line 610 of file RootAuxVectorFactory.cxx.

613 {
614  if (n == 0) return;
615  m_type.clearRange (dst.getDataArray (auxid), dst_index, n);
616 }

◆ copy() [1/2]

void SG::IAuxTypeVectorFactory::copy ( SG::auxid_t  auxid,
AuxVectorData &&  dst,
size_t  dst_index,
const AuxVectorData src,
size_t  src_index,
size_t  n 
) const
inlineinherited

Copy elements between vectors.

Parameters
auxidThe aux data item being operated on.
dstContainer for the destination vector. Declared as a rvalue reference to allow passing a temporary here (such as from AuxVectorInterface).
dst_indexIndex of the first destination element in the vector.
srcContainer for the source vector.
src_indexIndex of the first source element in the vector.
nNumber of elements to copy.

dst and @ src can be either the same or different.

Definition at line 132 of file IAuxTypeVectorFactory.h.

136  {
137  copy (auxid, dst, dst_index, src, src_index, n);
138  }

◆ copy() [2/2]

void SG::RootAuxVectorFactory::copy ( SG::auxid_t  auxid,
AuxVectorData dst,
size_t  dst_index,
const AuxVectorData src,
size_t  src_index,
size_t  n 
) const
overridevirtual

Copy elements between vectors.

Parameters
auxidThe aux data item being operated on.
dstContainer for the destination vector.
dst_indexIndex of the first destination element in the vector.
srcContainer for the source vector.
src_indexIndex of the first source element in the vector.
nNumber of elements to copy.

dst and @ src can be either the same or different.

Implements SG::IAuxTypeVectorFactory.

Definition at line 525 of file RootAuxVectorFactory.cxx.

531 {
532  (void)copyImpl (auxid, dst, dst_index, src, src_index, n);
533 }

◆ copyForOutput()

void SG::RootAuxVectorFactory::copyForOutput ( SG::auxid_t  auxid,
AuxVectorData dst,
size_t  dst_index,
const AuxVectorData src,
size_t  src_index,
size_t  n 
) const
overridevirtual

Copy elements between vectors, possibly applying thinning.

Parameters
auxidThe aux data item being operated on.
dstContainer for the destination vector.
dst_indexIndex of the first destination element in the vector.
srcContainer for the source vector.
src_indexIndex of source element in the vector.
src_indexIndex of the first source element in the vector.
nNumber of elements to copy.

dst and @ src can be either the same or different.

Implements SG::IAuxTypeVectorFactory.

Definition at line 548 of file RootAuxVectorFactory.cxx.

552 {
553  char* dstptr = copyImpl (auxid, dst, dst_index, src, src_index, n);
554 
555  if (m_isEL == ELEMENT_LINK) {
556  size_t eltsz = m_type.getSize();
557  for (size_t i = 0; i < n; i++) {
558  reinterpret_cast<ElementLinkBase*>(dstptr + i*eltsz)->thin();
559  }
560  }
561  else if (m_isEL == ELEMENT_LINK_VECTOR) {
562  size_t eltsz = m_type.getSize();
563  for (size_t i = 0; i < n; i++) {
564  std::vector<ElementLinkBase>& v =
565  *reinterpret_cast<std::vector<ElementLinkBase>* > (dstptr +i*eltsz);
566  for (ElementLinkBase& el : v) {
567  el.thin();
568  }
569  }
570  }
571  else if (m_isEL == ELEMENT_LINK_NONPOINTER) {
572  ATHCONTAINERS_ERROR("RootAuxVectorFactory::copyForOutput",
573  std::string("Cannot apply thinning for ElementLink with non-pointer element: ") +
574  m_vecClass->GetName());
575  }
576 }

◆ copyImpl()

char * SG::RootAuxVectorFactory::copyImpl ( SG::auxid_t  auxid,
AuxVectorData dst,
size_t  dst_index,
const AuxVectorData src,
size_t  src_index,
size_t  n 
) const
private

Helper for copy; returns a pointer to the first destination object, or nullptr if the destination was cleared rather than copied.

Definition at line 483 of file RootAuxVectorFactory.cxx.

489 {
490  if (n == 0) return nullptr;
491  size_t eltsz = m_type.getSize();
492  char* dstptr = reinterpret_cast<char*> (dst.getDataArray (auxid));
493  if (&src == &dst) {
494  // Source and destination containers are the same,
495  // so we don't need to bother with fetching the src pointer.
496  // copyRange properly handles overlapping regions.
497  m_type.copyRange (dstptr + eltsz*dst_index, dstptr + eltsz*src_index, n);
498  return dstptr + eltsz*dst_index;
499  }
500  else {
501  const char* srcptr = reinterpret_cast<const char*>(src.getDataArrayAllowMissing (auxid));
502  if (srcptr) {
503  m_type.copyRange (dstptr + eltsz*dst_index, srcptr + eltsz*src_index, n);
504  return dstptr + eltsz*dst_index;
505  }
506  else {
507  m_type.clearRange (dstptr + eltsz*dst_index, n);
508  return nullptr;
509  }
510  }
511 }

◆ create()

std::unique_ptr< SG::IAuxTypeVector > SG::RootAuxVectorFactory::create ( SG::auxid_t  auxid,
size_t  size,
size_t  capacity,
bool  isLinked 
) const
overridevirtual

Create a vector object of this type.

Parameters
auxidID for the variable being created.
sizeInitial size of the new vector.
capacityInitial capacity of the new vector.
isLinkedTrue if this variable is linked from another one.

Returns a newly-allocated object.

Parameters
auxidID for the variable being created.
sizeInitial size of the new vector.
capacityInitial capacity of the new vector.
isLinkedTrue if this variable is linked from another one.

Implements SG::IAuxTypeVectorFactory.

Definition at line 437 of file RootAuxVectorFactory.cxx.

441 {
442  return std::make_unique<RootAuxVector> (this, auxid, size, capacity,
443  isLinked);
444 }

◆ createFromData()

std::unique_ptr< SG::IAuxTypeVector > SG::RootAuxVectorFactory::createFromData ( SG::auxid_t  auxid,
void *  data,
IAuxTypeVector linkedVector,
bool  isPacked,
bool  ownFlag,
bool  isLinked 
) const
overridevirtual

Create a vector object of this type from a data blob.

Parameters
auxidID for the variable being created.
dataThe vector object.
linkedVectorThe interface for another variable linked to this one, or nullptr if there isn't one. (We do not take ownership.)
isPackedIf true, data is a PackedContainer.
ownFlagIf true, the newly-created IAuxTypeVector object will take ownership of data.
isLinkedTrue if this variable is linked from another one.

If the element type is T, then data should be a pointer to a std::vector<T> object, which was obtained with new.

This version does not support packed containers, so isPacked must be false.

Returns a newly-allocated object.

Implements SG::IAuxTypeVectorFactory.

Definition at line 468 of file RootAuxVectorFactory.cxx.

474 {
475  if (linkedVector) std::abort();
476  return std::make_unique<RootAuxVector> (this, auxid, data, isPacked, ownFlag,
477  isLinked);
478 }

◆ getEltSize()

size_t SG::RootAuxVectorFactory::getEltSize ( ) const
overridevirtual

Return the size of an element of this vector type.

Implements SG::IAuxTypeVectorFactory.

Definition at line 622 of file RootAuxVectorFactory.cxx.

623 {
624  return m_type.getSize();
625 }

◆ isDynamic()

bool SG::RootAuxVectorFactory::isDynamic ( ) const
overridevirtual

True if the vectors created by this factory work by dynamic emulation (via TVirtualCollectionProxy or similar); false if the std::vector code is used directly.

Implements SG::IAuxTypeVectorFactory.

Definition at line 642 of file RootAuxVectorFactory.cxx.

643 {
644  return true;
645 }

◆ offset()

size_t SG::RootAuxVectorFactory::offset ( ) const
inline

Return the offset of the vector within the object.

Definition at line 302 of file RootAuxVectorFactory.h.

302 { return m_offset; }

◆ rootType()

const RootUtils::Type& SG::RootAuxVectorFactory::rootType ( ) const
inline

Return the ROOT type wrapper.

Definition at line 280 of file RootAuxVectorFactory.h.

280 { return m_type; }

◆ swap()

void SG::RootAuxVectorFactory::swap ( SG::auxid_t  auxid,
AuxVectorData a,
size_t  aindex,
AuxVectorData b,
size_t  bindex,
size_t  n 
) const
overridevirtual

Swap elements between vectors.

Parameters
auxidThe aux data item being operated on.
aContainer for the first vector.
aindexIndex of the first element in the first vector.
bContainer for the second vector.
bindexIndex of the first element in the second vector.
nNumber of elements to swap.

a and @ b can be either the same or different. However, the ranges should not overlap.

Implements SG::IAuxTypeVectorFactory.

Definition at line 591 of file RootAuxVectorFactory.cxx.

595 {
596  if (n == 0) return;
597  void* aptr = a.getDataArray (auxid);
598  void* bptr = &a == &b ? aptr : b.getDataArray (auxid);
599  m_type.swapRange (aptr, aindex, bptr, bindex, n);
600 }

◆ tiAlloc()

const std::type_info * SG::RootAuxVectorFactory::tiAlloc ( ) const
overridevirtual

Return the type_info of the vector allocator.

May be nullptr for a dynamic vector.

Implements SG::IAuxTypeVectorFactory.

Definition at line 653 of file RootAuxVectorFactory.cxx.

654 {
655  return nullptr;
656 }

◆ tiAllocName()

std::string SG::RootAuxVectorFactory::tiAllocName ( ) const
overridevirtual

Return the (demangled) name of the vector allocator.

Implements SG::IAuxTypeVectorFactory.

Definition at line 662 of file RootAuxVectorFactory.cxx.

663 {
664  std::string name = SG::normalizedTypeinfoName (*m_vecClass->GetTypeInfo());
666  std::string alloc_name;
667  if (cn.ntargs() >= 2) {
668  alloc_name = cn.targ(1).fullName();
669  }
670  else if (cn.ntargs() == 1) {
671  alloc_name = "std::allocator<" + cn.targ(0).fullName();
672  if (alloc_name[alloc_name.size()-1] == '>') alloc_name += " ";
673  alloc_name += ">";
674  }
675  return alloc_name;
676 }

◆ tiVec()

const std::type_info * SG::RootAuxVectorFactory::tiVec ( ) const
overridevirtual

Return the type_info of the overall object.

Implements SG::IAuxTypeVectorFactory.

Definition at line 631 of file RootAuxVectorFactory.cxx.

632 {
633  return m_objClass->GetTypeInfo();
634 }

Member Data Documentation

◆ m_isEL

enum { ... } SG::RootAuxVectorFactory::m_isEL

Flag to tell whether we need to do thinning.

◆ m_objClass

TClass* SG::RootAuxVectorFactory::m_objClass
private

The TClass for the overall object.

Definition at line 460 of file RootAuxVectorFactory.h.

◆ m_offset

size_t SG::RootAuxVectorFactory::m_offset
private

Offset of the STL vector within the overall object.

Definition at line 466 of file RootAuxVectorFactory.h.

◆ m_type

RootUtils::Type SG::RootAuxVectorFactory::m_type
private

Wrapper for the ROOT type of the element.

Definition at line 469 of file RootAuxVectorFactory.h.

◆ m_vecClass

TClass* SG::RootAuxVectorFactory::m_vecClass
private

The TClass for the std::vector.

Definition at line 463 of file RootAuxVectorFactory.h.


The documentation for this class was generated from the following files:
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
RootUtils::Type::swapRange
void swapRange(void *a, size_t a_index, void *b, size_t b_index, size_t n) const
Swap a range of objects between vectors.
Definition: Type.cxx:567
RootUtils::Type::init
void init(const std::string &typname)
Initialize from a type name.
Definition: Type.cxx:154
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:392
WriteCellNoiseToCool.src
src
Definition: WriteCellNoiseToCool.py:513
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
SG::RootAuxVectorFactory::m_isEL
enum SG::RootAuxVectorFactory::@28 m_isEL
Flag to tell whether we need to do thinning.
ATHCONTAINERS_ERROR
#define ATHCONTAINERS_ERROR(ctx, msg)
Definition: error.h:50
SG::RootAuxVectorFactory::m_type
RootUtils::Type m_type
Wrapper for the ROOT type of the element.
Definition: RootAuxVectorFactory.h:469
SG::RootAuxVectorFactory::NONE
@ NONE
Definition: RootAuxVectorFactory.h:472
ElementLinkBase
Base class for ElementLinks to vectors of pointers.
Definition: AthLinks/ElementLinkBase.h:59
RootUtils::Type::getSize
size_t getSize() const
Return the size in bytes of an instance of the described type.
Definition: Type.cxx:375
SG::RootAuxVectorFactory::m_offset
size_t m_offset
Offset of the STL vector within the overall object.
Definition: RootAuxVectorFactory.h:466
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
CxxUtils::ClassName
Recursively separate out template arguments in a C++ class name.
Definition: CxxUtils/CxxUtils/ClassName.h:101
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:193
lumiFormat.i
int i
Definition: lumiFormat.py:92
RootUtils::Type::clearRange
void clearRange(void *dst, size_t n) const
Clear a range of objects.
Definition: Type.cxx:420
beamspotman.n
n
Definition: beamspotman.py:731
plotIsoValidation.el
el
Definition: plotIsoValidation.py:197
SG::IAuxTypeVectorFactory::copy
virtual void copy(SG::auxid_t auxid, AuxVectorData &dst, size_t dst_index, const AuxVectorData &src, size_t src_index, size_t n) const =0
Copy elements between vectors.
SG::RootAuxVectorFactory::ELEMENT_LINK_VECTOR
@ ELEMENT_LINK_VECTOR
Definition: RootAuxVectorFactory.h:472
SG::RootAuxVectorFactory::m_objClass
TClass * m_objClass
The TClass for the overall object.
Definition: RootAuxVectorFactory.h:460
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
SG::RootAuxVectorFactory::m_vecClass
TClass * m_vecClass
The TClass for the std::vector.
Definition: RootAuxVectorFactory.h:463
python.PyAthena.v
v
Definition: PyAthena.py:157
SG::RootAuxVectorFactory::ELEMENT_LINK
@ ELEMENT_LINK
Definition: RootAuxVectorFactory.h:472
a
TList * a
Definition: liststreamerinfos.cxx:10
RootUtils::Type::copyRange
void copyRange(void *dst, const void *src, size_t n) const
Copy a range of objects.
Definition: Type.cxx:389
CxxUtils::ClassName::match_t
std::map< std::string, ClassName > match_t
Map used to hold variable assignments from matching.
Definition: CxxUtils/CxxUtils/ClassName.h:200
SG::RootAuxVectorFactory::ELEMENT_LINK_NONPOINTER
@ ELEMENT_LINK_NONPOINTER
Definition: RootAuxVectorFactory.h:472
SG::RootAuxVectorFactory::copyImpl
char * copyImpl(SG::auxid_t auxid, AuxVectorData &dst, size_t dst_index, const AuxVectorData &src, size_t src_index, size_t n) const
Helper for copy; returns a pointer to the first destination object, or nullptr if the destination was...
Definition: RootAuxVectorFactory.cxx:483