All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 &right)
 copy constructor More...
 
Statoperator= (const Stat &right)
 Assignement operator. More...
 
 ~Stat ()
 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::ostream & print (std::ostream &o=std::cout) const
 printout to std::ostream More...
 
std::ostream & fillStream (std::ostream &o) const
 printout to std::ostream More...
 
StatEntitycounter () const
 alternative access to underlying counter (for ICounterSvc::CounterObj) More...
 
const std::string & name () const
 counter name More...
 
const std::string & group () const
 counter group (for ICounterSvc) More...
 

Private Attributes

StatEntitym_entity
 underlying counter More...
 
std::string m_tag
 unique stat tag(name) More...
 
std::string m_group
 
IStatSvcm_stat
 Stat service. More...
 
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 50 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 69 of file Stat.h.

72  : m_entity ( entity )
73  , m_tag ( name )
74  , m_group ( group )
75  , m_stat ( 0 )
76  , m_counter ( 0 )
77  {}
StatEntity * m_entity
underlying counter
Definition: Stat.h:290
const std::string & name() const
counter name
Definition: Stat.h:284
ICounterSvc * m_counter
Counter Service.
Definition: Stat.h:298
std::string m_tag
unique stat tag(name)
Definition: Stat.h:292
std::string m_group
Definition: Stat.h:294
IStatSvc * m_stat
Stat service.
Definition: Stat.h:296
const std::string & group() const
counter group (for ICounterSvc)
Definition: Stat.h:286
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 92 of file Stat.h.

95  : m_entity ( &entity )
96  , m_tag ( name )
97  , m_group ( group )
98  , m_stat ( 0 )
99  , m_counter ( 0 )
100  {}
StatEntity * m_entity
underlying counter
Definition: Stat.h:290
const std::string & name() const
counter name
Definition: Stat.h:284
ICounterSvc * m_counter
Counter Service.
Definition: Stat.h:298
std::string m_tag
unique stat tag(name)
Definition: Stat.h:292
std::string m_group
Definition: Stat.h:294
IStatSvc * m_stat
Stat service.
Definition: Stat.h:296
const std::string & group() const
counter group (for ICounterSvc)
Definition: Stat.h:286
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 44 of file Stat.cpp.

46  : m_entity ( 0 )
47  , m_tag ( tag )
48  , m_group ( )
49  , m_stat ( svc )
50  , m_counter ( 0 )
51 {
52  if ( 0 != m_stat )
53  {
54  m_stat -> addRef() ;
55  // get from the service
56  const StatEntity* tmp = m_stat->stat ( tag ) ;
57  if ( 0 == tmp )
58  {
59  // create if needed
60  m_stat->stat ( tag , 0 ) ;
61  tmp = m_stat->stat ( tag ) ;
62  StatEntity* aux = const_cast<StatEntity*>( tmp );
63  aux->reset () ;
64  }
65  m_entity = const_cast<StatEntity*> ( tmp ) ;
66  }
67 }
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:290
void reset()
reset the counters
Definition: StatEntity.cpp:209
ICounterSvc * m_counter
Counter Service.
Definition: Stat.h:298
std::string m_tag
unique stat tag(name)
Definition: Stat.h:292
std::string m_group
Definition: Stat.h:294
IStatSvc * m_stat
Stat service.
Definition: Stat.h:296
The basic counter used for Monitoring purposes.
Definition: StatEntity.h:68
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 86 of file Stat.cpp.

89  : m_entity ( 0 )
90  , m_tag ( tag )
91  , m_group ( )
92  , m_stat ( svc )
93  , m_counter ( 0 )
94 {
95  if ( 0 != m_stat )
96  {
97  m_stat -> addRef() ;
98  m_stat -> stat( tag , flag ) ;
99  // get from the service
100  m_entity = const_cast<StatEntity*>( m_stat -> stat ( tag ) ) ;
101  }
102 }
StatEntity * m_entity
underlying counter
Definition: Stat.h:290
ICounterSvc * m_counter
Counter Service.
Definition: Stat.h:298
std::string m_tag
unique stat tag(name)
Definition: Stat.h:292
std::string m_group
Definition: Stat.h:294
IStatSvc * m_stat
Stat service.
Definition: Stat.h:296
The basic counter used for Monitoring purposes.
Definition: StatEntity.h:68
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 112 of file Stat.cpp.

115  : m_entity ( 0 )
116  , m_tag ( name )
117  , m_group ( group )
118  , m_stat ( 0 )
119  , m_counter ( svc )
120 {
121  if ( 0 != m_counter )
122  {
123  m_counter -> addRef() ;
124  // get from the service
125  m_entity = m_counter -> get ( group , name ) ;
126  // create if needed:
127  if ( 0 == m_entity ) { m_counter -> create( group , name , 0 , m_entity ) ; }
128  }
129 }
StatEntity * m_entity
underlying counter
Definition: Stat.h:290
const std::string & name() const
counter name
Definition: Stat.h:284
ICounterSvc * m_counter
Counter Service.
Definition: Stat.h:298
std::string m_tag
unique stat tag(name)
Definition: Stat.h:292
std::string m_group
Definition: Stat.h:294
IStatSvc * m_stat
Stat service.
Definition: Stat.h:296
const std::string & group() const
counter group (for ICounterSvc)
Definition: Stat.h:286
Stat::Stat ( const Stat right)

copy constructor

Definition at line 133 of file Stat.cpp.

134  : m_entity ( right.m_entity )
135  , m_tag ( right.m_tag )
136  , m_group ( right.m_group )
137  , m_stat ( right.m_stat )
138  , m_counter ( right.m_counter )
139 {
140  if ( 0 != m_stat ) { m_stat -> addRef () ; }
141  if ( 0 != m_counter ) { m_counter -> addRef () ; }
142 }
StatEntity * m_entity
underlying counter
Definition: Stat.h:290
ICounterSvc * m_counter
Counter Service.
Definition: Stat.h:298
std::string m_tag
unique stat tag(name)
Definition: Stat.h:292
std::string m_group
Definition: Stat.h:294
IStatSvc * m_stat
Stat service.
Definition: Stat.h:296
Stat::~Stat ( )

destructor

Definition at line 169 of file Stat.cpp.

170 {
171  m_entity = 0 ;
172  if ( 0 != m_stat ) { m_stat -> release() ; m_stat = 0 ; }
173  if ( 0 != m_counter ) { m_counter -> release() ; m_counter = 0 ; }
174 }
StatEntity * m_entity
underlying counter
Definition: Stat.h:290
ICounterSvc * m_counter
Counter Service.
Definition: Stat.h:298
IStatSvc * m_stat
Stat service.
Definition: Stat.h:296

Member Function Documentation

StatEntity* Stat::counter ( ) const
inline

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

Definition at line 282 of file Stat.h.

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

get the entity

Definition at line 169 of file Stat.h.

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

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

counter group (for ICounterSvc)

Definition at line 286 of file Stat.h.

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

counter name

Definition at line 284 of file Stat.h.

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

cast to StatEntity

Definition at line 173 of file Stat.h.

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

check validity

Definition at line 175 of file Stat.h.

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

Pre-increment operator for the counter.

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

Definition at line 211 of file Stat.h.

212  {
213  if ( 0 != m_entity ) { ++(*m_entity) ; }
214  return *this ;
215  }
StatEntity * m_entity
underlying counter
Definition: Stat.h:290
Stat& Stat::operator++ ( int  )
inline

Post-increment operator for the counter.

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

Definition at line 228 of file Stat.h.

229  {
230  if ( 0 != m_entity ) { (*m_entity)++ ; }
231  return *this ;
232  }
StatEntity * m_entity
underlying counter
Definition: Stat.h:290
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 193 of file Stat.h.

194  {
195  if ( 0 != m_entity ) { (*m_entity) += f ; }
196  return *this ;
197  }
StatEntity * m_entity
underlying counter
Definition: Stat.h:290
Stat& Stat::operator+= ( const StatEntity right)
inline

increment with StatEntity object

Definition at line 256 of file Stat.h.

257  {
258  if ( 0 != m_entity ) { (*m_entity) += right ; }
259  return *this ;
260  }
StatEntity * m_entity
underlying counter
Definition: Stat.h:290
Stat& Stat::operator+= ( const Stat right)
inline

increment with other stat objects

Definition at line 262 of file Stat.h.

263  {
264  if ( 0 != right.entity() ) { (*this) += *right.entity() ; }
265  return *this ;
266  }
const StatEntity * entity() const
get the entity
Definition: Stat.h:169
Stat& Stat::operator-- ( )
inline

Pre-decrement operator for the flag.

Definition at line 244 of file Stat.h.

245  {
246  if ( 0 != m_entity ) { --(*m_entity) ; }
247  return *this ;
248  }
StatEntity * m_entity
underlying counter
Definition: Stat.h:290
Stat& Stat::operator-- ( int  )
inline

Post-decrement operator for the flag.

Definition at line 250 of file Stat.h.

251  {
252  if ( 0 != m_entity ) { (*m_entity)-- ; }
253  return *this ;
254  }
StatEntity * m_entity
underlying counter
Definition: Stat.h:290
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 238 of file Stat.h.

239  {
240  if ( 0 != m_entity ) { (*m_entity) -= f ; }
241  return *this ;
242  }
StatEntity * m_entity
underlying counter
Definition: Stat.h:290
const StatEntity* Stat::operator-> ( ) const
inline

dereference operaqtor

Definition at line 171 of file Stat.h.

171 { return entity() ; }
const StatEntity * entity() const
get the entity
Definition: Stat.h:169
Stat & Stat::operator= ( const Stat right)

Assignement operator.

Definition at line 146 of file Stat.cpp.

147 {
148  if ( this == &right ) { return *this ; }
149  m_entity = right.m_entity ;
150  m_tag = right.m_tag ;
151  m_group = right.m_group ;
152  {
153  IStatSvc* stat= right.m_stat ;
154  if ( 0 != stat ) { stat -> addRef() ; }
155  if ( 0 != m_stat ) { m_stat -> release() ; m_stat = 0 ; }
156  m_stat = stat ;
157  }
158  {
159  ICounterSvc* counter= right.m_counter ;
160  if ( 0 != counter ) { counter -> addRef() ; }
161  if ( 0 != m_counter ) { m_counter -> release() ; m_counter = 0 ; }
162  m_counter = counter ;
163  }
164  return *this ;
165 }
Create / access multi purpose counters.
Definition: ICounterSvc.h:78
StatEntity * counter() const
alternative access to underlying counter (for ICounterSvc::CounterObj)
Definition: Stat.h:282
StatEntity * m_entity
underlying counter
Definition: Stat.h:290
ICounterSvc * m_counter
Counter Service.
Definition: Stat.h:298
std::string m_tag
unique stat tag(name)
Definition: Stat.h:292
std::string m_group
Definition: Stat.h:294
IStatSvc * m_stat
Stat service.
Definition: Stat.h:296
"Stat"-related part of interface IChronoStatSvc
Definition: IStatSvc.h:27
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 189 of file Stat.cpp.

190 {
191  if ( m_group.empty() && m_tag.empty() )
192  { return 0 == m_entity ? ( o << "NULL" ) : ( o << m_entity ) ; }
193  if ( !m_group.empty() )
194  {
195  if ( 0 != m_entity )
196  {
197  return o << boost::format(" %|1$15s|::%|2$-15s| %|32t|%3%")
198  % ( "\"" + m_group ) % ( m_tag + "\"") % (*m_entity) ;
199  }
200  else
201  {
202  return o << boost::format(" %|1$15s|::%|2$-15s| %|32t|%NULL%")
203  % ( "\"" + m_group ) % ( m_tag + "\"") ;
204  }
205  }
206  if ( 0 != m_entity )
207  {
208  return o << boost::format(" %|1$=30s| %|32t|%2%")
209  % ("\"" + m_tag + "\"" ) % (*m_entity) ;
210  }
211  return o << boost::format(" %|1$=30s| %|32t|%NULL%")
212  % ( "\"" + m_tag + "\"" ) ;
213 }
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:133
StatEntity * m_entity
underlying counter
Definition: Stat.h:290
std::string m_tag
unique stat tag(name)
Definition: Stat.h:292
std::string m_group
Definition: Stat.h:294
std::string Stat::toString ( ) const

representation as string

Definition at line 178 of file Stat.cpp.

179 {
180  std::ostringstream ost ;
181  print ( ost ) ;
182  return ost.str () ;
183 }
std::ostream & print(std::ostream &o=std::cout) const
printout to std::ostream
Definition: Stat.cpp:189

Member Data Documentation

ICounterSvc* Stat::m_counter
private

Counter Service.

Definition at line 298 of file Stat.h.

StatEntity* Stat::m_entity
private

underlying counter

Definition at line 290 of file Stat.h.

std::string Stat::m_group
private

Definition at line 294 of file Stat.h.

IStatSvc* Stat::m_stat
private

Stat service.

Definition at line 296 of file Stat.h.

std::string Stat::m_tag
private

unique stat tag(name)

Definition at line 292 of file Stat.h.


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