16 #include <boost/algorithm/string.hpp>
19 #include <fmt/format.h>
23 #include <string_view>
25 #if FMT_VERSION < 80000
48 {
"counter",
"{0:nEntries|10d}" },
49 {
"histogram",
"{0:nEntries|10d}" },
50 {
"counter:AveragingCounter",
"{0:nEntries|10d} |{0:sum|11.7g} |{0:mean|#11.5g}" },
51 {
"counter:SigmaCounter",
"{0:nEntries|10d} |{0:sum|11.7g} |{0:mean|#11.5g} |{0:standard_deviation|#11.5g}" },
52 {
"counter:StatCounter",
"{0:nEntries|10d} |{0:sum|11.7g} |{0:mean|#11.5g} |{0:standard_deviation|#11.5g} "
53 "|{0:min|#12.5g} |{0:max|#12.5g}" },
54 {
"counter:BinomialCounter",
55 "{0:nEntries|10d} |{0:nTrueEntries|11d} |({0:efficiency|#9.7p} +- {0:efficiencyErr|-#8.7p})%" },
76 class fmt::formatter<json_fmt_arg> {
78 template <
typename ParseContext>
80 auto fmt_begin =
ctx.begin();
82 if ( fmt_begin == fmt_end ) {
87 auto fmt_colon =
std::find( fmt_begin, fmt_end,
'|' );
88 currentName =
std::string( fmt_begin, fmt_colon - fmt_begin );
89 currentFormat =
std::string( fmt_colon + 1, fmt_end - fmt_colon - 1 );
93 template <
typename FormatContext>
94 auto format(
const json_fmt_arg& json_arg, FormatContext&
ctx ) {
95 const auto&
j = json_arg.payload;
96 if ( currentFormat.size() == 0 ) {
100 std::string_view type_key{
type };
102 auto entry =
registry.find( type_key );
104 auto sep = type_key.rfind(
':' );
105 while ( sep != type_key.npos && entry ==
registry.end() ) {
107 type_key.remove_suffix( type_key.size() - sep );
109 sep = type_key.rfind(
':' );
118 return fmt::format_to(
ctx.out(),
fmt::runtime( entry->second ), json_arg );
121 auto actualFormat =
"{:" + currentFormat +
'}';
122 switch ( currentFormat.back() ) {
125 j.at( currentName ).template get<unsigned int>() );
127 return fmt::format_to(
ctx.out(),
fmt::runtime( actualFormat ),
j.at( currentName ).template get<double>() );
129 actualFormat[actualFormat.size() - 2] =
'g';
131 j.at( currentName ).template get<double>() * 100 );
133 return fmt::format_to(
ctx.out(),
"Unknown counter format : {}", currentFormat );
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;
190 unsigned int nbNonEmptyEntities = 0;
191 auto dumpAlgoCounters = [&]() {
193 if ( nbNonEmptyEntities > 0 ) {
195 log <<
MSG::INFO <<
"Number of counters : " << nbNonEmptyEntities <<
"\n"
196 <<
" | Counter | # | "
197 <<
" sum | mean/eff^* | rms/err^* | min | max |";
203 if ( algo != curAlgo ) {
206 nbNonEmptyEntities = 0;
210 if ( !
j.at(
"empty" ).template get<bool>() ) {
211 ++nbNonEmptyEntities;
213 printCounter( curLog, entity,
j );