ATLAS Offline Software
Loading...
Searching...
No Matches
TAuxVector.cxx
Go to the documentation of this file.
1// Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2
3// ROOT include(s):
4#include <TClass.h>
5#include <TVirtualCollectionProxy.h>
6#include <TError.h>
7
8// EDM include(s):
12
13// Local include(s):
17
18namespace xAOD {
19
22 const ::TClass* cl, size_t size, size_t,
23 bool isLinked )
25 m_factory( factory ),
26 m_proxy( cl->GetCollectionProxy()->Generate() ), m_vec( cl->New() ) {
27
28 // A little sanity check:
29 if( ! m_proxy ) {
30 ::Fatal( "xAOD::TAuxVector::TAuxVector",
31 XAOD_MESSAGE( "No collection proxy found for type %s" ),
32 cl->GetName() );
33 }
34 else {
35 m_proxy->PushProxy( m_vec );
36 }
37
38 // Make sure the object is of the right size:
39 this->resize( size );
40 }
41
43 : IAuxTypeVector( parent ),
44 m_factory( parent.m_factory ), m_proxy( parent.m_proxy->Generate() ),
45 m_vec( parent.m_proxy->GetCollectionClass()->New() ) {
46
47 m_proxy->PushProxy( m_vec );
48
49 // Check the size of the parent object:
50 const size_t size = parent.size();
51 // Check if we need to do anything:
52 if( ! size ) {
53 return;
54 }
55
56 // First off, resize this vector:
57 this->resize( size );
58
59 // Get a pointer to the start of the parent's payload:
60 const void* parentPtr = parent.toPtr();
61
62 // Do the copy:
63 this->copyRange( parentPtr, this->toPtr(), size );
64 }
65
67
68 m_proxy->Destructor( m_vec );
69 }
70
72
73 // Check if anything needs to be done:
74 if( this == &other ) {
75 return *this;
76 }
77
78 // Clean out the previous payload:
79 m_proxy->Destructor( m_vec );
80
81 // Get the information from the other object:
82 IAuxTypeVector::operator=( other );
83 m_factory = other.m_factory;
84 m_proxy.reset( other.m_proxy->Generate() );
85
86 // Create a new vector:
87 m_vec = m_proxy->GetCollectionClass()->New();
88 m_proxy->PushProxy( m_vec );
89
90 IAuxTypeVector::resetDataSpan();
91
92 // Check the size of the other object:
93 const size_t size = other.size();
94 // Check if we need to do anything:
95 if( ! size ) {
96 return *this;
97 }
98
99 // Get a pointer to the start of the other object's payload:
100 const void* otherPtr = other.toPtr();
101
102 // Do the copy:
103 this->copyRange( otherPtr, this->toPtr(), size );
104
105 // Return a reference to this object:
106 return *this;
107 }
108
109 std::unique_ptr< SG::IAuxTypeVector > TAuxVector::clone() const {
110
111 return std::make_unique< TAuxVector >( *this );
112 }
113
114
116
117 return m_proxy->At( 0 );
118 }
119
120 const void* TAuxVector::toPtr() const {
121
122 return m_proxy->At( 0 );
123 }
124
126
127 return m_vec;
128 }
129
130 size_t TAuxVector::size() const {
131
132 return m_proxy->Size();
133 }
134
135 bool TAuxVector::resize( size_t sz ) {
136
137 const void* orig = this->getDataSpan().beg;
138 m_proxy->Allocate( sz, false );
139 this->storeDataSpan();
140 return this->getDataSpan().beg == orig;
141 }
142
143 void TAuxVector::reserve( size_t ) {
144
145 return;
146 }
147
174 bool TAuxVector::shift( size_t pos, ptrdiff_t offs ) {
175
176 size_t eltsz = m_proxy->GetIncrement();
177 if( offs < 0 ) {
178
179 if( -offs > static_cast< ptrdiff_t >( pos ) ) {
180 offs = -pos;
181 }
182 char* beg = reinterpret_cast< char* >( m_proxy->At( 0 ) );
183 copyRange( beg + eltsz * pos,
184 beg + eltsz * ( pos + offs ),
185 m_proxy->Size() - pos );
186 m_proxy->Allocate( m_proxy->Size() + offs, false );
187 this->storeDataSpan();
188 return true;
189
190 } else if( offs > 0 ) {
191
192 size_t oldsz = m_proxy->Size();
193 m_proxy->Allocate( oldsz + offs, false );
194 char* beg = reinterpret_cast< char* >( m_proxy->At( 0 ) );
195 copyRange( beg + eltsz * pos,
196 beg + eltsz * ( pos + offs ),
197 m_proxy->Size() - pos - offs);
198 clearRange( beg + eltsz * pos, offs );
199 this->storeDataSpan();
200 return false;
201 }
202
203 return true;
204 }
205
206 bool TAuxVector::insertMove (size_t pos,
207 void* src, size_t src_pos, size_t src_n,
208 SG::IAuxStore& /*srcStore*/)
209 {
210 size_t eltsz = m_proxy->GetIncrement();
211 const void* orig = this->getDataSpan().beg;
212
213 char* srcp = reinterpret_cast<char*> (src);
214 char* begp = srcp + src_pos*eltsz;
215
216 shift (pos, src_n);
217 // FIXME: want move, not copy.
218 // But i don't seem to be able to call move operations through cling,
219 // so just use copy for now.
220 copyRange (begp,
221 reinterpret_cast<char*>(this->toPtr()) + pos*eltsz,
222 src_n);
223 this->storeDataSpan();
224 return this->getDataSpan().beg == orig;
225 }
226
227
228 void TAuxVector::copyRange( const void* src, void* dst, size_t n ) {
229
230 SG::AuxVectorInterface idst( auxid(), n, dst );
231 m_factory->copy( auxid(),
232 idst, 0,
233 SG::AuxVectorInterface( auxid(), n, src ), 0,
234 n );
235
236 return;
237 }
238
239 void TAuxVector::clearRange( void* dst, size_t n ) {
240
241 // Size of an element in the vector:
242 size_t eltsz = m_proxy->GetIncrement();
243
244 // If the payload is a class:
245 if( m_proxy->GetValueClass() ) {
246 m_factory->clear (dst, 0, n);
247 }
248 // If the payload is an array of primitives, the cleaning is much simpler:
249 else {
250 memset( dst, 0, n * eltsz );
251 }
252
253 return;
254 }
255
257 {
258 return SG::AuxDataSpanBase( const_cast<void*> (toPtr()), size() );
259 }
260
262 {
263 IAuxTypeVector::storeDataSpan( toPtr(), size() );
264 }
265
266} // namespace xAOD
Manage lookup of vectors of auxiliary data.
Make an AuxVectorData object from either a raw vector or an aux store.
#define XAOD_MESSAGE(MESSAGE)
Simple macro for printing error/verbose messages.
Interface for factory objects that create vectors.
static Double_t sz
Make an AuxVectorData object from either a raw array or an aux store.
Interface for non-const operations on an auxiliary store.
Definition IAuxStore.h:48
bool isLinked() const
Return true if this variable is linked from another one.
auxid_t auxid() const
Return the auxid of the variable this vector represents.
const AuxDataSpanBase & getDataSpan() const
Return a reference to a description of this vector's start+size.
IAuxTypeVector(auxid_t auxid, bool isLinked)
Constructor.
Auxiliary vector factory based on a ROOT dictionary.
TAuxVector & operator=(const TAuxVector &other)
Assignment operator.
~TAuxVector()
Destructor.
virtual void * toPtr() override
Return a pointer to the start of the vector's data.
virtual bool insertMove(size_t pos, void *src, size_t src_pos, size_t src_n, SG::IAuxStore &srcStore) override
Insert a range of elements via move.
TAuxVector(const TAuxVectorFactory *factory, SG::auxid_t auxid, const ::TClass *cl, size_t size, size_t capacity, bool isLinked)
Constructor.
virtual void reserve(size_t sz) override
Change the capacity of the vector.
virtual void * toVector() override
Return a pointer to the STL vector itself.
void storeDataSpan()
Update the stored span.
std::unique_ptr<::TVirtualCollectionProxy > m_proxy
ROOT's description of the vector type Cloned from the proxy held by the TClass and permanently bound ...
Definition TAuxVector.h:94
void copyRange(const void *src, void *dst, size_t n)
Function copying the payload of a range to a new location.
virtual bool shift(size_t pos, ptrdiff_t offs) override
Shift the elements of the vector.
virtual size_t size() const override
Return the size of the vector.
virtual bool resize(size_t sz) override
Change the size of the vector.
void clearRange(void *dst, size_t n)
void * m_vec
Pointer to the vector object.
Definition TAuxVector.h:96
const TAuxVectorFactory * m_factory
The parent factory object.
Definition TAuxVector.h:89
virtual std::unique_ptr< SG::IAuxTypeVector > clone() const override
Copy the managed vector.
virtual SG::AuxDataSpanBase getDataSpanImpl() const override final
Return a span object describing the current vector.
size_t auxid_t
Identifier for a particular aux data item.
Definition AuxTypes.h:27
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Minimal span-like object describing the range of an auxiliary variable.
Definition AuxDataSpan.h:40
void * beg
Pointer to the start of the variable's vector.
Definition AuxDataSpan.h:54