The Gaudi Framework  master (594c33fa)
Gaudi::NTuple::WriterMixin< std::tuple< OUTPUTs... >(const INPUTs &...)> Struct Template Referenceabstract

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

Inheritance diagram for Gaudi::NTuple::WriterMixin< std::tuple< OUTPUTs... >(const INPUTs &...)>:
Collaboration diagram for Gaudi::NTuple::WriterMixin< std::tuple< OUTPUTs... >(const INPUTs &...)>:

Public Member Functions

virtual std::tuple< OUTPUTs... > transform (const INPUTs &... inputs) const =0
 Transform input data to the desired output format. More...
 
void initTree (const std::unique_ptr< TFile > &file, const gsl::span< std::string, sizeof...(OUTPUTs)> branchNames, const Gaudi::Algorithm &algRef)
 
template<std::size_t... Is>
void createBranchesForOutputs (const gsl::span< std::string, sizeof...(OUTPUTs)> branchNames, const std::index_sequence< Is... >, const Gaudi::Algorithm &algRef) const
 
void fillTree (const INPUTs &... inputs) const
 
void writeTree (const std::unique_ptr< TFile > &file, const Gaudi::Algorithm &algRef)
 
virtual ~WriterMixin ()=default
 

Public Attributes

TTree * m_tree = nullptr
 
std::array< std::string, sizeof...(OUTPUTs)> m_branchNames
 
std::vector< details::BranchWrapperm_branchWrappers {}
 

Detailed Description

template<typename... OUTPUTs, typename... INPUTs>
struct Gaudi::NTuple::WriterMixin< std::tuple< OUTPUTs... >(const INPUTs &...)>

Definition at line 50 of file Writer.h.

Constructor & Destructor Documentation

◆ ~WriterMixin()

template<typename... OUTPUTs, typename... INPUTs>
virtual Gaudi::NTuple::WriterMixin< std::tuple< OUTPUTs... >(const INPUTs &...)>::~WriterMixin ( )
virtualdefault

Member Function Documentation

◆ createBranchesForOutputs()

template<typename... OUTPUTs, typename... INPUTs>
template<std::size_t... Is>
void Gaudi::NTuple::WriterMixin< std::tuple< OUTPUTs... >(const INPUTs &...)>::createBranchesForOutputs ( const gsl::span< std::string, sizeof...(OUTPUTs)>  branchNames,
const std::index_sequence< Is... >  ,
const Gaudi::Algorithm algRef 
) const
inline

Definition at line 77 of file Writer.h.

78  {
79  ( ..., m_branchWrappers.emplace_back(
80  m_tree, System::typeinfoName( typeid( std::tuple_element_t<Is, std::tuple<OUTPUTs...>> ) ),
81  branchNames[Is], "", algRef ) );
82  }

◆ fillTree()

template<typename... OUTPUTs, typename... INPUTs>
void Gaudi::NTuple::WriterMixin< std::tuple< OUTPUTs... >(const INPUTs &...)>::fillTree ( const INPUTs &...  inputs) const
inline

Definition at line 85 of file Writer.h.

85  {
86  auto transformedData = transform( inputs... );
87  std::apply(
88  [&]( const auto&... elems ) {
89  size_t index = 0;
90  ( ..., m_branchWrappers[index++].setDataPtr( const_cast<void*>( static_cast<const void*>( &elems ) ) ) );
91  },
92  transformedData );
93  m_tree->Fill();
94  }

◆ initTree()

template<typename... OUTPUTs, typename... INPUTs>
void Gaudi::NTuple::WriterMixin< std::tuple< OUTPUTs... >(const INPUTs &...)>::initTree ( const std::unique_ptr< TFile > &  file,
const gsl::span< std::string, sizeof...(OUTPUTs)>  branchNames,
const Gaudi::Algorithm algRef 
)
inline

Definition at line 63 of file Writer.h.

64  {
65  file->cd();
66  m_tree = std::make_unique<TTree>( "WriterTree", "Tree of Writer Algorithm" ).release();
67  if ( !m_tree ) {
68  throw GaudiException( "Failed to create TTree. Ensure sufficient resources and permissions.", algRef.name(),
70  }
71  m_branchWrappers.reserve( m_branchWrappers.size() + sizeof...( OUTPUTs ) );
72  createBranchesForOutputs( branchNames, std::make_index_sequence<sizeof...( OUTPUTs )>{}, algRef );
73  }

◆ transform()

template<typename... OUTPUTs, typename... INPUTs>
virtual std::tuple<OUTPUTs...> Gaudi::NTuple::WriterMixin< std::tuple< OUTPUTs... >(const INPUTs &...)>::transform ( const INPUTs &...  inputs) const
pure virtual

Transform input data to the desired output format.

Must be overridden in derived classes.

Parameters
inputsVariadic inputs of types specified by INPUTs...
Returns
A tuple of output data corresponding to OUTPUTs...

◆ writeTree()

template<typename... OUTPUTs, typename... INPUTs>
void Gaudi::NTuple::WriterMixin< std::tuple< OUTPUTs... >(const INPUTs &...)>::writeTree ( const std::unique_ptr< TFile > &  file,
const Gaudi::Algorithm algRef 
)
inline

Definition at line 97 of file Writer.h.

97  {
98  file->cd();
99  if ( m_tree->Write() <= 0 ) {
100  throw GaudiException( "Failed to write TTree to ROOT file.", algRef.name(), StatusCode::FAILURE );
101  }
102  m_tree = nullptr;
103  algRef.info() << "TTree written to TFile." << endmsg;
104  }

Member Data Documentation

◆ m_branchNames

template<typename... OUTPUTs, typename... INPUTs>
std::array<std::string, sizeof...( OUTPUTs )> Gaudi::NTuple::WriterMixin< std::tuple< OUTPUTs... >(const INPUTs &...)>::m_branchNames

Definition at line 52 of file Writer.h.

◆ m_branchWrappers

template<typename... OUTPUTs, typename... INPUTs>
std::vector<details::BranchWrapper> Gaudi::NTuple::WriterMixin< std::tuple< OUTPUTs... >(const INPUTs &...)>::m_branchWrappers {}
mutable

Definition at line 53 of file Writer.h.

◆ m_tree

template<typename... OUTPUTs, typename... INPUTs>
TTree* Gaudi::NTuple::WriterMixin< std::tuple< OUTPUTs... >(const INPUTs &...)>::m_tree = nullptr

Definition at line 51 of file Writer.h.


The documentation for this struct was generated from the following file:
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
std::tuple
System::typeinfoName
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:313
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
Gaudi::NTuple::WriterMixin< std::tuple< OUTPUTs... >(const INPUTs &...)>::m_tree
TTree * m_tree
Definition: Writer.h:51
Gaudi::NTuple::WriterMixin< std::tuple< OUTPUTs... >(const INPUTs &...)>::m_branchWrappers
std::vector< details::BranchWrapper > m_branchWrappers
Definition: Writer.h:53
Gaudi::NTuple::WriterMixin< std::tuple< OUTPUTs... >(const INPUTs &...)>::createBranchesForOutputs
void createBranchesForOutputs(const gsl::span< std::string, sizeof...(OUTPUTs)> branchNames, const std::index_sequence< Is... >, const Gaudi::Algorithm &algRef) const
Definition: Writer.h:77
Gaudi::NTuple::WriterMixin< std::tuple< OUTPUTs... >(const INPUTs &...)>::transform
virtual std::tuple< OUTPUTs... > transform(const INPUTs &... inputs) const =0
Transform input data to the desired output format.
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
Gaudi::ParticleProperties::index
size_t index(const Gaudi::ParticleProperty *property, const Gaudi::Interfaces::IParticlePropertySvc *service)
helper utility for mapping of Gaudi::ParticleProperty object into non-negative integral sequential id...
Definition: IParticlePropertySvc.cpp:39