21#include <nlohmann/json.hpp>
35 using HistoHandler = std::function<void( TFile& file, std::string, std::string, nlohmann::json
const& )>;
45 setProperty(
"TypesToSave", std::vector<std::string>{
"histogram:.*" } )
46 .orThrow(
"Unable to set typesToSaveProperty",
"Histograming::Sink::Base" );
50 return BaseSink::initialize().
andThen( [&] {
53 info() <<
"Writing ROOT histograms to: " <<
m_fileName.value() <<
" ("
66 std::shared_ptr<TFile> histoFile;
74 histoFile = std::make_shared<TFile>(
m_fileName.value().c_str(),
"UPDATE" );
83 binSaver->second( *histoFile, component,
name, ent );
87 nlohmann::json j = ent;
88 auto dim = j.at(
"dimension" ).template get<unsigned int>();
89 auto type = j.at(
"type" ).template get<std::string>();
92 type = type.substr( 0, type.find_last_of(
':' ) );
94 if ( saver !=
m_registry.end() ) ( saver->second )( *histoFile, component,
name, j );
100 m_binRegistry.emplace( std::piecewise_construct, std::make_tuple(
id ), std::make_tuple( func ) );
104 m_registry.emplace( std::piecewise_construct, std::make_tuple(
id ), std::make_tuple( func ) );
114 "Name of file where to save histograms" };
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
std::function< void(TFile &file, std::string, std::string, nlohmann::json const &)> HistoHandler
void flush(bool) override
pure virtual method to be defined by children and responsible for flushing current data of the Sink.
ServiceHandle< Gaudi::Interfaces::IFileSvc > m_fileSvc
Base(const std::string &name, ISvcLocator *svcloc)
Gaudi::Property< std::string > m_fileName
std::type_index HistoBinIdentification
HistoBinRegistry m_binRegistry
map of supported type and the way to handle them
std::map< HistoBinIdentification, HistoBinHandler > HistoBinRegistry
std::function< void(TFile &file, std::string, std::string, Monitoring::Hub::Entity const &)> HistoBinHandler
StatusCode initialize() override
void registerHandler(HistoIdentification const &id, HistoHandler const &func)
void registerHandler(HistoBinIdentification const &id, HistoBinHandler const &func)
std::map< HistoIdentification, HistoHandler > HistoRegistry
HistoRegistry m_registry
map of supported type and the way to handle them
std::pair< std::string, int > HistoIdentification
Base class for all Sinks registering to the Monitoring Hub Should be extended by actual Sinks.
void applyToAllSortedEntities(Callable func) const
applies a callable to all monitoring entities ordered by component the callable will be called once p...
Wrapper class for arbitrary monitoring objects.
std::type_index typeIndex() const
function to get internal type
Implementation of property with value of concrete type.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
StatusCode setProperty(const Gaudi::Details::PropertyBase &p)
Handle to be used in lieu of naked pointers to services.
const std::string & name() const override
Retrieve name of the service.
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.