52 #include "boost/format.hpp" 53 #include "boost/tokenizer.hpp" 57 #pragma warning( disable : 4661 ) // incomplete explicit templates 64 template <
class PBASE>
69 if (
const GaudiAlgorithm* gAlg = dynamic_cast<const GaudiAlgorithm*>( parent ) ) {
70 m_context = gAlg->context();
71 m_rootInTES = gAlg->rootInTES();
72 }
else if (
const GaudiTool* gTool = dynamic_cast<const GaudiTool*>( parent ) ) {
73 m_context = gTool->context();
74 m_rootInTES = gTool->rootInTES();
79 auto jos = PBASE::template service<IJobOptionsSvc>(
"JobOptionsSvc" );
80 if ( !jos ) Exception(
"Cannot get JobOptionsSvc" );
83 const auto myList = jos->getProperties( this->
name() );
86 for (
const auto& iter : *myList ) {
89 if ( iter->name().compare(
"Context" ) == 0 ) {
90 m_context = sp->
value();
91 }
else if ( iter->name().compare(
"RootInTES" ) == 0 ) {
92 m_rootInTES = sp->
value();
103 template <
class PBASE>
116 return Error(
"Failed to initialise base class PBASE", sc );
122 if ( !context().empty() ) this->debug() <<
"Created with context = '" << context() <<
"'" <<
endmsg;
126 if ( !m_rootInTES.empty() && m_rootInTES[m_rootInTES.size() - 1] !=
'/' ) m_rootInTES = m_rootInTES +
"/";
129 m_counterSummarySvc = this->svcLoc()->service(
"CounterSummarySvc",
false );
131 if ( !m_counterSummarySvc )
132 this->debug() <<
"could not locate CounterSummarySvc, no counter summary will be made" <<
endmsg;
134 this->debug() <<
"found CounterSummarySvc OK" <<
endmsg;
138 if ( propsPrint() ) {
148 auto rootName = dataMgrSvc->
rootName();
149 if ( !rootName.empty() &&
'/' != rootName.back() ) rootName +=
"/";
152 auto tokens = boost::tokenizer<boost::char_separator<char>>{
location, boost::char_separator<char>{
":"}};
155 std::string r = fullTESLocation( tok, UseRootInTES );
157 if ( r[0] !=
'/' ) r = rootName + r;
158 return s.
empty() ? r : s +
':' + r;
161 this->debug() <<
"Changing " <<
location <<
" to " << result <<
endmsg;
175 r = m_f( h->objKey() );
176 if ( r != h->objKey() ) h->updateKey( r );
179 r = m_f( h->objKey() );
180 if ( r != h->objKey() ) h->updateKey( r );
188 this->m_updateDataHandles = std::make_unique<DHHFixer>( fixLocation );
197 template <
class PBASE>
209 if ( this->msgLevel(
MSG::DEBUG ) || ( statPrint() && !m_counters.empty() ) ) {
214 if ( m_counterSummarySvc && this->svcLoc()->existsService(
"CounterSummarySvc" ) ) {
215 if ( this->msgLevel(
MSG::DEBUG ) ) this->debug() <<
"adding counters to CounterSummarySvc" <<
endmsg;
220 for (
const auto& i : m_countersOwn ) {
221 if ( statList.Or( i.first ) )
223 else if ( counterList.Or( i.first ) )
224 m_counterSummarySvc->addCounter( this->name(), i.first, i.second );
229 this->debug() <<
"Tools to release :";
230 for (
const auto& i : m_managedTools ) {
231 this->debug() <<
" " << i->name();
235 while ( !m_managedTools.empty() ) {
241 this->debug() <<
"Services to release :";
242 for (
const auto& i : m_services ) this->debug() <<
" " << i->name();
245 while ( !m_services.empty() ) {
250 m_counterSummarySvc.reset();
253 if ( !m_errors.empty() || !m_warnings.empty() || !m_exceptions.empty() ) {
254 this->always() <<
"Exceptions/Errors/Warnings/Infos Statistics : " << m_exceptions.size() <<
"/" << m_errors.size()
255 <<
"/" << m_warnings.size() <<
"/" << m_infos.size() <<
endmsg;
256 if ( errorsPrint() ) {
263 m_countersOwn.clear();
264 m_exceptions.clear();
268 m_counterList.clear();
269 m_statEntityList.clear();
283 template <
class PBASE>
287 return Error(
"release(IInterface):: IInterface* points to NULL!" );
292 return algTool ? releaseTool( algTool ) : releaseSvc( interface );
299 template <
class PBASE>
303 return Error(
"releaseTool(IAlgTool):: IAlgTool* points to NULL!" );
305 if ( !this->toolSvc() ) {
306 return Error(
"releaseTool(IAlgTool):: IToolSvc* points to NULL!" );
309 auto it =
std::find( m_managedTools.begin(), m_managedTools.end(), algTool );
310 if ( m_managedTools.end() == it ) {
311 return Warning(
"releaseTool(IAlgTool):: IAlgTool* is not active" );
318 this->debug() <<
"Releasing tool '" << name <<
"'" <<
endmsg;
321 PBASE::deregisterTool( t );
322 m_managedTools.erase( it );
326 <<
"' is released" <<
endmsg;
328 const StatusCode sc = this->toolSvc()->releaseTool( t );
329 return sc.
isSuccess() ? sc : Warning(
"releaseTool(IAlgTool):: error from IToolSvc releasing " + name, sc );
336 template <
class PBASE>
339 if ( !Svc )
return Error(
"releaseSvc(IInterface):: IInterface* points to NULL!" );
341 if ( !svc )
return Warning(
"releaseSvc(IInterface):: IInterface* is not a service" );
344 return Warning(
"releaseSvc(IInterface):: IInterface* is not active" );
347 this->debug() <<
"Releasing service '" << ( *it )->name() <<
"'" <<
endmsg;
349 m_services.erase( it );
358 template <
class PBASE>
364 m_services.insert( i,
std::move( svc ) );
366 this->warning() <<
"Service " << svc->name() <<
" already present -- skipping" <<
endmsg;
379 template <
class PBASE>
383 const size_t num = ++m_errors[
msg];
389 return Print(
"The ERROR message is suppressed : '" + msg +
"'", st,
MSG::ERROR );
399 template <
class PBASE>
403 const size_t num = ++m_warnings[
msg];
409 return Print(
"The WARNING message is suppressed : '" + msg +
"'", st,
MSG::WARNING );
419 template <
class PBASE>
423 const size_t num = ++m_infos[
msg];
429 return Print(
"The INFO message is suppressed : '" + msg +
"'", st,
MSG::INFO );
439 template <
class PBASE>
443 if ( !this->msgLevel( lvl ) ) {
459 str <<
" StatusCode=" << st.
getCode();
461 str <<
" StatusCode=FAILURE";
475 template <
class PBASE>
480 Print(
"Exception (re)throw: " + msg, sc,
MSG::FATAL ).ignore();
488 template <
class PBASE>
493 Print(
"Exception (re)throw: " + msg, sc,
MSG::FATAL ).ignore();
501 template <
class PBASE>
506 Print(
"Exception throw: " + msg, sc,
MSG::FATAL ).ignore();
514 template <
class PBASE>
519 unsigned int nbPrintedCounters = 0;
520 if ( !m_printEmptyCounters && !this->msgLevel(
MSG::DEBUG ) ) {
522 m_counters.begin(), m_counters.end(), nbPrintedCounters,
523 [](
unsigned int&
sum,
const auto& entry ) {
return sum + entry.second.get().toBePrinted(); } );
525 nbPrintedCounters = m_counters.size();
528 if ( nbPrintedCounters == 0 ) {
532 msg <<
"Number of counters : " << nbPrintedCounters <<
"\n" << m_header.value();
533 for (
const auto& entry : m_counters ) {
534 if ( m_printEmptyCounters || this->msgLevel(
MSG::DEBUG ) || entry.second.get().toBePrinted() ) {
536 entry.second.get().print( ost, entry.first );
537 msg <<
"\n" << ost.
str();
543 return nbPrintedCounters;
550 template <
class PBASE>
554 boost::format ftm(
" #%|-10s| = %|.8s| %|23t| Message = '%s'" );
557 for (
const auto& i : c ) {
558 this->msgStream( level ) << ( ftm % label % i.second % i.first ) <<
endmsg;
562 print( m_exceptions,
"EXCEPTIONS" );
563 print( m_errors,
"ERRORS" );
564 print( m_warnings,
"WARNINGS" );
565 print( m_infos,
"INFOS" );
568 return m_exceptions.size() + m_errors.size() + m_warnings.size() + m_infos.size();
577 template <
class PBASE>
587 msg <<
"Property ['Name': Value] = " << *
property <<
endmsg;
600 template <
class PBASE>
605 Assert( svc,
"put():: Invalid 'service'!" );
606 Assert( static_cast<bool>(
object ),
"put():: Invalid 'Object'!" );
607 Assert( !location.
empty(),
"put():: Invalid 'address' = '' " );
609 const std::string& fullLocation = fullTESLocation( location, useRootInTES );
615 Exception(
"put():: could not register '" +
System::typeinfoName(
typeid( *
object ) ) +
"' at address '" +
620 Print(
"The object of type '" +
System::typeinfoName(
typeid( *
object ) ) +
"' is registered in TS at address '" +
626 return object.release();
constexpr static const auto FAILURE
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.
double sum(double x, double y, double z)
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
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.
constexpr static const auto SUCCESS
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
Implements the common functionality between GaudiTools and GaudiAlgorithms.
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.