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;
290 log <<
"Registering algorithm: ";
302 info() <<
"Dumping properties for " << alg.
name() <<
endl;
318 if ( !hist ) {
return; }
320 PropertyList::const_iterator itr;
327 auto itr = m_algmap.find( &alg );
328 if ( itr == m_algmap.end() ) {
329 warning() <<
"Algorithm " << alg.
name() <<
" not registered" <<
endmsg;
347 log <<
"Dumping properties for all Algorithms (" << m_algmap.size() <<
")" <<
endmsg;
349 for (
auto& alg : m_algmap ) { listProperties( *alg.first ).ignore(); }
353 log <<
"Dumping properties for all AlgTools (" << m_algtoolmap.size() <<
")" <<
endmsg;
355 for (
auto& algtool : m_algtoolmap ) {
357 debug() <<
" --> " << algtool.second->algtool_name() <<
endmsg;
358 listProperties( *algtool.first ).ignore();
363 log <<
"Dumping properties for all Services (" << m_svcmap.size() <<
")" <<
endmsg;
365 for (
auto& svc : m_svcmap ) { listProperties( *svc.first ).ignore(); }
369 log <<
"Dumping properties for Job";
381 for (
const auto& prop : m_jobHistory->propertyPairs() ) {
382 ofs << prop.first <<
" " << dumpProp( prop.second ) <<
std::endl;
385 ofs << std::endl <<
"SERVICES" <<
std::endl;
386 for (
const auto&
s : m_svcmap ) dumpProperties( *
s.first, ofs );
388 ofs << std::endl <<
"ALGORITHMS" <<
std::endl;
389 for (
const auto& alg : m_algmap ) dumpProperties( *alg.first, ofs );
391 ofs << std::endl <<
"ALGTOOLS" <<
std::endl;
392 for (
const auto& tool : m_algtoolmap ) dumpProperties( *tool.first, ofs );
400 if ( p_algCtxSvc )
return p_algCtxSvc->currentAlg();
401 warning() <<
"trying to create DataHistoryObj before " 402 <<
"HistorySvc has been initialized" <<
endmsg;
411 if ( !m_activate )
return nullptr;
418 debug() <<
"Could not discover current Algorithm:" <<
endl 419 <<
" object CLID: " <<
id <<
" key: \"" << key <<
"\"" <<
endmsg;
424 algHist = getAlgHistory( *alg );
426 warning() <<
"Could not extract concrete Algorithm:" <<
endl 427 <<
" object CLID: " <<
id <<
" key: \"" << key <<
"\"" <<
endmsg;
439 auto boundaries = m_datMap.equal_range( dhh );
440 auto match = boundaries.second;
442 if ( boundaries.first != boundaries.second ) {
448 algName = ialg->name();
453 match =
std::find_if( boundaries.first, boundaries.second,
454 [&algName]( decltype( boundaries )::first_type::reference p ) ->
bool {
455 return p.second->algorithmHistory()->algorithm_name() == algName;
459 if ( match == boundaries.second ) {
460 DataHistory* dh = createDataHistoryObj(
id, key, storeName );
473 auto mitr = m_datMap.equal_range( dhh );
474 return ( mitr.first != mitr.second ) ? mitr.first->second :
nullptr;
486 auto mitr = m_datMap.equal_range( dhh );
487 for (
auto itr = mitr.first; itr != mitr.second; ++itr ) {
502 auto itr = m_svcmap.find( psvc );
503 if ( itr == m_svcmap.end() ) {
507 log <<
"Registering Service: ";
515 (
const_cast<IService*
>( psvc ) )->addRef();
526 auto itr = m_svcmap.find( psvc );
527 if ( itr != m_svcmap.end() )
return itr->second;
529 warning() <<
"Service " << svc.name() <<
" not registered" <<
endmsg;
540 info() <<
"Dumping properties for " << svc.name() <<
endl;
546 info() << svc.name() <<
" --> " <<
endl << *hist <<
endmsg;
559 for (
auto& prop : hist->
properties() ) { ofs << svc.name() <<
" " << dumpProp( prop ) <<
std::endl; }
566 if ( !m_isInitialized ) {
567 if ( !p_algCtxSvc ) {
568 if ( service(
"AlgContextSvc", p_algCtxSvc,
true ).isFailure() ) {
569 error() <<
"unable to get the AlgContextSvc" <<
endmsg;
573 m_ialgtools.insert( &ialg );
579 error() <<
"Could not dcast IAlgTool \"" << ialg.
name() <<
"\" to an AlgTool" <<
endmsg;
583 if ( m_algtoolmap.find( alg ) != m_algtoolmap.end() ) {
584 warning() <<
"AlgTool " << ialg.
name() <<
" already registered in HistorySvc" <<
endmsg;
593 log <<
"Registering algtool: ";
606 info() <<
"Dumping properties for " << alg.
name() <<
endl;
632 auto itr = m_algtoolmap.find( palg );
633 if ( itr == m_algtoolmap.end() ) {
634 warning() <<
"AlgTool " << alg.
name() <<
" not registered" <<
endmsg;
648 if ( incident.
type() == IncidentType::BeginEvent ) {
649 if ( captureState().isFailure() ) {
650 warning() <<
"Error capturing state." <<
endl <<
"Will try again at next BeginEvent incident" <<
endmsg;
676 if ( m_outputFileTypeXML ) {
678 ofs <<
"<?xml version=\"1.0\" ?> " <<
std::endl;
687 for (
auto& item : m_jobHistory->propertyPairs() ) {
692 if ( m_outputFileTypeXML ) {
694 if ( client != client_currently_open ) {
695 if ( client_currently_open !=
"start" ) ofs <<
" </COMPONENT>" <<
endl;
696 ofs <<
" <COMPONENT name=\"" << client <<
"\" class=\"undefined\">" <<
std::endl;
699 ofs << client <<
" ";
702 ofs << dumpProp( prp, m_outputFileTypeXML, 6 ) <<
endl;
704 client_currently_open = client;
706 if ( m_outputFileTypeXML ) ofs <<
" </COMPONENT>" << endl;
709 if ( m_outputFileTypeXML ) {
710 ofs <<
"</GLOBAL>" <<
endl <<
"<SERVICES>" <<
endl;
716 auto sortedDump = [&ofs,
this](
const auto&
map ) {
718 for (
const auto& item :
map ) sorted[item.first->name()] = item.first;
719 for (
const auto& item : sorted ) dumpState( item.second, ofs );
722 sortedDump( m_svcmap );
724 if ( m_outputFileTypeXML ) {
725 ofs <<
"</SERVICES>" <<
endl <<
"<ALGORITHMS> " <<
endl;
730 sortedDump( m_algmap );
732 if ( m_outputFileTypeXML ) {
733 ofs <<
"</ALGORITHMS>" <<
endl <<
"<ALGTOOLS> " <<
endl;
738 sortedDump( m_algtoolmap );
740 if ( m_outputFileTypeXML ) { ofs <<
"</ALGTOOLS>" <<
endl <<
"</SETUP>" <<
endl; }
753 if ( ( is = dynamic_cast<const IService*>( in ) ) !=
nullptr ) {
759 }
else if ( ( ia = dynamic_cast<const Gaudi::Algorithm*>( in ) ) !=
nullptr ) {
765 }
else if ( ( it = dynamic_cast<const IAlgTool*>( in ) ) !=
nullptr ) {
772 error() <<
"Could not dcast interface to accepted History Obj type for " << in->
name() <<
endmsg;
776 if ( !hist || !vhist ) {
777 error() <<
"Could not dcast recognized object to HistoryObj or IVersHistoryObj. This should never happen." 782 if ( m_outputFileTypeXML ) {
783 hist->
dump( ofs,
true );
StatusCode reinitialize() override
virtual const std::string & name() const =0
AlgToolHistory * getAlgToolHistory(const IAlgTool &) const override
StatusCode initialize() override
const std::string & type() const
Access to the incident type.
StatusCode finalize() override
StatusCode registerSvc(const IService &) override
StatusCode registerAlgTool(const IAlgTool &) override
const std::string & name() const override
The identifying name of the algorithm object.
std::string dumpProp(const Gaudi::Details::PropertyBase *, const bool isXML=false, int indent=0) const
const std::string name() const
property name
AlgorithmHistory class definition.
StatusCode initialize() override
AlgorithmHistory * getAlgHistory(const Gaudi::Algorithm &) const 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...
constexpr static const auto SUCCESS
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.
StatusCode finalize() override
AlgToolHistory class definition.
void dumpState(std::ofstream &) const
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
Base class from which all concrete algorithm classes should be derived.
virtual const std::list< IService * > & getServices() const =0
Get a reference to a service and create it if it does not exists.
constexpr static const auto FAILURE
ServiceHistory class definition.
Interface for Versioned History Objects.
StatusCode registerAlg(const Gaudi::Algorithm &) override
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