52 #include "boost/format.hpp" 53 #include "boost/tokenizer.hpp" 57 #pragma warning( disable : 4661 ) // incomplete explicit templates 64 template <
class PBASE>
73 if (
const GaudiAlgorithm* gAlg = dynamic_cast<const GaudiAlgorithm*>( parent ) ) {
74 m_context = gAlg->context();
75 m_rootInTES = gAlg->rootInTES();
76 }
else if (
const GaudiTool* gTool = dynamic_cast<const GaudiTool*>( parent ) ) {
77 m_context = gTool->context();
78 m_rootInTES = gTool->rootInTES();
83 auto jos = PBASE::template service<IJobOptionsSvc>(
"JobOptionsSvc" );
84 if ( !jos ) Exception(
"Cannot get JobOptionsSvc" );
87 const auto myList = jos->getProperties( this->
name() );
90 for (
const auto& iter : *myList ) {
93 if ( iter->name().compare(
"Context" ) == 0 ) {
94 m_context = sp->
value();
95 }
else if ( iter->name().compare(
"RootInTES" ) == 0 ) {
96 m_rootInTES = sp->
value();
107 template <
class PBASE>
120 return Error(
"Failed to initialise base class PBASE", sc );
126 if ( !context().empty() ) this->debug() <<
"Created with context = '" << context() <<
"'" <<
endmsg;
130 if ( !m_rootInTES.empty() && m_rootInTES[m_rootInTES.size() - 1] !=
'/' ) m_rootInTES = m_rootInTES +
"/";
133 m_counterSummarySvc = this->svcLoc()->service(
"CounterSummarySvc",
false );
135 if ( !m_counterSummarySvc )
136 this->debug() <<
"could not locate CounterSummarySvc, no counter summary will be made" <<
endmsg;
138 this->debug() <<
"found CounterSummarySvc OK" <<
endmsg;
142 if ( propsPrint() ) {
152 auto rootName = dataMgrSvc->
rootName();
153 if ( !rootName.empty() &&
'/' != rootName.back() ) rootName +=
"/";
156 auto tokens = boost::tokenizer<boost::char_separator<char>>{
location, boost::char_separator<char>{
":"}};
159 std::string r = fullTESLocation( tok, UseRootInTES );
161 if ( r[0] !=
'/' ) r = rootName + r;
162 return s.
empty() ? r : s +
':' + r;
165 this->debug() <<
"Changing " <<
location <<
" to " << result <<
endmsg;
179 r = m_f(
h->objKey() );
180 if ( r !=
h->objKey() )
h->updateKey( r );
183 r = m_f(
h->objKey() );
184 if ( r !=
h->objKey() )
h->updateKey( r );
192 this->m_updateDataHandles = std::make_unique<DHHFixer>( fixLocation );
201 template <
class PBASE>
213 if ( this->msgLevel(
MSG::DEBUG ) || ( statPrint() && !counters().empty() ) ) {
218 if ( m_counterSummarySvc && this->svcLoc()->existsService(
"CounterSummarySvc" ) ) {
219 if ( this->msgLevel(
MSG::DEBUG ) ) this->debug() <<
"adding counters to CounterSummarySvc" <<
endmsg;
224 for (
const auto& i : this->counters() ) {
225 if ( statList.Or( i.first ) )
227 else if ( counterList.Or( i.first ) )
228 m_counterSummarySvc->addCounter( this->name(), i.first, i.second );
233 this->debug() <<
"Tools to release :";
234 for (
const auto& i : m_managedTools ) {
235 this->debug() <<
" " << i->name();
239 while ( !m_managedTools.empty() ) {
240 sc = releaseTool( m_managedTools.back() ) && sc;
245 this->debug() <<
"Services to release :";
246 for (
const auto& i : m_services ) this->debug() <<
" " << i->name();
249 while ( !m_services.empty() ) {
250 sc = releaseSvc( m_services.front() ) && sc;
254 m_counterSummarySvc.reset();
257 if ( !m_errors.empty() || !m_warnings.empty() || !m_exceptions.empty() ) {
258 this->always() <<
"Exceptions/Errors/Warnings/Infos Statistics : " << m_exceptions.size() <<
"/" << m_errors.size()
259 <<
"/" << m_warnings.size() <<
"/" << m_infos.size() <<
endmsg;
260 if ( errorsPrint() ) {
267 m_exceptions.clear();
271 m_counterList.clear();
272 m_statEntityList.clear();
275 return sc && PBASE::finalize();
286 template <
class PBASE>
290 return Error(
"release(IInterface):: IInterface* points to NULL!" );
295 return algTool ? releaseTool( algTool ) : releaseSvc( interface );
302 template <
class PBASE>
306 return Error(
"releaseTool(IAlgTool):: IAlgTool* points to NULL!" );
308 if ( !this->toolSvc() ) {
309 return Error(
"releaseTool(IAlgTool):: IToolSvc* points to NULL!" );
312 auto it =
std::find( m_managedTools.begin(), m_managedTools.end(), algTool );
313 if ( m_managedTools.end() == it ) {
314 return Warning(
"releaseTool(IAlgTool):: IAlgTool* is not active" );
321 this->debug() <<
"Releasing tool '" << name <<
"'" <<
endmsg;
324 PBASE::deregisterTool( t );
325 m_managedTools.erase( it );
329 <<
"' is released" <<
endmsg;
331 const StatusCode sc = this->toolSvc()->releaseTool( t );
332 return sc.
isSuccess() ? sc : Warning(
"releaseTool(IAlgTool):: error from IToolSvc releasing " + name, sc );
339 template <
class PBASE>
342 if ( !Svc )
return Error(
"releaseSvc(IInterface):: IInterface* points to NULL!" );
344 if ( !svc )
return Warning(
"releaseSvc(IInterface):: IInterface* is not a service" );
347 return Warning(
"releaseSvc(IInterface):: IInterface* is not active" );
350 this->debug() <<
"Releasing service '" << ( *it )->name() <<
"'" <<
endmsg;
352 m_services.erase( it );
361 template <
class PBASE>
367 m_services.insert( i,
std::move( svc ) );
369 this->warning() <<
"Service " << svc->name() <<
" already present -- skipping" <<
endmsg;
382 template <
class PBASE>
386 const size_t num = ++m_errors[
msg];
392 return Print(
"The ERROR message is suppressed : '" + msg +
"'", st,
MSG::ERROR );
402 template <
class PBASE>
406 const size_t num = ++m_warnings[
msg];
412 return Print(
"The WARNING message is suppressed : '" + msg +
"'", st,
MSG::WARNING );
422 template <
class PBASE>
426 const size_t num = ++m_infos[
msg];
432 return Print(
"The INFO message is suppressed : '" + msg +
"'", st,
MSG::INFO );
442 template <
class PBASE>
446 if ( !this->msgLevel( lvl ) ) {
462 str <<
" StatusCode=" << st.
getCode();
464 str <<
" StatusCode=FAILURE";
478 template <
class PBASE>
483 Print(
"Exception (re)throw: " + msg, sc,
MSG::FATAL ).ignore();
491 template <
class PBASE>
496 Print(
"Exception (re)throw: " + msg, sc,
MSG::FATAL ).ignore();
504 template <
class PBASE>
509 Print(
"Exception throw: " + msg, sc,
MSG::FATAL ).ignore();
517 template <
class PBASE>
521 if ( counters().empty() ) {
526 msg <<
"Number of counters : " << counters().size();
528 if ( !counters().empty() ) {
532 for (
const auto& entry : counters() ) {
539 return counters().size();
546 template <
class PBASE>
550 boost::format ftm(
" #%|-10s| = %|.8s| %|23t| Message = '%s'" );
553 for (
const auto& i : c ) {
554 this->msgStream( level ) << ( ftm % label % i.second % i.first ) <<
endmsg;
558 print( m_exceptions,
"EXCEPTIONS" );
559 print( m_errors,
"ERRORS" );
560 print( m_warnings,
"WARNINGS" );
561 print( m_infos,
"INFOS" );
564 return m_exceptions.size() + m_errors.size() + m_warnings.size() + m_infos.size();
573 template <
class PBASE>
583 msg <<
"Property ['Name': Value] = " << *
property <<
endmsg;
596 template <
class PBASE>
598 const bool useRootInTES )
const 601 Assert( svc,
"put():: Invalid 'service'!" );
602 Assert(
object,
"put():: Invalid 'Object'!" );
603 Assert( !location.
empty(),
"put():: Invalid 'address' = '' " );
605 const std::string& fullLocation = fullTESLocation( location, useRootInTES );
611 Exception(
"put():: could not register '" +
System::typeinfoName(
typeid( *
object ) ) +
"' at address '" +
616 Print(
"The object of type '" +
System::typeinfoName(
typeid( *
object ) ) +
"' is registered in TS at address '" +
628 template <
class PBASE>
635 if ( this->errorsPrint() ) {
642 template <
class PBASE>
649 if ( this->propsPrint() ) {
656 template <
class PBASE>
663 if ( this->statPrint() ) {
Definition of the MsgStream class used to transmit messages.
void printErrorHandler(Gaudi::Details::PropertyBase &)
handler for "ErrorPrint" property
virtual const std::string & rootName() const =0
Get Name of root Event.
Define general base for Gaudi exception.
void printStatHandler(Gaudi::Details::PropertyBase &)
handler for "StatPrint" property
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.
Implementation of property with value of concrete type.
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.
Header file for class GaudiAlgorithm.
Gaudi::Details::PropertyBase * property(const std::string &name) const
void printPropsHandler(Gaudi::Details::PropertyBase &)
handler for "PropertiesPrint" property
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 std::vector< Gaudi::DataHandle * > inputHandles() const =0
virtual std::vector< Gaudi::DataHandle * > outputHandles() const =0
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.
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...
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
reverse_wrapper< T > reverse(T &&iterable)
StatusCode releaseTool(const IAlgTool *tool) const
manual forced (and 'safe') release of the tool
Implements the common functionality between GaudiTools and GaudiAlgorithms.
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.
const ValueType & value() const
Backward compatibility (.
long printStat(const MSG::Level level=MSG::ALWAYS) const
perform the actual printout of statistical counters
virtual StatusCode registerObject(const std::string &fullPath, DataObject *pObject)=0
Register object with the data store.
const std::vector< Gaudi::Details::PropertyBase * > & getProperties() const override
get all properties
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.
virtual const std::string & name() const =0
Retrieve the name of the instance.
void initGaudiCommonConstructor(const IInterface *parent=nullptr)
Constructor initializations.
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.