18 #include <boost/algorithm/string.hpp>
21 #include <fmt/format.h>
25 #include <string_view>
41 {
"counter",
"{0:nEntries|10d}" },
42 {
"counter:AveragingCounter",
"{0:nEntries|10d} |{0:sum|11.7g} |{0:mean|#11.5g}" },
43 {
"counter:SigmaCounter",
"{0:nEntries|10d} |{0:sum|11.7g} |{0:mean|#11.5g} |{0:standard_deviation|#11.5g}" },
44 {
"counter:StatCounter",
"{0:nEntries|10d} |{0:sum|11.7g} |{0:mean|#11.5g} |{0:standard_deviation|#11.5g} "
45 "|{0:min|#12.5g} |{0:max|#12.5g}" },
46 {
"counter:BinomialCounter",
47 "{0:nEntries|10d} |{0:nTrueEntries|11d} |({0:efficiency|#9.7p} +- {0:efficiencyErr|-#8.7p})%" },
53 using HistoBinHandler =
56 namespace Acc = ::Gaudi::Accumulators;
63 { 4, &Gaudi::Histograming::Sink::printProfileHisto1D<Acc::atomicity::full, double> } },
65 { 4, &Gaudi::Histograming::Sink::printProfileHisto1D<Acc::atomicity::none, double> } },
67 { 4, &Gaudi::Histograming::Sink::printProfileHisto1D<Acc::atomicity::full, float> } },
69 { 4, &Gaudi::Histograming::Sink::printProfileHisto1D<Acc::atomicity::none, float> } },
71 { 5, &Gaudi::Histograming::Sink::printProfileHisto2D<Acc::atomicity::full, double> } },
73 { 5, &Gaudi::Histograming::Sink::printProfileHisto2D<Acc::atomicity::none, double> } },
75 { 5, &Gaudi::Histograming::Sink::printProfileHisto2D<Acc::atomicity::full, float> } },
77 { 5, &Gaudi::Histograming::Sink::printProfileHisto2D<Acc::atomicity::none, float> } },
79 { 6, &Gaudi::Histograming::Sink::printProfileHisto3D<Acc::atomicity::full, double> } },
81 { 6, &Gaudi::Histograming::Sink::printProfileHisto3D<Acc::atomicity::none, double> } },
83 { 6, &Gaudi::Histograming::Sink::printProfileHisto3D<Acc::atomicity::full, float> } },
85 { 6, &Gaudi::Histograming::Sink::printProfileHisto3D<Acc::atomicity::none, float> } },
107 class fmt::formatter<json_fmt_arg> {
109 template <
typename ParseContext>
111 auto fmt_begin =
ctx.begin();
113 if ( fmt_begin == fmt_end ) {
118 auto fmt_colon =
std::find( fmt_begin, fmt_end,
'|' );
119 currentName =
std::string( fmt_begin, fmt_colon - fmt_begin );
120 currentFormat =
std::string( fmt_colon + 1, fmt_end - fmt_colon - 1 );
124 template <
typename FormatContext>
125 auto format(
const json_fmt_arg& json_arg, FormatContext&
ctx )
const {
126 const auto&
j = json_arg.payload;
127 if ( currentFormat.size() == 0 ) {
131 std::string_view type_key{
type };
133 auto entry =
registry.find( type_key );
135 auto sep = type_key.rfind(
':' );
136 while ( sep != type_key.npos && entry ==
registry.end() ) {
138 type_key.remove_suffix( type_key.size() - sep );
140 sep = type_key.rfind(
':' );
149 return fmt::format_to(
ctx.out(), fmt::runtime( entry->second ), json_arg );
152 auto actualFormat =
"{:" + currentFormat +
'}';
153 switch ( currentFormat.back() ) {
155 return fmt::format_to(
ctx.out(), fmt::runtime( actualFormat ),
156 j.at( currentName ).template get<unsigned int>() );
158 return fmt::format_to(
ctx.out(), fmt::runtime( actualFormat ),
j.at( currentName ).template get<double>() );
160 actualFormat[actualFormat.size() - 2] =
'g';
161 return fmt::format_to(
ctx.out(), fmt::runtime( actualFormat ),
162 j.at( currentName ).template get<double>() * 100 );
164 return fmt::format_to(
ctx.out(),
"Unknown counter format : {}", currentFormat );
180 if (
type ==
"statentity" ) {
181 using boost::algorithm::icontains;
182 bool isBinomial = icontains(
id,
"eff" ) || icontains(
id,
"acc" ) || icontains(
id,
"filt" ) ||
183 icontains(
id,
"fltr" ) || icontains(
id,
"pass" );
185 nj[
"type"] = isBinomial ?
"counter:BinomialCounter" :
"counter:StatCounter";
186 return printCounter(
log,
id, nj );
192 ( std::string_view{
type }.substr( 0, 23 ) ==
"counter:BinomialCounter" ?
'*' :
' ' ),
193 fmt::format( fmt::runtime(
"\"{}\"" ),
id ), json_fmt_arg{
j } );
211 .orThrow(
"Unable to set TypesToSave property",
"Gaudi::Monitoring::MessageSvcSink" );
214 .orThrow(
"Unable to set ComponentsToSave property",
"Gaudi::Monitoring::MessageSvcSink" );
217 void flush(
bool )
override;
219 "length of histograms names and titles in the output" };
234 auto dumpAlgoCounters = [&]() {
237 if ( nbNonEmptyEntities[0] > 0 ) {
238 log <<
MSG::INFO <<
"Number of counters : " << nbNonEmptyEntities[0] <<
"\n"
239 <<
" | Counter | # | "
240 <<
" sum | mean/eff^* | rms/err^* | min | max |";
244 unsigned int nHistos = nbNonEmptyEntities[1] + nbNonEmptyEntities[2] + nbNonEmptyEntities[3] +
245 nbNonEmptyEntities[4] + nbNonEmptyEntities[5] + nbNonEmptyEntities[6];
247 log <<
MSG::INFO <<
"Booked " << nHistos <<
" Histogram(s) : 1D=" << nbNonEmptyEntities[1]
248 <<
" 2D=" << nbNonEmptyEntities[2] <<
" 3D=" << nbNonEmptyEntities[3] <<
" 1DProf=" << nbNonEmptyEntities[4]
249 <<
" 2DProf=" << nbNonEmptyEntities[5] <<
" 3DProf=" << nbNonEmptyEntities[6] <<
endmsg;
250 if ( nbNonEmptyEntities[1] > 0 ) {
251 log <<
MSG::INFO <<
"1D histograms in directory \"" << curAlgo <<
"\" : " << nbNonEmptyEntities[1] <<
"\n"
254 " | {:{}s} | {:{}s} | # | Mean | RMS | Skewness | Kurtosis |" ),
256 << curLog[1].str() <<
endmsg;
258 if ( nbNonEmptyEntities[2] > 0 ) {
259 log <<
MSG::INFO <<
"2D histograms in directory \"" << curAlgo <<
"\" : " << nbNonEmptyEntities[2]
260 << curLog[2].str() <<
endmsg;
262 if ( nbNonEmptyEntities[3] > 0 ) {
263 log <<
MSG::INFO <<
"3D histograms in directory \"" << curAlgo <<
"\" : " << nbNonEmptyEntities[3]
264 << curLog[3].str() <<
endmsg;
266 if ( nbNonEmptyEntities[4] > 0 ) {
267 log <<
MSG::INFO <<
"1D profile histograms in directory \"" << curAlgo <<
"\" : " << nbNonEmptyEntities[4]
271 " | {:{}s} | {:{}s} | # | Mean | RMS | Skewness | Kurtosis |" ),
273 << curLog[4].str() <<
endmsg;
275 if ( nbNonEmptyEntities[5] > 0 ) {
276 log <<
MSG::INFO <<
"2D profile histograms in directory \"" << curAlgo <<
"\" : " << nbNonEmptyEntities[5]
277 << curLog[5].str() <<
endmsg;
279 if ( nbNonEmptyEntities[6] > 0 ) {
280 log <<
MSG::INFO <<
"3D profile histograms in directory \"" << curAlgo <<
"\" : " << nbNonEmptyEntities[6]
281 << curLog[6].str() <<
endmsg;
288 if ( algo != curAlgo ) {
291 nbNonEmptyEntities = { 0, 0, 0, 0, 0, 0, 0 };
297 auto binWriter = binRegistry.
find( typeIndex );
298 if ( binWriter != binRegistry.
end() ) {
299 auto index = binWriter->second.first;
300 ++nbNonEmptyEntities[
index];
302 if ( logLine.
size() > 0 ) { curLog[
index] <<
"\n" << logLine; }
308 if (
type.find(
"histogram" ) == 0 ) {
309 if ( !
j.at(
"empty" ).template get<bool>() ) {
310 unsigned int d =
j.at(
"dimension" ).get<
int>();
311 auto subtype = std::string_view(
type ).substr( 10 );
312 bool isProfile = subtype.substr( 0, 15 ) ==
"WeightedProfile" || subtype.substr( 0, 7 ) ==
"Profile";
313 unsigned int index = ( isProfile ? 3 : 0 ) + d;
327 if ( logLine.size() > 0 ) {
328 curLog[
index] <<
"\n" << logLine;
329 ++nbNonEmptyEntities[
index];
334 if ( !
j.at(
"empty" ).template get<bool>() ) {
335 ++nbNonEmptyEntities[0];
337 printCounter( curLog[0],
name,
j );