| The Gaudi Framework v29r1 (5cd95fa2)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

StatEntity.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_STATENTITY_H
2 #define GAUDIKERNEL_STATENTITY_H 1
3 // ============================================================================
4 // Include files
5 // ============================================================================
6 // STD & STL
7 // ============================================================================
8 #include <iostream>
9 #include <mutex>
10 #include <string>
11 // ============================================================================
12 // Gaudi
13 // ============================================================================
14 #include "GaudiKernel/Kernel.h"
15 // ============================================================================
65 class GAUDI_API StatEntity final
66 {
67 public:
68 // ==========================================================================
70 StatEntity() = default;
71 /* The full constructor from all important values:
72 * @attention it need to be coherent with
73 * the actual structure of the class
74 * and the format description
75 * @see StatEntity::format
76 * @param entries number of entries
77 * @param flag accumulated flag
78 * @param flag2 accumulated statistics: flag**2
79 * @param minFlag the minimum value for flag
80 * @param maxFlag the maximum value for flag
81 */
82 StatEntity( const unsigned long entries, const double flag, const double flag2, const double minFlag,
83 const double maxFlag );
85 StatEntity( const StatEntity& );
87 StatEntity& operator=( const StatEntity& );
88 // ==========================================================================
89 public: // the basic quantities
90 // ==========================================================================
92 const unsigned long& nEntries() const { return m_se.nEntries; }
94 const double& sum() const { return m_se.accumulatedFlag; }
96 const double& sum2() const { return m_se.accumulatedFlag2; }
98 double mean() const { return m_se.mean(); }
100 double rms() const { return m_se.rms(); }
102 double meanErr() const { return m_se.meanErr(); }
104 const double& min() const { return m_se.minimalFlag; }
106 const double& max() const { return m_se.maximalFlag; }
107 // ==========================================================================
108 public:
109 // ==========================================================================
142 double efficiency() const { return m_se.efficiency(); }
179 double efficiencyErr() const { return m_se.efficiencyErr(); }
181 double eff() const { return efficiency(); }
183 double effErr() const { return efficiencyErr(); }
184 // ==========================================================================
185 // operators
186 // ==========================================================================
187 public:
207 StatEntity& operator+=( const double f )
208 {
209 addFlag( f );
210 return *this;
211 }
229 StatEntity& operator++() { return ( *this ) += 1; }
248 StatEntity& operator++( int ) { return ++( *this ); }
268 StatEntity& operator-=( const double f )
269 {
270 addFlag( -f );
271 return *this;
272 }
290 StatEntity& operator--() { return ( *this ) -= 1; }
308 StatEntity& operator--( int ) { return --( *this ); }
326 StatEntity& operator=( const double f )
327 {
328 // reset the statistics
329 reset();
330 // use the regular increment
331 return ( ( *this ) += f );
332 }
348 StatEntity& operator+=( const StatEntity& other );
349 // ==========================================================================
350 public:
351 // ==========================================================================
353 GAUDI_API friend bool operator<( const StatEntity& lhs, const StatEntity& rhs );
358 unsigned long add( const double Flag );
360 void reset();
362 void setnEntriesBeforeReset( unsigned long nEntriesBeforeReset );
364 std::string toString() const;
368 std::ostream& print( std::ostream& o = std::cout ) const;
372 std::ostream& fillStream( std::ostream& o ) const { return print( o ); }
373 // ==========================================================================
374 public: // aliases (a'la ROOT)
375 // ==========================================================================
377 inline double Sum() const { return sum(); } // get sum
379 inline double Mean() const { return mean(); } // get mean
381 inline double MeanErr() const { return meanErr(); } // get error in mean
383 inline double Rms() const { return rms(); } // get rms
385 inline double RMS() const { return rms(); } // get rms
387 inline double Eff() const { return eff(); } // get efficiency
389 inline double Min() const { return min(); } // get minimal value
391 inline double Max() const { return max(); } // get maximal value
392 // ==========================================================================
393 public: // some legacy methods, to be removed ...
394 // ==========================================================================
396 inline double flag() const { return sum(); }
398 inline double flag2() const { return sum2(); }
400 inline double flagMean() const { return mean(); }
402 inline double flagRMS() const { return rms(); }
404 inline double flagMeanErr() const { return meanErr(); }
406 inline double flagMin() const { return min(); }
408 inline double flagMax() const { return max(); }
413 inline unsigned long addFlag( const double Flag ) { return add( Flag ); }
414 // ==========================================================================
415 public:
416 // ==========================================================================
423 static const std::string& format();
430 static int size();
431 // ==========================================================================
432 // ============================================================================
434 GAUDI_API friend StatEntity operator+( const StatEntity& entity, const double value );
436 GAUDI_API friend StatEntity operator+( const double value, const StatEntity& entity );
438 GAUDI_API friend StatEntity operator+( const StatEntity& entity, const StatEntity& value );
440 GAUDI_API friend StatEntity operator-( const StatEntity& entity, const double value );
442 GAUDI_API friend std::ostream& operator<<( std::ostream& stream, const StatEntity& entity );
443 // ============================================================================
444 private:
445 // ==========================================================================
446 struct se {
448 unsigned long nEntries = 0;
450 double accumulatedFlag = 0;
451 double accumulatedFlag2 = 0;
452 double minimalFlag = std::numeric_limits<double>::max();
453 double maximalFlag = -1 * std::numeric_limits<double>::max();
454 // DR number of calls before reset
455 long nEntriesBeforeReset = -1; // ?
456
457 se& operator+=( const struct se& other )
458 {
459 nEntries += other.nEntries;
460 accumulatedFlag += other.accumulatedFlag;
461 accumulatedFlag2 += other.accumulatedFlag2;
462 minimalFlag = std::min( minimalFlag, other.minimalFlag );
463 maximalFlag = std::max( maximalFlag, other.maximalFlag );
464 return *this;
465 }
466
467 unsigned long add( double Flag );
468 double mean() const;
469 double rms() const;
470 double meanErr() const;
471 double efficiency() const;
472 double efficiencyErr() const;
473
474 friend bool operator<( const struct se& lhs, const struct se& rhs )
475 {
476 auto order = []( const auto& s ) {
477 return std::tie( s.nEntries, s.accumulatedFlag, s.minimalFlag, s.maximalFlag, s.accumulatedFlag2 );
478 };
479 return order( lhs ) < order( rhs );
480 };
481 } m_se = {};
482 // Mutex to protect calls of add/reset/operator++, i.e. all _writes_ to (but not reads from!) m_se;
483 std::mutex m_mutex;
484 // ==========================================================================
485 };
486 namespace Gaudi
487 {
488 // ==========================================================================
489 namespace Utils
490 {
491 // ========================================================================
541 GAUDI_API std::string formatAsTableRow(
542 const StatEntity& counter, const bool flag,
543 const std::string& format1 = " |%|7d| |%|11.7g| |%|#11.5g| |%|#10.5g| |%|#10.5g| |%|#10.5g| |",
544 const std::string& format2 = "*|%|7d| |%|11.5g| |(%|#9.7g| +- %|-#8.6g|)%%| ----- | ----- |" );
545 // ========================================================================
606 GAUDI_API std::string formatAsTableRow(
607 const std::string& name, const StatEntity& counter, const bool flag = true,
608 const std::string& format1 = " %|-15.15s|%|17t||%|7d| |%|11.7g| |%|#11.5g| |%|#10.5g| |%|#10.5g| |%|#10.5g| |",
609 const std::string& format2 =
610 "*%|-15.15s|%|17t||%|7d| |%|11.5g| |(%|#9.7g| +- %|-#8.6g|)%%| ----- | ----- |" );
611 // ========================================================================
679 GAUDI_API std::string formatAsTableRow(
680 const std::string& name, const std::string& group, const StatEntity& entity, const bool flag = true,
681 const std::string& format1 =
682 " %|15.15s|%|-15.15s|%|32t||%|7d| |%|11.7g| |%|#11.5g| |%|#10.5g| |%|#10.5g| |%|#10.5g| |",
683 const std::string& format2 =
684 "*%|15.15s|%|-15.15s|%|32t||%|7d| |%|11.5g| |(%|#9.7g| +- %|-#8.6g|)%%| ----- | ----- |" );
685 // ========================================================================
686 } // end of namespace Gaudi::Utils
687 // ==========================================================================
688 } // end of namespace Gaudi
689 // ============================================================================
690 // The END
691 // ============================================================================
692 #endif // GAUDIKERNEL_STATENTITY_H
693 // ============================================================================
StatEntity::effErr
double effErr() const
shortcut,
Definition: StatEntity.h:183
StatEntity::max
const double & max() const
maximal value
Definition: StatEntity.h:106
Kernel.h
StatEntity::Min
double Min() const
get minimal value
Definition: StatEntity.h:389
StatEntity::nEntries
const unsigned long & nEntries() const
getters – no synchronization!
Definition: StatEntity.h:92
StatEntity::se
Definition: StatEntity.h:446
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:120
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:32
std::tie
T tie(T...args)
StatEntity::Mean
double Mean() const
get mean
Definition: StatEntity.h:379
StatEntity::operator=
StatEntity & operator=(const double f)
Assignment from the flag The action: reset and the general increment Such case could be useful for st...
Definition: StatEntity.h:326
StatEntity::flagRMS
double flagRMS() const
r.m.s of flag
Definition: StatEntity.h:402
StatEntity::fillStream
std::ostream & fillStream(std::ostream &o) const
printout to std::ostream
Definition: StatEntity.h:372
StatEntity::m_mutex
std::mutex m_mutex
Definition: StatEntity.h:483
StatEntity::efficiency
double efficiency() const
Interpret the counter as some measure of efficiency The efficiency is calculated as the ratio of the ...
Definition: StatEntity.h:142
sum
double sum(double x, double y, double z)
Definition: 3DoubleFuncTest.cpp:25
GaudiPython.HistoUtils.meanErr
meanErr
Definition: HistoUtils.py:840
StatEntity::flagMin
double flagMin() const
minimal flag
Definition: StatEntity.h:406
StatEntity::se::accumulatedFlag
double accumulatedFlag
accumulated flag
Definition: StatEntity.h:450
StatEntity::meanErr
double meanErr() const
error in mean value of counter
Definition: StatEntity.h:102
StatEntity::se::operator+=
se & operator+=(const struct se &other)
Definition: StatEntity.h:457
StatEntity::se::minimalFlag
double minimalFlag
Definition: StatEntity.h:452
StatEntity::flagMeanErr
double flagMeanErr() const
error in mean value of flag
Definition: StatEntity.h:404
StatEntity::operator++
StatEntity & operator++(int)
Post-increment operator for the flag.
Definition: StatEntity.h:248
std::mutex
StatEntity::Max
double Max() const
get maximal value
Definition: StatEntity.h:391
StatEntity::sum2
const double & sum2() const
accumulated value**2
Definition: StatEntity.h:96
StatEntity::flagMax
double flagMax() const
maximal flag
Definition: StatEntity.h:408
Gaudi::Utils::formatAsTableRow
GAUDI_API std::string formatAsTableRow(const std::string &name, const std::string &group, const StatEntity &entity, const bool flag=true, const std::string &format1=" %|15.15s|%|-15.15s|%|32t||%|7d| |%|11.7g| |%|#11.5g| |%|#10.5g| |%|#10.5g| |%|#10.5g| |", const std::string &format2="*%|15.15s|%|-15.15s|%|32t||%|7d| |%|11.5g| |(%|#9.7g| +- %|-#8.6g|)%%| ----- | ----- |")
print the counter in a form of the table row
Definition: StatEntity.cpp:358
operator=
PropertyMgr & operator=(const PropertyMgr &)=delete
StatEntity::sum
const double & sum() const
accumulated value
Definition: StatEntity.h:94
std::string
STL class.
std::min
T min(T...args)
StatEntity::eff
double eff() const
shortcut,
Definition: StatEntity.h:181
GaudiPython.Persistency.add
def add(instance)
Definition: Persistency.py:39
StatEntity::operator++
StatEntity & operator++()
Pre-increment operator for the flag Could be used for easy manipulation with StatEntity object: ...
Definition: StatEntity.h:229
GaudiPython.HistoUtils.mean
mean
Definition: HistoUtils.py:838
GaudiPython.HistoUtils.nEntries
nEntries
Definition: HistoUtils.py:873
StatEntity::mean
double mean() const
mean value of counter
Definition: StatEntity.h:98
StatEntity::MeanErr
double MeanErr() const
get error in mean
Definition: StatEntity.h:381
StatEntity::flagMean
double flagMean() const
mean value of flag
Definition: StatEntity.h:400
StatEntity::Eff
double Eff() const
get efficiency
Definition: StatEntity.h:387
StatEntity::min
const double & min() const
minimal value
Definition: StatEntity.h:104
StatEntity::se::maximalFlag
double maximalFlag
Definition: StatEntity.h:453
StatEntity::Sum
double Sum() const
get sum
Definition: StatEntity.h:377
std::numeric_limits::max
T max(T...args)
StatEntity::addFlag
unsigned long addFlag(const double Flag)
add a flag
Definition: StatEntity.h:413
StatEntity::operator+=
StatEntity & operator+=(const double f)
General increment operator for the flag Could be used for easy manipulation with StatEntity object: ...
Definition: StatEntity.h:207
operator<
bool operator<(const EventIDBase &lhs, const EventIDBase &rhs)
Definition: EventIDBase.h:207
StatEntity::operator--
StatEntity & operator--()
Pre-decrement operator for the flag Could be used for easy manipulation with StatEntity object: ...
Definition: StatEntity.h:290
plotSpeedupsPyRoot.counter
int counter
Definition: plotSpeedupsPyRoot.py:149
StatEntity::operator--
StatEntity & operator--(int)
Post-decrement operator for the flag Could be used for easy manipulation with StatEntity object: ...
Definition: StatEntity.h:308
StatEntity::se::accumulatedFlag2
double accumulatedFlag2
Definition: StatEntity.h:451
print
void print(string text)
Definition: mergesort.cpp:30
gaudirun.s
string s
Definition: gaudirun.py:253
StatEntity::Rms
double Rms() const
get rms
Definition: StatEntity.h:383
operator-
GAUDI_API Stat operator-(const Stat &stat, const double value)
external operator for subtraction of Stat and a number
Definition: Stat.cpp:150
StatEntity::RMS
double RMS() const
get rms
Definition: StatEntity.h:385
StatEntity::rms
double rms() const
r.m.s of value
Definition: StatEntity.h:100
StatEntity
The basic counter used for Monitoring purposes.
Definition: StatEntity.h:65
StatEntity::flag2
double flag2() const
accumulated "flag squared"
Definition: StatEntity.h:398
StatEntity::se::operator<
friend bool operator<(const struct se &lhs, const struct se &rhs)
Definition: StatEntity.h:474
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:110
std::ostream
STL class.
StatEntity::operator-=
StatEntity & operator-=(const double f)
General decrement operator for the flag Could be used for easy manipulation with StatEntity object: ...
Definition: StatEntity.h:268
Gaudi
Helper functions to set/get the application return code.
Definition: __init__.py:1
GaudiMath::Interpolation::toString
std::string toString(const Type &)
Definition: Interpolation.cpp:42
StatEntity::flag
double flag() const
accumulated "flag"
Definition: StatEntity.h:396
StatEntity::se::nEntries
unsigned long nEntries
number of calls
Definition: StatEntity.h:448
Gaudi::operator+
decltype(std::declval< TP >()+std::declval< T >()) operator+(const T &v, const Property< TP, V, H > &p)
implemantation of (value + property)
Definition: Property.h:687
StatEntity::efficiencyErr
double efficiencyErr() const
Interpret the counter as some measure of efficiency and evaluate the uncertainty of this efficiency u...
Definition: StatEntity.h:179
GaudiAlg::operator<<
std::ostream & operator<<(std::ostream &str, const GaudiAlg::ID &id)
Operator overloading for ostream.
Definition: GaudiHistoID.h:136
GaudiPython.HistoUtils.rms
rms
Definition: HistoUtils.py:842