| The Gaudi Framework v32r1 (f65d50dc)

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