20#include <fmt/format.h>
21#include <gsl/pointers>
43 template <
typename... COLUMNS>
47 void initTree( TFile& file, std::string
const& algName, std::string
const& name,
48 std::array<std::string,
sizeof...( COLUMNS )>
const& branchNames ) {
50 m_tree = std::make_unique<TTree>( name.c_str(),
"Tree of Writer Algorithm" ).release();
52 createBranches( std::make_index_sequence<
sizeof...( COLUMNS )>{}, algName, branchNames );
59 void fillTree( std::tuple<COLUMNS...>
const& data )
const {
60 std::scoped_lock lock{
m_mtx };
62 [&](
const auto&... elems ) {
64 ( ...,
m_branchWrappers[index++].setDataPtr(
const_cast<void*
>(
static_cast<const void*
>( &elems ) ) ) );
71 void writeTree( TFile& file, std::string
const& algName ) {
73 if (
m_tree->Write() <= 0 ) {
85 template <std::size_t... Is>
86 void createBranches( std::index_sequence<Is...>
const, std::string
const& algName,
87 std::array<std::string,
sizeof...( COLUMNS )>
const& branchNames )
const {
90 branchNames[Is],
"", algName ) );
102 template <
typename Base>
108 return Base::initialize().
andThen( [
this]() {
111 this->error() <<
"Failed to retrieve TFile." <<
endmsg;
128 template <
typename Signature,
typename Traits_ = Gaudi::Functional::Traits::BaseClass_t<Gaudi::Algorithm>>
151 template <
typename... OUTPUTs,
typename... INPUTs,
typename Traits_>
153 :
FileHolder<Gaudi::Functional::Consumer<void( const INPUTs&... ), Traits_>> {
155 using Consumer_t::Consumer_t;
159 this,
"BranchNames", {},
"Names of the tree branches." };
174 m_ntuple.writeTree( *this->file(), this->name() );
175 return Consumer_t::finalize();
186 template <
typename Signature,
typename Traits_ = Gaudi::Functional::Traits::BaseClass_t<Gaudi::Algorithm>>
204 template <
typename... OUTPUTs,
typename... INPUTs,
typename Traits_>
205 struct Writer<
std::tuple<OUTPUTs...>( const INPUTs&... ), Traits_>
206 :
SimpleWriter<std::tuple<OUTPUTs...>( const INPUTs&... ), Traits_> {
209 using SimpleWriter_t::SimpleWriter_t;
216 virtual std::tuple<OUTPUTs...>
transform(
const INPUTs&... inputs )
const = 0;
220 auto transformedData =
transform( inputs... );
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.
Wrapper around a given NTuple.
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 initTree(TFile &file, std::string const &algName, std::string const &name, std::array< std::string, sizeof...(COLUMNS)> const &branchNames)
std::vector< details::BranchWrapper > m_branchWrappers
void writeTree(TFile &file, std::string const &algName)
void createBranches(std::index_sequence< Is... > const, std::string const &algName, std::array< std::string, sizeof...(COLUMNS)> const &branchNames) const
Implementation of property with value of concrete type.
Define general base for Gaudi exception.
Handle to be used in lieu of naked pointers to services.
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.
Small class wrapping an algorithm and adding management of a Root File via the FileSvc.
virtual StatusCode initialize() override
Gaudi::Property< std::string > m_fileId
std::shared_ptr< TFile > m_file
ServiceHandle< Gaudi::Interfaces::IFileSvc > m_fileSvc
FileHolder< Gaudi::Functional::Consumer< void(const INPUTs &...), Traits_ > > Consumer_t
Gaudi::Property< std::string > m_ntupleTname
void fillTree(const std::tuple< OUTPUTs... > &data) const
virtual StatusCode initialize() override
virtual StatusCode finalize() override
Wrapper< OUTPUTs... > m_ntuple
Gaudi::Property< std::array< std::string, sizeof...(OUTPUTs)> > m_branchNames
void operator()(const INPUTs &... inputs) const override
virtual std::tuple< OUTPUTs... > transform(const INPUTs &... inputs) const =0
Transform input data to the desired output format.
SimpleWriter< std::tuple< OUTPUTs... >(const INPUTs &...), Traits_ > SimpleWriter_t