32 ,
m_header (
" Counter :: Group | # | sum | mean/eff^* | rms/err^* | min | max |")
34 ,
m_format1 (
" %|15.15s|%|-15.15s|%|32t||%|10d| |%|11.7g| |%|#11.5g| |%|#11.5g| |%|#12.5g| |%|#12.5g| |" )
36 ,
m_format2 (
"*%|15.15s|%|-15.15s|%|32t||%|10d| |%|11.5g| |(%|#9.7g| +- %|-#9.7g|)%%| ------- | ------- |" )
43 "The header row for the output Stat-table" ) ;
47 "The format for the regular row in the output Stat-table" ) ;
51 "The format for the regular row in the outptu Stat-table" ) ;
55 "Use the special format for printout of efficiency counters" ) ;
96 Counter*& refpCounter )
override ;
111 longlong initial_value = 0 )
override ;
143 Printout& printer)
const override;
153 Printout& printer)
const override;
161 (
const Counter* pCounter,
162 Printout& printer)
const override;
170 (
const CountObject& pCounter,
171 Printout& printer)
const override;
179 const Counter* pCounter)
const override ;
188 return k.second ==
c;
190 if (j!=
i.second.end())
return {
i.first, j->first } ;
196 inline size_t num ()
const
206 void print ()
const ;
231 ( const
std::
string& grp ,
232 const
std::
string& nam )
const
234 auto i = m_counts.find ( grp ) ;
235 if ( m_counts.end() ==
i ) {
return nullptr ; }
236 auto j =
i->second.find ( nam ) ;
237 if (
i->second.end() == j ) {
return nullptr ; }
251 return CountObject{ j.second,
i->first, j.first };
261 #pragma warning(push)
262 #pragma warning(disable:2259)
268 Counter*& refpCounter )
271 refpCounter =
get ( grp , nam ) ;
272 if ( refpCounter ) {
return COUNTER_EXISTS ; }
274 auto newc =
new Counter() ;
276 if ( 0 != initial_value ) {
277 refpCounter->addFlag ( static_cast<double>(initial_value) ) ;
280 auto i = m_counts.find ( grp ) ;
282 if ( m_counts.end() ==
i )
283 {
i = m_counts.emplace ( grp ,
NameMap() ).first ; }
285 i->second.emplace( nam , newc );
300 Counter* p =
nullptr;
301 StatusCode sc = create ( group, name, initial_value, p ) ;
302 if ( sc.
isSuccess() && p ) {
return CountObject ( p , group , name ) ; }
303 throw std::runtime_error(
"CounterSvc::Counter('"+group+
"::"+name+
"') exists already!");
312 auto i = m_counts.find ( grp ) ;
313 if ( m_counts.end() ==
i ) {
return COUNTER_NOT_PRESENT ; }
314 auto j =
i->second.find ( nam ) ;
315 if (
i->second.end() == j ) {
return COUNTER_NOT_PRESENT ; }
317 i->second.erase ( j ) ;
326 if (
m_counts.
end() ==
i ) {
return COUNTER_NOT_PRESENT ; }
327 for (
auto& j :
i->second )
delete j.second ;
337 for (
auto&
i :
m_counts )
remove (
i.first ).ignore () ;
347 Printout& printer)
const
349 const Counter*
c =
get( grp , nam ) ;
350 if ( !c ) {
return COUNTER_NOT_PRESENT ; }
352 return printer ( msgStream() , c ) ;
357 class conditionalPrint {
359 CounterSvc::Printout *printer;
362 conditionalPrint(CounterSvc::Printout &_p,
MsgStream &_l): printer(&_p), log(&_l) {}
364 void operator() (
const Pair &p) {
366 (*printer)(*
log, p.second).ignore();
376 Printout& printer )
const
378 auto i = m_counts.find ( grp ) ;
379 if ( m_counts.end() ==
i ) {
return COUNTER_NOT_PRESENT ; }
384 conditionalPrint(printer, msgStream()));
391 (
const Counter* pCounter,
392 Printout& printer )
const
394 return printer ( msgStream() , pCounter ) ;
400 (
const CountObject& refCounter,
401 Printout& printer)
const
402 {
return print( refCounter.counter() , printer ) ; }
410 for (
const auto&
i :
m_counts )
for (
const auto& j :
i.second )
411 sorted_map[ {
i.first, j.first } ] = j.second;
421 const Counter*
c )
const
424 auto p = _find ( c ) ;
427 << CountObject( const_cast<Counter*>(c) , p.first , p.second )
438 const auto _num =
num() ;
442 <<
"Number of counters : " << _num <<
endmsg
448 for (
const auto& j :
i.second ) {
449 if ( j.second ) sorted_map[ {
i.first, j.first} ] = j.second;
452 for (
const auto&
i : sorted_map ) {
std::pair< std::string, std::string > _find(const Counter *c) const
GaudiUtils::HashMap< std::string, NameMap > CountMap
Definition of the MsgStream class used to transmit messages.
virtual StatusCode remove()
Remove all known counter objects.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
std::string m_header
the header row
StatusCode finalize() override
bool isSuccess() const
Test for a status code of SUCCESS.
Counter * get(const std::string &group, const std::string &name) const override
Access an existing counter object.
bool m_useEffFormat
flag to use the special "efficiency" format
bool m_print
boolean flag to print statistics
std::string m_format2
format for "efficiency" statistical printout rows
Simple implementation of the abstract interface ICounterSvc.
#define DECLARE_COMPONENT(type)
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
StatusCode create(const std::string &group, const std::string &name, longlong initial_value, Counter *&refpCounter) override
Create a new counter object.
GaudiUtils::HashMap< std::string, Counter * > NameMap
const std::string & name() const override
Retrieve name of the service.
void print() const
"standard" printout a'la GaudiCommon
This class is used for returning status codes from appropriate routines.
CountMap m_counts
the actual map of counters
CounterSvc(const std::string &name, ISvcLocator *svcLoc)
Standard Constructor.
iterator find(const key_type &key)
std::string m_format1
format for regular statistical printout rows
StatusCode defaultPrintout(MsgStream &log, const Counter *pCounter) const override
Default Printout for counters.
Base class used to extend a class implementing other interfaces.
T back_inserter(T...args)
Common class providing an architecture-independent hash map.
MsgStream & msgStream() const
Return an uninitialized MsgStream.
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
MsgStream & always() const
shortcut for the method msgStream(MSG::ALWAYS)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
~CounterSvc() override
Standard destructor.
StatusCode finalize() override
Finalization.