16 #include <boost/algorithm/string.hpp>
19 #include <fmt/format.h>
22 #include <string_view>
24 #if FMT_VERSION < 80000
47 {
"counter",
"{0:nEntries|10d}" },
48 {
"histogram",
"{0:nEntries|10d}" },
49 {
"counter:AveragingCounter",
"{0:nEntries|10d} |{0:sum|11.7g} |{0:mean|#11.5g}" },
50 {
"counter:SigmaCounter",
"{0:nEntries|10d} |{0:sum|11.7g} |{0:mean|#11.5g} |{0:standard_deviation|#11.5g}" },
51 {
"counter:StatCounter",
"{0:nEntries|10d} |{0:sum|11.7g} |{0:mean|#11.5g} |{0:standard_deviation|#11.5g} "
52 "|{0:min|#12.5g} |{0:max|#12.5g}" },
53 {
"counter:BinomialCounter",
54 "{0:nEntries|10d} |{0:nTrueEntries|11d} |({0:efficiency|#9.7p} +- {0:efficiencyErr|-#8.7p})%" },
75 class fmt::formatter<json_fmt_arg> {
77 template <
typename ParseContext>
79 auto fmt_begin =
ctx.begin();
81 if ( fmt_begin == fmt_end ) {
86 auto fmt_colon =
std::find( fmt_begin, fmt_end,
'|' );
87 currentName =
std::string( fmt_begin, fmt_colon - fmt_begin );
88 currentFormat =
std::string( fmt_colon + 1, fmt_end - fmt_colon - 1 );
92 template <
typename FormatContext>
93 auto format(
const json_fmt_arg& json_arg, FormatContext&
ctx ) {
94 const auto&
j = json_arg.payload;
95 if ( currentFormat.size() == 0 ) {
99 std::string_view type_key{
type };
101 auto entry =
registry.find( type_key );
103 auto sep = type_key.rfind(
':' );
104 while ( sep != type_key.npos && entry ==
registry.end() ) {
106 type_key.remove_suffix( type_key.size() - sep );
108 sep = type_key.rfind(
':' );
117 return fmt::format_to(
ctx.out(),
fmt::runtime( entry->second ), json_arg );
120 auto actualFormat =
"{:" + currentFormat +
'}';
121 switch ( currentFormat.back() ) {
124 j.at( currentName ).template get<unsigned int>() );
126 return fmt::format_to(
ctx.out(),
fmt::runtime( actualFormat ),
j.at( currentName ).template get<double>() );
128 actualFormat[actualFormat.size() - 2] =
'g';
130 j.at( currentName ).template get<double>() * 100 );
132 return fmt::format_to(
ctx.out(),
"Unknown counter format : {}", currentFormat );
144 template <
typename Stream>
149 if (
type ==
"statentity" ) {
150 using boost::algorithm::icontains;
151 bool isBinomial = icontains(
id,
"eff" ) || icontains(
id,
"acc" ) || icontains(
id,
"filt" ) ||
152 icontains(
id,
"fltr" ) || icontains(
id,
"pass" );
154 nj[
"type"] = isBinomial ?
"counter:BinomialCounter" :
"counter:StatCounter";
155 return printCounter(
log,
id, nj );
159 ( std::string_view{
type }.substr( 0, 23 ) ==
"counter:BinomialCounter" ?
'*' :
' ' ),
178 .orThrow(
"Unable to set typesToSaveProperty",
"Histograming::Sink::Base" );
181 void flush(
bool )
override;
191 unsigned int nbCounters =
193 return a + (
j.second.at(
"empty" ).
template get<bool>() ? 0 : 1 );
195 if ( 0 == nbCounters )
continue;
197 log <<
MSG::INFO <<
"Number of counters : " << nbCounters <<
"\n"
198 <<
" | Counter | # | "
199 <<
" sum | mean/eff^* | rms/err^* | min | max |";
202 if ( !p.second.at(
"empty" ).template get<bool>() ) {
204 printCounter( log, p.first, p.second );