Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 <iostream>
9 #include <string>
10 // ============================================================================
11 // GaudiKernel
12 // ============================================================================
13 #include "GaudiKernel/IStatSvc.h"
14 #include "GaudiKernel/SmartIF.h"
15 #include "GaudiKernel/StatEntity.h"
16 // ============================================================================
46 class GAUDI_API Stat {
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 ) {}
80  Stat( StatEntity& entity, const std::string& name = "", const std::string& group = "" )
81  : m_entity( &entity ), m_tag( name ), m_group( group ) {}
100  Stat( IStatSvc* svc, const std::string& tag );
118  Stat( IStatSvc* svc, const std::string& tag, const double flag );
120  Stat( const Stat& ) = default;
122  Stat& operator=( const Stat& ) = default;
124  ~Stat() = default;
125  // ==========================================================================
127  const StatEntity* entity() const { return m_entity; }
129  const StatEntity* operator->() const { return entity(); }
131  operator const StatEntity&() const { return *entity(); }
133  bool operator!() const { return 0 == m_entity; }
134  // ==========================================================================
151  Stat& operator+=( const double f ) {
152  if ( m_entity ) { ( *m_entity ) += f; }
153  return *this;
154  }
169  if ( m_entity ) { ++( *m_entity ); }
170  return *this;
171  }
184  Stat& operator++( int ) {
185  if ( m_entity ) { ( *m_entity )++; }
186  return *this;
187  }
193  Stat& operator-=( const double f ) {
194  if ( m_entity ) { ( *m_entity ) -= f; }
195  return *this;
196  }
199  if ( m_entity ) { --( *m_entity ); }
200  return *this;
201  }
203  Stat& operator--( int ) {
204  if ( m_entity ) { ( *m_entity )--; }
205  return *this;
206  }
208  Stat& operator+=( const StatEntity& right ) {
209  if ( m_entity ) { ( *m_entity ) += right; }
210  return *this;
211  }
213  Stat& operator+=( const Stat& right ) {
214  if ( 0 != right.entity() ) { ( *this ) += *right.entity(); }
215  return *this;
216  }
217  // ==========================================================================
219  std::string toString() const;
224  std::ostream& print( std::ostream& o = std::cout ) const;
229  std::ostream& fillStream( std::ostream& o ) const { return print( o ); }
230  // ==========================================================================
232  StatEntity* counter() const { return m_entity; }
234  const std::string& name() const { return m_tag; }
236  const std::string& group() const { return m_group; }
237  // ==========================================================================
238 private:
239  // underlying counter
240  StatEntity* m_entity = nullptr;
241  // unique stat tag(name)
243  // group
245  // Stat service
247 };
248 // ============================================================================
250 GAUDI_API Stat operator+( const Stat& stat, const double value );
251 // ============================================================================
253 GAUDI_API Stat operator-( const Stat& stat, const double value );
254 // ============================================================================
256 GAUDI_API Stat operator+( const double value, const Stat& stat );
257 // ============================================================================
259 GAUDI_API Stat operator+( const Stat& stat, const Stat& value );
260 // ============================================================================
262 GAUDI_API std::ostream& operator<<( std::ostream& stream, const Stat& stat );
263 // ============================================================================
264 
265 // ============================================================================
266 // The END
267 // ============================================================================
268 #endif // __GAUDI_CHRONOSTATSVC_STAT_H__
Stat & operator-=(const double f)
General decrement operator for the counter.
Definition: Stat.h:193
bool operator!() const
check validity
Definition: Stat.h:133
Small wrapper class for easy manipulation with generic counters and IStatSvc interface.
Definition: Stat.h:46
SmartIF< IStatSvc > m_stat
Stat service.
Definition: Stat.h:246
StatEntity * counter() const
alternative access to underlying counter
Definition: Stat.h:232
const std::string & name() const
counter name
Definition: Stat.h:234
Stat & operator++(int)
Post-increment operator for the counter.
Definition: Stat.h:184
std::ostream & fillStream(std::ostream &o) const
printout to std::ostream
Definition: Stat.h:229
Stat & operator++()
Pre-increment operator for the counter.
Definition: Stat.h:168
Stat & operator+=(const double f)
General increment for the counter.
Definition: Stat.h:151
GAUDI_API std::ostream & operator<<(std::ostream &stream, const Stat &stat)
external printout operator to std::ostream
Definition: Stat.cpp:140
PropertyMgr & operator=(const PropertyMgr &)=delete
STL class.
Stat & operator--()
Pre-decrement operator for the flag.
Definition: Stat.h:198
std::string m_tag
unique stat tag(name)
Definition: Stat.h:242
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:244
Stat & operator--(int)
Post-decrement operator for the flag.
Definition: Stat.h:203
Stat(StatEntity &entity, const std::string &name="", const std::string &group="")
constructor from StatEntity, name and group :
Definition: Stat.h:80
const StatEntity * operator->() const
dereference operaqtor
Definition: Stat.h:129
const StatEntity * entity() const
get the entity
Definition: Stat.h:127
Stat & operator+=(const StatEntity &right)
increment with StatEntity object
Definition: Stat.h:208
GAUDI_API Stat operator+(const Stat &stat, const double value)
external operator for addition of Stat and a number
Definition: Stat.cpp:110
GAUDI_API Stat operator-(const Stat &stat, const double value)
external operator for subtraction of Stat and a number
Definition: Stat.cpp:118
"Stat"-related part of interface IChronoStatSvc
Definition: IStatSvc.h:25
backward compatible StatEntity class.
Definition: Counters.h:837
Stat & operator+=(const Stat &right)
increment with other stat objects
Definition: Stat.h:213
#define GAUDI_API
Definition: Kernel.h:71
STL class.
std::string toString(const Type &)
const std::string & group() const
counter group
Definition: Stat.h:236