The Gaudi Framework  v30r2 (9eca68f7)
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/IStatSvc.h"
13 #include "GaudiKernel/SmartIF.h"
14 #include "GaudiKernel/StatEntity.h"
15 // ============================================================================
46 {
47 public:
64  Stat( StatEntity* entity = 0, const std::string& name = "", const std::string& group = "" )
65  : m_entity( entity ), m_tag( name ), m_group( group )
66  {
67  }
82  Stat( StatEntity& entity, const std::string& name = "", const std::string& group = "" )
83  : m_entity( &entity ), m_tag( name ), m_group( group )
84  {
85  }
104  Stat( IStatSvc* svc, const std::string& tag );
122  Stat( IStatSvc* svc, const std::string& tag, const double flag );
124  Stat( const Stat& ) = default;
126  Stat& operator=( const Stat& ) = default;
128  ~Stat() = default;
129  // ==========================================================================
131  const StatEntity* entity() const { return m_entity; }
133  const StatEntity* operator->() const { return entity(); }
135  operator const StatEntity&() const { return *entity(); }
137  bool operator!() const { return 0 == m_entity; }
138  // ==========================================================================
155  Stat& operator+=( const double f )
156  {
157  if ( m_entity ) {
158  ( *m_entity ) += f;
159  }
160  return *this;
161  }
176  {
177  if ( m_entity ) {
178  ++( *m_entity );
179  }
180  return *this;
181  }
194  Stat& operator++( int )
195  {
196  if ( m_entity ) {
197  ( *m_entity )++;
198  }
199  return *this;
200  }
206  Stat& operator-=( const double f )
207  {
208  if ( m_entity ) {
209  ( *m_entity ) -= f;
210  }
211  return *this;
212  }
215  {
216  if ( m_entity ) {
217  --( *m_entity );
218  }
219  return *this;
220  }
222  Stat& operator--( int )
223  {
224  if ( m_entity ) {
225  ( *m_entity )--;
226  }
227  return *this;
228  }
230  Stat& operator+=( const StatEntity& right )
231  {
232  if ( m_entity ) {
233  ( *m_entity ) += right;
234  }
235  return *this;
236  }
238  Stat& operator+=( const Stat& right )
239  {
240  if ( 0 != right.entity() ) {
241  ( *this ) += *right.entity();
242  }
243  return *this;
244  }
245  // ==========================================================================
247  std::string toString() const;
252  std::ostream& print( std::ostream& o = std::cout ) const;
257  std::ostream& fillStream( std::ostream& o ) const { return print( o ); }
258  // ==========================================================================
260  StatEntity* counter() const { return m_entity; }
262  const std::string& name() const { return m_tag; }
264  const std::string& group() const { return m_group; }
265  // ==========================================================================
266 private:
267  // underlying counter
268  StatEntity* m_entity = nullptr;
269  // unique stat tag(name)
271  // group
273  // Stat service
275 };
276 // ============================================================================
278 GAUDI_API Stat operator+( const Stat& stat, const double value );
279 // ============================================================================
281 GAUDI_API Stat operator-( const Stat& stat, const double value );
282 // ============================================================================
284 GAUDI_API Stat operator+( const double value, const Stat& stat );
285 // ============================================================================
287 GAUDI_API Stat operator+( const Stat& stat, const Stat& value );
288 // ============================================================================
290 GAUDI_API std::ostream& operator<<( std::ostream& stream, const Stat& stat );
291 // ============================================================================
292 
293 // ============================================================================
294 // The END
295 // ============================================================================
296 #endif // __GAUDI_CHRONOSTATSVC_STAT_H__
297 // ============================================================================
Stat & operator-=(const double f)
General decrement operator for the counter.
Definition: Stat.h:206
bool operator!() const
check validity
Definition: Stat.h:137
Small wrapper class for easy manipulation with generic counters and IStatSvc interface.
Definition: Stat.h:45
SmartIF< IStatSvc > m_stat
Stat service.
Definition: Stat.h:274
StatEntity * counter() const
alternative access to underlying counter
Definition: Stat.h:260
const std::string & name() const
counter name
Definition: Stat.h:262
Stat & operator++(int)
Post-increment operator for the counter.
Definition: Stat.h:194
std::ostream & fillStream(std::ostream &o) const
printout to std::ostream
Definition: Stat.h:257
Stat & operator++()
Pre-increment operator for the counter.
Definition: Stat.h:175
Stat & operator+=(const double f)
General increment for the counter.
Definition: Stat.h:155
GAUDI_API std::ostream & operator<<(std::ostream &stream, const Stat &stat)
external printout operator to std::ostream
Definition: Stat.cpp:153
PropertyMgr & operator=(const PropertyMgr &)=delete
STL class.
Stat & operator--()
Pre-decrement operator for the flag.
Definition: Stat.h:214
std::string m_tag
unique stat tag(name)
Definition: Stat.h:270
Stat(StatEntity *entity=0, const std::string &name="", const std::string &group="")
constructor from StatEntity, name and group :
Definition: Stat.h:64
std::string m_group
Definition: Stat.h:272
Stat & operator--(int)
Post-decrement operator for the flag.
Definition: Stat.h:222
Stat(StatEntity &entity, const std::string &name="", const std::string &group="")
constructor from StatEntity, name and group :
Definition: Stat.h:82
const StatEntity * operator->() const
dereference operaqtor
Definition: Stat.h:133
const StatEntity * entity() const
get the entity
Definition: Stat.h:131
Stat & operator+=(const StatEntity &right)
increment with StatEntity object
Definition: Stat.h:230
GAUDI_API Stat operator+(const Stat &stat, const double value)
external operator for addition of Stat and a number
Definition: Stat.cpp:119
GAUDI_API Stat operator-(const Stat &stat, const double value)
external operator for subtraction of Stat and a number
Definition: Stat.cpp:128
"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:238
#define GAUDI_API
Definition: Kernel.h:110
STL class.
std::string toString(const Type &)
const std::string & group() const
counter group
Definition: Stat.h:264