All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Stat.h
Go to the documentation of this file.
1 // $Id: Stat.h,v 1.6 2008/04/04 18:32:39 marcocle Exp $
2 // ============================================================================
3 #ifndef __GAUDI_CHRONOSTATSVC_STAT_H__
4 #define __GAUDI_CHRONOSTATSVC_STAT_H__
5 // ============================================================================
6 // Iinclude files
7 // ============================================================================
8 // STD & STL
9 // ============================================================================
10 #include <string>
11 // ============================================================================
12 // GaudiKernel
13 // ============================================================================
14 #include "GaudiKernel/StatEntity.h"
15 // ============================================================================
16 // forward declarations
17 // ============================================================================
18 class IStatSvc ;
19 class ICounterSvc ;
20 // ============================================================================
51 {
52 public:
69  Stat ( StatEntity* entity = 0 ,
70  const std::string& name = "" ,
71  const std::string& group = "" )
72  : m_entity ( entity )
73  , m_tag ( name )
74  , m_group ( group )
75  , m_stat ( 0 )
76  , m_counter ( 0 )
77  {}
92  Stat ( StatEntity& entity ,
93  const std::string& name = "" ,
94  const std::string& group = "" )
95  : m_entity ( &entity )
96  , m_tag ( name )
97  , m_group ( group )
98  , m_stat ( 0 )
99  , m_counter ( 0 )
100  {}
119  Stat ( IStatSvc* svc ,
120  const std::string& tag ) ;
138  Stat ( IStatSvc* svc ,
139  const std::string& tag ,
140  const double flag ) ;
158  Stat ( ICounterSvc* svc ,
159  const std::string& group ,
160  const std::string& name ) ;
162  Stat ( const Stat& right ) ;
164  Stat& operator=( const Stat& right) ;
166  ~Stat() ;
167  // ==========================================================================
169  const StatEntity* entity () const { return m_entity ; }
171  const StatEntity* operator->() const { return entity() ; }
173  operator const StatEntity& () const { return *entity() ; }
175  bool operator!() const { return 0 == m_entity ; }
176  // ==========================================================================
193  Stat& operator+= ( const double f )
194  {
195  if ( 0 != m_entity ) { (*m_entity) += f ; }
196  return *this ;
197  }
211  Stat& operator++ ()
212  {
213  if ( 0 != m_entity ) { ++(*m_entity) ; }
214  return *this ;
215  }
228  Stat& operator++ (int)
229  {
230  if ( 0 != m_entity ) { (*m_entity)++ ; }
231  return *this ;
232  }
238  Stat& operator-= ( const double f )
239  {
240  if ( 0 != m_entity ) { (*m_entity) -= f ; }
241  return *this ;
242  }
244  Stat& operator-- ()
245  {
246  if ( 0 != m_entity ) { --(*m_entity) ; }
247  return *this ;
248  }
250  Stat& operator-- (int)
251  {
252  if ( 0 != m_entity ) { (*m_entity)-- ; }
253  return *this ;
254  }
256  Stat& operator+=( const StatEntity& right )
257  {
258  if ( 0 != m_entity ) { (*m_entity) += right ; }
259  return *this ;
260  }
262  Stat& operator+=( const Stat& right )
263  {
264  if ( 0 != right.entity() ) { (*this) += *right.entity() ; }
265  return *this ;
266  }
267  // ==========================================================================
269  std::string toString() const ;
274  std::ostream& print( std::ostream& o = std::cout ) const ;
279  std::ostream& fillStream ( std::ostream& o ) const { return print ( o ) ; }
280  // ==========================================================================
282  StatEntity* counter () const { return m_entity ; }
284  const std::string& name () const { return m_tag ; }
286  const std::string& group () const { return m_group ; }
287  // ==========================================================================
288 private:
289  // underlying counter
291  // unique stat tag(name)
292  std::string m_tag ;
293  // group (for ICounterSvc)
294  std::string m_group ;
295  // Stat service
297  // Counter Svc
299 };
300 // ============================================================================
302 GAUDI_API Stat operator+( const Stat& stat , const double value ) ;
303 // ============================================================================
305 GAUDI_API Stat operator-( const Stat& stat , const double value ) ;
306 // ============================================================================
308 GAUDI_API Stat operator+( const double value , const Stat& stat ) ;
309 // ============================================================================
311 GAUDI_API Stat operator+( const Stat& stat , const Stat& value ) ;
312 // ============================================================================
314 GAUDI_API std::ostream& operator<<( std::ostream& stream , const Stat& stat ) ;
315 // ============================================================================
316 
317 // ============================================================================
318 // The END
319 // ============================================================================
320 #endif // __GAUDI_CHRONOSTATSVC_STAT_H__
321 // ============================================================================
322 
bool operator!() const
check validity
Definition: Stat.h:175
Small wrapper class for easy manipulation with generic counters and IStatSvc&ICounterSvc interface...
Definition: Stat.h:50
Create / access multi purpose counters.
Definition: ICounterSvc.h:78
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:367
StatEntity * counter() const
alternative access to underlying counter (for ICounterSvc::CounterObj)
Definition: Stat.h:282
StatEntity * m_entity
underlying counter
Definition: Stat.h:290
const std::string & name() const
counter name
Definition: Stat.h:284
std::ostream & fillStream(std::ostream &o) const
printout to std::ostream
Definition: Stat.h:279
ICounterSvc * m_counter
Counter Service.
Definition: Stat.h:298
GAUDI_API std::ostream & operator<<(std::ostream &stream, const Stat &stat)
external printout operator to std::ostream
Definition: Stat.cpp:235
std::string m_tag
unique stat tag(name)
Definition: Stat.h:292
Stat(StatEntity *entity=0, const std::string &name="", const std::string &group="")
constructor from StatEntity, name and group :
Definition: Stat.h:69
std::string m_group
Definition: Stat.h:294
IStatSvc * m_stat
Stat service.
Definition: Stat.h:296
Stat(StatEntity &entity, const std::string &name="", const std::string &group="")
constructor from StatEntity, name and group :
Definition: Stat.h:92
const StatEntity * operator->() const
dereference operaqtor
Definition: Stat.h:171
const StatEntity * entity() const
get the entity
Definition: Stat.h:169
Stat & operator+=(const StatEntity &right)
increment with StatEntity object
Definition: Stat.h:256
GAUDI_API Stat operator+(const Stat &stat, const double value)
external operator for addition of Stat and a number
Definition: Stat.cpp:217
GAUDI_API Stat operator-(const Stat &stat, const double value)
external operator for subtraction of Stat and a number
Definition: Stat.cpp:222
"Stat"-related part of interface IChronoStatSvc
Definition: IStatSvc.h:27
The basic counter used for Monitoring purposes.
Definition: StatEntity.h:68
Stat & operator+=(const Stat &right)
increment with other stat objects
Definition: Stat.h:262
#define GAUDI_API
Definition: Kernel.h:108
const std::string & group() const
counter group (for ICounterSvc)
Definition: Stat.h:286