28#include <fmt/format.h>
29#include <gsl/pointers>
47 template <
typename... COLUMNS>
51 void initTree( TFile& file, std::string
const& algName, std::string name,
52 std::array<std::string,
sizeof...( COLUMNS )>
const& branchNames ) {
54 auto pos = name.rfind(
'/' );
55 if ( pos != std::string::npos ) {
56 m_dir = name.substr( 0, pos );
57 name = name.substr( pos + 1 );
60 if (
m_dir !=
"" ) file.mkdir(
m_dir.c_str(),
"",
true );
62 file.cd(
m_dir.c_str() );
64 m_tree = std::make_unique<TTree>( name.c_str(),
"Tree of Writer Algorithm" ).release();
66 createBranches( std::make_index_sequence<
sizeof...( COLUMNS )>{}, algName, branchNames );
73 void fillTree( std::tuple<COLUMNS...>
const& data )
const {
74 std::scoped_lock lock{
m_mtx };
76 [&](
const auto&... elems ) {
78 ( ...,
m_branchWrappers[index++].setDataPtr(
const_cast<void*
>(
static_cast<const void*
>( &elems ) ) ) );
85 void writeTree( TFile& file, std::string
const& algName ) {
87 file.cd(
m_dir.c_str() );
88 if (
m_tree->Write() <= 0 ) {
101 template <std::size_t... Is>
102 void createBranches( std::index_sequence<Is...>
const, std::string
const& algName,
103 std::array<std::string,
sizeof...( COLUMNS )>
const& branchNames )
const {
106 branchNames[Is],
"", algName ) );
118 template <
typename Base>
124 return Base::initialize().
andThen( [
this]() {
127 this->error() <<
"Failed to retrieve TFile." <<
endmsg;
144 template <
typename Signature,
typename Traits_ = Gaudi::Functional::Traits::BaseClass_t<Gaudi::Algorithm>>
167 template <
typename... OUTPUTs,
typename... INPUTs,
typename Traits_>
169 :
FileHolder<Gaudi::Functional::Consumer<void( const INPUTs&... ), Traits_>> {
171 using Consumer_t::Consumer_t;
175 this,
"BranchNames", {},
"Names of the tree branches." };
190 m_ntuple.writeTree( *this->file(), this->name() );
191 return Consumer_t::finalize();
202 template <
typename Signature,
typename Traits_ = Gaudi::Functional::Traits::BaseClass_t<Gaudi::Algorithm>>
220 template <
typename... OUTPUTs,
typename... INPUTs,
typename Traits_>
221 struct Writer<
std::tuple<OUTPUTs...>( const INPUTs&... ), Traits_>
222 :
SimpleWriter<std::tuple<OUTPUTs...>( const INPUTs&... ), Traits_> {
225 using SimpleWriter_t::SimpleWriter_t;
232 virtual std::tuple<OUTPUTs...>
transform(
const INPUTs&... inputs )
const = 0;
236 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
std::vector< Gaudi::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
void initTree(TFile &file, std::string const &algName, std::string name, std::array< std::string, sizeof...(COLUMNS)> const &branchNames)
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