51 #include "boost/format.hpp"
55 #pragma warning ( disable:4661 ) // incomplete explicit templates
62 template <
class PBASE>
69 m_header =
" | Counter | # | sum | mean/eff^* | rms/err^* | min | max |" ;
71 m_format1 =
" | %|-48.48s|%|50t||%|10d| |%|11.7g| |%|#11.5g| |%|#11.5g| |%|#12.5g| |%|#12.5g| |" ;
73 m_format2 =
" |*%|-48.48s|%|50t||%|10d| |%|11.5g| |(%|#9.6g| +- %|-#9.6g|)%%| ------- | ------- |" ;
75 m_useEffFormat = true ;
80 (
"ErrorsPrint" , m_errorsPrint ,
81 "Print the statistics of errors/warnings/exceptions")
82 -> declareUpdateHandler
86 (
"PropertiesPrint" , m_propsPrint ,
87 "Print the properties of the component ")
88 -> declareUpdateHandler
92 (
"StatPrint" , m_statPrint ,
93 "Print the table of counters" )
94 -> declareUpdateHandler
98 (
"TypePrint" , m_typePrint ,
99 "Add the actal C++ component type into the messages" ) ;
101 this->declareProperty (
"Context" , m_context ) ;
103 this->declareProperty (
"RootInTES" , m_rootInTES ) ;
107 this->declareProperty
108 (
"StatTableHeader" , m_header ,
109 "The header row for the output Stat-table" ) ;
111 this->declareProperty
112 (
"RegularRowFormat" , m_format1 ,
113 "The format for the regular row in the output Stat-table" ) ;
115 this->declareProperty
116 (
"EfficiencyRowFormat" , m_format2 ,
117 "The format for the regular row in the output Stat-table" ) ;
119 this->declareProperty
120 (
"UseEfficiencyRowFormat" , m_useEffFormat ,
121 "Use the special format for printout of efficiency counters" ) ;
125 this->declareProperty(
128 "RegEx list, of simple integer counters for CounterSummary.");
130 this->declareProperty(
133 "RegEx list, of StatEntity counters for CounterSummary.");
138 if (
const GaudiAlgorithm* gAlg = dynamic_cast<const GaudiAlgorithm*>(parent) )
140 m_context = gAlg->context();
141 m_rootInTES = gAlg->rootInTES();
143 else if (
const GaudiTool* gTool = dynamic_cast<const GaudiTool*> (parent) )
145 m_context = gTool->context();
146 m_rootInTES = gTool->rootInTES();
152 if (!jos.
isValid()) Exception(
"Cannot get JobOptionsSvc");
159 for (
const auto& iter : *myList )
164 if ( iter->name().compare(
"Context") == 0 ) {
165 m_context = sp->
value();
166 }
else if ( iter->name().compare(
"RootInTES") == 0 ) {
167 m_rootInTES = sp->
value();
179 template <
class PBASE >
192 {
return Error (
"Failed to initialise base class PBASE", sc ) ; }
199 if ( !context().empty() )
200 this->debug() <<
"Created with context = '" << context() <<
"'" <<
endmsg;
204 if ( !m_rootInTES.empty() &&
205 m_rootInTES.substr(m_rootInTES.size()-1) !=
"/" ) m_rootInTES +=
"/";
208 m_counterSummarySvc = this->svcLoc()->service(
"CounterSummarySvc",
false);
211 if (!m_counterSummarySvc)
212 this->debug() <<
"could not locate CounterSummarySvc, no counter summary will be made" <<
endmsg;
213 else this->debug() <<
"found CounterSummarySvc OK" <<
endmsg;
225 if (
"" != rootName &&
'/' != rootName[rootName.size() - 1]) {
226 rootName = rootName +
"/";
231 std::string result = fullTESLocation(location, UseRootInTES);
233 result = (result[0] ==
'/' ? result : rootName + result);
235 if (result != location && this->msgLevel(
MSG::DEBUG))
236 this->debug() <<
"Changing " << location <<
" to " << result <<
endmsg;
246 if (idhh == 0)
return;
250 r = m_f(
h->objKey());
251 if (r !=
h->objKey())
255 r = m_f(
h->objKey());
256 if (r !=
h->objKey())
264 this->m_updateDataHandles.reset(
new DHHFixer(fixLocation));
273 template <
class PBASE >
285 if ( this->msgLevel(
MSG::DEBUG) || (statPrint() && !counters().empty()) )
291 if(m_counterSummarySvc && this->svcLoc()->existsService(
"CounterSummarySvc"))
293 if ( this->msgLevel(
MSG::DEBUG) ) this->debug() <<
"adding counters to CounterSummarySvc" <<
endmsg;
298 for(
const auto&
i : this->counters() )
300 if (statList.Or(
i.first) )
301 m_counterSummarySvc->addCounter(this->name(),
i.first,
i.second,
303 else if (counterList.Or(
i.first))
304 m_counterSummarySvc->addCounter(this->name(),
i.first,
i.second);
310 this->debug() <<
"Tools to release :";
311 for (
const auto&
i : m_managedTools )
313 this->debug() <<
" " <<
i->name();
317 while ( !m_managedTools.empty() ) { sc = releaseTool( m_managedTools.back() ) && sc; }
322 this->debug() <<
"Services to release :";
323 for (
const auto&
i : m_services ) this->debug() <<
" " <<
i->name();
326 while ( !m_services.empty() ) { sc = releaseSvc( m_services.front() ) && sc; }
329 m_counterSummarySvc.reset();
332 if ( !m_errors.empty() || !m_warnings.empty() || !m_exceptions.empty() )
334 this->always() <<
"Exceptions/Errors/Warnings/Infos Statistics : "
335 << m_exceptions .size () <<
"/"
336 << m_errors .size () <<
"/"
337 << m_warnings .size () <<
"/"
338 << m_infos .size () <<
endmsg ;
339 if ( errorsPrint() ) { printErrors () ; }
344 m_counters .clear() ;
345 m_exceptions .clear() ;
347 m_warnings .clear() ;
349 m_counterList.clear() ;
350 m_statEntityList.clear() ;
353 return sc && PBASE::finalize();
364 template <
class PBASE >
368 {
return Error (
"release(IInterface):: IInterface* points to NULL!" ) ; }
372 return algTool ? releaseTool( algTool ) : releaseSvc( interface ) ;
379 template <
class PBASE >
383 {
return Error (
"releaseTool(IAlgTool):: IAlgTool* points to NULL!" ) ; }
384 if( !this->toolSvc() )
385 {
return Error (
"releaseTool(IAlgTool):: IToolSvc* points to NULL!" ) ; }
387 auto it =
std::find(m_managedTools.begin(), m_managedTools.end(), algTool);
388 if (m_managedTools.end() == it)
389 {
return Warning(
"releaseTool(IAlgTool):: IAlgTool* is not active" ) ; }
395 { this->debug() <<
"Releasing tool '" << name <<
"'" <<
endmsg; }
397 PBASE::deregisterTool(t);
398 m_managedTools.erase(it);
401 this->debug() <<
"The tool '" << t->
name() <<
"' of type '"
403 <<
"' is released" <<
endmsg;
408 Warning(
"releaseTool(IAlgTool):: error from IToolSvc releasing "+name , sc ) ;
415 template <
class PBASE >
418 if( !Svc )
return Error (
"releaseSvc(IInterface):: IInterface* points to NULL!" ) ;
420 if (!svc)
return Warning(
"releaseSvc(IInterface):: IInterface* is not a service" );
423 return Warning(
"releaseSvc(IInterface):: IInterface* is not active" );
426 this->debug() <<
"Releasing service '" << (*it)->name() <<
"'" <<
endmsg;
428 m_services.erase(it);
437 template <
class PBASE >
445 this->warning() <<
"Service " << svc->name() <<
" already present -- skipping" <<
endmsg;
458 template <
class PBASE >
461 const size_t mx )
const
464 const size_t num = ++m_errors[
msg] ;
466 if ( num > mx ) {
return st ; }
468 {
return Print (
"The ERROR message is suppressed : '" +
478 template <
class PBASE >
482 const size_t mx )
const
485 const size_t num = ++m_warnings[
msg] ;
487 if ( num > mx ) {
return st ; }
489 {
return Print (
"The WARNING message is suppressed : '" +
499 template <
class PBASE >
503 const size_t mx )
const
506 const size_t num = ++m_infos[
msg] ;
508 if ( num > mx ) {
return st ; }
510 {
return Print (
"The INFO message is suppressed : '" +
520 template <
class PBASE >
526 if ( !this->msgLevel( lvl ) ) {
return st ; }
529 MsgStream& str = this->msgStream( lvl ) ;
538 { str <<
" StatusCode=" << st.
getCode() ; }
540 { str <<
" StatusCode=FAILURE" ; }
553 template <
class PBASE >
559 ++m_exceptions[
msg ];
560 Print (
"Exception (re)throw: " + msg , sc ,
MSG::FATAL ).ignore();
568 template <
class PBASE >
574 ++m_exceptions[
msg ];
575 Print (
"Exception (re)throw: " + msg , sc ,
MSG::FATAL ).ignore();
583 template <
class PBASE >
588 ++m_exceptions[
msg ];
589 Print (
"Exception throw: " + msg , sc ,
MSG::FATAL ).ignore();
597 template <
class PBASE >
601 if ( counters().empty() ) {
return 0 ; }
602 MsgStream& msg = this->msgStream ( level ) ;
604 msg <<
"Number of counters : " << counters().size() ;
606 if ( !counters().empty() ) { msg <<
std::endl << m_header ; }
608 for (
const auto& entry : counters() )
615 m_format1 , m_format2 );
620 return counters().size() ;
627 template <
class PBASE >
631 boost::format ftm (
" #%|-10s| = %|.8s| %|23t| Message = '%s'" );
634 for (
const auto&
i : c ) {
635 this->msgStream(level)
636 << ( ftm % label %
i.second %
i.first )
641 print( m_exceptions,
"EXCEPTIONS" );
642 print( m_errors,
"ERRORS" );
643 print( m_warnings,
"WARNINGS" );
644 print( m_infos,
"INFOS" );
648 m_exceptions .size () +
650 m_warnings .size () +
660 template <
class PBASE >
665 MsgStream& msg = this->msgStream ( level );
666 const auto&
properties = this->getProperties() ;
667 msg <<
"List of ALL properties of "
672 msg <<
"Property ['Name': Value] = " << *
property <<
endmsg ;
685 template <
class PBASE >
689 const bool useRootInTES )
const
692 Assert ( svc ,
"put():: Invalid 'service'!" ) ;
693 Assert (
object ,
"put():: Invalid 'Object'!" ) ;
694 Assert ( !location.
empty() ,
"put():: Invalid 'address' = '' " ) ;
696 const std::string & fullLocation = fullTESLocation( location, useRootInTES );
698 const StatusCode status =
'/' == fullLocation[0] ?
699 svc -> registerObject( fullLocation ,
object ) :
700 svc -> registerObject(
"/Event/" + fullLocation ,
object ) ;
703 { Exception (
"put():: could not register '" +
705 "' at address '" + fullLocation +
"'" , status ) ; }
707 { Print(
"The object of type '" +
709 "' is registered in TS at address '"
710 + fullLocation +
"'" , status ,
MSG::DEBUG ).ignore() ; }
718 template <
class PBASE >
723 if (
this -> errorsPrint() ) {
this -> printErrors () ; }
728 template <
class PBASE >
733 if (
this -> propsPrint() ) {
this -> printProps (
MSG::ALWAYS ) ; }
738 template <
class PBASE >
743 if (
this -> statPrint() ) {
this -> printStat (
MSG::ALWAYS ) ; }
Definition of the MsgStream class used to transmit messages.
virtual const std::vector< const Property * > * getProperties(const std::string &client) const =0
Get the properties associated to a given client.
Define general base for Gaudi exception.
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
StatusCode releaseSvc(const IInterface *svc) const
manual forced (and 'safe') release of the service
virtual std::vector< Gaudi::DataHandle * > inputHandles() const =0
DataObject * put(IDataProviderSvc *svc, DataObject *object, const std::string &location, const bool useRootInTES=true) const
Register a data object or container into Gaudi Event Transient Store.
unsigned long getCode() const
Get the status code by value.
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
void addToServiceList(SmartIF< IService > svc) const
Add the given service to the list of acquired services.
constexpr const struct GaudiCommon_details::svc_eq_t svc_eq
bool isSuccess() const
Test for a status code of SUCCESS.
StatusCode Error(const std::string &msg, const StatusCode st=StatusCode::FAILURE, const size_t mx=10) const
Print the error message and return with the given StatusCode.
void initGaudiCommonConstructor(const IInterface *parent=0)
Constructor initializations.
Data provider interface definition.
bool isFailure() const
Test for a status code of FAILURE.
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
virtual const std::string & name() const =0
Retrieve the name of the instance.
virtual void visit(const IDataHandleHolder *)=0
constexpr const struct GaudiCommon_details::svc_lt_t svc_lt
This class is used for returning status codes from appropriate routines.
Definition of the basic interface.
void printStatHandler(Property &)
handler for "StatPrint" property
StatusCode Print(const std::string &msg, const StatusCode st=StatusCode::SUCCESS, const MSG::Level lev=MSG::INFO) const
Print the message and return with the given StatusCode.
The useful base class for data processing algorithms.
StatusCode Warning(const std::string &msg, const StatusCode st=StatusCode::FAILURE, const size_t mx=10) const
Print the warning message and return with the given StatusCode.
collection of useful utilities to print certain objects (currently used for implementation in class G...
virtual const std::string & rootName() const =0
Get Name of root Event.
const TYPE & value() const
explicit conversion
reverse_wrapper< T > reverse(T &&iterable)
Property base class allowing Property* collections to be "homogeneous".
virtual std::vector< Gaudi::DataHandle * > outputHandles() const =0
bool isValid() const
Allow for check if smart pointer is valid.
StatusCode releaseTool(const IAlgTool *tool) const
manual forced (and 'safe') release of the tool
Implements the common functionality between GaudiTools and GaudiAlgorithms.
void printPropsHandler(Property &)
handler for "PropertiesPrint" property
StatusCode Info(const std::string &msg, const StatusCode st=StatusCode::SUCCESS, const size_t mx=10) const
Print the info message and return with the given StatusCode.
long printStat(const MSG::Level level=MSG::ALWAYS) const
perform the actual printout of statistical counters
A DataObject is the base class of any identifiable object on any data store.
StatusCode release(const IInterface *interface) const
Manual forced (and 'safe') release of the active tool or service.
long printProps(const MSG::Level level=MSG::ALWAYS) const
perform the actual printout of properties
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
void printErrorHandler(Property &)
handler for "ErrorPrint" property
long printErrors(const MSG::Level level=MSG::ALWAYS) const
perform the actual printout of error counters
void Exception(const std::string &msg, const GaudiException &exc, const StatusCode sc=StatusCode(StatusCode::FAILURE, true)) const
Create and (re)-throw a given GaudiException.