3 #include "GaudiKernel/HistoryObj.h"
4 #include "GaudiKernel/IVersHistoryObj.h"
6 #include "GaudiKernel/JobHistory.h"
7 #include "GaudiKernel/AlgorithmHistory.h"
8 #include "GaudiKernel/AlgToolHistory.h"
9 #include "GaudiKernel/DataHistory.h"
10 #include "GaudiKernel/ServiceHistory.h"
12 #include "GaudiKernel/ISvcLocator.h"
14 #include "GaudiKernel/System.h"
15 #include "GaudiKernel/Bootstrap.h"
16 #include "GaudiKernel/IAlgManager.h"
17 #include "GaudiKernel/IAlgorithm.h"
18 #include "GaudiKernel/Algorithm.h"
19 #include "GaudiKernel/IAlgTool.h"
20 #include "GaudiKernel/AlgTool.h"
21 #include "GaudiKernel/IService.h"
22 #include "GaudiKernel/IJobOptionsSvc.h"
23 #include "GaudiKernel/IAppMgrUI.h"
24 #include "GaudiKernel/IIncidentSvc.h"
25 #include "GaudiKernel/IToolSvc.h"
26 #include "GaudiKernel/ServiceHandle.h"
28 #include "GaudiKernel/IAlgContextSvc.h"
35 #define ON_DEBUG if (UNLIKELY(outputLevel() <= MSG::DEBUG))
36 #define ON_VERBOSE if (UNLIKELY(outputLevel() <= MSG::VERBOSE))
48 template <
typename MAP,
typename SET>
49 inline void map_to_set(
const MAP&
m,
SET&
s) {
50 std::transform(std::begin(m),
std::end(m),
51 std::inserter(s, s.begin()),
52 [](
typename MAP::const_reference p){
return p.second; });
60 DHH(
const CLID&
i,
const std::string& k):id(i), key(k) {}
66 return (key < rhs.
key);
75 m_isInitialized(
false),
81 m_log(msgSvc(), name ),
82 m_outputFileTypeXML(
false)
115 template <
typename T1,
typename T2>
116 void clear(std::pair<const T1* const, T2*>& p) {
117 const_cast<T1*
>(p.first)->release();
122 std::for_each(std::begin(m),
std::end(m),
123 [](
typename M::value_type& alg){ clear(alg); });
160 static const bool CREATEIF(
true);
183 const bool rethrow =
false;
184 const bool oneShot =
true;
206 if (
service(
"JobOptionsSvc",jo).isFailure()) {
208 <<
"Could not get jobOptionsSvc - "
209 <<
"not adding properties to JobHistory" <<
endmsg;
212 bool foundAppMgr(
false);
215 if (client ==
"ApplicationMgr") foundAppMgr =
true;
223 if (
service(
"ApplicationMgr", ap).isFailure()) {
240 pp_cast<void>(&algMgr) );
250 <<
" does not inherit from Algorithm. Not registering it."
266 (
const_cast<IAlgTool*
>(algtool))->addRef();
349 <<
" already registered with HistorySvc" <<
endmsg;
353 (
const_cast<Algorithm*
>(&alg))->addRef();
386 std::string str = ost.str();
404 PropertyList::const_iterator itr;
406 ofs << alg.
name() <<
" " <<
dumpProp(prop) << std::endl;
416 set<const Algorithm*>::const_iterator itr =
m_algs.find(palg);
417 if ( itr ==
m_algs.end() ) {
423 map<const Algorithm*, AlgorithmHistory*>::const_iterator itr2;
426 return ( itr2->second );
454 m_log <<
"Dumping properties for all Algorithms (" <<
m_algmap.size()
474 m_log <<
"Dumping properties for all Services (" <<
m_svcmap.size()
483 m_log <<
"Dumping properties for Job";
488 std::string str = ost.str();
501 ofs <<
"GLOBAL" << std::endl;
503 JobHistory::PropertyPairList::const_iterator itrj;
504 for (itrj=props.begin(); itrj != props.end(); ++itrj) {
505 std::string client = itrj->first;
507 ofs << client <<
" " <<
dumpProp(prp) << std::endl;
510 ofs << std::endl <<
"SERVICES" << std::endl;
511 std::map<const IService*, ServiceHistory*>::const_iterator itr_s;
519 ofs << std::endl <<
"ALGORITHMS" << std::endl;
520 std::map<const Algorithm*, AlgorithmHistory*>::const_iterator itr;
528 ofs << std::endl <<
"ALGTOOLS" << std::endl;
529 std::map<const AlgTool*, AlgToolHistory*>::const_iterator itr_a;
531 const AlgTool* alg = itr_a->first;
553 <<
"HistorySvc has been initialized" <<
endmsg;
566 const std::string& ) {
577 <<
"Could not discover current Algorithm:" << endl
578 <<
" object CLID: " <<
id <<
" key: \"" << key
587 <<
"Could not extract concrete Algorithm:"
589 <<
" object CLID: " <<
id <<
" key: \"" << key
604 const std::string& storeName) {
608 auto boundaries =
m_datMap.equal_range(dhh);
609 auto match = boundaries.second;
611 if (boundaries.first != boundaries.second) {
617 algName = ialg->
name();
622 match = std::find_if(boundaries.first, boundaries.second,
624 return p.second->algorithmHistory()->algorithm_name() == algName;
628 if (match == boundaries.second) {
630 m_datMap.insert(pair<DHH, DataHistory*>(dhh,dh));
641 const std::string& )
const {
645 pair<DHMCitr,DHMCitr> mitr =
m_datMap.equal_range(dhh);
647 if(mitr.first == mitr.second) {
651 return mitr.first->second;
660 std::list<DataHistory*>& dhlist)
const {
666 pair<DHMCitr,DHMCitr> mitr =
m_datMap.equal_range(dhh);
668 for (
DHMCitr itr=mitr.first; itr != mitr.second; ++itr) {
669 dhlist.push_back(itr->second);
682 if ( svc.
name() ==
"HistoryStore" ) {
689 map<const IService*, ServiceHistory*>::const_iterator itr =
719 map<const IService*, ServiceHistory*>::const_iterator itr =
727 return ( itr->second );
753 std::string str = ost.str();
775 ofs << svc.
name() <<
" " <<
dumpProp(prop) << std::endl;
800 <<
"\" to an AlgTool" <<
endmsg;
806 <<
" already registered in HistorySvc" <<
endmsg;
811 (
const_cast<AlgTool*
>(alg))->addRef();
844 std::string str = ost.str();
863 ofs << alg.
name() <<
" " <<
dumpProp(prop) << std::endl;
874 set<const AlgTool*>::const_iterator itr =
m_algtools.find(palg);
881 map<const AlgTool*, AlgToolHistory*>::const_iterator itr2;
884 return ( itr2->second );
903 <<
"Will try again at next BeginEvent incident" <<
endmsg;
914 std::ostringstream ost;
920 ost <<
"<PROPERTY name=\"" << prop->
name()
938 ofs <<
"<?xml version=\"1.0\" ?> " << std::endl;
939 ofs <<
"<!--Test-xml-->" << std::endl;
940 ofs <<
"<SETUP>" << std::endl;
941 ofs <<
" <GLOBAL>" << std::endl;
943 ofs <<
"GLOBAL" << std::endl;
946 std::string client_currently_open =
"start";
949 const std::string& client =
item.first;
954 if (client != client_currently_open) {
955 if(client_currently_open!=
"start") ofs <<
" </COMPONENT>" << endl;
956 ofs <<
" <COMPONENT name=\""
957 << client <<
"\" class=\"undefined\">" << std::endl;
960 ofs << client <<
" ";
965 client_currently_open = client;
968 ofs <<
" </COMPONENT>" << endl;
973 ofs <<
"</GLOBAL>" << endl <<
"<SERVICES>" << endl;
975 ofs <<
"SERVICES" << std::endl;
984 ofs <<
"</SERVICES>" << endl <<
"<ALGORITHMS> " << endl;
986 ofs <<
"ALGORITHMS" << std::endl;
996 ofs <<
"</ALGORITHMS>" << endl <<
"<ALGTOOLS> " << endl;
998 ofs <<
"ALGTOOLS" << std::endl;
1007 ofs <<
"</ALGTOOLS>" << endl <<
"</SETUP>" << endl;
1023 if ( (is=dynamic_cast<const IService*>(in)) != 0) {
1029 }
else if ( (ia = dynamic_cast<const Algorithm*>(in)) != 0 ) {
1035 }
else if ( (it = dynamic_cast<const IAlgTool*>(in)) != 0 ) {
1043 <<
"Could not dcast interface to accepted History Obj type for "
1048 if (hist == 0 || vhist == 0) {
1049 m_log <<
MSG::ERROR <<
"Could not dcast recognized object to HistoryObj or IVersHistoryObj. This should never happen."
1055 hist->
dump(ofs,
true);
1057 ofs <<
">> " << vhist->
name() << endl << *hist << endl;
const std::string BeginEvent
Processing of a new event has started.
virtual StatusCode stop()
Stop (from RUNNING to INITIALIZED).
IntegerProperty m_outputLevel
Service output level.
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...
const std::string & type() const
Access to the incident type.
virtual const std::vector< Property * > & getProperties() const =0
Get list of properties.
Gaudi::StateMachine::State m_state
Service state.
SmartIF< IToolSvc > m_toolSvc
GAUDI_API void resetColor()
Reset the colors to defaults.
virtual std::string toString() const =0
value -> string
MSG::Level level()
Retrieve output level.
const std::string & name() const
property name
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
std::vector< std::pair< std::string, const Property * > > PropertyPairList
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.
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.
virtual const std::vector< IAlgorithm * > & getAlgorithms() const =0
Return the list of Algorithms.
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.
GAUDI_API void setColor(MSG::Color col)
Set the text color.
virtual AlgToolHistory * getAlgToolHistory(const IAlgTool &) const
virtual void handle(const Incident &inc)
Inform that a new incident has occurred.
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
virtual unsigned long addRef()
Add reference to object.
std::set< const Algorithm * > m_algs
Main interface for the JobOptions service.
DHH(const CLID &i, const std::string &k)
GAUDI_API ISvcLocator * svcLocator()
#define DECLARE_COMPONENT(type)
General service interface definition.
virtual StatusCode registerSvc(const IService &)
This class is used for returning status codes from appropriate routines.
HistorySvc(const std::string &name, ISvcLocator *svc)
virtual StatusCode registerAlgTool(const IAlgTool &)
DataHistory class definition.
IAlgContextSvc * p_algCtxSvc
virtual const std::string & name() const
The identifying name of the algorithm object.
JobHistory * m_jobHistory
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()
Initialization (from CONFIGURED to INITIALIZED).
virtual AlgorithmHistory * getAlgHistory(const Algorithm &) const
virtual StatusCode finalize()
Finalize (from INITIALIZED to CONFIGURED).
const PropertyList & properties() const
void addProperty(const std::string &, const Property *)
DataHistMap::const_iterator DHMCitr
The IAlgorithm is the interface implemented by the Algorithm base class.
unsigned int CLID
Class ID definition.
const TYPE & value() const
explicit conversion
const PropertyPairList & propertyPairs() const
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
virtual StatusCode initialize()
Initialization (from CONFIGURED to INITIALIZED).
const PropertyList & properties() const
void dumpProperties(std::ofstream &) const
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.
Templated class to add the standard messaging functionalities.
ServiceHistory class definition.
virtual const std::string & name() const =0
std::map< const Algorithm *, AlgorithmHistory * > m_algmap
StatusCode service(const std::string &name, const T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
std::set< const IService * > m_svcs
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
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Interface for Versioned History Objects.
The IProperty is the basic interface for all components which have properties that can be set or get...
virtual IAlgorithm * currentAlg() const =0
accessor to current algorithm:
static const InterfaceID & interfaceID()
Return an instance of InterfaceID identifying the interface.
virtual StatusCode captureState()
TO * reference(FROM *from)
std::map< const IService *, ServiceHistory * > m_svcmap
virtual StatusCode finalize()
Finalize (from INITIALIZED to CONFIGURED).
virtual StatusCode reinitialize()
Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED).
std::set< const AlgTool * > m_algtools
virtual JobHistory * getJobHistory() const
SmartIF< ISvcLocator > & serviceLocator() const
Retrieve pointer to service locator.
virtual StatusCode queryInterface(const InterfaceID &ti, void **pp)=0
Set the void** to the pointer to the requested interface of the instance.