18 #include <TDirectory.h>
21 #include <range/v3/numeric/accumulate.hpp>
22 #include <range/v3/range/conversion.hpp>
23 #include <range/v3/view/split_when.hpp>
24 #include <range/v3/view/transform.hpp>
26 #if RANGE_V3_VERSION < 900
28 using namespace ranges::view;
32 #include <nlohmann/json.hpp>
43 return std::string_view( ent.
type ).substr( 0, 10 ) ==
"histogram:";
59 return { jAxis.at(
"nBins" ).get<
unsigned int>(), jAxis.at(
"minValue" ).get<
double>(),
60 jAxis.at(
"maxValue" ).get<
double>(),
69 std::index_sequence<index...> ) {
71 auto jsonAxis = j.at(
"axis" );
75 auto nentries = j.
at(
"nEntries" ).get<
unsigned int>();
77 title += ( axis[index].title + ... );
79 auto totNBins = ( ( axis[index].nBins + 2 ) * ... );
80 assert( weights.size() == totNBins );
82 if (
name[0] ==
'/' ) {
89 if (
auto pos =
name.rfind(
'/' ); pos != std::string::npos ) {
90 dir +=
'/' +
name.substr( 0, pos );
95 auto previousDir = gDirectory;
100 auto is_delimiter = [](
auto c ) {
return c ==
'/' ||
c ==
'.'; };
101 auto transform_to_string = views::transform( [](
auto&& rng ) {
return rng | to<std::string>; } );
103 auto currentDir =
accumulate( dir | views::split_when( is_delimiter ) | transform_to_string,
104 file.GetDirectory(
"" ), [](
auto current,
auto&& dir_level ) {
107 auto nextDir = current->GetDirectory( dir_level.c_str() );
109 if ( !nextDir ) nextDir = current->mkdir( dir_level.c_str() );
123 auto histo = Traits::create(
name, title, axis[index]... );
126 for (
unsigned int i = 0; i < totNBins; i++ )
Traits::fill(
histo, i, weights[i] );
128 Traits::fillMetaData(
histo, jsonAxis, nentries );
151 template <
typename Traits>
154 std::make_index_sequence<Traits::Dimension>() );
171 :
Service(
name, svcloc ), m_isRelevant(
std::move( isRelevant ) ) {}
179 if ( !ok )
return ok;
181 std::sort(
begin( m_monitoringEntities ),
end( m_monitoringEntities ), [](
const auto& a,
const auto& b ) {
184 TFile histoFile( m_fileName.value().c_str(),
"RECREATE" );
185 std::for_each(
begin( m_monitoringEntities ),
end( m_monitoringEntities ), [&histoFile,
this](
auto& ent ) {
186 auto j = ent.toJSON();
187 auto dim = j.at(
"dimension" ).
template get<unsigned int>();
188 auto type = j.at(
"type" ).
template get<std::string>();
192 auto saver = m_registry.find( { type, dim } );
193 if ( saver != m_registry.end() ) ( saver->second )( histoFile, ent.component, ent.name, j );
199 if ( m_isRelevant( ent ) ) { m_monitoringEntities.emplace_back(
std::move( ent ) ); }
203 auto it =
std::find(
begin( m_monitoringEntities ),
end( m_monitoringEntities ), ent );
204 if ( it != m_monitoringEntities.end() ) { m_monitoringEntities.erase( it ); }
222 "Name of file where to save histograms" };