52 #include "boost/format.hpp" 53 #include "boost/tokenizer.hpp" 57 # pragma warning( disable : 4661 ) // incomplete explicit templates 64 template <
class PBASE>
68 if (
const GaudiAlgorithm* gAlg = dynamic_cast<const GaudiAlgorithm*>( parent ) ) {
69 m_context = gAlg->context();
70 }
else if (
const GaudiTool* gTool = dynamic_cast<const GaudiTool*>( parent ) ) {
71 m_context = gTool->context();
76 auto jos = PBASE::template service<IJobOptionsSvc>(
"JobOptionsSvc" );
77 if ( !jos ) Exception(
"Cannot get JobOptionsSvc" );
80 const auto myList = jos->getProperties( this->
name() );
83 for (
const auto& iter : *myList ) {
85 if (
sp && iter->name().compare(
"Context" ) == 0 ) { m_context =
sp->value(); }
94 template <
class PBASE>
98 const StatusCode sc = base_class::initialize();
99 if ( sc.
isFailure() ) {
return Error(
"Failed to initialise base class PBASE", sc ); }
104 if ( !context().empty() ) this->debug() <<
"Created with context = '" << context() <<
"'" <<
endmsg;
108 m_counterSummarySvc = this->svcLoc()->service(
"CounterSummarySvc",
false );
110 if ( !m_counterSummarySvc )
111 this->debug() <<
"could not locate CounterSummarySvc, no counter summary will be made" <<
endmsg;
113 this->debug() <<
"found CounterSummarySvc OK" <<
endmsg;
117 if ( propsPrint() ) {
130 template <
class PBASE>
135 if ( this->msgLevel(
MSG::DEBUG ) || ( statPrint() && this->nCounters() > 0 ) ) {
140 if ( m_counterSummarySvc && this->svcLoc()->existsService(
"CounterSummarySvc" ) ) {
141 if ( this->msgLevel(
MSG::DEBUG ) ) this->debug() <<
"adding counters to CounterSummarySvc" <<
endmsg;
146 for (
const auto& i : m_countersOwn ) {
147 if ( statList.Or( i.first ) )
149 else if ( counterList.Or( i.first ) )
150 m_counterSummarySvc->addCounter( this->name(), i.first, i.second );
155 this->debug() <<
"Tools to release :";
156 for (
const auto& i : m_managedTools ) { this->debug() <<
" " << i->name(); }
159 while ( !m_managedTools.empty() ) {
165 this->debug() <<
"Services to release :";
166 for (
const auto& i : m_services ) this->debug() <<
" " << i->name();
169 while ( !m_services.empty() ) {
174 m_counterSummarySvc.reset();
177 if ( !m_errors.empty() || !m_warnings.empty() || !m_exceptions.empty() ) {
178 this->always() <<
"Exceptions/Errors/Warnings/Infos Statistics : " << m_exceptions.size() <<
"/" << m_errors.size()
179 <<
"/" << m_warnings.size() <<
"/" << m_infos.size() <<
endmsg;
180 if ( errorsPrint() ) { printErrors(); }
184 this->clearCounters();
185 m_countersOwn.clear();
186 m_exceptions.clear();
190 m_counterList.clear();
191 m_statEntityList.clear();
205 template <
class PBASE>
207 if ( !interface ) {
return Error(
"release(IInterface):: IInterface* points to NULL!" ); }
209 const IAlgTool* algTool = dynamic_cast<const IAlgTool*>( interface );
211 return algTool ? releaseTool( algTool ) : releaseSvc( interface );
218 template <
class PBASE>
220 if ( !algTool ) {
return Error(
"releaseTool(IAlgTool):: IAlgTool* points to NULL!" ); }
221 if ( !this->toolSvc() ) {
return Error(
"releaseTool(IAlgTool):: IToolSvc* points to NULL!" ); }
223 auto it =
std::find( m_managedTools.begin(), m_managedTools.end(), algTool );
224 if ( m_managedTools.end() == it ) {
return Warning(
"releaseTool(IAlgTool):: IAlgTool* is not active" ); }
229 if ( this->msgLevel(
MSG::DEBUG ) ) { this->debug() <<
"Releasing tool '" <<
name <<
"'" <<
endmsg; }
231 base_class::deregisterTool( t );
232 m_managedTools.erase( it );
236 <<
"' is released" <<
endmsg;
238 const StatusCode sc = this->toolSvc()->releaseTool( t );
239 return sc.
isSuccess() ? sc : Warning(
"releaseTool(IAlgTool):: error from IToolSvc releasing " +
name, sc );
246 template <
class PBASE>
248 if ( !Svc )
return Error(
"releaseSvc(IInterface):: IInterface* points to NULL!" );
250 if ( !svc )
return Warning(
"releaseSvc(IInterface):: IInterface* is not a service" );
253 return Warning(
"releaseSvc(IInterface):: IInterface* is not active" );
255 if ( this->msgLevel(
MSG::DEBUG ) ) { this->debug() <<
"Releasing service '" << ( *it )->name() <<
"'" <<
endmsg; }
256 m_services.erase( it );
265 template <
class PBASE>
270 m_services.insert( i,
std::move( svc ) );
272 this->warning() <<
"Service " << svc->name() <<
" already present -- skipping" <<
endmsg;
285 template <
class PBASE>
288 const size_t num = ++m_errors[
msg];
294 return Print(
"The ERROR message is suppressed : '" +
msg +
"'", st,
MSG::ERROR );
304 template <
class PBASE>
307 const size_t num = ++m_warnings[
msg];
313 return Print(
"The WARNING message is suppressed : '" +
msg +
"'", st,
MSG::WARNING );
323 template <
class PBASE>
326 const size_t num = ++m_infos[
msg];
332 return Print(
"The INFO message is suppressed : '" +
msg +
"'", st,
MSG::INFO );
342 template <
class PBASE>
345 if ( !this->msgLevel( lvl ) ) {
return st; }
357 str <<
" StatusCode=" << st.
getCode();
359 str <<
" StatusCode=FAILURE";
373 template <
class PBASE>
377 Print(
"Exception (re)throw: " +
msg, sc,
MSG::FATAL ).ignore();
385 template <
class PBASE>
389 Print(
"Exception (re)throw: " +
msg, sc,
MSG::FATAL ).ignore();
397 template <
class PBASE>
409 template <
class PBASE>
413 auto countToBePrinted = [&]() {
418 auto nbPrintedCounters =
419 ( ( !m_printEmptyCounters && !this->msgLevel(
MSG::DEBUG ) ) ? countToBePrinted() : this->nCounters() );
421 if ( nbPrintedCounters == 0 )
return 0;
423 msg <<
"Number of counters : " << nbPrintedCounters <<
"\n" << m_header.value();
425 if ( m_printEmptyCounters || this->msgLevel(
MSG::DEBUG ) ||
counter.toBePrinted() ) {
434 return nbPrintedCounters;
441 template <
class PBASE>
444 boost::format ftm(
" #%|-10s| = %|.8s| %|23t| Message = '%s'" );
447 for (
const auto& i :
c ) { this->msgStream(
level ) << ( ftm % label % i.second % i.first ) <<
endmsg; }
450 print( m_exceptions,
"EXCEPTIONS" );
451 print( m_errors,
"ERRORS" );
452 print( m_warnings,
"WARNINGS" );
453 print( m_infos,
"INFOS" );
456 return m_exceptions.size() + m_errors.size() + m_warnings.size() + m_infos.size();
465 template <
class PBASE>
470 const auto&
properties = this->getProperties();
485 template <
class PBASE>
489 Assert( svc,
"put():: Invalid 'service'!" );
490 Assert( static_cast<bool>(
object ),
"put():: Invalid 'Object'!" );
491 Assert( !
location.empty(),
"put():: Invalid 'address' = '' " );
500 Exception(
"put():: could not register '" +
System::typeinfoName(
typeid( obj ) ) +
"' at address '" +
505 Print(
"The object of type '" +
System::typeinfoName(
typeid( obj ) ) +
"' is registered in TS at address '" +
511 return object.release();
code_t getCode() const
Retrieve value ("checks" the StatusCode)
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(...)".
long printStat(const MSG::Level level=MSG::ALWAYS) const
perform the actual printout of statistical counters
Implementation of property with value of concrete type.
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
constexpr const struct GaudiCommon_details::svc_eq_t svc_eq
::details::reverse_wrapper< T > reverse(T &&iterable)
Header file for class GaudiAlgorithm.
void addToServiceList(SmartIF< IService > svc) const
Add the given service to the list of acquired services.
void Exception(const std::string &msg, const GaudiException &exc, const StatusCode sc=StatusCode(StatusCode::FAILURE, true)) const
Create and (re)-throw a given GaudiException.
WARN_UNUSED 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.
constexpr static const auto SUCCESS
long printErrors(const MSG::Level level=MSG::ALWAYS) const
perform the actual printout of error counters
DataObject * put(IDataProviderSvc *svc, std::unique_ptr< DataObject > object, const std::string &location, const bool useRootInTES=true) const
Register a data object or container into Gaudi Event Transient Store.
StatusCode finalize() override
standard finalization method
auto get(const Handle &handle, const Algo &, const EventContext &) -> decltype(details::deref(handle.get()))
Data provider interface definition.
virtual const std::string & name() const =0
Retrieve the name of the instance.
constexpr const struct GaudiCommon_details::svc_lt_t svc_lt
StatusCode releaseTool(const IAlgTool *tool) const
manual forced (and 'safe') release of the tool
This class is used for returning status codes from appropriate routines.
Definition of the basic interface.
long printProps(const MSG::Level level=MSG::ALWAYS) const
perform the actual printout of properties
The useful base class for data processing algorithms.
StatusCode releaseSvc(const IInterface *svc) const
manual forced (and 'safe') release of the service
std::string fullTESLocation(std::string_view location, std::string_view rit)
collection of useful utilities to print certain objects (currently used for implementation in class G...
StatusCode initialize() override
standard initialization method
StatusCode release(const IInterface *interface) const
Manual forced (and 'safe') release of the active tool or service.
StatusCode registerObject(std::string_view fullPath, DataObject *pObject)
Register object with the data store.
WARN_UNUSED 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.
constexpr static const auto FAILURE
WARN_UNUSED 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.
A DataObject is the base class of any identifiable object on any data store.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
void initGaudiCommonConstructor(const IInterface *parent=nullptr)
Constructor initializations.
WARN_UNUSED 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.