The Gaudi Framework  master (37c0b60a)
Stat Class Reference

#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 56 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 ) ;
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 74 of file Stat.h.

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

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

91  : 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 ;
See also
IStatSvc
Parameters
svcpointer to Chrono&Stat Service @paran tag unique tag for the entry

Definition at line 46 of file Stat.cpp.

46  : m_tag( tag ), m_group(), m_stat( svc ) {
47  if ( m_stat ) {
48  // get from the service
49  StatEntity* tmp = m_stat->stat( tag );
50  if ( !tmp ) {
51  // create if needed
52  m_stat->stat( tag, 0 );
53  tmp = m_stat->stat( tag );
54  tmp->reset();
55  }
56  m_entity = tmp;
57  }
58 }

◆ 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 77 of file Stat.cpp.

77  : m_tag( tag ), m_group(), m_stat( svc ) {
78  if ( m_stat ) {
79  m_stat->stat( tag, flag );
80  // get from the service
81  m_entity = m_stat->stat( tag );
82  }
83 }

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

242 { return m_entity; }

◆ entity()

const StatEntity* Stat::entity ( ) const
inline

get the entity

Definition at line 137 of file Stat.h.

137 { 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 239 of file Stat.h.

239 { return print( o ); }

◆ group()

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

counter group

Definition at line 246 of file Stat.h.

246 { return m_group; }

◆ name()

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

counter name

Definition at line 244 of file Stat.h.

244 { return m_tag; }

◆ operator const StatEntity &()

Stat::operator const StatEntity & ( ) const
inline

cast to StatEntity

Definition at line 141 of file Stat.h.

141 { return *entity(); }

◆ operator!()

bool Stat::operator! ( ) const
inline

check validity

Definition at line 143 of file Stat.h.

143 { 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 178 of file Stat.h.

178  {
179  if ( m_entity ) { ++( *m_entity ); }
180  return *this;
181  }

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

194  {
195  if ( m_entity ) { ( *m_entity )++; }
196  return *this;
197  }

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

161  {
162  if ( m_entity ) { ( *m_entity ) += f; }
163  return *this;
164  }

◆ operator+=() [2/3]

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

increment with other stat objects

Definition at line 223 of file Stat.h.

223  {
224  if ( 0 != right.entity() ) { ( *this ) += *right.entity(); }
225  return *this;
226  }

◆ operator+=() [3/3]

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

increment with StatEntity object

Definition at line 218 of file Stat.h.

218  {
219  if ( m_entity ) { ( *m_entity ) += right; }
220  return *this;
221  }

◆ operator--() [1/2]

Stat& Stat::operator-- ( )
inline

Pre-decrement operator for the flag.

Definition at line 208 of file Stat.h.

208  {
209  if ( m_entity ) { --( *m_entity ); }
210  return *this;
211  }

◆ operator--() [2/2]

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

Post-decrement operator for the flag.

Definition at line 213 of file Stat.h.

213  {
214  if ( m_entity ) { ( *m_entity )--; }
215  return *this;
216  }

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

203  {
204  if ( m_entity ) { ( *m_entity ) -= f; }
205  return *this;
206  }

◆ operator->()

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

dereference operaqtor

Definition at line 139 of file Stat.h.

139 { 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 98 of file Stat.cpp.

98  {
99  auto entity = ( m_entity ) ? fmt::format( "{}", *m_entity ) : "NULL";
100  std::string tag;
101  if ( !m_tag.empty() ) {
102  if ( !m_group.empty() ) {
103  tag = fmt::format( "\"{}::{}\"", m_group, m_tag );
104  } else {
105  tag = fmt::format( "\"{}\"", m_tag );
106  }
107  }
108  return o << fmt::format( " {:^30} {}", tag, entity );
109 }

◆ toString()

std::string Stat::toString ( ) const

representation as string

Definition at line 88 of file Stat.cpp.

88  {
90  print( ost );
91  return ost.str();
92 }

Member Data Documentation

◆ m_entity

StatEntity* Stat::m_entity = nullptr
private

underlying counter

Definition at line 250 of file Stat.h.

◆ m_group

std::string Stat::m_group
private

Definition at line 254 of file Stat.h.

◆ m_stat

SmartIF<IStatSvc> Stat::m_stat
private

Stat service.

Definition at line 256 of file Stat.h.

◆ m_tag

std::string Stat::m_tag
private

unique stat tag(name)

Definition at line 252 of file Stat.h.


The documentation for this class was generated from the following files:
Stat::print
std::ostream & print(std::ostream &o=std::cout) const
printout to std::ostream
Definition: Stat.cpp:98
std::string
STL class.
StatEntity
backward compatible StatEntity class.
Definition: StatEntity.h:23
Stat::entity
const StatEntity * entity() const
get the entity
Definition: Stat.h:137
Stat::m_stat
SmartIF< IStatSvc > m_stat
Stat service.
Definition: Stat.h:256
IStatSvc
Definition: IStatSvc.h:35
Stat::name
const std::string & name() const
counter name
Definition: Stat.h:244
Stat::m_group
std::string m_group
Definition: Stat.h:254
Stat::m_tag
std::string m_tag
unique stat tag(name)
Definition: Stat.h:252
Stat::m_entity
StatEntity * m_entity
underlying counter
Definition: Stat.h:250
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
Stat::Stat
Stat(StatEntity *entity=0, const std::string &name="", const std::string &group="")
constructor from StatEntity, name and group :
Definition: Stat.h:74
Stat
Definition: Stat.h:56
std::ostringstream
STL class.
std::right
T right(T... args)
Stat::group
const std::string & group() const
counter group
Definition: Stat.h:246
StatEntity::reset
friend void reset(StatEntity &s)
Definition: StatEntity.h:40
std::string::empty
T empty(T... args)
std::ostringstream::str
T str(T... args)