Gaudi Framework, version v23r6

Home   Generated: Wed Jan 30 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HistorySvc.cpp
Go to the documentation of this file.
1 #ifndef GAUDISVC_FASTHISTORYSVC_H
2  #include "HistorySvc.h"
3 #endif
4 
6 
12 
13 #ifndef KERNEL_SVCFACTORY_H
14  #include "GaudiKernel/SvcFactory.h"
15 #endif
16 #ifndef GAUDIKERNEL_ISVCLOCATOR_H
17  #include "GaudiKernel/ISvcLocator.h"
18 #endif
19 
20 #include "GaudiKernel/System.h"
21 #include "GaudiKernel/Bootstrap.h"
23 #include "GaudiKernel/IAlgorithm.h"
24 #include "GaudiKernel/Algorithm.h"
25 #include "GaudiKernel/IAlgTool.h"
26 #include "GaudiKernel/AlgTool.h"
27 #include "GaudiKernel/IService.h"
29 #include "GaudiKernel/IAppMgrUI.h"
31 #include "GaudiKernel/IToolSvc.h"
33 
35 
36 #include <iostream>
37 #include <fstream>
38 #include <sstream>
39 #include <limits>
40 
41 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
43 
44 using namespace std;
45 
46 //
48 //
49 
50 struct DHH {
53 
54  DHH(const CLID& i, const std::string& k):id(i), key(k) {}
55 
56  bool operator < ( DHH const &rhs ) const {
57  if (id != rhs.id) {
58  return (id < rhs.id);
59  } else {
60  return (key < rhs.key);
61  }
62  }
63 };
64 
65 void fenv_dummy(char**) {}
66 
68  : base_class( name, svc ),
69  m_isInitialized(false),
70  m_dump(false),
71  p_algCtxSvc(0),
72  m_jobHistory(0),
73  m_outputFile(""),
74  m_incidentSvc(0),
75  m_log(msgSvc(), name )
76 
77 {
78  declareProperty("Dump",m_dump);
79  declareProperty("Activate", m_activate=true);
80  declareProperty("OutputFile",m_outputFile);
81 
82  // hack to bring in environ
83  vector<string> envtmp = System::getEnv();
84  envtmp.size(); // prevent icc remark #177: X declared but never referenced
85 }
86 
87 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
88 
90  delete m_jobHistory;
91 }
92 
93 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
94 
96 
97  clearState();
98 
100 
101  return initialize();
102 
103 }
104 
105 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
106 
108  m_algs.clear();
110  for (algitr = m_algmap.begin(); algitr != m_algmap.end(); ++algitr) {
111  AlgorithmHistory* h = algitr->second;
112  (const_cast<Algorithm*> (algitr->first))->release();
113  delete h;
114  }
115  m_algmap.clear();
116 
117  m_ialgtools.clear();
118  m_algtools.clear();
120  for (atitr=m_algtoolmap.begin(); atitr != m_algtoolmap.end(); ++atitr) {
121  (const_cast<AlgTool*> (atitr->first))->release();
122  delete atitr->second;
123  }
125 
126  m_svcs.clear();
128  for (svitr = m_svcmap.begin(); svitr != m_svcmap.end(); ++svitr) {
129  (const_cast<IService*> (svitr->first))->release();
130  delete svitr->second;
131  }
132  m_svcmap.clear();
133 }
134 
135 
136 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
137 
139 
140  StatusCode status = Service::initialize();
142 
143  if (status.isFailure()) {
144 #ifndef NDEBUG
145  m_log << MSG::DEBUG << "Failed to initialize the base class (Service)"
146  << endmsg;
147 #endif
148  return status;
149  }
150 
151 #ifndef NDEBUG
152  m_log << MSG::DEBUG << "Initializing HistorySvc" << endmsg;
153 #endif
154 
155  if (!m_activate) return StatusCode::SUCCESS;
156 
157  static const bool CREATEIF(true);
158 
159  if ( service("AlgContextSvc",p_algCtxSvc,CREATEIF).isFailure() ) {
160  m_log << MSG::ERROR << "unable to get the AlgContextSvc" << endmsg;
161  return StatusCode::FAILURE;
162  }
163 
164  if (service("IncidentSvc", m_incidentSvc, CREATEIF).isFailure()) {
165  m_log << MSG::ERROR << "unable to get the IncidentSvc" << endmsg;
166  return StatusCode::FAILURE;
167  }
168 
169  // create a weak dependency on the ToolSvc, so that it doesn't get deleted
170  // before we're done with it in finalize
171  m_toolSvc = serviceLocator()->service("ToolSvc");
172  if (! m_toolSvc) {
173  m_log << MSG::ERROR << "could not retrieve the ToolSvc handle !"
174  << endmsg;
175  return StatusCode::FAILURE;
176  }
177 
178  // add listener to be triggered by first BeginEvent with low priority
179  // so it gets called first
180  const bool rethrow = false;
181  const bool oneShot = true; // make the listener called only once
183  std::numeric_limits<long>::min(),rethrow,oneShot);
184 
185  m_isInitialized = true;
186 
187  return StatusCode::SUCCESS;
188 
189 }
190 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
191 
193 
194  if (m_jobHistory == 0) {
195  m_jobHistory = new JobHistory;
196  IJobOptionsSvc *jo;
197  if (service("JobOptionsSvc",jo).isFailure()) {
198  m_log << MSG::ERROR
199  << "Could not get jobOptionsSvc - "
200  << "not adding properties to JobHistory" << endmsg;
201  } else {
202 
203  bool foundAppMgr(false);
204 
205  std::vector<std::string> clients = jo->getClients();
208  for (it=clients.begin(); it!=clients.end(); ++it) {
209  if (*it == "ApplicationMgr") {
210  foundAppMgr = true;
211  }
212  const std::vector<const Property*> *props = jo->getProperties(*it);
213  for (itr=props->begin(); itr != props->end(); ++itr) {
214  m_jobHistory->addProperty( *it, *itr );
215  }
216  }
217 
218  if (!foundAppMgr) {
219  IProperty *ap;
220  if (service("ApplicationMgr",ap).isFailure()) {
221  m_log << MSG::ERROR << "could not get the ApplicationMgr" << endmsg;
222  } else {
224  const std::vector<Property*> props = ap->getProperties();
225  for (itr2=props.begin(); itr2 != props.end(); ++itr2) {
226  m_jobHistory->addProperty( "ApplicationMgr", *itr2 );
227  }
228  }
229  }
230 
231  }
232  }
233 
235 
236  StatusCode sc;
237  IAlgManager* algMgr = 0;
239  pp_cast<void>(&algMgr) );
240  if (sc.isFailure()) {
241  m_log << MSG::ERROR << "Could not get AlgManager" << endmsg;
242  return StatusCode::FAILURE;
243  } else {
244 
246  algs = algMgr->getAlgorithms();
248  for (itr=algs.begin(); itr!=algs.end(); ++itr) {
249  Algorithm* alg = dynamic_cast<Algorithm*> (*itr);
250  if (alg == 0) {
251  m_log << MSG::WARNING << "Algorithm " << (*itr)->name()
252  << " does not inherit from Algorithm. Not registering it."
253  << endmsg;
254  } else {
255  registerAlg( *alg ).ignore();
256  }
257  }
258 
259  m_log << MSG::INFO;
260  m_log << "Registered " << algs.size() << " Algorithms" << endmsg;
261 
262  }
263 
265 
266  m_isInitialized = true;
268  for (itra = m_ialgtools.begin(); itra != m_ialgtools.end(); ++itra) {
269  (const_cast<IAlgTool*>(*itra))->addRef();
270  registerAlgTool(**itra).ignore();
271  }
272 
273  m_log << MSG::INFO << "Registered " << m_algtools.size() << " AlgTools"
274  << endmsg;
275 
277 
279 
281  for (itrs=svcs.begin(); itrs!=svcs.end(); ++itrs) {
282  (*itrs)->addRef();
283  registerSvc(**itrs).ignore();
284  }
285 
286  m_log << MSG::INFO;
287  m_log << "Registered " << svcs.size() << " Services" << endmsg;
288 
289  return StatusCode::SUCCESS;
290 
291 
292 }
293 
294 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
295 
297 
298  if (!m_activate) return StatusCode::SUCCESS;
299 
300  if (m_dump) {
302  }
303 
304  if (m_outputFile != "") {
305  std::ofstream ofs;
306  ofs.open(m_outputFile.c_str());
307  if (!ofs) {
308  m_log << MSG::ERROR << "Unable to open output file \"m_outputFile\""
309  << endmsg;
310  } else {
311 
312  // dumpProperties(ofs);
313  dumpState(ofs);
314 
315  ofs.close();
316  }
317  }
318 
319  clearState();
320 
321  return StatusCode::SUCCESS;
322 
323 }
324 
325 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
326 
328 
329 
330  clearState();
331 
332  StatusCode status = Service::finalize();
333 
334  if ( status.isSuccess() )
335  m_log << MSG::INFO << "Service finalised successfully" << endmsg;
336 
337  return status;
338 
339 }
340 
341 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
342 
343 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
344 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
345 
348 
349  JobHistory *job = getJobHistory();
350  if (m_algmap.find(&alg) != m_algmap.end()) {
351  m_log << MSG::WARNING << "Algorithm " << alg.name()
352  << " already registered with HistorySvc" << endmsg;
353  return StatusCode::SUCCESS;
354  }
355 
356  (const_cast<Algorithm*>(&alg))->addRef();
357 
358  m_algs.insert(&alg);
359 
360  AlgorithmHistory *algHist = new AlgorithmHistory(alg, job);
361  m_algmap[&alg] = algHist;
362 
363 #ifndef NDEBUG
364  m_log << MSG::DEBUG << "Registering algorithm: ";
366  m_log << alg.name() << endmsg;
367  m_log.resetColor();
368 #endif
369 
370  return StatusCode(StatusCode::SUCCESS,true);
371 
372 }
373 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
374 
377 
378  m_log << MSG::INFO << "Dumping properties for " << alg.name() << endl;
379 
380  AlgorithmHistory *hist = getAlgHistory( alg );
381 
382  if (hist == 0) {
383  return StatusCode::FAILURE;
384  }
385 
386  ostringstream ost;
387  ost << *hist;
388 
389  std::string str = ost.str();
390 
391  m_log << MSG::INFO << alg.name() << " --> " << endl << str << endmsg;
392 
393  return StatusCode(StatusCode::SUCCESS,true);
394 
395 }
396 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
397 
398 void
400 
401  AlgorithmHistory *hist = getAlgHistory( alg );
402 
403  if (hist == 0) {
404  return;
405  }
406 
408  for (itr=hist->properties().begin(); itr!=hist->properties().end(); ++itr) {
409  ofs << alg.name() << " " << dumpProp(*itr) << std::endl;
410  }
411 
412 }
413 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
414 
417 
418  const Algorithm *palg = &alg;
420  if ( itr == m_algs.end() ) {
421  m_log << MSG::WARNING << "Algorithm " << alg.name() << " not registered"
422  << endmsg;
423  return 0;
424  }
425 
427  itr2 = m_algmap.find( *itr );
428 
429  return ( itr2->second );
430 
431 }
432 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
433 
434 void
436 
438  for (itr=m_algs.begin(); itr!=m_algs.end(); ++itr) {
439  AlgorithmHistory *ah = m_algmap.find(*itr)->second;
440 
441  algs.insert(ah);
442  }
443 
444 }
445 
446 
447 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
450 
451 
452  return StatusCode(StatusCode::SUCCESS,true);
453 
454 
455 }
456 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
457 
458 
461 
462  m_log << MSG::INFO;
464  m_log << "Dumping properties for all Algorithms (" << m_algmap.size()
465  << ")" << endmsg;
466 
468  for (itr=m_algmap.begin(); itr != m_algmap.end(); ++itr) {
469  const Algorithm* alg = itr->first;
470 
471  listProperties( *alg ).ignore();
472 
473  }
474 
475  m_log << MSG::INFO;
477  m_log << "Dumping properties for all AlgTools (" << m_algtoolmap.size()
478  << ")" << endmsg;
479 
481  for (itr_a=m_algtoolmap.begin(); itr_a != m_algtoolmap.end(); ++itr_a) {
482  m_log << MSG::DEBUG << " --> " << itr_a->second->algtool_name() << endmsg;
483  const AlgTool* alg = itr_a->first;
484 
485  listProperties( *alg ).ignore();
486 
487  }
488 
489  m_log << MSG::INFO;
491  m_log << "Dumping properties for all Services (" << m_svcmap.size()
492  << ")" << endmsg;
493 
495  for (itr_s=m_svcmap.begin(); itr_s != m_svcmap.end(); ++itr_s) {
496  const IService* svc = itr_s->first;
497 
498  listProperties( *svc ).ignore();
499 
500  }
501 
502  m_log << MSG::INFO;
504  m_log << "Dumping properties for Job";
505  m_log.resetColor();
506 
507  ostringstream ost;
508  ost << *m_jobHistory;
509  std::string str = ost.str();
510 
511  m_log << std::endl << str << endmsg;
512 
513  return StatusCode(StatusCode::SUCCESS,true);
514 
515 }
516 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
517 
518 void
520 
521 
522  ofs << "GLOBAL" << std::endl;
525  for (itrj=props.begin(); itrj != props.end(); ++itrj) {
526  std::string client = itrj->first;
527  const Property* prp = itrj->second;
528  ofs << client << " " << dumpProp(prp) << std::endl;
529  }
530 
531  ofs << std::endl << "SERVICES" << std::endl;
533  for (itr_s=m_svcmap.begin(); itr_s != m_svcmap.end(); ++itr_s) {
534  const IService* svc = itr_s->first;
535 
536  dumpProperties( *svc, ofs );
537 
538  }
539 
540  ofs << std::endl << "ALGORITHMS" << std::endl;
542  for (itr=m_algmap.begin(); itr != m_algmap.end(); ++itr) {
543  const Algorithm* alg = itr->first;
544 
545  dumpProperties( *alg, ofs );
546 
547  }
548 
549  ofs << std::endl << "ALGTOOLS" << std::endl;
551  for (itr_a=m_algtoolmap.begin(); itr_a != m_algtoolmap.end(); ++itr_a) {
552  const AlgTool* alg = itr_a->first;
553 
554  dumpProperties( *alg, ofs );
555 
556  }
557 
558 
559 }
560 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
561 
562 JobHistory*
564 
565  return m_jobHistory;
566 
567 }
568 
569 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
570 IAlgorithm*
572  if (p_algCtxSvc == 0) {
573  m_log << MSG::WARNING << "trying to create DataHistoryObj before "
574  << "HistorySvc has been initialized" << endmsg;
575  return 0;
576 
577  } else {
578  return p_algCtxSvc->currentAlg();
579  }
580 }
581 
582 
583 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
584 
587  const std::string& /* storeName */) {
588 
589  if (!m_activate) return 0;
590 
591 
592  AlgorithmHistory *algHist;
593 
594  IAlgorithm* ialg = getCurrentIAlg();
595  if (ialg == 0) {
596 #ifndef NDEBUG
597  m_log << MSG::DEBUG
598  << "Could not discover current Algorithm:" << endl
599  << " object CLID: " << id << " key: \"" << key
600  << "\"" << endmsg;
601 #endif
602  algHist = 0;
603  } else {
604  Algorithm* alg = dynamic_cast<Algorithm*>(ialg);
605  if (alg != 0) {
606  algHist = getAlgHistory( *alg );
607  } else {
609  << "Could not extract concerete Algorithm:"
610  << endl
611  << " object CLID: " << id << " key: \"" << key
612  << "\"" << endmsg;
613  algHist = 0;
614  }
615  }
616 
617  DataHistory *hist = new DataHistory(id, key, algHist);
618 
619  return hist;
620 
621 }
622 
623 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
626  const std::string& storeName) {
627 
628  DHH dhh(id,key);
629 
631 
632  if (mitr.first == mitr.second) {
633  // not in the map
634  DataHistory *dh = createDataHistoryObj(id,key,storeName);
636  } else {
637  // found at least one
638  bool match(false);
639 
640  std::string algName;
641  IAlgorithm *ialg = getCurrentIAlg();
642  if (ialg != 0) {
643  algName = ialg->name();
644  } else {
645  algName = "UNKNOWN";
646  }
647 
648  for (DHMitr itr = mitr.first; itr != mitr.second; ++itr) {
649  DataHistory *dh = itr->second;
650  if (dh->algorithmHistory()->algorithm_name() == algName) {
651  match = true;
652  break;
653  }
654  }
655 
656  if (! match) {
657  DataHistory *dh = createDataHistoryObj(id,key,storeName);
659  }
660  }
661 
662  return StatusCode::SUCCESS;
663 
664 }
665 
666 
667 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
670  const std::string& /*storeName*/) const {
671 
672  DHH dhh(id,key);
673 
675 
676  if(mitr.first == mitr.second) {
677  return 0;
678  }
679 
680  return mitr.first->second;
681 
682 }
683 
684 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
685 
686 int
688  const std::string& /*storeName*/,
689  std::list<DataHistory*>& dhlist) const {
690 
691  DHH dhh(id,key);
692 
693  int n(0);
694 
696 
697  for (DHMCitr itr=mitr.first; itr != mitr.second; ++itr) {
698  dhlist.push_back(itr->second);
699  n++;
700  }
701 
702  return n;
703 
704 }
705 
706 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
707 
710 
711  if ( svc.name() == "HistoryStore" ) {
712  // m_log << MSG::WARNING << "not registering store" << endmsg;
713  return StatusCode(StatusCode::SUCCESS,true);
714  }
715 
716  JobHistory *job = getJobHistory();
717  const IService* psvc = &svc;
719  m_svcmap.find(psvc);
720  if (itr == m_svcmap.end()) {
721 
722 #ifndef NDEBUG
723  m_log << MSG::DEBUG << "Registering Service: ";
725  m_log << svc.name() << endmsg;
726 #endif
727 
728  m_svcs.insert(psvc);
729 
730  ServiceHistory *svcHist = new ServiceHistory(&svc, job);
731  m_svcmap[psvc] = svcHist;
732 
733  (const_cast<IService*>(psvc))->addRef();
734 
735  }
736 
737  m_log.resetColor();
738  return StatusCode(StatusCode::SUCCESS,true);
739 
740 }
741 
742 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
743 
746 
747  const IService *psvc = &svc;
749  m_svcmap.find(psvc);
750  if ( itr == m_svcmap.end() ) {
751  m_log << MSG::WARNING << "Service " << svc.name() << " not registered"
752  << endmsg;
753  return 0;
754  }
755 
756  return ( itr->second );
757 
758 }
759 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
760 
761 void
763 
765  for (itr=m_svcs.begin(); itr!=m_svcs.end(); ++itr) {
766  ServiceHistory *sh = m_svcmap.find( *itr )->second;
767 
768  svcs.insert(sh);
769  }
770 
771 }
772 
773 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
774 
777 
778  m_log << MSG::INFO << "Dumping properties for " << svc.name() << endl;
779 
780  ServiceHistory *hist = getServiceHistory( svc );
781 
782  if (hist == 0) {
783  return StatusCode::FAILURE;
784  }
785 
786  ostringstream ost;
787  ost << *hist;
788 
789  std::string str = ost.str();
790 
791  m_log << MSG::INFO << svc.name() << " --> " << endl << str << endmsg;
792 
793 
794 
795  return StatusCode(StatusCode::SUCCESS,true);
796 
797 }
798 
799 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
800 
801 void
803 
804  ServiceHistory *hist = getServiceHistory( svc );
805 
806  if (hist == 0) {
807  return;
808  }
809 
811  for (itr=hist->properties().begin(); itr != hist->properties().end();++itr) {
812  ofs << svc.name() << " " << dumpProp(*itr) << std::endl;
813  }
814 
815 }
816 
817 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
818 
821 
822  if (! m_isInitialized) {
823  if (p_algCtxSvc == 0) {
824  if ( service("AlgContextSvc",p_algCtxSvc,true).isFailure() ) {
825  m_log << MSG::ERROR << "unable to get the AlgContextSvc" << endmsg;
826  return StatusCode::FAILURE;
827  }
828  }
829 
830  m_ialgtools.insert(&ialg);
831  return StatusCode::SUCCESS;
832  }
833 
834  const AlgTool *alg = dynamic_cast<const AlgTool*>( &ialg );
835  if ( alg == 0 ) {
836  m_log << MSG::ERROR << "Could not dcast IAlgTool \"" << ialg.name()
837  << "\" to an AlgTool" << endmsg;
838  return StatusCode::FAILURE;
839  }
840 
841  if (m_algtools.find(alg) != m_algtools.end()) {
842  m_log << MSG::WARNING << "AlgTool " << ialg.name()
843  << " already registered in HistorySvc" << endmsg;
844  return StatusCode::SUCCESS;
845  }
846 
847  m_algtools.insert(alg);
848  (const_cast<AlgTool*>(alg))->addRef();
849 
850  const JobHistory *job = getJobHistory();
851  AlgToolHistory *algHist = new AlgToolHistory(*alg, job);
852  m_algtoolmap[alg] = algHist;
853 
854 #ifndef NDEBUG
855  m_log << MSG::DEBUG << "Registering algtool: ";
857  m_log << alg->name() << endmsg;
858  m_log.resetColor();
859 #endif
860 
861  return StatusCode::SUCCESS;
862 
863 }
864 
865 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
866 
869 
870  m_log << MSG::INFO << "Dumping properties for " << alg.name() << endl;
871 
872  AlgToolHistory *hist = getAlgToolHistory( alg );
873 
874  if (hist == 0) {
875  return StatusCode::FAILURE;
876  }
877 
878  ostringstream ost;
879  ost << *hist;
880 
881  std::string str = ost.str();
882 
883  m_log << MSG::INFO << alg.name() << " --> " << endl << str << endmsg;
884 
885  return StatusCode::SUCCESS;
886 
887 }
888 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
889 
890 void
892 
893  AlgToolHistory *hist = getAlgToolHistory( alg );
894 
895  if (hist == 0) {
896  return;
897  }
898 
900  for (itr=hist->properties().begin(); itr!=hist->properties().end(); ++itr) {
901  ofs << alg.name() << " " << dumpProp(*itr) << std::endl;
902  }
903 
904 }
905 
906 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
907 
910 
911  const AlgTool *palg = dynamic_cast<const AlgTool*>(&alg);
913  if ( itr == m_algtools.end() ) {
914  m_log << MSG::WARNING << "AlgTool " << alg.name() << " not registered"
915  << endmsg;
916  return 0;
917  }
918 
920  itr2 = m_algtoolmap.find( *itr );
921 
922  return ( itr2->second );
923 
924 }
925 
926 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
927 
928 void
930 
932  for (itr=m_algtools.begin(); itr!=m_algtools.end(); ++itr) {
933  AlgToolHistory *ah = m_algtoolmap.find(*itr)->second;
934 
935  algs.insert(ah);
936  }
937 
938 }
939 
940 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
941 
942 void
943 HistorySvc::handle(const Incident& incident) {
944 
945  if (incident.type() == IncidentType::BeginEvent) {
946  if (captureState().isFailure()) {
947  m_log << MSG::WARNING << "Error capturing state." << endl
948  << "Will try again at next BeginEvent incident" << endmsg;
949  }
950  }
951 
952 }
953 
954 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
955 
956 
958 HistorySvc::dumpProp(const Property* prop, bool isXML, int ind) const {
959  std::ostringstream ost;
960  if (isXML) {
961  while (ind > 0) {
962  ost << " ";
963  ind --;
964  }
965  ost << "<PROPERTY name=\"" << prop->name()
966  << "\" value=\"" << HistoryObj::convert_string(prop->toString())
967  << "\" documentation=\"" << HistoryObj::convert_string(prop->documentation())
968  << "\">";
969  } else {
970  prop->fillStream(ost);
971  }
972  return ost.str();
973 }
974 
975 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
976 
977 void
979 
980 
981  if(m_outputFileTypeXML) {
982  //xml header
983  ofs << "<?xml version=\"1.0\" ?> " << std::endl;
984  ofs << "<!--Test-xml-->" << std::endl;
985  ofs << "<SETUP>" << std::endl;
986  ofs << " <GLOBAL>" << std::endl;
987  } else {
988  ofs << "GLOBAL" << std::endl;
989  }
990 
993  std::string client_currently_open = "start";
994  for (itrj=props.begin(); itrj != props.end(); ++itrj) {
995  // client is the name of the component of the current property
996  std::string client = itrj->first;
997  const Property* prp = itrj->second;
998 
999  if (m_outputFileTypeXML) {
1000 
1001  if (client != client_currently_open) {
1002  if(client_currently_open!="start") ofs << " </COMPONENT>" << endl;
1003  ofs << " <COMPONENT name=\""
1004  << client << "\" class=\"undefined\">" << std::endl;
1005  }
1006  } else {
1007  ofs << client << " ";
1008  }
1009 
1010  ofs << dumpProp(prp,m_outputFileTypeXML,6) << endl;
1011 
1012  client_currently_open = client;
1013  }
1014 
1015  if (m_outputFileTypeXML)
1016  ofs << " </COMPONENT>" << endl;
1017 
1018  if(m_outputFileTypeXML) {
1019  ofs << "</GLOBAL>" << endl << "<SERVICES>" << endl;
1020  } else {
1021  ofs << "SERVICES" << std::endl;
1022  }
1023 
1025  for (itr_s=m_svcmap.begin(); itr_s != m_svcmap.end(); ++itr_s) {
1026  const IService* svc = itr_s->first;
1027 
1028  dumpState(svc,ofs);
1029 
1030  }
1031 
1032  if(m_outputFileTypeXML) {
1033  ofs << "</SERVICES>" << endl << "<ALGORITHMS> " << endl;
1034  } else {
1035  ofs << "ALGORITHMS" << std::endl;
1036  }
1037 
1039  for (itr=m_algmap.begin(); itr != m_algmap.end(); ++itr) {
1040  const Algorithm* alg = itr->first;
1041 
1042  dumpState(alg,ofs);
1043 
1044  }
1045 
1046 
1047  if(m_outputFileTypeXML) {
1048  ofs << "</ALGORITHMS>" << endl << "<ALGTOOLS> " << endl;
1049  } else {
1050  ofs << "ALGTOOLS" << std::endl;
1051  }
1052 
1054  for (itr_a=m_algtoolmap.begin(); itr_a != m_algtoolmap.end(); ++itr_a) {
1055  const AlgTool* alg = itr_a->first;
1056 
1057  dumpState( alg, ofs);
1058 
1059  }
1060 
1061  if(m_outputFileTypeXML) {
1062  ofs << "</ALGTOOLS>" << endl << "</SETUP>" << endl;
1063  }
1064 
1065 }
1066 
1067 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1068 
1069 void
1071 
1072  HistoryObj *hist(0);
1073  IVersHistoryObj *vhist(0);
1074 
1075  const IService* is(0);
1076  const Algorithm* ia(0);
1077  const IAlgTool* it(0);
1078  if ( (is=dynamic_cast<const IService*>(in)) != 0) {
1079 // m_log << MSG::DEBUG << in->name() << " is Service" << endmsg;
1080  hist = getServiceHistory( *is );
1081  } else if ( (ia = dynamic_cast<const Algorithm*>(in)) != 0 ) {
1082 // m_log << MSG::DEBUG << in->name() << " is Alg" << endmsg;
1083  hist = getAlgHistory( *ia );
1084  } else if ( (it = dynamic_cast<const IAlgTool*>(in)) != 0 ) {
1085 // m_log << MSG::DEBUG << in->name() << " is AlgTool" << endmsg;
1086  hist = getAlgToolHistory( *it );
1087  } else {
1088  m_log << MSG::ERROR
1089  << "Could not dcast interface to accepted History Obj type for "
1090  << in->name() << endmsg;
1091  return;
1092  }
1093 
1094  if (hist == 0) { return; }
1095 
1096  vhist = dynamic_cast<IVersHistoryObj*>(hist);
1097 
1098  if (!vhist) {
1099  warning() << "Failed to dynamic cast IVersHistoryObj for " << in->name() << endmsg;
1100  return;
1101  }
1102 
1103  if (m_outputFileTypeXML) {
1104  hist->dump(ofs,true);
1105  } else {
1106  ofs << ">> " << vhist->name() << endl << *hist << endl;
1107  }
1108 
1109 }

Generated at Wed Jan 30 2013 17:13:41 for Gaudi Framework, version v23r6 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004