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

Dynamic implementation of IAuxTypeVector, relying on root vector proxy. More...

#include <RootAuxVectorFactory.h>

Inheritance diagram for SG::RootAuxVector:
Collaboration diagram for SG::RootAuxVector:

Public Member Functions

 RootAuxVector (const RootAuxVectorFactory *factory, SG::auxid_t auxid, size_t size, size_t capacity, bool isLinked)
 Constructor. More...
 
 RootAuxVector (const RootAuxVectorFactory *factory, SG::auxid_t auxid, void *data, bool isPacked, bool ownFlag, bool isLinked)
 Constructor, from a pointer to a vector object. More...
 
 RootAuxVector (const RootAuxVector &other)
 Copy constructor. More...
 
RootAuxVectoroperator= (const RootAuxVector &)=delete
 
virtual ~RootAuxVector () override
 Destructor. More...
 
virtual std::unique_ptr< SG::IAuxTypeVectorclone () const override
 Make a copy of this vector. More...
 
virtual void * toPtr () override
 Return a pointer to the start of the vector's data. More...
 
virtual const void * toPtr () const override
 Return a pointer to the start of the vector's data. More...
 
virtual void * toVector () override
 Return a pointer to the overall object. More...
 
virtual size_t size () const override
 Return the size of the vector. More...
 
virtual bool resize (size_t sz) override
 Change the size of the vector. More...
 
virtual void reserve (size_t sz) override
 Change the capacity of the vector. More...
 
virtual bool shift (size_t pos, ptrdiff_t offs) override
 Shift the elements of the vector. More...
 
virtual bool insertMove (size_t pos, void *beg, void *end, SG::IAuxStore &srcStore) override
 Insert elements into the vector via move semantics. More...
 
virtual const std::type_info * objType () const override
 Return the type of the complete object to be saved. More...
 
virtual bool setOption (const AuxDataOption &)
 Set an option for this variable. More...
 
virtual std::unique_ptr< IAuxTypeVectortoPacked ()
 Make a packed version of the variable. More...
 
virtual std::unique_ptr< IAuxTypeVectorlinkedVector ()
 Return IAuxTypeVector of a linked variable, if there is one. More...
 
bool isLinked () const
 Return true if this variable is linked from another one. More...
 
auxid_t auxid () const
 Return the auxid of the variable this vector represents. More...
 

Private Attributes

const RootAuxVectorFactorym_factory
 Pointer back to the factory class for this type. More...
 
std::unique_ptr< TVirtualCollectionProxy > m_proxy
 The collection proxy for the vector. More...
 
void * m_obj
 Pointer to the overall object itself. More...
 
void * m_vec
 Pointer to the vector object itself. More...
 
bool m_ownFlag
 Should be delete the vector object? More...
 
auxid_t m_auxid
 The auxid of the variable this vector represents. More...
 
bool m_isLinked
 True if this variable is linked from another one. More...
 

Detailed Description

Dynamic implementation of IAuxTypeVector, relying on root vector proxy.

This is used for the case when we need to manipulate an aux data vector present in an input data file but we have neither a proper template instantiation for the factory (because the variable was never explicitly referenced), nor can we find a dictionary entry for the factory.j

This implementation works by relying entirely on the root dictionary information.

Definition at line 46 of file RootAuxVectorFactory.h.

Constructor & Destructor Documentation

◆ RootAuxVector() [1/3]

SG::RootAuxVector::RootAuxVector ( const RootAuxVectorFactory factory,
SG::auxid_t  auxid,
size_t  size,
size_t  capacity,
bool  isLinked 
)

Constructor.

Makes a new vector.

Parameters
factoryThe factory object for this type.
auxidThe auxid of the variable this vector represents.
sizeInitial size of the new vector.
capacityInitial capacity of the new vector.
isLinkedTrue if this variable is linked from another one.

Definition at line 63 of file RootAuxVectorFactory.cxx.

68  m_factory (factory),
69  m_ownFlag (true)
70 {
71  const TClass* vecClass = factory->vecClass();
72  m_proxy.reset (vecClass->GetCollectionProxy()->Generate());
73  m_obj = factory->objClass()->New ();
74  m_vec = reinterpret_cast<char*> (m_obj) + factory->offset();
75  m_proxy->PushProxy (m_vec);
76  this->resize (size);
77 }

◆ RootAuxVector() [2/3]

SG::RootAuxVector::RootAuxVector ( const RootAuxVectorFactory factory,
SG::auxid_t  auxid,
void *  data,
bool  isPacked,
bool  ownFlag,
bool  isLinked 
)

Constructor, from a pointer to a vector object.

Parameters
factoryThe factory object for this type.
auxidThe auxid of the variable this vector represents.
dataThe vector object.
isPackedIf true, data is a PackedContainer.
ownFlagIf true, then take ownership of data.
isLinkedTrue if this variable is linked from another one.

If the element type is T, then data should be a pointer to a std::vector<T> object, which was obtained with new.

This version does not support packed containers, so isPacked must be false.

Definition at line 95 of file RootAuxVectorFactory.cxx.

102  m_factory (factory),
103  m_ownFlag (ownFlag)
104 {
105  if (isPacked) std::abort();
106  const TClass* vecClass = factory->vecClass();
107  m_proxy.reset (vecClass->GetCollectionProxy()->Generate());
108  m_obj = data;
109  m_vec = reinterpret_cast<char*> (m_obj) + factory->offset();
110  m_proxy->PushProxy (m_vec);
111 }

◆ RootAuxVector() [3/3]

SG::RootAuxVector::RootAuxVector ( const RootAuxVector other)

Copy constructor.

Parameters
otherThe vector to copy.

Definition at line 118 of file RootAuxVectorFactory.cxx.

119  : IAuxTypeVector (other),
120  m_factory (other.m_factory),
121  m_proxy (other.m_proxy->Generate()),
122  m_ownFlag (true)
123 {
124  m_obj = m_factory->objClass()->New ();
125  m_vec = reinterpret_cast<char*> (m_obj) + m_factory->offset();
126  m_proxy->PushProxy (m_vec);
127  size_t sz = other.size();
128  this->resize (sz);
129 
130  if (sz > 0) {
132  const void* otherPtr = other.toPtr();
133  rootType.copyRange (this->toPtr(), otherPtr, sz);
134  }
135 }

◆ ~RootAuxVector()

SG::RootAuxVector::~RootAuxVector ( )
overridevirtual

Destructor.

This will free the vector data.

Definition at line 143 of file RootAuxVectorFactory.cxx.

144 {
145  if (m_ownFlag)
146  m_factory->objClass()->Destructor (m_obj);
147 }

Member Function Documentation

◆ auxid()

auxid_t SG::IAuxTypeVector::auxid ( ) const
inlineinherited

Return the auxid of the variable this vector represents.

Definition at line 227 of file IAuxTypeVector.h.

228  {
229  return m_auxid;
230  }

◆ clone()

std::unique_ptr< SG::IAuxTypeVector > SG::RootAuxVector::clone ( ) const
overridevirtual

Make a copy of this vector.

Implements SG::IAuxTypeVector.

Definition at line 153 of file RootAuxVectorFactory.cxx.

154 {
155  return std::make_unique<RootAuxVector> (*this);
156 }

◆ insertMove()

bool SG::RootAuxVector::insertMove ( size_t  pos,
void *  beg,
void *  end,
SG::IAuxStore srcStore 
)
overridevirtual

Insert elements into the vector via move semantics.

Parameters
posThe starting index of the insertion.
begStart of the range of elements to insert.
endEnd of the range of elements to insert.
srcStoreThe source store.

beg and end define a range of container elements, with length len defined by the difference of the pointers divided by the element size.

The size of the container will be increased by len, with the elements starting at pos copied to pos+len.

The contents of the beg:end range will then be moved to our vector starting at pos. This will be done via move semantics if possible; otherwise, it will be done with a copy.

Returns true if it is known that the vector's memory did not move, false otherwise.

Implements SG::IAuxTypeVector.

Definition at line 300 of file RootAuxVectorFactory.cxx.

302 {
303  size_t eltsz = m_proxy->GetIncrement();
304  const void* orig = this->toPtr();
306 
307  char* begp = reinterpret_cast<char*> (beg);
308  char* endp = reinterpret_cast<char*> (end);
309  size_t nelt = (endp-begp) / eltsz;
310 
311  shift (pos, nelt);
312  // FIXME: want move, not copy.
313  // But i don't seem to be able to call move operations through cling,
314  // so just use copy for now.
315  rootType.copyRange (reinterpret_cast<char*>(this->toPtr()) + pos*eltsz,
316  beg, nelt);
317  return this->toPtr() == orig;
318 }

◆ isLinked()

bool SG::IAuxTypeVector::isLinked ( ) const
inlineinherited

Return true if this variable is linked from another one.

This is inlined here rather than being a virtual function because this is frequently called from loops over auxids.

Definition at line 221 of file IAuxTypeVector.h.

221 { return m_isLinked; }

◆ linkedVector()

virtual std::unique_ptr<IAuxTypeVector> SG::IAuxTypeVector::linkedVector ( )
inlinevirtualinherited

Return IAuxTypeVector of a linked variable, if there is one.

If the variable represented by this vector has a linked variable, then return its IAuxTypeVector. Otherwise, return nullptr. Beware of potential threading issues: the returned object is not locked, so it should not be modified in contexts where the parent container cannot be modified.

This returns a unique_ptr, so it can generally be called only once on a given instance. After that, it will return nullptr.

Definition at line 212 of file IAuxTypeVector.h.

212 { return nullptr; }

◆ objType()

const std::type_info * SG::RootAuxVector::objType ( ) const
overridevirtual

Return the type of the complete object to be saved.

For example, if the object is a std::vector, then we return the type_info of the vector. But if we're holding a PackedContainer, then we return the type_info of the PackedContainer.

Can return null if the operation is not supported. In that case, I/O will use the type found from the variable registry.

Reimplemented from SG::IAuxTypeVector.

Definition at line 332 of file RootAuxVectorFactory.cxx.

333 {
334  return m_factory->objClass()->GetTypeInfo();
335 }

◆ operator=()

RootAuxVector& SG::RootAuxVector::operator= ( const RootAuxVector )
delete

◆ reserve()

void SG::RootAuxVector::reserve ( size_t  sz)
overridevirtual

Change the capacity of the vector.

Parameters
szThe new vector capacity.

Implements SG::IAuxTypeVector.

Definition at line 218 of file RootAuxVectorFactory.cxx.

219 {
220 }

◆ resize()

bool SG::RootAuxVector::resize ( size_t  sz)
overridevirtual

Change the size of the vector.

Parameters
szThe new vector size. Returns true if it is known that iterators have not been invalidated; false otherwise.

Implements SG::IAuxTypeVector.

Definition at line 206 of file RootAuxVectorFactory.cxx.

207 {
208  const void* orig = this->toPtr();
209  m_proxy->Allocate(sz, false);
210  return this->toPtr() == orig;
211 }

◆ setOption()

virtual bool SG::IAuxTypeVector::setOption ( const AuxDataOption )
inlinevirtualinherited

Set an option for this variable.

Parameters
optionThe option to set.

The interpretation of the option depends on the particular representation of the variable provided by the concrete class.

Returns true if the option setting was successful; false otherwise.

Reimplemented in SG::AuxTypeVectorHolder< T, CONT >, and SG::AuxTypeVectorHolder< T, std::vector< T > >.

Definition at line 167 of file IAuxTypeVector.h.

168  { return false; }

◆ shift()

bool SG::RootAuxVector::shift ( size_t  pos,
ptrdiff_t  offs 
)
overridevirtual

Shift the elements of the vector.

Parameters
posThe starting index for the shift.
offsThe (signed) amount of the shift.

This operation shifts the elements in the vectors for all aux data items, to implement an insertion or deletion. offs may be either positive or negative.

If offs is positive, then the container is growing. The container size should be increased by offs, the element at pos moved to pos + offs, and similarly for following elements. The elements between pos and pos + offs should be default-initialized.

If offs is negative, then the container is shrinking. The element at pos should be moved to pos + offs, and similarly for following elements. The container should then be shrunk by -offs elements (running destructors as appropriate).

Returns true if it is known that iterators have not been invalidated; false otherwise. (Will always return false when increasing the size of an empty container.)

Implements SG::IAuxTypeVector.

Definition at line 249 of file RootAuxVectorFactory.cxx.

250 {
251  size_t eltsz = m_proxy->GetIncrement();
252 
254 
255  if (offs < 0) {
256  if (-offs > static_cast<ptrdiff_t>(pos)) offs = -pos;
257  char* beg = reinterpret_cast<char*>(m_proxy->At(0));
258  rootType.copyRange (beg + eltsz*(pos+offs),
259  beg + eltsz*pos,
260  m_proxy->Size() - pos);
261  m_proxy->Allocate (m_proxy->Size() + offs, false);
262  return true;
263  }
264  else if (offs > 0) {
265  size_t oldsz = m_proxy->Size();
266  m_proxy->Allocate (oldsz + offs, false);
267  char* beg = reinterpret_cast<char*>(m_proxy->At(0));
268  if (pos < oldsz)
269  rootType.copyRange (beg + eltsz*(pos+offs),
270  beg + eltsz*pos,
271  oldsz - pos);
272  rootType.clearRange (beg + eltsz*pos, offs);
273  return false;
274  }
275  return true;
276 }

◆ size()

size_t SG::RootAuxVector::size ( ) const
overridevirtual

Return the size of the vector.

Implements SG::IAuxTypeVector.

Definition at line 194 of file RootAuxVectorFactory.cxx.

195 {
196  return m_proxy->Size();
197 }

◆ toPacked()

virtual std::unique_ptr<IAuxTypeVector> SG::IAuxTypeVector::toPacked ( )
inlinevirtualinherited

Make a packed version of the variable.

If possible, return a new vector object that stores the data in a PackedContainer. The data itself should be moved to the new container (so that this vector becomes empty). This ensures that pointers to the data are preserved.

If successful, a newly-allocated object is returned. A null pointer is returned on failure (operation not supported, type can't be packed, type is already packed).

Reimplemented in SG::AuxTypeVectorHolder< T, CONT >, and SG::AuxTypeVectorHolder< T, std::vector< T > >.

Definition at line 183 of file IAuxTypeVector.h.

183 { return 0; }

◆ toPtr() [1/2]

const void * SG::RootAuxVector::toPtr ( ) const
overridevirtual

Return a pointer to the start of the vector's data.

Implements SG::IAuxTypeVector.

Definition at line 173 of file RootAuxVectorFactory.cxx.

174 {
175  if (m_proxy->Size() == 0)
176  return 0;
177  TVirtualCollectionProxy* proxy ATLAS_THREAD_SAFE = m_proxy.get();
178  return proxy->At(0);
179 }

◆ toPtr() [2/2]

void * SG::RootAuxVector::toPtr ( )
overridevirtual

Return a pointer to the start of the vector's data.

Implements SG::IAuxTypeVector.

Definition at line 162 of file RootAuxVectorFactory.cxx.

163 {
164  if (m_proxy->Size() == 0)
165  return 0;
166  return m_proxy->At(0);
167 }

◆ toVector()

void * SG::RootAuxVector::toVector ( )
overridevirtual

Return a pointer to the overall object.

Implements SG::IAuxTypeVector.

Definition at line 185 of file RootAuxVectorFactory.cxx.

186 {
187  return m_obj;
188 }

Member Data Documentation

◆ m_auxid

auxid_t SG::IAuxTypeVector::m_auxid
privateinherited

The auxid of the variable this vector represents.

Definition at line 235 of file IAuxTypeVector.h.

◆ m_factory

const RootAuxVectorFactory* SG::RootAuxVector::m_factory
private

Pointer back to the factory class for this type.

Definition at line 224 of file RootAuxVectorFactory.h.

◆ m_isLinked

bool SG::IAuxTypeVector::m_isLinked
privateinherited

True if this variable is linked from another one.

Definition at line 238 of file IAuxTypeVector.h.

◆ m_obj

void* SG::RootAuxVector::m_obj
private

Pointer to the overall object itself.

Definition at line 233 of file RootAuxVectorFactory.h.

◆ m_ownFlag

bool SG::RootAuxVector::m_ownFlag
private

Should be delete the vector object?

Definition at line 239 of file RootAuxVectorFactory.h.

◆ m_proxy

std::unique_ptr<TVirtualCollectionProxy> SG::RootAuxVector::m_proxy
private

The collection proxy for the vector.

Cloned from the proxy held by the TClass and permanently bound to m_vec. That makes things a bit more efficient, and prevents potential thread-safety problems.

Definition at line 230 of file RootAuxVectorFactory.h.

◆ m_vec

void* SG::RootAuxVector::m_vec
private

Pointer to the vector object itself.

Definition at line 236 of file RootAuxVectorFactory.h.


The documentation for this class was generated from the following files:
SG::RootAuxVector::toPtr
virtual void * toPtr() override
Return a pointer to the start of the vector's data.
Definition: RootAuxVectorFactory.cxx:162
SG::IAuxTypeVector::isLinked
bool isLinked() const
Return true if this variable is linked from another one.
Definition: IAuxTypeVector.h:221
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
SG::RootAuxVector::m_ownFlag
bool m_ownFlag
Should be delete the vector object?
Definition: RootAuxVectorFactory.h:239
fitman.sz
sz
Definition: fitman.py:527
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:392
SG::RootAuxVector::shift
virtual bool shift(size_t pos, ptrdiff_t offs) override
Shift the elements of the vector.
Definition: RootAuxVectorFactory.cxx:249
SG::RootAuxVector::m_obj
void * m_obj
Pointer to the overall object itself.
Definition: RootAuxVectorFactory.h:233
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
SG::RootAuxVector::m_factory
const RootAuxVectorFactory * m_factory
Pointer back to the factory class for this type.
Definition: RootAuxVectorFactory.h:224
SG::RootAuxVectorFactory::rootType
const RootUtils::Type & rootType() const
Return the ROOT type wrapper.
Definition: RootAuxVectorFactory.h:280
SG::RootAuxVector::size
virtual size_t size() const override
Return the size of the vector.
Definition: RootAuxVectorFactory.cxx:194
SG::RootAuxVectorFactory::offset
size_t offset() const
Return the offset of the vector within the object.
Definition: RootAuxVectorFactory.h:302
SG::IAuxTypeVector::IAuxTypeVector
IAuxTypeVector(auxid_t auxid, bool isLinked)
Constructor.
Definition: IAuxTypeVector.h:47
SG::RootAuxVector::m_vec
void * m_vec
Pointer to the vector object itself.
Definition: RootAuxVectorFactory.h:236
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
SG::IAuxTypeVector::m_auxid
auxid_t m_auxid
The auxid of the variable this vector represents.
Definition: IAuxTypeVector.h:235
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
SG::IAuxTypeVector::m_isLinked
bool m_isLinked
True if this variable is linked from another one.
Definition: IAuxTypeVector.h:238
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
RootUtils::Type
Wrapper for ROOT types.
Definition: Type.h:40
SG::RootAuxVector::m_proxy
std::unique_ptr< TVirtualCollectionProxy > m_proxy
The collection proxy for the vector.
Definition: RootAuxVectorFactory.h:230
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
xAOD::Utils::rootType
char rootType(char typeidType)
This function is used internally in the code when creating primitive dynamic auxiliary branches.
Definition: Control/xAODRootAccess/Root/Utils.cxx:226
SG::RootAuxVector::resize
virtual bool resize(size_t sz) override
Change the size of the vector.
Definition: RootAuxVectorFactory.cxx:206