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 277 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 489 of file RootAuxVectorFactory.h.

Constructor & Destructor Documentation

◆ RootAuxVectorFactory()

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

Constructor.

Parameters
vecClassThe TClass for the vector object.

Definition at line 371 of file RootAuxVectorFactory.cxx.

372  : m_objClass (objClass),
373  m_vecClass (objClass),
374  m_offset (0),
375  m_isEL (NONE)
376 {
377  TVirtualCollectionProxy* proxy = m_vecClass->GetCollectionProxy();
378 
379  if (!proxy) {
380  TClass* vecClass = lookupVectorType (objClass);
381  if (vecClass) {
382  m_vecClass = vecClass;
383  Int_t offs = objClass->GetBaseClassOffset (vecClass);
384  if (offs >= 0) {
385  m_offset = offs;
386  proxy = vecClass->GetCollectionProxy();
387  }
388  else {
389  ATHCONTAINERS_ERROR("RootAuxVectorFactory::RootAuxVectorFactory",
390  std::string("Can't find vector base class in ") +
391  objClass->GetName());
392  }
393  }
394  }
395 
396  if (!proxy) {
397  std::string err = "Can't find collection proxy for ";
398  err += m_vecClass->GetName();
399  throw std::runtime_error (err.c_str());
400  }
401 
402  if (m_vecClass->GetTypeInfo() == 0) {
403  ATHCONTAINERS_ERROR("RootAuxVectorFactory::RootAuxVectorFactory",
404  std::string("No type_info available for class ") +
405  m_vecClass->GetName() +
406  std::string(". There is probably a missing dictionary. We will likely crash further on."));
407  }
408 
409  TClass* eltClass = proxy->GetValueClass();
410  if (eltClass) {
411  m_type.init (eltClass);
412 
413  const std::type_info* ti = eltClass->GetTypeInfo();
414  if (ti) {
415 
416  static const CxxUtils::ClassName pat1 ("ElementLink<$T>");
417  static const CxxUtils::ClassName pat2 ("std::vector<ElementLink<$T> >");
418 
421  if (clname.match (pat1, matches)) {
423  if (eltClass->GetBaseClass ("ElementLinkBase") == nullptr) {
425  }
426  }
427  else if (clname.match (pat2, matches)) {
429 
430  TVirtualCollectionProxy* proxy2 = eltClass->GetCollectionProxy();
431  if (proxy2) {
432  TClass* innerEltClass = proxy2->GetValueClass();
433  if (innerEltClass) {
434  if (innerEltClass->GetBaseClass ("ElementLinkBase") == nullptr) {
436  }
437  }
438  }
439  }
440  }
441  }
442  else
443  m_type.init (proxy->GetType());
444 }

◆ ~RootAuxVectorFactory()

SG::RootAuxVectorFactory::~RootAuxVectorFactory ( )
overridevirtual

Destructor.

Definition at line 450 of file RootAuxVectorFactory.cxx.

451 {
452 }

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 305 of file RootAuxVectorFactory.h.

305 { 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 313 of file RootAuxVectorFactory.h.

313 { 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 636 of file RootAuxVectorFactory.cxx.

639 {
640  if (n == 0) return;
641  m_type.clearRange (dst.getDataArray (auxid), dst_index, n);
642 }

◆ 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 551 of file RootAuxVectorFactory.cxx.

557 {
558  (void)copyImpl (auxid, dst, dst_index, src, src_index, n);
559 }

◆ 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 574 of file RootAuxVectorFactory.cxx.

578 {
579  char* dstptr = copyImpl (auxid, dst, dst_index, src, src_index, n);
580 
581  if (m_isEL == ELEMENT_LINK) {
582  size_t eltsz = m_type.getSize();
583  for (size_t i = 0; i < n; i++) {
584  reinterpret_cast<ElementLinkBase*>(dstptr + i*eltsz)->thin();
585  }
586  }
587  else if (m_isEL == ELEMENT_LINK_VECTOR) {
588  size_t eltsz = m_type.getSize();
589  for (size_t i = 0; i < n; i++) {
590  std::vector<ElementLinkBase>& v =
591  *reinterpret_cast<std::vector<ElementLinkBase>* > (dstptr +i*eltsz);
592  for (ElementLinkBase& el : v) {
593  el.thin();
594  }
595  }
596  }
597  else if (m_isEL == ELEMENT_LINK_NONPOINTER) {
598  ATHCONTAINERS_ERROR("RootAuxVectorFactory::copyForOutput",
599  std::string("Cannot apply thinning for ElementLink with non-pointer element: ") +
600  m_vecClass->GetName());
601  }
602 }

◆ 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 509 of file RootAuxVectorFactory.cxx.

515 {
516  if (n == 0) return nullptr;
517  size_t eltsz = m_type.getSize();
518  char* dstptr = reinterpret_cast<char*> (dst.getDataArray (auxid));
519  if (&src == &dst) {
520  // Source and destination containers are the same,
521  // so we don't need to bother with fetching the src pointer.
522  // copyRange properly handles overlapping regions.
523  m_type.copyRange (dstptr + eltsz*dst_index, dstptr + eltsz*src_index, n);
524  return dstptr + eltsz*dst_index;
525  }
526  else {
527  const char* srcptr = reinterpret_cast<const char*>(src.getDataArrayAllowMissing (auxid));
528  if (srcptr) {
529  m_type.copyRange (dstptr + eltsz*dst_index, srcptr + eltsz*src_index, n);
530  return dstptr + eltsz*dst_index;
531  }
532  else {
533  m_type.clearRange (dstptr + eltsz*dst_index, n);
534  return nullptr;
535  }
536  }
537 }

◆ 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 463 of file RootAuxVectorFactory.cxx.

467 {
468  return std::make_unique<RootAuxVector> (this, auxid, size, capacity,
469  isLinked);
470 }

◆ 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 494 of file RootAuxVectorFactory.cxx.

500 {
501  if (linkedVector) std::abort();
502  return std::make_unique<RootAuxVector> (this, auxid, data, isPacked, ownFlag,
503  isLinked);
504 }

◆ getEltSize()

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

Return the size of an element of this vector type.

Implements SG::IAuxTypeVectorFactory.

Definition at line 648 of file RootAuxVectorFactory.cxx.

649 {
650  return m_type.getSize();
651 }

◆ 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 668 of file RootAuxVectorFactory.cxx.

669 {
670  return true;
671 }

◆ offset()

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

Return the offset of the vector within the object.

Definition at line 319 of file RootAuxVectorFactory.h.

319 { return m_offset; }

◆ rootType()

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

Return the ROOT type wrapper.

Definition at line 297 of file RootAuxVectorFactory.h.

297 { 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 617 of file RootAuxVectorFactory.cxx.

621 {
622  if (n == 0) return;
623  void* aptr = a.getDataArray (auxid);
624  void* bptr = &a == &b ? aptr : b.getDataArray (auxid);
625  m_type.swapRange (aptr, aindex, bptr, bindex, n);
626 }

◆ 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 679 of file RootAuxVectorFactory.cxx.

680 {
681  return nullptr;
682 }

◆ tiAllocName()

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

Return the (demangled) name of the vector allocator.

Implements SG::IAuxTypeVectorFactory.

Definition at line 688 of file RootAuxVectorFactory.cxx.

689 {
690  std::string name = SG::normalizedTypeinfoName (*m_vecClass->GetTypeInfo());
692  std::string alloc_name;
693  if (cn.ntargs() >= 2) {
694  alloc_name = cn.targ(1).fullName();
695  }
696  else if (cn.ntargs() == 1) {
697  alloc_name = "std::allocator<" + cn.targ(0).fullName();
698  if (alloc_name[alloc_name.size()-1] == '>') alloc_name += " ";
699  alloc_name += ">";
700  }
701  return alloc_name;
702 }

◆ tiVec()

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

Return the type_info of the overall object.

Implements SG::IAuxTypeVectorFactory.

Definition at line 657 of file RootAuxVectorFactory.cxx.

658 {
659  return m_objClass->GetTypeInfo();
660 }

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 477 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 483 of file RootAuxVectorFactory.h.

◆ m_type

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

Wrapper for the ROOT type of the element.

Definition at line 486 of file RootAuxVectorFactory.h.

◆ m_vecClass

TClass* SG::RootAuxVectorFactory::m_vecClass
private

The TClass for the std::vector.

Definition at line 480 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:54
SG::RootAuxVectorFactory::m_type
RootUtils::Type m_type
Wrapper for the ROOT type of the element.
Definition: RootAuxVectorFactory.h:486
SG::RootAuxVectorFactory::NONE
@ NONE
Definition: RootAuxVectorFactory.h:489
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:483
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:182
lumiFormat.i
int i
Definition: lumiFormat.py:85
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:489
SG::RootAuxVectorFactory::m_objClass
TClass * m_objClass
The TClass for the overall object.
Definition: RootAuxVectorFactory.h:477
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
SG::RootAuxVectorFactory::m_vecClass
TClass * m_vecClass
The TClass for the std::vector.
Definition: RootAuxVectorFactory.h:480
python.PyAthena.v
v
Definition: PyAthena.py:154
SG::RootAuxVectorFactory::ELEMENT_LINK
@ ELEMENT_LINK
Definition: RootAuxVectorFactory.h:489
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:489
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:509