20#include <fmt/format.h>
21#include <gsl/pointers>
35 template <
typename Signature>
50 template <
typename... OUTPUTs,
typename... INPUTs>
61 virtual std::tuple<OUTPUTs...>
transform(
const INPUTs&... inputs )
const = 0;
64 void initTree(
const std::shared_ptr<TFile>& file,
const std::string& ntupleName,
65 const gsl::span<std::string,
sizeof...( OUTPUTs )> branchNames,
const std::string& algName ) {
67 m_tree = std::make_unique<TTree>( ntupleName.c_str(),
"Tree of Writer Algorithm" ).release();
73 template <std::size_t... Is>
75 const std::index_sequence<Is...>,
const std::string& algName )
const {
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 ) ) ) );
94 void writeTree(
const std::shared_ptr<TFile>& file,
const std::string& algName ) {
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;
150 this->error() <<
"Failed to retrieve TFile." <<
endmsg;
162 std::scoped_lock lock{
m_mtx };
169 return Consumer_t::finalize();
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Collection of utilities, which allows to use class std::array as property for Gaudi-components.
Implementation of property with value of concrete type.
Define general base for Gaudi exception.
This class is used for returning status codes from appropriate routines.
StatusCode andThen(F &&f, ARGS &&... args) const
Chain code blocks making the execution conditional a success result.
constexpr static const auto SUCCESS
constexpr static const auto FAILURE
details::Consumer< Signature, Traits_, details::isLegacy< Traits_ > > Consumer
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Interface for a component that manages file access within Gaudi applications.
Gaudi::Functional::Consumer< void(const INPUTs &...), Traits_ > Consumer_t
Gaudi::Interfaces::IFileSvc * m_fileSvc
std::shared_ptr< TFile > m_file
void operator()(const INPUTs &... args) const override
Gaudi::Property< std::string > m_ntupleTname
virtual StatusCode initialize() override
Gaudi::Property< std::string > m_fileId
Gaudi::Property< std::array< std::string, sizeof...(OUTPUTs)> > m_branchNames
virtual StatusCode finalize() override
void writeTree(const std::shared_ptr< TFile > &file, const std::string &algName)
std::array< std::string, sizeof...(OUTPUTs)> m_branchNames
void createBranchesForOutputs(const gsl::span< std::string, sizeof...(OUTPUTs)> branchNames, const std::index_sequence< Is... >, const std::string &algName) const
virtual std::tuple< OUTPUTs... > transform(const INPUTs &... inputs) const =0
Transform input data to the desired output format.
void initTree(const std::shared_ptr< TFile > &file, const std::string &ntupleName, const gsl::span< std::string, sizeof...(OUTPUTs)> branchNames, const std::string &algName)
void fillTree(const INPUTs &... inputs) const
std::vector< details::BranchWrapper > m_branchWrappers
virtual ~WriterMixin()=default