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  // Check the size of the other object:
91  const size_t size = other.size();
92  // Check if we need to do anything:
93  if( ! size ) {
94  return *this;
95  }
96 
97  // Get a pointer to the start of the other object's payload:
98  const void* otherPtr = other.toPtr();
99 
100  // Do the copy:
101  this->copyRange( otherPtr, this->toPtr(), size );
102 
103  // Return a reference to this object:
104  return *this;
105  }
106 
107  std::unique_ptr< SG::IAuxTypeVector > TAuxVector::clone() const {
108 
109  return std::make_unique< TAuxVector >( *this );
110  }
111 
112 
114 
115  return m_proxy->At( 0 );
116  }
117 
118  const void* TAuxVector::toPtr() const {
119 
120  return m_proxy->At( 0 );
121  }
122 
124 
125  return m_vec;
126  }
127 
128  size_t TAuxVector::size() const {
129 
130  return m_proxy->Size();
131  }
132 
133  bool TAuxVector::resize( size_t sz ) {
134 
135  const void* orig = toPtr();
136  m_proxy->Allocate( sz, false );
137  return toPtr() == orig;
138  }
139 
140  void TAuxVector::reserve( size_t ) {
141 
142  return;
143  }
144 
171  bool TAuxVector::shift( size_t pos, ptrdiff_t offs ) {
172 
173  size_t eltsz = m_proxy->GetIncrement();
174  if( offs < 0 ) {
175 
176  if( -offs > static_cast< ptrdiff_t >( pos ) ) {
177  offs = -pos;
178  }
179  char* beg = reinterpret_cast< char* >( m_proxy->At( 0 ) );
180  copyRange( beg + eltsz * pos,
181  beg + eltsz * ( pos + offs ),
182  m_proxy->Size() - pos );
183  m_proxy->Allocate( m_proxy->Size() + offs, false );
184  return true;
185 
186  } else if( offs > 0 ) {
187 
188  size_t oldsz = m_proxy->Size();
189  m_proxy->Allocate( oldsz + offs, false );
190  char* beg = reinterpret_cast< char* >( m_proxy->At( 0 ) );
191  copyRange( beg + eltsz * pos,
192  beg + eltsz * ( pos + offs ),
193  m_proxy->Size() - pos - offs);
194  clearRange( beg + eltsz * pos, offs );
195  return false;
196  }
197 
198  return true;
199  }
200 
201  bool TAuxVector::insertMove (size_t pos, void* beg, void* end,
202  SG::IAuxStore& /*srcStore*/)
203  {
204  size_t eltsz = m_proxy->GetIncrement();
205  const void* orig = this->toPtr();
206 
207  char* begp = reinterpret_cast<char*> (beg);
208  char* endp = reinterpret_cast<char*> (end);
209  size_t nelt = (endp-begp) / eltsz;
210 
211  shift (pos, nelt);
212  // FIXME: want move, not copy.
213  // But i don't seem to be able to call move operations through cling,
214  // so just use copy for now.
215  copyRange (beg,
216  reinterpret_cast<char*>(this->toPtr()) + pos*eltsz,
217  nelt);
218  return this->toPtr() == orig;
219  }
220 
221 
222  void TAuxVector::copyRange( const void* src, void* dst, size_t n ) {
223 
224  SG::AuxVectorInterface idst( auxid(), n, dst );
225  m_factory->copy( auxid(),
226  idst, 0,
227  SG::AuxVectorInterface( auxid(), n, src ), 0,
228  n );
229 
230  return;
231  }
232 
233  void TAuxVector::clearRange( void* dst, size_t n ) {
234 
235  // Size of an element in the vector:
236  size_t eltsz = m_proxy->GetIncrement();
237 
238  // If the payload is a class:
239  if( m_proxy->GetValueClass() ) {
240  m_factory->clear (dst, 0, n);
241  }
242  // If the payload is an array of primitives, the cleaning is much simpler:
243  else {
244  memset( dst, 0, n * eltsz );
245  }
246 
247  return;
248  }
249 
250 } // 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:140
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:123
xAOD::TAuxVector::insertMove
virtual bool insertMove(size_t pos, void *beg, void *end, SG::IAuxStore &srcStore) override
Insert a range of elements via move.
Definition: TAuxVector.cxx:201
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:85
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
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
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:113
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:107
beamspotman.n
n
Definition: beamspotman.py:731
Message.h
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::size
virtual size_t size() const override
Return the size of the vector.
Definition: TAuxVector.cxx:128
xAOD::TAuxVector::resize
virtual bool resize(size_t sz) override
Change the size of the vector.
Definition: TAuxVector.cxx:133
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:227
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:171
xAOD::TAuxVector::clearRange
void clearRange(void *dst, size_t n)
Definition: TAuxVector.cxx:233
xAOD::TAuxVector::m_vec
void * m_vec
Pointer to the vector object.
Definition: TAuxVector.h:87
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:222
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:80
TAuxVectorFactory.h
xAOD::TAuxVector::~TAuxVector
~TAuxVector()
Destructor.
Definition: TAuxVector.cxx:66