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...
 
 ~CounterSvc () override
 Standard destructor. More...
 
StatusCode finalize () override
 Finalization. More...
 
Counter * get (const std::string &group, const std::string &name) const override
 Access an existing counter object. More...
 
ICounterSvc::Counters get (const std::string &group) const override
 get all counters form the given group: More...
 
StatusCode create (const std::string &group, const std::string &name, longlong initial_value, Counter *&refpCounter) override
 Create a new counter object. More...
 
CountObject create (const std::string &group, const std::string &name, longlong initial_value=0) override
 Create a new counter object. More...
 
StatusCode remove (const std::string &group, const std::string &name) override
 Remove a counter object. More...
 
StatusCode remove (const std::string &group) override
 Remove all counters of a given group. More...
 
virtual StatusCode remove ()
 Remove all known counter objects. More...
 
StatusCode print (const std::string &group, const std::string &name, Printout &printer) const override
 Print counter value. More...
 
StatusCode print (const std::string &group, Printout &printer) const override
 If no such counter exists the return code is COUNTER_NOT_PRESENT Note: This call is not direct access. More...
 
StatusCode print (const Counter *pCounter, Printout &printer) const override
 Print counter value. More...
 
StatusCode print (const CountObject &pCounter, Printout &printer) const override
 Print counter value. More...
 
StatusCode print (Printout &printer) const override
 
StatusCode defaultPrintout (MsgStream &log, const Counter *pCounter) const override
 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 = true
 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 = true
 flag to use the special "efficiency" format More...
 

Additional Inherited Members

- Public Types inherited from extends< BASE, Interfaces >
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 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 208 of file CounterSvc.cpp.

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

Definition at line 207 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  // the header row
31  , m_header ( " Counter :: Group | # | sum | mean/eff^* | rms/err^* | min | max |")
32  // format for regular statistical printout rows
33  , m_format1 ( " %|15.15s|%|-15.15s|%|32t||%|10d| |%|11.7g| |%|#11.5g| |%|#11.5g| |%|#12.5g| |%|#12.5g| |" )
34  // format for "efficiency" statistical printout rows
35  , m_format2 ( "*%|15.15s|%|-15.15s|%|32t||%|10d| |%|11.5g| |(%|#9.7g| +- %|-#9.7g|)%%| ------- | ------- |" )
36  //
37  {
38  declareProperty ("PrintStat" , m_print ) ;
39  //
40  declareProperty
41  ( "StatTableHeader" , m_header ,
42  "The header row for the output Stat-table" ) ;
43  //
44  declareProperty
45  ( "RegularRowFormat" , m_format1 ,
46  "The format for the regular row in the output Stat-table" ) ;
47  //
48  declareProperty
49  ( "EfficiencyRowFormat" , m_format2 ,
50  "The format for the regular row in the outptu Stat-table" ) ;
51  //
52  declareProperty
53  ( "UseEfficiencyRowFormat" , m_useEffFormat ,
54  "Use the special format for printout of efficiency counters" ) ;
55  }
std::string m_header
the header row
Definition: CounterSvc.cpp:214
bool m_useEffFormat
flag to use the special "efficiency" format
Definition: CounterSvc.cpp:220
bool m_print
boolean flag to print statistics
Definition: CounterSvc.cpp:212
std::string m_format2
format for "efficiency" statistical printout rows
Definition: CounterSvc.cpp:218
extends base_class
Typedef to this class.
Definition: extends.h:14
std::string m_format1
format for regular statistical printout rows
Definition: CounterSvc.cpp:216
CounterSvc::~CounterSvc ( )
inlineoverride

Standard destructor.

Definition at line 57 of file CounterSvc.cpp.

57 { remove().ignore() ; }

Member Function Documentation

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

Definition at line 181 of file CounterSvc.cpp.

182  {
183  if ( c ) {
184  for ( const auto& i : m_counts ) {
185  auto j = std::find_if( i.second.begin(), i.second.end(),
186  [&](const NameMap::value_type& k) {
187  return k.second == c;
188  });
189  if (j!=i.second.end()) return { i.first, j->first } ;
190  }
191  }
192  return { };
193  }
tuple c
Definition: gaudirun.py:391
std::pair< const K, T > value_type
Definition: Map.h:94
CountMap m_counts
the actual map of counters
Definition: CounterSvc.cpp:210
list i
Definition: ana.py:128
StatusCode CounterSvc::create ( const std::string &  group,
const std::string &  name,
longlong  initial_value,
Counter *&  refpCounter 
)
override

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

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

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

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

Default Printout for counters.

Definition at line 423 of file CounterSvc.cpp.

425 {
426  if ( !c ) { return StatusCode::FAILURE ; }
427  auto p = _find ( c ) ;
428 
429  log << MSG::ALWAYS
430  << CountObject( const_cast<Counter*>(c) , p.first , p.second )
431  << endmsg ;
432 
433  return StatusCode::SUCCESS;
434 }
std::pair< std::string, std::string > _find(const Counter *c) const
Definition: CounterSvc.cpp:181
tuple c
Definition: gaudirun.py:391
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
StatusCode CounterSvc::finalize ( )
inlineoverride

Finalization.

< finalize the base class

Definition at line 59 of file CounterSvc.cpp.

60  {
61  if ( outputLevel() <= MSG::DEBUG || m_print ) { print () ; }
62  remove().ignore() ;
63  // finalize the base class
64  return Service::finalize() ;
65  }
StatusCode finalize() override
Definition: Service.cpp:188
bool m_print
boolean flag to print statistics
Definition: CounterSvc.cpp:212
void print() const
"standard" printout a'la GaudiCommon
Definition: CounterSvc.cpp:438
CounterSvc::Counter * CounterSvc::get ( const std::string &  group,
const std::string &  name 
) const
override

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

232 {
233  auto i = m_counts.find ( grp ) ;
234  if ( m_counts.end() == i ) { return nullptr ; } // RETURN
235  auto j = i->second.find ( nam ) ;
236  if ( i->second.end() == j ) { return nullptr ; } // RETURN
237  return j->second ; // RETURN
238 }
iterator end()
Definition: Map.h:132
CountMap m_counts
the actual map of counters
Definition: CounterSvc.cpp:210
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
override

get all counters form the given group:

Definition at line 242 of file CounterSvc.cpp.

243 {
244  ICounterSvc::Counters result ;
245  auto i = m_counts.find ( group ) ;
246  if ( i != m_counts.end() ) {
247  std::transform( i->second.begin(), i->second.end(),
248  std::back_inserter(result),
249  [&](const NameMap::value_type& j) {
250  return CountObject{ j.second, i->first, j.first };
251  } );
252  }
253  return result ;
254 }
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:210
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 195 of file CounterSvc.cpp.

196  {
197  return std::accumulate( m_counts.begin(), m_counts.end(), size_t{0},
198  [](size_t r, const CountMap::value_type& i) {
199  return r + std::count_if(i.second.begin(),i.second.end(),
200  [](const NameMap::value_type& j) -> bool { return j.second; });
201  });
202  }
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:210
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
override

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

347 {
348  const Counter* c = get( grp , nam ) ;
349  if ( !c ) { return COUNTER_NOT_PRESENT ; } // RETURN
350  // create the stream and use it!
351  MsgStream log ( msgSvc() , name() ) ;
352  return printer ( log , c ) ;
353 }
tuple c
Definition: gaudirun.py:391
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode CounterSvc::print ( const std::string &  group,
Printout &  printer 
) const
override

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

377 {
378  auto i = m_counts.find ( grp ) ;
379  if ( m_counts.end() == i ) { return COUNTER_NOT_PRESENT ; }
380 
381  MsgStream log(msgSvc(), name());
382  // Force printing in alphabetical order
383  std::map<std::string, Counter*> sorted_map(i->second.begin(), i->second.end());
384  std::for_each(sorted_map.begin(), sorted_map.end(),
385  conditionalPrint(printer, log));
386  return StatusCode::SUCCESS; // RETURN
387 }
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:210
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
override

Print counter value.

Parameters
pCounter[IN] Pointer to Counter object
printer[IN] Print actor
Returns
StatusCode indicating failure or success.

Definition at line 392 of file CounterSvc.cpp.

394 {
395  MsgStream log(msgSvc(), name() ) ;
396  return printer ( log , pCounter ) ;
397 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode CounterSvc::print ( const CountObject &  pCounter,
Printout &  printer 
) const
override

Print counter value.

Parameters
refCounter[IN] Reference to CountObject object
printer[IN] Print actor
Returns
StatusCode indicating failure or success.

Definition at line 402 of file CounterSvc.cpp.

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

Definition at line 408 of file CounterSvc.cpp.

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

"standard" printout a'la GaudiCommon

Definition at line 438 of file CounterSvc.cpp.

439 {
440  MsgStream log ( msgSvc() , name() ) ;
441  // number of counters
442  const auto _num = num() ;
443  if ( 0 != _num )
444  {
445  log << MSG::ALWAYS
446  << "Number of counters : " << _num << endmsg
447  << m_header << endmsg ;
448  }
449  // Force printing in alphabetical order
450  std::map<std::pair<std::string,std::string>, Counter*> sorted_map;
451  for ( const auto& i : m_counts ) {
452  for ( const auto& j : i.second ) {
453  if ( j.second ) sorted_map[ {i.first, j.first} ] = j.second;
454  }
455  }
456  for ( const auto& i : sorted_map ) {
457  log << Gaudi::Utils::formatAsTableRow( i.first.second
458  , i.first.first
459  , *i.second
461  , m_format1
462  , m_format2 )
463  << endmsg ;
464  }
465 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
std::string m_header
the header row
Definition: CounterSvc.cpp:214
bool m_useEffFormat
flag to use the special "efficiency" format
Definition: CounterSvc.cpp:220
std::string m_format2
format for "efficiency" statistical printout rows
Definition: CounterSvc.cpp:218
CountMap m_counts
the actual map of counters
Definition: CounterSvc.cpp:210
std::string m_format1
format for regular statistical printout rows
Definition: CounterSvc.cpp:216
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:195
list i
Definition: ana.py:128
StatusCode CounterSvc::remove ( const std::string &  group,
const std::string &  name 
)
override

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

310 {
311  auto i = m_counts.find ( grp ) ;
312  if ( m_counts.end() == i ) { return COUNTER_NOT_PRESENT ; } // RETURN
313  auto j = i->second.find ( nam ) ;
314  if ( i->second.end() == j ) { return COUNTER_NOT_PRESENT ; } // RETURN
315  delete j->second ;
316  i->second.erase ( j ) ;
317  return StatusCode::SUCCESS ;
318 }
iterator end()
Definition: Map.h:132
CountMap m_counts
the actual map of counters
Definition: CounterSvc.cpp:210
iterator find(const key_type &key)
Definition: Map.h:149
list i
Definition: ana.py:128
StatusCode CounterSvc::remove ( const std::string &  group)
override

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

323 {
324  auto i = m_counts.find ( grp ) ;
325  if ( m_counts.end() == i ) { return COUNTER_NOT_PRESENT ; } // RETURN
326  for ( auto& j : i->second ) delete j.second ;
327  i->second.clear() ;
328  return StatusCode::SUCCESS ;
329 }
iterator end()
Definition: Map.h:132
CountMap m_counts
the actual map of counters
Definition: CounterSvc.cpp:210
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 333 of file CounterSvc.cpp.

334 {
335  // remove group by group
336  for ( auto& i : m_counts ) remove ( i.first ).ignore () ;
337  m_counts.clear() ;
338  return StatusCode::SUCCESS;
339 }
CountMap m_counts
the actual map of counters
Definition: CounterSvc.cpp:210
list i
Definition: ana.py:128

Member Data Documentation

CountMap CounterSvc::m_counts
private

the actual map of counters

Definition at line 210 of file CounterSvc.cpp.

std::string CounterSvc::m_format1
private

format for regular statistical printout rows

Definition at line 216 of file CounterSvc.cpp.

std::string CounterSvc::m_format2
private

format for "efficiency" statistical printout rows

Definition at line 218 of file CounterSvc.cpp.

std::string CounterSvc::m_header
private

the header row

Definition at line 214 of file CounterSvc.cpp.

bool CounterSvc::m_print = true
private

boolean flag to print statistics

Definition at line 212 of file CounterSvc.cpp.

bool CounterSvc::m_useEffFormat = true
private

flag to use the special "efficiency" format

Definition at line 220 of file CounterSvc.cpp.


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