Stat.h
Go to the documentation of this file.
1 #ifndef __GAUDI_CHRONOSTATSVC_STAT_H__
2 #define __GAUDI_CHRONOSTATSVC_STAT_H__
3 // ============================================================================
4 // Iinclude files
5 // ============================================================================
6 // STD & STL
7 // ============================================================================
8 #include <string>
9 // ============================================================================
10 // GaudiKernel
11 // ============================================================================
12 #include "GaudiKernel/ICounterSvc.h"
13 #include "GaudiKernel/StatEntity.h"
14 #include "GaudiKernel/SmartIF.h"
15 #include "GaudiKernel/IStatSvc.h"
16 // ============================================================================
46 class GAUDI_API Stat
47 {
48 public:
65  Stat ( StatEntity* entity = 0 ,
66  const std::string& name = "" ,
67  const std::string& group = "" )
68  : m_entity ( entity )
69  , m_tag ( name )
70  , m_group ( group )
71  , m_counter ( 0 )
72  {}
87  Stat ( StatEntity& entity ,
88  const std::string& name = "" ,
89  const std::string& group = "" )
90  : m_entity ( &entity )
91  , m_tag ( name )
92  , m_group ( group )
93  , m_counter ( 0 )
94  {}
113  Stat ( IStatSvc* svc ,
114  const std::string& tag ) ;
132  Stat ( IStatSvc* svc ,
133  const std::string& tag ,
134  const double flag ) ;
152  Stat ( ICounterSvc* svc ,
153  const std::string& group ,
154  const std::string& name ) ;
156  Stat ( const Stat& ) = default;
158  Stat& operator=( const Stat& ) = default;
160  ~Stat() = default;
161  // ==========================================================================
163  const StatEntity* entity () const { return m_entity ; }
165  const StatEntity* operator->() const { return entity() ; }
167  operator const StatEntity& () const { return *entity() ; }
169  bool operator!() const { return 0 == m_entity ; }
170  // ==========================================================================
187  Stat& operator+= ( const double f )
188  {
189  if ( m_entity ) { (*m_entity) += f ; }
190  return *this ;
191  }
205  Stat& operator++ ()
206  {
207  if ( m_entity ) { ++(*m_entity) ; }
208  return *this ;
209  }
222  Stat& operator++ (int)
223  {
224  if ( m_entity ) { (*m_entity)++ ; }
225  return *this ;
226  }
232  Stat& operator-= ( const double f )
233  {
234  if ( m_entity ) { (*m_entity) -= f ; }
235  return *this ;
236  }
238  Stat& operator-- ()
239  {
240  if ( m_entity ) { --(*m_entity) ; }
241  return *this ;
242  }
244  Stat& operator-- (int)
245  {
246  if ( m_entity ) { (*m_entity)-- ; }
247  return *this ;
248  }
250  Stat& operator+=( const StatEntity& right )
251  {
252  if ( m_entity ) { (*m_entity) += right ; }
253  return *this ;
254  }
256  Stat& operator+=( const Stat& right )
257  {
258  if ( 0 != right.entity() ) { (*this) += *right.entity() ; }
259  return *this ;
260  }
261  // ==========================================================================
263  std::string toString() const ;
268  std::ostream& print( std::ostream& o = std::cout ) const ;
273  std::ostream& fillStream ( std::ostream& o ) const { return print ( o ) ; }
274  // ==========================================================================
276  StatEntity* counter () const { return m_entity ; }
278  const std::string& name () const { return m_tag ; }
280  const std::string& group () const { return m_group ; }
281  // ==========================================================================
282 private:
283  // underlying counter
284  StatEntity* m_entity = nullptr ;
285  // unique stat tag(name)
286  std::string m_tag ;
287  // group (for ICounterSvc)
288  std::string m_group ;
289  // Stat service
290  SmartIF<IStatSvc> m_stat ;
291  // Counter Svc
292  SmartIF<ICounterSvc> m_counter ;
293 };
294 // ============================================================================
296 GAUDI_API Stat operator+( const Stat& stat , const double value ) ;
297 // ============================================================================
299 GAUDI_API Stat operator-( const Stat& stat , const double value ) ;
300 // ============================================================================
302 GAUDI_API Stat operator+( const double value , const Stat& stat ) ;
303 // ============================================================================
305 GAUDI_API Stat operator+( const Stat& stat , const Stat& value ) ;
306 // ============================================================================
308 GAUDI_API std::ostream& operator<<( std::ostream& stream , const Stat& stat ) ;
309 // ============================================================================
310 
311 // ============================================================================
312 // The END
313 // ============================================================================
314 #endif // __GAUDI_CHRONOSTATSVC_STAT_H__
315 // ============================================================================
316 
GAUDI_API std::ostream & operator<<(std::ostream &stream, const Stat &stat)
external printout operator to std::ostream
Definition: Stat.cpp:181
#define GAUDI_API
Definition: Kernel.h:107
Small wrapper class for easy manipulation with generic counters and IStatSvc&ICounterSvc interface...
Definition: Stat.h:46
Create / access multi purpose counters.
Definition: ICounterSvc.h:75
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:371
GAUDI_API Stat operator+(const Stat &stat, const double value)
external operator for addition of Stat and a number
Definition: Stat.cpp:163
GAUDI_API Stat operator-(const Stat &stat, const double value)
external operator for subtraction of Stat and a number
Definition: Stat.cpp:168
const StatEntity * entity() const
get the entity
Definition: Stat.h:163
bool operator!(const Gaudi::Time &t)
Definition: Time.icpp:248
void print(string text)
Definition: mergesort.cpp:33
"Stat"-related part of interface IChronoStatSvc
Definition: IStatSvc.h:25
The basic counter used for Monitoring purposes.
Definition: StatEntity.h:64