20 #include <fmt/format.h>
21 #include <gsl/pointers>
35 template <
typename Signature>
50 template <
typename... OUTPUTs,
typename... INPUTs>
52 TTree* m_tree =
nullptr;
67 m_tree = std::make_unique<TTree>( ntupleName.
c_str(),
"Tree of Writer Algorithm" ).release();
68 m_branchWrappers.reserve( m_branchWrappers.size() +
sizeof...( OUTPUTs ) );
69 createBranchesForOutputs( branchNames, std::make_index_sequence<
sizeof...( OUTPUTs )>{}, algName );
75 const std::index_sequence<Is...>,
const std::string& algName )
const {
76 ( ..., m_branchWrappers.emplace_back(
78 branchNames[Is],
"", algName ) );
82 void fillTree(
const INPUTs&... inputs )
const {
83 auto transformedData = transform( inputs... );
85 [&](
const auto&... elems ) {
87 ( ..., m_branchWrappers[
index++].setDataPtr(
const_cast<void*
>(
static_cast<const void*
>( &elems ) ) ) );
96 if ( m_tree->Write() <= 0 ) {
110 template <
typename Signature,
typename Traits_ = Gaudi::Functional::Traits::BaseClass_t<Gaudi::Algorithm>>
124 template <
typename... OUTPUTs,
typename... INPUTs,
typename Traits_>
125 struct Writer<
std::tuple<OUTPUTs...>( const INPUTs&... ), Traits_>
127 WriterMixin<std::tuple<OUTPUTs...>( const INPUTs&... )> {
129 using Consumer_t::Consumer_t;
134 this,
"BranchNames", {},
"Names of the tree branches." };
141 return Consumer_t::initialize().
andThen( [
this]() {
142 m_fileSvc = this->
template service<Gaudi::Interfaces::IFileSvc>(
"FileSvc" );
144 this->error() <<
"Failed to retrieve FileSvc." <<
endmsg;
148 m_file = m_fileSvc->
getFile( m_fileId );
150 this->error() <<
"Failed to retrieve TFile." <<
endmsg;
154 this->initTree( m_file, m_ntupleTname.value(), m_branchNames.value(), this->name() );
162 std::scoped_lock lock{ m_mtx };
163 this->fillTree(
args... );
168 this->writeTree( m_file, this->
name() );
169 return Consumer_t::finalize();