The Gaudi Framework  v30r3 (a5ef0a68)
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 // ============================================================================
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 )
67  {
68  }
83  Stat( StatEntity& entity, const std::string& name = "", const std::string& group = "" )
84  : m_entity( &entity ), m_tag( name ), m_group( group )
85  {
86  }
105  Stat( IStatSvc* svc, const std::string& tag );
123  Stat( IStatSvc* svc, const std::string& tag, const double flag );
125  Stat( const Stat& ) = default;
127  Stat& operator=( const Stat& ) = default;
129  ~Stat() = default;
130  // ==========================================================================
132  const StatEntity* entity() const { return m_entity; }
134  const StatEntity* operator->() const { return entity(); }
136  operator const StatEntity&() const { return *entity(); }
138  bool operator!() const { return 0 == m_entity; }
139  // ==========================================================================
156  Stat& operator+=( const double f )
157  {
158  if ( m_entity ) {
159  ( *m_entity ) += f;
160  }
161  return *this;
162  }
177  {
178  if ( m_entity ) {
179  ++( *m_entity );
180  }
181  return *this;
182  }
195  Stat& operator++( int )
196  {
197  if ( m_entity ) {
198  ( *m_entity )++;
199  }
200  return *this;
201  }
207  Stat& operator-=( const double f )
208  {
209  if ( m_entity ) {
210  ( *m_entity ) -= f;
211  }
212  return *this;
213  }
216  {
217  if ( m_entity ) {
218  --( *m_entity );
219  }
220  return *this;
221  }
223  Stat& operator--( int )
224  {
225  if ( m_entity ) {
226  ( *m_entity )--;
227  }
228  return *this;
229  }
231  Stat& operator+=( const StatEntity& right )
232  {
233  if ( m_entity ) {
234  ( *m_entity ) += right;
235  }
236  return *this;
237  }
239  Stat& operator+=( const Stat& right )
240  {
241  if ( 0 != right.entity() ) {
242  ( *this ) += *right.entity();
243  }
244  return *this;
245  }
246  // ==========================================================================
248  std::string toString() const;
253  std::ostream& print( std::ostream& o = std::cout ) const;
258  std::ostream& fillStream( std::ostream& o ) const { return print( o ); }
259  // ==========================================================================
261  StatEntity* counter() const { return m_entity; }
263  const std::string& name() const { return m_tag; }
265  const std::string& group() const { return m_group; }
266  // ==========================================================================
267 private:
268  // underlying counter
269  StatEntity* m_entity = nullptr;
270  // unique stat tag(name)
272  // group
274  // Stat service
276 };
277 // ============================================================================
279 GAUDI_API Stat operator+( const Stat& stat, const double value );
280 // ============================================================================
282 GAUDI_API Stat operator-( const Stat& stat, const double value );
283 // ============================================================================
285 GAUDI_API Stat operator+( const double value, const Stat& stat );
286 // ============================================================================
288 GAUDI_API Stat operator+( const Stat& stat, const Stat& value );
289 // ============================================================================
291 GAUDI_API std::ostream& operator<<( std::ostream& stream, const Stat& stat );
292 // ============================================================================
293 
294 // ============================================================================
295 // The END
296 // ============================================================================
297 #endif // __GAUDI_CHRONOSTATSVC_STAT_H__
298 // ============================================================================
Stat & operator-=(const double f)
General decrement operator for the counter.
Definition: Stat.h:207
bool operator!() const
check validity
Definition: Stat.h:138
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:275
StatEntity * counter() const
alternative access to underlying counter
Definition: Stat.h:261
const std::string & name() const
counter name
Definition: Stat.h:263
Stat & operator++(int)
Post-increment operator for the counter.
Definition: Stat.h:195
std::ostream & fillStream(std::ostream &o) const
printout to std::ostream
Definition: Stat.h:258
Stat & operator++()
Pre-increment operator for the counter.
Definition: Stat.h:176
Stat & operator+=(const double f)
General increment for the counter.
Definition: Stat.h:156
GAUDI_API std::ostream & operator<<(std::ostream &stream, const Stat &stat)
external printout operator to std::ostream
Definition: Stat.cpp:152
PropertyMgr & operator=(const PropertyMgr &)=delete
STL class.
Stat & operator--()
Pre-decrement operator for the flag.
Definition: Stat.h:215
std::string m_tag
unique stat tag(name)
Definition: Stat.h:271
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:273
Stat & operator--(int)
Post-decrement operator for the flag.
Definition: Stat.h:223
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:134
const StatEntity * entity() const
get the entity
Definition: Stat.h:132
Stat & operator+=(const StatEntity &right)
increment with StatEntity object
Definition: Stat.h:231
GAUDI_API Stat operator+(const Stat &stat, const double value)
external operator for addition of Stat and a number
Definition: Stat.cpp:118
GAUDI_API Stat operator-(const Stat &stat, const double value)
external operator for subtraction of Stat and a number
Definition: Stat.cpp:127
"Stat"-related part of interface IChronoStatSvc
Definition: IStatSvc.h:25
backward compatible StatEntity class.
Definition: Counters.h:777
Stat & operator+=(const Stat &right)
increment with other stat objects
Definition: Stat.h:239
#define GAUDI_API
Definition: Kernel.h:104
STL class.
std::string toString(const Type &)
const std::string & group() const
counter group
Definition: Stat.h:265