The Gaudi Framework  master (594c33fa)
Gaudi::details::BranchWrapper Struct Reference

Encapsulates a branch within a ROOT TTree, managing the data and interaction with the TTree. More...

#include </builds/gaudi/Gaudi/GaudiUtils/include/Gaudi/details/BranchWrapper.h>

Collaboration diagram for Gaudi::details::BranchWrapper:

Public Member Functions

 BranchWrapper (const gsl::not_null< TTree * > tree, const std::string &className, const std::string &branchName, const std::string &location, const Gaudi::Algorithm &algRef)
 
void setDataPtr (void const *dataPtr)
 
void setBranchData (const gsl::not_null< DataObject * > pObj)
 
std::string getLocation () const
 
std::string getClassName () const
 

Private Attributes

void const * m_dataBuffer = nullptr
 
AnyDataWrapperBasebaseWrapper = nullptr
 
TBranch * m_branch = nullptr
 
std::string m_className
 
std::string m_branchName
 
std::string m_location
 
const Gaudi::Algorithmm_algRef
 
void(* setBranchAddress )(gsl::not_null< TBranch * >, const void **)
 

Detailed Description

Encapsulates a branch within a ROOT TTree, managing the data and interaction with the TTree.

Definition at line 25 of file BranchWrapper.h.

Constructor & Destructor Documentation

◆ BranchWrapper()

Gaudi::details::BranchWrapper::BranchWrapper ( const gsl::not_null< TTree * >  tree,
const std::string className,
const std::string branchName,
const std::string location,
const Gaudi::Algorithm algRef 
)

Definition at line 35 of file BranchWrapper.cpp.

38  : m_className( className ), m_branchName( branchName ), m_location( location ), m_algRef( algRef ) {
39  auto leafListTag = getLeafListForType( m_className );
40  if ( !leafListTag.empty() ) {
41  // Create a branch for fundamental types using the leaflist
42  m_branch = tree->Branch( m_branchName.c_str(), &m_dataBuffer,
43  ( fmt::format( "{}/{}", m_className, leafListTag ) ).c_str() );
44  setBranchAddress = []( gsl::not_null<TBranch*> br, const void** wrappedDataPtr ) {
45  br->SetAddress( const_cast<void*>( *wrappedDataPtr ) );
46  };
47 
48  } else if ( TClass::GetClass( m_className.c_str() ) ) {
49  // Create a branch for object types using the classname string
50  m_branch = tree->Branch( m_branchName.c_str(), m_className.c_str(), &m_dataBuffer );
51  setBranchAddress = []( gsl::not_null<TBranch*> br, const void** wrappedDataPtr ) {
52  br->SetAddress( wrappedDataPtr );
53  };
54 
55  } else {
56  throw GaudiException( fmt::format( "Cannot create branch {} for unknown class: {}. Provide a dictionary please.",
59  }
60 
61  if ( !m_branch ) {
62  throw GaudiException( fmt::format( "Failed to create branch {} for type {}.", m_branchName, m_className ),
64  }
65  }

Member Function Documentation

◆ getClassName()

std::string Gaudi::details::BranchWrapper::getClassName ( ) const

Definition at line 89 of file BranchWrapper.cpp.

89 { return m_className; }

◆ getLocation()

std::string Gaudi::details::BranchWrapper::getLocation ( ) const

Definition at line 87 of file BranchWrapper.cpp.

87 { return m_location; }

◆ setBranchData()

void Gaudi::details::BranchWrapper::setBranchData ( const gsl::not_null< DataObject * >  pObj)

Definition at line 76 of file BranchWrapper.cpp.

76  {
77  baseWrapper = dynamic_cast<AnyDataWrapperBase*>( pObj.get() );
78  if ( !baseWrapper ) {
79  throw GaudiException( "Failed to cast DataObject to AnyDataWrapperBase type.", m_algRef.name(),
81  }
82 
85  }

◆ setDataPtr()

void Gaudi::details::BranchWrapper::setDataPtr ( void const *  dataPtr)

Definition at line 69 of file BranchWrapper.cpp.

69  {
70  m_dataBuffer = dataPtr;
72  }

Member Data Documentation

◆ baseWrapper

AnyDataWrapperBase* Gaudi::details::BranchWrapper::baseWrapper = nullptr
private

Definition at line 29 of file BranchWrapper.h.

◆ m_algRef

const Gaudi::Algorithm& Gaudi::details::BranchWrapper::m_algRef
private

Definition at line 34 of file BranchWrapper.h.

◆ m_branch

TBranch* Gaudi::details::BranchWrapper::m_branch = nullptr
private

Definition at line 30 of file BranchWrapper.h.

◆ m_branchName

std::string Gaudi::details::BranchWrapper::m_branchName
private

Definition at line 32 of file BranchWrapper.h.

◆ m_className

std::string Gaudi::details::BranchWrapper::m_className
private

Definition at line 31 of file BranchWrapper.h.

◆ m_dataBuffer

void const* Gaudi::details::BranchWrapper::m_dataBuffer = nullptr
private

Definition at line 28 of file BranchWrapper.h.

◆ m_location

std::string Gaudi::details::BranchWrapper::m_location
private

Definition at line 33 of file BranchWrapper.h.

◆ setBranchAddress

void( * Gaudi::details::BranchWrapper::setBranchAddress) (gsl::not_null< TBranch * >, const void **)
private

Definition at line 35 of file BranchWrapper.h.


The documentation for this struct was generated from the following files:
Gaudi::details::BranchWrapper::m_location
std::string m_location
Definition: BranchWrapper.h:33
GaudiAlg.HistoUtils.location
location
Definition: HistoUtils.py:964
Gaudi::Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:528
GaudiException
Definition: GaudiException.h:31
Gaudi::details::BranchWrapper::baseWrapper
AnyDataWrapperBase * baseWrapper
Definition: BranchWrapper.h:29
Gaudi::details::BranchWrapper::m_branch
TBranch * m_branch
Definition: BranchWrapper.h:30
AnyDataWrapperBase
Definition: AnyDataWrapper.h:30
Gaudi::details::BranchWrapper::m_branchName
std::string m_branchName
Definition: BranchWrapper.h:32
Gaudi::details::BranchWrapper::m_className
std::string m_className
Definition: BranchWrapper.h:31
Gaudi::details::BranchWrapper::m_dataBuffer
void const * m_dataBuffer
Definition: BranchWrapper.h:28
std::string::c_str
T c_str(T... args)
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
AnyDataWrapperBase::payload
virtual Ptr payload() const =0
Gaudi::details::BranchWrapper::m_algRef
const Gaudi::Algorithm & m_algRef
Definition: BranchWrapper.h:34
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
Gaudi::details::BranchWrapper::setBranchAddress
void(* setBranchAddress)(gsl::not_null< TBranch * >, const void **)
Definition: BranchWrapper.h:35