ATLAS Offline Software
Loading...
Searching...
No Matches
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.
virtual ~TAuxVectorFactory ()
 Destructor.
 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.
Functions implementing the SG::IAuxTypeVectorFactory interface
virtual std::unique_ptr< SG::IAuxTypeVectorcreate (SG::auxid_t auxid, size_t size, size_t capacity, bool isLinked) const override
 Create a new vector in memory with the requested size and capacity.
virtual std::unique_ptr< SG::IAuxTypeVectorcreateFromData (SG::auxid_t auxid, void *data, SG::IAuxTypeVector *linkedVector, bool isPacked, bool ownFlag, bool isLinked) const override
 Create a vector object of this type from a data blob.
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.
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.
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.
void clear (void *dst, size_t dst_index, size_t n) const
 Clear the payload of a given range inside a vector.
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.
virtual size_t getEltSize () const override
 Size of the elements inside the vector type.
virtual const std::type_info * tiVec () const override
 Type info of the vector type handled by the factory object.
virtual bool isDynamic () const override
 Type of the factory.
virtual const std::type_info * tiAlloc () const override
 Return the type_info of the vector allocator.
virtual std::string tiAllocName () const override
 Return the (demangled) name of the vector allocator.

Private Attributes

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

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 }
#define XAOD_MESSAGE(MESSAGE)
Simple macro for printing error/verbose messages.
void * m_defElt
Pointer to a default element object in memory.
::TClass * m_class
The type that this factory operates on.
::TVirtualCollectionProxy * m_proxy
ROOT's description of the vector type.
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]

◆ ~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 230 of file TAuxVectorFactory.cxx.

233 {
234
235 clear( dst.getDataArray (auxid), dst_index, n );
236 return;
237 }
const void * getDataArray(SG::auxid_t auxid) const
Return a const pointer to the start of an aux data vector.
void clear(void *dst, size_t dst_index, size_t n) const
Clear the payload of a given range inside a vector.

◆ 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 200 of file TAuxVectorFactory.cxx.

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

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

◆ 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 81 of file TAuxVectorFactory.cxx.

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

◆ 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 128 of file TAuxVectorFactory.cxx.

132 {
133
134 // Do a "regular" copy.
135 copy( auxid, dst, dst_index, src, src_index, n );
136
137 ::Warning( "xAOD::TAuxVectorFactory::TAuxVectorFactory",
138 XAOD_MESSAGE( "copyForOutput called; should only be used "
139 "with pool converters." ) );
140 }
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.

◆ create()

std::unique_ptr< SG::IAuxTypeVector > xAOD::TAuxVectorFactory::create ( SG::auxid_t auxid,
size_t size,
size_t capacity,
bool isLinked ) 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.

62 {
63
64 return std::make_unique< TAuxVector >( this, auxid,
66 size, capacity,
67 isLinked );
68 }
const T * as_const_ptr(const T *p)
Helper for getting a const version of a pointer.

◆ createFromData()

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

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

Implements SG::IAuxTypeVectorFactory.

Definition at line 71 of file TAuxVectorFactory.cxx.

76 {
77
78 std::abort();
79 }

◆ getEltSize()

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

Size of the elements inside the vector type.

Implements SG::IAuxTypeVectorFactory.

Definition at line 239 of file TAuxVectorFactory.cxx.

239 {
240
241 return m_proxy->GetIncrement();
242 }

◆ isDynamic()

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

Type of the factory.

Implements SG::IAuxTypeVectorFactory.

Definition at line 91 of file TAuxVectorFactory.h.

91{ 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 142 of file TAuxVectorFactory.cxx.

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

◆ 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 249 of file TAuxVectorFactory.cxx.

249 {
250
251 return nullptr;
252 }

◆ tiAllocName()

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

Return the (demangled) name of the vector allocator.

Implements SG::IAuxTypeVectorFactory.

Definition at line 254 of file TAuxVectorFactory.cxx.

254 {
255
256 std::string name = SG::normalizedTypeinfoName (*m_class->GetTypeInfo());
257 CxxUtils::ClassName cn (name);
258 std::string alloc_name;
259 if (cn.ntargs() >= 2) {
260 alloc_name = cn.targ(1).fullName();
261 }
262 else if (cn.ntargs() == 1) {
263 alloc_name = "std::allocator<" + cn.targ(0).fullName();
264 if (alloc_name[alloc_name.size()-1] == '>') alloc_name += " ";
265 alloc_name += ">";
266 }
267 return alloc_name;
268 }
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...

◆ 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 244 of file TAuxVectorFactory.cxx.

244 {
245
246 return m_class->GetTypeInfo();
247 }

Member Data Documentation

◆ ATLAS_THREAD_SAFE

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

Assignment operator.

Definition at line 115 of file TAuxVectorFactory.h.

◆ m_class

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

The type that this factory operates on.

Definition at line 111 of file TAuxVectorFactory.h.

◆ m_defElt

void* xAOD::TAuxVectorFactory::m_defElt
private

Pointer to a default element object in memory.

Definition at line 117 of file TAuxVectorFactory.h.

◆ m_proxy

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

ROOT's description of the vector type.

Definition at line 113 of file TAuxVectorFactory.h.


The documentation for this class was generated from the following files: