The Gaudi Framework  v30r3 (a5ef0a68)
Stat Class Reference

Small wrapper class for easy manipulation with generic counters and IStatSvc 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 (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 More...
 
const std::stringname () const
 counter name More...
 
const std::stringgroup () const
 counter group 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...
 

Detailed Description

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

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

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 )
67  {
68  }
StatEntity * m_entity
underlying counter
Definition: Stat.h:269
std::string m_tag
unique stat tag(name)
Definition: Stat.h:271
std::string m_group
Definition: Stat.h:273
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 )
85  {
86  }
StatEntity * m_entity
underlying counter
Definition: Stat.h:269
std::string m_tag
unique stat tag(name)
Definition: Stat.h:271
std::string m_group
Definition: Stat.h:273
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 42 of file Stat.cpp.

42  : m_tag( tag ), m_group(), m_stat( svc )
43 {
44  if ( m_stat ) {
45  // get from the service
46  StatEntity* tmp = m_stat->stat( tag );
47  if ( !tmp ) {
48  // create if needed
49  m_stat->stat( tag, 0 );
50  tmp = m_stat->stat( tag );
51  tmp->reset();
52  }
53  m_entity = tmp;
54  }
55 }
SmartIF< IStatSvc > m_stat
Stat service.
Definition: Stat.h:275
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:269
void reset()
Definition: Counters.h:803
std::string m_tag
unique stat tag(name)
Definition: Stat.h:271
std::string m_group
Definition: Stat.h:273
backward compatible StatEntity class.
Definition: Counters.h:777
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 74 of file Stat.cpp.

74  : m_tag( tag ), m_group(), m_stat( svc )
75 {
76  if ( m_stat ) {
77  m_stat->stat( tag, flag );
78  // get from the service
79  m_entity = m_stat->stat( tag );
80  }
81 }
SmartIF< IStatSvc > m_stat
Stat service.
Definition: Stat.h:275
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:269
std::string m_tag
unique stat tag(name)
Definition: Stat.h:271
std::string m_group
Definition: Stat.h:273
Stat::Stat ( const Stat )
default

copy constructor

Stat::~Stat ( )
default

destructor

Member Function Documentation

StatEntity* Stat::counter ( ) const
inline

alternative access to underlying counter

Definition at line 261 of file Stat.h.

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

get the entity

Definition at line 132 of file Stat.h.

132 { return m_entity; }
StatEntity * m_entity
underlying counter
Definition: Stat.h:269
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 258 of file Stat.h.

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

counter group

Definition at line 265 of file Stat.h.

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

counter name

Definition at line 263 of file Stat.h.

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

cast to StatEntity

Definition at line 136 of file Stat.h.

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

check validity

Definition at line 138 of file Stat.h.

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

Pre-increment operator for the counter.

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

Definition at line 176 of file Stat.h.

177  {
178  if ( m_entity ) {
179  ++( *m_entity );
180  }
181  return *this;
182  }
StatEntity * m_entity
underlying counter
Definition: Stat.h:269
Stat& Stat::operator++ ( int  )
inline

Post-increment operator for the counter.

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

Definition at line 195 of file Stat.h.

196  {
197  if ( m_entity ) {
198  ( *m_entity )++;
199  }
200  return *this;
201  }
StatEntity * m_entity
underlying counter
Definition: Stat.h:269
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 156 of file Stat.h.

157  {
158  if ( m_entity ) {
159  ( *m_entity ) += f;
160  }
161  return *this;
162  }
StatEntity * m_entity
underlying counter
Definition: Stat.h:269
Stat& Stat::operator+= ( const StatEntity right)
inline

increment with StatEntity object

Definition at line 231 of file Stat.h.

232  {
233  if ( m_entity ) {
234  ( *m_entity ) += right;
235  }
236  return *this;
237  }
StatEntity * m_entity
underlying counter
Definition: Stat.h:269
Stat& Stat::operator+= ( const Stat right)
inline

increment with other stat objects

Definition at line 239 of file Stat.h.

240  {
241  if ( 0 != right.entity() ) {
242  ( *this ) += *right.entity();
243  }
244  return *this;
245  }
const StatEntity * entity() const
get the entity
Definition: Stat.h:132
Stat& Stat::operator-- ( )
inline

Pre-decrement operator for the flag.

Definition at line 215 of file Stat.h.

216  {
217  if ( m_entity ) {
218  --( *m_entity );
219  }
220  return *this;
221  }
StatEntity * m_entity
underlying counter
Definition: Stat.h:269
Stat& Stat::operator-- ( int  )
inline

Post-decrement operator for the flag.

Definition at line 223 of file Stat.h.

224  {
225  if ( m_entity ) {
226  ( *m_entity )--;
227  }
228  return *this;
229  }
StatEntity * m_entity
underlying counter
Definition: Stat.h:269
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 207 of file Stat.h.

208  {
209  if ( m_entity ) {
210  ( *m_entity ) -= f;
211  }
212  return *this;
213  }
StatEntity * m_entity
underlying counter
Definition: Stat.h:269
const StatEntity* Stat::operator-> ( ) const
inline

dereference operaqtor

Definition at line 134 of file Stat.h.

134 { return entity(); }
const StatEntity * entity() const
get the entity
Definition: Stat.h:132
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 97 of file Stat.cpp.

98 {
99  if ( m_group.empty() && m_tag.empty() ) {
100  return !m_entity ? ( o << "NULL" ) : ( o << m_entity );
101  }
102  if ( !m_group.empty() ) {
103  if ( m_entity ) {
104  return o << boost::format( " %|1$15s|::%|2$-15s| %|32t|%3%" ) % ( "\"" + m_group ) % ( m_tag + "\"" ) %
105  ( *m_entity );
106  } else {
107  return o << boost::format( " %|1$15s|::%|2$-15s| %|32t|%NULL%" ) % ( "\"" + m_group ) % ( m_tag + "\"" );
108  }
109  }
110  if ( m_entity ) {
111  return o << boost::format( " %|1$=30s| %|32t|%2%" ) % ( "\"" + m_tag + "\"" ) % ( *m_entity );
112  }
113  return o << boost::format( " %|1$=30s| %|32t|%NULL%" ) % ( "\"" + m_tag + "\"" );
114 }
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:269
std::string m_tag
unique stat tag(name)
Definition: Stat.h:271
std::string m_group
Definition: Stat.h:273
std::string Stat::toString ( ) const

representation as string

Definition at line 86 of file Stat.cpp.

87 {
89  print( ost );
90  return ost.str();
91 }
std::ostream & print(std::ostream &o=std::cout) const
printout to std::ostream
Definition: Stat.cpp:97

Member Data Documentation

StatEntity* Stat::m_entity = nullptr
private

underlying counter

Definition at line 269 of file Stat.h.

std::string Stat::m_group
private

Definition at line 273 of file Stat.h.

SmartIF<IStatSvc> Stat::m_stat
private

Stat service.

Definition at line 275 of file Stat.h.

std::string Stat::m_tag
private

unique stat tag(name)

Definition at line 271 of file Stat.h.


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