5 #include "GaudiKernel/HistoryObj.h"
6 #include "GaudiKernel/IVersHistoryObj.h"
8 #include "GaudiKernel/JobHistory.h"
9 #include "GaudiKernel/AlgorithmHistory.h"
10 #include "GaudiKernel/AlgToolHistory.h"
11 #include "GaudiKernel/DataHistory.h"
12 #include "GaudiKernel/ServiceHistory.h"
14 #include "GaudiKernel/ISvcLocator.h"
16 #include "GaudiKernel/System.h"
17 #include "GaudiKernel/Bootstrap.h"
18 #include "GaudiKernel/IAlgManager.h"
19 #include "GaudiKernel/IAlgorithm.h"
20 #include "GaudiKernel/Algorithm.h"
21 #include "GaudiKernel/IAlgTool.h"
22 #include "GaudiKernel/AlgTool.h"
23 #include "GaudiKernel/IService.h"
24 #include "GaudiKernel/IJobOptionsSvc.h"
25 #include "GaudiKernel/IAppMgrUI.h"
26 #include "GaudiKernel/IIncidentSvc.h"
27 #include "GaudiKernel/IToolSvc.h"
28 #include "GaudiKernel/ServiceHandle.h"
30 #include "GaudiKernel/IAlgContextSvc.h"
32 #include "boost/algorithm/string/predicate.hpp"
33 namespace ba = boost::algorithm;
40 #define ON_DEBUG if (UNLIKELY(outputLevel() <= MSG::DEBUG))
41 #define ON_VERBOSE if (UNLIKELY(outputLevel() <= MSG::VERBOSE))
53 template <
typename MAP,
typename SET>
54 inline void map_to_set(
const MAP&
m,
SET&
s) {
56 std::inserter(s, s.begin()),
71 return (key < rhs.
key);
80 declareProperty(
"Dump",
m_dump);
102 constexpr
struct clear_t {
103 template <
typename T1,
typename T2>
104 void operator()(std::pair<const T1* const, T2*>& p) {
105 const_cast<T1*
>(p.first)->release();
145 static const bool CREATEIF(
true);
147 if ( service(
"AlgContextSvc",
p_algCtxSvc,CREATEIF).isFailure() ) {
152 if (service(
"IncidentSvc",
m_incidentSvc, CREATEIF).isFailure()) {
159 m_toolSvc = serviceLocator()->service(
"ToolSvc");
168 const bool rethrow =
false;
169 const bool oneShot =
true;
171 std::numeric_limits<long>::min(),rethrow,oneShot);
189 if (service(
"JobOptionsSvc",jo).isFailure()) {
191 <<
"Could not get jobOptionsSvc - "
192 <<
"not adding properties to JobHistory" <<
endmsg;
195 bool foundAppMgr(
false);
198 if (client ==
"ApplicationMgr") foundAppMgr =
true;
205 auto ap = service<IProperty>(
"ApplicationMgr");
209 for (
auto prop: ap->getProperties()) {
227 for (
auto ialg: algMgr->getAlgorithms()) {
231 <<
" does not inherit from Algorithm. Not registering it."
247 (
const_cast<IAlgTool*
>(algtool))->addRef();
325 <<
" already registered with HistorySvc" <<
endmsg;
329 (
const_cast<Algorithm*
>(&alg))->addRef();
372 PropertyList::const_iterator itr;
374 ofs << alg.
name() <<
" " <<
dumpProp(prop) << std::endl;
416 m_log <<
"Dumping properties for all Algorithms (" <<
m_algmap.size()
436 m_log <<
"Dumping properties for all Services (" <<
m_svcmap.size()
445 m_log <<
"Dumping properties for Job";
458 ofs <<
"GLOBAL" << std::endl;
459 for (
const auto & prop :
m_jobHistory->propertyPairs() ) {
460 ofs << prop.first <<
" " <<
dumpProp(prop.second) << std::endl;
463 ofs << std::endl <<
"SERVICES" << std::endl;
466 ofs << std::endl <<
"ALGORITHMS" << std::endl;
469 ofs << std::endl <<
"ALGTOOLS" << std::endl;
487 <<
"HistorySvc has been initialized" <<
endmsg;
496 const std::string& ) {
507 <<
"Could not discover current Algorithm:" << endl
508 <<
" object CLID: " <<
id <<
" key: \"" << key
517 <<
"Could not extract concrete Algorithm:"
519 <<
" object CLID: " <<
id <<
" key: \"" << key
530 const std::string& storeName) {
534 auto boundaries =
m_datMap.equal_range(dhh);
535 auto match = boundaries.second;
537 if (boundaries.first != boundaries.second) {
543 algName = ialg->name();
548 match = std::find_if(boundaries.first, boundaries.second,
550 return p.second->algorithmHistory()->algorithm_name() == algName;
554 if (match == boundaries.second) {
556 m_datMap.insert(pair<DHH, DataHistory*>(dhh,dh));
567 const std::string& )
const {
571 auto mitr =
m_datMap.equal_range(dhh);
572 return (mitr.first != mitr.second) ? mitr.first->second
582 std::list<DataHistory*>& dhlist)
const {
588 auto mitr =
m_datMap.equal_range(dhh);
589 for (
auto itr=mitr.first; itr != mitr.second; ++itr) {
590 dhlist.push_back(itr->second);
602 if ( svc.name() ==
"HistoryStore" ) {
620 (
const_cast<IService*
>(psvc))->addRef();
636 if ( itr !=
m_svcmap.end() )
return itr->second;
654 m_log <<
MSG::INFO <<
"Dumping properties for " << svc.name() << endl;
676 ofs << svc.name() <<
" " <<
dumpProp(prop) << std::endl;
688 if ( service(
"AlgContextSvc",
p_algCtxSvc,
true).isFailure() ) {
700 <<
"\" to an AlgTool" <<
endmsg;
706 <<
" already registered in HistorySvc" <<
endmsg;
729 m_log <<
MSG::INFO <<
"Dumping properties for " << alg.name() << endl;
751 ofs << alg.name() <<
" " <<
dumpProp(prop) << std::endl;
784 if (incident.
type() == IncidentType::BeginEvent) {
787 <<
"Will try again at next BeginEvent incident" <<
endmsg;
798 std::ostringstream ost;
804 ost <<
"<PROPERTY name=\"" << prop->
name()
822 ofs <<
"<?xml version=\"1.0\" ?> " << std::endl;
823 ofs <<
"<!--Test-xml-->" << std::endl;
824 ofs <<
"<SETUP>" << std::endl;
825 ofs <<
" <GLOBAL>" << std::endl;
827 ofs <<
"GLOBAL" << std::endl;
830 std::string client_currently_open =
"start";
833 const std::string& client =
item.first;
838 if (client != client_currently_open) {
839 if(client_currently_open!=
"start") ofs <<
" </COMPONENT>" << endl;
840 ofs <<
" <COMPONENT name=\""
841 << client <<
"\" class=\"undefined\">" << std::endl;
844 ofs << client <<
" ";
849 client_currently_open = client;
852 ofs <<
" </COMPONENT>" << endl;
857 ofs <<
"</GLOBAL>" << endl <<
"<SERVICES>" << endl;
859 ofs <<
"SERVICES" << std::endl;
868 ofs <<
"</SERVICES>" << endl <<
"<ALGORITHMS> " << endl;
870 ofs <<
"ALGORITHMS" << std::endl;
880 ofs <<
"</ALGORITHMS>" << endl <<
"<ALGTOOLS> " << endl;
882 ofs <<
"ALGTOOLS" << std::endl;
891 ofs <<
"</ALGTOOLS>" << endl <<
"</SETUP>" << endl;
907 if ( (is=dynamic_cast<const IService*>(in)) !=
nullptr) {
913 }
else if ( (ia = dynamic_cast<const Algorithm*>(in)) !=
nullptr ) {
919 }
else if ( (it = dynamic_cast<const IAlgTool*>(in)) !=
nullptr ) {
927 <<
"Could not dcast interface to accepted History Obj type for "
932 if ( !hist || !vhist ) {
933 m_log <<
MSG::ERROR <<
"Could not dcast recognized object to HistoryObj or IVersHistoryObj. This should never happen."
939 hist->
dump(ofs,
true);
941 ofs <<
">> " << vhist->
name() << endl << *hist << endl;
virtual StatusCode stop()
StatusCode initialize() override
virtual const std::vector< const Property * > * getProperties(const std::string &client) const =0
Get the properties associated to a given client.
virtual ServiceHistory * getServiceHistory(const IService &) const
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
const std::string & type() const
Access to the incident type.
SmartIF< IToolSvc > m_toolSvc
GAUDI_API void resetColor()
Reset the colors to defaults.
StatusCode finalize() override
virtual std::string toString() const =0
value -> string
MSG::Level level()
Retrieve output level.
const std::string & name() const
property name
virtual void dump(std::ostream &, const bool isXML=false, int indent=0) const =0
AlgorithmHistory class definition.
bool isSuccess() const
Test for a status code of SUCCESS.
auto begin(reverse_wrapper< T > &w)
virtual StatusCode registerDataHistory(const CLID &id, const std::string &key, const std::string &store)
virtual StatusCode listProperties() const
The IAlgManager is the interface implemented by the Algorithm Factory in the Application Manager to s...
virtual StatusCode registerJob()
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)
std::multimap< DHH, DataHistory * > m_datMap
std::map< const AlgTool *, AlgToolHistory * > m_algtoolmap
const std::string & documentation() const
property documentation
JobHistory class definition.
bool isFailure() const
Test for a status code of FAILURE.
virtual std::ostream & fillStream(std::ostream &) const
the printout of the property value
IAlgorithm * getCurrentIAlg() const
virtual const std::string & name() const =0
Retrieve the name of the instance.
const std::string & name() const override
The identifying name of the algorithm object.
GAUDI_API void setColor(MSG::Color col)
Set the text color.
virtual AlgToolHistory * getAlgToolHistory(const IAlgTool &) const
virtual void handle(const Incident &inc)
Main interface for the JobOptions service.
GAUDI_API ISvcLocator * svcLocator()
General service interface definition.
virtual StatusCode registerSvc(const IService &)
auto end(reverse_wrapper< T > &w)
This class is used for returning status codes from appropriate routines.
HistorySvc(const std::string &name, ISvcLocator *svc)
#define DECLARE_COMPONENT(type)
virtual StatusCode registerAlgTool(const IAlgTool &)
DataHistory class definition.
IAlgContextSvc * p_algCtxSvc
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
virtual StatusCode registerAlg(const Algorithm &)
virtual StatusCode initialize()
virtual AlgorithmHistory * getAlgHistory(const Algorithm &) const
virtual StatusCode finalize()
const PropertyList & properties() const
The IAlgorithm is the interface implemented by the Algorithm base class.
std::string dumpProp(const Property *, const bool isXML=false, int indent=0) const
AlgToolHistory class definition.
void dumpState(std::ofstream &) const
const PropertyList & properties() const
IIncidentSvc * m_incidentSvc
virtual DataHistory * createDataHistoryObj(const CLID &id, const std::string &key, const std::string &store)
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
Property base class allowing Property* collections to be "homogeneous".
virtual DataHistory * getDataHistory(const CLID &id, const std::string &key, const std::string &store) const
const PropertyList & properties() const
void dumpProperties(std::ofstream &) const
Base class used to extend a class implementing other interfaces.
static std::string convert_string(const std::string &)
Base class for all Incidents (computing events).
virtual void addListener(IIncidentListener *lis, const std::string &type="", long priority=0, bool rethrow=false, bool singleShot=false)=0
Add listener.
void setLevel(int level)
Update outputlevel.
ServiceHistory class definition.
virtual const std::string & name() const =0
std::map< const Algorithm *, AlgorithmHistory * > m_algmap
virtual const std::list< IService * > & getServices() const =0
Get a reference to a service and create it if it does not exists.
std::set< const IAlgTool * > m_ialgtools
unsigned int CLID
Class ID definition.
Interface for Versioned History Objects.
virtual IAlgorithm * currentAlg() const =0
accessor to current algorithm:
virtual StatusCode captureState()
TO * reference(FROM *from)
std::map< const IService *, ServiceHistory * > m_svcmap
virtual StatusCode reinitialize()
virtual JobHistory * getJobHistory() const
std::unique_ptr< JobHistory > m_jobHistory