49 #include "boost/format.hpp"
50 #include "boost/lexical_cast.hpp"
54 #pragma warning ( disable:4661 ) // incomplete explicit templates
61 template <
class PBASE>
75 m_globalTimeOffset = 0.0 ;
77 m_counterSummarySvc=NULL;
78 m_counterList=std::vector<std::string>(1,
".*");
79 m_statEntityList=std::vector<std::string>(0);
84 m_header =
" | Counter | # | sum | mean/eff^* | rms/err^* | min | max |" ;
86 m_format1 =
" | %|-48.48s|%|50t||%|10d| |%|11.7g| |%|#11.5g| |%|#11.5g| |%|#12.5g| |%|#12.5g| |" ;
88 m_format2 =
" |*%|-48.48s|%|50t||%|10d| |%|11.5g| |(%|#9.6g| +- %|-#9.6g|)%%| ------- | ------- |" ;
90 m_useEffFormat = true ;
95 (
"ErrorsPrint" , m_errorsPrint ,
96 "Print the statistics of errors/warnings/exceptions")
97 -> declareUpdateHandler
100 this->declareProperty
101 (
"PropertiesPrint" , m_propsPrint ,
102 "Print the properties of the component ")
103 -> declareUpdateHandler
106 this->declareProperty
107 (
"StatPrint" , m_statPrint ,
108 "Print the table of counters" )
109 -> declareUpdateHandler
112 this->declareProperty
113 (
"TypePrint" , m_typePrint ,
114 "Add the actal C++ component type into the messages" ) ;
116 this->declareProperty (
"Context" , m_context ) ;
118 this->declareProperty (
"RootInTES" , m_rootInTES ) ;
120 this->declareProperty (
"RootOnTES" , m_rootOnTES ) ;
122 this->declareProperty (
"GlobalTimeOffset", m_globalTimeOffset ) ;
126 this->declareProperty
127 (
"StatTableHeader" , m_header ,
128 "The header row for the output Stat-table" ) ;
130 this->declareProperty
131 (
"RegularRowFormat" , m_format1 ,
132 "The format for the regular row in the output Stat-table" ) ;
134 this->declareProperty
135 (
"EfficiencyRowFormat" , m_format2 ,
136 "The format for the regular row in the output Stat-table" ) ;
138 this->declareProperty
139 (
"UseEfficiencyRowFormat" , m_useEffFormat ,
140 "Use the special format for printout of efficiency counters" ) ;
144 this->declareProperty(
146 m_counterList=std::vector<std::string>(1,
".*"),
147 "RegEx list, of simple integer counters for CounterSummary.");
149 this->declareProperty(
151 m_statEntityList=std::vector<std::string>(0),
152 "RegEx list, of StatEntity counters for CounterSummary.");
160 if (
const GaudiAlgorithm* gAlg = dynamic_cast<const GaudiAlgorithm*>(parent) )
162 m_context = gAlg->context();
163 m_rootInTES = gAlg->rootInTES();
164 m_globalTimeOffset = gAlg->globalTimeOffset();
166 else if (
const GaudiTool* gTool = dynamic_cast<const GaudiTool*> (parent) )
168 m_context = gTool->context();
169 m_rootInTES = gTool->rootInTES();
170 m_globalTimeOffset = gTool->globalTimeOffset();
176 if (!jos.
isValid()) Exception(
"Cannot get JobOptionsSvc");
179 const std::vector<const Property*>* myList = jos->getProperties( this->name() );
183 for ( std::vector<const Property*>::const_iterator iter = myList->begin();
184 iter != myList->end();
190 if (
"Context" == (*iter)->name() )
192 m_context = sp->
value();
193 }
else if (
"RootInTES" == (*iter)->name() ) {
194 m_rootInTES = sp->
value();
195 }
else if (
"GlobalTimeOffset" == (*iter)->name() ) {
196 m_globalTimeOffset = atof( sp->
value().c_str() );
208 template <
class PBASE >
221 {
return Error (
"Failed to initialise base class PBASE", sc ) ; }
228 if ( !context().empty() )
229 debug() <<
"Created with context = '" << context() <<
"'" <<
endmsg;
234 if ( m_rootInTES.empty() && !m_rootOnTES.empty() )
236 m_rootInTES = m_rootOnTES;
237 Warning(
"RootOnTES option is OBSOLETE -> Use RootInTES instead. RootInTES has been updated to "
240 else if ( !m_rootInTES.empty() && !m_rootOnTES.empty() )
242 Warning(
"Options RootOnTES AND RootInTES are defined ! Use RootInTES. RootOnTES is ignored",
247 if ( !m_rootInTES.empty() &&
248 m_rootInTES.substr(m_rootInTES.size()-1) !=
"/" ) m_rootInTES +=
"/";
251 this->svcLoc()->service(
"CounterSummarySvc",m_counterSummarySvc,
false).ignore() ;
254 if (m_counterSummarySvc==NULL )
255 debug() <<
"could not locate CounterSummarySvc, no counter summary will be made" <<
endmsg;
256 else debug() <<
"found CounterSummarySvc OK" <<
endmsg;
270 template <
class PBASE >
282 if ( msgLevel(
MSG::DEBUG) || (statPrint() && !counters().empty()) )
288 if(m_counterSummarySvc && this->svcLoc()->existsService(
"CounterSummarySvc"))
290 if ( msgLevel(
MSG::DEBUG) ) debug() <<
"adding counters to CounterSummarySvc" <<
endmsg;
291 for(Statistics::const_iterator
i=this->counters().begin();
292 i!=this->counters().end();
296 m_counterSummarySvc->addCounter(this->name(),
i->first,
i->second,
299 m_counterSummarySvc->addCounter(this->name(),
i->first,
i->second);
305 debug() <<
"Tools to release :";
306 for ( AlgTools::const_iterator
i = m_tools.begin();
307 i != m_tools.end(); ++
i )
309 debug() <<
" " << (*i)->name();
313 while ( !m_tools.empty() ) { sc = sc && releaseTool( m_tools.back() ) ; }
318 debug() <<
"Services to release :";
320 i != m_services.end(); ++
i )
322 debug() <<
" " << (*i).first;
326 while ( !m_services.empty() ) { sc = sc && releaseSvc( m_services.begin()->second ) ; }
329 if(m_counterSummarySvc)
331 m_counterSummarySvc->release();
332 m_counterSummarySvc=NULL;
336 if ( !m_errors.empty() || !m_warnings.empty() || !m_exceptions.empty() )
338 always() <<
"Exceptions/Errors/Warnings/Infos Statistics : "
339 << m_exceptions .size () <<
"/"
340 << m_errors .size () <<
"/"
341 << m_warnings .size () <<
"/"
342 << m_infos .size () <<
endmsg ;
343 if ( errorsPrint() ) { printErrors () ; }
350 m_counters .clear() ;
351 m_exceptions .clear() ;
353 m_warnings .clear() ;
355 m_counterList.clear() ;
356 m_statEntityList.clear() ;
359 return sc && PBASE::finalize();
370 template <
class PBASE >
373 if ( 0 == interface )
374 {
return Error (
"release(IInterface):: IInterface* points to NULL!" ) ; }
378 return 0 != algTool ? releaseTool( algTool ) : releaseSvc( interface ) ;
385 template <
class PBASE >
389 {
return Error (
"releaseTool(IAlgTool):: IAlgTool* points to NULL!" ) ; }
390 if( this->toolSvc() == 0 )
391 {
return Error (
"releaseTool(IAlgTool):: IToolSvc* points to NULL!" ) ; }
393 AlgTools::reverse_iterator it =
394 std::find( m_tools.rbegin() , m_tools.rend() , algTool ) ;
395 if( m_tools.rend() == it )
396 {
return Warning(
"releaseTool(IAlgTool):: IAlgTool* is not active" ) ; }
400 const std::string name = t->
name();
402 { debug() <<
"Releasing tool '" << name <<
"'" <<
endmsg; }
404 m_tools.erase( --it.base() ) ;
407 this->debug() <<
"The tool '" << t->
name() <<
"' of type '"
409 <<
"' is released" <<
endmsg;
411 const StatusCode sc = this->toolSvc()->releaseTool( t ) ;
413 {
return Warning (
"releaseTool(IAlgTool):: error from IToolSvc whilst releasing "+name , sc ) ; }
422 template <
class PBASE >
426 return Error (
"releaseSvc(IInterface):: IInterface* points to NULL!" ) ;
431 if (it == m_services.end()) {
432 return Warning(
"releaseSvc(IInterface):: IInterface* is not active" );
435 debug() <<
"Releasing service '" << it->first <<
"'" <<
endmsg;
437 m_services.erase(it);
440 return Warning(
"releaseSvc(IInterface):: IInterface* is not a service" );
447 template <
class PBASE >
452 this->debug() <<
"The tool of type '"
454 <<
"' has been added with the name '"
457 m_tools.push_back( tool ) ;
465 template <
class PBASE >
469 m_services[svc->name()] = svc;
481 template <
class PBASE >
484 const size_t mx )
const
487 const size_t num = ++m_errors[
msg] ;
489 if ( num > mx ) {
return st ; }
490 else if ( num == mx )
491 {
return Print (
"The ERROR message is suppressed : '" +
501 template <
class PBASE >
503 (
const std::string&
msg ,
505 const size_t mx )
const
508 const size_t num = ++m_warnings[
msg] ;
510 if ( num > mx ) {
return st ; }
511 else if ( num == mx )
512 {
return Print (
"The WARNING message is suppressed : '" +
522 template <
class PBASE >
524 (
const std::string& msg ,
526 const size_t mx )
const
529 const size_t num = ++m_infos[
msg] ;
531 if ( num > mx ) {
return st ; }
532 else if ( num == mx )
533 {
return Print (
"The INFO message is suppressed : '" +
543 template <
class PBASE >
549 if ( !msgLevel( lvl ) ) {
return st ; }
559 { str <<
" StatusCode=" << st.
getCode() ; }
561 { str <<
" StatusCode=FAILURE" ; }
572 template <
class PBASE >
578 ++m_exceptions[
msg ];
579 Print (
"Exception (re)throw: " + msg , sc ,
MSG::FATAL ).ignore();
580 throw GaudiException( this->name() +
":: " + msg , this->name() , sc, exc);
587 template <
class PBASE >
589 const std::exception & exc ,
593 ++m_exceptions[
msg ];
594 Print (
"Exception (re)throw: " + msg , sc ,
MSG::FATAL ).ignore();
595 throw GaudiException( this->name() +
":: " + msg+
"("+exc.what()+
")",
"",
sc );
602 template <
class PBASE >
607 ++m_exceptions[
msg ];
608 Print (
"Exception throw: " + msg , sc ,
MSG::FATAL ).ignore();
616 template <
class PBASE >
620 if ( counters().empty() ) {
return 0 ; }
623 msg <<
"Number of counters : " << counters().size() ;
625 if ( !counters().empty() ) { msg << std::endl << m_header ; }
627 for ( Statistics::const_iterator entry = counters().begin() ;
628 counters().end() != entry ; ++entry )
635 m_format1 , m_format2 );
640 return counters().size() ;
647 template <
class PBASE >
654 for ( Counter::const_iterator excp = m_exceptions.begin() ;
655 excp != m_exceptions.end() ; ++excp )
658 << ( ftm %
"#EXCEPTIONS" % excp->second % excp->first )
663 for ( Counter::const_iterator error = m_errors.begin() ;
664 error != m_errors.end() ; ++error )
667 << ( ftm %
"#ERRORS " % error->second % error->first )
672 for ( Counter::const_iterator warning = m_warnings.begin() ;
673 warning != m_warnings.end() ; ++warning )
676 << ( ftm %
"#WARNINGS " % warning->second % warning->first )
681 for ( Counter::const_iterator info = m_infos.begin() ;
682 info != m_infos.end() ; ++info )
685 << ( ftm %
"#INFOS " % info->second % info->first )
692 m_exceptions .size () +
694 m_warnings .size () +
704 template <
class PBASE >
710 typedef std::vector<Property*> Properties;
711 const Properties& properties = this->getProperties() ;
712 msg <<
"List of ALL properties of "
714 <<
" #properties = " << properties.size() <<
endmsg ;
715 for ( Properties::const_reverse_iterator property
716 = properties.rbegin() ;
717 properties.rend() != property ; ++property )
719 msg <<
"Property ['Name': Value] = "
723 return properties.size() ;
730 template <
class PBASE >
743 if ( this->msgSvc()->outputLevel(this->name()) != this->outputLevel() )
745 this->msgSvc()->setOutputLevel( this->name(), this->outputLevel() );
751 debug() <<
"Property update for "
752 << theProp.
name() <<
" : new value = " << this->outputLevel() <<
endmsg;
764 template <
class PBASE >
767 const std::string& location ,
768 const bool useRootInTES )
const
771 Assert ( 0 != svc ,
"put():: Invalid 'service'!" ) ;
772 Assert ( 0 !=
object ,
"put():: Invalid 'Object'!" ) ;
773 Assert ( !location.empty() ,
"put():: Invalid 'address' = '' " ) ;
775 const std::string & fullLocation = fullTESLocation( location, useRootInTES );
777 const StatusCode status =
'/' == fullLocation[0] ?
778 svc -> registerObject( fullLocation ,
object ) :
779 svc -> registerObject(
"/Event/" + fullLocation ,
object ) ;
782 { Exception (
"put():: could not register '" +
784 "' at address '" + fullLocation +
"'" , status ) ; }
786 { Print(
"The object of type '" +
788 "' is registered in TS at address '"
789 + fullLocation +
"'" , status ,
MSG::DEBUG ).ignore() ; }
797 template <
class PBASE >
802 if (
this -> errorsPrint() ) {
this -> printErrors () ; }
807 template <
class PBASE >
812 if (
this -> propsPrint() ) {
this -> printProps (
MSG::ALWAYS ) ; }
817 template <
class PBASE >
822 if (
this -> statPrint() ) {
this -> printStat (
MSG::ALWAYS ) ; }
Definition of the MsgStream class used to transmit messages.
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
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.
const std::string & name() const
property name
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
void addToServiceList(const SmartIF< IService > &svc) const
Add the given service to the list of acquired services.
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.
bool matchOr(const std::string &test, const T ®exps)
return true if the string is in any of the regex's
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.
bool isValid() const
Allow for check if smart pointer is valid.
virtual unsigned long release()
Un-hide IInterface::release (ICC warning #1125)
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...
void msgLevelHandler(Property &theProp)
Handle method for changes in the Messaging levels.
map_type::const_iterator const_iterator
const TYPE & value() const
explicit conversion
Property base class allowing Property* collections to be "homogeneous".
map_type::iterator iterator
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
void addToToolList(IAlgTool *tool) const
Add the given tool to the list of acquired tools.
A DataObject is the base class of any identifiable object on any data store.
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.