| The Gaudi Framework v32r1 (f65d50dc)

Public Member Functions | Private Attributes | List of all members
Stat Class Reference

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

`#include <GaudiKernel/Stat.h>`

Collaboration diagram for Stat:
[legend]

## 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...
Stat & | operator= (const Stat &)=default
| Assignement operator. More...
| ~Stat ()=default
| destructor More...
const StatEntity * | entity () const
| get the entity More...
const StatEntity * | operator-> () const
| dereference operaqtor More...
| operator const StatEntity & () const
| cast to StatEntity More...
bool | operator! () const
| check validity More...
Stat & | operator+= (const double f)
| General increment for the counter. More...
Stat & | operator++ ()
| Pre-increment operator for the counter. More...
Stat & | operator++ (int)
| Post-increment operator for the counter. More...
Stat & | operator-= (const double f)
| General decrement operator for the counter. More...
Stat & | operator-- ()
| Pre-decrement operator for the flag. More...
Stat & | operator-- (int)
| Post-decrement operator for the flag. More...
Stat & | operator+= (const StatEntity &right)
| increment with StatEntity object More...
Stat & | operator+= (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...
StatEntity * | counter () const
| alternative access to underlying counter More...
const std::string & | name () const
| counter name More...
const std::string & | group () const
| counter group More...

## Private Attributes
StatEntity * | m_entity = nullptr
| underlying counter More...
std::string | m_tag
| unique stat tag(name) More...
std::string | m_group
SmartIF< IStatSvc > | m_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() [1/5]

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

constructor from StatEntity, name and group :

StatEntity* entity = ... ;
// make helper object:
Stat stat ( entity ) ;

See also
  StatEntity

Parameters

  entity | pointer to entity object
  name | (optional) name of the object, for printout
  group | (optional) group of the object, for printout

Definition at line 64 of file Stat.h.

65 : m_entity( entity ), m_tag( name ), m_group( group ) {}
Stat::entity
const StatEntity * entity() const
get the entity
Definition: Stat.h:127
Stat::m_entity
StatEntity * m_entity
underlying counter
Definition: Stat.h:240
Stat::m_tag
std::string m_tag
unique stat tag(name)
Definition: Stat.h:242
Stat::name
const std::string & name() const
counter name
Definition: Stat.h:234
Stat::m_group
std::string m_group
Definition: Stat.h:244
Stat::group
const std::string & group() const
counter group
Definition: Stat.h:236

## ◆ Stat() [2/5]

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

  entity | reference to entity object
  name | (optional) name of the object, for printout
  group | (optional) group of the object, for printout

Definition at line 80 of file Stat.h.

81 : m_entity( &entity ), m_tag( name ), m_group( group ) {}
Stat::entity
const StatEntity * entity() const
get the entity
Definition: Stat.h:127
Stat::m_entity
StatEntity * m_entity
underlying counter
Definition: Stat.h:240
Stat::m_tag
std::string m_tag
unique stat tag(name)
Definition: Stat.h:242
Stat::name
const std::string & name() const
counter name
Definition: Stat.h:234
Stat::m_group
std::string m_group
Definition: Stat.h:244
Stat::group
const std::string & group() const
counter group
Definition: Stat.h:236

## ◆ Stat() [3/5]

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

  svc | pointer to Chrono&Stat Service @paran tag unique tag for the entry

Definition at line 42 of file Stat.cpp.

42 : m_tag( tag ), m_group(), m_stat( svc ) {
43 if ( m_stat ) {
44 // get from the service
45 StatEntity* tmp = m_stat->stat( tag );
46 if ( !tmp ) {
47 // create if needed
48 m_stat->stat( tag, 0 );
49 tmp = m_stat->stat( tag );
50 tmp->reset();
51 }
52 m_entity = tmp;
53 }
54 }
Stat::m_stat
SmartIF< IStatSvc > m_stat
Stat service.
Definition: Stat.h:246
IStatSvc::stat
virtual void stat(const StatTag &t, const StatFlag &f)=0
add statistical information to the entity , tagged by its name
Stat::m_entity
StatEntity * m_entity
underlying counter
Definition: Stat.h:240
Stat::m_tag
std::string m_tag
unique stat tag(name)
Definition: Stat.h:242
Stat::m_group
std::string m_group
Definition: Stat.h:244

## ◆ Stat() [4/5]

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

  svc | pointer to Chrono&Stat Service @paran tag unique tag for the entry
  flag | "flag"(additive quantity) to be used

Definition at line 73 of file Stat.cpp.

73 : m_tag( tag ), m_group(), m_stat( svc ) {
74 if ( m_stat ) {
75 m_stat->stat( tag, flag );
76 // get from the service
77 m_entity = m_stat->stat( tag );
78 }
79 }
Stat::m_stat
SmartIF< IStatSvc > m_stat
Stat service.
Definition: Stat.h:246
IStatSvc::stat
virtual void stat(const StatTag &t, const StatFlag &f)=0
add statistical information to the entity , tagged by its name
Stat::m_entity
StatEntity * m_entity
underlying counter
Definition: Stat.h:240
Stat::m_tag
std::string m_tag
unique stat tag(name)
Definition: Stat.h:242
Stat::m_group
std::string m_group
Definition: Stat.h:244

## ◆ Stat() [5/5]

Stat::Stat | ( | const Stat & |  | ) |
| default

copy constructor

## ◆ ~Stat()

Stat::~Stat | ( |  | ) |
| default

destructor

## Member Function Documentation

## ◆ counter()

StatEntity* Stat::counter | ( |  | ) | const
| inline

alternative access to underlying counter

Definition at line 232 of file Stat.h.

232 { return m_entity; }
Stat::m_entity
StatEntity * m_entity
underlying counter
Definition: Stat.h:240

## ◆ entity()

const StatEntity* Stat::entity | ( |  | ) | const
| inline

get the entity

Definition at line 127 of file Stat.h.

127 { return m_entity; }
Stat::m_entity
StatEntity * m_entity
underlying counter
Definition: Stat.h:240

## ◆ fillStream()

std::ostream& Stat::fillStream | ( | std::ostream & | o | ) | const
| inline

printout to std::ostream

Parameters

  s | the reference to the output stream

Returns
  the reference to the output stream

Definition at line 229 of file Stat.h.

229 { return print( o ); }
Stat::print
std::ostream & print(std::ostream &o=std::cout) const
printout to std::ostream
Definition: Stat.cpp:94

## ◆ group()

const std::string& Stat::group | ( |  | ) | const
| inline

counter group

Definition at line 236 of file Stat.h.

236 { return m_group; }
Stat::m_group
std::string m_group
Definition: Stat.h:244

## ◆ name()

const std::string& Stat::name | ( |  | ) | const
| inline

counter name

Definition at line 234 of file Stat.h.

234 { return m_tag; }
Stat::m_tag
std::string m_tag
unique stat tag(name)
Definition: Stat.h:242

## ◆ operator const StatEntity &()

Stat::operator const StatEntity & | ( |  | ) | const
| inline

cast to StatEntity

Definition at line 131 of file Stat.h.

131 { return *entity(); }
Stat::entity
const StatEntity * entity() const
get the entity
Definition: Stat.h:127

## ◆ operator!()

bool Stat::operator! | ( |  | ) | const
| inline

check validity

Definition at line 133 of file Stat.h.

133 { return 0 == m_entity; }
Stat::m_entity
StatEntity * m_entity
underlying counter
Definition: Stat.h:240

## ◆ operator++() [1/2]

Stat& Stat::operator++ | ( |  | ) |
| inline

Pre-increment operator for the counter.

Stat stat = ... ;
++stat ;

See also
  StatEntity

Returns
  selfreference

Definition at line 168 of file Stat.h.

168 {
169 if ( m_entity ) { ++( *m_entity ); }
170 return *this;
171 }
Stat::m_entity
StatEntity * m_entity
underlying counter
Definition: Stat.h:240

## ◆ operator++() [2/2]

Stat& Stat::operator++ | ( | int |  | ) |
| inline

Post-increment operator for the counter.

Stat stat = ... ;
stat++ ;

See also
  StatEntity

Returns
  self-reference

Definition at line 184 of file Stat.h.

184 {
185 if ( m_entity ) { ( *m_entity )++; }
186 return *this;
187 }
Stat::m_entity
StatEntity * m_entity
underlying counter
Definition: Stat.h:240

## ◆ operator+=() [1/3]

Stat& Stat::operator+= | ( | const double | f | ) |
| inline

General increment for the counter.

Stat stat = ... ;
const long nTracks = ... ;
stat += nTracks ;

See also
  StatEntity

Parameters

  f | value to be added to the counter

Returns
  selfreference

Definition at line 151 of file Stat.h.

151 {
152 if ( m_entity ) { ( *m_entity ) += f; }
153 return *this;
154 }
Stat::m_entity
StatEntity * m_entity
underlying counter
Definition: Stat.h:240

## ◆ operator+=() [2/3]

Stat& Stat::operator+= | ( | const StatEntity & | right | ) |
| inline

increment with StatEntity object

Definition at line 208 of file Stat.h.

208 {
209 if ( m_entity ) { ( *m_entity ) += right; }
210 return *this;
211 }
std::right
T right(T... args)
Stat::m_entity
StatEntity * m_entity
underlying counter
Definition: Stat.h:240

## ◆ operator+=() [3/3]

Stat& Stat::operator+= | ( | const Stat & | right | ) |
| inline

increment with other stat objects

Definition at line 213 of file Stat.h.

213 {
214 if ( 0 != right.entity() ) { ( *this ) += *right.entity(); }
215 return *this;
216 }
std::right
T right(T... args)

## ◆ operator--() [1/2]

Stat& Stat::operator-- | ( |  | ) |
| inline

Pre-decrement operator for the flag.

Definition at line 198 of file Stat.h.

198 {
199 if ( m_entity ) { --( *m_entity ); }
200 return *this;
201 }
Stat::m_entity
StatEntity * m_entity
underlying counter
Definition: Stat.h:240

## ◆ operator--() [2/2]

Stat& Stat::operator-- | ( | int |  | ) |
| inline

Post-decrement operator for the flag.

Definition at line 203 of file Stat.h.

203 {
204 if ( m_entity ) { ( *m_entity )--; }
205 return *this;
206 }
Stat::m_entity
StatEntity * m_entity
underlying counter
Definition: Stat.h:240

## ◆ operator-=()

Stat& Stat::operator-= | ( | const double | f | ) |
| inline

General decrement operator for the counter.

See also
  StatEntity

Returns
  self-reference

Parameters

  f | counter decrement

Definition at line 193 of file Stat.h.

193 {
194 if ( m_entity ) { ( *m_entity ) -= f; }
195 return *this;
196 }
Stat::m_entity
StatEntity * m_entity
underlying counter
Definition: Stat.h:240

## ◆ operator->()

const StatEntity* Stat::operator-> | ( |  | ) | const
| inline

dereference operaqtor

Definition at line 129 of file Stat.h.

129 { return entity(); }
Stat::entity
const StatEntity * entity() const
get the entity
Definition: Stat.h:127

## ◆ operator=()

Stat& Stat::operator= | ( | const Stat & |  | ) |
| default

Assignement operator.

## ◆ print()

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

printout to std::ostream

Parameters

  s | the reference to the output stream

Returns
  the reference to the output stream

Definition at line 94 of file Stat.cpp.

94 {
95 if ( m_group.empty() && m_tag.empty() ) { return !m_entity ? ( o << "NULL" ) : ( o << m_entity ); }
96 if ( !m_group.empty() ) {
97 if ( m_entity ) {
98 return o << boost::format( " %|1$15s|::%|2$-15s| %|32t|%3%" ) % ( "\"" + m_group ) % ( m_tag + "\"" ) %
99 ( *m_entity );
100 } else {
101 return o << boost::format( " %|1$15s|::%|2$-15s| %|32t|%NULL%" ) % ( "\"" + m_group ) % ( m_tag + "\"" );
102 }
103 }
104 if ( m_entity ) { return o << boost::format( " %|1$=30s| %|32t|%2%" ) % ( "\"" + m_tag + "\"" ) % ( *m_entity ); }
105 return o << boost::format( " %|1$=30s| %|32t|%NULL%" ) % ( "\"" + m_tag + "\"" );
106 }
std::string::empty
T empty(T... args)
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:109
Stat::m_entity
StatEntity * m_entity
underlying counter
Definition: Stat.h:240
Stat::m_tag
std::string m_tag
unique stat tag(name)
Definition: Stat.h:242
Stat::m_group
std::string m_group
Definition: Stat.h:244

## ◆ toString()

std::string Stat::toString | ( |  | ) | const

representation as string

Definition at line 84 of file Stat.cpp.

84 {
85 std::ostringstream ost;
86 print( ost );
87 return ost.str();
88 }
std::ostringstream
STL class.
std::ostringstream::str
T str(T... args)
Stat::print
std::ostream & print(std::ostream &o=std::cout) const
printout to std::ostream
Definition: Stat.cpp:94

## Member Data Documentation

## ◆ m_entity

StatEntity* Stat::m_entity = nullptr
| private

underlying counter

Definition at line 240 of file Stat.h.

## ◆ m_group

std::string Stat::m_group
| private

Definition at line 244 of file Stat.h.

## ◆ m_stat

SmartIF<IStatSvc> Stat::m_stat
| private

Stat service.

Definition at line 246 of file Stat.h.

## ◆ m_tag

std::string Stat::m_tag
| private

unique stat tag(name)

Definition at line 242 of file Stat.h.

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

- GaudiKernel/GaudiKernel/Stat.h
- GaudiKernel/src/Lib/Stat.cpp