CounterSvc Class Reference

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

Inheritance diagram for CounterSvc:
Collaboration diagram for CounterSvc:

Public Member Functions

 CounterSvc (const std::string &name, ISvcLocator *svcLoc)
 Standard Constructor. More...
 
virtual ~CounterSvc ()
 Standard destructor. More...
 
virtual StatusCode finalize ()
 Finalization. More...
 
virtual Counter * get (const std::string &group, const std::string &name) const
 Access an existing counter object. More...
 
virtual ICounterSvc::Counters get (const std::string &group) const
 get all counters form the given group: More...
 
virtual StatusCode create (const std::string &group, const std::string &name, longlong initial_value, Counter *&refpCounter)
 Create a new counter object. More...
 
virtual CountObject create (const std::string &group, const std::string &name, longlong initial_value=0)
 Create a new counter object. More...
 
virtual StatusCode remove (const std::string &group, const std::string &name)
 Remove a counter object. More...
 
virtual StatusCode remove (const std::string &group)
 Remove all counters of a given group. More...
 
virtual StatusCode remove ()
 Remove all known counter objects. More...
 
virtual StatusCode print (const std::string &group, const std::string &name, Printout &printer) const
 Print counter value. More...
 
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. More...
 
virtual StatusCode print (const Counter *pCounter, Printout &printer) const
 Print counter value. More...
 
virtual StatusCode print (const CountObject &pCounter, Printout &printer) const
 Print counter value. More...
 
virtual StatusCode print (Printout &printer) const
 
virtual StatusCode defaultPrintout (MsgStream &log, const Counter *pCounter) const
 Default Printout for counters. More...
 
void print () const
 "standard" printout a'la GaudiCommon More...
 
- Public Member Functions inherited from extends< BASE, Interfaces >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces...>
 ~extend_interfaces () override=default
 Virtual destructor. More...
 
 ~extend_interfaces () override=default
 Virtual destructor. More...
 

Private Types

typedef GaudiUtils::HashMap< std::string, Counter * > NameMap
 
typedef GaudiUtils::HashMap< std::string, NameMapCountMap
 

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 More...
 
bool m_print
 boolean flag to print statistics More...
 
std::string m_header
 the header row More...
 
std::string m_format1
 format for regular statistical printout rows More...
 
std::string m_format2
 format for "efficiency" statistical printout rows More...
 
bool m_useEffFormat
 flag to use the special "efficiency" format More...
 

Additional Inherited Members

- Public Types inherited from extends< BASE, Interfaces >
typedef extends base_class
 Typedef to this class. More...
 
typedef extend_interfaces< Interfaces...> extend_interfaces_base
 Typedef to the base of this class. More...
 
typedef extends base_class
 Typedef to this class. More...
 
typedef extend_interfaces< Interfaces...> extend_interfaces_base
 Typedef to the base of this class. More...
 
- Public Types inherited from extend_interfaces< Interfaces...>
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 

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

Member Typedef Documentation

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

Definition at line 213 of file CounterSvc.cpp.

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

Definition at line 212 of file CounterSvc.cpp.

Constructor & Destructor Documentation

CounterSvc::CounterSvc ( const std::string &  name,
ISvcLocator svcLoc 
)
inline

Standard Constructor.

Definition at line 27 of file CounterSvc.cpp.

29  : base_class(name, svcLoc)
30  , m_counts ()
31  , m_print ( true )
32  //
33  // the header row
34  , m_header ( " Counter :: Group | # | sum | mean/eff^* | rms/err^* | min | max |")
35  // format for regular statistical printout rows
36  , m_format1 ( " %|15.15s|%|-15.15s|%|32t||%|10d| |%|11.7g| |%|#11.5g| |%|#11.5g| |%|#12.5g| |%|#12.5g| |" )
37  // format for "efficiency" statistical printout rows
38  , m_format2 ( "*%|15.15s|%|-15.15s|%|32t||%|10d| |%|11.5g| |(%|#9.7g| +- %|-#9.7g|)%%| ------- | ------- |" )
39  // flag to use the special "efficiency" format
40  , m_useEffFormat ( true )
41  //
42  {
43  declareProperty ("PrintStat" , m_print ) ;
44  //
45  declareProperty
46  ( "StatTableHeader" , m_header ,
47  "The header row for the output Stat-table" ) ;
48  //
49  declareProperty
50  ( "RegularRowFormat" , m_format1 ,
51  "The format for the regular row in the output Stat-table" ) ;
52  //
53  declareProperty
54  ( "EfficiencyRowFormat" , m_format2 ,
55  "The format for the regular row in the outptu Stat-table" ) ;
56  //
57  declareProperty
58  ( "UseEfficiencyRowFormat" , m_useEffFormat ,
59  "Use the special format for printout of efficiency counters" ) ;
60  }
std::string m_header
the header row
Definition: CounterSvc.cpp:219
bool m_useEffFormat
flag to use the special "efficiency" format
Definition: CounterSvc.cpp:225
bool m_print
boolean flag to print statistics
Definition: CounterSvc.cpp:217
std::string m_format2
format for "efficiency" statistical printout rows
Definition: CounterSvc.cpp:223
extends base_class
Typedef to this class.
Definition: extends.h:14
CountMap m_counts
the actual map of counters
Definition: CounterSvc.cpp:215
std::string m_format1
format for regular statistical printout rows
Definition: CounterSvc.cpp:221
virtual CounterSvc::~CounterSvc ( )
inlinevirtual

Standard destructor.

Definition at line 62 of file CounterSvc.cpp.

62 { remove().ignore() ; }

Member Function Documentation

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

Definition at line 186 of file CounterSvc.cpp.

187  {
188  if ( c ) {
189  for ( const auto& i : m_counts ) {
190  auto j = std::find_if( i.second.begin(), i.second.end(),
191  [&](const NameMap::value_type& k) {
192  return k.second == c;
193  });
194  if (j!=i.second.end()) return { i.first, j->first } ;
195  }
196  }
197  return { };
198  }
tuple c
Definition: gaudirun.py:392
std::pair< const K, T > value_type
Definition: Map.h:94
CountMap m_counts
the actual map of counters
Definition: CounterSvc.cpp:215
list i
Definition: ana.py:128
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.

Definition at line 269 of file CounterSvc.cpp.

273 {
274  // try to find existing counter:
275  refpCounter = get ( grp , nam ) ;
276  if ( refpCounter ) { return COUNTER_EXISTS ; } // RETURN
277  // create the new counter
278  Counter* newc = new Counter() ;
279  refpCounter = newc ;
280  if ( 0 != initial_value ) {
281  refpCounter->addFlag ( static_cast<double>(initial_value) ) ; // icc remark #2259
282  }
283  // find a proper group
284  auto i = m_counts.find ( grp ) ;
285  // (create a group if needed)
286  if ( m_counts.end() == i )
287  { i = m_counts.emplace ( grp , NameMap() ).first ; }
288  // insert new counter with proper name into proper group:
289  i->second.emplace( nam , newc );
290  return StatusCode::SUCCESS ; // RETURN
291 }
std::pair< iterator, bool > emplace(Args &&...args)
Definition: Map.h:166
GaudiUtils::HashMap< std::string, Counter * > NameMap
Definition: CounterSvc.cpp:212
iterator end()
Definition: Map.h:132
CountMap m_counts
the actual map of counters
Definition: CounterSvc.cpp:215
iterator find(const key_type &key)
Definition: Map.h:149
list i
Definition: ana.py:128
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.

Definition at line 300 of file CounterSvc.cpp.

303 {
304  Counter* p = nullptr;
305  StatusCode sc = create ( group, name, initial_value, p ) ;
306  if ( sc.isSuccess() && 0 != p ) { return CountObject ( p , group , name ) ; }
307  throw std::runtime_error("CounterSvc::Counter('"+group+"::"+name+"') exists already!");
308 }
virtual StatusCode create(const std::string &group, const std::string &name, longlong initial_value, Counter *&refpCounter)
Create a new counter object.
Definition: CounterSvc.cpp:269
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
StatusCode CounterSvc::defaultPrintout ( MsgStream log,
const Counter *  pCounter 
) const
virtual

Default Printout for counters.

Definition at line 428 of file CounterSvc.cpp.

430 {
431  if ( !c ) { return StatusCode::FAILURE ; }
432  auto p = _find ( c ) ;
433 
434  log << MSG::ALWAYS
435  << CountObject( const_cast<Counter*>(c) , p.first , p.second )
436  << endmsg ;
437 
438  return StatusCode::SUCCESS;
439 }
std::pair< std::string, std::string > _find(const Counter *c) const
Definition: CounterSvc.cpp:186
tuple c
Definition: gaudirun.py:392
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
virtual StatusCode CounterSvc::finalize ( )
inlinevirtual

Finalization.

< finalize the base class

Definition at line 64 of file CounterSvc.cpp.

65  {
66  if ( outputLevel() <= MSG::DEBUG || m_print ) { print () ; }
67  remove().ignore() ;
68  // finalize the base class
69  return Service::finalize() ;
70  }
StatusCode finalize() override
Definition: Service.cpp:187
bool m_print
boolean flag to print statistics
Definition: CounterSvc.cpp:217
void print() const
"standard" printout a'la GaudiCommon
Definition: CounterSvc.cpp:443
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).

Definition at line 235 of file CounterSvc.cpp.

237 {
238  auto i = m_counts.find ( grp ) ;
239  if ( m_counts.end() == i ) { return nullptr ; } // RETURN
240  auto j = i->second.find ( nam ) ;
241  if ( i->second.end() == j ) { return nullptr ; } // RETURN
242  return j->second ; // RETURN
243 }
iterator end()
Definition: Map.h:132
CountMap m_counts
the actual map of counters
Definition: CounterSvc.cpp:215
iterator find(const key_type &key)
Definition: Map.h:149
list i
Definition: ana.py:128
ICounterSvc::Counters CounterSvc::get ( const std::string &  group) const
virtual

get all counters form the given group:

Definition at line 247 of file CounterSvc.cpp.

248 {
249  ICounterSvc::Counters result ;
250  auto i = m_counts.find ( group ) ;
251  if ( i != m_counts.end() ) {
252  std::transform( i->second.begin(), i->second.end(),
253  std::back_inserter(result),
254  [&](const NameMap::value_type& j) {
255  return CountObject{ j.second, i->first, j.first };
256  } );
257  }
258  return result ;
259 }
std::vector< CountObject > Counters
the actual type of vectors of initialized counters
Definition: ICounterSvc.h:99
iterator end()
Definition: Map.h:132
std::pair< const K, T > value_type
Definition: Map.h:94
CountMap m_counts
the actual map of counters
Definition: CounterSvc.cpp:215
iterator find(const key_type &key)
Definition: Map.h:149
list i
Definition: ana.py:128
size_t CounterSvc::num ( ) const
inlineprivate

Definition at line 200 of file CounterSvc.cpp.

201  {
202  return std::accumulate( m_counts.begin(), m_counts.end(), size_t{0},
203  [](size_t r, const CountMap::value_type& i) {
204  return r + std::count_if(i.second.begin(),i.second.end(),
205  [](const NameMap::value_type& j) -> bool { return j.second; });
206  });
207  }
iterator end()
Definition: Map.h:132
std::pair< const K, T > value_type
Definition: Map.h:94
CountMap m_counts
the actual map of counters
Definition: CounterSvc.cpp:215
iterator begin()
Definition: Map.h:131
list i
Definition: ana.py:128
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.

Definition at line 349 of file CounterSvc.cpp.

352 {
353  const Counter* c = get( grp , nam ) ;
354  if ( !c ) { return COUNTER_NOT_PRESENT ; } // RETURN
355  // create the stream and use it!
356  MsgStream log ( msgSvc() , name() ) ;
357  return printer ( log , c ) ;
358 }
tuple c
Definition: gaudirun.py:392
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
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.

Definition at line 380 of file CounterSvc.cpp.

382 {
383  auto i = m_counts.find ( grp ) ;
384  if ( m_counts.end() == i ) { return COUNTER_NOT_PRESENT ; }
385 
386  MsgStream log(msgSvc(), name());
387  // Force printing in alphabetical order
388  std::map<std::string, Counter*> sorted_map(i->second.begin(), i->second.end());
389  std::for_each(sorted_map.begin(), sorted_map.end(),
390  conditionalPrint(printer, log));
391  return StatusCode::SUCCESS; // RETURN
392 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
iterator end()
Definition: Map.h:132
CountMap m_counts
the actual map of counters
Definition: CounterSvc.cpp:215
iterator find(const key_type &key)
Definition: Map.h:149
list i
Definition: ana.py:128
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.

Definition at line 397 of file CounterSvc.cpp.

399 {
400  MsgStream log(msgSvc(), name() ) ;
401  return printer ( log , pCounter ) ;
402 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
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.

Definition at line 407 of file CounterSvc.cpp.

409 { return print( refCounter.counter() , printer ) ; }
void print() const
"standard" printout a'la GaudiCommon
Definition: CounterSvc.cpp:443
StatusCode CounterSvc::print ( Printout &  printer) const
virtual
Parameters
printer[IN] Print actor
Returns
StatusCode indicating failure or success.

Definition at line 413 of file CounterSvc.cpp.

414 {
415  MsgStream log ( msgSvc() , name() ) ;
416  // Force printing in alphabetical order
417  std::map<std::pair<std::string,std::string>, Counter*> sorted_map;
418  for ( const auto& i : m_counts ) for ( const auto& j : i.second )
419  sorted_map[ { i.first, j.first } ] = j.second;
420  std::for_each(sorted_map.begin(), sorted_map.end(),
421  conditionalPrint(printer, log));
422  return StatusCode::SUCCESS;
423 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
CountMap m_counts
the actual map of counters
Definition: CounterSvc.cpp:215
list i
Definition: ana.py:128
void CounterSvc::print ( ) const

"standard" printout a'la GaudiCommon

Definition at line 443 of file CounterSvc.cpp.

444 {
445  MsgStream log ( msgSvc() , name() ) ;
446  // number of counters
447  const auto _num = num() ;
448  if ( 0 != _num )
449  {
450  log << MSG::ALWAYS
451  << "Number of counters : " << _num << endmsg
452  << m_header << endmsg ;
453  }
454  // Force printing in alphabetical order
455  std::map<std::pair<std::string,std::string>, Counter*> sorted_map;
456  for ( const auto& i : m_counts ) {
457  for ( const auto& j : i.second ) {
458  if ( j.second ) sorted_map[ {i.first, j.first} ] = j.second;
459  }
460  }
461  for ( const auto& i : sorted_map ) {
462  log << Gaudi::Utils::formatAsTableRow( i.first.second
463  , i.first.first
464  , *i.second
466  , m_format1
467  , m_format2 )
468  << endmsg ;
469  }
470 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
std::string m_header
the header row
Definition: CounterSvc.cpp:219
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
bool m_useEffFormat
flag to use the special "efficiency" format
Definition: CounterSvc.cpp:225
std::string m_format2
format for "efficiency" statistical printout rows
Definition: CounterSvc.cpp:223
CountMap m_counts
the actual map of counters
Definition: CounterSvc.cpp:215
std::string m_format1
format for regular statistical printout rows
Definition: CounterSvc.cpp:221
GAUDI_API std::string formatAsTableRow(const StatEntity &counter, const bool flag, const std::string &format1=" |%|7d| |%|11.7g| |%|#11.5g| |%|#10.5g| |%|#10.5g| |%|#10.5g| |", const std::string &format2="*|%|7d| |%|11.5g| |(%|#9.7g| +- %|-#8.6g|)%%| ----- | ----- |")
print the counter in a form of the table row
Definition: StatEntity.cpp:299
size_t num() const
Definition: CounterSvc.cpp:200
list i
Definition: ana.py:128
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.

Definition at line 313 of file CounterSvc.cpp.

315 {
316  auto i = m_counts.find ( grp ) ;
317  if ( m_counts.end() == i ) { return COUNTER_NOT_PRESENT ; } // RETURN
318  auto j = i->second.find ( nam ) ;
319  if ( i->second.end() == j ) { return COUNTER_NOT_PRESENT ; } // RETURN
320  delete j->second ;
321  i->second.erase ( j ) ;
322  return StatusCode::SUCCESS ;
323 }
iterator end()
Definition: Map.h:132
CountMap m_counts
the actual map of counters
Definition: CounterSvc.cpp:215
iterator find(const key_type &key)
Definition: Map.h:149
list i
Definition: ana.py:128
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.

Definition at line 327 of file CounterSvc.cpp.

328 {
329  auto i = m_counts.find ( grp ) ;
330  if ( m_counts.end() == i ) { return COUNTER_NOT_PRESENT ; } // RETURN
331  for ( auto& j : i->second ) delete j.second ;
332  i->second.clear() ;
333  return StatusCode::SUCCESS ;
334 }
iterator end()
Definition: Map.h:132
CountMap m_counts
the actual map of counters
Definition: CounterSvc.cpp:215
iterator find(const key_type &key)
Definition: Map.h:149
list i
Definition: ana.py:128
StatusCode CounterSvc::remove ( )
virtual

Remove all known counter objects.

Definition at line 338 of file CounterSvc.cpp.

339 {
340  // remove group by group
341  for ( auto& i : m_counts ) remove ( i.first ).ignore () ;
342  m_counts.clear() ;
343  return StatusCode::SUCCESS;
344 }
CountMap m_counts
the actual map of counters
Definition: CounterSvc.cpp:215
list i
Definition: ana.py:128

Member Data Documentation

CountMap CounterSvc::m_counts
private

the actual map of counters

Definition at line 215 of file CounterSvc.cpp.

std::string CounterSvc::m_format1
private

format for regular statistical printout rows

Definition at line 221 of file CounterSvc.cpp.

std::string CounterSvc::m_format2
private

format for "efficiency" statistical printout rows

Definition at line 223 of file CounterSvc.cpp.

std::string CounterSvc::m_header
private

the header row

Definition at line 219 of file CounterSvc.cpp.

bool CounterSvc::m_print
private

boolean flag to print statistics

Definition at line 217 of file CounterSvc.cpp.

bool CounterSvc::m_useEffFormat
private

flag to use the special "efficiency" format

Definition at line 225 of file CounterSvc.cpp.


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