| # Gaudi Framework, version v22r0 |

Home |  | Generated: 9 Feb 2011

# CounterSvc Class Reference

Simple imeplementation of the abstract interface ICounterSvc. More...

Inheritance diagram for CounterSvc:
[legend]
Collaboration diagram for CounterSvc:
[legend]

List of all members.

## Public Member Functions
| CounterSvc (const std::string &name, ISvcLocator *svcLoc)
| Standard Constructor.
virtual | ~CounterSvc ()
| Standard destructor.
virtual StatusCode | finalize ()
| Finalization.
virtual Counter * | get (const std::string &group, const std::string &name) const
| Access an existing counter object.
virtual ICounterSvc::Counters | get (const std::string &group) const
| get all counters form the given group:
virtual StatusCode | create (const std::string &group, const std::string &name, longlong initial_value, Counter *&refpCounter)
| Create a new counter object.
virtual CountObject | create (const std::string &group, const std::string &name, longlong initial_value=0)
| Create a new counter object.
virtual StatusCode | remove (const std::string &group, const std::string &name)
| Remove a counter object.
virtual StatusCode | remove (const std::string &group)
| Remove all counters of a given group.
virtual StatusCode | remove ()
| Remove all known counter objects.
virtual StatusCode | print (const std::string &group, const std::string &name, Printout &printer) const
| Print counter value.
virtual StatusCode | print (const std::string &group, Printout &printer) const
| If no such counter exists the return code is COUNTER_NOT_PRESENT Note: This call is not direct access.
virtual StatusCode | print (const Counter *pCounter, Printout &printer) const
| Print counter value.
virtual StatusCode | print (const CountObject &pCounter, Printout &printer) const
| Print counter value.
virtual StatusCode | print (Printout &printer) const
virtual StatusCode | defaultPrintout (MsgStream &log, const Counter *pCounter) const
| Default Printout for counters.
void | print () const
| "standard" printout a'la GaudiCommon
## Private Types
typedef GaudiUtils::HashMap < std::string, Counter * > | NameMap
typedef GaudiUtils::HashMap < std::string, NameMap > | CountMap
## Private Member Functions
std::pair< std::string, std::string > | _find (const Counter *c) const
size_t | num () const
## Private Attributes
CountMap | m_counts
| the actual map of counters
bool | m_print
| boolean flag to print statistics
std::string | m_header
| the header row
std::string | m_format1
| format for regular statistical printout rows
std::string | m_format2
| format for "efficiency" statistical printout rows
bool | m_useEffFormat
| flag to use the special "efficiency" format

## Detailed Description

Simple imeplementation of the abstract interface ICounterSvc.

Author:
  Markus FRANK
  Vanya BELYAEV ibelyaev@physics.syr.edu

Date:
  2007-05-25

Definition at line 27 of file CounterSvc.cpp.

## Member Typedef Documentation

typedef GaudiUtils::HashMap<std::string,NameMap> CounterSvc::CountMap`[private]`

Definition at line 217 of file CounterSvc.cpp.

typedef GaudiUtils::HashMap<std::string,Counter*> CounterSvc::NameMap`[private]`

Definition at line 216 of file CounterSvc.cpp.

## Constructor & Destructor Documentation

CounterSvc::CounterSvc | ( | const std::string & | name,
|  | ISvcLocator * | svcLoc |
| ) |  |  | `[inline]`

Standard Constructor.

Definition at line 30 of file CounterSvc.cpp.

    00032     : base_class(name, svcLoc)
    00033     , m_counts ()
    00034     , m_print  ( true )
    00035     //
    00036     // the header row
    00037     , m_header  ( "       Counter :: Group         |     #     |    sum     | mean/eff^* | rms/err^*  |     min     |     max     |")
    00038     // format for regular statistical printout rows
    00039     , m_format1 ( " %|15.15s|%|-15.15s|%|32t||%|10d| |%|11.7g| |%|#11.5g| |%|#11.5g| |%|#12.5g| |%|#12.5g| |"         )
    00040     // format for "efficiency" statistical printout rows
    00041     , m_format2 ( "*%|15.15s|%|-15.15s|%|32t||%|10d| |%|11.5g| |(%|#9.7g| +- %|-#9.7g|)%%|   -------   |   -------   |" )
    00042     // flag to use the special "efficiency" format
    00043     , m_useEffFormat ( true )
    00044     //
    00045   {
    00046     declareProperty ("PrintStat" , m_print ) ;
    00047     //
    00048     declareProperty
    00049       ( "StatTableHeader"        , m_header                          ,
    00050         "The header row for the output Stat-table"                   ) ;
    00051     //
    00052     declareProperty
    00053       ( "RegularRowFormat"       , m_format1                         ,
    00054         "The format for the regular row in the output Stat-table"    ) ;
    00055     //
    00056     declareProperty
    00057       ( "EfficiencyRowFormat"    , m_format2                         ,
    00058         "The format for the regular row in the outptu Stat-table"    ) ;
    00059     //
    00060     declareProperty
    00061       ( "UseEfficiencyRowFormat" , m_useEffFormat                    ,
    00062         "Use the special format for printout of efficiency counters" ) ;
    00063   }

virtual CounterSvc::~CounterSvc | ( |  | ) | `[inline, virtual]`

Standard destructor.

Definition at line 65 of file CounterSvc.cpp.

    00065 { remove().ignore() ; }

## Member Function Documentation

std::pair<std::string,std::string> CounterSvc::_find | ( | const Counter * | c | ) | const`[inline, private]`

Definition at line 189 of file CounterSvc.cpp.

    00190   {
    00191     if ( 0 == c ) { return std::pair<std::string,std::string>() ; }
    00192     for ( CountMap::const_iterator i = m_counts.begin() ; m_counts.end() != i ; ++i )
    00193     {
    00194       for ( NameMap::const_iterator j = i->second.begin() ; i->second.end() != j ; ++j )
    00195       { if ( j->second == c ) { return std::make_pair( i->first , j->first )  ; } }
    00196     }
    00197     return std::pair<std::string,std::string>() ;
    00198   }

CounterSvc::CountObject CounterSvc::create | ( | const std::string & | group,
|  | const std::string & | name,
|  | longlong | initial_value = `0` |
| ) |  |  | `[virtual]`

Create a new counter object.

If the counter object exists already, a std::runtime_error exception is thrown. The ownership of the actual counter stays with the service.

Parameters:

  | group | [IN] Hint for smart printing
  | name | [IN] Counter name
  | initial_value | [IN] Initial counter value
  | refpCounter | [OUT] Reference to store pointer to counter.

Returns:
  Fully initialized CountObject.

Implements ICounterSvc.

Definition at line 300 of file CounterSvc.cpp.

    00303 {
    00304   Counter* p = 0;
    00305   StatusCode sc = create ( group, name, initial_value, p ) ;
    00306   if ( sc.isSuccess() && 0 != p ) { return CountObject ( p , group , name ) ; }
    00307   throw std::runtime_error("CounterSvc::Counter('"+group+"::"+name+"') exists already!");
    00308 }

StatusCode CounterSvc::create | ( | const std::string & | group,
|  | const std::string & | name,
|  | longlong | initial_value,
|  | Counter *& | refpCounter |
| ) |  |  | `[virtual]`

Create a new counter object.

If the counter object exists already the existing object is returned. In this event the return code is COUNTER_EXISTS. The ownership of the actual counter stays with the service.

Parameters:

  | group | [IN] Hint for smart printing
  | name | [IN] Counter name
  | initial_value | [IN] Initial counter value
  | refpCounter | [OUT] Reference to store pointer to counter.

Returns:
  StatusCode indicating failure or success.

Implements ICounterSvc.

Definition at line 269 of file CounterSvc.cpp.

    00273 {
    00274   // try to find existing counter:
    00275   refpCounter = get ( grp , nam ) ;
    00276   if ( 0 != refpCounter ) { return COUNTER_EXISTS ; }                // RETURN
    00277   // create the new counter
    00278   Counter* newc = new Counter() ;
    00279   refpCounter = newc ;
    00280   if ( 0 != initial_value ) {
    00281     refpCounter->addFlag ( static_cast<double>(initial_value) ) ; // icc remark #2259
    00282   }
    00283   // find a proper group
    00284   CountMap::iterator i = m_counts.find  ( grp ) ;
    00285   // (create a group if needed)
    00286   if (  m_counts.end() == i )
    00287   { i = m_counts.insert ( std::make_pair ( grp , NameMap() ) ).first ; }
    00288   // insert new counter with proper name into proper group:
    00289   i->second.insert( std::make_pair( nam , newc ) ).first ;
    00290   return StatusCode::SUCCESS ;                                     // RETURN
    00291 }

StatusCode CounterSvc::defaultPrintout | ( | MsgStream & | log,
|  | const Counter * | pCounter |
| ) |  |  | const`[virtual]`

Default Printout for counters.

Implements ICounterSvc.

Definition at line 437 of file CounterSvc.cpp.

    00439 {
    00440   if ( 0 == c ) { return StatusCode::FAILURE ; }
    00441   std::pair<std::string,std::string> p = _find ( c ) ;
    00442
    00443   log << MSG::ALWAYS
    00444       << CountObject( const_cast<Counter*>(c) , p.first , p.second )
    00445       << endmsg ;
    00446
    00447   return StatusCode::SUCCESS;
    00448 }

virtual StatusCode CounterSvc::finalize | ( |  | ) | `[inline, virtual]`

Finalization.

< finalize the base class

Reimplemented from Service.

Definition at line 67 of file CounterSvc.cpp.

    00068   {
    00069     if ( outputLevel() <= MSG::DEBUG || m_print ) { print () ; }
    00070     remove().ignore() ;
    00071     // finalize the base class
    00072     return Service::finalize() ;
    00073   }

ICounterSvc::Counters CounterSvc::get | ( | const std::string & | group | ) | const`[virtual]`

get all counters form the given group:

Implements ICounterSvc.

Definition at line 251 of file CounterSvc.cpp.

    00252 {
    00253   ICounterSvc::Counters result ;
    00254   CountMap::const_iterator i = m_counts.find  ( group ) ;
    00255   if (  m_counts.end() == i ) { return result ; } // RETURN
    00256   for ( NameMap::const_iterator j = i->second.begin() ; i->second.end() != j ; ++j )
    00257   { result.push_back( CountObject ( j->second, i->first , j->first ) ) ; }
    00258   return result ;
    00259 }

CounterSvc::Counter * CounterSvc::get | ( | const std::string & | group,
|  | const std::string & | name |
| ) |  |  | const`[virtual]`

Access an existing counter object.

Parameters:

  | group | [IN] Hint for smart printing
  | name | [IN] Counter name

Returns:
  Pointer to existing counter object (NULL if non existing).

Implements ICounterSvc.

Definition at line 239 of file CounterSvc.cpp.

    00241 {
    00242   CountMap::const_iterator i = m_counts.find  ( grp ) ;
    00243   if (  m_counts.end() == i ) { return 0 ; }                    // RETURN
    00244   NameMap::const_iterator  j = i->second.find ( nam ) ;
    00245   if ( i->second.end() == j ) { return 0 ; }                    // RETURN
    00246   return j->second ;                                            // RETURN
    00247 }

size_t CounterSvc::num | ( |  | ) | const`[inline, private]`

Definition at line 200 of file CounterSvc.cpp.

    00201   {
    00202     size_t result = 0 ;
    00203     {
    00204       for ( CountMap::const_iterator i = m_counts.begin(); i != m_counts.end(); ++i )
    00205       {
    00206         for ( NameMap::const_iterator j = i->second.begin() ; i->second.end() != j ; ++j )
    00207         { if ( 0 != j->second ) { ++result ; } ; }
    00208       }
    00209     }
    00210     return result ;
    00211   }

void CounterSvc::print | ( |  | ) | const

"standard" printout a'la GaudiCommon

Definition at line 452 of file CounterSvc.cpp.

    00453 {
    00454   MsgStream log ( msgSvc() , name() ) ;
    00455   // number of counters
    00456   const size_t _num = num() ;
    00457   if ( 0 != _num )
    00458   {
    00459     log << MSG::ALWAYS
    00460         << "Number of counters : "  << _num << endmsg
    00461         << m_header << endmsg ;
    00462   }
    00463   {
    00464     // Force printing in alphabetical order
    00465     typedef std::map<std::pair<std::string,std::string>, Counter*> sorted_map_t;
    00466     sorted_map_t sorted_map;
    00467     for ( CountMap::const_iterator i = m_counts.begin(); i != m_counts.end(); ++i )
    00468     {
    00469       for ( NameMap::const_iterator j = i->second.begin() ; i->second.end() != j ; ++j )
    00470       {
    00471         Counter* c = j->second ;
    00472         if ( 0 == c ) { continue ; }
    00473         sorted_map[std::make_pair(i->first, j->first)] = c;
    00474       }
    00475     }
    00476     for (sorted_map_t::const_iterator i = sorted_map.begin(); i != sorted_map.end(); ++i )
    00477       log << Gaudi::Utils::formatAsTableRow( i->first.second
    00478                                            , i->first.first
    00479                                            , *i->second
    00480                                            , m_useEffFormat
    00481                                            , m_format1
    00482                                            , m_format2 )
    00483           << endmsg ;
    00484   }
    00485 }

StatusCode CounterSvc::print | ( | Printout & | printer | ) | const`[virtual]`

Parameters:

  | printer | [IN] Print actor

Returns:
  StatusCode indicating failure or success.

Implements ICounterSvc.

Definition at line 416 of file CounterSvc.cpp.

    00417 {
    00418   MsgStream log ( msgSvc() , name() ) ;
    00419   // Force printing in alphabetical order
    00420   typedef std::map<std::pair<std::string,std::string>, Counter*> sorted_map_t;
    00421   sorted_map_t sorted_map;
    00422   for ( CountMap::const_iterator i = m_counts.begin(); i != m_counts.end(); ++i )
    00423   {
    00424     for ( NameMap::const_iterator j = i->second.begin() ; i->second.end() != j ; ++j )
    00425     {
    00426       sorted_map[std::make_pair(i->first, j->first)] = j->second;
    00427     }
    00428   }
    00429   std::for_each(sorted_map.begin(), sorted_map.end(),
    00430                 conditionalPrint(printer, log));
    00431   return StatusCode::SUCCESS;
    00432 }

StatusCode CounterSvc::print | ( | const CountObject & | pCounter,
|  | Printout & | printer |
| ) |  |  | const`[virtual]`

Print counter value.

Parameters:

  | refCounter | [IN] Reference to CountObject object
  | printer | [IN] Print actor

Returns:
  StatusCode indicating failure or success.

Implements ICounterSvc.

Definition at line 410 of file CounterSvc.cpp.

    00412 { return print( refCounter.counter() , printer ) ; }

StatusCode CounterSvc::print | ( | const Counter * | pCounter,
|  | Printout & | printer |
| ) |  |  | const`[virtual]`

Print counter value.

Parameters:

  | pCounter | [IN] Pointer to Counter object
  | printer | [IN] Print actor

Returns:
  StatusCode indicating failure or success.

Implements ICounterSvc.

Definition at line 400 of file CounterSvc.cpp.

    00402 {
    00403   MsgStream log(msgSvc(), name() ) ;
    00404   return printer ( log , pCounter ) ;
    00405 }

StatusCode CounterSvc::print | ( | const std::string & | group,
|  | Printout & | printer |
| ) |  |  | const`[virtual]`

If no such counter exists the return code is COUNTER_NOT_PRESENT Note: This call is not direct access.

Parameters:

  | group | [IN] Hint for smart printing
  | printer | [IN] Print actor

Returns:
  StatusCode indicating failure or success.

Implements ICounterSvc.

Definition at line 382 of file CounterSvc.cpp.

    00384 {
    00385   CountMap::const_iterator i = m_counts.find ( grp ) ;
    00386   if ( m_counts.end() == i ) { return COUNTER_NOT_PRESENT ; }
    00387
    00388   MsgStream log(msgSvc(), name());
    00389   // Force printing in alphabetical order
    00390   typedef std::map<std::string, Counter*> sorted_map_t;
    00391   sorted_map_t sorted_map(i->second.begin(), i->second.end());
    00392   std::for_each(sorted_map.begin(), sorted_map.end(),
    00393                 conditionalPrint(printer, log));
    00394   return StatusCode::SUCCESS;   // RETURN
    00395 }

StatusCode CounterSvc::print | ( | const std::string & | group,
|  | const std::string & | name,
|  | Printout & | printer |
| ) |  |  | const`[virtual]`

Print counter value.

Parameters:

  | group | [IN] Hint for smart printing
  | name | [IN] Counter name
  | printer | [IN] Print actor

Returns:
  StatusCode indicating failure or success.

Implements ICounterSvc.

Definition at line 351 of file CounterSvc.cpp.

    00354 {
    00355   const Counter* c = get( grp , nam ) ;
    00356   if ( 0 == c ) { return COUNTER_NOT_PRESENT ; }                  // RETURN
    00357   // create the stream and use it!
    00358   MsgStream log ( msgSvc() , name() ) ;
    00359   return printer ( log , c ) ;
    00360 }

StatusCode CounterSvc::remove | ( |  | ) | `[virtual]`

Remove all known counter objects.

Definition at line 339 of file CounterSvc.cpp.

    00340 {
    00341   // remove group by group
    00342   for ( CountMap::iterator i = m_counts.begin() ; m_counts.end() != i ; ++i )
    00343   { remove ( i->first ).ignore () ; }
    00344   m_counts.clear() ;
    00345   return StatusCode::SUCCESS;
    00346 }

StatusCode CounterSvc::remove | ( | const std::string & | group | ) | `[virtual]`

Remove all counters of a given group.

If no such counter exists the return code is COUNTER_NOT_PRESENT

Parameters:

  | group | [IN] Hint for smart printing

Returns:
  StatusCode indicating failure or success.

Implements ICounterSvc.

Definition at line 327 of file CounterSvc.cpp.

    00328 {
    00329   CountMap::iterator i = m_counts.find ( grp  ) ;
    00330   if (  m_counts.end() == i ) { return COUNTER_NOT_PRESENT ; }  // RETURN
    00331   for ( NameMap::iterator j = i->second.begin() ; i->second.end() != j ; ++j )
    00332   { delete j->second ; }
    00333   i->second.clear() ;
    00334   return StatusCode::SUCCESS ;
    00335 }

StatusCode CounterSvc::remove | ( | const std::string & | group,
|  | const std::string & | name |
| ) |  |  | `[virtual]`

Remove a counter object.

If the counter object does not exists, the return code is COUNTER_NOT_PRESENT. The counter may not be used anymore after this call.

Parameters:

  | group | [IN] Hint for smart printing
  | name | [IN] Counter name
  | initial_value | [IN] Initial counter value
  | refpCounter | [OUT] Reference to store pointer to counter.

Returns:
  StatusCode indicating failure or success.

Implements ICounterSvc.

Definition at line 313 of file CounterSvc.cpp.

    00315 {
    00316   CountMap::iterator i = m_counts.find  ( grp ) ;
    00317   if (  m_counts.end() == i ) { return COUNTER_NOT_PRESENT ; }  // RETURN
    00318   NameMap::iterator  j = i->second.find ( nam ) ;
    00319   if ( i->second.end() == j ) { return COUNTER_NOT_PRESENT ; }  // RETURN
    00320   delete j->second ;
    00321   i->second.erase ( j ) ;
    00322   return StatusCode::SUCCESS ;
    00323 }

## Member Data Documentation

CountMap CounterSvc::m_counts`[private]`

the actual map of counters

Definition at line 219 of file CounterSvc.cpp.

std::string CounterSvc::m_format1`[private]`

format for regular statistical printout rows

Definition at line 225 of file CounterSvc.cpp.

std::string CounterSvc::m_format2`[private]`

format for "efficiency" statistical printout rows

Definition at line 227 of file CounterSvc.cpp.

std::string CounterSvc::m_header`[private]`

the header row

Definition at line 223 of file CounterSvc.cpp.

bool CounterSvc::m_print`[private]`

boolean flag to print statistics

Definition at line 221 of file CounterSvc.cpp.

bool CounterSvc::m_useEffFormat`[private]`

flag to use the special "efficiency" format

Definition at line 229 of file CounterSvc.cpp.

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v22r0/GaudiSvc/src/ChronoStatSvc/CounterSvc.cpp

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines