| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

HistorySvc.cpp
Go to the documentation of this file.
1 #include "HistorySvc.h"
2
3 #include <functional>
4
5 #include "GaudiKernel/HistoryObj.h"
6 #include "GaudiKernel/IVersHistoryObj.h"
7
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"
13
14 #include "GaudiKernel/ISvcLocator.h"
15
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"
29
30 #include "GaudiKernel/IAlgContextSvc.h"
31
32 #include "boost/algorithm/string/predicate.hpp"
33 namespace ba = boost::algorithm;
34
35 #include <iostream>
36 #include <fstream>
37 #include <sstream>
38 #include <limits>
39
40 #define ON_DEBUG if (msgLevel(MSG::DEBUG))
41 #define ON_VERBOSE if (msgLevel(MSG::VERBOSE))
42
43 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
44 DECLARE_COMPONENT(HistorySvc)
45
46 using namespace std;
47
48 //
50 //
51
52 namespace {
53 template <typename MAP, typename SET>
54 inline void map_to_set(const MAP& m, SET& s) {
55 std::transform(std::begin(m), std::end(m),
56 std::inserter(s, s.begin()),
57 std::mem_fn(&MAP::value_type::second));
58 }
59 }
60
61 struct DHH {
62 CLID id;
63 std::string key;
64
65 DHH(const CLID& i, std::string k):id(i), key(std::move(k)) {}
66
67 bool operator < ( DHH const &rhs ) const {
68 if (id != rhs.id) {
69 return (id < rhs.id);
70 } else {
71 return (key < rhs.key);
72 }
73 }
74 };
75
76 HistorySvc::HistorySvc( const std::string& name, ISvcLocator* svc )
77 : base_class( name, svc ),
78 m_log(msgSvc(), name )
79 {
80 declareProperty("Dump",m_dump);
81 declareProperty("Activate", m_activate=true);
82 declareProperty("OutputFile",m_outputFile);
83
84 // hack to bring in environ
85 vector<string> envtmp = System::getEnv();
86 envtmp.size(); // prevent icc remark #177: X declared but never referenced
87 }
88
89 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
90
91 StatusCode HistorySvc::reinitialize() {
92
93 clearState();
94 m_state = Gaudi::StateMachine::OFFLINE;
95 return initialize();
96
97 }
98
99 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
100
101 namespace {
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();
106 delete p.second;
107 }
108 } clear_{};
109 template<typename M>
110 void clear(M& m) {
111 std::for_each(std::begin(m), std::end(m), clear_ );
112 m.clear();
113 }
114 }
115 void HistorySvc::clearState() {
116 clear(m_algmap);
117
118 m_ialgtools.clear();
119 clear(m_algtoolmap);
120
121 clear(m_svcmap);
122 }
123
124
125 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
126
127 StatusCode HistorySvc::initialize() {
128
129 StatusCode status = Service::initialize();
130 m_log.setLevel( m_outputLevel.value() );
131
132 if (status.isFailure()) {
133
134 ON_DEBUG
135 m_log << MSG::DEBUG << "Failed to initialize the base class (Service)"
136 << endmsg;
137 return status;
138 }
139
140 ON_DEBUG
141 m_log << MSG::DEBUG << "Initializing HistorySvc" << endmsg;
142
143 if (!m_activate) return StatusCode::SUCCESS;
144
145 static const bool CREATEIF(true);
146
147 if ( service("AlgContextSvc",p_algCtxSvc,CREATEIF).isFailure() ) {
148 m_log << MSG::ERROR << "unable to get the AlgContextSvc" << endmsg;
149 return StatusCode::FAILURE;
150 }
151
152 if (service("IncidentSvc", m_incidentSvc, CREATEIF).isFailure()) {
153 m_log << MSG::ERROR << "unable to get the IncidentSvc" << endmsg;
154 return StatusCode::FAILURE;
155 }
156
157 // create a weak dependency on the ToolSvc, so that it doesn't get deleted
158 // before we're done with it in finalize
159 m_toolSvc = serviceLocator()->service("ToolSvc");
160 if (! m_toolSvc) {
161 m_log << MSG::ERROR << "could not retrieve the ToolSvc handle !"
162 << endmsg;
163 return StatusCode::FAILURE;
164 }
165
166 // add listener to be triggered by first BeginEvent with low priority
167 // so it gets called first
168 const bool rethrow = false;
169 const bool oneShot = true; // make the listener called only once
170 m_incidentSvc->addListener(this,IncidentType::BeginEvent,
171 std::numeric_limits<long>::min(),rethrow,oneShot);
172
173 m_outputFileTypeXML = ba::iends_with( m_outputFile, ".xml");
174 ON_DEBUG if (m_outputFileTypeXML ) {
175 m_log << MSG::DEBUG << "output format is XML" << endmsg;
176 }
177
178 m_isInitialized = true;
179
180 return StatusCode::SUCCESS;
181 }
182 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
183
184 StatusCode HistorySvc::captureState() {
185
186 if (!m_jobHistory ) {
187 m_jobHistory.reset( new JobHistory );
188 IJobOptionsSvc *jo;
189 if (service("JobOptionsSvc",jo).isFailure()) {
190 m_log << MSG::ERROR
191 << "Could not get jobOptionsSvc - "
192 << "not adding properties to JobHistory" << endmsg;
193 } else {
194
195 bool foundAppMgr(false);
196
197 for (auto& client: jo->getClients()) {
198 if (client == "ApplicationMgr") foundAppMgr = true;
199 for (auto prop: *jo->getProperties(client)) {
200 m_jobHistory->addProperty(client, prop);
201 }
202 }
203
204 if (!foundAppMgr) {
205 auto ap = service<IProperty>("ApplicationMgr");
206 if (!ap) {
207 m_log << MSG::ERROR << "could not get the ApplicationMgr" << endmsg;
208 } else {
209 for (auto prop: ap->getProperties()) {
210 m_jobHistory->addProperty("ApplicationMgr", prop);
211 }
212 }
213 }
214
215 }
216 }
217
219
220 auto algMgr = Gaudi::svcLocator()->as<IAlgManager>();
221 if ( !algMgr ) {
222 m_log << MSG::ERROR << "Could not get AlgManager" << endmsg;
223 return StatusCode::FAILURE;
224 }
225
226 size_t count = 0;
227 for (auto ialg: algMgr->getAlgorithms()) {
228 Algorithm* alg = dynamic_cast<Algorithm*>(ialg);
229 if ( !alg ) {
230 m_log << MSG::WARNING << "Algorithm " << ialg->name()
231 << " does not inherit from Algorithm. Not registering it."
232 << endmsg;
233 } else {
234 ++count;
235 registerAlg( *alg ).ignore();
236 }
237 }
238
239 m_log << MSG::INFO << "Registered " << count << " Algorithms" << endmsg;
240
241
242
244
245 m_isInitialized = true;
246 for (auto algtool: m_ialgtools) {
247 (const_cast<IAlgTool*>(algtool))->addRef();
248 registerAlgTool(*algtool).ignore();
249 }
250
251 m_log << MSG::INFO << "Registered " << m_algtoolmap.size() << " AlgTools"
252 << endmsg;
253
255
256 for (auto svc: Gaudi::svcLocator()->getServices()) {
257 svc->addRef();
258 registerSvc(*svc).ignore();
259 }
260
261 m_log << MSG::INFO;
262 m_log << "Registered " << Gaudi::svcLocator()->getServices().size() << " Services" << endmsg;
263
264 return StatusCode::SUCCESS;
265
266
267 }
268
269 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
270
271 StatusCode HistorySvc::stop() {
272
273 if (!m_activate) return StatusCode::SUCCESS;
274
275 if (m_dump) {
276 listProperties().ignore();
277 }
278
279 if (!m_outputFile.empty()) {
280 std::ofstream ofs(m_outputFile);
281 if (!ofs) {
282 m_log << MSG::ERROR << "Unable to open output file \"m_outputFile\""
283 << endmsg;
284 } else {
285 // dumpProperties(ofs);
286 dumpState(ofs);
287 }
288 }
289
290 clearState();
291
292 return StatusCode::SUCCESS;
293
294 }
295
296 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
297
298 StatusCode HistorySvc::finalize() {
299
300 ON_VERBOSE
301 m_log << MSG::VERBOSE << "HistorySvc::finalize()" << endmsg;
302
303 clearState();
304
305 StatusCode status = Service::finalize();
306
307 if ( status.isSuccess() )
308 m_log << MSG::INFO << "Service finalised successfully" << endmsg;
309
310 return status;
311
312 }
313
314 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
315
316 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
317 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
318
319 StatusCode
320 HistorySvc::registerAlg(const Algorithm &alg) {
321
322 JobHistory *job = getJobHistory();
323 if (m_algmap.find(&alg) != m_algmap.end()) {
324 m_log << MSG::WARNING << "Algorithm " << alg.name()
325 << " already registered with HistorySvc" << endmsg;
326 return StatusCode::SUCCESS;
327 }
328
329 (const_cast<Algorithm*>(&alg))->addRef();
330
331 m_algmap[&alg] = new AlgorithmHistory(alg, job);
332
333 ON_DEBUG {
334 m_log << MSG::DEBUG << "Registering algorithm: ";
335 m_log.setColor(MSG::CYAN);
336 m_log << alg.name() << endmsg;
337 m_log.resetColor();
338 }
339
340 return StatusCode(StatusCode::SUCCESS,true);
341
342 }
343 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
344
345 StatusCode
346 HistorySvc::listProperties(const Algorithm &alg) const {
347
348 m_log << MSG::INFO << "Dumping properties for " << alg.name() << endl;
349
350 AlgorithmHistory *hist = getAlgHistory( alg );
351
352 if ( !hist ) {
353 return StatusCode::FAILURE;
354 }
355
356 m_log << MSG::INFO << alg.name() << " --> " << endl << *hist << endmsg;
357
358 return StatusCode(StatusCode::SUCCESS,true);
359
360 }
361 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
362
363 void
364 HistorySvc::dumpProperties(const Algorithm &alg, std::ofstream& ofs) const {
365
366 AlgorithmHistory *hist = getAlgHistory( alg );
367
368 if ( !hist ) {
369 return;
370 }
371
372 PropertyList::const_iterator itr;
373 for (auto prop: hist->properties()) {
374 ofs << alg.name() << " " << dumpProp(prop) << std::endl;
375 }
376
377 }
378 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
379
380 AlgorithmHistory*
381 HistorySvc::getAlgHistory(const Algorithm &alg) const {
382
383 auto itr = m_algmap.find( &alg );
384 if ( itr == m_algmap.end() ) {
385 m_log << MSG::WARNING << "Algorithm " << alg.name() << " not registered"
386 << endmsg;
387 return nullptr;
388 }
389 return itr->second;
390 }
391 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
392
393 void
394 HistorySvc::getAlgHistory(std::set<AlgorithmHistory*>& algs) const {
395 map_to_set(m_algmap, algs);
396 }
397
398
399 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
400 StatusCode
401 HistorySvc::registerJob() {
402
403
404 return StatusCode(StatusCode::SUCCESS,true);
405
406
407 }
408 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
409
410
411 StatusCode
412 HistorySvc::listProperties() const {
413
414 m_log << MSG::INFO;
415 m_log.setColor(MSG::CYAN);
416 m_log << "Dumping properties for all Algorithms (" << m_algmap.size()
417 << ")" << endmsg;
418
419 for (auto& alg: m_algmap) {
420 listProperties(*alg.first).ignore();
421 }
422
423 m_log << MSG::INFO;
424 m_log.setColor(MSG::CYAN);
425 m_log << "Dumping properties for all AlgTools (" << m_algtoolmap.size()
426 << ")" << endmsg;
427
428 for (auto& algtool: m_algtoolmap) {
429 ON_DEBUG
430 m_log << MSG::DEBUG << " --> " << algtool.second->algtool_name() << endmsg;
431 listProperties(*algtool.first).ignore();
432 }
433
434 m_log << MSG::INFO;
435 m_log.setColor(MSG::CYAN);
436 m_log << "Dumping properties for all Services (" << m_svcmap.size()
437 << ")" << endmsg;
438
439 for (auto& svc: m_svcmap) {
440 listProperties(*svc.first).ignore();
441 }
442
443 m_log << MSG::INFO;
444 m_log.setColor(MSG::CYAN);
445 m_log << "Dumping properties for Job";
446 m_log.resetColor();
447
448 m_log << std::endl << *m_jobHistory << endmsg;
449
450 return StatusCode(StatusCode::SUCCESS,true);
451
452 }
453 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
454
455 void
456 HistorySvc::dumpProperties(std::ofstream& ofs) const {
457
458 ofs << "GLOBAL" << std::endl;
459 for (const auto & prop : m_jobHistory->propertyPairs() ) {
460 ofs << prop.first << " " << dumpProp(prop.second) << std::endl;
461 }
462
463 ofs << std::endl << "SERVICES" << std::endl;
464 for (const auto &s : m_svcmap ) dumpProperties( *s.first, ofs );
465
466 ofs << std::endl << "ALGORITHMS" << std::endl;
467 for (const auto & alg : m_algmap ) dumpProperties( *alg.first, ofs );
468
469 ofs << std::endl << "ALGTOOLS" << std::endl;
470 for (const auto& tool : m_algtoolmap ) dumpProperties( *tool.first, ofs );
471
472 }
473 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
474
475 JobHistory*
476 HistorySvc::getJobHistory() const {
477
478 return m_jobHistory.get();
479
480 }
481
482 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
483 IAlgorithm*
484 HistorySvc::getCurrentIAlg() const {
485 if ( p_algCtxSvc ) return p_algCtxSvc->currentAlg();
486 m_log << MSG::WARNING << "trying to create DataHistoryObj before "
487 << "HistorySvc has been initialized" << endmsg;
488 return nullptr;
489 }
490
491
492 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
493
494 DataHistory*
495 HistorySvc::createDataHistoryObj(const CLID& id, const std::string& key,
496 const std::string& /* storeName */) {
497
498 if (!m_activate) return nullptr;
499
500
501 AlgorithmHistory *algHist = nullptr;
502
503 IAlgorithm* ialg = getCurrentIAlg();
504 if ( !ialg ) {
505 ON_DEBUG
506 m_log << MSG::DEBUG
507 << "Could not discover current Algorithm:" << endl
508 << " object CLID: " << id << " key: \"" << key
509 << "\"" << endmsg;
510 algHist = nullptr;
511 } else {
512 Algorithm* alg = dynamic_cast<Algorithm*>(ialg);
513 if ( alg ) {
514 algHist = getAlgHistory( *alg );
515 } else {
516 m_log << MSG::WARNING
517 << "Could not extract concrete Algorithm:"
518 << endl
519 << " object CLID: " << id << " key: \"" << key
520 << "\"" << endmsg;
521 algHist = nullptr;
522 }
523 }
524 return new DataHistory(id, key, algHist);
525 }
526
527 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
528 StatusCode
529 HistorySvc::registerDataHistory(const CLID& id, const std::string& key,
530 const std::string& storeName) {
531
532 DHH dhh(id,key);
533
534 auto boundaries = m_datMap.equal_range(dhh);
535 auto match = boundaries.second;
536
537 if (boundaries.first != boundaries.second) {
538 // there is something in the map, let's look for the specific entry
539
540 std::string algName;
541 IAlgorithm *ialg = getCurrentIAlg();
542 if (ialg) {
543 algName = ialg->name();
544 } else {
545 algName = "UNKNOWN";
546 }
547
548 match = std::find_if(boundaries.first, boundaries.second,
549 [&algName](decltype(boundaries)::first_type::reference p) -> bool {
550 return p.second->algorithmHistory()->algorithm_name() == algName;
551 });
552 }
553
554 if (match == boundaries.second) { // not found, crete the entry
555 DataHistory *dh = createDataHistoryObj(id, key, storeName);
556 m_datMap.insert(pair<DHH, DataHistory*>(dhh,dh));
557 }
558
559 return StatusCode::SUCCESS;
560
561 }
562
563
564 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
565 DataHistory*
566 HistorySvc::getDataHistory(const CLID& id, const std::string& key,
567 const std::string& /*storeName*/) const {
568
569 DHH dhh(id,key);
570
571 auto mitr = m_datMap.equal_range(dhh);
572 return (mitr.first != mitr.second) ? mitr.first->second
573 : nullptr ;
574
575 }
576
577 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
578
579 int
580 HistorySvc::getDataHistory(const CLID& id, const std::string& key,
581 const std::string& /*storeName*/,
582 std::list<DataHistory*>& dhlist) const {
583
584 DHH dhh(id,key);
585
586 int n(0);
587
588 auto mitr = m_datMap.equal_range(dhh);
589 for (auto itr=mitr.first; itr != mitr.second; ++itr) {
590 dhlist.push_back(itr->second);
591 ++n;
592 }
593 return n;
594
595 }
596
597 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
598
599 StatusCode
600 HistorySvc::registerSvc(const IService &svc) {
601
602 if ( svc.name() == "HistoryStore" ) {
603 // m_log << MSG::WARNING << "not registering store" << endmsg;
604 return StatusCode(StatusCode::SUCCESS,true);
605 }
606
607 JobHistory *job = getJobHistory();
608 const IService* psvc = &svc;
609 auto itr = m_svcmap.find(psvc);
610 if (itr == m_svcmap.end()) {
611
612 if (m_log.level() <= MSG::DEBUG) {
613 m_log << MSG::DEBUG << "Registering Service: ";
614 m_log.setColor(MSG::CYAN);
615 m_log << svc.name() << endmsg;
616 }
617
618 m_svcmap[psvc] = new ServiceHistory(&svc, job);
619
620 (const_cast<IService*>(psvc))->addRef();
621
622 }
623
624 m_log.resetColor();
625 return StatusCode(StatusCode::SUCCESS,true);
626
627 }
628
629 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
630
631 ServiceHistory*
632 HistorySvc::getServiceHistory(const IService &svc) const {
633
634 const IService *psvc = &svc;
635 auto itr = m_svcmap.find(psvc);
636 if ( itr != m_svcmap.end() ) return itr->second;
637
638 m_log << MSG::WARNING << "Service " << svc.name() << " not registered"
639 << endmsg;
640 return nullptr;
641 }
642 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
643
644 void
645 HistorySvc::getServiceHistory(std::set<ServiceHistory*>& svcs) const {
646 map_to_set(m_svcmap, svcs);
647 }
648
649 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
650
651 StatusCode
652 HistorySvc::listProperties(const IService &svc) const {
653
654 m_log << MSG::INFO << "Dumping properties for " << svc.name() << endl;
655
656 ServiceHistory *hist = getServiceHistory( svc );
657
658 if ( !hist ) return StatusCode::FAILURE;
659
660 m_log << MSG::INFO << svc.name() << " --> " << endl << *hist << endmsg;
661
662 return StatusCode(StatusCode::SUCCESS,true);
663
664 }
665
666 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
667
668 void
669 HistorySvc::dumpProperties(const IService &svc, std::ofstream &ofs) const {
670
671 ServiceHistory *hist = getServiceHistory( svc );
672
673 if ( !hist ) return;
674
675 for (auto &prop: hist->properties()) {
676 ofs << svc.name() << " " << dumpProp(prop) << std::endl;
677 }
678
679 }
680
681 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
682
683 StatusCode
684 HistorySvc::registerAlgTool(const IAlgTool& ialg) {
685
686 if (! m_isInitialized) {
687 if ( !p_algCtxSvc ) {
688 if ( service("AlgContextSvc",p_algCtxSvc,true).isFailure() ) {
689 m_log << MSG::ERROR << "unable to get the AlgContextSvc" << endmsg;
690 return StatusCode::FAILURE;
691 }
692 }
693 m_ialgtools.insert(&ialg);
694 return StatusCode::SUCCESS;
695 }
696
697 const AlgTool *alg = dynamic_cast<const AlgTool*>( &ialg );
698 if ( !alg ) {
699 m_log << MSG::ERROR << "Could not dcast IAlgTool \"" << ialg.name()
700 << "\" to an AlgTool" << endmsg;
701 return StatusCode::FAILURE;
702 }
703
704 if (m_algtoolmap.find(alg) != m_algtoolmap.end()) {
705 m_log << MSG::WARNING << "AlgTool " << ialg.name()
706 << " already registered in HistorySvc" << endmsg;
707 return StatusCode::SUCCESS;
708 }
709
710 const JobHistory *job = getJobHistory();
711 m_algtoolmap[alg] = new AlgToolHistory(*alg, job);
712
713 if (m_log.level() <= MSG::DEBUG) {
714 m_log << MSG::DEBUG << "Registering algtool: ";
715 m_log.setColor(MSG::CYAN);
716 m_log << alg->name() << endmsg;
717 m_log.resetColor();
718 }
719
720 return StatusCode::SUCCESS;
721
722 }
723
724 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
725
726 StatusCode
727 HistorySvc::listProperties(const IAlgTool& alg) const {
728
729 m_log << MSG::INFO << "Dumping properties for " << alg.name() << endl;
730
731 AlgToolHistory *hist = getAlgToolHistory( alg );
732
733 if ( !hist ) return StatusCode::FAILURE;
734
735
736 m_log << MSG::INFO << alg.name() << " --> " << endl << *hist << endmsg;
737
738 return StatusCode::SUCCESS;
739
740 }
741 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
742
743 void
744 HistorySvc::dumpProperties(const IAlgTool& alg, std::ofstream &ofs) const {
745
746 AlgToolHistory *hist = getAlgToolHistory( alg );
747
748 if ( !hist ) return;
749
750 for (auto& prop: hist->properties()) {
751 ofs << alg.name() << " " << dumpProp(prop) << std::endl;
752 }
753
754 }
755
756 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
757
758 AlgToolHistory*
759 HistorySvc::getAlgToolHistory(const IAlgTool& alg) const {
760
761 const AlgTool *palg = dynamic_cast<const AlgTool*>(&alg);
762 auto itr = m_algtoolmap.find(palg);
763 if ( itr == m_algtoolmap.end() ) {
764 m_log << MSG::WARNING << "AlgTool " << alg.name() << " not registered"
765 << endmsg;
766 return nullptr;
767 }
768 return itr->second;
769
770 }
771
772 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
773
774 void
775 HistorySvc::getAlgToolHistory(std::set<AlgToolHistory*>& algs) const {
776 map_to_set(m_algtoolmap, algs);
777 }
778
779 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
780
781 void
782 HistorySvc::handle(const Incident& incident) {
783
784 if (incident.type() == IncidentType::BeginEvent) {
785 if (captureState().isFailure()) {
786 m_log << MSG::WARNING << "Error capturing state." << endl
787 << "Will try again at next BeginEvent incident" << endmsg;
788 }
789 }
790
791 }
792
793 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
794
795
796 std::string
797 HistorySvc::dumpProp(const Property* prop, bool isXML, int ind) const {
798 std::ostringstream ost;
799 if (isXML) {
800 while (ind > 0) {
801 ost << " ";
802 ind --;
803 }
804 ost << "<PROPERTY name=\"" << prop->name()
805 << "\" value=\"" << HistoryObj::convert_string(prop->toString())
806 << "\" documentation=\"" << HistoryObj::convert_string(prop->documentation())
807 << "\">";
808 } else {
809 prop->fillStream(ost);
810 }
811 return ost.str();
812 }
813
814 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
815
816 void
817 HistorySvc::dumpState(std::ofstream& ofs) const {
818
819
820 if(m_outputFileTypeXML) {
821 //xml header
822 ofs << "<?xml version=\"1.0\" ?> " << std::endl;
823 ofs << "<!--Test-xml-->" << std::endl;
824 ofs << "<SETUP>" << std::endl;
825 ofs << " <GLOBAL>" << std::endl;
826 } else {
827 ofs << "GLOBAL" << std::endl;
828 }
829
830 std::string client_currently_open = "start";
831 for (auto& item: m_jobHistory->propertyPairs()) {
832 // client is the name of the component of the current property
833 const std::string& client = item.first;
834 const Property* prp = item.second;
835
836 if (m_outputFileTypeXML) {
837
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;
842 }
843 } else {
844 ofs << client << " ";
845 }
846
847 ofs << dumpProp(prp,m_outputFileTypeXML,6) << endl;
848
849 client_currently_open = client;
850
851 if (m_outputFileTypeXML)
852 ofs << " </COMPONENT>" << endl;
853 }
854
855
856 if(m_outputFileTypeXML) {
857 ofs << "</GLOBAL>" << endl << "<SERVICES>" << endl;
858 } else {
859 ofs << "SERVICES" << std::endl;
860 }
861
862 for (auto& item: m_svcmap) {
863 const IService* svc = item.first;
864 dumpState(svc, ofs);
865 }
866
867 if(m_outputFileTypeXML) {
868 ofs << "</SERVICES>" << endl << "<ALGORITHMS> " << endl;
869 } else {
870 ofs << "ALGORITHMS" << std::endl;
871 }
872
873 for (auto& item: m_algmap) {
874 const Algorithm* alg = item.first;
875 dumpState(alg, ofs);
876 }
877
878
879 if(m_outputFileTypeXML) {
880 ofs << "</ALGORITHMS>" << endl << "<ALGTOOLS> " << endl;
881 } else {
882 ofs << "ALGTOOLS" << std::endl;
883 }
884
885 for (auto& item: m_algtoolmap) {
886 const AlgTool* algtool = item.first;
887 dumpState(algtool, ofs);
888 }
889
890 if(m_outputFileTypeXML) {
891 ofs << "</ALGTOOLS>" << endl << "</SETUP>" << endl;
892 }
893
894 }
895
896 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
897
898 void
899 HistorySvc::dumpState(const INamedInterface *in, std::ofstream& ofs) const {
900
901 HistoryObj *hist = nullptr;
902 IVersHistoryObj *vhist = nullptr;
903
904 const IService* is = nullptr;
905 const Algorithm* ia = nullptr;
906 const IAlgTool* it = nullptr;
907 if ( (is=dynamic_cast<const IService*>(in)) != nullptr) {
908 ON_VERBOSE
909 m_log << MSG::VERBOSE << in->name() << " is Service" << endmsg;
910 ServiceHistory* o = getServiceHistory( *is );
911 hist = dynamic_cast<HistoryObj*>( o );
912 vhist = dynamic_cast<IVersHistoryObj*>( o );
913 } else if ( (ia = dynamic_cast<const Algorithm*>(in)) != nullptr ) {
914 ON_VERBOSE
915 m_log << MSG::VERBOSE << in->name() << " is Alg" << endmsg;
916 AlgorithmHistory *o = getAlgHistory( *ia );
917 hist = dynamic_cast<HistoryObj*>( o );
918 vhist = dynamic_cast<IVersHistoryObj*>( o );
919 } else if ( (it = dynamic_cast<const IAlgTool*>(in)) != nullptr ) {
920 ON_VERBOSE
921 m_log << MSG::VERBOSE << in->name() << " is AlgTool" << endmsg;
922 AlgToolHistory *o = getAlgToolHistory( *it );
923 hist = dynamic_cast<HistoryObj*>( o );
924 vhist = dynamic_cast<IVersHistoryObj*>( o );
925 } else {
926 m_log << MSG::ERROR
927 << "Could not dcast interface to accepted History Obj type for "
928 << in->name() << endmsg;
929 return;
930 }
931
932 if ( !hist || !vhist ) {
933 m_log << MSG::ERROR << "Could not dcast recognized object to HistoryObj or IVersHistoryObj. This should never happen."
934 << endmsg;
935 return;
936 }
937
938 if (m_outputFileTypeXML) {
939 hist->dump(ofs,true);
940 } else {
941 ofs << ">> " << vhist->name() << endl << *hist << endl;
942 }
943
944 }
System::getEnv
GAUDI_API std::string getEnv(const char *var)
get a particular environment variable (returning "UNKNOWN" if not set)
Definition: System.cpp:617
System.h
HistorySvc::stop
virtual StatusCode stop()
Definition: HistorySvc.cpp:271
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:68
Service::m_outputLevel
IntegerProperty m_outputLevel
Service output level.
Definition: Service.h:309
IJobOptionsSvc::getProperties
virtual const std::vector< const Property * > * getProperties(const std::string &client) const =0
Get the properties associated to a given client.
Algorithm.h
HistorySvc::getServiceHistory
virtual ServiceHistory * getServiceHistory(const IService &) const
Definition: HistorySvc.cpp:632
Service::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:324
std::string::empty
T empty(T...args)
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
Incident::type
const std::string & type() const
Access to the incident type.
Definition: Incident.h:41
Service::m_state
Gaudi::StateMachine::State m_state
Service state.
Definition: Service.h:311
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
HistorySvc::m_toolSvc
SmartIF< IToolSvc > m_toolSvc
Definition: HistorySvc.h:138
MsgStream::resetColor
GAUDI_API void resetColor()
Reset the colors to defaults.
Definition: MsgStream.cpp:108
Service::finalize
StatusCode finalize() override
Definition: Service.cpp:193
Property::toString
virtual std::string toString() const =0
value -> string
HistorySvc.h
MsgStream::level
MSG::Level level()
Retrieve output level.
Definition: MsgStream.h:112
IAppMgrUI.h
Property::name
const std::string & name() const
property name
Definition: Property.h:45
MSG::CYAN
Definition: IMessageSvc.h:33
DHH
Definition: HistorySvc.cpp:61
IAlgorithm.h
DHH::id
CLID id
Definition: HistorySvc.cpp:62
HistoryObj::dump
virtual void dump(std::ostream &, const bool isXML=false, int indent=0) const =0
AlgorithmHistory
AlgorithmHistory class definition.
Definition: AlgorithmHistory.h:27
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
AlgTool.h
HistorySvc::registerDataHistory
virtual StatusCode registerDataHistory(const CLID &id, const std::string &key, const std::string &store)
Definition: HistorySvc.cpp:529
MSG::DEBUG
Definition: IMessageSvc.h:18
std::endl
T endl(T...args)
HistorySvc::listProperties
virtual StatusCode listProperties() const
Definition: HistorySvc.cpp:412
IAlgManager
The IAlgManager is the interface implemented by the Algorithm Factory in the Application Manager to s...
Definition: IAlgManager.h:27
Bootstrap.h
HistorySvc::registerJob
virtual StatusCode registerJob()
Definition: HistorySvc.cpp:401
std
STL namespace.
IJobOptionsSvc::getClients
virtual std::vector< std::string > getClients() const =0
Get the list of clients.
HistoryObj
Base class for History Objects.
Definition: HistoryObj.h:22
HistorySvc
HistorySvc class definition.
Definition: HistorySvc.h:41
std::end
T end(T...args)
DHH::DHH
DHH(const CLID &i, std::string k)
Definition: HistorySvc.cpp:65
HistoryObj.h
DataHistory.h
ISvcLocator::as
SmartIF< IFace > as()
Definition: ISvcLocator.h:106
HistorySvc::m_datMap
std::multimap< DHH, DataHistory * > m_datMap
Definition: HistorySvc.h:116
SET
#define SET(x)
HistorySvc::m_algtoolmap
std::map< const AlgTool *, AlgToolHistory * > m_algtoolmap
Definition: HistorySvc.h:113
MSG::VERBOSE
Definition: IMessageSvc.h:17
DHH::key
std::string key
Definition: HistorySvc.cpp:63
Property::documentation
const std::string & documentation() const
property documentation
Definition: Property.h:47
JobHistory
JobHistory class definition.
Definition: JobHistory.h:24
IToolSvc.h
HistorySvc::m_outputFile
std::string m_outputFile
Definition: HistorySvc.h:122
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
GaudiPluginService.cpluginsvc.n
list n
Definition: cpluginsvc.py:217
Property::fillStream
virtual std::ostream & fillStream(std::ostream &) const
the printout of the property value
Definition: Property.cpp:111
IVersHistoryObj.h
HistorySvc::getCurrentIAlg
IAlgorithm * getCurrentIAlg() const
Definition: HistorySvc.cpp:484
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
Gaudi::Units::second
constexpr double second
Definition: SystemOfUnits.h:122
INamedInterface::name
virtual const std::string & name() const =0
Retrieve the name of the instance.
std::string
STL class.
Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:820
MsgStream::setColor
GAUDI_API void setColor(MSG::Color col)
Set the text color.
Definition: MsgStream.cpp:81
HistorySvc::getAlgToolHistory
virtual AlgToolHistory * getAlgToolHistory(const IAlgTool &) const
Definition: HistorySvc.cpp:759
HistorySvc::handle
virtual void handle(const Incident &inc)
Definition: HistorySvc.cpp:782
HistorySvc::m_activate
bool m_activate
Definition: HistorySvc.h:106
ISvcLocator::service
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:78
std::list::push_back
T push_back(T...args)
std::ofstream
STL class.
JobHistory.h
IJobOptionsSvc
Main interface for the JobOptions service.
Definition: IJobOptionsSvc.h:20
Gaudi::svcLocator
GAUDI_API ISvcLocator * svcLocator()
HistorySvc::m_isInitialized
bool m_isInitialized
Definition: HistorySvc.h:104
StatusCode::FAILURE
Definition: StatusCode.h:29
AlgToolHistory.h
IIncidentSvc.h
IService
General service interface definition.
Definition: IService.h:18
StatusCode::SUCCESS
Definition: StatusCode.h:30
HistorySvc::registerSvc
virtual StatusCode registerSvc(const IService &)
Definition: HistorySvc.cpp:600
ON_DEBUG
#define ON_DEBUG
Definition: HistorySvc.cpp:40
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
HistorySvc::HistorySvc
HistorySvc(const std::string &name, ISvcLocator *svc)
Definition: HistorySvc.cpp:76
Gaudi::Units::m
constexpr double m
Definition: SystemOfUnits.h:93
std::ostringstream
STL class.
HistorySvc::m_outputFileTypeXML
bool m_outputFileTypeXML
Definition: HistorySvc.h:141
HistorySvc::registerAlgTool
virtual StatusCode registerAlgTool(const IAlgTool &)
Definition: HistorySvc.cpp:684
DataHistory
DataHistory class definition.
Definition: DataHistory.h:23
HistorySvc::p_algCtxSvc
IAlgContextSvc * p_algCtxSvc
Definition: HistorySvc.h:108
IAlgTool.h
HistorySvc::registerAlg
virtual StatusCode registerAlg(const Algorithm &)
Definition: HistorySvc.cpp:320
HistorySvc::initialize
virtual StatusCode initialize()
Definition: HistorySvc.cpp:127
std::ostringstream::str
T str(T...args)
HistorySvc::getAlgHistory
virtual AlgorithmHistory * getAlgHistory(const Algorithm &) const
Definition: HistorySvc.cpp:381
HistorySvc::finalize
virtual StatusCode finalize()
Definition: HistorySvc.cpp:298
std::unique_ptr::reset
T reset(T...args)
AlgToolHistory::properties
const PropertyList & properties() const
Definition: AlgToolHistory.h:75
CLID
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
std::set::clear
T clear(T...args)
JobHistory::addProperty
void addProperty(const std::string &, const Property *)
Definition: JobHistory.cpp:84
std::list
STL class.
ServiceHandle.h
IAlgorithm
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:25
HistorySvc::m_log
MsgStream m_log
Definition: HistorySvc.h:140
std::move
T move(T...args)
PropertyWithValue::value
const TYPE & value() const
explicit conversion
Definition: Property.h:341
IService.h
JobHistory::propertyPairs
const PropertyPairList & propertyPairs() const
Definition: JobHistory.h:79
std::count
T count(T...args)
HistorySvc::dumpProp
std::string dumpProp(const Property *, const bool isXML=false, int indent=0) const
Definition: HistorySvc.cpp:797
std::pair
AlgToolHistory
AlgToolHistory class definition.
Definition: AlgToolHistory.h:22
HistorySvc::dumpState
void dumpState(std::ofstream &) const
Definition: HistorySvc.cpp:817
AlgorithmHistory::properties
const PropertyList & properties() const
Definition: AlgorithmHistory.h:88
std::unique_ptr::get
T get(T...args)
HistorySvc::m_incidentSvc
IIncidentSvc * m_incidentSvc
Definition: HistorySvc.h:137
std::multimap::insert
T insert(T...args)
HistorySvc::createDataHistoryObj
virtual DataHistory * createDataHistoryObj(const CLID &id, const std::string &key, const std::string &store)
Definition: HistorySvc.cpp:495
IAlgContextSvc.h
Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:74
INamedInterface
IInterface compliant class extending IInterface with the name() method.
Definition: INamedInterface.h:15
std::map::find
T find(T...args)
std::vector::size
T size(T...args)
std::set
STL class.
DHH::operator<
bool operator<(DHH const &rhs) const
Definition: HistorySvc.cpp:67
Property
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
std::vector
STL class.
HistorySvc::getDataHistory
virtual DataHistory * getDataHistory(const CLID &id, const std::string &key, const std::string &store) const
Definition: HistorySvc.cpp:566
ServiceHistory::properties
const PropertyList & properties() const
Definition: ServiceHistory.h:36
HistorySvc::dumpProperties
void dumpProperties(std::ofstream &) const
Definition: HistorySvc.cpp:456
std::begin
T begin(T...args)
HistoryObj::convert_string
static std::string convert_string(const std::string &)
Definition: HistoryObj.cpp:21
Incident
Base class for all Incidents (computing events).
Definition: Incident.h:17
AlgTool
Base class from which all the concrete tool classes should be derived.
Definition: AlgTool.h:45
IAlgTool
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
IIncidentSvc::addListener
virtual void addListener(IIncidentListener *lis, const std::string &type="", long priority=0, bool rethrow=false, bool singleShot=false)=0
Add listener.
MsgStream::setLevel
void setLevel(int level)
Update outputlevel.
Definition: MsgStream.h:106
gaudirun.s
string s
Definition: gaudirun.py:245
ana.item
tuple item
print s1,s2
Definition: ana.py:146
CommonMessaging
Definition: CommonMessaging.h:58
ServiceHistory
ServiceHistory class definition.
Definition: ServiceHistory.h:22
IVersHistoryObj::name
virtual const std::string & name() const =0
HistorySvc::m_algmap
std::map< const Algorithm *, AlgorithmHistory * > m_algmap
Definition: HistorySvc.h:110
MSG::ERROR
Definition: IMessageSvc.h:21
IAlgManager.h
HistorySvc::m_dump
bool m_dump
Definition: HistorySvc.h:105
ON_VERBOSE
#define ON_VERBOSE
Definition: HistorySvc.cpp:41
Service::service
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.
Definition: Service.h:144
ISvcLocator::getServices
virtual const std::list< IService * > & getServices() const =0
Get a reference to a service and create it if it does not exists.
std::transform
T transform(T...args)
std::mem_fn
T mem_fn(T...args)
MSG::WARNING
Definition: IMessageSvc.h:20
HistorySvc::m_ialgtools
std::set< const IAlgTool * > m_ialgtools
Definition: HistorySvc.h:112
StatusCode::ignore
void ignore() const
Definition: StatusCode.h:108
Service::declareProperty
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Service.h:215
IVersHistoryObj
Interface for Versioned History Objects.
Definition: IVersHistoryObj.h:18
std::inserter
T inserter(T...args)
MSG::INFO
Definition: IMessageSvc.h:19
Gaudi::StateMachine::OFFLINE
Definition: StateMachine.h:13
std::for_each
T for_each(T...args)
ServiceHistory.h
IAlgContextSvc::currentAlg
virtual IAlgorithm * currentAlg() const =0
accessor to current algorithm:
HistorySvc::clearState
void clearState()
Definition: HistorySvc.cpp:115
ana.i
list i
Definition: ana.py:128
AlgTool::name
const std::string & name() const override
Retrieve full identifying name of the concrete tool object.
Definition: AlgTool.cpp:65
ISvcLocator.h
HistorySvc::captureState
virtual StatusCode captureState()
Definition: HistorySvc.cpp:184
Objects::reference
TO * reference(FROM *from)
Definition: KeyedObject.cpp:20
std::multimap::equal_range
T equal_range(T...args)
AlgorithmHistory.h
HistorySvc::m_svcmap
std::map< const IService *, ServiceHistory * > m_svcmap
Definition: HistorySvc.h:114
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
HistorySvc::reinitialize
virtual StatusCode reinitialize()
Definition: HistorySvc.cpp:91
HistorySvc::getJobHistory
virtual JobHistory * getJobHistory() const
Definition: HistorySvc.cpp:476
ForwardSchedulerSimpleTest.msgSvc
tuple msgSvc
Definition: ForwardSchedulerSimpleTest.py:112
HistorySvc::m_jobHistory
std::unique_ptr< JobHistory > m_jobHistory
Definition: HistorySvc.h:120
std::numeric_limits
IJobOptionsSvc.h