Gaudi Framework, version v23r6

Home   Generated: Wed Jan 30 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
CounterSvc Class Reference

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

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

Public Member Functions

 CounterSvc (const std::string &name, ISvcLocator *svcLoc)
 Standard Constructor.
 
virtual ~CounterSvc ()
 Standard destructor.
 
virtual StatusCode finalize ()
 Finalization.
 
virtual Counterget (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
 
- Public Member Functions inherited from extends1< Service, ICounterSvc >
 extends1 (A1 a1, A2 a2, A3 a3)
 Templated constructor with 3 arguments.
 
 extends1 (A1 a1, A2 a2)
 Templated constructor with 2 arguments.
 
 extends1 (A1 a1)
 Templated constructor with 1 argument.
 
 extends1 ()
 Default constructor.
 
virtual void * i_cast (const InterfaceID &tid) const
 Implementation of IInterface::i_cast.
 
virtual StatusCode queryInterface (const InterfaceID &ti, void **pp)
 Implementation of IInterface::queryInterface.
 
virtual std::vector< std::stringgetInterfaceNames () const
 Implementation of IInterface::getInterfaceNames.
 
virtual ~extends1 ()
 Virtual destructor.
 
- Public Member Functions inherited from Service
virtual unsigned long release ()
 Release Interface instance.
 
virtual const std::stringname () const
 Retrieve name of the service.
 
virtual StatusCode configure ()
 
virtual StatusCode initialize ()
 
virtual StatusCode start ()
 
virtual StatusCode stop ()
 
virtual StatusCode terminate ()
 
virtual Gaudi::StateMachine::State FSMState () const
 
virtual Gaudi::StateMachine::State targetFSMState () const
 
virtual StatusCode reinitialize ()
 
virtual StatusCode restart ()
 
virtual StatusCode sysInitialize ()
 Initialize Service.
 
virtual StatusCode sysStart ()
 Initialize Service.
 
virtual StatusCode sysStop ()
 Initialize Service.
 
virtual StatusCode sysFinalize ()
 Finalize Service.
 
virtual StatusCode sysReinitialize ()
 Re-initialize the Service.
 
virtual StatusCode sysRestart ()
 Re-initialize the Service.
 
virtual StatusCode setProperty (const Property &p)
 
virtual StatusCode setProperty (const std::string &s)
 
virtual StatusCode setProperty (const std::string &n, const std::string &v)
 
virtual StatusCode getProperty (Property *p) const
 
virtual const PropertygetProperty (const std::string &name) const
 
virtual StatusCode getProperty (const std::string &n, std::string &v) const
 
virtual const std::vector
< Property * > & 
getProperties () const
 
template<class TYPE >
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
 Service (const std::string &name, ISvcLocator *svcloc)
 Standard Constructor.
 
SmartIF< ISvcLocator > & serviceLocator () const
 Retrieve pointer to service locator.
 
StatusCode setProperties ()
 Method for setting declared properties to the values specified for the job.
 
template<class T >
StatusCode service (const std::string &name, const T *&psvc, bool createIf=true) const
 Access a service by name, creating it if it doesn't already exist.
 
template<class T >
StatusCode service (const std::string &name, T *&psvc, bool createIf=true) const
 
template<class T >
StatusCode service (const std::string &svcType, const std::string &svcName, T *&psvc) const
 Access a service by name and type, creating it if it doesn't already exist.
 
template<class T >
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
 Declare the named property.
 
PropertydeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
 Declare remote named properties.
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked.
 
- Public Member Functions inherited from CommonMessaging< implements3< IService, IProperty, IStateful > >
 CommonMessaging (const A1 &a1, const A2 &a2, const A3 &a3)
 Templated constructor with 3 arguments.
 
 CommonMessaging (const A1 &a1, const A2 &a2)
 Templated constructor with 2 arguments.
 
 CommonMessaging (const A1 &a1)
 Templated constructor with 1 argument.
 
 CommonMessaging ()
 Default constructor.
 
virtual ~CommonMessaging ()
 Virtual destructor.
 
SmartIF< IMessageSvc > & msgSvc () const
 The standard message service.
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream.
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts.
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS)
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL)
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING)
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO)
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG)
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE)
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO)
 
MSG::Level msgLevel () const
 get the output level from the embedded MsgStream
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream
 
- Public Member Functions inherited from extend_interfaces1< ICounterSvc >
virtual ~extend_interfaces1 ()
 Virtual destructor.
 
- Public Member Functions inherited from ICounterSvc
 DeclareInterfaceID (ICounterSvc, 4, 0)
 InterfaceID.
 
- Public Member Functions inherited from IInterface
virtual unsigned long addRef ()=0
 Increment the reference count of Interface instance.
 
virtual unsigned long release ()=0
 Release Interface instance.
 
virtual unsigned long refCount () const =0
 Current reference count.
 
virtual ~IInterface ()
 Virtual destructor.
 

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
 

Additional Inherited Members

- Public Types inherited from extends1< Service, ICounterSvc >
typedef extends1 base_class
 Typedef to this class.
 
typedef extend_interfaces1
< ICounterSvc
extend_interfaces_base
 Typedef to the base of this class.
 
typedef
extend_interfaces_base::ext_iids 
interfaces
 MPL set of all the implemented interfaces.
 
- Static Public Member Functions inherited from IInterface
static const InterfaceIDinterfaceID ()
 Return an instance of InterfaceID identifying the interface.
 
- Protected Member Functions inherited from Service
virtual ~Service ()
 Standard Destructor.
 
int outputLevel () const
 get the Service's output level
 
- Protected Member Functions inherited from ICounterSvc
virtual ~ICounterSvc ()
 
- Protected Attributes inherited from Service
IntegerProperty m_outputLevel
 Service output level.
 
Gaudi::StateMachine::State m_state
 Service state.
 
Gaudi::StateMachine::State m_targetState
 Service state.
 

Detailed Description

Simple implementation of the abstract interface ICounterSvc.

Author
Markus FRANK
Vanya BELYAEV ibely.nosp@m.aev@.nosp@m.physi.nosp@m.cs.s.nosp@m.yr.ed.nosp@m.u
Date
2007-05-25

Definition at line 27 of file CounterSvc.cpp.

Member Typedef Documentation

Definition at line 217 of file CounterSvc.cpp.

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.

: 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 ) ;
//
( "StatTableHeader" , m_header ,
"The header row for the output Stat-table" ) ;
//
( "RegularRowFormat" , m_format1 ,
"The format for the regular row in the output Stat-table" ) ;
//
( "EfficiencyRowFormat" , m_format2 ,
"The format for the regular row in the outptu Stat-table" ) ;
//
( "UseEfficiencyRowFormat" , m_useEffFormat ,
"Use the special format for printout of efficiency counters" ) ;
}
virtual CounterSvc::~CounterSvc ( )
inlinevirtual

Standard destructor.

Definition at line 65 of file CounterSvc.cpp.

{ remove().ignore() ; }

Member Function Documentation

std::pair<std::string,std::string> CounterSvc::_find ( const Counter c) const
inlineprivate

Definition at line 189 of file CounterSvc.cpp.

{
if ( 0 == c ) { return std::pair<std::string,std::string>() ; }
{
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 ) ; } }
}
}
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.

{
// 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
// (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 ) );
return StatusCode::SUCCESS ; // RETURN
}
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.

{
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::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 ; }
log << MSG::ALWAYS
<< CountObject( const_cast<Counter*>(c) , p.first , p.second )
<< endmsg ;
}
virtual StatusCode CounterSvc::finalize ( )
inlinevirtual

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.

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.

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

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

Definition at line 200 of file CounterSvc.cpp.

{
size_t result = 0 ;
{
{
for ( NameMap::const_iterator j = i->second.begin() ; i->second.end() != j ; ++j )
{ if ( 0 != j->second ) { ++result ; } ; }
}
}
return result ;
}
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.

{
const Counter* c = get( grp , nam ) ;
if ( 0 == c ) { return COUNTER_NOT_PRESENT ; } // RETURN
// create the stream and use it!
MsgStream log ( msgSvc() , name() ) ;
return printer ( log , c ) ;
}
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.

{
if ( m_counts.end() == i ) { return COUNTER_NOT_PRESENT ; }
// 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 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.

{
return printer ( log , pCounter ) ;
}
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.

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

{
MsgStream log ( msgSvc() , name() ) ;
// Force printing in alphabetical order
sorted_map_t sorted_map;
{
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));
}
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 )
{
<< "Number of counters : " << _num << endmsg
<< m_header << endmsg ;
}
{
// Force printing in alphabetical order
sorted_map_t sorted_map;
{
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 )
, i->first.first
, *i->second
<< endmsg ;
}
}
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.

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

{
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() ;
}
StatusCode CounterSvc::remove ( )
virtual

Remove all known counter objects.

Definition at line 339 of file CounterSvc.cpp.

{
// remove group by group
for ( CountMap::iterator i = m_counts.begin() ; m_counts.end() != i ; ++i )
{ remove ( i->first ).ignore () ; }
}

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:

Generated at Wed Jan 30 2013 17:13:44 for Gaudi Framework, version v23r6 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004