Project
Loading...
Searching...
No Matches
o2::dataformats::MCTruthContainer< TruthElement > Class Template Reference

A container to hold and manage MC truth information/labels. More...

#include <MCTruthContainer.h>

Classes

struct  FlatHeader
 

Public Types

using self_type = MCTruthContainer< TruthElement >
 

Public Member Functions

 MCTruthContainer ()=default
 
 ~MCTruthContainer ()=default
 
 MCTruthContainer (const MCTruthContainer &other)=default
 
 MCTruthContainer (MCTruthContainer &&other)=default
 
 MCTruthContainer (std::vector< MCTruthHeaderElement > &header, std::vector< TruthElement > &truthArray)
 
MCTruthContaineroperator= (const MCTruthContainer &other)=default
 
MCTruthContaineroperator= (MCTruthContainer &&other)=default
 
MCTruthHeaderElement const & getMCTruthHeader (uint32_t dataindex) const
 
TruthElement const & getElement (uint32_t elementindex) const
 
size_t getIndexedSize () const
 
size_t getNElements () const
 
const std::vector< TruthElement > & getTruthArray () const
 
gsl::span< TruthElement > getLabels (uint32_t dataindex)
 
gsl::span< const TruthElement > getLabels (uint32_t dataindex) const
 
void clear ()
 
void clear_andfreememory ()
 
void addElement (uint32_t dataindex, TruthElement const &element, bool noElement=false)
 
void addNoLabelIndex (uint32_t dataindex)
 adds a data index that has no label
 
template<typename CompatibleLabel >
void addElements (uint32_t dataindex, gsl::span< CompatibleLabel > elements)
 
template<typename CompatibleLabel >
void addElements (uint32_t dataindex, const std::vector< CompatibleLabel > &v)
 
void addElementRandomAccess (uint32_t dataindex, TruthElement const &element)
 
void setFrom (std::vector< MCTruthHeaderElement > &header, std::vector< TruthElement > &truthArray)
 
void mergeAtBack (MCTruthContainer< TruthElement > const &other)
 
void mergeAtBack (MCTruthContainer< TruthElement > const &other, size_t from, size_t n)
 
template<typename ContainerType >
size_t flatten_to (ContainerType &container) const
 
void restore_from (const char *buffer, size_t bufferSize)
 
template<typename Stream >
void print (Stream &stream)
 Print some info.
 
void inflate ()
 
void deflate ()
 
 ClassDefNV (MCTruthContainer, 2)
 
void Streamer (TBuffer &R__b)
 

Detailed Description

template<typename TruthElement>
class o2::dataformats::MCTruthContainer< TruthElement >

A container to hold and manage MC truth information/labels.

The actual MCtruth type is a generic template type and can be supplied by the user It is meant to manage associations from one "dataobject" identified by an index into an array to multiple TruthElements. Each "dataobject" is identified by a sequential index. Truth elements belonging to one object are always in contingous sequence in the truth element storage. Since multiple truth elements can be associated with one object, the header array stores the start of the associated truth element sequence.

Since the class contains two subsequent vectors, it is not POD even if the TruthElement is POD. ROOT serialization is rather inefficient and in addition has a large memory footprint if the container has lots of (>1000000) elements. between 3 and 4x more than the actual size is allocated. If the two vectors are flattend to a raw vector before streaming, the serialization works without memory overhead. The deflate/inflate methods are called from a custom streamer, storing the vectors in the raw buffer and vice versa, each of the methods emptying the source data.

TODO:

  • add move assignment from a source vector, by that passing an object which has access to different underlying memory resources, until that, the pmr::MemoryResource has been removed again
  • add interface to access header and truth elements directly from the raw buffer, by that inflation can be postponed until new elements are added, with the effect that inflation can be avoided in most cases

Note: The two original vector members could be transient, however reading serialized version 1 objects does not work correctly. In a different approach, the two vectors have been removed completely with an efficient interface to the binary buffer, but the read pragma was not able to access the member offset from the StreamerInfo.

Definition at line 82 of file MCTruthContainer.h.

Member Typedef Documentation

◆ self_type

template<typename TruthElement >
using o2::dataformats::MCTruthContainer< TruthElement >::self_type = MCTruthContainer<TruthElement>

Definition at line 126 of file MCTruthContainer.h.

Constructor & Destructor Documentation

◆ MCTruthContainer() [1/4]

template<typename TruthElement >
o2::dataformats::MCTruthContainer< TruthElement >::MCTruthContainer ( )
default

◆ ~MCTruthContainer()

template<typename TruthElement >
o2::dataformats::MCTruthContainer< TruthElement >::~MCTruthContainer ( )
default

◆ MCTruthContainer() [2/4]

template<typename TruthElement >
o2::dataformats::MCTruthContainer< TruthElement >::MCTruthContainer ( const MCTruthContainer< TruthElement > &  other)
default

◆ MCTruthContainer() [3/4]

template<typename TruthElement >
o2::dataformats::MCTruthContainer< TruthElement >::MCTruthContainer ( MCTruthContainer< TruthElement > &&  other)
default

◆ MCTruthContainer() [4/4]

template<typename TruthElement >
o2::dataformats::MCTruthContainer< TruthElement >::MCTruthContainer ( std::vector< MCTruthHeaderElement > &  header,
std::vector< TruthElement > &  truthArray 
)
inline

Definition at line 117 of file MCTruthContainer.h.

Member Function Documentation

◆ addElement()

template<typename TruthElement >
void o2::dataformats::MCTruthContainer< TruthElement >::addElement ( uint32_t  dataindex,
TruthElement const &  element,
bool  noElement = false 
)
inline

Definition at line 190 of file MCTruthContainer.h.

◆ addElementRandomAccess()

template<typename TruthElement >
void o2::dataformats::MCTruthContainer< TruthElement >::addElementRandomAccess ( uint32_t  dataindex,
TruthElement const &  element 
)
inline

Definition at line 248 of file MCTruthContainer.h.

◆ addElements() [1/2]

template<typename TruthElement >
template<typename CompatibleLabel >
void o2::dataformats::MCTruthContainer< TruthElement >::addElements ( uint32_t  dataindex,
const std::vector< CompatibleLabel > &  v 
)
inline

Definition at line 237 of file MCTruthContainer.h.

◆ addElements() [2/2]

template<typename TruthElement >
template<typename CompatibleLabel >
void o2::dataformats::MCTruthContainer< TruthElement >::addElements ( uint32_t  dataindex,
gsl::span< CompatibleLabel >  elements 
)
inline

Definition at line 224 of file MCTruthContainer.h.

◆ addNoLabelIndex()

template<typename TruthElement >
void o2::dataformats::MCTruthContainer< TruthElement >::addNoLabelIndex ( uint32_t  dataindex)
inline

adds a data index that has no label

Definition at line 216 of file MCTruthContainer.h.

◆ ClassDefNV()

template<typename TruthElement >
o2::dataformats::MCTruthContainer< TruthElement >::ClassDefNV ( MCTruthContainer< TruthElement >  ,
 
)

◆ clear()

template<typename TruthElement >
void o2::dataformats::MCTruthContainer< TruthElement >::clear ( )
inline

Definition at line 171 of file MCTruthContainer.h.

◆ clear_andfreememory()

template<typename TruthElement >
void o2::dataformats::MCTruthContainer< TruthElement >::clear_andfreememory ( )
inline

Definition at line 178 of file MCTruthContainer.h.

◆ deflate()

template<typename TruthElement >
void o2::dataformats::MCTruthContainer< TruthElement >::deflate ( )
inline

Deflate the object to the internal buffer The class has a specific member to store flattened data. Due to some limitations in ROOT it is more efficient to first flatten the objects to a raw buffer and empty the two vectors before serialization. This function stores the vectors to the internal raw buffer. Called from the custom streamer.

Definition at line 423 of file MCTruthContainer.h.

◆ flatten_to()

template<typename TruthElement >
template<typename ContainerType >
size_t o2::dataformats::MCTruthContainer< TruthElement >::flatten_to ( ContainerType &  container) const
inline

Flatten the internal arrays to the provided container Copies the content of the two vectors of PODs to a contiguous container. The flattened data starts with a specific header FlatHeader describing size and content of the two vectors within the raw buffer.

Definition at line 342 of file MCTruthContainer.h.

◆ getElement()

template<typename TruthElement >
TruthElement const & o2::dataformats::MCTruthContainer< TruthElement >::getElement ( uint32_t  elementindex) const
inline

Definition at line 140 of file MCTruthContainer.h.

◆ getIndexedSize()

template<typename TruthElement >
size_t o2::dataformats::MCTruthContainer< TruthElement >::getIndexedSize ( ) const
inline

Definition at line 142 of file MCTruthContainer.h.

◆ getLabels() [1/2]

template<typename TruthElement >
gsl::span< TruthElement > o2::dataformats::MCTruthContainer< TruthElement >::getLabels ( uint32_t  dataindex)
inline

Definition at line 153 of file MCTruthContainer.h.

◆ getLabels() [2/2]

template<typename TruthElement >
gsl::span< const TruthElement > o2::dataformats::MCTruthContainer< TruthElement >::getLabels ( uint32_t  dataindex) const
inline

Definition at line 163 of file MCTruthContainer.h.

◆ getMCTruthHeader()

template<typename TruthElement >
MCTruthHeaderElement const & o2::dataformats::MCTruthContainer< TruthElement >::getMCTruthHeader ( uint32_t  dataindex) const
inline

Definition at line 137 of file MCTruthContainer.h.

◆ getNElements()

template<typename TruthElement >
size_t o2::dataformats::MCTruthContainer< TruthElement >::getNElements ( ) const
inline

Definition at line 144 of file MCTruthContainer.h.

◆ getTruthArray()

template<typename TruthElement >
const std::vector< TruthElement > & o2::dataformats::MCTruthContainer< TruthElement >::getTruthArray ( ) const
inline

Definition at line 146 of file MCTruthContainer.h.

◆ inflate()

template<typename TruthElement >
void o2::dataformats::MCTruthContainer< TruthElement >::inflate ( )
inline

Inflate the object from the internal buffer The class has a specific member to store flattened data. Due to some limitations in ROOT it is more efficient to first flatten the objects to a raw buffer and empty the two vectors before serialization. This function restores the vectors from the internal raw buffer. Called from the custom streamer.

Definition at line 408 of file MCTruthContainer.h.

◆ mergeAtBack() [1/2]

template<typename TruthElement >
void o2::dataformats::MCTruthContainer< TruthElement >::mergeAtBack ( MCTruthContainer< TruthElement > const &  other)
inline

Definition at line 300 of file MCTruthContainer.h.

◆ mergeAtBack() [2/2]

template<typename TruthElement >
void o2::dataformats::MCTruthContainer< TruthElement >::mergeAtBack ( MCTruthContainer< TruthElement > const &  other,
size_t  from,
size_t  n 
)
inline

Definition at line 316 of file MCTruthContainer.h.

◆ operator=() [1/2]

template<typename TruthElement >
MCTruthContainer & o2::dataformats::MCTruthContainer< TruthElement >::operator= ( const MCTruthContainer< TruthElement > &  other)
default

◆ operator=() [2/2]

template<typename TruthElement >
MCTruthContainer & o2::dataformats::MCTruthContainer< TruthElement >::operator= ( MCTruthContainer< TruthElement > &&  other)
default

◆ print()

template<typename TruthElement >
template<typename Stream >
void o2::dataformats::MCTruthContainer< TruthElement >::print ( Stream stream)
inline

Print some info.

Definition at line 398 of file MCTruthContainer.h.

◆ restore_from()

template<typename TruthElement >
void o2::dataformats::MCTruthContainer< TruthElement >::restore_from ( const char buffer,
size_t  bufferSize 
)
inline

Resore internal vectors from a raw buffer The two vectors are resized according to the information in the FlatHeader struct at the beginning of the buffer. Data is copied to the vectors.

Definition at line 366 of file MCTruthContainer.h.

◆ setFrom()

template<typename TruthElement >
void o2::dataformats::MCTruthContainer< TruthElement >::setFrom ( std::vector< MCTruthHeaderElement > &  header,
std::vector< TruthElement > &  truthArray 
)
inline

Definition at line 293 of file MCTruthContainer.h.

◆ Streamer()

void o2::dataformats::MCTruthContainer< MCCompLabel >::Streamer ( TBuffer &  R__b)

Definition at line 27 of file CustomStreamers.cxx.


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