The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
HistorySvc Class Reference

HistorySvc class definition. More...

#include </builds/gaudi/Gaudi/GaudiMonitor/src/HistorySvc.h>

Inheritance diagram for HistorySvc:
Collaboration diagram for HistorySvc:

Public Member Functions

StatusCode initialize () override
 
StatusCode reinitialize () override
 
StatusCode finalize () override
 
StatusCode stop () override
 
virtual StatusCode captureState ()
 
StatusCode registerJob () override
 
StatusCode listProperties () const override
 
JobHistorygetJobHistory () const override
 
StatusCode registerSvc (const IService &) override
 
StatusCode listProperties (const IService &) const override
 
ServiceHistorygetServiceHistory (const IService &) const override
 
void getServiceHistory (std::set< ServiceHistory * > &) const override
 
StatusCode registerAlg (const Gaudi::Algorithm &) override
 
StatusCode listProperties (const Gaudi::Algorithm &) const override
 
AlgorithmHistorygetAlgHistory (const Gaudi::Algorithm &) const override
 
void getAlgHistory (std::set< AlgorithmHistory * > &) const override
 
StatusCode registerAlgTool (const IAlgTool &) override
 
StatusCode listProperties (const IAlgTool &) const override
 
AlgToolHistorygetAlgToolHistory (const IAlgTool &) const override
 
void getAlgToolHistory (std::set< AlgToolHistory * > &) const override
 
DataHistorycreateDataHistoryObj (const CLID &id, const std::string &key, const std::string &store) override
 
virtual StatusCode registerDataHistory (const CLID &id, const std::string &key, const std::string &store)
 
DataHistorygetDataHistory (const CLID &id, const std::string &key, const std::string &store) const override
 
virtual int getDataHistory (const CLID &id, const std::string &key, const std::string &storeName, std::list< DataHistory * > &dhlist) const
 
void handle (const Incident &inc) override
 
- Public Member Functions inherited from extends< Service, IHistorySvc, IIncidentListener >
void const * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast.
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface.
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames.
 
- Public Member Functions inherited from Service
const std::string & name () const override
 Retrieve name of the service.
 
StatusCode configure () override
 
StatusCode initialize () override
 
StatusCode start () override
 
StatusCode stop () override
 
StatusCode finalize () override
 
StatusCode terminate () override
 
Gaudi::StateMachine::State FSMState () const override
 
Gaudi::StateMachine::State targetFSMState () const override
 
StatusCode reinitialize () override
 
StatusCode restart () override
 
StatusCode sysInitialize () override
 Initialize Service.
 
StatusCode sysStart () override
 Initialize Service.
 
StatusCode sysStop () override
 Initialize Service.
 
StatusCode sysFinalize () override
 Finalize Service.
 
StatusCode sysReinitialize () override
 Re-initialize the Service.
 
StatusCode sysRestart () override
 Re-initialize the Service.
 
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor.
 
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator.
 
template<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, bool createIf=true) const
 
template<class T>
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
 
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, bool createIf=true)
 
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, const std::string &toolTypeAndName, bool createIf=true)
 Declare used tool.
 
template<class T>
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandleArray< T > &hndlArr, const std::string &doc="none")
 
template<class T>
void addToolsArray (ToolHandleArray< T > &hndlArr)
 
const std::vector< IAlgTool * > & tools () const
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked.
 
- Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property.
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals.
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string.
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
 PropertyHolder ()=default
 
Gaudi::Details::PropertyBasedeclareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property.
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, TYPE &value, const std::string &doc="none")
 Helper to wrap a regular data member and use it as a regular property.
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, Gaudi::Property< TYPE, VERIFIER, HANDLERS > &prop, const std::string &doc="none")
 Declare a PropertyBase instance setting name and documentation.
 
Gaudi::Details::PropertyBasedeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property.
 
StatusCode setProperty (const std::string &name, const Gaudi::Details::PropertyBase &p) override
 set the property from another property with a different name
 
StatusCode setProperty (const std::string &s) override
 set the property from the formatted string
 
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property.
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals.
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string.
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
StatusCode setPropertyRepr (const std::string &n, const std::string &r) override
 set the property from name and value string representation
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property
 
const Gaudi::Details::PropertyBasegetProperty (std::string_view name) const override
 get the property by name
 
StatusCode getProperty (std::string_view n, std::string &v) const override
 convert the property to the string
 
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties
 
bool hasProperty (std::string_view name) const override
 Return true if we have a property with the given name.
 
Gaudi::Details::PropertyBaseproperty (std::string_view name) const
 \fixme property and bindPropertiesTo should be protected
 
void bindPropertiesTo (Gaudi::Interfaces::IOptionsSvc &optsSvc)
 
 PropertyHolder (const PropertyHolder &)=delete
 
PropertyHolderoperator= (const PropertyHolder &)=delete
 
- Public Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level msgLevel () const
 get the cached level (originally extracted from the embedded MsgStream)
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor.
 
const SmartIF< IMessageSvc > & msgSvc () const
 The standard message service.
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream.
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts.
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS)
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL)
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING)
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO)
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG)
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE)
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO)
 

Private Types

typedef IVersHistoryObj::PropertyList PropertyList
 
typedef std::multimap< DHH, DataHistory * > DataHistMap
 
typedef DataHistMap::iterator DHMitr
 
typedef DataHistMap::const_iterator DHMCitr
 

Private Member Functions

void clearState ()
 
void dumpProperties (std::ofstream &) const
 
void dumpProperties (const IService &, std::ofstream &) const
 
void dumpProperties (const Gaudi::Algorithm &, std::ofstream &) const
 
void dumpProperties (const IAlgTool &, std::ofstream &) const
 
void dumpState (std::ofstream &) const
 
void dumpState (const INamedInterface *, std::ofstream &) const
 
std::string dumpProp (const Gaudi::Details::PropertyBase *, const bool isXML=false, int indent=0) const
 
IAlgorithmgetCurrentIAlg () const
 

Private Attributes

Gaudi::Property< bool > m_dump { this, "Dump", false }
 
Gaudi::Property< bool > m_activate { this, "Activate", true }
 
Gaudi::Property< std::string > m_outputFile { this, "OutputFile" }
 
ServiceHandle< IAlgContextSvcp_algCtxSvc { this, "AlgContextSvc", "AlgContextSvc" }
 
bool m_isInitialized = false
 
std::map< const Gaudi::Algorithm *, AlgorithmHistory * > m_algmap
 
std::set< const IAlgTool * > m_ialgtools
 
std::map< const AlgTool *, AlgToolHistory * > m_algtoolmap
 
std::map< const IService *, ServiceHistory * > m_svcmap
 
std::multimap< DHH, DataHistory * > m_datMap
 
std::unique_ptr< JobHistorym_jobHistory
 
SmartIF< IToolSvcm_toolSvc
 
bool m_outputFileTypeXML = false
 

Additional Inherited Members

- Public Types inherited from extends< Service, IHistorySvc, IIncidentListener >
using base_class
 Typedef to this class.
 
using extend_interfaces_base
 Typedef to the base of this class.
 
- Public Types inherited from Service
using Factory = Gaudi::PluginService::Factory<IService*( const std::string&, ISvcLocator* )>
 
- Public Types inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
using PropertyHolderImpl
 Typedef used to refer to this class from derived classes, as in.
 
- Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class
 
- Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids
 take union of the ext_iids of all Interfaces...
 
- Protected Member Functions inherited from Service
std::vector< IAlgTool * > & tools ()
 
 ~Service () override
 
int outputLevel () const
 get the Service's output level
 
- Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level setUpMessaging () const
 Set up local caches.
 
MSG::Level resetMessaging ()
 Reinitialize internal states.
 
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream.
 
- Protected Attributes inherited from Service
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state.
 
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state.
 
Gaudi::Property< int > m_outputLevel { this, "OutputLevel", MSG::NIL, "output level" }
 flag indicating whether ToolHandle tools have been added to m_tools
 
Gaudi::Property< bool > m_auditorInitialize { this, "AuditInitialize", false, "trigger auditor on initialize()" }
 
Gaudi::Property< bool > m_auditorStart { this, "AuditStart", false, "trigger auditor on start()" }
 
Gaudi::Property< bool > m_auditorStop { this, "AuditStop", false, "trigger auditor on stop()" }
 
Gaudi::Property< bool > m_auditorFinalize { this, "AuditFinalize", false, "trigger auditor on finalize()" }
 
Gaudi::Property< bool > m_auditorReinitialize { this, "AuditReinitialize", false, "trigger auditor on reinitialize()" }
 
Gaudi::Property< bool > m_auditorRestart { this, "AuditRestart", false, "trigger auditor on restart()" }
 
Gaudi::Property< bool > m_autoRetrieveTools
 
Gaudi::Property< bool > m_checkToolDeps
 
SmartIF< IAuditorSvcm_pAuditorSvc
 Auditor Service.
 

Detailed Description

HistorySvc class definition.

Definition at line 46 of file HistorySvc.h.

Member Typedef Documentation

◆ DataHistMap

typedef std::multimap<DHH, DataHistory*> HistorySvc::DataHistMap
private

Definition at line 90 of file HistorySvc.h.

◆ DHMCitr

typedef DataHistMap::const_iterator HistorySvc::DHMCitr
private

Definition at line 92 of file HistorySvc.h.

◆ DHMitr

typedef DataHistMap::iterator HistorySvc::DHMitr
private

Definition at line 91 of file HistorySvc.h.

◆ PropertyList

Definition at line 88 of file HistorySvc.h.

Member Function Documentation

◆ captureState()

StatusCode HistorySvc::captureState ( )
virtual

Get all the Algorithms

Get all the AlgTools

Get all the Services

Definition at line 168 of file HistorySvc.cpp.

168 {
169
170 if ( !m_jobHistory ) {
171 m_jobHistory = std::make_unique<JobHistory>();
172
173 bool foundAppMgr( false );
174 for ( const auto& item : serviceLocator()->getOptsSvc().items() ) {
175 m_jobHistory->addProperty( get<0>( item ), get<1>( item ) );
176 foundAppMgr |= get<0>( item ).compare( 0, 15, "ApplicationMgr." ) == 0;
177 }
178
179 if ( !foundAppMgr ) {
180 auto ap = service<IProperty>( "ApplicationMgr" );
181 if ( !ap ) {
182 error() << "could not get the ApplicationMgr" << endmsg;
183 } else {
184 for ( auto prop : ap->getProperties() ) {
185 m_jobHistory->addProperty( "ApplicationMgr." + prop->name(), prop->toString() );
186 }
187 }
188 }
189 }
190
192
193 auto algMgr = Gaudi::svcLocator()->as<IAlgManager>();
194 if ( !algMgr ) {
195 error() << "Could not get AlgManager" << endmsg;
196 return StatusCode::FAILURE;
197 }
198
199 size_t count = 0;
200 for ( auto ialg : algMgr->getAlgorithms() ) {
201 Gaudi::Algorithm* alg = dynamic_cast<Gaudi::Algorithm*>( ialg );
202 if ( !alg ) {
203 warning() << "Algorithm " << ialg->name() << " does not inherit from Gaudi::Algorithm. Not registering it."
204 << endmsg;
205 } else {
206 ++count;
207 registerAlg( *alg ).ignore();
208 }
209 }
210
211 info() << "Registered " << count << " Algorithms" << endmsg;
212
214
215 m_isInitialized = true;
216 for ( auto algtool : m_ialgtools ) {
217 ( const_cast<IAlgTool*>( algtool ) )->addRef();
218 registerAlgTool( *algtool ).ignore();
219 }
220
221 info() << "Registered " << m_algtoolmap.size() << " AlgTools" << endmsg;
222
224
225 for ( auto svc : Gaudi::svcLocator()->getServices() ) {
226 svc->addRef();
227 registerSvc( *svc ).ignore();
228 }
229
230 info() << "Registered " << Gaudi::svcLocator()->getServices().size() << " Services" << endmsg;
231
232 return StatusCode::SUCCESS;
233}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
StatusCode registerAlgTool(const IAlgTool &) override
bool m_isInitialized
Definition HistorySvc.h:101
std::set< const IAlgTool * > m_ialgtools
Definition HistorySvc.h:105
StatusCode registerSvc(const IService &) override
StatusCode registerAlg(const Gaudi::Algorithm &) override
std::unique_ptr< JobHistory > m_jobHistory
Definition HistorySvc.h:111
std::map< const AlgTool *, AlgToolHistory * > m_algtoolmap
Definition HistorySvc.h:106
virtual const std::list< IService * > & getServices() const =0
Return the list of Services.
SmartIF< IFace > as()
Definition ISvcLocator.h:64
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition Service.cpp:336
SmartIF< IFace > service(const std::string &name, bool createIf=true) const
Definition Service.h:79
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition StatusCode.h:139
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100
GAUDI_API ISvcLocator * svcLocator()

◆ clearState()

void HistorySvc::clearState ( )
private

Definition at line 109 of file HistorySvc.cpp.

109 {
110 clear( m_algmap );
111
112 m_ialgtools.clear();
113 clear( m_algtoolmap );
114
115 clear( m_svcmap );
116}
std::map< const Gaudi::Algorithm *, AlgorithmHistory * > m_algmap
Definition HistorySvc.h:103
std::map< const IService *, ServiceHistory * > m_svcmap
Definition HistorySvc.h:107

◆ createDataHistoryObj()

DataHistory * HistorySvc::createDataHistoryObj ( const CLID & id,
const std::string & key,
const std::string & store )
override

Definition at line 410 of file HistorySvc.cpp.

411 {
412
413 if ( !m_activate ) return nullptr;
414
415 AlgorithmHistory* algHist = nullptr;
416
417 IAlgorithm* ialg = getCurrentIAlg();
418 if ( !ialg ) {
420 debug() << "Could not discover current Algorithm:" << endl
421 << " object CLID: " << id << " key: \"" << key << "\"" << endmsg;
422 algHist = nullptr;
423 } else {
424 Gaudi::Algorithm* alg = dynamic_cast<Gaudi::Algorithm*>( ialg );
425 if ( alg ) {
426 algHist = getAlgHistory( *alg );
427 } else {
428 warning() << "Could not extract concrete Algorithm:" << endl
429 << " object CLID: " << id << " key: \"" << key << "\"" << endmsg;
430 algHist = nullptr;
431 }
432 }
433 return new DataHistory( id, key, algHist );
434}
#define ON_DEBUG
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Gaudi::Property< bool > m_activate
Definition HistorySvc.h:95
IAlgorithm * getCurrentIAlg() const
AlgorithmHistory * getAlgHistory(const Gaudi::Algorithm &) const override

◆ dumpProp()

std::string HistorySvc::dumpProp ( const Gaudi::Details::PropertyBase * prop,
const bool isXML = false,
int indent = 0 ) const
private

Definition at line 659 of file HistorySvc.cpp.

659 {
660 std::ostringstream ost;
661 if ( isXML ) {
662 while ( ind > 0 ) {
663 ost << " ";
664 ind--;
665 }
666 ost << "<PROPERTY name=\"" << prop->name() << "\" value=\"" << HistoryObj::convert_string( prop->toString() )
667 << "\" documentation=\"" << HistoryObj::convert_string( prop->documentation() ) << "\">";
668 } else {
669 prop->fillStream( ost );
670 }
671 return ost.str();
672}
std::string documentation() const
property documentation
virtual std::string toString() const =0
value -> string
virtual std::ostream & fillStream(std::ostream &) const
the printout of the property value
Definition Property.cpp:45
const std::string name() const
property name
static std::string convert_string(const std::string &)

◆ dumpProperties() [1/4]

void HistorySvc::dumpProperties ( const Gaudi::Algorithm & alg,
std::ofstream & ofs ) const
private

Definition at line 317 of file HistorySvc.cpp.

317 {
318
319 AlgorithmHistory* hist = getAlgHistory( alg );
320
321 if ( !hist ) { return; }
322
323 for ( auto prop : hist->properties() ) { ofs << alg.name() << " " << dumpProp( prop ) << std::endl; }
324}
const PropertyList & properties() const override
std::string dumpProp(const Gaudi::Details::PropertyBase *, const bool isXML=false, int indent=0) const

◆ dumpProperties() [2/4]

void HistorySvc::dumpProperties ( const IAlgTool & alg,
std::ofstream & ofs ) const
private

Definition at line 620 of file HistorySvc.cpp.

620 {
621
622 AlgToolHistory* hist = getAlgToolHistory( alg );
623
624 if ( !hist ) return;
625
626 for ( auto& prop : hist->properties() ) { ofs << alg.name() << " " << dumpProp( prop ) << std::endl; }
627}
const PropertyList & properties() const override
AlgToolHistory * getAlgToolHistory(const IAlgTool &) const override

◆ dumpProperties() [3/4]

void HistorySvc::dumpProperties ( const IService & svc,
std::ofstream & ofs ) const
private

Definition at line 555 of file HistorySvc.cpp.

555 {
556
557 ServiceHistory* hist = getServiceHistory( svc );
558
559 if ( !hist ) return;
560
561 for ( auto& prop : hist->properties() ) { ofs << svc.name() << " " << dumpProp( prop ) << std::endl; }
562}
ServiceHistory * getServiceHistory(const IService &) const override
const PropertyList & properties() const override

◆ dumpProperties() [4/4]

void HistorySvc::dumpProperties ( std::ofstream & ofs) const
private

Definition at line 380 of file HistorySvc.cpp.

380 {
381
382 ofs << "GLOBAL" << std::endl;
383 for ( const auto& prop : m_jobHistory->propertyPairs() ) {
384 ofs << prop.first << " " << dumpProp( prop.second.get() ) << std::endl;
385 }
386
387 ofs << std::endl << "SERVICES" << std::endl;
388 for ( const auto& s : m_svcmap ) dumpProperties( *s.first, ofs );
389
390 ofs << std::endl << "ALGORITHMS" << std::endl;
391 for ( const auto& alg : m_algmap ) dumpProperties( *alg.first, ofs );
392
393 ofs << std::endl << "ALGTOOLS" << std::endl;
394 for ( const auto& tool : m_algtoolmap ) dumpProperties( *tool.first, ofs );
395}
void dumpProperties(std::ofstream &) const

◆ dumpState() [1/2]

void HistorySvc::dumpState ( const INamedInterface * in,
std::ofstream & ofs ) const
private

Definition at line 747 of file HistorySvc.cpp.

747 {
748
749 HistoryObj* hist = nullptr;
750 IVersHistoryObj* vhist = nullptr;
751
752 const IService* is = nullptr;
753 const Gaudi::Algorithm* ia = nullptr;
754 const IAlgTool* it = nullptr;
755 if ( ( is = dynamic_cast<const IService*>( in ) ) != nullptr ) {
757 verbose() << in->name() << " is Service" << endmsg;
758 ServiceHistory* o = getServiceHistory( *is );
759 hist = dynamic_cast<HistoryObj*>( o );
760 vhist = dynamic_cast<IVersHistoryObj*>( o );
761 } else if ( ( ia = dynamic_cast<const Gaudi::Algorithm*>( in ) ) != nullptr ) {
763 verbose() << in->name() << " is Alg" << endmsg;
764 AlgorithmHistory* o = getAlgHistory( *ia );
765 hist = dynamic_cast<HistoryObj*>( o );
766 vhist = dynamic_cast<IVersHistoryObj*>( o );
767 } else if ( ( it = dynamic_cast<const IAlgTool*>( in ) ) != nullptr ) {
769 verbose() << in->name() << " is AlgTool" << endmsg;
770 AlgToolHistory* o = getAlgToolHistory( *it );
771 hist = dynamic_cast<HistoryObj*>( o );
772 vhist = dynamic_cast<IVersHistoryObj*>( o );
773 } else {
774 error() << "Could not dcast interface to accepted History Obj type for " << in->name() << endmsg;
775 return;
776 }
777
778 if ( !hist || !vhist ) {
779 error() << "Could not dcast recognized object to HistoryObj or IVersHistoryObj. This should never happen."
780 << endmsg;
781 return;
782 }
783
784 if ( m_outputFileTypeXML ) {
785 hist->dump( ofs, true );
786 } else {
787 ofs << ">> " << vhist->name() << endl << *hist << endl;
788 }
789}
#define ON_VERBOSE
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
virtual std::ostream & dump(std::ostream &, bool isXML=false, int indent=0) const =0
bool m_outputFileTypeXML
Definition HistorySvc.h:127
virtual const std::string & name() const =0
Retrieve the name of the instance.
virtual const std::string & name() const =0

◆ dumpState() [2/2]

void HistorySvc::dumpState ( std::ofstream & ofs) const
private

Definition at line 676 of file HistorySvc.cpp.

676 {
677
678 if ( m_outputFileTypeXML ) {
679 // xml header
680 ofs << "<?xml version=\"1.0\" ?> " << std::endl;
681 ofs << "<!--Test-xml-->" << std::endl;
682 ofs << "<SETUP>" << std::endl;
683 ofs << " <GLOBAL>" << std::endl;
684 } else {
685 ofs << "GLOBAL" << std::endl;
686 }
687
688 std::string client_currently_open = "start";
689 for ( auto& item : m_jobHistory->propertyPairs() ) {
690 // client is the name of the component of the current property
691 const auto& client = item.first;
692 const auto& prp = item.second;
693
694 if ( m_outputFileTypeXML ) {
695
696 if ( client != client_currently_open ) {
697 if ( client_currently_open != "start" ) ofs << " </COMPONENT>" << endl;
698 ofs << " <COMPONENT name=\"" << client << "\" class=\"undefined\">" << std::endl;
699 }
700 } else {
701 ofs << client << " ";
702 }
703
704 ofs << dumpProp( prp.get(), m_outputFileTypeXML, 6 ) << endl;
705
706 client_currently_open = client;
707
708 if ( m_outputFileTypeXML ) ofs << " </COMPONENT>" << endl;
709 }
710
711 if ( m_outputFileTypeXML ) {
712 ofs << "</GLOBAL>" << endl << "<SERVICES>" << endl;
713 } else {
714 ofs << "SERVICES" << std::endl;
715 }
716
717 // helper to dump monitored components sorted by name
718 auto sortedDump = [&ofs, this]( const auto& map ) {
719 std::map<std::string, const INamedInterface*> sorted;
720 for ( const auto& item : map ) sorted[item.first->name()] = item.first;
721 for ( const auto& item : sorted ) dumpState( item.second, ofs );
722 };
723
724 sortedDump( m_svcmap );
725
726 if ( m_outputFileTypeXML ) {
727 ofs << "</SERVICES>" << endl << "<ALGORITHMS> " << endl;
728 } else {
729 ofs << "ALGORITHMS" << std::endl;
730 }
731
732 sortedDump( m_algmap );
733
734 if ( m_outputFileTypeXML ) {
735 ofs << "</ALGORITHMS>" << endl << "<ALGTOOLS> " << endl;
736 } else {
737 ofs << "ALGTOOLS" << std::endl;
738 }
739
740 sortedDump( m_algtoolmap );
741
742 if ( m_outputFileTypeXML ) { ofs << "</ALGTOOLS>" << endl << "</SETUP>" << endl; }
743}
void dumpState(std::ofstream &) const
struct GAUDI_API map
Parametrisation class for map-like implementation.

◆ finalize()

StatusCode HistorySvc::finalize ( )
override

Definition at line 260 of file HistorySvc.cpp.

260 {
261
263 verbose() << "HistorySvc::finalize()" << endmsg;
264
265 clearState();
266
267 StatusCode status = Service::finalize();
268
269 if ( status.isSuccess() ) info() << "Service finalised successfully" << endmsg;
270
271 return status;
272}
void clearState()
StatusCode finalize() override
Definition Service.cpp:223
bool isSuccess() const
Definition StatusCode.h:314

◆ getAlgHistory() [1/2]

AlgorithmHistory * HistorySvc::getAlgHistory ( const Gaudi::Algorithm & alg) const
override

Definition at line 327 of file HistorySvc.cpp.

327 {
328
329 auto itr = m_algmap.find( &alg );
330 if ( itr == m_algmap.end() ) {
331 warning() << "Algorithm " << alg.name() << " not registered" << endmsg;
332 return nullptr;
333 }
334 return itr->second;
335}

◆ getAlgHistory() [2/2]

void HistorySvc::getAlgHistory ( std::set< AlgorithmHistory * > & algs) const
override

Definition at line 338 of file HistorySvc.cpp.

338{ map_to_set( m_algmap, algs ); }

◆ getAlgToolHistory() [1/2]

AlgToolHistory * HistorySvc::getAlgToolHistory ( const IAlgTool & alg) const
override

Definition at line 631 of file HistorySvc.cpp.

631 {
632
633 const AlgTool* palg = dynamic_cast<const AlgTool*>( &alg );
634 auto itr = m_algtoolmap.find( palg );
635 if ( itr == m_algtoolmap.end() ) {
636 warning() << "AlgTool " << alg.name() << " not registered" << endmsg;
637 return nullptr;
638 }
639 return itr->second;
640}

◆ getAlgToolHistory() [2/2]

void HistorySvc::getAlgToolHistory ( std::set< AlgToolHistory * > & algs) const
override

Definition at line 644 of file HistorySvc.cpp.

644{ map_to_set( m_algtoolmap, algs ); }

◆ getCurrentIAlg()

IAlgorithm * HistorySvc::getCurrentIAlg ( ) const
private

Definition at line 401 of file HistorySvc.cpp.

401 {
402 if ( p_algCtxSvc.isSet() ) return p_algCtxSvc->currentAlg();
403 warning() << "trying to create DataHistoryObj before "
404 << "HistorySvc has been initialized" << endmsg;
405 return nullptr;
406}
ServiceHandle< IAlgContextSvc > p_algCtxSvc
Definition HistorySvc.h:97

◆ getDataHistory() [1/2]

DataHistory * HistorySvc::getDataHistory ( const CLID & id,
const std::string & key,
const std::string & store ) const
override

Definition at line 470 of file HistorySvc.cpp.

471 {
472
473 DHH dhh( id, key );
474
475 auto mitr = m_datMap.equal_range( dhh );
476 return ( mitr.first != mitr.second ) ? mitr.first->second : nullptr;
477}
std::multimap< DHH, DataHistory * > m_datMap
Definition HistorySvc.h:109

◆ getDataHistory() [2/2]

int HistorySvc::getDataHistory ( const CLID & id,
const std::string & key,
const std::string & storeName,
std::list< DataHistory * > & dhlist ) const
virtual

Definition at line 481 of file HistorySvc.cpp.

482 {
483
484 DHH dhh( id, key );
485
486 int n( 0 );
487
488 auto mitr = m_datMap.equal_range( dhh );
489 for ( auto itr = mitr.first; itr != mitr.second; ++itr ) {
490 dhlist.push_back( itr->second );
491 ++n;
492 }
493 return n;
494}

◆ getJobHistory()

JobHistory * HistorySvc::getJobHistory ( ) const
override

Definition at line 398 of file HistorySvc.cpp.

398{ return m_jobHistory.get(); }

◆ getServiceHistory() [1/2]

ServiceHistory * HistorySvc::getServiceHistory ( const IService & svc) const
override

Definition at line 525 of file HistorySvc.cpp.

525 {
526
527 const IService* psvc = &svc;
528 auto itr = m_svcmap.find( psvc );
529 if ( itr != m_svcmap.end() ) return itr->second;
530
531 warning() << "Service " << svc.name() << " not registered" << endmsg;
532 return nullptr;
533}

◆ getServiceHistory() [2/2]

void HistorySvc::getServiceHistory ( std::set< ServiceHistory * > & svcs) const
override

Definition at line 536 of file HistorySvc.cpp.

536{ map_to_set( m_svcmap, svcs ); }

◆ handle()

void HistorySvc::handle ( const Incident & inc)
override

Definition at line 648 of file HistorySvc.cpp.

648 {
649
650 if ( incident.type() == IncidentType::BeginEvent ) {
651 if ( captureState().isFailure() ) {
652 warning() << "Error capturing state." << endl << "Will try again at next BeginEvent incident" << endmsg;
653 }
654 }
655}
virtual StatusCode captureState()

◆ initialize()

StatusCode HistorySvc::initialize ( )
override

Definition at line 120 of file HistorySvc.cpp.

120 {
121
122 StatusCode status = Service::initialize();
123 if ( status.isFailure() ) {
125 debug() << "Failed to initialize the base class (Service)" << endmsg;
126 return status;
127 }
128
130 debug() << "Initializing HistorySvc" << endmsg;
131
132 if ( !m_activate ) return StatusCode::SUCCESS;
133
134 if ( p_algCtxSvc.retrieve().isFailure() ) {
135 error() << "unable to get the AlgContextSvc" << endmsg;
136 return StatusCode::FAILURE;
137 }
138
139 auto incidentSvc = service<IIncidentSvc>( "IncidentSvc", true );
140 if ( !incidentSvc ) {
141 error() << "unable to get the IncidentSvc" << endmsg;
142 return StatusCode::FAILURE;
143 }
144
145 // create a weak dependency on the ToolSvc, so that it doesn't get deleted
146 // before we're done with it in finalize
147 m_toolSvc = serviceLocator()->service( "ToolSvc" );
148 if ( !m_toolSvc ) {
149 error() << "could not retrieve the ToolSvc handle !" << endmsg;
150 return StatusCode::FAILURE;
151 }
152
153 // add listener to be triggered by first BeginEvent with low priority
154 // so it gets called first
155 const bool rethrow = false;
156 const bool oneShot = true; // make the listener called only once
157 incidentSvc->addListener( this, IncidentType::BeginEvent, std::numeric_limits<long>::min(), rethrow, oneShot );
158
159 m_outputFileTypeXML = ba::iends_with( m_outputFile.value(), ".xml" );
160 ON_DEBUG if ( m_outputFileTypeXML ) { debug() << "output format is XML" << endmsg; }
161
162 m_isInitialized = true;
163
164 return StatusCode::SUCCESS;
165}
Gaudi::Property< std::string > m_outputFile
Definition HistorySvc.h:96
SmartIF< IToolSvc > m_toolSvc
Definition HistorySvc.h:125
virtual SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)=0
Returns a smart pointer to a service.
StatusCode initialize() override
Definition Service.cpp:118
bool isFailure() const
Definition StatusCode.h:129

◆ listProperties() [1/4]

StatusCode HistorySvc::listProperties ( ) const
override

Definition at line 344 of file HistorySvc.cpp.

344 {
345
346 auto& log = info();
347
348 log.setColor( MSG::CYAN );
349 log << "Dumping properties for all Algorithms (" << m_algmap.size() << ")" << endmsg;
350
351 for ( auto& alg : m_algmap ) { listProperties( *alg.first ).ignore(); }
352
353 log << MSG::INFO;
354 log.setColor( MSG::CYAN );
355 log << "Dumping properties for all AlgTools (" << m_algtoolmap.size() << ")" << endmsg;
356
357 for ( auto& algtool : m_algtoolmap ) {
359 debug() << " --> " << algtool.second->algtool_name() << endmsg;
360 listProperties( *algtool.first ).ignore();
361 }
362
363 log << MSG::INFO;
364 log.setColor( MSG::CYAN );
365 log << "Dumping properties for all Services (" << m_svcmap.size() << ")" << endmsg;
366
367 for ( auto& svc : m_svcmap ) { listProperties( *svc.first ).ignore(); }
368
369 log << MSG::INFO;
370 log.setColor( MSG::CYAN );
371 log << "Dumping properties for Job";
372 log.resetColor();
373
374 log << std::endl << *m_jobHistory << endmsg;
375
376 return StatusCode::SUCCESS;
377}
StatusCode listProperties() const override
@ CYAN
Definition IMessageSvc.h:23
@ INFO
Definition IMessageSvc.h:22

◆ listProperties() [2/4]

StatusCode HistorySvc::listProperties ( const Gaudi::Algorithm & alg) const
override

Definition at line 303 of file HistorySvc.cpp.

303 {
304
305 info() << "Dumping properties for " << alg.name() << endl;
306
307 AlgorithmHistory* hist = getAlgHistory( alg );
308
309 if ( !hist ) { return StatusCode::FAILURE; }
310
311 info() << alg.name() << " --> " << endl << *hist << endmsg;
312
313 return StatusCode::SUCCESS;
314}

◆ listProperties() [3/4]

StatusCode HistorySvc::listProperties ( const IAlgTool & alg) const
override

Definition at line 606 of file HistorySvc.cpp.

606 {
607
608 info() << "Dumping properties for " << alg.name() << endl;
609
610 AlgToolHistory* hist = getAlgToolHistory( alg );
611
612 if ( !hist ) return StatusCode::FAILURE;
613
614 info() << alg.name() << " --> " << endl << *hist << endmsg;
615
616 return StatusCode::SUCCESS;
617}

◆ listProperties() [4/4]

StatusCode HistorySvc::listProperties ( const IService & svc) const
override

Definition at line 540 of file HistorySvc.cpp.

540 {
541
542 info() << "Dumping properties for " << svc.name() << endl;
543
544 ServiceHistory* hist = getServiceHistory( svc );
545
546 if ( !hist ) return StatusCode::FAILURE;
547
548 info() << svc.name() << " --> " << endl << *hist << endmsg;
549
550 return StatusCode::SUCCESS;
551}

◆ registerAlg()

StatusCode HistorySvc::registerAlg ( const Gaudi::Algorithm & alg)
override

Definition at line 279 of file HistorySvc.cpp.

279 {
280
281 JobHistory* job = getJobHistory();
282 if ( m_algmap.find( &alg ) != m_algmap.end() ) {
283 warning() << "Algorithm " << alg.name() << " already registered with HistorySvc" << endmsg;
284 return StatusCode::SUCCESS;
285 }
286
287 ( const_cast<Gaudi::Algorithm*>( &alg ) )->addRef();
288
289 m_algmap[&alg] = new AlgorithmHistory( alg, job );
290
291 ON_DEBUG {
292 auto& log = debug();
293 log << "Registering algorithm: ";
294 log.setColor( MSG::CYAN );
295 log << alg.name() << endmsg;
296 log.resetColor();
297 }
298
299 return StatusCode::SUCCESS;
300}
JobHistory * getJobHistory() const override

◆ registerAlgTool()

StatusCode HistorySvc::registerAlgTool ( const IAlgTool & ialg)
override

Definition at line 566 of file HistorySvc.cpp.

566 {
567
568 if ( !m_isInitialized ) {
569 if ( !p_algCtxSvc.isSet() ) {
570 if ( p_algCtxSvc.retrieve().isFailure() ) {
571 error() << "unable to get the AlgContextSvc" << endmsg;
572 return StatusCode::FAILURE;
573 }
574 }
575 m_ialgtools.insert( &ialg );
576 return StatusCode::SUCCESS;
577 }
578
579 const AlgTool* alg = dynamic_cast<const AlgTool*>( &ialg );
580 if ( !alg ) {
581 error() << "Could not dcast IAlgTool \"" << ialg.name() << "\" to an AlgTool" << endmsg;
582 return StatusCode::FAILURE;
583 }
584
585 if ( m_algtoolmap.find( alg ) != m_algtoolmap.end() ) {
586 warning() << "AlgTool " << ialg.name() << " already registered in HistorySvc" << endmsg;
587 return StatusCode::SUCCESS;
588 }
589
590 const JobHistory* job = getJobHistory();
591 m_algtoolmap[alg] = new AlgToolHistory( *alg, job );
592
593 ON_DEBUG {
594 auto& log = debug();
595 log << "Registering algtool: ";
596 log.setColor( MSG::CYAN );
597 log << alg->name() << endmsg;
598 log.resetColor();
599 }
600
601 return StatusCode::SUCCESS;
602}

◆ registerDataHistory()

StatusCode HistorySvc::registerDataHistory ( const CLID & id,
const std::string & key,
const std::string & store )
virtual

Definition at line 437 of file HistorySvc.cpp.

437 {
438
439 DHH dhh( id, key );
440
441 auto boundaries = m_datMap.equal_range( dhh );
442 auto match = boundaries.second;
443
444 if ( boundaries.first != boundaries.second ) {
445 // there is something in the map, let's look for the specific entry
446
447 std::string algName;
448 IAlgorithm* ialg = getCurrentIAlg();
449 if ( ialg ) {
450 algName = ialg->name();
451 } else {
452 algName = "UNKNOWN";
453 }
454
455 match = std::find_if( boundaries.first, boundaries.second,
456 [&algName]( decltype( boundaries )::first_type::reference p ) -> bool {
457 return p.second->algorithmHistory()->algorithm_name() == algName;
458 } );
459 }
460
461 if ( match == boundaries.second ) { // not found, crete the entry
462 DataHistory* dh = createDataHistoryObj( id, key, storeName );
463 m_datMap.insert( pair<DHH, DataHistory*>( dhh, dh ) );
464 }
465
466 return StatusCode::SUCCESS;
467}
DataHistory * createDataHistoryObj(const CLID &id, const std::string &key, const std::string &store) override

◆ registerJob()

StatusCode HistorySvc::registerJob ( )
override

Definition at line 341 of file HistorySvc.cpp.

341{ return StatusCode::SUCCESS; }

◆ registerSvc()

StatusCode HistorySvc::registerSvc ( const IService & svc)
override

Definition at line 498 of file HistorySvc.cpp.

498 {
499
500 if ( svc.name() == "HistoryStore" ) { return StatusCode::SUCCESS; }
501
502 JobHistory* job = getJobHistory();
503 const IService* psvc = &svc;
504 auto itr = m_svcmap.find( psvc );
505 if ( itr == m_svcmap.end() ) {
506
507 ON_DEBUG {
508 auto& log = debug();
509 log << "Registering Service: ";
510 log.setColor( MSG::CYAN );
511 log << svc.name() << endmsg;
512 log.resetColor();
513 }
514
515 m_svcmap[psvc] = new ServiceHistory( &svc, job );
516
517 ( const_cast<IService*>( psvc ) )->addRef();
518 }
519
520 return StatusCode::SUCCESS;
521}

◆ reinitialize()

StatusCode HistorySvc::reinitialize ( )
override

Definition at line 86 of file HistorySvc.cpp.

86 {
87
88 clearState();
90 return initialize();
91}
StatusCode initialize() override
Gaudi::StateMachine::State m_state
Service state.
Definition Service.h:155

◆ stop()

StatusCode HistorySvc::stop ( )
override

Definition at line 237 of file HistorySvc.cpp.

237 {
238
239 if ( !m_activate ) return StatusCode::SUCCESS;
240
241 if ( m_dump ) { listProperties().ignore(); }
242
243 if ( !m_outputFile.empty() ) {
244 std::ofstream ofs( m_outputFile );
245 if ( !ofs ) {
246 error() << "Unable to open output file \"m_outputFile\"" << endmsg;
247 } else {
248 // dumpProperties(ofs);
249 dumpState( ofs );
250 }
251 }
252
253 clearState();
254
255 return StatusCode::SUCCESS;
256}
Gaudi::Property< bool > m_dump
Definition HistorySvc.h:94

Member Data Documentation

◆ m_activate

Gaudi::Property<bool> HistorySvc::m_activate { this, "Activate", true }
private

Definition at line 95 of file HistorySvc.h.

95{ this, "Activate", true };

◆ m_algmap

std::map<const Gaudi::Algorithm*, AlgorithmHistory*> HistorySvc::m_algmap
private

Definition at line 103 of file HistorySvc.h.

◆ m_algtoolmap

std::map<const AlgTool*, AlgToolHistory*> HistorySvc::m_algtoolmap
private

Definition at line 106 of file HistorySvc.h.

◆ m_datMap

std::multimap<DHH, DataHistory*> HistorySvc::m_datMap
private

Definition at line 109 of file HistorySvc.h.

◆ m_dump

Gaudi::Property<bool> HistorySvc::m_dump { this, "Dump", false }
private

Definition at line 94 of file HistorySvc.h.

94{ this, "Dump", false };

◆ m_ialgtools

std::set<const IAlgTool*> HistorySvc::m_ialgtools
private

Definition at line 105 of file HistorySvc.h.

◆ m_isInitialized

bool HistorySvc::m_isInitialized = false
private

Definition at line 101 of file HistorySvc.h.

◆ m_jobHistory

std::unique_ptr<JobHistory> HistorySvc::m_jobHistory
private

Definition at line 111 of file HistorySvc.h.

◆ m_outputFile

Gaudi::Property<std::string> HistorySvc::m_outputFile { this, "OutputFile" }
private

Definition at line 96 of file HistorySvc.h.

96{ this, "OutputFile" };

◆ m_outputFileTypeXML

bool HistorySvc::m_outputFileTypeXML = false
private

Definition at line 127 of file HistorySvc.h.

◆ m_svcmap

std::map<const IService*, ServiceHistory*> HistorySvc::m_svcmap
private

Definition at line 107 of file HistorySvc.h.

◆ m_toolSvc

SmartIF<IToolSvc> HistorySvc::m_toolSvc
private

Definition at line 125 of file HistorySvc.h.

◆ p_algCtxSvc

ServiceHandle<IAlgContextSvc> HistorySvc::p_algCtxSvc { this, "AlgContextSvc", "AlgContextSvc" }
private

Definition at line 97 of file HistorySvc.h.

97{ this, "AlgContextSvc", "AlgContextSvc" };

The documentation for this class was generated from the following files: