The Gaudi Framework  master (69a68366)
Loading...
Searching...
No Matches
Gaudi::NTuple::Wrapper< COLUMNS > Class Template Reference

Wrapper around a given NTuple. More...

#include </builds/gaudi/Gaudi/GaudiUtils/include/Gaudi/NTuple/Writer.h>

Collaboration diagram for Gaudi::NTuple::Wrapper< COLUMNS >:

Public Member Functions

void initTree (TFile &file, std::string const &algName, std::string const &name, std::array< std::string, sizeof...(COLUMNS)> const &branchNames)
 
void fillTree (std::tuple< COLUMNS... > const &data) const
 fills the tree with given data this is safe to be called in the threaded context
 
void writeTree (TFile &file, std::string const &algName)
 

Private Member Functions

template<std::size_t... Is>
void createBranches (std::index_sequence< Is... > const, std::string const &algName, std::array< std::string, sizeof...(COLUMNS)> const &branchNames) const
 

Private Attributes

TTree * m_tree { nullptr }
 
std::vector< details::BranchWrapperm_branchWrappers {}
 
std::mutex m_mtx
 

Detailed Description

template<typename... COLUMNS>
class Gaudi::NTuple::Wrapper< COLUMNS >

Wrapper around a given NTuple.

Provides the functionality for initializing branches in a ROOT TTree, filling the tree, and writing it to a given file.

An algorithm wanting to write NTuple would typically declare one or several Wrappers as its member and call initTree at initialization, fillTree during processing (that one is thread safe) and finally writeTree at finalization initTree and writeTree are not thread safe

Template Parameters
COLUMNSVariadic template parameters representing data types in the NTuple

Definition at line 44 of file Writer.h.

Member Function Documentation

◆ createBranches()

template<typename... COLUMNS>
template<std::size_t... Is>
void Gaudi::NTuple::Wrapper< COLUMNS >::createBranches ( std::index_sequence< Is... > const ,
std::string const & algName,
std::array< std::string, sizeof...(COLUMNS)> const & branchNames ) const
inlineprivate

Definition at line 86 of file Writer.h.

87 {
88 ( ..., m_branchWrappers.emplace_back(
90 branchNames[Is], "", algName ) );
91 }
Wrapper around a given NTuple.
Definition Writer.h:44
std::vector< details::BranchWrapper > m_branchWrappers
Definition Writer.h:81

◆ fillTree()

template<typename... COLUMNS>
void Gaudi::NTuple::Wrapper< COLUMNS >::fillTree ( std::tuple< COLUMNS... > const & data) const
inline

fills the tree with given data this is safe to be called in the threaded context

Definition at line 59 of file Writer.h.

59 {
62 [&]( const auto&... elems ) {
63 size_t index = 0;
64 ( ..., m_branchWrappers[index++].setDataPtr( const_cast<void*>( static_cast<const void*>( &elems ) ) ) );
65 },
66 data );
67 m_tree->Fill();
68 }
std::mutex m_mtx
Definition Writer.h:82

◆ initTree()

template<typename... COLUMNS>
void Gaudi::NTuple::Wrapper< COLUMNS >::initTree ( TFile & file,
std::string const & algName,
std::string const & name,
std::array< std::string, sizeof...(COLUMNS)> const & branchNames )
inline

Definition at line 47 of file Writer.h.

48 {
49 file.cd();
50 m_tree = std::make_unique<TTree>( name.c_str(), "Tree of Writer Algorithm" ).release();
51 m_branchWrappers.reserve( m_branchWrappers.size() + sizeof...( COLUMNS ) );
53 }
void createBranches(std::index_sequence< Is... > const, std::string const &algName, std::array< std::string, sizeof...(COLUMNS)> const &branchNames) const
Definition Writer.h:86

◆ writeTree()

template<typename... COLUMNS>
void Gaudi::NTuple::Wrapper< COLUMNS >::writeTree ( TFile & file,
std::string const & algName )
inline

Definition at line 71 of file Writer.h.

71 {
72 file.cd();
73 if ( m_tree->Write() <= 0 ) {
74 throw GaudiException( "Failed to write TTree to ROOT file.", algName, StatusCode::FAILURE );
75 }
76 m_tree = nullptr;
77 }

Member Data Documentation

◆ m_branchWrappers

template<typename... COLUMNS>
std::vector<details::BranchWrapper> Gaudi::NTuple::Wrapper< COLUMNS >::m_branchWrappers {}
mutableprivate

Definition at line 81 of file Writer.h.

81{}; // Container for BranchWrapper objects

◆ m_mtx

template<typename... COLUMNS>
std::mutex Gaudi::NTuple::Wrapper< COLUMNS >::m_mtx
mutableprivate

Definition at line 82 of file Writer.h.

◆ m_tree

template<typename... COLUMNS>
TTree* Gaudi::NTuple::Wrapper< COLUMNS >::m_tree { nullptr }
private

Definition at line 80 of file Writer.h.

80{ nullptr }; // Pointer to the TTree being written to

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