|
Gaudi Framework, version v23r2 |
| Home | Generated: Thu Jun 28 2012 |
Simple implementation of the abstract interface ICounterSvc. More...


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 | |
Simple implementation of the abstract interface ICounterSvc.
Definition at line 27 of file CounterSvc.cpp.
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.
| CounterSvc::CounterSvc | ( | const std::string & | name, |
| ISvcLocator * | svcLoc | ||
| ) | [inline] |
Standard Constructor.
Definition at line 30 of file CounterSvc.cpp.
: base_class(name, svcLoc) , m_counts () , m_print ( true ) // // the header row , m_header ( " Counter :: Group | # | sum | mean/eff^* | rms/err^* | min | max |") // format for regular statistical printout rows , m_format1 ( " %|15.15s|%|-15.15s|%|32t||%|10d| |%|11.7g| |%|#11.5g| |%|#11.5g| |%|#12.5g| |%|#12.5g| |" ) // format for "efficiency" statistical printout rows , m_format2 ( "*%|15.15s|%|-15.15s|%|32t||%|10d| |%|11.5g| |(%|#9.7g| +- %|-#9.7g|)%%| ------- | ------- |" ) // flag to use the special "efficiency" format , m_useEffFormat ( true ) // { declareProperty ("PrintStat" , m_print ) ; // declareProperty ( "StatTableHeader" , m_header , "The header row for the output Stat-table" ) ; // declareProperty ( "RegularRowFormat" , m_format1 , "The format for the regular row in the output Stat-table" ) ; // declareProperty ( "EfficiencyRowFormat" , m_format2 , "The format for the regular row in the outptu Stat-table" ) ; // declareProperty ( "UseEfficiencyRowFormat" , m_useEffFormat , "Use the special format for printout of efficiency counters" ) ; }
| virtual CounterSvc::~CounterSvc | ( | ) | [inline, virtual] |
| std::pair<std::string,std::string> CounterSvc::_find | ( | const Counter * | c ) | const [inline, private] |
Definition at line 189 of file CounterSvc.cpp.
{
if ( 0 == c ) { return std::pair<std::string,std::string>() ; }
for ( CountMap::const_iterator i = m_counts.begin() ; m_counts.end() != i ; ++i )
{
for ( NameMap::const_iterator j = i->second.begin() ; i->second.end() != j ; ++j )
{ if ( j->second == c ) { return std::make_pair( i->first , j->first ) ; } }
}
return std::pair<std::string,std::string>() ;
}
| 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.
| group | [IN] Hint for smart printing |
| name | [IN] Counter name |
| initial_value | [IN] Initial counter value |
| refpCounter | [OUT] Reference to store pointer to counter. |
Implements ICounterSvc.
Definition at line 300 of file CounterSvc.cpp.
{
Counter* p = 0;
StatusCode sc = create ( group, name, initial_value, p ) ;
if ( sc.isSuccess() && 0 != p ) { return CountObject ( p , group , name ) ; }
throw std::runtime_error("CounterSvc::Counter('"+group+"::"+name+"') exists already!");
}
| 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.
| group | [IN] Hint for smart printing |
| name | [IN] Counter name |
| initial_value | [IN] Initial counter value |
| refpCounter | [OUT] Reference to store pointer to counter. |
Implements ICounterSvc.
Definition at line 269 of file CounterSvc.cpp.
{
// try to find existing counter:
refpCounter = get ( grp , nam ) ;
if ( 0 != refpCounter ) { return COUNTER_EXISTS ; } // RETURN
// create the new counter
Counter* newc = new Counter() ;
refpCounter = newc ;
if ( 0 != initial_value ) {
refpCounter->addFlag ( static_cast<double>(initial_value) ) ; // icc remark #2259
}
// find a proper group
CountMap::iterator i = m_counts.find ( grp ) ;
// (create a group if needed)
if ( m_counts.end() == i )
{ i = m_counts.insert ( std::make_pair ( grp , NameMap() ) ).first ; }
// insert new counter with proper name into proper group:
i->second.insert( std::make_pair( nam , newc ) ).first ;
return StatusCode::SUCCESS ; // RETURN
}
| StatusCode CounterSvc::defaultPrintout | ( | MsgStream & | log, |
| const Counter * | pCounter | ||
| ) | const [virtual] |
Default Printout for counters.
Implements ICounterSvc.
Definition at line 437 of file CounterSvc.cpp.
{
if ( 0 == c ) { return StatusCode::FAILURE ; }
std::pair<std::string,std::string> p = _find ( c ) ;
log << MSG::ALWAYS
<< CountObject( const_cast<Counter*>(c) , p.first , p.second )
<< endmsg ;
return StatusCode::SUCCESS;
}
| virtual StatusCode CounterSvc::finalize | ( | ) | [inline, virtual] |
Finalization.
< finalize the base class
Reimplemented from Service.
Definition at line 67 of file CounterSvc.cpp.
{
if ( outputLevel() <= MSG::DEBUG || m_print ) { print () ; }
remove().ignore() ;
// finalize the base class
return Service::finalize() ;
}
| CounterSvc::Counter * CounterSvc::get | ( | const std::string & | group, |
| const std::string & | name | ||
| ) | const [virtual] |
Access an existing counter object.
| group | [IN] Hint for smart printing |
| name | [IN] Counter name |
Implements ICounterSvc.
Definition at line 239 of file CounterSvc.cpp.
{
CountMap::const_iterator i = m_counts.find ( grp ) ;
if ( m_counts.end() == i ) { return 0 ; } // RETURN
NameMap::const_iterator j = i->second.find ( nam ) ;
if ( i->second.end() == j ) { return 0 ; } // RETURN
return j->second ; // RETURN
}
| 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.
{
ICounterSvc::Counters result ;
CountMap::const_iterator i = m_counts.find ( group ) ;
if ( m_counts.end() == i ) { return result ; } // RETURN
for ( NameMap::const_iterator j = i->second.begin() ; i->second.end() != j ; ++j )
{ result.push_back( CountObject ( j->second, i->first , j->first ) ) ; }
return result ;
}
| size_t CounterSvc::num | ( | ) | const [inline, private] |
Definition at line 200 of file CounterSvc.cpp.
| 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.
| group | [IN] Hint for smart printing |
| printer | [IN] Print actor |
Implements ICounterSvc.
Definition at line 382 of file CounterSvc.cpp.
{
CountMap::const_iterator i = m_counts.find ( grp ) ;
if ( m_counts.end() == i ) { return COUNTER_NOT_PRESENT ; }
MsgStream log(msgSvc(), name());
// Force printing in alphabetical order
typedef std::map<std::string, Counter*> sorted_map_t;
sorted_map_t sorted_map(i->second.begin(), i->second.end());
std::for_each(sorted_map.begin(), sorted_map.end(),
conditionalPrint(printer, log));
return StatusCode::SUCCESS; // RETURN
}
| StatusCode CounterSvc::print | ( | const std::string & | group, |
| const std::string & | name, | ||
| Printout & | printer | ||
| ) | const [virtual] |
Print counter value.
| group | [IN] Hint for smart printing |
| name | [IN] Counter name |
| printer | [IN] Print actor |
Implements ICounterSvc.
Definition at line 351 of file CounterSvc.cpp.
| StatusCode CounterSvc::print | ( | const Counter * | pCounter, |
| Printout & | printer | ||
| ) | const [virtual] |
Print counter value.
| pCounter | [IN] Pointer to Counter object |
| printer | [IN] Print actor |
Implements ICounterSvc.
Definition at line 400 of file CounterSvc.cpp.
| StatusCode CounterSvc::print | ( | Printout & | printer ) | const [virtual] |
| printer | [IN] Print actor |
Implements ICounterSvc.
Definition at line 416 of file CounterSvc.cpp.
{
MsgStream log ( msgSvc() , name() ) ;
// Force printing in alphabetical order
typedef std::map<std::pair<std::string,std::string>, Counter*> sorted_map_t;
sorted_map_t sorted_map;
for ( CountMap::const_iterator i = m_counts.begin(); i != m_counts.end(); ++i )
{
for ( NameMap::const_iterator j = i->second.begin() ; i->second.end() != j ; ++j )
{
sorted_map[std::make_pair(i->first, j->first)] = j->second;
}
}
std::for_each(sorted_map.begin(), sorted_map.end(),
conditionalPrint(printer, log));
return StatusCode::SUCCESS;
}
| void CounterSvc::print | ( | ) | const |
"standard" printout a'la GaudiCommon
Definition at line 452 of file CounterSvc.cpp.
{
MsgStream log ( msgSvc() , name() ) ;
// number of counters
const size_t _num = num() ;
if ( 0 != _num )
{
log << MSG::ALWAYS
<< "Number of counters : " << _num << endmsg
<< m_header << endmsg ;
}
{
// Force printing in alphabetical order
typedef std::map<std::pair<std::string,std::string>, Counter*> sorted_map_t;
sorted_map_t sorted_map;
for ( CountMap::const_iterator i = m_counts.begin(); i != m_counts.end(); ++i )
{
for ( NameMap::const_iterator j = i->second.begin() ; i->second.end() != j ; ++j )
{
Counter* c = j->second ;
if ( 0 == c ) { continue ; }
sorted_map[std::make_pair(i->first, j->first)] = c;
}
}
for (sorted_map_t::const_iterator i = sorted_map.begin(); i != sorted_map.end(); ++i )
log << Gaudi::Utils::formatAsTableRow( i->first.second
, i->first.first
, *i->second
, m_useEffFormat
, m_format1
, m_format2 )
<< endmsg ;
}
}
| StatusCode CounterSvc::print | ( | const CountObject & | pCounter, |
| Printout & | printer | ||
| ) | const [virtual] |
Print counter value.
| refCounter | [IN] Reference to CountObject object |
| printer | [IN] Print actor |
Implements ICounterSvc.
Definition at line 410 of file CounterSvc.cpp.
{ return print( refCounter.counter() , printer ) ; }
| 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
| group | [IN] Hint for smart printing |
Implements ICounterSvc.
Definition at line 327 of file CounterSvc.cpp.
{
CountMap::iterator i = m_counts.find ( grp ) ;
if ( m_counts.end() == i ) { return COUNTER_NOT_PRESENT ; } // RETURN
for ( NameMap::iterator j = i->second.begin() ; i->second.end() != j ; ++j )
{ delete j->second ; }
i->second.clear() ;
return StatusCode::SUCCESS ;
}
| StatusCode CounterSvc::remove | ( | ) | [virtual] |
Remove all known counter objects.
Definition at line 339 of file CounterSvc.cpp.
| 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.
| group | [IN] Hint for smart printing |
| name | [IN] Counter name |
| initial_value | [IN] Initial counter value |
| refpCounter | [OUT] Reference to store pointer to counter. |
Implements ICounterSvc.
Definition at line 313 of file CounterSvc.cpp.
{
CountMap::iterator i = m_counts.find ( grp ) ;
if ( m_counts.end() == i ) { return COUNTER_NOT_PRESENT ; } // RETURN
NameMap::iterator j = i->second.find ( nam ) ;
if ( i->second.end() == j ) { return COUNTER_NOT_PRESENT ; } // RETURN
delete j->second ;
i->second.erase ( j ) ;
return StatusCode::SUCCESS ;
}
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.