19 #include <fmt/format.h>
20 #include <gsl/pointers>
34 template <
typename Signature>
49 template <
typename... OUTPUTs,
typename... INPUTs>
51 TTree* m_tree =
nullptr;
66 m_tree = std::make_unique<TTree>(
"WriterTree",
"Tree of Writer Algorithm" ).
release();
68 throw GaudiException(
"Failed to create TTree. Ensure sufficient resources and permissions.", algRef.
name(),
71 m_branchWrappers.reserve( m_branchWrappers.size() +
sizeof...( OUTPUTs ) );
72 createBranchesForOutputs( branchNames, std::make_index_sequence<
sizeof...( OUTPUTs )>{}, algRef );
79 ( ..., m_branchWrappers.emplace_back(
81 branchNames[Is],
"", algRef ) );
85 void fillTree(
const INPUTs&... inputs )
const {
86 auto transformedData = transform( inputs... );
88 [&](
const auto&... elems ) {
90 ( ..., m_branchWrappers[
index++].setDataPtr(
const_cast<void*
>(
static_cast<const void*
>( &elems ) ) ) );
99 if ( m_tree->Write() <= 0 ) {
103 algRef.info() <<
"TTree written to TFile." <<
endmsg;
114 template <
typename Signature,
typename Traits_ = Gaudi::Functional::Traits::BaseClass_t<Gaudi::Algorithm>>
128 template <
typename... OUTPUTs,
typename... INPUTs,
typename Traits_>
129 struct Writer<
std::tuple<OUTPUTs...>( const INPUTs&... ), Traits_>
131 WriterMixin<std::tuple<OUTPUTs...>( const INPUTs&... )> {
133 using Consumer_t::Consumer_t;
136 "Filename for the TTree." };
138 this,
"BranchNames", {},
"Names of the tree branches." };
144 return Consumer_t::initialize().
andThen( [
this]() {
145 m_file = std::make_unique<TFile>( m_filename.value().c_str(),
"RECREATE" );
146 if ( !m_file || m_file->IsZombie() ) {
148 fmt::format(
"Failed to open file '{}'. Check file path and permissions.", m_filename.value() ),
152 this->initTree( m_file, m_branchNames.value(), *
this );
161 this->fillTree(
args... );
166 this->writeTree( m_file, *
this );
167 return Consumer_t::finalize();