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 ) ) 54 template <
typename MAP,
typename SET>
55 inline void map_to_set(
const MAP&
m,
SET&
s )
71 return (
id < rhs.
id );
73 return ( key < rhs.
key );
92 constexpr
struct clear_t {
93 template <
typename T1,
typename T2>
96 const_cast<T1*
>( p.first )->release();
100 template <
typename M>
112 clear( m_algtoolmap );
125 debug() <<
"Failed to initialize the base class (Service)" <<
endmsg;
130 debug() <<
"Initializing HistorySvc" <<
endmsg;
134 static const bool CREATEIF(
true );
136 if ( service(
"AlgContextSvc", p_algCtxSvc, CREATEIF ).isFailure() ) {
137 error() <<
"unable to get the AlgContextSvc" <<
endmsg;
141 if ( service(
"IncidentSvc", m_incidentSvc, CREATEIF ).isFailure() ) {
142 error() <<
"unable to get the IncidentSvc" <<
endmsg;
148 m_toolSvc = serviceLocator()->service(
"ToolSvc" );
150 error() <<
"could not retrieve the ToolSvc handle !" <<
endmsg;
156 const bool rethrow =
false;
157 const bool oneShot =
true;
160 m_outputFileTypeXML = ba::iends_with( m_outputFile.value(),
".xml" );
161 ON_DEBUG if ( m_outputFileTypeXML ) { debug() <<
"output format is XML" <<
endmsg; }
163 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;
185 m_jobHistory->addProperty( client, prop );
189 if ( !foundAppMgr ) {
190 auto ap = service<IProperty>(
"ApplicationMgr" );
192 error() <<
"could not get the ApplicationMgr" <<
endmsg;
194 for (
auto prop : ap->getProperties() ) {
195 m_jobHistory->addProperty(
"ApplicationMgr", prop );
206 error() <<
"Could not get AlgManager" <<
endmsg;
211 for (
auto ialg : algMgr->getAlgorithms() ) {
214 warning() <<
"Algorithm " << ialg->
name() <<
" does not inherit from Algorithm. Not registering it." <<
endmsg;
217 registerAlg( *alg ).ignore();
221 info() <<
"Registered " << count <<
" Algorithms" <<
endmsg;
225 m_isInitialized =
true;
226 for (
auto algtool : m_ialgtools ) {
227 (
const_cast<IAlgTool*
>( algtool ) )->addRef();
228 registerAlgTool( *algtool ).ignore();
231 info() <<
"Registered " << m_algtoolmap.size() <<
" AlgTools" <<
endmsg;
237 registerSvc( *svc ).ignore();
253 listProperties().ignore();
256 if ( !m_outputFile.empty() ) {
259 error() <<
"Unable to open output file \"m_outputFile\"" <<
endmsg;
283 if ( status.
isSuccess() ) info() <<
"Service finalised successfully" <<
endmsg;
297 if ( m_algmap.find( &alg ) != m_algmap.end() ) {
298 warning() <<
"Algorithm " << alg.
name() <<
" already registered with HistorySvc" <<
endmsg;
302 (
const_cast<Algorithm*
>( &alg ) )->addRef();
309 log <<
"Registering algorithm: ";
322 info() <<
"Dumping properties for " << alg.
name() <<
endl;
345 PropertyList::const_iterator itr;
355 auto itr = m_algmap.find( &alg );
356 if ( itr == m_algmap.end() ) {
357 warning() <<
"Algorithm " << alg.
name() <<
" not registered" <<
endmsg;
376 log <<
"Dumping properties for all Algorithms (" << m_algmap.size() <<
")" <<
endmsg;
378 for (
auto& alg : m_algmap ) {
379 listProperties( *alg.first ).ignore();
384 log <<
"Dumping properties for all AlgTools (" << m_algtoolmap.size() <<
")" <<
endmsg;
386 for (
auto& algtool : m_algtoolmap ) {
388 debug() <<
" --> " << algtool.second->algtool_name() <<
endmsg;
389 listProperties( *algtool.first ).ignore();
394 log <<
"Dumping properties for all Services (" << m_svcmap.size() <<
")" <<
endmsg;
396 for (
auto& svc : m_svcmap ) {
397 listProperties( *svc.first ).ignore();
402 log <<
"Dumping properties for Job";
415 for (
const auto& prop : m_jobHistory->propertyPairs() ) {
416 ofs << prop.first <<
" " << dumpProp( prop.second ) <<
std::endl;
419 ofs << std::endl <<
"SERVICES" <<
std::endl;
420 for (
const auto&
s : m_svcmap ) dumpProperties( *
s.first, ofs );
422 ofs << std::endl <<
"ALGORITHMS" <<
std::endl;
423 for (
const auto& alg : m_algmap ) dumpProperties( *alg.first, ofs );
425 ofs << std::endl <<
"ALGTOOLS" <<
std::endl;
426 for (
const auto& tool : m_algtoolmap ) dumpProperties( *tool.first, ofs );
435 if ( p_algCtxSvc )
return p_algCtxSvc->currentAlg();
436 warning() <<
"trying to create DataHistoryObj before " 437 <<
"HistorySvc has been initialized" <<
endmsg;
447 if ( !m_activate )
return nullptr;
454 debug() <<
"Could not discover current Algorithm:" <<
endl 455 <<
" object CLID: " <<
id <<
" key: \"" << key <<
"\"" <<
endmsg;
460 algHist = getAlgHistory( *alg );
462 warning() <<
"Could not extract concrete Algorithm:" <<
endl 463 <<
" object CLID: " <<
id <<
" key: \"" << key <<
"\"" <<
endmsg;
476 auto boundaries = m_datMap.equal_range( dhh );
477 auto match = boundaries.second;
479 if ( boundaries.first != boundaries.second ) {
485 algName = ialg->name();
490 match =
std::find_if( boundaries.first, boundaries.second,
491 [&algName]( decltype( boundaries )::first_type::reference p ) ->
bool {
492 return p.second->algorithmHistory()->algorithm_name() == algName;
496 if ( match == boundaries.second ) {
497 DataHistory* dh = createDataHistoryObj(
id, key, storeName );
511 auto mitr = m_datMap.equal_range( dhh );
512 return ( mitr.first != mitr.second ) ? mitr.first->second :
nullptr;
525 auto mitr = m_datMap.equal_range( dhh );
526 for (
auto itr = mitr.first; itr != mitr.second; ++itr ) {
538 if ( svc.name() ==
"HistoryStore" ) {
544 auto itr = m_svcmap.find( psvc );
545 if ( itr == m_svcmap.end() ) {
550 log <<
"Registering Service: ";
558 (
const_cast<IService*
>( psvc ) )->addRef();
570 auto itr = m_svcmap.find( psvc );
571 if ( itr != m_svcmap.end() )
return itr->second;
573 warning() <<
"Service " << svc.name() <<
" not registered" <<
endmsg;
585 info() <<
"Dumping properties for " << svc.name() <<
endl;
591 info() << svc.name() <<
" --> " <<
endl << *hist <<
endmsg;
606 ofs << svc.name() <<
" " << dumpProp( prop ) <<
std::endl;
615 if ( !m_isInitialized ) {
616 if ( !p_algCtxSvc ) {
617 if ( service(
"AlgContextSvc", p_algCtxSvc,
true ).isFailure() ) {
618 error() <<
"unable to get the AlgContextSvc" <<
endmsg;
622 m_ialgtools.insert( &ialg );
628 error() <<
"Could not dcast IAlgTool \"" << ialg.
name() <<
"\" to an AlgTool" <<
endmsg;
632 if ( m_algtoolmap.find( alg ) != m_algtoolmap.end() ) {
633 warning() <<
"AlgTool " << ialg.
name() <<
" already registered in HistorySvc" <<
endmsg;
643 log <<
"Registering algtool: ";
657 info() <<
"Dumping properties for " << alg.
name() <<
endl;
687 auto itr = m_algtoolmap.find( palg );
688 if ( itr == m_algtoolmap.end() ) {
689 warning() <<
"AlgTool " << alg.
name() <<
" not registered" <<
endmsg;
704 if ( incident.
type() == IncidentType::BeginEvent ) {
705 if ( captureState().isFailure() ) {
706 warning() <<
"Error capturing state." <<
endl <<
"Will try again at next BeginEvent incident" <<
endmsg;
734 if ( m_outputFileTypeXML ) {
736 ofs <<
"<?xml version=\"1.0\" ?> " <<
std::endl;
745 for (
auto& item : m_jobHistory->propertyPairs() ) {
750 if ( m_outputFileTypeXML ) {
752 if ( client != client_currently_open ) {
753 if ( client_currently_open !=
"start" ) ofs <<
" </COMPONENT>" <<
endl;
754 ofs <<
" <COMPONENT name=\"" << client <<
"\" class=\"undefined\">" <<
std::endl;
757 ofs << client <<
" ";
760 ofs << dumpProp( prp, m_outputFileTypeXML, 6 ) <<
endl;
762 client_currently_open = client;
764 if ( m_outputFileTypeXML ) ofs <<
" </COMPONENT>" << endl;
767 if ( m_outputFileTypeXML ) {
768 ofs <<
"</GLOBAL>" <<
endl <<
"<SERVICES>" <<
endl;
774 auto sortedDump = [&ofs,
this](
const auto&
map ) {
776 for (
const auto& item :
map ) sorted[item.first->name()] = item.first;
777 for (
const auto& item : sorted ) dumpState( item.second, ofs );
780 sortedDump( m_svcmap );
782 if ( m_outputFileTypeXML ) {
783 ofs <<
"</SERVICES>" <<
endl <<
"<ALGORITHMS> " <<
endl;
788 sortedDump( m_algmap );
790 if ( m_outputFileTypeXML ) {
791 ofs <<
"</ALGORITHMS>" <<
endl <<
"<ALGTOOLS> " <<
endl;
796 sortedDump( m_algtoolmap );
798 if ( m_outputFileTypeXML ) {
799 ofs <<
"</ALGTOOLS>" <<
endl <<
"</SETUP>" <<
endl;
814 if ( ( is = dynamic_cast<const IService*>( in ) ) !=
nullptr ) {
820 }
else if ( ( ia = dynamic_cast<const Algorithm*>( in ) ) !=
nullptr ) {
826 }
else if ( ( it = dynamic_cast<const IAlgTool*>( in ) ) !=
nullptr ) {
833 error() <<
"Could not dcast interface to accepted History Obj type for " << in->
name() <<
endmsg;
837 if ( !hist || !vhist ) {
838 error() <<
"Could not dcast recognized object to HistoryObj or IVersHistoryObj. This should never happen." 843 if ( m_outputFileTypeXML ) {
844 hist->
dump( ofs,
true );
StatusCode reinitialize() override
virtual const std::string & name() const =0
AlgToolHistory * getAlgToolHistory(const IAlgTool &) const override
constexpr static const auto FAILURE
StatusCode initialize() override
const std::string & name() const override
The identifying name of the algorithm object.
const std::string & type() const
Access to the incident type.
StatusCode finalize() override
StatusCode registerSvc(const IService &) override
StatusCode registerAlgTool(const IAlgTool &) override
std::string dumpProp(const Gaudi::Details::PropertyBase *, const bool isXML=false, int indent=0) const
StatusCode registerAlg(const Algorithm &) override
const std::string name() const
property name
AlgorithmHistory class definition.
StatusCode initialize() override
StatusCode listProperties() const override
virtual StatusCode registerDataHistory(const CLID &id, const std::string &key, const std::string &store)
The IAlgManager is the interface implemented by the Algorithm Factory in the Application Manager to s...
AlgorithmHistory * getAlgHistory(const Algorithm &) const override
StatusCode stop() override
virtual void dump(std::ostream &, const bool isXML=false, int indent=0) const =0
Base class for History Objects.
HistorySvc class definition.
DHH(const CLID &i, std::string k)
const PropertyList & properties() const override
virtual std::string toString() const =0
value -> string
JobHistory class definition.
IAlgorithm * getCurrentIAlg() const
void handle(const Incident &inc) override
#define DECLARE_COMPONENT(type)
Main interface for the JobOptions service.
struct GAUDI_API map
Parametrisation class for map-like implementation.
GAUDI_API ISvcLocator * svcLocator()
JobHistory * getJobHistory() const override
General service interface definition.
This class is used for returning status codes from appropriate routines.
const PropertyList & properties() const override
DataHistory class definition.
const PropertyList & properties() const override
virtual std::vector< std::string > getClients() const =0
Get the list of clients.
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
virtual std::ostream & fillStream(std::ostream &) const
the printout of the property value
unsigned int CLID
Class ID definition.
virtual const std::vector< const Gaudi::Details::PropertyBase * > * getProperties(const std::string &client) const =0
Get the properties associated to a given client.
The IAlgorithm is the interface implemented by the Algorithm base class.
constexpr static const auto SUCCESS
StatusCode finalize() override
AlgToolHistory class definition.
void dumpState(std::ofstream &) const
Base class from which all concrete algorithm classes should be derived.
IInterface compliant class extending IInterface with the name() method.
bool operator<(DHH const &rhs) const
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
void dumpProperties(std::ofstream &) 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
std::string documentation() const
property documentation
virtual const std::list< IService * > & getServices() const =0
Get a reference to a service and create it if it does not exists.
ServiceHistory class definition.
Interface for Versioned History Objects.
virtual StatusCode captureState()
ServiceHistory * getServiceHistory(const IService &) const override
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.
DataHistory * getDataHistory(const CLID &id, const std::string &key, const std::string &store) const override