16 #include <boost/algorithm/string.hpp>
19 #include <fmt/format.h>
23 #include <string_view>
39 {
"counter",
"{0:nEntries|10d}" },
40 {
"histogram",
"{0:nEntries|10d}" },
41 {
"counter:AveragingCounter",
"{0:nEntries|10d} |{0:sum|11.7g} |{0:mean|#11.5g}" },
42 {
"counter:SigmaCounter",
"{0:nEntries|10d} |{0:sum|11.7g} |{0:mean|#11.5g} |{0:standard_deviation|#11.5g}" },
43 {
"counter:StatCounter",
"{0:nEntries|10d} |{0:sum|11.7g} |{0:mean|#11.5g} |{0:standard_deviation|#11.5g} "
44 "|{0:min|#12.5g} |{0:max|#12.5g}" },
45 {
"counter:BinomialCounter",
46 "{0:nEntries|10d} |{0:nTrueEntries|11d} |({0:efficiency|#9.7p} +- {0:efficiencyErr|-#8.7p})%" },
67 class fmt::formatter<json_fmt_arg> {
69 template <
typename ParseContext>
71 auto fmt_begin =
ctx.begin();
73 if ( fmt_begin == fmt_end ) {
78 auto fmt_colon =
std::find( fmt_begin, fmt_end,
'|' );
79 currentName =
std::string( fmt_begin, fmt_colon - fmt_begin );
80 currentFormat =
std::string( fmt_colon + 1, fmt_end - fmt_colon - 1 );
84 template <
typename FormatContext>
85 auto format(
const json_fmt_arg& json_arg, FormatContext&
ctx )
const {
86 const auto&
j = json_arg.payload;
87 if ( currentFormat.size() == 0 ) {
91 std::string_view type_key{
type };
93 auto entry =
registry.find( type_key );
95 auto sep = type_key.rfind(
':' );
96 while ( sep != type_key.npos && entry ==
registry.end() ) {
98 type_key.remove_suffix( type_key.size() - sep );
100 sep = type_key.rfind(
':' );
109 return fmt::format_to(
ctx.out(), fmt::runtime( entry->second ), json_arg );
112 auto actualFormat =
"{:" + currentFormat +
'}';
113 switch ( currentFormat.back() ) {
115 return fmt::format_to(
ctx.out(), fmt::runtime( actualFormat ),
116 j.at( currentName ).template get<unsigned int>() );
118 return fmt::format_to(
ctx.out(), fmt::runtime( actualFormat ),
j.at( currentName ).template get<double>() );
120 actualFormat[actualFormat.size() - 2] =
'g';
121 return fmt::format_to(
ctx.out(), fmt::runtime( actualFormat ),
122 j.at( currentName ).template get<double>() * 100 );
124 return fmt::format_to(
ctx.out(),
"Unknown counter format : {}", currentFormat );
140 if (
type ==
"statentity" ) {
141 using boost::algorithm::icontains;
142 bool isBinomial = icontains(
id,
"eff" ) || icontains(
id,
"acc" ) || icontains(
id,
"filt" ) ||
143 icontains(
id,
"fltr" ) || icontains(
id,
"pass" );
145 nj[
"type"] = isBinomial ?
"counter:BinomialCounter" :
"counter:StatCounter";
146 return printCounter(
log,
id, nj );
152 ( std::string_view{
type }.substr( 0, 23 ) ==
"counter:BinomialCounter" ?
'*' :
' ' ),
153 fmt::format( fmt::runtime(
"\"{}\"" ),
id ), json_fmt_arg{
j } );
171 .orThrow(
"Unable to set typesToSaveProperty",
"Histograming::Sink::Base" );
174 void flush(
bool )
override;
183 unsigned int nbNonEmptyEntities = 0;
184 auto dumpAlgoCounters = [&]() {
186 if ( nbNonEmptyEntities > 0 ) {
188 log <<
MSG::INFO <<
"Number of counters : " << nbNonEmptyEntities <<
"\n"
189 <<
" | Counter | # | "
190 <<
" sum | mean/eff^* | rms/err^* | min | max |";
196 if ( algo != curAlgo ) {
199 nbNonEmptyEntities = 0;
203 if ( !
j.at(
"empty" ).template get<bool>() ) {
204 ++nbNonEmptyEntities;
206 printCounter( curLog, entity,
j );