Go to the documentation of this file.
45 #include <fmt/format.h>
51 template <
class PBASE>
56 m_context = gAlg->context();
58 m_context = gTool->context();
66 const auto& optsSvc = this->serviceLocator()->getOptsSvc();
68 if ( optsSvc.has(
key ) ) { this->setPropertyRepr(
"Context", optsSvc.get(
key ) ).ignore(); }
75 template <
class PBASE>
79 const StatusCode sc = base_class::initialize();
80 if ( sc.
isFailure() ) {
return Error(
"Failed to initialise base class PBASE", sc ); }
85 if ( !context().empty() ) this->debug() <<
"Created with context = '" << context() <<
"'" <<
endmsg;
89 m_counterSummarySvc = this->svcLoc()->service(
"CounterSummarySvc",
false );
91 if ( !m_counterSummarySvc )
92 this->debug() <<
"could not locate CounterSummarySvc, no counter summary will be made" <<
endmsg;
94 this->debug() <<
"found CounterSummarySvc OK" <<
endmsg;
98 if ( m_propsPrint.value() ) {
111 template <
class PBASE>
116 if ( m_counterSummarySvc && this->svcLoc()->existsService(
"CounterSummarySvc" ) ) {
117 if ( this->msgLevel(
MSG::DEBUG ) ) this->debug() <<
"adding counters to CounterSummarySvc" <<
endmsg;
121 for (
const auto& i : m_countersOwn ) {
122 if ( counterList.Or( i.first ) ) m_counterSummarySvc->addCounter( this->
name(), i.first, i.second );
127 this->debug() <<
"Tools to release :";
128 for (
const auto& i : m_managedTools ) { this->debug() <<
" " << i->name(); }
131 while ( !m_managedTools.empty() ) {
137 this->debug() <<
"Services to release :";
138 for (
const auto& i : m_services ) this->debug() <<
" " << i->name();
141 while ( !m_services.empty() ) {
146 m_counterSummarySvc.reset();
149 if ( !m_errors.empty() || !m_warnings.empty() || !m_exceptions.empty() ) {
150 this->always() <<
"Exceptions/Errors/Warnings/Infos Statistics : " << m_exceptions.size() <<
"/" << m_errors.size()
151 <<
"/" << m_warnings.size() <<
"/" << m_infos.size() <<
endmsg;
152 if ( m_errorsPrint.value() ) { printErrors(); }
156 m_countersOwn.clear();
157 m_exceptions.clear();
161 m_counterList.clear();
175 template <
class PBASE>
177 if ( !interface ) {
return Error(
"release(IInterface):: IInterface* points to NULL!" ); }
181 return algTool ? releaseTool( algTool ) : releaseSvc( interface );
188 template <
class PBASE>
190 if ( !algTool ) {
return Error(
"releaseTool(IAlgTool):: IAlgTool* points to NULL!" ); }
191 if ( !this->toolSvc() ) {
return Error(
"releaseTool(IAlgTool):: IToolSvc* points to NULL!" ); }
193 auto it =
std::find( m_managedTools.begin(), m_managedTools.end(), algTool );
194 if ( m_managedTools.end() == it ) {
return Warning(
"releaseTool(IAlgTool):: IAlgTool* is not active" ); }
199 if ( this->msgLevel(
MSG::DEBUG ) ) { this->debug() <<
"Releasing tool '" <<
name <<
"'" <<
endmsg; }
201 base_class::deregisterTool(
t );
202 m_managedTools.erase( it );
206 <<
"' is released" <<
endmsg;
208 const StatusCode sc = this->toolSvc()->releaseTool(
t );
209 return sc.
isSuccess() ? sc : Warning(
"releaseTool(IAlgTool):: error from IToolSvc releasing " +
name, sc );
216 template <
class PBASE>
218 if ( !Svc )
return Error(
"releaseSvc(IInterface):: IInterface* points to NULL!" );
220 if ( !svc )
return Warning(
"releaseSvc(IInterface):: IInterface* is not a service" );
223 return Warning(
"releaseSvc(IInterface):: IInterface* is not active" );
225 if ( this->msgLevel(
MSG::DEBUG ) ) { this->debug() <<
"Releasing service '" << ( *it )->name() <<
"'" <<
endmsg; }
226 m_services.erase( it );
235 template <
class PBASE>
240 m_services.insert( i,
std::move( svc ) );
242 this->warning() <<
"Service " << svc->name() <<
" already present -- skipping" <<
endmsg;
255 template <
class PBASE>
258 const size_t num = increment( m_errors,
msg );
262 }
else if ( num == mx )
274 template <
class PBASE>
277 const size_t num = increment( m_warnings,
msg );
281 }
else if ( num == mx )
283 return Print(
std::string{
"The WARNING message is suppressed : '" }.
append(
msg ).append(
"'" ), st,
294 template <
class PBASE>
297 const size_t num = increment( m_infos,
msg );
301 }
else if ( num == mx )
313 template <
class PBASE>
316 if ( !this->msgLevel( lvl ) ) {
return st; }
328 str <<
" StatusCode=" << st.
getCode();
330 str <<
" StatusCode=FAILURE";
344 template <
class PBASE>
347 increment( m_exceptions,
msg );
356 template <
class PBASE>
359 increment( m_exceptions,
msg );
368 template <
class PBASE>
371 increment( m_exceptions,
msg );
380 template <
class PBASE>
382 auto print = [&](
const Counter&
c,
const auto& label ) {
383 for (
const auto& i :
c ) {
384 this->msgStream(
level ) <<
fmt::format(
" #{:<10s} = {:<8d} Message = '{}'", label, i.second, i.first )
389 print( m_exceptions,
"EXCEPTIONS" );
390 print( m_errors,
"ERRORS" );
391 print( m_warnings,
"WARNINGS" );
392 print( m_infos,
"INFOS" );
395 return m_exceptions.size() + m_errors.size() + m_warnings.size() + m_infos.size();
404 template <
class PBASE>
409 const auto&
properties = this->getProperties();
424 template <
class PBASE>
426 std::string_view
location,
const bool useRootInTES )
const {
428 Assert( svc,
"put():: Invalid 'service'!" );
429 Assert(
static_cast<bool>(
object ),
"put():: Invalid 'Object'!" );
430 Assert( !
location.empty(),
"put():: Invalid 'address' = '' " );
432 const auto& fullLocation = this->
fullTESLocation( location, useRootInTES );
439 Exception(
"put():: could not register '" +
System::typeinfoName(
typeid( obj ) ) +
"' at address '" +
444 Print(
"The object of type '" +
System::typeinfoName(
typeid( obj ) ) +
"' is registered in TS at address '" +
450 return object.release();
long printErrors(const MSG::Level level=MSG::ALWAYS) const
perform the actual printout of error counters
StatusCode releaseTool(const IAlgTool *tool) const
manual forced (and 'safe') release of the tool
::details::reverse_wrapper< T > reverse(T &&iterable)
constexpr const struct GaudiCommon_details::svc_lt_t svc_lt
std::string fullTESLocation(std::string_view location, std::string_view rit)
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
StatusCode registerObject(std::string_view fullPath, DataObject *pObject)
Register object with the data store.
void initGaudiCommonConstructor(const IInterface *parent=nullptr)
Constructor initializations.
auto get(const Handle &handle, const Algo &, const EventContext &) -> decltype(details::deref(handle.get()))
StatusCode Print(std::string_view msg, const StatusCode st=StatusCode::SUCCESS, const MSG::Level lev=MSG::INFO) const
Print the message and return with the given StatusCode.
constexpr const struct GaudiCommon_details::svc_eq_t svc_eq
StatusCode Warning(std::string_view msg, const StatusCode st=StatusCode::FAILURE, const size_t mx=10) const
Print the warning message and return with the given StatusCode.
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
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
void addToServiceList(SmartIF< IService > svc) const
Add the given service to the list of acquired services.
StatusCode release(const IInterface *interface) const
Manual forced (and 'safe') release of the active tool or service.
DataObject * put(IDataProviderSvc *svc, std::unique_ptr< DataObject > object, std::string_view location, const bool useRootInTES=true) const
Register a data object or container into Gaudi Event Transient Store.
StatusCode initialize() override
standard initialization method
long printProps(const MSG::Level level=MSG::ALWAYS) const
perform the actual printout of properties
StatusCode finalize() override
standard finalization method
constexpr static const auto SUCCESS
void Exception(std::string_view msg, const GaudiException &exc, const StatusCode sc=StatusCode::FAILURE) const
Create and (re)-throw a given GaudiException.
code_t getCode() const
Retrieve value.
constexpr static const auto FAILURE
StatusCode Info(std::string_view msg, const StatusCode st=StatusCode::SUCCESS, const size_t mx=10) const
Print the info message and return with the given StatusCode.
StatusCode Error(std::string_view msg, const StatusCode st=StatusCode::FAILURE, const size_t mx=10) const
Print the error message and return with the given StatusCode.