ATLAS Offline Software
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 
18 namespace xAOD {
19 
21  SG::auxid_t auxid,
22  const ::TClass* cl, size_t size, size_t,
23  bool isLinked )
24  : IAuxTypeVector( auxid, 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 
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
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:81
xAOD::TAuxVector::reserve
virtual void reserve(size_t sz) override
Change the capacity of the vector.
Definition: TAuxVector.cxx:143
SG::IAuxTypeVector::getDataSpan
const AuxDataSpanBase & getDataSpan() const
Return a reference to a description of this vector's start+size.
Definition: IAuxTypeVector.h:261
fitman.sz
sz
Definition: fitman.py:527
xAOD::TAuxVector::toVector
virtual void * toVector() override
Return a pointer to the STL vector itself.
Definition: TAuxVector.cxx:125
AuxVectorInterface.h
Make an AuxVectorData object from either a raw vector or an aux store.
WriteCellNoiseToCool.src
src
Definition: WriteCellNoiseToCool.py:513
xAOD::TAuxVector::m_proxy
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
xAOD::other
@ other
Definition: TrackingPrimitives.h:509
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
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:200
XAOD_MESSAGE
#define XAOD_MESSAGE(MESSAGE)
Simple macro for printing error/verbose messages.
Definition: Control/xAODRootAccess/xAODRootAccess/tools/Message.h:19
xAOD::TAuxVector::storeDataSpan
void storeDataSpan()
Update the stored span.
Definition: TAuxVector.cxx:261
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
xAOD::TAuxVector::toPtr
virtual void * toPtr() override
Return a pointer to the start of the vector's data.
Definition: TAuxVector.cxx:115
SG::auxid_t
size_t auxid_t
Identifier for a particular aux data item.
Definition: AuxTypes.h:27
xAOD::TAuxVector::clone
virtual std::unique_ptr< SG::IAuxTypeVector > clone() const override
Copy the managed vector.
Definition: TAuxVector.cxx:109
beamspotman.n
n
Definition: beamspotman.py:731
Message.h
SG::AuxDataSpanBase::beg
void * beg
Pointer to the start of the variable's vector.
Definition: AuxDataSpan.h:53
test_pyathena.parent
parent
Definition: test_pyathena.py:15
xAOD::TAuxVector::TAuxVector
TAuxVector(const TAuxVectorFactory *factory, SG::auxid_t auxid, const ::TClass *cl, size_t size, size_t capacity, bool isLinked)
Constructor.
Definition: TAuxVector.cxx:20
xAOD::TAuxVector::operator=
TAuxVector & operator=(const TAuxVector &other)
Assignment operator.
Definition: TAuxVector.cxx:71
xAOD::TAuxVector
Auxiliary vector type for types known to ROOT.
Definition: TAuxVector.h:30
AuxVectorData.h
Manage lookup of vectors of auxiliary data.
xAOD::TAuxVectorFactory
Auxiliary vector factory based on a ROOT dictionary.
Definition: TAuxVectorFactory.h:30
TAuxVector.h
xAOD::TAuxVector::getDataSpanImpl
virtual SG::AuxDataSpanBase getDataSpanImpl() const override final
Return a span object describing the current vector.
Definition: TAuxVector.cxx:256
xAOD::TAuxVector::size
virtual size_t size() const override
Return the size of the vector.
Definition: TAuxVector.cxx:130
xAOD::TAuxVector::insertMove
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.
Definition: TAuxVector.cxx:206
xAOD::TAuxVector::resize
virtual bool resize(size_t sz) override
Change the size of the vector.
Definition: TAuxVector.cxx:135
SG::AuxDataSpanBase
Minimal span-like object describing the range of an auxiliary variable.
Definition: AuxDataSpan.h:39
WriteBchToCool.beg
beg
Definition: WriteBchToCool.py:69
SG::IAuxTypeVector::auxid
auxid_t auxid() const
Return the auxid of the variable this vector represents.
Definition: IAuxTypeVector.h:232
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
SG::IAuxStore
Interface for non-const operations on an auxiliary store.
Definition: IAuxStore.h:48
SG::AuxVectorInterface
Make an AuxVectorData object from either a raw array or an aux store.
Definition: AuxVectorInterface.h:33
IAuxTypeVectorFactory.h
Interface for factory objects that create vectors.
xAOD::TAuxVector::shift
virtual bool shift(size_t pos, ptrdiff_t offs) override
Shift the elements of the vector.
Definition: TAuxVector.cxx:174
xAOD::TAuxVector::clearRange
void clearRange(void *dst, size_t n)
Definition: TAuxVector.cxx:239
xAOD::TAuxVector::m_vec
void * m_vec
Pointer to the vector object.
Definition: TAuxVector.h:96
xAOD::TAuxVector::copyRange
void copyRange(const void *src, void *dst, size_t n)
Function copying the payload of a range to a new location.
Definition: TAuxVector.cxx:228
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
xAOD::TAuxVector::m_factory
const TAuxVectorFactory * m_factory
The parent factory object.
Definition: TAuxVector.h:89
TAuxVectorFactory.h
xAOD::TAuxVector::~TAuxVector
~TAuxVector()
Destructor.
Definition: TAuxVector.cxx:66