The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
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 :
 
 Stat (StatEntity &entity, const std::string &name="", const std::string &group="")
 constructor from StatEntity, name and group :
 
 Stat (IStatSvc *svc, const std::string &tag)
 constructor from IStatSvc, tag and value
 
 Stat (IStatSvc *svc, const std::string &tag, const double flag)
 constructor from IStatSvc, tag and value
 
 Stat (const Stat &)=default
 copy constructor
 
Statoperator= (const Stat &)=default
 Assignement operator.
 
 ~Stat ()=default
 destructor
 
const StatEntityentity () const
 get the entity
 
const StatEntityoperator-> () const
 dereference operaqtor
 
 operator const StatEntity & () const
 cast to StatEntity
 
bool operator! () const
 check validity
 
Statoperator+= (const double f)
 General increment for the counter.
 
Statoperator++ ()
 Pre-increment operator for the counter.
 
Statoperator++ (int)
 Post-increment operator for the counter.
 
Statoperator-= (const double f)
 General decrement operator for the counter.
 
Statoperator-- ()
 Pre-decrement operator for the flag.
 
Statoperator-- (int)
 Post-decrement operator for the flag.
 
Statoperator+= (const StatEntity &right)
 increment with StatEntity object
 
Statoperator+= (const Stat &right)
 increment with other stat objects
 
std::string toString () const
 representation as string
 
std::ostream & print (std::ostream &o=std::cout) const
 printout to std::ostream
 
std::ostream & fillStream (std::ostream &o) const
 printout to std::ostream
 
StatEntitycounter () const
 alternative access to underlying counter
 
const std::string & name () const
 counter name
 
const std::string & group () const
 counter group
 

Private Attributes

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

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 ) ;
Stat(StatEntity *entity=0, const std::string &name="", const std::string &group="")
constructor from StatEntity, name and group :
Definition Stat.h:66

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 48 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 :

// make helper object:
Stat stat ( entity ) ;
backward compatible StatEntity class.
Definition StatEntity.h:23
const StatEntity * entity() const
get the entity
Definition Stat.h:128
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 66 of file Stat.h.

67 : m_entity( entity ), m_tag( name ), m_group( group ) {}
std::string m_tag
unique stat tag(name)
Definition Stat.h:240
StatEntity * m_entity
underlying counter
Definition Stat.h:238
std::string m_group
Definition Stat.h:242
const std::string & name() const
counter name
Definition Stat.h:232
const std::string & group() const
counter group
Definition Stat.h:234

◆ 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
entityreference to entity object
name(optional) name of the object, for printout
group(optional) group of the object, for printout

Definition at line 82 of file Stat.h.

83 : m_entity( &entity ), m_tag( name ), m_group( group ) {}

◆ 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 ;
"Stat"-related part of interface IChronoStatSvc
Definition IStatSvc.h:25
See also
IStatSvc
Parameters
svcpointer to Chrono&Stat Service @paran tag unique tag for the entry

Definition at line 28 of file Stat.cpp.

28 : m_tag( tag ), m_group(), m_stat( svc ) {
29 if ( m_stat ) {
30 // get from the service
31 StatEntity* tmp = m_stat->stat( tag );
32 if ( !tmp ) {
33 // create if needed
34 m_stat->stat( tag, 0 );
35 tmp = m_stat->stat( tag );
36 tmp->reset();
37 }
38 m_entity = tmp;
39 }
40}
friend void reset(StatEntity &s)
Definition StatEntity.h:40
SmartIF< IStatSvc > m_stat
Stat service.
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
svcpointer to Chrono&Stat Service @paran tag unique tag for the entry
flag"flag"(additive quantity) to be used

Definition at line 42 of file Stat.cpp.

42 : m_tag( tag ), m_group(), m_stat( svc ) {
43 if ( m_stat ) {
44 m_stat->stat( tag, flag );
45 // get from the service
46 m_entity = m_stat->stat( tag );
47 }
48}

◆ 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 230 of file Stat.h.

230{ return m_entity; }

◆ entity()

const StatEntity * Stat::entity ( ) const
inline

get the entity

Definition at line 128 of file Stat.h.

128{ return m_entity; }

◆ fillStream()

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 228 of file Stat.h.

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

◆ group()

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

counter group

Definition at line 234 of file Stat.h.

234{ return m_group; }

◆ name()

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

counter name

Definition at line 232 of file Stat.h.

232{ return m_tag; }

◆ operator const StatEntity &()

Stat::operator const StatEntity & ( ) const
inline

cast to StatEntity

Definition at line 132 of file Stat.h.

132{ return *entity(); }

◆ operator!()

bool Stat::operator! ( ) const
inline

check validity

Definition at line 134 of file Stat.h.

134{ return 0 == m_entity; }

◆ 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 }

◆ 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 }

◆ 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
fvalue 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 }

◆ operator+=() [2/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 }

◆ operator+=() [3/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 }

◆ 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 }

◆ 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 }

◆ operator-=()

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 193 of file Stat.h.

193 {
194 if ( m_entity ) { ( *m_entity ) -= f; }
195 return *this;
196 }

◆ operator->()

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

dereference operaqtor

Definition at line 130 of file Stat.h.

130{ return entity(); }

◆ 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
sthe reference to the output stream
Returns
the reference to the output stream

Definition at line 56 of file Stat.cpp.

56 {
57 auto entity = ( m_entity ) ? fmt::format( "{}", *m_entity ) : "NULL";
58 std::string tag;
59 if ( !m_tag.empty() ) {
60 if ( !m_group.empty() ) {
61 tag = fmt::format( "\"{}::{}\"", m_group, m_tag );
62 } else {
63 tag = fmt::format( "\"{}\"", m_tag );
64 }
65 }
66 return o << fmt::format( " {:^30} {}", tag, entity );
67}

◆ toString()

std::string Stat::toString ( ) const

representation as string

Definition at line 50 of file Stat.cpp.

50 {
51 std::ostringstream ost;
52 print( ost );
53 return ost.str();
54}

Member Data Documentation

◆ m_entity

StatEntity* Stat::m_entity = nullptr
private

underlying counter

Definition at line 238 of file Stat.h.

◆ m_group

std::string Stat::m_group
private

Definition at line 242 of file Stat.h.

◆ m_stat

SmartIF<IStatSvc> Stat::m_stat
private

Stat service.

Definition at line 244 of file Stat.h.

◆ m_tag

std::string Stat::m_tag
private

unique stat tag(name)

Definition at line 240 of file Stat.h.


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