16 #include <boost/algorithm/string.hpp>
19 #include <fmt/format.h>
22 #include <string_view>
38 {
"counter",
"{0:nEntries|10d}" },
39 {
"histogram",
"{0:nEntries|10d}" },
40 {
"counter:AveragingCounter",
"{0:nEntries|10d} |{0:sum|11.7g} |{0:mean|#11.5g}" },
41 {
"counter:SigmaCounter",
"{0:nEntries|10d} |{0:sum|11.7g} |{0:mean|#11.5g} |{0:standard_deviation|#11.5g}" },
42 {
"counter:StatCounter",
"{0:nEntries|10d} |{0:sum|11.7g} |{0:mean|#11.5g} |{0:standard_deviation|#11.5g} "
43 "|{0:min|#12.5g} |{0:max|#12.5g}" },
44 {
"counter:BinomialCounter",
45 "{0:nEntries|10d} |{0:nTrueEntries|11d} |({0:efficiency|#9.7p} +- {0:efficiencyErr|-#8.7p})%" },
66 class fmt::formatter<json_fmt_arg> {
68 template <
typename ParseContext>
70 auto fmt_begin =
ctx.begin();
72 if ( fmt_begin == fmt_end ) {
77 auto fmt_colon =
std::find( fmt_begin, fmt_end,
'|' );
78 currentName =
std::string( fmt_begin, fmt_colon - fmt_begin );
79 currentFormat =
std::string( fmt_colon + 1, fmt_end - fmt_colon - 1 );
83 template <
typename FormatContext>
84 auto format(
const json_fmt_arg& json_arg, FormatContext&
ctx ) {
85 const auto& j = json_arg.payload;
86 if ( currentFormat.size() == 0 ) {
90 std::string_view type_key{
type };
92 auto entry =
registry.find( type_key );
94 auto sep = type_key.rfind(
':' );
95 while ( sep != type_key.npos && entry ==
registry.end() ) {
97 type_key.remove_suffix( type_key.size() - sep );
99 sep = type_key.rfind(
':' );
108 return fmt::format_to(
ctx.out(), entry->second, json_arg );
111 auto actualFormat =
fmt::format(
"{{:{}", currentFormat ) +
"}";
112 switch ( currentFormat.back() ) {
114 return fmt::format_to(
ctx.out(), actualFormat, j.at( currentName ).template get<unsigned int>() );
116 return fmt::format_to(
ctx.out(), actualFormat, j.at( currentName ).template get<double>() );
118 actualFormat[actualFormat.size() - 2] =
'g';
119 return fmt::format_to(
ctx.out(), actualFormat, j.at( currentName ).template get<double>() * 100 );
121 return fmt::format_to(
ctx.out(),
"Unknown counter format : {}", currentFormat );
133 template <
typename stream>
138 if (
type ==
"statentity" ) {
139 using boost::algorithm::icontains;
140 bool isBinomial = icontains(
id,
"eff" ) || icontains(
id,
"acc" ) || icontains(
id,
"filt" ) ||
141 icontains(
id,
"fltr" ) || icontains(
id,
"pass" );
143 nj[
"type"] = isBinomial ?
"counter:BinomialCounter" :
"counter:StatCounter";
144 return printCounter(
log,
id, nj );
148 ( std::string_view{
type }.substr( 0, 23 ) ==
"counter:BinomialCounter" ?
'*' :
' ' ),
160 .orThrow(
"Unable to set typesToSaveProperty",
"Histograming::Sink::Base" );
177 applytoAllEntities( [&sortedEntities](
auto& ent ) { sortedEntities[ent.component][ent.name] = ent.toJSON(); } );
179 for (
auto& [algoName, entityMap] : sortedEntities ) {
181 unsigned int nbCounters =
183 return a + ( j.second.at(
"empty" ).
template get<bool>() ? 0 : 1 );
185 if ( 0 == nbCounters )
continue;
187 log <<
MSG::INFO <<
"Number of counters : " << nbCounters <<
"\n"
188 <<
" | Counter | # | "
189 <<
" sum | mean/eff^* | rms/err^* | min | max |";
192 if ( !p.second.at(
"empty" ).template get<bool>() ) {
194 printCounter( log, p.first, p.second );