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 <string>
9 #include <iostream>
10 // ============================================================================
11 // Gaudi
12 // ============================================================================
13 #include "GaudiKernel/Kernel.h"
14 // ============================================================================
64 class GAUDI_API StatEntity final
65 {
66 public:
67  // ==========================================================================
69  StatEntity () { reset() ; }
70  /* The full constructor from all important values:
71  * @attention it need to be coherent with
72  * the actual structure of the class
73  * and the format description
74  * @see StatEntity::format
75  * @param entries number of entries
76  * @param flag accumulated flag
77  * @param flag2 accumulated statistics: flag**2
78  * @param minFlag the minimum value for flag
79  * @param maxFlag the maximum value for flag
80  */
81  StatEntity ( const unsigned long entries ,
82  const double flag ,
83  const double flag2 ,
84  const double minFlag ,
85  const double maxFlag ) ;
87  ~StatEntity () = default;
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 ;
100  double rms () const ;
102  double meanErr () const ;
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 ;
179  double efficiencyErr () const ;
181  double eff () const { return efficiency () ; }
183  double effErr () const { return efficiencyErr () ; }
184  // ==========================================================================
185 public: // operators
186  // ==========================================================================
206  StatEntity& operator+= ( const double f )
207  {
208  addFlag ( f ) ;
209  return *this ;
210  }
228  StatEntity& operator++ () { return (*this)+= 1 ; }
247  StatEntity& operator++ (int) { return ++(*this) ; }
267  StatEntity& operator-= ( const double f )
268  {
269  addFlag ( -f ) ;
270  return *this ;
271  }
289  StatEntity& operator-- () { return (*this)-=1 ; }
307  StatEntity& operator-- (int) { return --(*this) ; }
325  StatEntity& operator= ( const double f )
326  {
327  // reset the statistics
328  reset() ;
329  // use the regular increment
330  return ((*this)+=f);
331  }
347  StatEntity& operator+= ( const StatEntity& other ) ;
348  // ==========================================================================
349 public:
350  // ==========================================================================
352  bool operator<( const StatEntity& se ) const ;
357  unsigned long add ( const double Flag ) ;
359  void reset () ;
361  void setnEntriesBeforeReset ( unsigned long nEntriesBeforeReset );
363  std::string toString () const;
367  std::ostream& print ( std::ostream& o = std::cout ) const ;
371  std::ostream& fillStream ( std::ostream& o ) const { return print ( o ) ; }
372  // ==========================================================================
373 public: // aliases (a'la ROOT)
374  // ==========================================================================
376  inline double Sum () const { return sum () ; } // get sum
378  inline double Mean () const { return mean () ; } // get mean
380  inline double MeanErr () const { return meanErr () ; } // get error in mean
382  inline double Rms () const { return rms () ; } // get rms
384  inline double RMS () const { return rms () ; } // get rms
386  inline double Eff () const { return eff () ; } // get efficiency
388  inline double Min () const { return min () ; } // get minimal value
390  inline double Max () const { return max () ; } // get maximal value
391  // ==========================================================================
392 public: // some legacy methods, to be removed ...
393  // ==========================================================================
395  inline double flag () const { return sum () ; }
397  inline double flag2 () const { return sum2 () ; }
399  inline double flagMean () const { return mean () ; }
401  inline double flagRMS () const { return rms () ; }
403  inline double flagMeanErr () const { return meanErr () ; }
405  inline double flagMin () const { return min () ; }
407  inline double flagMax () const { return max () ; }
412  inline unsigned long addFlag ( const double Flag ) { return add ( Flag ) ; }
413  // ==========================================================================
414 public:
415  // ==========================================================================
422  static const std::string& format () ;
429  static int size () ;
430  // ==========================================================================
431 private:
432  // ==========================================================================
434  unsigned long m_se_nEntries ;
436  double m_se_accumulatedFlag ;
437  double m_se_accumulatedFlag2 ;
438  double m_se_minimalFlag ;
439  double m_se_maximalFlag ;
440  // DR number of calls before reset
441  long m_se_nEntriesBeforeReset ;
442  // ==========================================================================
443 };
444 // ============================================================================
446 GAUDI_API StatEntity operator+( const StatEntity& entity , const double value ) ;
448 GAUDI_API StatEntity operator+( const double value , const StatEntity& entity ) ;
450 GAUDI_API StatEntity operator+( const StatEntity& entity , const StatEntity& value ) ;
452 GAUDI_API StatEntity operator-( const StatEntity& entity , const double value ) ;
454 GAUDI_API std::ostream& operator<<( std::ostream& stream , const StatEntity& entity ) ;
455 // ============================================================================
456 namespace Gaudi
457 {
458  // ==========================================================================
459  namespace Utils
460  {
461  // ========================================================================
511  GAUDI_API std::string formatAsTableRow
512  ( const StatEntity& counter ,
513  const bool flag ,
514  const std::string& format1 =
515  " |%|7d| |%|11.7g| |%|#11.5g| |%|#10.5g| |%|#10.5g| |%|#10.5g| |" ,
516  const std::string& format2 =
517  "*|%|7d| |%|11.5g| |(%|#9.7g| +- %|-#8.6g|)%%| ----- | ----- |" );
518  // ========================================================================
579  GAUDI_API std::string formatAsTableRow
580  ( const std::string& name ,
581  const StatEntity& counter ,
582  const bool flag = true ,
583  const std::string& format1 =
584  " %|-15.15s|%|17t||%|7d| |%|11.7g| |%|#11.5g| |%|#10.5g| |%|#10.5g| |%|#10.5g| |" ,
585  const std::string& format2 =
586  "*%|-15.15s|%|17t||%|7d| |%|11.5g| |(%|#9.7g| +- %|-#8.6g|)%%| ----- | ----- |" );
587  // ========================================================================
655  GAUDI_API std::string formatAsTableRow
656  ( const std::string& name ,
657  const std::string& group ,
658  const StatEntity& entity ,
659  const bool flag = true ,
660  const std::string& format1 =
661  " %|15.15s|%|-15.15s|%|32t||%|7d| |%|11.7g| |%|#11.5g| |%|#10.5g| |%|#10.5g| |%|#10.5g| |" ,
662  const std::string& format2 =
663  "*%|15.15s|%|-15.15s|%|32t||%|7d| |%|11.5g| |(%|#9.7g| +- %|-#8.6g|)%%| ----- | ----- |" ) ;
664  // ========================================================================
665  } // end of namespace Gaudi::Utils
666  // ==========================================================================
667 } // end of namespace Gaudi
668 // ============================================================================
669 // The END
670 // ============================================================================
671 #endif // GAUDIKERNEL_STATENTITY_H
672 // ============================================================================
#define GAUDI_API
Definition: Kernel.h:107
double sum(double x, double y, double z)
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:400
GAUDI_API StatEntity operator+(const StatEntity &entity, const double value)
external operator for addition of StatEntity and a number
Definition: StatEntity.cpp:244
GAUDI_API StatEntity operator-(const StatEntity &entity, const double value)
external operator for subtraction of StatEntity and a number
Definition: StatEntity.cpp:254
GAUDI_API std::ostream & operator<<(std::ostream &stream, const StatEntity &entity)
external printout operator to std::ostream
Definition: StatEntity.cpp:264
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
Definition: StatEntity.cpp:299
bool operator<(const Gaudi::Time &t1, const Gaudi::Time &t2)
Definition: Time.icpp:232
The basic counter used for Monitoring purposes.
Definition: StatEntity.h:64
Helper functions to set/get the application return code.
Definition: __init__.py:1
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:120