42 #include "boost/algorithm/string/predicate.hpp" 43 namespace ba = boost::algorithm;
50 #define ON_DEBUG if ( msgLevel( MSG::DEBUG ) ) 51 #define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) ) 63 template <
typename MAP,
typename SET>
64 inline void map_to_set(
const MAP&
m,
SET&
s ) {
78 return (
id < rhs.
id );
80 return ( key < rhs.
key );
97 constexpr
struct clear_t {
98 template <
typename T1,
typename T2>
100 const_cast<T1*>( p.first )->release();
104 template <
typename M>
114 clear( m_algtoolmap );
126 debug() <<
"Failed to initialize the base class (Service)" <<
endmsg;
131 debug() <<
"Initializing HistorySvc" <<
endmsg;
135 static const bool CREATEIF(
true );
137 if ( service(
"AlgContextSvc", p_algCtxSvc, CREATEIF ).isFailure() ) {
138 error() <<
"unable to get the AlgContextSvc" <<
endmsg;
142 if ( service(
"IncidentSvc", m_incidentSvc, CREATEIF ).isFailure() ) {
143 error() <<
"unable to get the IncidentSvc" <<
endmsg;
149 m_toolSvc = serviceLocator()->service(
"ToolSvc" );
151 error() <<
"could not retrieve the ToolSvc handle !" <<
endmsg;
157 const bool rethrow =
false;
158 const bool oneShot =
true;
161 m_outputFileTypeXML = ba::iends_with( m_outputFile.value(),
".xml" );
162 ON_DEBUG if ( m_outputFileTypeXML ) { debug() <<
"output format is XML" <<
endmsg; }
164 m_isInitialized =
true;
172 if ( !m_jobHistory ) {
175 if ( service(
"JobOptionsSvc", jo ).isFailure() ) {
176 error() <<
"Could not get jobOptionsSvc - " 177 <<
"not adding properties to JobHistory" <<
endmsg;
180 bool foundAppMgr(
false );
183 if ( client ==
"ApplicationMgr" ) foundAppMgr =
true;
184 for (
auto prop : *jo->
getProperties( client ) ) { m_jobHistory->addProperty( client, prop ); }
187 if ( !foundAppMgr ) {
188 auto ap = service<IProperty>(
"ApplicationMgr" );
190 error() <<
"could not get the ApplicationMgr" <<
endmsg;
192 for (
auto prop : ap->getProperties() ) { m_jobHistory->addProperty(
"ApplicationMgr", prop ); }
202 error() <<
"Could not get AlgManager" <<
endmsg;
207 for (
auto ialg : algMgr->getAlgorithms() ) {
210 warning() <<
"Algorithm " << ialg->name() <<
" does not inherit from Gaudi::Algorithm. Not registering it." 214 registerAlg( *alg ).ignore();
218 info() <<
"Registered " <<
count <<
" Algorithms" <<
endmsg;
222 m_isInitialized =
true;
223 for (
auto algtool : m_ialgtools ) {
224 ( const_cast<IAlgTool*>( algtool ) )->addRef();
225 registerAlgTool( *algtool ).ignore();
228 info() <<
"Registered " << m_algtoolmap.size() <<
" AlgTools" <<
endmsg;
234 registerSvc( *svc ).ignore();
248 if ( m_dump ) { listProperties().ignore(); }
250 if ( !m_outputFile.empty() ) {
253 error() <<
"Unable to open output file \"m_outputFile\"" <<
endmsg;
276 if ( status.
isSuccess() ) info() <<
"Service finalised successfully" <<
endmsg;
289 if ( m_algmap.find( &
alg ) != m_algmap.end() ) {
290 warning() <<
"Algorithm " <<
alg.name() <<
" already registered with HistorySvc" <<
endmsg;
294 ( const_cast<Gaudi::Algorithm*>( &
alg ) )->addRef();
300 log <<
"Registering algorithm: ";
312 info() <<
"Dumping properties for " <<
alg.name() <<
endl;
328 if ( !hist ) {
return; }
336 auto itr = m_algmap.find( &
alg );
337 if ( itr == m_algmap.end() ) {
338 warning() <<
"Algorithm " <<
alg.name() <<
" not registered" <<
endmsg;
356 log <<
"Dumping properties for all Algorithms (" << m_algmap.size() <<
")" <<
endmsg;
358 for (
auto&
alg : m_algmap ) { listProperties( *
alg.first ).ignore(); }
362 log <<
"Dumping properties for all AlgTools (" << m_algtoolmap.size() <<
")" <<
endmsg;
364 for (
auto& algtool : m_algtoolmap ) {
366 debug() <<
" --> " << algtool.second->algtool_name() <<
endmsg;
367 listProperties( *algtool.first ).ignore();
372 log <<
"Dumping properties for all Services (" << m_svcmap.size() <<
")" <<
endmsg;
374 for (
auto& svc : m_svcmap ) { listProperties( *svc.first ).ignore(); }
378 log <<
"Dumping properties for Job";
390 for (
const auto& prop : m_jobHistory->propertyPairs() ) {
391 ofs << prop.first <<
" " << dumpProp( prop.second ) <<
std::endl;
395 for (
const auto&
s : m_svcmap ) dumpProperties( *
s.first, ofs );
398 for (
const auto&
alg : m_algmap ) dumpProperties( *
alg.first, ofs );
401 for (
const auto& tool : m_algtoolmap ) dumpProperties( *tool.first, ofs );
409 if ( p_algCtxSvc )
return p_algCtxSvc->currentAlg();
410 warning() <<
"trying to create DataHistoryObj before " 411 <<
"HistorySvc has been initialized" <<
endmsg;
420 if ( !m_activate )
return nullptr;
427 debug() <<
"Could not discover current Algorithm:" <<
endl 428 <<
" object CLID: " <<
id <<
" key: \"" << key <<
"\"" <<
endmsg;
433 algHist = getAlgHistory( *
alg );
435 warning() <<
"Could not extract concrete Algorithm:" <<
endl 436 <<
" object CLID: " <<
id <<
" key: \"" << key <<
"\"" <<
endmsg;
448 auto boundaries = m_datMap.equal_range( dhh );
449 auto match = boundaries.second;
451 if ( boundaries.first != boundaries.second ) {
457 algName = ialg->name();
462 match =
std::find_if( boundaries.first, boundaries.second,
463 [&algName]( decltype( boundaries )::first_type::reference p ) ->
bool {
464 return p.second->algorithmHistory()->algorithm_name() == algName;
468 if ( match == boundaries.second ) {
469 DataHistory* dh = createDataHistoryObj(
id, key, storeName );
482 auto mitr = m_datMap.equal_range( dhh );
483 return ( mitr.first != mitr.second ) ? mitr.first->second :
nullptr;
495 auto mitr = m_datMap.equal_range( dhh );
496 for (
auto itr = mitr.first; itr != mitr.second; ++itr ) {
511 auto itr = m_svcmap.find( psvc );
512 if ( itr == m_svcmap.end() ) {
516 log <<
"Registering Service: ";
524 ( const_cast<IService*>( psvc ) )->addRef();
535 auto itr = m_svcmap.find( psvc );
536 if ( itr != m_svcmap.end() )
return itr->second;
538 warning() <<
"Service " << svc.name() <<
" not registered" <<
endmsg;
549 info() <<
"Dumping properties for " << svc.name() <<
endl;
555 info() << svc.name() <<
" --> " <<
endl << *hist <<
endmsg;
568 for (
auto& prop : hist->
properties() ) { ofs << svc.name() <<
" " << dumpProp( prop ) <<
std::endl; }
575 if ( !m_isInitialized ) {
576 if ( !p_algCtxSvc ) {
577 if ( service(
"AlgContextSvc", p_algCtxSvc,
true ).isFailure() ) {
578 error() <<
"unable to get the AlgContextSvc" <<
endmsg;
582 m_ialgtools.insert( &ialg );
586 const AlgTool*
alg = dynamic_cast<const AlgTool*>( &ialg );
588 error() <<
"Could not dcast IAlgTool \"" << ialg.
name() <<
"\" to an AlgTool" <<
endmsg;
592 if ( m_algtoolmap.find(
alg ) != m_algtoolmap.end() ) {
593 warning() <<
"AlgTool " << ialg.
name() <<
" already registered in HistorySvc" <<
endmsg;
602 log <<
"Registering algtool: ";
615 info() <<
"Dumping properties for " <<
alg.name() <<
endl;
640 const AlgTool* palg = dynamic_cast<const AlgTool*>( &
alg );
641 auto itr = m_algtoolmap.find( palg );
642 if ( itr == m_algtoolmap.end() ) {
643 warning() <<
"AlgTool " <<
alg.name() <<
" not registered" <<
endmsg;
657 if ( incident.
type() == IncidentType::BeginEvent ) {
658 if ( captureState().isFailure() ) {
659 warning() <<
"Error capturing state." <<
endl <<
"Will try again at next BeginEvent incident" <<
endmsg;
685 if ( m_outputFileTypeXML ) {
687 ofs <<
"<?xml version=\"1.0\" ?> " <<
std::endl;
696 for (
auto& item : m_jobHistory->propertyPairs() ) {
701 if ( m_outputFileTypeXML ) {
703 if ( client != client_currently_open ) {
704 if ( client_currently_open !=
"start" ) ofs <<
" </COMPONENT>" <<
endl;
705 ofs <<
" <COMPONENT name=\"" << client <<
"\" class=\"undefined\">" <<
std::endl;
708 ofs << client <<
" ";
711 ofs << dumpProp( prp, m_outputFileTypeXML, 6 ) <<
endl;
713 client_currently_open = client;
715 if ( m_outputFileTypeXML ) ofs <<
" </COMPONENT>" <<
endl;
718 if ( m_outputFileTypeXML ) {
719 ofs <<
"</GLOBAL>" <<
endl <<
"<SERVICES>" <<
endl;
725 auto sortedDump = [&ofs,
this](
const auto&
map ) {
727 for (
const auto& item :
map ) sorted[item.first->name()] = item.first;
728 for (
const auto& item : sorted ) dumpState( item.second, ofs );
731 sortedDump( m_svcmap );
733 if ( m_outputFileTypeXML ) {
734 ofs <<
"</SERVICES>" <<
endl <<
"<ALGORITHMS> " <<
endl;
739 sortedDump( m_algmap );
741 if ( m_outputFileTypeXML ) {
742 ofs <<
"</ALGORITHMS>" <<
endl <<
"<ALGTOOLS> " <<
endl;
747 sortedDump( m_algtoolmap );
749 if ( m_outputFileTypeXML ) { ofs <<
"</ALGTOOLS>" <<
endl <<
"</SETUP>" <<
endl; }
762 if ( ( is = dynamic_cast<const IService*>( in ) ) !=
nullptr ) {
766 hist = dynamic_cast<HistoryObj*>( o );
767 vhist = dynamic_cast<IVersHistoryObj*>( o );
768 }
else if ( ( ia = dynamic_cast<const Gaudi::Algorithm*>( in ) ) !=
nullptr ) {
772 hist = dynamic_cast<HistoryObj*>( o );
773 vhist = dynamic_cast<IVersHistoryObj*>( o );
774 }
else if ( ( it = dynamic_cast<const IAlgTool*>( in ) ) !=
nullptr ) {
778 hist = dynamic_cast<HistoryObj*>( o );
779 vhist = dynamic_cast<IVersHistoryObj*>( o );
781 error() <<
"Could not dcast interface to accepted History Obj type for " << in->
name() <<
endmsg;
785 if ( !hist || !vhist ) {
786 error() <<
"Could not dcast recognized object to HistoryObj or IVersHistoryObj. This should never happen." 791 if ( m_outputFileTypeXML ) {
792 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 std::ostream & dump(std::ostream &, 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