32 #include "boost/algorithm/string/predicate.hpp" 33 namespace ba = boost::algorithm;
40 #define ON_DEBUG if ( msgLevel( MSG::DEBUG ) ) 41 #define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) ) 53 template <
typename MAP,
typename SET>
54 inline void map_to_set(
const MAP&
m,
SET&
s ) {
68 return (
id < rhs.
id );
70 return ( key < rhs.
key );
87 constexpr
struct clear_t {
88 template <
typename T1,
typename T2>
90 const_cast<T1*>( p.first )->release();
104 clear( m_algtoolmap );
116 debug() <<
"Failed to initialize the base class (Service)" <<
endmsg;
121 debug() <<
"Initializing HistorySvc" <<
endmsg;
125 static const bool CREATEIF(
true );
127 if ( service(
"AlgContextSvc", p_algCtxSvc, CREATEIF ).isFailure() ) {
128 error() <<
"unable to get the AlgContextSvc" <<
endmsg;
132 if ( service(
"IncidentSvc", m_incidentSvc, CREATEIF ).isFailure() ) {
133 error() <<
"unable to get the IncidentSvc" <<
endmsg;
139 m_toolSvc = serviceLocator()->service(
"ToolSvc" );
141 error() <<
"could not retrieve the ToolSvc handle !" <<
endmsg;
147 const bool rethrow =
false;
148 const bool oneShot =
true;
151 m_outputFileTypeXML = ba::iends_with( m_outputFile.value(),
".xml" );
152 ON_DEBUG if ( m_outputFileTypeXML ) { debug() <<
"output format is XML" <<
endmsg; }
154 m_isInitialized =
true;
162 if ( !m_jobHistory ) {
165 if ( service(
"JobOptionsSvc", jo ).isFailure() ) {
166 error() <<
"Could not get jobOptionsSvc - " 167 <<
"not adding properties to JobHistory" <<
endmsg;
170 bool foundAppMgr(
false );
173 if ( client ==
"ApplicationMgr" ) foundAppMgr =
true;
174 for (
auto prop : *jo->
getProperties( client ) ) { m_jobHistory->addProperty( client, prop ); }
177 if ( !foundAppMgr ) {
178 auto ap = service<IProperty>(
"ApplicationMgr" );
180 error() <<
"could not get the ApplicationMgr" <<
endmsg;
182 for (
auto prop : ap->getProperties() ) { m_jobHistory->addProperty(
"ApplicationMgr", prop ); }
192 error() <<
"Could not get AlgManager" <<
endmsg;
197 for (
auto ialg : algMgr->getAlgorithms() ) {
200 warning() <<
"Algorithm " << ialg->name() <<
" does not inherit from Gaudi::Algorithm. Not registering it." 204 registerAlg( *alg ).ignore();
208 info() <<
"Registered " <<
count <<
" Algorithms" <<
endmsg;
212 m_isInitialized =
true;
213 for (
auto algtool : m_ialgtools ) {
214 ( const_cast<IAlgTool*>( algtool ) )->addRef();
215 registerAlgTool( *algtool ).ignore();
218 info() <<
"Registered " << m_algtoolmap.size() <<
" AlgTools" <<
endmsg;
224 registerSvc( *svc ).ignore();
238 if ( m_dump ) { listProperties().ignore(); }
240 if ( !m_outputFile.empty() ) {
243 error() <<
"Unable to open output file \"m_outputFile\"" <<
endmsg;
266 if ( status.
isSuccess() ) info() <<
"Service finalised successfully" <<
endmsg;
279 if ( m_algmap.find( &
alg ) != m_algmap.end() ) {
280 warning() <<
"Algorithm " <<
alg.name() <<
" already registered with HistorySvc" <<
endmsg;
284 ( const_cast<Gaudi::Algorithm*>( &
alg ) )->addRef();
290 log <<
"Registering algorithm: ";
302 info() <<
"Dumping properties for " <<
alg.name() <<
endl;
318 if ( !hist ) {
return; }
326 auto itr = m_algmap.find( &
alg );
327 if ( itr == m_algmap.end() ) {
328 warning() <<
"Algorithm " <<
alg.name() <<
" not registered" <<
endmsg;
346 log <<
"Dumping properties for all Algorithms (" << m_algmap.size() <<
")" <<
endmsg;
348 for (
auto&
alg : m_algmap ) { listProperties( *
alg.first ).ignore(); }
352 log <<
"Dumping properties for all AlgTools (" << m_algtoolmap.size() <<
")" <<
endmsg;
354 for (
auto& algtool : m_algtoolmap ) {
356 debug() <<
" --> " << algtool.second->algtool_name() <<
endmsg;
357 listProperties( *algtool.first ).ignore();
362 log <<
"Dumping properties for all Services (" << m_svcmap.size() <<
")" <<
endmsg;
364 for (
auto& svc : m_svcmap ) { listProperties( *svc.first ).ignore(); }
368 log <<
"Dumping properties for Job";
380 for (
const auto& prop : m_jobHistory->propertyPairs() ) {
381 ofs << prop.first <<
" " << dumpProp( prop.second ) <<
std::endl;
385 for (
const auto&
s : m_svcmap ) dumpProperties( *
s.first, ofs );
388 for (
const auto&
alg : m_algmap ) dumpProperties( *
alg.first, ofs );
391 for (
const auto& tool : m_algtoolmap ) dumpProperties( *tool.first, ofs );
399 if ( p_algCtxSvc )
return p_algCtxSvc->currentAlg();
400 warning() <<
"trying to create DataHistoryObj before " 401 <<
"HistorySvc has been initialized" <<
endmsg;
410 if ( !m_activate )
return nullptr;
417 debug() <<
"Could not discover current Algorithm:" <<
endl 418 <<
" object CLID: " <<
id <<
" key: \"" << key <<
"\"" <<
endmsg;
423 algHist = getAlgHistory( *
alg );
425 warning() <<
"Could not extract concrete Algorithm:" <<
endl 426 <<
" object CLID: " <<
id <<
" key: \"" << key <<
"\"" <<
endmsg;
438 auto boundaries = m_datMap.equal_range( dhh );
439 auto match = boundaries.second;
441 if ( boundaries.first != boundaries.second ) {
447 algName = ialg->name();
452 match =
std::find_if( boundaries.first, boundaries.second,
453 [&algName]( decltype( boundaries )::first_type::reference p ) ->
bool {
454 return p.second->algorithmHistory()->algorithm_name() == algName;
458 if ( match == boundaries.second ) {
459 DataHistory* dh = createDataHistoryObj(
id, key, storeName );
472 auto mitr = m_datMap.equal_range( dhh );
473 return ( mitr.first != mitr.second ) ? mitr.first->second :
nullptr;
485 auto mitr = m_datMap.equal_range( dhh );
486 for (
auto itr = mitr.first; itr != mitr.second; ++itr ) {
501 auto itr = m_svcmap.find( psvc );
502 if ( itr == m_svcmap.end() ) {
506 log <<
"Registering Service: ";
514 ( const_cast<IService*>( psvc ) )->addRef();
525 auto itr = m_svcmap.find( psvc );
526 if ( itr != m_svcmap.end() )
return itr->second;
528 warning() <<
"Service " << svc.name() <<
" not registered" <<
endmsg;
539 info() <<
"Dumping properties for " << svc.name() <<
endl;
545 info() << svc.name() <<
" --> " <<
endl << *hist <<
endmsg;
558 for (
auto& prop : hist->
properties() ) { ofs << svc.name() <<
" " << dumpProp( prop ) <<
std::endl; }
565 if ( !m_isInitialized ) {
566 if ( !p_algCtxSvc ) {
567 if ( service(
"AlgContextSvc", p_algCtxSvc,
true ).isFailure() ) {
568 error() <<
"unable to get the AlgContextSvc" <<
endmsg;
572 m_ialgtools.insert( &ialg );
576 const AlgTool*
alg = dynamic_cast<const AlgTool*>( &ialg );
578 error() <<
"Could not dcast IAlgTool \"" << ialg.
name() <<
"\" to an AlgTool" <<
endmsg;
582 if ( m_algtoolmap.find(
alg ) != m_algtoolmap.end() ) {
583 warning() <<
"AlgTool " << ialg.
name() <<
" already registered in HistorySvc" <<
endmsg;
592 log <<
"Registering algtool: ";
605 info() <<
"Dumping properties for " <<
alg.name() <<
endl;
630 const AlgTool* palg = dynamic_cast<const AlgTool*>( &
alg );
631 auto itr = m_algtoolmap.find( palg );
632 if ( itr == m_algtoolmap.end() ) {
633 warning() <<
"AlgTool " <<
alg.name() <<
" not registered" <<
endmsg;
647 if ( incident.
type() == IncidentType::BeginEvent ) {
648 if ( captureState().isFailure() ) {
649 warning() <<
"Error capturing state." <<
endl <<
"Will try again at next BeginEvent incident" <<
endmsg;
675 if ( m_outputFileTypeXML ) {
677 ofs <<
"<?xml version=\"1.0\" ?> " <<
std::endl;
686 for (
auto& item : m_jobHistory->propertyPairs() ) {
691 if ( m_outputFileTypeXML ) {
693 if ( client != client_currently_open ) {
694 if ( client_currently_open !=
"start" ) ofs <<
" </COMPONENT>" <<
endl;
695 ofs <<
" <COMPONENT name=\"" << client <<
"\" class=\"undefined\">" <<
std::endl;
698 ofs << client <<
" ";
701 ofs << dumpProp( prp, m_outputFileTypeXML, 6 ) <<
endl;
703 client_currently_open = client;
705 if ( m_outputFileTypeXML ) ofs <<
" </COMPONENT>" <<
endl;
708 if ( m_outputFileTypeXML ) {
709 ofs <<
"</GLOBAL>" <<
endl <<
"<SERVICES>" <<
endl;
715 auto sortedDump = [&ofs,
this](
const auto&
map ) {
717 for (
const auto& item :
map ) sorted[item.first->name()] = item.first;
718 for (
const auto& item : sorted ) dumpState( item.second, ofs );
721 sortedDump( m_svcmap );
723 if ( m_outputFileTypeXML ) {
724 ofs <<
"</SERVICES>" <<
endl <<
"<ALGORITHMS> " <<
endl;
729 sortedDump( m_algmap );
731 if ( m_outputFileTypeXML ) {
732 ofs <<
"</ALGORITHMS>" <<
endl <<
"<ALGTOOLS> " <<
endl;
737 sortedDump( m_algtoolmap );
739 if ( m_outputFileTypeXML ) { ofs <<
"</ALGTOOLS>" <<
endl <<
"</SETUP>" <<
endl; }
752 if ( ( is = dynamic_cast<const IService*>( in ) ) !=
nullptr ) {
756 hist = dynamic_cast<HistoryObj*>( o );
757 vhist = dynamic_cast<IVersHistoryObj*>( o );
758 }
else if ( ( ia = dynamic_cast<const Gaudi::Algorithm*>( in ) ) !=
nullptr ) {
762 hist = dynamic_cast<HistoryObj*>( o );
763 vhist = dynamic_cast<IVersHistoryObj*>( o );
764 }
else if ( ( it = dynamic_cast<const IAlgTool*>( in ) ) !=
nullptr ) {
768 hist = dynamic_cast<HistoryObj*>( o );
769 vhist = dynamic_cast<IVersHistoryObj*>( o );
771 error() <<
"Could not dcast interface to accepted History Obj type for " << in->
name() <<
endmsg;
775 if ( !hist || !vhist ) {
776 error() <<
"Could not dcast recognized object to HistoryObj or IVersHistoryObj. This should never happen." 781 if ( m_outputFileTypeXML ) {
782 hist->
dump( ofs,
true );
StatusCode reinitialize() override
const PropertyList & properties() const override
void dumpState(std::ofstream &) const
StatusCode initialize() override
IAlgorithm * getCurrentIAlg() const
StatusCode finalize() override
StatusCode registerSvc(const IService &) override
StatusCode registerAlgTool(const IAlgTool &) override
const std::string & type() const
Access to the incident type.
virtual void dump(std::ostream &, const bool isXML=false, int indent=0) const =0
AlgorithmHistory class definition.
StatusCode initialize() override
virtual StatusCode registerDataHistory(const CLID &id, const std::string &key, const std::string &store)
JobHistory * getJobHistory() const override
The IAlgManager is the interface implemented by the Algorithm Factory in the Application Manager to s...
virtual const std::vector< const Gaudi::Details::PropertyBase * > * getProperties(const std::string &client) const =0
Get the properties associated to a given client.
constexpr static const auto SUCCESS
StatusCode stop() override
virtual std::vector< std::string > getClients() const =0
Get the list of clients.
Base class for History Objects.
HistorySvc class definition.
DHH(const CLID &i, std::string k)
AlgorithmHistory * getAlgHistory(const Gaudi::Algorithm &) const override
const std::string name() const
property name
JobHistory class definition.
void handle(const Incident &inc) override
virtual const std::string & name() const =0
Retrieve the name of the instance.
#define DECLARE_COMPONENT(type)
AlgToolHistory * getAlgToolHistory(const IAlgTool &) const override
void dumpProperties(std::ofstream &) const
Main interface for the JobOptions service.
struct GAUDI_API map
Parametrisation class for map-like implementation.
GAUDI_API ISvcLocator * svcLocator()
General service interface definition.
This class is used for returning status codes from appropriate routines.
DataHistory class definition.
const PropertyList & properties() const override
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
unsigned int CLID
Class ID definition.
The IAlgorithm is the interface implemented by the Algorithm base class.
virtual std::ostream & fillStream(std::ostream &) const
the printout of the property value
StatusCode finalize() override
AlgToolHistory class definition.
IInterface compliant class extending IInterface with the name() method.
std::string dumpProp(const Gaudi::Details::PropertyBase *, const bool isXML=false, int indent=0) const
DataHistory * createDataHistoryObj(const CLID &id, const std::string &key, const std::string &store) override
static std::string convert_string(const std::string &)
Base class for all Incidents (computing events).
StatusCode registerJob() override
Base class from which all concrete algorithm classes should be derived.
constexpr static const auto FAILURE
ServiceHistory * getServiceHistory(const IService &) const override
ServiceHistory class definition.
virtual const std::string & name() const =0
virtual const std::list< IService * > & getServices() const =0
Get a reference to a service and create it if it does not exists.
bool operator<(DHH const &rhs) const
Interface for Versioned History Objects.
StatusCode registerAlg(const Gaudi::Algorithm &) override
virtual std::string toString() const =0
value -> string
StatusCode listProperties() const override
virtual StatusCode captureState()
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
std::string documentation() const
property documentation
const PropertyList & properties() const override
DataHistory * getDataHistory(const CLID &id, const std::string &key, const std::string &store) const override