Gaudi Framework, version v24r2

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

Generated at Wed Dec 4 2013 14:33:10 for Gaudi Framework, version v24r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004