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; });
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;