The Gaudi Framework  v29r0 (ff2e7097)
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 // ============================================================================
13 #include "GaudiKernel/IStatSvc.h"
14 #include "GaudiKernel/SmartIF.h"
15 #include "GaudiKernel/StatEntity.h"
16 // ============================================================================
47 {
48 public:
65  Stat( StatEntity* entity = 0, const std::string& name = "", const std::string& group = "" )
66  : m_entity( entity ), m_tag( name ), m_group( group ), m_counter( 0 )
67  {
68  }
83  Stat( StatEntity& entity, const std::string& name = "", const std::string& group = "" )
84  : m_entity( &entity ), m_tag( name ), m_group( group ), m_counter( 0 )
85  {
86  }
105  Stat( IStatSvc* svc, const std::string& tag );
123  Stat( IStatSvc* svc, const std::string& tag, const double flag );
141  Stat( ICounterSvc* svc, const std::string& group, const std::string& name );
143  Stat( const Stat& ) = default;
145  Stat& operator=( const Stat& ) = default;
147  ~Stat() = default;
148  // ==========================================================================
150  const StatEntity* entity() const { return m_entity; }
152  const StatEntity* operator->() const { return entity(); }
154  operator const StatEntity&() const { return *entity(); }
156  bool operator!() const { return 0 == m_entity; }
157  // ==========================================================================
174  Stat& operator+=( const double f )
175  {
176  if ( m_entity ) {
177  ( *m_entity ) += f;
178  }
179  return *this;
180  }
195  {
196  if ( m_entity ) {
197  ++( *m_entity );
198  }
199  return *this;
200  }
213  Stat& operator++( int )
214  {
215  if ( m_entity ) {
216  ( *m_entity )++;
217  }
218  return *this;
219  }
225  Stat& operator-=( const double f )
226  {
227  if ( m_entity ) {
228  ( *m_entity ) -= f;
229  }
230  return *this;
231  }
234  {
235  if ( m_entity ) {
236  --( *m_entity );
237  }
238  return *this;
239  }
241  Stat& operator--( int )
242  {
243  if ( m_entity ) {
244  ( *m_entity )--;
245  }
246  return *this;
247  }
249  Stat& operator+=( const StatEntity& right )
250  {
251  if ( m_entity ) {
252  ( *m_entity ) += right;
253  }
254  return *this;
255  }
257  Stat& operator+=( const Stat& right )
258  {
259  if ( 0 != right.entity() ) {
260  ( *this ) += *right.entity();
261  }
262  return *this;
263  }
264  // ==========================================================================
266  std::string toString() const;
271  std::ostream& print( std::ostream& o = std::cout ) const;
276  std::ostream& fillStream( std::ostream& o ) const { return print( o ); }
277  // ==========================================================================
279  StatEntity* counter() const { return m_entity; }
281  const std::string& name() const { return m_tag; }
283  const std::string& group() const { return m_group; }
284  // ==========================================================================
285 private:
286  // underlying counter
287  StatEntity* m_entity = nullptr;
288  // unique stat tag(name)
290  // group (for ICounterSvc)
292  // Stat service
294  // Counter Svc
296 };
297 // ============================================================================
299 GAUDI_API Stat operator+( const Stat& stat, const double value );
300 // ============================================================================
302 GAUDI_API Stat operator-( const Stat& stat, const double value );
303 // ============================================================================
305 GAUDI_API Stat operator+( const double value, const Stat& stat );
306 // ============================================================================
308 GAUDI_API Stat operator+( const Stat& stat, const Stat& value );
309 // ============================================================================
311 GAUDI_API std::ostream& operator<<( std::ostream& stream, const Stat& stat );
312 // ============================================================================
313 
314 // ============================================================================
315 // The END
316 // ============================================================================
317 #endif // __GAUDI_CHRONOSTATSVC_STAT_H__
318 // ============================================================================
Stat & operator-=(const double f)
General decrement operator for the counter.
Definition: Stat.h:225
bool operator!() const
check validity
Definition: Stat.h:156
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
SmartIF< IStatSvc > m_stat
Stat service.
Definition: Stat.h:293
StatEntity * counter() const
alternative access to underlying counter (for ICounterSvc::CounterObj)
Definition: Stat.h:279
const std::string & name() const
counter name
Definition: Stat.h:281
Stat & operator++(int)
Post-increment operator for the counter.
Definition: Stat.h:213
std::ostream & fillStream(std::ostream &o) const
printout to std::ostream
Definition: Stat.h:276
Stat & operator++()
Pre-increment operator for the counter.
Definition: Stat.h:194
Stat & operator+=(const double f)
General increment for the counter.
Definition: Stat.h:174
GAUDI_API std::ostream & operator<<(std::ostream &stream, const Stat &stat)
external printout operator to std::ostream
Definition: Stat.cpp:175
PropertyMgr & operator=(const PropertyMgr &)=delete
STL class.
Stat & operator--()
Pre-decrement operator for the flag.
Definition: Stat.h:233
std::string m_tag
unique stat tag(name)
Definition: Stat.h:289
SmartIF< ICounterSvc > m_counter
Counter Service.
Definition: Stat.h:295
Stat(StatEntity *entity=0, const std::string &name="", const std::string &group="")
constructor from StatEntity, name and group :
Definition: Stat.h:65
std::string m_group
Definition: Stat.h:291
Stat & operator--(int)
Post-decrement operator for the flag.
Definition: Stat.h:241
Stat(StatEntity &entity, const std::string &name="", const std::string &group="")
constructor from StatEntity, name and group :
Definition: Stat.h:83
const StatEntity * operator->() const
dereference operaqtor
Definition: Stat.h:152
const StatEntity * entity() const
get the entity
Definition: Stat.h:150
Stat & operator+=(const StatEntity &right)
increment with StatEntity object
Definition: Stat.h:249
void print(string text)
Definition: mergesort.cpp:30
GAUDI_API Stat operator+(const Stat &stat, const double value)
external operator for addition of Stat and a number
Definition: Stat.cpp:141
GAUDI_API Stat operator-(const Stat &stat, const double value)
external operator for subtraction of Stat and a number
Definition: Stat.cpp:150
"Stat"-related part of interface IChronoStatSvc
Definition: IStatSvc.h:25
The basic counter used for Monitoring purposes.
Definition: StatEntity.h:65
Stat & operator+=(const Stat &right)
increment with other stat objects
Definition: Stat.h:257
#define GAUDI_API
Definition: Kernel.h:110
STL class.
std::string toString(const Type &)
const std::string & group() const
counter group (for ICounterSvc)
Definition: Stat.h:283