5 #define GAUDIKERNEL_STATENTITY_CPP 1
23 #include "boost/format.hpp"
24 #include "boost/static_assert.hpp"
25 #include "boost/algorithm/string/case_conv.hpp"
31 #pragma warning(disable:1572)
35 #pragma warning(disable:2259)
48 (
const unsigned long entries ,
51 const double minFlag ,
52 const double maxFlag )
53 : m_se_nEntries ( entries )
54 , m_se_accumulatedFlag ( flag )
55 , m_se_accumulatedFlag2 ( flag2 )
56 , m_se_minimalFlag ( minFlag )
57 , m_se_maximalFlag ( maxFlag )
58 , m_se_nEntriesBeforeReset ( -1 )
66 BOOST_STATIC_ASSERT(((
sizeof(
unsigned long)==4)||(
sizeof(
unsigned long)==8)));
68 BOOST_STATIC_ASSERT((
sizeof(
double)==8)) ;
70 static const std::string s_fmt =
71 ( ( 8 ==
sizeof(
unsigned long) ) ?
"X:1;" :
"L:1;" ) + std::string(
"D:4") ;
79 static const int s_size =
sizeof(
unsigned long) + 4 *
sizeof(
double) ;
97 if ( 0 >=
nEntries() ) {
return 0 ; }
99 const long double f2 = f1 /
nEntries () ;
101 const long double f4 = f3 /
nEntries () ;
102 const long double result = f4 - f2 * f2 ;
103 return ( 0 > result ) ? 0 : ::sqrtl ( result ) ;
110 if ( 0 >=
nEntries () ) {
return 0 ; }
112 const long double f2 = f1 /
nEntries () ;
114 const long double f4 = f3 /
nEntries () ;
115 const long double result = f4 - f2 * f2 ;
116 if ( 0 > result ) {
return 0 ; }
118 return ::sqrtl ( result /
nEntries () ) ;
126 const long double fMin =
min () ;
127 if ( 0 != fMin && 1 != fMin ) {
return -1 ; }
128 const long double fMax =
max () ;
129 if ( 0 != fMax && 1 != fMax ) {
return -1 ; }
139 long double n1 =
sum () ;
141 if ( 0 == n1 ) { n1 = 1 ; }
142 const long double n3 =
nEntries () ;
143 long double n2 = n3 -
flag () ;
145 if ( 1 > fabsl( n2 ) ) { n2 = 1 ; }
147 return ::sqrtl( n1 * n2 / n3 ) / n3 ;
167 if ( &se ==
this ) {
return false ; }
170 sum () < se.
sum () ) {
return true ; }
173 min () < se.
min () ) {
return true ; }
177 max () < se.
max () ) {
return true ; }
182 sum2 () < se.
sum2 () ) {
return true ; }
201 if ( s_min1 < Flag || -s_min1 > Flag )
229 std::ostringstream ost ;
240 boost::format fmt2 (
" Mean=%|#10.4g| +- %|-#10.5g| Min/Max=%|#10.4g|/%|-#10.4g|" ) ;
253 {
return entity +
value ; }
268 {
return entity.
print ( stream ) ; }
280 inline bool effCounter (
const std::string& name )
282 const std::string lower = boost::algorithm::to_lower_copy( name ) ;
284 std::string::npos != lower.find (
"eff" ) ||
285 std::string::npos != lower.find (
"acc" ) ||
286 std::string::npos != lower.find (
"filt" ) ||
287 std::string::npos != lower.find (
"fltr" ) ||
288 std::string::npos != lower.find (
"pass" ) ;
304 const std::string& format1 ,
305 const std::string& format2 )
307 using namespace boost::io ;
308 if ( flag && 0 <= counter.
eff() && 0 <= counter.
effErr() )
311 fmt.exceptions ( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) ) ;
315 % ( counter.
eff () * 100 )
316 % ( counter.
effErr () * 100 ) ;
320 fmt.exceptions ( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) ) ;
341 (
const std::string& name ,
344 const std::string& format1 ,
345 const std::string& format2 )
347 using namespace boost::io ;
348 if ( flag && effCounter ( name ) && 0 <= counter.
eff() && 0 <= counter.
effErr() )
351 fmt.exceptions ( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) ) ;
353 % (
"\"" + name +
"\"" )
356 % ( counter.
eff () * 100 )
357 % ( counter.
effErr () * 100 ) ;
361 fmt.exceptions ( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) ) ;
363 % (
"\"" + name +
"\"" )
384 (
const std::string& name ,
385 const std::string& group ,
388 const std::string& format1 ,
389 const std::string& format2 )
391 using namespace boost::io ;
392 if ( flag && ( effCounter ( name ) || effCounter ( group ) )
393 && 0 <= counter.
eff() && 0 <= counter.
effErr() )
396 fmt.exceptions ( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) ) ;
398 % (
"\"" + name +
":" )
399 % (
":" + group +
"\"" )
402 % ( counter.
eff () * 100 )
403 % ( counter.
effErr () * 100 ) ;
407 fmt.exceptions ( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) ) ;
409 % (
"\"" + name +
":" )
410 % (
":" + group +
"\"" )
std::string toString() const
representation as string
double effErr() const
shortcut,
const double & max() const
maximal value
unsigned long m_se_nEntries
number of calls
StatEntity()
the default constructor
const unsigned long & nEntries() const
getters
StatEntity operator+(const StatEntity &entity, const double value)
external operator for addition of StatEntity and a number
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
double efficiency() const
Interpret the counter as some measure of efficiency The efficiency is calculated as the ratio of the ...
std::ostream & operator<<(std::ostream &stream, const StatEntity &entity)
external printout operator to std::ostream
double meanErr() const
error in mean value of counter
void reset()
reset the counters
long m_se_nEntriesBeforeReset
unsigned long add(const double Flag)
add a value
bool operator<(const StatEntity &se) const
comparison
std::ostream & print(std::ostream &o=std::cout) const
printout to std::ostream
const double & sum2() const
accumulated value**2
GAUDI_API std::string formatAsTableRow(const StatEntity &counter, const bool flag, const std::string &format1=" |%|7d| |%|11.7g| |%|#11.5g| |%|#10.5g| |%|#10.5g| |%|#10.5g| |", const std::string &format2="*|%|7d| |%|11.5g| |(%|#9.7g| +- %|-#8.6g|)%%| ----- | ----- |")
print the counter in a form of the table row
const double & sum() const
accumulated value
void setnEntriesBeforeReset(unsigned long nEntriesBeforeReset)
DR specify number of entry before reset.
double eff() const
shortcut,
double mean() const
mean value of counter
double m_se_accumulatedFlag
accumulated flag
StatEntity operator-(const StatEntity &entity, const double value)
external operator for subtraction of StatEntity and a number
const double & min() const
minimal value
static const std::string & format()
the internal format description
StatEntity & operator+=(const double f)
General increment operator for the flag Could be used for easy manipulation with StatEntity object: ...
static int size()
the actual size of published data
double rms() const
r.m.s of value
The basic counter used for Monitoring purposes.
double flag() const
accumulated "flag"
double efficiencyErr() const
Interpret the counter as some measure of efficiency and evaluate the uncertainty of this efficiency u...
double m_se_accumulatedFlag2