The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
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 std::string &algName)
 
void setDataPtr (void const *dataPtr)
 
void setBranchData (const gsl::not_null< DataObject * > pObj)
 
const std::string & getLocation () const
 
const std::string & getClassName () const
 

Private Attributes

void const * m_dataBuffer = nullptr
 
TBranch * m_branch = nullptr
 
std::string m_className
 
std::string m_branchName
 
std::string m_location
 
std::string m_algName
 
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 std::string & algName )

Definition at line 35 of file BranchWrapper.cpp.

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

Member Function Documentation

◆ getClassName()

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

Definition at line 83 of file BranchWrapper.cpp.

83{ return m_className; }

◆ getLocation()

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

Definition at line 81 of file BranchWrapper.cpp.

81{ return m_location; }

◆ setBranchData()

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

Definition at line 75 of file BranchWrapper.cpp.

75 {
76 auto baseWrapper = dynamic_cast<AnyDataWrapperBase*>( pObj.get() );
77 m_dataBuffer = baseWrapper ? baseWrapper->payload() : pObj.get();
79 }

◆ setDataPtr()

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

Definition at line 68 of file BranchWrapper.cpp.

68 {
69 m_dataBuffer = dataPtr;
71 }

Member Data Documentation

◆ m_algName

std::string Gaudi::details::BranchWrapper::m_algName
private

Definition at line 33 of file BranchWrapper.h.

◆ m_branch

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

Definition at line 29 of file BranchWrapper.h.

◆ m_branchName

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

Definition at line 31 of file BranchWrapper.h.

◆ m_className

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

Definition at line 30 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 32 of file BranchWrapper.h.

◆ setBranchAddress

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

Definition at line 34 of file BranchWrapper.h.


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