Gaudi Framework, version v22r2

Home   Generated: Tue May 10 2011
Public Member Functions | Private Attributes

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

    : m_entity  ( entity )
    , m_tag     ( name   )
    , m_group   ( group  )
    , m_stat    ( 0      )
    , m_counter ( 0      )
  {}
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.

    : m_entity  ( &entity )
    , m_tag     ( name    )
    , m_group   ( group   )
    , m_stat    ( 0       )
    , m_counter ( 0       )
  {}
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.

  : m_entity  ( 0    ) 
  , m_tag     ( tag  ) 
  , m_group   (      )
  , m_stat    ( svc  ) 
  , m_counter ( 0    )
{
  if ( 0 != m_stat ) 
  {
    m_stat -> addRef() ;
    // get from the service 
    const StatEntity* tmp = m_stat->stat ( tag ) ;
    if ( 0 == tmp ) 
    {
      // create if needed  
      m_stat->stat ( tag , 0 ) ; 
      tmp = m_stat->stat ( tag ) ;
      StatEntity* aux = const_cast<StatEntity*>( tmp );
      aux->reset () ;
    }
    m_entity = const_cast<StatEntity*> ( tmp ) ;
  } 
}
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.

  : m_entity  ( 0    ) 
  , m_tag     ( tag  ) 
  , m_group   (      )
  , m_stat    ( svc  ) 
  , m_counter ( 0    )
{
  if ( 0 != m_stat ) 
  {
    m_stat -> addRef() ; 
    m_stat -> stat( tag , flag ) ;
    // get from the service 
    m_entity = const_cast<StatEntity*>( m_stat -> stat ( tag ) ) ;
  } 
}
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.

  : m_entity  ( 0     ) 
  , m_tag     ( name  ) 
  , m_group   ( group )
  , m_stat    ( 0     ) 
  , m_counter ( svc   )
{
  if ( 0 != m_counter ) 
  {
    m_counter -> addRef() ;
    // get from the service 
    m_entity = m_counter -> get ( group , name ) ;
    // create if needed:
    if ( 0 == m_entity ) { m_counter -> create( group , name , 0 , m_entity ) ; }
  }
}
Stat::Stat ( const Stat right )

copy constructor

Definition at line 133 of file Stat.cpp.

  : m_entity  ( right.m_entity  ) 
  , m_tag     ( right.m_tag     ) 
  , m_group   ( right.m_group   ) 
  , m_stat    ( right.m_stat    ) 
  , m_counter ( right.m_counter )
{
  if ( 0 != m_stat    ) { m_stat    -> addRef () ; }
  if ( 0 != m_counter ) { m_counter -> addRef () ; }  
}
Stat::~Stat (  )

destructor

Definition at line 169 of file Stat.cpp.

{
  m_entity = 0 ;
  if ( 0 != m_stat    ) { m_stat    -> release() ; m_stat    = 0 ; }
  if ( 0 != m_counter ) { m_counter -> release() ; m_counter = 0 ; } 
}

Member Function Documentation

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

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

Definition at line 282 of file Stat.h.

{ return  m_entity   ; }
const StatEntity* Stat::entity (  ) const [inline]

get the entity

Definition at line 169 of file Stat.h.

{ return  m_entity     ; }
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.

{ return print ( o ) ; }
const std::string& Stat::group (  ) const [inline]

counter group (for ICounterSvc)

Definition at line 286 of file Stat.h.

{ return  m_group    ; }
const std::string& Stat::name (  ) const [inline]

counter name

Definition at line 284 of file Stat.h.

{ return  m_tag      ; }
Stat::operator const StatEntity & (  ) const [inline]

cast to StatEntity

Definition at line 173 of file Stat.h.

{ return   *entity()   ; }
bool Stat::operator! (  ) const [inline]

check validity

Definition at line 175 of file Stat.h.

{ 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.

  {
    if ( 0 != m_entity ) { (*m_entity)++ ; }
    return *this ;
  }
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.

  {
    if ( 0 != m_entity ) { ++(*m_entity) ; }
    return *this ;
  }
Stat& Stat::operator+= ( const Stat right ) [inline]

increment with other stat objects

Definition at line 262 of file Stat.h.

  {
    if ( 0 != right.entity() ) { (*this) += *right.entity() ; }
    return *this ;
  }
Stat& Stat::operator+= ( const StatEntity right ) [inline]

increment with StatEntity object

Definition at line 256 of file Stat.h.

  {
    if ( 0 != m_entity ) { (*m_entity) += right ; }
    return *this ;
  }
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.

  {
    if ( 0 != m_entity ) { (*m_entity) += f ; }
    return *this ;
  }
Stat& Stat::operator-- ( int   ) [inline]

Post-decrement operator for the flag.

Definition at line 250 of file Stat.h.

  {
    if ( 0 != m_entity ) {   (*m_entity)-- ; }
    return *this ;
  }
Stat& Stat::operator-- (  ) [inline]

Pre-decrement operator for the flag.

Definition at line 244 of file Stat.h.

  {
    if ( 0 != m_entity ) { --(*m_entity)   ; }
    return *this ;
  }
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.

  {
    if ( 0 != m_entity ) { (*m_entity) -= f ; }
    return *this ;
  }
const StatEntity* Stat::operator-> (  ) const [inline]

dereference operaqtor

Definition at line 171 of file Stat.h.

{ return    entity()   ; }
Stat & Stat::operator= ( const Stat right )

Assignement operator.

Definition at line 146 of file Stat.cpp.

{
  if ( this == &right ) { return *this ; }
  m_entity = right.m_entity ;
  m_tag    = right.m_tag    ;
  m_group  = right.m_group  ;
  {
    IStatSvc* stat= right.m_stat ;
    if ( 0 !=   stat ) {   stat -> addRef()  ; }
    if ( 0 != m_stat ) { m_stat -> release() ; m_stat = 0 ; }
    m_stat = stat ;
  }
  {
    ICounterSvc* counter= right.m_counter ;
    if ( 0 !=    counter ) {   counter -> addRef()  ; }
    if ( 0 !=  m_counter ) { m_counter -> release() ; m_counter = 0 ; }
    m_counter = counter ;
  }
  return *this ;
}
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.

{
  if ( m_group.empty() && m_tag.empty() ) 
  { return  0 == m_entity ? ( o << "NULL" ) : ( o << m_entity ) ; }
  if ( !m_group.empty() ) 
  {
    if ( 0 != m_entity ) 
    { 
      return o << boost::format(" %|1$15s|::%|2$-15s| %|32t|%3%") 
        % ( "\"" + m_group ) % ( m_tag + "\"") % (*m_entity) ;
    }
    else
    {
      return o << boost::format(" %|1$15s|::%|2$-15s| %|32t|%NULL%") 
        % ( "\"" + m_group ) % ( m_tag + "\"") ;
    }
  }
  if ( 0 != m_entity )
  {
    return o << boost::format(" %|1$=30s| %|32t|%2%") 
      % ("\"" + m_tag + "\"" ) % (*m_entity) ;
  }
  return o << boost::format(" %|1$=30s| %|32t|%NULL%") 
    % ( "\"" + m_tag + "\"" ) ; 
}
std::string Stat::toString (  ) const

representation as string

Definition at line 178 of file Stat.cpp.

{
  std::ostringstream ost ;
  print ( ost )  ;
  return ost.str () ;
}

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 Tue May 10 2011 18:55:10 for Gaudi Framework, version v22r2 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004