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

Auxiliary vector factory based on a ROOT dictionary. More...

#include <TAuxVectorFactory.h>

Inheritance diagram for xAOD::TAuxVectorFactory:
Collaboration diagram for xAOD::TAuxVectorFactory:

Public Member Functions

 TAuxVectorFactory (::TClass *cl)
 Constructor, setting up the object based on a dictionary. More...
 
virtual ~TAuxVectorFactory ()
 Destructor. More...
 
 TAuxVectorFactory (const TAuxVectorFactory &)=delete
 
TAuxVectorFactoryoperator= (const TAuxVectorFactory &)=delete
 
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...
 
Functions implementing the SG::IAuxTypeVectorFactory interface
virtual std::unique_ptr< SG::IAuxTypeVectorcreate (SG::auxid_t auxid, size_t size, size_t capacity) const override
 Create a new vector in memory with the requested size and capacity. More...
 
virtual std::unique_ptr< SG::IAuxTypeVectorcreateFromData (SG::auxid_t auxid, void *data, bool isPacked, bool ownFlag) const override
 Create a vector object of this type from a data blob. More...
 
virtual void copy (SG::auxid_t auxid, SG::AuxVectorData &dst, size_t dst_index, const SG::AuxVectorData &src, size_t src_index, size_t n) const override
 Copy elements from one location to another. More...
 
virtual void copyForOutput (SG::auxid_t auxid, SG::AuxVectorData &dst, size_t dst_index, const SG::AuxVectorData &src, size_t src_index, size_t n) const override
 Copy one element from one location to another. More...
 
virtual void swap (SG::auxid_t auxid, SG::AuxVectorData &a, size_t aindex, SG::AuxVectorData &b, size_t bindex, size_t n) const override
 Swap the payload of two ranges of elements in memory. More...
 
void clear (void *dst, size_t dst_index, size_t n) const
 Clear the payload of a given range inside a vector. More...
 
virtual void clear (SG::auxid_t auxid, SG::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
 Size of the elements inside the vector type. More...
 
virtual const std::type_info * tiVec () const override
 Type info of the vector type handled by the factory object. More...
 
virtual bool isDynamic () const override
 Type of the factory. 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...
 

Private Attributes

::TClass * m_class
 The type that this factory operates on. More...
 
::TVirtualCollectionProxy * m_proxy
 ROOT's description of the vector type. More...
 
RootUtils::TSMethodCall m_assign ATLAS_THREAD_SAFE
 Assignment operator. More...
 
void * m_defElt
 Pointer to a default element object in memory. More...
 

Detailed Description

Auxiliary vector factory based on a ROOT dictionary.

Factory implementation that creates vectors that can be operated on using ROOT's dictionary for the underlying vector type.

The code is pretty much a copy of what Scott wrote for RootStorageSvc for the offline code.

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

Definition at line 30 of file TAuxVectorFactory.h.

Constructor & Destructor Documentation

◆ TAuxVectorFactory() [1/2]

xAOD::TAuxVectorFactory::TAuxVectorFactory ( ::TClass *  cl)

Constructor, setting up the object based on a dictionary.

Definition at line 22 of file TAuxVectorFactory.cxx.

23  : m_class( cl ), m_proxy( cl->GetCollectionProxy() ),
24  m_defElt( 0 ) {
25 
26  // A little sanity check:
27  if( ! m_proxy ) {
28  ::Fatal( "xAOD::TAuxVectorFactory::TAuxVectorFactory",
29  XAOD_MESSAGE( "No collection proxy found for type %s" ),
30  cl->GetName() );
31  }
32  else {
33  // Check if the elements of the vector are objects:
34  ::TClass* eltClass = m_proxy->GetValueClass();
35  if( eltClass ) {
36  // Initialise the assignment operator's method call:
37  std::string proto = "const ";
38  proto += eltClass->GetName();
39  proto += "&";
40  m_assign.setProto( eltClass, "operator=", proto );
41  if( m_assign.call() == nullptr ) {
42  ::Warning( "xAOD::TAuxVectorFactory::TAuxVectorFactory",
43  XAOD_MESSAGE( "Can't get assignment operator for "
44  "class %s" ),
45  eltClass->GetName() );
46  }
47  m_defElt = eltClass->New();
48  }
49  }
50  }

◆ ~TAuxVectorFactory()

xAOD::TAuxVectorFactory::~TAuxVectorFactory ( )
virtual

Destructor.

Definition at line 52 of file TAuxVectorFactory.cxx.

52  {
53 
54  // Remove the default element from memory if it exists:
55  if( m_defElt ) {
56  m_proxy->GetValueClass()->Destructor( m_defElt );
57  }
58  }

◆ TAuxVectorFactory() [2/2]

xAOD::TAuxVectorFactory::TAuxVectorFactory ( const TAuxVectorFactory )
delete

Member Function Documentation

◆ clear() [1/2]

void xAOD::TAuxVectorFactory::clear ( SG::auxid_t  auxid,
SG::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 225 of file TAuxVectorFactory.cxx.

228  {
229 
230  clear( dst.getDataArray (auxid), dst_index, n );
231  return;
232  }

◆ clear() [2/2]

void xAOD::TAuxVectorFactory::clear ( void *  dst,
size_t  dst_index,
size_t  n 
) const

Clear the payload of a given range inside a vector.

Definition at line 195 of file TAuxVectorFactory.cxx.

197  {
198 
199  if (n == 0) return;
200 
201  // The size of one element in memory:
202  const size_t eltsz = m_proxy->GetIncrement();
203 
204  // Get the memory address of the element:
205  char* dptr = reinterpret_cast< char* >( dst ) + eltsz * dst_index;
206 
207  TMethodCall* mc = m_assign.call();
208  if( mc ) {
209  // Assign the default element's contents to this object:
210  for (size_t i = 0; i < n; ++i) {
211  mc->ResetParam();
212  mc->SetParam( ( Long_t ) m_defElt );
213  mc->Execute( static_cast<void*>( dptr ) );
214  dptr += eltsz;
215  }
216  } else {
217  // Set the memory to zero:
218  memset( dst, 0, eltsz*n );
219  }
220 
221  return;
222  }

◆ 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 124 of file IAuxTypeVectorFactory.h.

128  {
129  copy (auxid, dst, dst_index, src, src_index, n);
130  }

◆ copy() [2/2]

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

Copy elements from one location to another.

Implements SG::IAuxTypeVectorFactory.

Definition at line 76 of file TAuxVectorFactory.cxx.

79  {
80 
81  if (n == 0) return;
82 
83  // The size of one element in memory:
84  const size_t eltsz = m_proxy->GetIncrement();
85 
86  // Get the location of the source and target element in memory:
87  char* dstptr = reinterpret_cast<char*> (dst.getDataArray (auxid));
88  const char* srcptr = &dst == &src ? dstptr : reinterpret_cast<const char*>(src.getDataArray (auxid));
89  dstptr += eltsz * dst_index;
90  srcptr += eltsz * src_index;
91 
92  // Do the copy either using the assignment operator of the type, or using
93  // simple memory copying:
94  TMethodCall* mc = m_assign.call();
95  if( mc ) {
96  auto copyone = [mc] (void* dst, const void* src)
97  {
98  mc->ResetParam();
99  mc->SetParam( ( Long_t ) src );
100  mc->Execute( dst );
101  };
102 
103  // If the source range doesn't overlap with the destination:
104  if( dstptr > srcptr && ( srcptr + n * eltsz ) > dstptr ) {
105  for( size_t i = n - 1; i < n; --i ) {
106  copyone( dstptr + i*eltsz, srcptr + i*eltsz );
107  }
108  }
109  // If it does:
110  else {
111  for( size_t i = 0; i < n; ++i ) {
112  copyone( dstptr + i*eltsz, srcptr + i*eltsz );
113  }
114  }
115 
116  } else {
117  memmove( dstptr, srcptr, n * eltsz );
118  }
119 
120  return;
121  }

◆ copyForOutput()

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

Copy one element from one location to another.

Implements SG::IAuxTypeVectorFactory.

Definition at line 123 of file TAuxVectorFactory.cxx.

127  {
128 
129  // Do a "regular" copy.
130  copy( auxid, dst, dst_index, src, src_index, n );
131 
132  ::Warning( "xAOD::TAuxVectorFactory::TAuxVectorFactory",
133  XAOD_MESSAGE( "copyForOutput called; should only be used "
134  "with pool converters." ) );
135  }

◆ create()

std::unique_ptr< SG::IAuxTypeVector > xAOD::TAuxVectorFactory::create ( SG::auxid_t  auxid,
size_t  size,
size_t  capacity 
) const
overridevirtual

Create a new vector in memory with the requested size and capacity.

Implements SG::IAuxTypeVectorFactory.

Definition at line 61 of file TAuxVectorFactory.cxx.

61  {
62 
63  return std::make_unique< TAuxVector >( this, auxid,
65  size, capacity );
66  }

◆ createFromData()

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

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

Implements SG::IAuxTypeVectorFactory.

Definition at line 69 of file TAuxVectorFactory.cxx.

71  {
72 
73  std::abort();
74  }

◆ getEltSize()

size_t xAOD::TAuxVectorFactory::getEltSize ( ) const
overridevirtual

Size of the elements inside the vector type.

Implements SG::IAuxTypeVectorFactory.

Definition at line 234 of file TAuxVectorFactory.cxx.

234  {
235 
236  return m_proxy->GetIncrement();
237  }

◆ isDynamic()

virtual bool xAOD::TAuxVectorFactory::isDynamic ( ) const
inlineoverridevirtual

Type of the factory.

Implements SG::IAuxTypeVectorFactory.

Definition at line 87 of file TAuxVectorFactory.h.

87 { return true; }

◆ operator=()

TAuxVectorFactory& xAOD::TAuxVectorFactory::operator= ( const TAuxVectorFactory )
delete

◆ swap()

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

Swap the payload of two ranges of elements in memory.

Implements SG::IAuxTypeVectorFactory.

Definition at line 137 of file TAuxVectorFactory.cxx.

140  {
141 
142  if (n == 0) return;
143 
144  // The size of one element in memory:
145  const size_t eltsz = m_proxy->GetIncrement();
146 
147  // Get the location of the two elements in memory:
148  char* aptr = reinterpret_cast<char*>( a.getDataArray (auxid) );
149  char* bptr = &a == &b ? aptr : reinterpret_cast<char*>( b.getDataArray (auxid) );
150  aptr += eltsz * aindex;
151  bptr += eltsz * bindex;
152 
153  TMethodCall* mc = m_assign.call();
154  if( mc ) {
155 
156  // Create a temporary object in memory:
157  TClass* eltClass = m_proxy->GetValueClass();
158  void* tmp = eltClass->New();
159 
160  for (size_t i = 0; i < n; ++i) {
161  // tmp = a
162  mc->ResetParam();
163  mc->SetParam( ( Long_t ) aptr );
164  mc->Execute( static_cast<void*>( tmp ) );
165  // a = b
166  mc->ResetParam();
167  mc->SetParam( ( Long_t ) bptr );
168  mc->Execute( static_cast<void*>( aptr ) );
169  // b = tmp
170  mc->ResetParam();
171  mc->SetParam( ( Long_t ) tmp );
172  mc->Execute( static_cast<void*>( bptr ) );
173  aptr += eltsz;
174  bptr += eltsz;
175  }
176 
177  // Delete the temporary object:
178  eltClass->Destructor( tmp );
179 
180  } else {
181 
182  // Allocate some temporary memory for the swap:
183  std::vector< char > tmp( eltsz*n );
184  // tmp = a
185  memcpy( tmp.data(), aptr, eltsz*n );
186  // a = b
187  memcpy( aptr, bptr, eltsz*n );
188  // b = tmp
189  memcpy( bptr, tmp.data(), eltsz*n );
190  }
191 
192  return;
193  }

◆ tiAlloc()

const std::type_info * xAOD::TAuxVectorFactory::tiAlloc ( ) const
overridevirtual

Return the type_info of the vector allocator.

May be nullptr for a dynamic vector.

Implements SG::IAuxTypeVectorFactory.

Definition at line 244 of file TAuxVectorFactory.cxx.

244  {
245 
246  return nullptr;
247  }

◆ tiAllocName()

std::string xAOD::TAuxVectorFactory::tiAllocName ( ) const
overridevirtual

Return the (demangled) name of the vector allocator.

Implements SG::IAuxTypeVectorFactory.

Definition at line 249 of file TAuxVectorFactory.cxx.

249  {
250 
251  std::string name = SG::normalizedTypeinfoName (*m_class->GetTypeInfo());
253  std::string alloc_name;
254  if (cn.ntargs() >= 2) {
255  alloc_name = cn.targ(1).fullName();
256  }
257  else if (cn.ntargs() == 1) {
258  alloc_name = "std::allocator<" + cn.targ(0).fullName();
259  if (alloc_name[alloc_name.size()-1] == '>') alloc_name += " ";
260  alloc_name += ">";
261  }
262  return alloc_name;
263  }

◆ tiVec()

const std::type_info * xAOD::TAuxVectorFactory::tiVec ( ) const
overridevirtual

Type info of the vector type handled by the factory object.

Implements SG::IAuxTypeVectorFactory.

Definition at line 239 of file TAuxVectorFactory.cxx.

239  {
240 
241  return m_class->GetTypeInfo();
242  }

Member Data Documentation

◆ ATLAS_THREAD_SAFE

RootUtils::TSMethodCall m_assign xAOD::TAuxVectorFactory::ATLAS_THREAD_SAFE
mutableprivate

Assignment operator.

Definition at line 111 of file TAuxVectorFactory.h.

◆ m_class

::TClass* xAOD::TAuxVectorFactory::m_class
private

The type that this factory operates on.

Definition at line 107 of file TAuxVectorFactory.h.

◆ m_defElt

void* xAOD::TAuxVectorFactory::m_defElt
private

Pointer to a default element object in memory.

Definition at line 113 of file TAuxVectorFactory.h.

◆ m_proxy

::TVirtualCollectionProxy* xAOD::TAuxVectorFactory::m_proxy
private

ROOT's description of the vector type.

Definition at line 109 of file TAuxVectorFactory.h.


The documentation for this class was generated from the following files:
xAOD::TAuxVectorFactory::copy
virtual void copy(SG::auxid_t auxid, SG::AuxVectorData &dst, size_t dst_index, const SG::AuxVectorData &src, size_t src_index, size_t n) const override
Copy elements from one location to another.
Definition: TAuxVectorFactory.cxx:76
xAOD::name
name
Definition: TriggerMenuJson_v1.cxx:29
SG::AuxVectorData::getDataArray
const void * getDataArray(SG::auxid_t auxid) const
Return a const pointer to the start of an aux data vector.
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
xAOD::TAuxVectorFactory::clear
void clear(void *dst, size_t dst_index, size_t n) const
Clear the payload of a given range inside a vector.
Definition: TAuxVectorFactory.cxx:195
XAOD_MESSAGE
#define XAOD_MESSAGE(MESSAGE)
Simple macro for printing error/verbose messages.
Definition: Control/xAODRootAccess/xAODRootAccess/tools/Message.h:19
xAOD::TAuxVectorFactory::m_defElt
void * m_defElt
Pointer to a default element object in memory.
Definition: TAuxVectorFactory.h:113
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
mc
Definition: mc.PG_single_nu_valid.py:1
CxxUtils::ClassName
Recursively separate out template arguments in a C++ class name.
Definition: CxxUtils/CxxUtils/ClassName.h:101
lumiFormat.i
int i
Definition: lumiFormat.py:92
beamspotman.n
n
Definition: beamspotman.py:731
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.
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
xAOD::TAuxVectorFactory::m_proxy
::TVirtualCollectionProxy * m_proxy
ROOT's description of the vector type.
Definition: TAuxVectorFactory.h:109
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
CxxUtils::as_const_ptr
const T * as_const_ptr(const T *p)
Helper for getting a const version of a pointer.
Definition: as_const_ptr.h:32
a
TList * a
Definition: liststreamerinfos.cxx:10
xAOD::TAuxVectorFactory::m_class
::TClass * m_class
The type that this factory operates on.
Definition: TAuxVectorFactory.h:107
covarianceTool.mc
mc
Definition: covarianceTool.py:554
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26