Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v29r0 (ff2e7097)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Stat Class Reference

Small wrapper class for easy manipulation with generic counters and IStatSvc&ICounterSvc interface. More...

#include <GaudiKernel/Stat.h>

Collaboration diagram for Stat:

Public Member Functions

 Stat (StatEntity *entity=0, const std::string &name="", const std::string &group="")
 constructor from StatEntity, name and group : More...
 
 Stat (StatEntity &entity, const std::string &name="", const std::string &group="")
 constructor from StatEntity, name and group : More...
 
 Stat (IStatSvc *svc, const std::string &tag)
 constructor from IStatSvc, tag and value More...
 
 Stat (IStatSvc *svc, const std::string &tag, const double flag)
 constructor from IStatSvc, tag and value More...
 
 Stat (ICounterSvc *svc, const std::string &group, const std::string &name)
 constructor from ICounterSvc, group and name More...
 
 Stat (const Stat &)=default
 copy constructor More...
 
Statoperator= (const Stat &)=default
 Assignement operator. More...
 
 ~Stat ()=default
 destructor More...
 
const StatEntityentity () const
 get the entity More...
 
const StatEntityoperator-> () const
 dereference operaqtor More...
 
 operator const StatEntity & () const
 cast to StatEntity More...
 
bool operator! () const
 check validity More...
 
Statoperator+= (const double f)
 General increment for the counter. More...
 
Statoperator++ ()
 Pre-increment operator for the counter. More...
 
Statoperator++ (int)
 Post-increment operator for the counter. More...
 
Statoperator-= (const double f)
 General decrement operator for the counter. More...
 
Statoperator-- ()
 Pre-decrement operator for the flag. More...
 
Statoperator-- (int)
 Post-decrement operator for the flag. More...
 
Statoperator+= (const StatEntity &right)
 increment with StatEntity object More...
 
Statoperator+= (const Stat &right)
 increment with other stat objects More...
 
std::string toString () const
 representation as string More...
 
std::ostreamprint (std::ostream &o=std::cout) const
 printout to std::ostream More...
 
std::ostreamfillStream (std::ostream &o) const
 printout to std::ostream More...
 
StatEntitycounter () const
 alternative access to underlying counter (for ICounterSvc::CounterObj) More...
 
const std::stringname () const
 counter name More...
 
const std::stringgroup () const
 counter group (for ICounterSvc) More...
 

Private Attributes

StatEntitym_entity = nullptr
 underlying counter More...
 
std::string m_tag
 unique stat tag(name) More...
 
std::string m_group
 
SmartIF< IStatSvcm_stat
 Stat service. More...
 
SmartIF< ICounterSvcm_counter
 Counter Service. More...
 

Detailed Description

Small wrapper class for easy manipulation with generic counters and IStatSvc&ICounterSvc interface.

It acts as "smart pointer" fro StatEntity objects, and allows manipulation with StatEntity objects, owned by GaudiCommon<TYPE> base class and/or IStatSvc/ICounterSvc

long nTracks = ... ;
Stat stat( chronoSvc() , "#tracks" , nTracks ) ;

Alternatively one can use operator methods:

long nTracks = ... ;
Stat stat( chronoSvc() , "#tracks" ) ;
stat += nTracks ;
Author
Vanya BELYAEV Ivan..nosp@m.Bely.nosp@m.aev@l.nosp@m.app..nosp@m.in2p3.nosp@m..fr
Date
2007-08-02

Definition at line 46 of file Stat.h.

Constructor & Destructor Documentation

Stat::Stat ( StatEntity entity = 0,
const std::string name = "",
const std::string group = "" 
)
inline

constructor from StatEntity, name and group :

// make helper object:
Stat stat ( entity ) ;
See also
StatEntity
Parameters
entitypointer to entity object
name(optional) name of the object, for printout
group(optional) group of the object, for printout

Definition at line 65 of file Stat.h.

66  : m_entity( entity ), m_tag( name ), m_group( group ), m_counter( 0 )
67  {
68  }
StatEntity * m_entity
underlying counter
Definition: Stat.h:287
std::string m_tag
unique stat tag(name)
Definition: Stat.h:289
SmartIF< ICounterSvc > m_counter
Counter Service.
Definition: Stat.h:295
std::string m_group
Definition: Stat.h:291
Stat::Stat ( StatEntity entity,
const std::string name = "",
const std::string group = "" 
)
inline

constructor from StatEntity, name and group :

// make helper object:
Stat stat = Stat( countter("Name") , "Name" ) ;
See also
StatEntity
GaudiCommon::counter
Parameters
entityreference to entity object
name(optional) name of the object, for printout
group(optional) group of the object, for printout

Definition at line 83 of file Stat.h.

84  : m_entity( &entity ), m_tag( name ), m_group( group ), m_counter( 0 )
85  {
86  }
StatEntity * m_entity
underlying counter
Definition: Stat.h:287
std::string m_tag
unique stat tag(name)
Definition: Stat.h:289
SmartIF< ICounterSvc > m_counter
Counter Service.
Definition: Stat.h:295
std::string m_group
Definition: Stat.h:291
Stat::Stat ( IStatSvc svc,
const std::string tag 
)

constructor from IStatSvc, tag and value

IStatSvc* svc = ... ;
double eTotal = .... ;
// get/create the counter from Stat Service
Stat eTot ( svc , "total energy" ) ;
eTot += eTotal ;
See also
IStatSvc
Parameters
svcpointer to Chrono&Stat Service tag unique tag for the entry

Definition at line 43 of file Stat.cpp.

43  : m_tag( tag ), m_group(), m_stat( svc )
44 {
45  if ( m_stat ) {
46  // get from the service
47  const StatEntity* tmp = m_stat->stat( tag );
48  if ( !tmp ) {
49  // create if needed
50  m_stat->stat( tag, 0 );
51  tmp = m_stat->stat( tag );
52  StatEntity* aux = const_cast<StatEntity*>( tmp );
53  aux->reset();
54  }
55  m_entity = const_cast<StatEntity*>( tmp );
56  }
57 }
SmartIF< IStatSvc > m_stat
Stat service.
Definition: Stat.h:293
virtual void stat(const StatTag &t, const StatFlag &f)=0
add statistical information to the entity , tagged by its name
StatEntity * m_entity
underlying counter
Definition: Stat.h:287
void reset()
reset the counters
Definition: StatEntity.cpp:207
std::string m_tag
unique stat tag(name)
Definition: Stat.h:289
std::string m_group
Definition: Stat.h:291
The basic counter used for Monitoring purposes.
Definition: StatEntity.h:65
Stat::Stat ( IStatSvc svc,
const std::string tag,
const double  flag 
)

constructor from IStatSvc, tag and value

IStatSvc* svc = ... ;
double eTotal = .... ;
// get/create the counter from Stat Service
Stat stat( svc , "total energy" , eTotal ) ;
See also
IStatSvc
Parameters
svcpointer to Chrono&Stat Service tag unique tag for the entry
flag"flag"(additive quantity) to be used

Definition at line 76 of file Stat.cpp.

76  : m_tag( tag ), m_group(), m_stat( svc )
77 {
78  if ( m_stat ) {
79  m_stat->stat( tag, flag );
80  // get from the service
81  m_entity = const_cast<StatEntity*>( m_stat->stat( tag ) );
82  }
83 }
SmartIF< IStatSvc > m_stat
Stat service.
Definition: Stat.h:293
virtual void stat(const StatTag &t, const StatFlag &f)=0
add statistical information to the entity , tagged by its name
StatEntity * m_entity
underlying counter
Definition: Stat.h:287
std::string m_tag
unique stat tag(name)
Definition: Stat.h:289
std::string m_group
Definition: Stat.h:291
The basic counter used for Monitoring purposes.
Definition: StatEntity.h:65
Stat::Stat ( ICounterSvc svc,
const std::string group,
const std::string name 
)

constructor from ICounterSvc, group and name

ICounterSvc* svc = ... ;
// get/create the counter from Counter Service
Stat stat( svc , "ECAL" , "TotalEnergy" ) ;
See also
ICounterSvc::get
ICounterSvc::create
Parameters
svcpointer to Counter Service
groupgroup name
namecounter name

Definition at line 93 of file Stat.cpp.

94  : m_tag( name ), m_group( group ), m_counter( svc )
95 {
96  if ( m_counter ) {
97  // get from the service
98  m_entity = m_counter->get( group, name );
99  // create if needed:
100  if ( !m_entity ) {
101  m_counter->create( group, name, 0, m_entity );
102  }
103  }
104 }
virtual StatusCode create(const std::string &group, const std::string &name, longlong initial_value, Counter *&refpCounter)=0
Create a new counter object.
virtual Counter * get(const std::string &group, const std::string &name) const =0
Access an existing counter object.
StatEntity * m_entity
underlying counter
Definition: Stat.h:287
std::string m_tag
unique stat tag(name)
Definition: Stat.h:289
SmartIF< ICounterSvc > m_counter
Counter Service.
Definition: Stat.h:295
std::string m_group
Definition: Stat.h:291
Stat::Stat ( const Stat )
default

copy constructor

Stat::~Stat ( )
default

destructor

Member Function Documentation

StatEntity* Stat::counter ( ) const
inline

alternative access to underlying counter (for ICounterSvc::CounterObj)

Definition at line 279 of file Stat.h.

279 { return m_entity; }
StatEntity * m_entity
underlying counter
Definition: Stat.h:287
const StatEntity* Stat::entity ( ) const
inline

get the entity

Definition at line 150 of file Stat.h.

150 { return m_entity; }
StatEntity * m_entity
underlying counter
Definition: Stat.h:287
std::ostream& Stat::fillStream ( std::ostream o) const
inline

printout to std::ostream

Parameters
sthe reference to the output stream
Returns
the reference to the output stream

Definition at line 276 of file Stat.h.

276 { return print( o ); }
std::ostream & print(std::ostream &o=std::cout) const
printout to std::ostream
Definition: Stat.cpp:120
const std::string& Stat::group ( ) const
inline

counter group (for ICounterSvc)

Definition at line 283 of file Stat.h.

283 { return m_group; }
std::string m_group
Definition: Stat.h:291
const std::string& Stat::name ( ) const
inline

counter name

Definition at line 281 of file Stat.h.

281 { return m_tag; }
std::string m_tag
unique stat tag(name)
Definition: Stat.h:289
Stat::operator const StatEntity & ( ) const
inline

cast to StatEntity

Definition at line 154 of file Stat.h.

154 { return *entity(); }
const StatEntity * entity() const
get the entity
Definition: Stat.h:150
bool Stat::operator! ( ) const
inline

check validity

Definition at line 156 of file Stat.h.

156 { return 0 == m_entity; }
StatEntity * m_entity
underlying counter
Definition: Stat.h:287
Stat& Stat::operator++ ( )
inline

Pre-increment operator for the counter.

Stat stat = ... ;
++stat ;
See also
StatEntity
Returns
selfreference

Definition at line 194 of file Stat.h.

195  {
196  if ( m_entity ) {
197  ++( *m_entity );
198  }
199  return *this;
200  }
StatEntity * m_entity
underlying counter
Definition: Stat.h:287
Stat& Stat::operator++ ( int  )
inline

Post-increment operator for the counter.

Stat stat = ... ;
stat++ ;
See also
StatEntity
Returns
self-reference

Definition at line 213 of file Stat.h.

214  {
215  if ( m_entity ) {
216  ( *m_entity )++;
217  }
218  return *this;
219  }
StatEntity * m_entity
underlying counter
Definition: Stat.h:287
Stat& Stat::operator+= ( const double  f)
inline

General increment for the counter.

Stat stat = ... ;
const long nTracks = ... ;
stat += nTracks ;
See also
StatEntity
Parameters
fvalue to be added to the counter
Returns
selfreference

Definition at line 174 of file Stat.h.

175  {
176  if ( m_entity ) {
177  ( *m_entity ) += f;
178  }
179  return *this;
180  }
StatEntity * m_entity
underlying counter
Definition: Stat.h:287
Stat& Stat::operator+= ( const StatEntity right)
inline

increment with StatEntity object

Definition at line 249 of file Stat.h.

250  {
251  if ( m_entity ) {
252  ( *m_entity ) += right;
253  }
254  return *this;
255  }
StatEntity * m_entity
underlying counter
Definition: Stat.h:287
Stat& Stat::operator+= ( const Stat right)
inline

increment with other stat objects

Definition at line 257 of file Stat.h.

258  {
259  if ( 0 != right.entity() ) {
260  ( *this ) += *right.entity();
261  }
262  return *this;
263  }
const StatEntity * entity() const
get the entity
Definition: Stat.h:150
Stat& Stat::operator-- ( )
inline

Pre-decrement operator for the flag.

Definition at line 233 of file Stat.h.

234  {
235  if ( m_entity ) {
236  --( *m_entity );
237  }
238  return *this;
239  }
StatEntity * m_entity
underlying counter
Definition: Stat.h:287
Stat& Stat::operator-- ( int  )
inline

Post-decrement operator for the flag.

Definition at line 241 of file Stat.h.

242  {
243  if ( m_entity ) {
244  ( *m_entity )--;
245  }
246  return *this;
247  }
StatEntity * m_entity
underlying counter
Definition: Stat.h:287
Stat& Stat::operator-= ( const double  f)
inline

General decrement operator for the counter.

See also
StatEntity
Returns
self-reference
Parameters
fcounter decrement

Definition at line 225 of file Stat.h.

226  {
227  if ( m_entity ) {
228  ( *m_entity ) -= f;
229  }
230  return *this;
231  }
StatEntity * m_entity
underlying counter
Definition: Stat.h:287
const StatEntity* Stat::operator-> ( ) const
inline

dereference operaqtor

Definition at line 152 of file Stat.h.

152 { return entity(); }
const StatEntity * entity() const
get the entity
Definition: Stat.h:150
Stat& Stat::operator= ( const Stat )
default

Assignement operator.

std::ostream & Stat::print ( std::ostream o = std::cout) const

printout to std::ostream

Parameters
sthe reference to the output stream
Returns
the reference to the output stream

Definition at line 120 of file Stat.cpp.

121 {
122  if ( m_group.empty() && m_tag.empty() ) {
123  return !m_entity ? ( o << "NULL" ) : ( o << m_entity );
124  }
125  if ( !m_group.empty() ) {
126  if ( m_entity ) {
127  return o << boost::format( " %|1$15s|::%|2$-15s| %|32t|%3%" ) % ( "\"" + m_group ) % ( m_tag + "\"" ) %
128  ( *m_entity );
129  } else {
130  return o << boost::format( " %|1$15s|::%|2$-15s| %|32t|%NULL%" ) % ( "\"" + m_group ) % ( m_tag + "\"" );
131  }
132  }
133  if ( m_entity ) {
134  return o << boost::format( " %|1$=30s| %|32t|%2%" ) % ( "\"" + m_tag + "\"" ) % ( *m_entity );
135  }
136  return o << boost::format( " %|1$=30s| %|32t|%NULL%" ) % ( "\"" + m_tag + "\"" );
137 }
T empty(T...args)
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:120
StatEntity * m_entity
underlying counter
Definition: Stat.h:287
std::string m_tag
unique stat tag(name)
Definition: Stat.h:289
std::string m_group
Definition: Stat.h:291
std::string Stat::toString ( ) const

representation as string

Definition at line 109 of file Stat.cpp.

110 {
111  std::ostringstream ost;
112  print( ost );
113  return ost.str();
114 }
std::ostream & print(std::ostream &o=std::cout) const
printout to std::ostream
Definition: Stat.cpp:120

Member Data Documentation

SmartIF<ICounterSvc> Stat::m_counter
private

Counter Service.

Definition at line 295 of file Stat.h.

StatEntity* Stat::m_entity = nullptr
private

underlying counter

Definition at line 287 of file Stat.h.

std::string Stat::m_group
private

Definition at line 291 of file Stat.h.

SmartIF<IStatSvc> Stat::m_stat
private

Stat service.

Definition at line 293 of file Stat.h.

std::string Stat::m_tag
private

unique stat tag(name)

Definition at line 289 of file Stat.h.


The documentation for this class was generated from the following files: