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 m_rootInTES = gAlg->rootInTES();
71 }
else if (
const GaudiTool* gTool = dynamic_cast<const GaudiTool*>( parent ) ) {
72 m_context = gTool->context();
73 m_rootInTES = gTool->rootInTES();
78 auto jos = PBASE::template service<IJobOptionsSvc>(
"JobOptionsSvc" );
79 if ( !jos ) Exception(
"Cannot get JobOptionsSvc" );
82 const auto myList = jos->getProperties( this->
name() );
85 for (
const auto& iter : *myList ) {
88 if ( iter->name().compare(
"Context" ) == 0 ) {
89 m_context = sp->
value();
90 }
else if ( iter->name().compare(
"RootInTES" ) == 0 ) {
91 m_rootInTES = sp->
value();
102 template <
class PBASE>
107 if ( sc.
isFailure() ) {
return Error(
"Failed to initialise base class PBASE", sc ); }
112 if ( !context().empty() ) this->debug() <<
"Created with context = '" << context() <<
"'" <<
endmsg;
116 if ( !m_rootInTES.empty() && m_rootInTES[m_rootInTES.size() - 1] !=
'/' ) m_rootInTES = m_rootInTES +
"/";
119 m_counterSummarySvc = this->svcLoc()->service(
"CounterSummarySvc",
false );
121 if ( !m_counterSummarySvc )
122 this->debug() <<
"could not locate CounterSummarySvc, no counter summary will be made" <<
endmsg;
124 this->debug() <<
"found CounterSummarySvc OK" <<
endmsg;
128 if ( propsPrint() ) {
138 auto rootName = dataMgrSvc->
rootName();
139 if ( !rootName.empty() &&
'/' != rootName.back() ) rootName +=
"/";
142 auto tokens = boost::tokenizer<boost::char_separator<char>>{
location, boost::char_separator<char>{
":"}};
145 std::string r = fullTESLocation( tok, UseRootInTES );
147 if ( r[0] !=
'/' ) r = rootName + r;
148 return s.
empty() ? r : s +
':' + r;
151 this->debug() <<
"Changing " <<
location <<
" to " << result <<
endmsg;
163 r = m_f( h->objKey() );
164 if ( r != h->objKey() ) h->updateKey( r );
167 r = m_f( h->objKey() );
168 if ( r != h->objKey() ) h->updateKey( r );
176 this->m_updateDataHandles = std::make_unique<DHHFixer>( fixLocation );
185 template <
class PBASE>
190 if ( this->msgLevel(
MSG::DEBUG ) || ( statPrint() && this->nCounters() > 0 ) ) {
195 if ( m_counterSummarySvc && this->svcLoc()->existsService(
"CounterSummarySvc" ) ) {
196 if ( this->msgLevel(
MSG::DEBUG ) ) this->debug() <<
"adding counters to CounterSummarySvc" <<
endmsg;
201 for (
const auto& i : m_countersOwn ) {
202 if ( statList.Or( i.first ) )
204 else if ( counterList.Or( i.first ) )
205 m_counterSummarySvc->addCounter( this->name(), i.first, i.second );
210 this->debug() <<
"Tools to release :";
211 for (
const auto& i : m_managedTools ) { this->debug() <<
" " << i->name(); }
214 while ( !m_managedTools.empty() ) {
220 this->debug() <<
"Services to release :";
221 for (
const auto& i : m_services ) this->debug() <<
" " << i->name();
224 while ( !m_services.empty() ) {
229 m_counterSummarySvc.reset();
232 if ( !m_errors.empty() || !m_warnings.empty() || !m_exceptions.empty() ) {
233 this->always() <<
"Exceptions/Errors/Warnings/Infos Statistics : " << m_exceptions.size() <<
"/" << m_errors.size()
234 <<
"/" << m_warnings.size() <<
"/" << m_infos.size() <<
endmsg;
235 if ( errorsPrint() ) { printErrors(); }
239 this->clearCounters();
240 m_countersOwn.clear();
241 m_exceptions.clear();
245 m_counterList.clear();
246 m_statEntityList.clear();
260 template <
class PBASE>
262 if ( !interface ) {
return Error(
"release(IInterface):: IInterface* points to NULL!" ); }
266 return algTool ? releaseTool( algTool ) : releaseSvc( interface );
273 template <
class PBASE>
275 if ( !algTool ) {
return Error(
"releaseTool(IAlgTool):: IAlgTool* points to NULL!" ); }
276 if ( !this->toolSvc() ) {
return Error(
"releaseTool(IAlgTool):: IToolSvc* points to NULL!" ); }
278 auto it =
std::find( m_managedTools.begin(), m_managedTools.end(), algTool );
279 if ( m_managedTools.end() == it ) {
return Warning(
"releaseTool(IAlgTool):: IAlgTool* is not active" ); }
284 if ( this->msgLevel(
MSG::DEBUG ) ) { this->debug() <<
"Releasing tool '" << name <<
"'" <<
endmsg; }
286 PBASE::deregisterTool( t );
287 m_managedTools.erase( it );
291 <<
"' is released" <<
endmsg;
293 const StatusCode sc = this->toolSvc()->releaseTool( t );
294 return sc.
isSuccess() ? sc : Warning(
"releaseTool(IAlgTool):: error from IToolSvc releasing " + name, sc );
301 template <
class PBASE>
303 if ( !Svc )
return Error(
"releaseSvc(IInterface):: IInterface* points to NULL!" );
305 if ( !svc )
return Warning(
"releaseSvc(IInterface):: IInterface* is not a service" );
308 return Warning(
"releaseSvc(IInterface):: IInterface* is not active" );
310 if ( this->msgLevel(
MSG::DEBUG ) ) { this->debug() <<
"Releasing service '" << ( *it )->name() <<
"'" <<
endmsg; }
311 m_services.erase( it );
320 template <
class PBASE>
325 m_services.insert( i,
std::move( svc ) );
327 this->warning() <<
"Service " << svc->name() <<
" already present -- skipping" <<
endmsg;
340 template <
class PBASE>
343 const size_t num = ++m_errors[
msg];
349 return Print(
"The ERROR message is suppressed : '" + msg +
"'", st,
MSG::ERROR );
359 template <
class PBASE>
362 const size_t num = ++m_warnings[
msg];
368 return Print(
"The WARNING message is suppressed : '" + msg +
"'", st,
MSG::WARNING );
378 template <
class PBASE>
381 const size_t num = ++m_infos[
msg];
387 return Print(
"The INFO message is suppressed : '" + msg +
"'", st,
MSG::INFO );
397 template <
class PBASE>
400 if ( !this->msgLevel( lvl ) ) {
return st; }
412 str <<
" StatusCode=" << st.
getCode();
414 str <<
" StatusCode=FAILURE";
428 template <
class PBASE>
432 Print(
"Exception (re)throw: " + msg, sc,
MSG::FATAL ).ignore();
440 template <
class PBASE>
444 Print(
"Exception (re)throw: " + msg, sc,
MSG::FATAL ).ignore();
452 template <
class PBASE>
456 Print(
"Exception throw: " + msg, sc,
MSG::FATAL ).ignore();
464 template <
class PBASE>
468 auto countToBePrinted = [&]() {
473 auto nbPrintedCounters =
474 ( ( !m_printEmptyCounters && !this->msgLevel(
MSG::DEBUG ) ) ? countToBePrinted() : this->nCounters() );
476 if ( nbPrintedCounters == 0 )
return 0;
478 msg <<
"Number of counters : " << nbPrintedCounters <<
"\n" << m_header.value();
480 if ( m_printEmptyCounters || this->msgLevel(
MSG::DEBUG ) ||
counter.toBePrinted() ) {
483 msg <<
"\n" << ost.
str();
489 return nbPrintedCounters;
496 template <
class PBASE>
499 boost::format ftm(
" #%|-10s| = %|.8s| %|23t| Message = '%s'" );
502 for (
const auto& i : c ) { this->msgStream( level ) << ( ftm % label % i.second % i.first ) <<
endmsg; }
505 print( m_exceptions,
"EXCEPTIONS" );
506 print( m_errors,
"ERRORS" );
507 print( m_warnings,
"WARNINGS" );
508 print( m_infos,
"INFOS" );
511 return m_exceptions.size() + m_errors.size() + m_warnings.size() + m_infos.size();
520 template <
class PBASE>
540 template <
class PBASE>
544 Assert( svc,
"put():: Invalid 'service'!" );
545 Assert( static_cast<bool>(
object ),
"put():: Invalid 'Object'!" );
546 Assert( !location.
empty(),
"put():: Invalid 'address' = '' " );
548 const std::string& fullLocation = fullTESLocation( location, useRootInTES );
554 Exception(
"put():: could not register '" +
System::typeinfoName(
typeid( *
object ) ) +
"' at address '" +
559 Print(
"The object of type '" +
System::typeinfoName(
typeid( *
object ) ) +
"' is registered in TS at address '" +
565 return object.release();
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
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.
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
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.
::details::reverse_wrapper< T > reverse(T &&iterable)
Header file for class GaudiAlgorithm.
Gaudi::Details::PropertyBase * property(const std::string &name) const
constexpr static const auto SUCCESS
StatusCode finalize() override
standard finalization method
Data provider interface definition.
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.
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.
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.
The useful base class for data processing algorithms.
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.
collection of useful utilities to print certain objects (currently used for implementation in class G...
virtual const std::string & rootName() const =0
Get Name of root Event.
StatusCode initialize() override
standard initialization method
StatusCode registerObject(boost::string_ref fullPath, DataObject *pObject)
Register object with the data store.
StatusCode releaseTool(const IAlgTool *tool) const
manual forced (and 'safe') release of the tool
constexpr static const auto FAILURE
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.
const ValueType & value() const
Backward compatibility (.
code_t getCode() const
Retrieve value ("checks" the StatusCode)
long printStat(const MSG::Level level=MSG::ALWAYS) const
perform the actual printout of statistical counters
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.