62 #include "boost/format.hpp" 63 #include "boost/tokenizer.hpp" 67 # pragma warning( disable : 4661 ) // incomplete explicit templates 74 template <
class PBASE>
78 if (
const GaudiAlgorithm* gAlg = dynamic_cast<const GaudiAlgorithm*>( parent ) ) {
79 m_context = gAlg->context();
80 }
else if (
const GaudiTool* gTool = dynamic_cast<const GaudiTool*>( parent ) ) {
81 m_context = gTool->context();
86 auto jos = PBASE::template service<IJobOptionsSvc>(
"JobOptionsSvc" );
87 if ( !jos ) Exception(
"Cannot get JobOptionsSvc" );
90 const auto myList = jos->getProperties( this->
name() );
93 for (
const auto& iter : *myList ) {
95 if (
sp && iter->name().compare(
"Context" ) == 0 ) { m_context =
sp->value(); }
104 template <
class PBASE>
108 const StatusCode sc = base_class::initialize();
109 if ( sc.
isFailure() ) {
return Error(
"Failed to initialise base class PBASE", sc ); }
114 if ( !context().empty() ) this->debug() <<
"Created with context = '" << context() <<
"'" <<
endmsg;
118 m_counterSummarySvc = this->svcLoc()->service(
"CounterSummarySvc",
false );
120 if ( !m_counterSummarySvc )
121 this->debug() <<
"could not locate CounterSummarySvc, no counter summary will be made" <<
endmsg;
123 this->debug() <<
"found CounterSummarySvc OK" <<
endmsg;
127 if ( propsPrint() ) {
140 template <
class PBASE>
145 if ( this->msgLevel(
MSG::DEBUG ) || ( statPrint() && this->nCounters() > 0 ) ) {
150 if ( m_counterSummarySvc && this->svcLoc()->existsService(
"CounterSummarySvc" ) ) {
151 if ( this->msgLevel(
MSG::DEBUG ) ) this->debug() <<
"adding counters to CounterSummarySvc" <<
endmsg;
156 for (
const auto& i : m_countersOwn ) {
157 if ( statList.Or( i.first ) )
159 else if ( counterList.Or( i.first ) )
160 m_counterSummarySvc->addCounter( this->name(), i.first, i.second );
165 this->debug() <<
"Tools to release :";
166 for (
const auto& i : m_managedTools ) { this->debug() <<
" " << i->name(); }
169 while ( !m_managedTools.empty() ) {
175 this->debug() <<
"Services to release :";
176 for (
const auto& i : m_services ) this->debug() <<
" " << i->name();
179 while ( !m_services.empty() ) {
184 m_counterSummarySvc.reset();
187 if ( !m_errors.empty() || !m_warnings.empty() || !m_exceptions.empty() ) {
188 this->always() <<
"Exceptions/Errors/Warnings/Infos Statistics : " << m_exceptions.size() <<
"/" << m_errors.size()
189 <<
"/" << m_warnings.size() <<
"/" << m_infos.size() <<
endmsg;
190 if ( errorsPrint() ) { printErrors(); }
194 this->clearCounters();
195 m_countersOwn.clear();
196 m_exceptions.clear();
200 m_counterList.clear();
201 m_statEntityList.clear();
215 template <
class PBASE>
217 if ( !interface ) {
return Error(
"release(IInterface):: IInterface* points to NULL!" ); }
219 const IAlgTool* algTool = dynamic_cast<const IAlgTool*>( interface );
221 return algTool ? releaseTool( algTool ) : releaseSvc( interface );
228 template <
class PBASE>
230 if ( !algTool ) {
return Error(
"releaseTool(IAlgTool):: IAlgTool* points to NULL!" ); }
231 if ( !this->toolSvc() ) {
return Error(
"releaseTool(IAlgTool):: IToolSvc* points to NULL!" ); }
233 auto it =
std::find( m_managedTools.begin(), m_managedTools.end(), algTool );
234 if ( m_managedTools.end() == it ) {
return Warning(
"releaseTool(IAlgTool):: IAlgTool* is not active" ); }
239 if ( this->msgLevel(
MSG::DEBUG ) ) { this->debug() <<
"Releasing tool '" <<
name <<
"'" <<
endmsg; }
241 base_class::deregisterTool( t );
242 m_managedTools.erase( it );
246 <<
"' is released" <<
endmsg;
248 const StatusCode sc = this->toolSvc()->releaseTool( t );
249 return sc.
isSuccess() ? sc : Warning(
"releaseTool(IAlgTool):: error from IToolSvc releasing " +
name, sc );
256 template <
class PBASE>
258 if ( !Svc )
return Error(
"releaseSvc(IInterface):: IInterface* points to NULL!" );
260 if ( !svc )
return Warning(
"releaseSvc(IInterface):: IInterface* is not a service" );
263 return Warning(
"releaseSvc(IInterface):: IInterface* is not active" );
265 if ( this->msgLevel(
MSG::DEBUG ) ) { this->debug() <<
"Releasing service '" << ( *it )->name() <<
"'" <<
endmsg; }
266 m_services.erase( it );
275 template <
class PBASE>
280 m_services.insert( i,
std::move( svc ) );
282 this->warning() <<
"Service " << svc->name() <<
" already present -- skipping" <<
endmsg;
295 template <
class PBASE>
298 const size_t num = ++m_errors[
msg];
304 return Print(
"The ERROR message is suppressed : '" +
msg +
"'", st,
MSG::ERROR );
314 template <
class PBASE>
317 const size_t num = ++m_warnings[
msg];
323 return Print(
"The WARNING message is suppressed : '" +
msg +
"'", st,
MSG::WARNING );
333 template <
class PBASE>
336 const size_t num = ++m_infos[
msg];
342 return Print(
"The INFO message is suppressed : '" +
msg +
"'", st,
MSG::INFO );
352 template <
class PBASE>
355 if ( !this->msgLevel( lvl ) ) {
return st; }
367 str <<
" StatusCode=" << st.
getCode();
369 str <<
" StatusCode=FAILURE";
383 template <
class PBASE>
387 Print(
"Exception (re)throw: " +
msg, sc,
MSG::FATAL ).ignore();
395 template <
class PBASE>
399 Print(
"Exception (re)throw: " +
msg, sc,
MSG::FATAL ).ignore();
407 template <
class PBASE>
419 template <
class PBASE>
423 auto countToBePrinted = [&]() {
428 auto nbPrintedCounters =
429 ( ( !m_printEmptyCounters && !this->msgLevel(
MSG::DEBUG ) ) ? countToBePrinted() : this->nCounters() );
431 if ( nbPrintedCounters == 0 )
return 0;
433 msg <<
"Number of counters : " << nbPrintedCounters <<
"\n" << m_header.value();
435 if ( m_printEmptyCounters || this->msgLevel(
MSG::DEBUG ) ||
counter.toBePrinted() ) {
444 return nbPrintedCounters;
451 template <
class PBASE>
454 boost::format ftm(
" #%|-10s| = %|.8s| %|23t| Message = '%s'" );
457 for (
const auto& i :
c ) { this->msgStream(
level ) << ( ftm % label % i.second % i.first ) <<
endmsg; }
460 print( m_exceptions,
"EXCEPTIONS" );
461 print( m_errors,
"ERRORS" );
462 print( m_warnings,
"WARNINGS" );
463 print( m_infos,
"INFOS" );
466 return m_exceptions.size() + m_errors.size() + m_warnings.size() + m_infos.size();
475 template <
class PBASE>
480 const auto&
properties = this->getProperties();
495 template <
class PBASE>
499 Assert( svc,
"put():: Invalid 'service'!" );
500 Assert( static_cast<bool>(
object ),
"put():: Invalid 'Object'!" );
501 Assert( !
location.empty(),
"put():: Invalid 'address' = '' " );
510 Exception(
"put():: could not register '" +
System::typeinfoName(
typeid( obj ) ) +
"' at address '" +
515 Print(
"The object of type '" +
System::typeinfoName(
typeid( obj ) ) +
"' is registered in TS at address '" +
521 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.