![]() |
|
|
Generated: 24 Nov 2008 |
00001 // $Id: Stat.h,v 1.6 2008/04/04 18:32:39 marcocle Exp $ 00002 // ============================================================================ 00003 #ifndef __GAUDI_CHRONOSTATSVC_STAT_H__ 00004 #define __GAUDI_CHRONOSTATSVC_STAT_H__ 00005 // ============================================================================ 00006 // Iinclude files 00007 // ============================================================================ 00008 // STD & STL 00009 // ============================================================================ 00010 #include <string> 00011 // ============================================================================ 00012 // GaudiKernel 00013 // ============================================================================ 00014 #include "GaudiKernel/StatEntity.h" 00015 // ============================================================================ 00016 // forward declarations 00017 // ============================================================================ 00018 class IStatSvc ; 00019 class ICounterSvc ; 00020 // ============================================================================ 00050 class Stat 00051 { 00052 public: 00069 Stat ( StatEntity* entity = 0 , 00070 const std::string& name = "" , 00071 const std::string& group = "" ) 00072 : m_entity ( entity ) 00073 , m_tag ( name ) 00074 , m_group ( group ) 00075 , m_stat ( 0 ) 00076 , m_counter ( 0 ) 00077 {} 00092 Stat ( StatEntity& entity , 00093 const std::string& name = "" , 00094 const std::string& group = "" ) 00095 : m_entity ( &entity ) 00096 , m_tag ( name ) 00097 , m_group ( group ) 00098 , m_stat ( 0 ) 00099 , m_counter ( 0 ) 00100 {} 00119 Stat ( IStatSvc* svc , 00120 const std::string& tag ) ; 00138 Stat ( IStatSvc* svc , 00139 const std::string& tag , 00140 const double flag ) ; 00158 Stat ( ICounterSvc* svc , 00159 const std::string& group , 00160 const std::string& name ) ; 00162 Stat ( const Stat& right ) ; 00164 Stat& operator=( const Stat& right) ; 00166 ~Stat() ; 00167 // ========================================================================== 00169 const StatEntity* entity () const { return m_entity ; } 00171 const StatEntity* operator->() const { return entity() ; } 00173 operator const StatEntity& () const { return *entity() ; } 00175 bool operator!() const { return 0 == m_entity ; } 00176 // ========================================================================== 00193 Stat& operator+= ( const double f ) 00194 { 00195 if ( 0 != m_entity ) { (*m_entity) += f ; } 00196 return *this ; 00197 } 00211 Stat& operator++ () 00212 { 00213 if ( 0 != m_entity ) { ++(*m_entity) ; } 00214 return *this ; 00215 } 00228 Stat& operator++ (int) 00229 { 00230 if ( 0 != m_entity ) { (*m_entity)++ ; } 00231 return *this ; 00232 } 00238 Stat& operator-= ( const double f ) 00239 { 00240 if ( 0 != m_entity ) { (*m_entity) -= f ; } 00241 return *this ; 00242 } 00244 Stat& operator-- () 00245 { 00246 if ( 0 != m_entity ) { --(*m_entity) ; } 00247 return *this ; 00248 } 00250 Stat& operator-- (int) 00251 { 00252 if ( 0 != m_entity ) { (*m_entity)-- ; } 00253 return *this ; 00254 } 00256 Stat& operator+=( const StatEntity& right ) 00257 { 00258 if ( 0 != m_entity ) { (*m_entity) += right ; } 00259 return *this ; 00260 } 00262 Stat& operator+=( const Stat& right ) 00263 { 00264 if ( 0 != right.entity() ) { (*this) += *right.entity() ; } 00265 return *this ; 00266 } 00267 // ========================================================================== 00269 std::string toString() const ; 00274 std::ostream& print( std::ostream& o = std::cout ) const ; 00279 std::ostream& fillStream ( std::ostream& o ) const { return print ( o ) ; } 00280 // ========================================================================== 00282 StatEntity* counter () const { return m_entity ; } 00284 const std::string& name () const { return m_tag ; } 00286 const std::string& group () const { return m_group ; } 00287 // ========================================================================== 00288 private: 00289 // underlying counter 00290 StatEntity* m_entity ; 00291 // unique stat tag(name) 00292 std::string m_tag ; 00293 // group (for ICounterSvc) 00294 std::string m_group ; 00295 // Stat service 00296 IStatSvc* m_stat ; 00297 // Counter Svc 00298 ICounterSvc* m_counter ; 00299 }; 00300 // ============================================================================ 00302 Stat operator+( const Stat& stat , const double value ) ; 00303 // ============================================================================ 00305 Stat operator-( const Stat& stat , const double value ) ; 00306 // ============================================================================ 00308 Stat operator+( const double value , const Stat& stat ) ; 00309 // ============================================================================ 00311 Stat operator+( const Stat& stat , const Stat& value ) ; 00312 // ============================================================================ 00314 std::ostream& operator<<( std::ostream& stream , const Stat& stat ) ; 00315 // ============================================================================ 00316 00317 // ============================================================================ 00318 // The END 00319 // ============================================================================ 00320 #endif // __GAUDI_CHRONOSTATSVC_STAT_H__ 00321 // ============================================================================ 00322