Gaudi Framework, version v22r0

Home   Generated: 9 Feb 2011

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:
Collaboration graph
[legend]

List of all members.

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 (ICounterSvc *svc, const std::string &group, const std::string &name)
 constructor from ICounterSvc, group and name
 Stat (const Stat &right)
 copy constructor
Statoperator= (const Stat &right)
 Assignement operator.
 ~Stat ()
 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::ostreamprint (std::ostream &o=std::cout) const
 printout to std::ostream
std::ostreamfillStream (std::ostream &o) const
 printout to std::ostream
StatEntitycounter () const
 alternative access to underlying counter (for ICounterSvc::CounterObj)
const std::stringname () const
 counter name
const std::stringgroup () const
 counter group (for ICounterSvc)

Private Attributes

StatEntitym_entity
 underlying counter
std::string m_tag
 unique stat tag(name)
std::string m_group
IStatSvcm_stat
 Stat service.
ICounterSvcm_counter
 Counter Service.

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.Belyaev@lapp.in2p3.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 :

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

00072     : m_entity  ( entity )
00073     , m_tag     ( name   )
00074     , m_group   ( group  )
00075     , m_stat    ( 0      )
00076     , m_counter ( 0      )
00077   {}

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

00095     : m_entity  ( &entity )
00096     , m_tag     ( name    )
00097     , m_group   ( group   )
00098     , m_stat    ( 0       )
00099     , m_counter ( 0       )
00100   {}

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 tag unique tag for the entry

Definition at line 44 of file Stat.cpp.

00046   : m_entity  ( 0    ) 
00047   , m_tag     ( tag  ) 
00048   , m_group   (      )
00049   , m_stat    ( svc  ) 
00050   , m_counter ( 0    )
00051 {
00052   if ( 0 != m_stat ) 
00053   {
00054     m_stat -> addRef() ;
00055     // get from the service 
00056     const StatEntity* tmp = m_stat->stat ( tag ) ;
00057     if ( 0 == tmp ) 
00058     {
00059       // create if needed  
00060       m_stat->stat ( tag , 0 ) ; 
00061       tmp = m_stat->stat ( tag ) ;
00062       StatEntity* aux = const_cast<StatEntity*>( tmp );
00063       aux->reset () ;
00064     }
00065     m_entity = const_cast<StatEntity*> ( tmp ) ;
00066   } 
00067 }

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 tag unique tag for the entry
flag "flag"(additive quantity) to be used

Definition at line 86 of file Stat.cpp.

00089   : m_entity  ( 0    ) 
00090   , m_tag     ( tag  ) 
00091   , m_group   (      )
00092   , m_stat    ( svc  ) 
00093   , m_counter ( 0    )
00094 {
00095   if ( 0 != m_stat ) 
00096   {
00097     m_stat -> addRef() ; 
00098     m_stat -> stat( tag , flag ) ;
00099     // get from the service 
00100     m_entity = const_cast<StatEntity*>( m_stat -> stat ( tag ) ) ;
00101   } 
00102 }

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:
svc pointer to Counter Service
group group name
name counter name

Definition at line 112 of file Stat.cpp.

00115   : m_entity  ( 0     ) 
00116   , m_tag     ( name  ) 
00117   , m_group   ( group )
00118   , m_stat    ( 0     ) 
00119   , m_counter ( svc   )
00120 {
00121   if ( 0 != m_counter ) 
00122   {
00123     m_counter -> addRef() ;
00124     // get from the service 
00125     m_entity = m_counter -> get ( group , name ) ;
00126     // create if needed:
00127     if ( 0 == m_entity ) { m_counter -> create( group , name , 0 , m_entity ) ; }
00128   }
00129 }

Stat::Stat ( const Stat right  ) 

copy constructor

Definition at line 133 of file Stat.cpp.

00134   : m_entity  ( right.m_entity  ) 
00135   , m_tag     ( right.m_tag     ) 
00136   , m_group   ( right.m_group   ) 
00137   , m_stat    ( right.m_stat    ) 
00138   , m_counter ( right.m_counter )
00139 {
00140   if ( 0 != m_stat    ) { m_stat    -> addRef () ; }
00141   if ( 0 != m_counter ) { m_counter -> addRef () ; }  
00142 }

Stat::~Stat (  ) 

destructor

Definition at line 169 of file Stat.cpp.

00170 {
00171   m_entity = 0 ;
00172   if ( 0 != m_stat    ) { m_stat    -> release() ; m_stat    = 0 ; }
00173   if ( 0 != m_counter ) { m_counter -> release() ; m_counter = 0 ; } 
00174 }


Member Function Documentation

StatEntity* Stat::counter (  )  const [inline]

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

Definition at line 282 of file Stat.h.

00282 { return  m_entity   ; }

const StatEntity* Stat::entity (  )  const [inline]

get the entity

Definition at line 169 of file Stat.h.

00169 { return  m_entity     ; }

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

00279 { return print ( o ) ; }

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

counter group (for ICounterSvc)

Definition at line 286 of file Stat.h.

00286 { return  m_group    ; }

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

counter name

Definition at line 284 of file Stat.h.

00284 { return  m_tag      ; }

Stat::operator const StatEntity & (  )  const [inline]

cast to StatEntity

Definition at line 173 of file Stat.h.

00173 { return   *entity()   ; }

bool Stat::operator! (  )  const [inline]

check validity

Definition at line 175 of file Stat.h.

00175 { return 0 == m_entity ; }

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.

00229   {
00230     if ( 0 != m_entity ) { (*m_entity)++ ; }
00231     return *this ;
00232   }

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.

00212   {
00213     if ( 0 != m_entity ) { ++(*m_entity) ; }
00214     return *this ;
00215   }

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

increment with other stat objects

Definition at line 262 of file Stat.h.

00263   {
00264     if ( 0 != right.entity() ) { (*this) += *right.entity() ; }
00265     return *this ;
00266   }

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

increment with StatEntity object

Definition at line 256 of file Stat.h.

00257   {
00258     if ( 0 != m_entity ) { (*m_entity) += right ; }
00259     return *this ;
00260   }

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

00194   {
00195     if ( 0 != m_entity ) { (*m_entity) += f ; }
00196     return *this ;
00197   }

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

Post-decrement operator for the flag.

Definition at line 250 of file Stat.h.

00251   {
00252     if ( 0 != m_entity ) {   (*m_entity)-- ; }
00253     return *this ;
00254   }

Stat& Stat::operator-- (  )  [inline]

Pre-decrement operator for the flag.

Definition at line 244 of file Stat.h.

00245   {
00246     if ( 0 != m_entity ) { --(*m_entity)   ; }
00247     return *this ;
00248   }

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

00239   {
00240     if ( 0 != m_entity ) { (*m_entity) -= f ; }
00241     return *this ;
00242   }

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

dereference operaqtor

Definition at line 171 of file Stat.h.

00171 { return    entity()   ; }

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

Assignement operator.

Definition at line 146 of file Stat.cpp.

00147 {
00148   if ( this == &right ) { return *this ; }
00149   m_entity = right.m_entity ;
00150   m_tag    = right.m_tag    ;
00151   m_group  = right.m_group  ;
00152   {
00153     IStatSvc* stat= right.m_stat ;
00154     if ( 0 !=   stat ) {   stat -> addRef()  ; }
00155     if ( 0 != m_stat ) { m_stat -> release() ; m_stat = 0 ; }
00156     m_stat = stat ;
00157   }
00158   {
00159     ICounterSvc* counter= right.m_counter ;
00160     if ( 0 !=    counter ) {   counter -> addRef()  ; }
00161     if ( 0 !=  m_counter ) { m_counter -> release() ; m_counter = 0 ; }
00162     m_counter = counter ;
00163   }
00164   return *this ;
00165 }

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

00190 {
00191   if ( m_group.empty() && m_tag.empty() ) 
00192   { return  0 == m_entity ? ( o << "NULL" ) : ( o << m_entity ) ; }
00193   if ( !m_group.empty() ) 
00194   {
00195     if ( 0 != m_entity ) 
00196     { 
00197       return o << boost::format(" %|1$15s|::%|2$-15s| %|32t|%3%") 
00198         % ( "\"" + m_group ) % ( m_tag + "\"") % (*m_entity) ;
00199     }
00200     else
00201     {
00202       return o << boost::format(" %|1$15s|::%|2$-15s| %|32t|%NULL%") 
00203         % ( "\"" + m_group ) % ( m_tag + "\"") ;
00204     }
00205   }
00206   if ( 0 != m_entity )
00207   {
00208     return o << boost::format(" %|1$=30s| %|32t|%2%") 
00209       % ("\"" + m_tag + "\"" ) % (*m_entity) ;
00210   }
00211   return o << boost::format(" %|1$=30s| %|32t|%NULL%") 
00212     % ( "\"" + m_tag + "\"" ) ; 
00213 }

std::string Stat::toString (  )  const

representation as string

Definition at line 178 of file Stat.cpp.

00179 {
00180   std::ostringstream ost ;
00181   print ( ost )  ;
00182   return ost.str () ;
00183 }


Member Data Documentation

Counter Service.

Definition at line 298 of file Stat.h.

underlying counter

Definition at line 290 of file Stat.h.

Definition at line 294 of file Stat.h.

IStatSvc* Stat::m_stat [private]

Stat service.

Definition at line 296 of file Stat.h.

unique stat tag(name)

Definition at line 292 of file Stat.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Wed Feb 9 16:31:53 2011 for Gaudi Framework, version v22r0 by Doxygen version 1.6.2 written by Dimitri van Heesch, © 1997-2004