| # Gaudi Framework, version v21r7 |

Home |  | Generated: 22 Jan 2010

# 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,Counter*> CounterSvc::NameMap`[private]`

Definition at line 216 of file CounterSvc.cpp.

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

Definition at line 217 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

virtual StatusCode CounterSvc::finalize | ( | void |  | ) | `[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   }

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 }

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 }

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 264 of file CounterSvc.cpp.

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

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 291 of file CounterSvc.cpp.

    00294 {
    00295   Counter* p = 0;
    00296   StatusCode sc = create ( group, name, initial_value, p ) ;
    00297   if ( sc.isSuccess() && 0 != p ) { return CountObject ( p , group , name ) ; }
    00298   throw std::runtime_error("CounterSvc::Counter('"+group+"::"+name+"') exists already!");
    00299 }

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 304 of file CounterSvc.cpp.

    00306 {
    00307   CountMap::iterator i = m_counts.find  ( grp ) ;
    00308   if (  m_counts.end() == i ) { return COUNTER_NOT_PRESENT ; }  // RETURN
    00309   NameMap::iterator  j = i->second.find ( nam ) ;
    00310   if ( i->second.end() == j ) { return COUNTER_NOT_PRESENT ; }  // RETURN
    00311   delete j->second ;
    00312   i->second.erase ( j ) ;
    00313   return StatusCode::SUCCESS ;
    00314 }

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 318 of file CounterSvc.cpp.

    00319 {
    00320   CountMap::iterator i = m_counts.find ( grp  ) ;
    00321   if (  m_counts.end() == i ) { return COUNTER_NOT_PRESENT ; }  // RETURN
    00322   for ( NameMap::iterator j = i->second.begin() ; i->second.end() != j ; ++j )
    00323   { delete j->second ; }
    00324   i->second.clear() ;
    00325   return StatusCode::SUCCESS ;
    00326 }

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

Remove all known counter objects.

Definition at line 330 of file CounterSvc.cpp.

    00331 {
    00332   // remove group by group
    00333   for ( CountMap::iterator i = m_counts.begin() ; m_counts.end() != i ; ++i )
    00334   { remove ( i->first ).ignore () ; }
    00335   m_counts.clear() ;
    00336   return StatusCode::SUCCESS;
    00337 }

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 342 of file CounterSvc.cpp.

    00345 {
    00346   const Counter* c = get( grp , nam ) ;
    00347   if ( 0 == c ) { return COUNTER_NOT_PRESENT ; }                  // RETURN
    00348   // create the stream and use it!
    00349   MsgStream log ( msgSvc() , name() ) ;
    00350   return printer ( log , c ) ;
    00351 }

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 373 of file CounterSvc.cpp.

    00375 {
    00376   CountMap::const_iterator i = m_counts.find ( grp ) ;
    00377   if ( m_counts.end() == i ) { return COUNTER_NOT_PRESENT ; }
    00378
    00379   MsgStream log(msgSvc(), name());
    00380   // Force printing in alphabetical order
    00381   typedef std::map<std::string, Counter*> sorted_map_t;
    00382   sorted_map_t sorted_map(i->second.begin(), i->second.end());
    00383   std::for_each(sorted_map.begin(), sorted_map.end(),
    00384                 conditionalPrint(printer, log));
    00385   return StatusCode::SUCCESS;   // RETURN
    00386 }

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 391 of file CounterSvc.cpp.

    00393 {
    00394   MsgStream log(msgSvc(), name() ) ;
    00395   return printer ( log , pCounter ) ;
    00396 }

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 401 of file CounterSvc.cpp.

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

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

Parameters:

  | printer | [IN] Print actor

Returns:
  StatusCode indicating failure or success.

Implements ICounterSvc.

Definition at line 407 of file CounterSvc.cpp.

    00408 {
    00409   MsgStream log ( msgSvc() , name() ) ;
    00410   // Force printing in alphabetical order
    00411   typedef std::map<std::pair<std::string,std::string>, Counter*> sorted_map_t;
    00412   sorted_map_t sorted_map;
    00413   for ( CountMap::const_iterator i = m_counts.begin(); i != m_counts.end(); ++i )
    00414   {
    00415     for ( NameMap::const_iterator j = i->second.begin() ; i->second.end() != j ; ++j )
    00416     {
    00417       sorted_map[std::make_pair(i->first, j->first)] = j->second;
    00418     }
    00419   }
    00420   std::for_each(sorted_map.begin(), sorted_map.end(),
    00421                 conditionalPrint(printer, log));
    00422   return StatusCode::SUCCESS;
    00423 }

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

Default Printout for counters.

Implements ICounterSvc.

Definition at line 428 of file CounterSvc.cpp.

    00430 {
    00431   if ( 0 == c ) { return StatusCode::FAILURE ; }
    00432   std::pair<std::string,std::string> p = _find ( c ) ;
    00433
    00434   log << MSG::ALWAYS
    00435       << CountObject( const_cast<Counter*>(c) , p.first , p.second )
    00436       << endmsg ;
    00437
    00438   return StatusCode::SUCCESS;
    00439 }

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   }

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 443 of file CounterSvc.cpp.

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

## Member Data Documentation

CountMap CounterSvc::m_counts`[private]`

the actual map of counters

Definition at line 219 of file CounterSvc.cpp.

bool CounterSvc::m_print`[private]`

boolean flag to print statistics

Definition at line 221 of file CounterSvc.cpp.

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

the header row

Definition at line 223 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.

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_v21r7/GaudiSvc/src/ChronoStatSvc/CounterSvc.cpp