The Gaudi Framework  v31r0 (aeb156f0)
HistorySvc.cpp
Go to the documentation of this file.
1 #include "HistorySvc.h"
2 
3 #include <functional>
4 
7 
11 #include "GaudiKernel/JobHistory.h"
13 
15 
16 #include "GaudiKernel/AlgTool.h"
17 #include "GaudiKernel/Bootstrap.h"
19 #include "GaudiKernel/IAlgTool.h"
20 #include "GaudiKernel/IAlgorithm.h"
21 #include "GaudiKernel/IAppMgrUI.h"
24 #include "GaudiKernel/IService.h"
25 #include "GaudiKernel/IToolSvc.h"
27 #include "GaudiKernel/System.h"
28 #include <Gaudi/Algorithm.h>
29 
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 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
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() ),
57  }
58 } // namespace
59 
60 struct DHH {
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 
78 
79  clearState();
81  return initialize();
82 }
83 
84 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
85 
86 namespace {
87  constexpr struct clear_t {
88  template <typename T1, typename T2>
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
101  clear( m_algmap );
102 
103  m_ialgtools.clear();
104  clear( m_algtoolmap );
105 
106  clear( m_svcmap );
107 }
108 
109 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
110 
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 
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 
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 
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 
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 
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 
315 
316  AlgorithmHistory* hist = getAlgHistory( alg );
317 
318  if ( !hist ) { return; }
319 
320  PropertyList::const_iterator itr;
321  for ( auto prop : hist->properties() ) { ofs << alg.name() << " " << dumpProp( prop ) << std::endl; }
322 }
323 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
324 
326 
327  auto itr = m_algmap.find( &alg );
328  if ( itr == m_algmap.end() ) {
329  warning() << "Algorithm " << alg.name() << " not registered" << endmsg;
330  return nullptr;
331  }
332  return itr->second;
333 }
334 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
335 
336 void HistorySvc::getAlgHistory( std::set<AlgorithmHistory*>& algs ) const { map_to_set( m_algmap, algs ); }
337 
338 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
340 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
341 
343 
344  auto& log = info();
345 
346  log.setColor( MSG::CYAN );
347  log << "Dumping properties for all Algorithms (" << m_algmap.size() << ")" << endmsg;
348 
349  for ( auto& alg : m_algmap ) { listProperties( *alg.first ).ignore(); }
350 
351  log << MSG::INFO;
352  log.setColor( MSG::CYAN );
353  log << "Dumping properties for all AlgTools (" << m_algtoolmap.size() << ")" << endmsg;
354 
355  for ( auto& algtool : m_algtoolmap ) {
356  ON_DEBUG
357  debug() << " --> " << algtool.second->algtool_name() << endmsg;
358  listProperties( *algtool.first ).ignore();
359  }
360 
361  log << MSG::INFO;
362  log.setColor( MSG::CYAN );
363  log << "Dumping properties for all Services (" << m_svcmap.size() << ")" << endmsg;
364 
365  for ( auto& svc : m_svcmap ) { listProperties( *svc.first ).ignore(); }
366 
367  log << MSG::INFO;
368  log.setColor( MSG::CYAN );
369  log << "Dumping properties for Job";
370  log.resetColor();
371 
372  log << std::endl << *m_jobHistory << endmsg;
373 
374  return StatusCode( StatusCode::SUCCESS, true );
375 }
376 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
377 
379 
380  ofs << "GLOBAL" << std::endl;
381  for ( const auto& prop : m_jobHistory->propertyPairs() ) {
382  ofs << prop.first << " " << dumpProp( prop.second ) << std::endl;
383  }
384 
385  ofs << std::endl << "SERVICES" << std::endl;
386  for ( const auto& s : m_svcmap ) dumpProperties( *s.first, ofs );
387 
388  ofs << std::endl << "ALGORITHMS" << std::endl;
389  for ( const auto& alg : m_algmap ) dumpProperties( *alg.first, ofs );
390 
391  ofs << std::endl << "ALGTOOLS" << std::endl;
392  for ( const auto& tool : m_algtoolmap ) dumpProperties( *tool.first, ofs );
393 }
394 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
395 
396 JobHistory* HistorySvc::getJobHistory() const { return m_jobHistory.get(); }
397 
398 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
400  if ( p_algCtxSvc ) return p_algCtxSvc->currentAlg();
401  warning() << "trying to create DataHistoryObj before "
402  << "HistorySvc has been initialized" << endmsg;
403  return nullptr;
404 }
405 
406 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
407 
409  const std::string& /* storeName */ ) {
410 
411  if ( !m_activate ) return nullptr;
412 
413  AlgorithmHistory* algHist = nullptr;
414 
415  IAlgorithm* ialg = getCurrentIAlg();
416  if ( !ialg ) {
417  ON_DEBUG
418  debug() << "Could not discover current Algorithm:" << endl
419  << " object CLID: " << id << " key: \"" << key << "\"" << endmsg;
420  algHist = nullptr;
421  } else {
422  Gaudi::Algorithm* alg = dynamic_cast<Gaudi::Algorithm*>( ialg );
423  if ( alg ) {
424  algHist = getAlgHistory( *alg );
425  } else {
426  warning() << "Could not extract concrete Algorithm:" << endl
427  << " object CLID: " << id << " key: \"" << key << "\"" << endmsg;
428  algHist = nullptr;
429  }
430  }
431  return new DataHistory( id, key, algHist );
432 }
433 
434 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
436 
437  DHH dhh( id, key );
438 
439  auto boundaries = m_datMap.equal_range( dhh );
440  auto match = boundaries.second;
441 
442  if ( boundaries.first != boundaries.second ) {
443  // there is something in the map, let's look for the specific entry
444 
445  std::string algName;
446  IAlgorithm* ialg = getCurrentIAlg();
447  if ( ialg ) {
448  algName = ialg->name();
449  } else {
450  algName = "UNKNOWN";
451  }
452 
453  match = std::find_if( boundaries.first, boundaries.second,
454  [&algName]( decltype( boundaries )::first_type::reference p ) -> bool {
455  return p.second->algorithmHistory()->algorithm_name() == algName;
456  } );
457  }
458 
459  if ( match == boundaries.second ) { // not found, crete the entry
460  DataHistory* dh = createDataHistoryObj( id, key, storeName );
461  m_datMap.insert( pair<DHH, DataHistory*>( dhh, dh ) );
462  }
463 
464  return StatusCode::SUCCESS;
465 }
466 
467 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
469  const std::string& /*storeName*/ ) const {
470 
471  DHH dhh( id, key );
472 
473  auto mitr = m_datMap.equal_range( dhh );
474  return ( mitr.first != mitr.second ) ? mitr.first->second : nullptr;
475 }
476 
477 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
478 
479 int HistorySvc::getDataHistory( const CLID& id, const std::string& key, const std::string& /*storeName*/,
480  std::list<DataHistory*>& dhlist ) const {
481 
482  DHH dhh( id, key );
483 
484  int n( 0 );
485 
486  auto mitr = m_datMap.equal_range( dhh );
487  for ( auto itr = mitr.first; itr != mitr.second; ++itr ) {
488  dhlist.push_back( itr->second );
489  ++n;
490  }
491  return n;
492 }
493 
494 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
495 
497 
498  if ( svc.name() == "HistoryStore" ) { return StatusCode( StatusCode::SUCCESS, true ); }
499 
500  JobHistory* job = getJobHistory();
501  const IService* psvc = &svc;
502  auto itr = m_svcmap.find( psvc );
503  if ( itr == m_svcmap.end() ) {
504 
505  ON_DEBUG {
506  auto& log = debug();
507  log << "Registering Service: ";
508  log.setColor( MSG::CYAN );
509  log << svc.name() << endmsg;
510  log.resetColor();
511  }
512 
513  m_svcmap[psvc] = new ServiceHistory( &svc, job );
514 
515  ( const_cast<IService*>( psvc ) )->addRef();
516  }
517 
518  return StatusCode( StatusCode::SUCCESS, true );
519 }
520 
521 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
522 
524 
525  const IService* psvc = &svc;
526  auto itr = m_svcmap.find( psvc );
527  if ( itr != m_svcmap.end() ) return itr->second;
528 
529  warning() << "Service " << svc.name() << " not registered" << endmsg;
530  return nullptr;
531 }
532 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
533 
534 void HistorySvc::getServiceHistory( std::set<ServiceHistory*>& svcs ) const { map_to_set( m_svcmap, svcs ); }
535 
536 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
537 
539 
540  info() << "Dumping properties for " << svc.name() << endl;
541 
542  ServiceHistory* hist = getServiceHistory( svc );
543 
544  if ( !hist ) return StatusCode::FAILURE;
545 
546  info() << svc.name() << " --> " << endl << *hist << endmsg;
547 
548  return StatusCode( StatusCode::SUCCESS, true );
549 }
550 
551 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
552 
553 void HistorySvc::dumpProperties( const IService& svc, std::ofstream& ofs ) const {
554 
555  ServiceHistory* hist = getServiceHistory( svc );
556 
557  if ( !hist ) return;
558 
559  for ( auto& prop : hist->properties() ) { ofs << svc.name() << " " << dumpProp( prop ) << std::endl; }
560 }
561 
562 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
563 
565 
566  if ( !m_isInitialized ) {
567  if ( !p_algCtxSvc ) {
568  if ( service( "AlgContextSvc", p_algCtxSvc, true ).isFailure() ) {
569  error() << "unable to get the AlgContextSvc" << endmsg;
570  return StatusCode::FAILURE;
571  }
572  }
573  m_ialgtools.insert( &ialg );
574  return StatusCode::SUCCESS;
575  }
576 
577  const AlgTool* alg = dynamic_cast<const AlgTool*>( &ialg );
578  if ( !alg ) {
579  error() << "Could not dcast IAlgTool \"" << ialg.name() << "\" to an AlgTool" << endmsg;
580  return StatusCode::FAILURE;
581  }
582 
583  if ( m_algtoolmap.find( alg ) != m_algtoolmap.end() ) {
584  warning() << "AlgTool " << ialg.name() << " already registered in HistorySvc" << endmsg;
585  return StatusCode::SUCCESS;
586  }
587 
588  const JobHistory* job = getJobHistory();
589  m_algtoolmap[alg] = new AlgToolHistory( *alg, job );
590 
591  ON_DEBUG {
592  auto& log = debug();
593  log << "Registering algtool: ";
594  log.setColor( MSG::CYAN );
595  log << alg->name() << endmsg;
596  log.resetColor();
597  }
598 
599  return StatusCode::SUCCESS;
600 }
601 
602 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
603 
605 
606  info() << "Dumping properties for " << alg.name() << endl;
607 
608  AlgToolHistory* hist = getAlgToolHistory( alg );
609 
610  if ( !hist ) return StatusCode::FAILURE;
611 
612  info() << alg.name() << " --> " << endl << *hist << endmsg;
613 
614  return StatusCode::SUCCESS;
615 }
616 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
617 
618 void HistorySvc::dumpProperties( const IAlgTool& alg, std::ofstream& ofs ) const {
619 
620  AlgToolHistory* hist = getAlgToolHistory( alg );
621 
622  if ( !hist ) return;
623 
624  for ( auto& prop : hist->properties() ) { ofs << alg.name() << " " << dumpProp( prop ) << std::endl; }
625 }
626 
627 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
628 
630 
631  const AlgTool* palg = dynamic_cast<const AlgTool*>( &alg );
632  auto itr = m_algtoolmap.find( palg );
633  if ( itr == m_algtoolmap.end() ) {
634  warning() << "AlgTool " << alg.name() << " not registered" << endmsg;
635  return nullptr;
636  }
637  return itr->second;
638 }
639 
640 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
641 
642 void HistorySvc::getAlgToolHistory( std::set<AlgToolHistory*>& algs ) const { map_to_set( m_algtoolmap, algs ); }
643 
644 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
645 
646 void HistorySvc::handle( const Incident& incident ) {
647 
648  if ( incident.type() == IncidentType::BeginEvent ) {
649  if ( captureState().isFailure() ) {
650  warning() << "Error capturing state." << endl << "Will try again at next BeginEvent incident" << endmsg;
651  }
652  }
653 }
654 
655 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
656 
657 std::string HistorySvc::dumpProp( const Gaudi::Details::PropertyBase* prop, bool isXML, int ind ) const {
658  std::ostringstream ost;
659  if ( isXML ) {
660  while ( ind > 0 ) {
661  ost << " ";
662  ind--;
663  }
664  ost << "<PROPERTY name=\"" << prop->name() << "\" value=\"" << HistoryObj::convert_string( prop->toString() )
665  << "\" documentation=\"" << HistoryObj::convert_string( prop->documentation() ) << "\">";
666  } else {
667  prop->fillStream( ost );
668  }
669  return ost.str();
670 }
671 
672 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
673 
675 
676  if ( m_outputFileTypeXML ) {
677  // xml header
678  ofs << "<?xml version=\"1.0\" ?> " << std::endl;
679  ofs << "<!--Test-xml-->" << std::endl;
680  ofs << "<SETUP>" << std::endl;
681  ofs << " <GLOBAL>" << std::endl;
682  } else {
683  ofs << "GLOBAL" << std::endl;
684  }
685 
686  std::string client_currently_open = "start";
687  for ( auto& item : m_jobHistory->propertyPairs() ) {
688  // client is the name of the component of the current property
689  const std::string& client = item.first;
690  const Gaudi::Details::PropertyBase* prp = item.second;
691 
692  if ( m_outputFileTypeXML ) {
693 
694  if ( client != client_currently_open ) {
695  if ( client_currently_open != "start" ) ofs << " </COMPONENT>" << endl;
696  ofs << " <COMPONENT name=\"" << client << "\" class=\"undefined\">" << std::endl;
697  }
698  } else {
699  ofs << client << " ";
700  }
701 
702  ofs << dumpProp( prp, m_outputFileTypeXML, 6 ) << endl;
703 
704  client_currently_open = client;
705 
706  if ( m_outputFileTypeXML ) ofs << " </COMPONENT>" << endl;
707  }
708 
709  if ( m_outputFileTypeXML ) {
710  ofs << "</GLOBAL>" << endl << "<SERVICES>" << endl;
711  } else {
712  ofs << "SERVICES" << std::endl;
713  }
714 
715  // helper to dump monitored components sorted by name
716  auto sortedDump = [&ofs, this]( const auto& map ) {
718  for ( const auto& item : map ) sorted[item.first->name()] = item.first;
719  for ( const auto& item : sorted ) dumpState( item.second, ofs );
720  };
721 
722  sortedDump( m_svcmap );
723 
724  if ( m_outputFileTypeXML ) {
725  ofs << "</SERVICES>" << endl << "<ALGORITHMS> " << endl;
726  } else {
727  ofs << "ALGORITHMS" << std::endl;
728  }
729 
730  sortedDump( m_algmap );
731 
732  if ( m_outputFileTypeXML ) {
733  ofs << "</ALGORITHMS>" << endl << "<ALGTOOLS> " << endl;
734  } else {
735  ofs << "ALGTOOLS" << std::endl;
736  }
737 
738  sortedDump( m_algtoolmap );
739 
740  if ( m_outputFileTypeXML ) { ofs << "</ALGTOOLS>" << endl << "</SETUP>" << endl; }
741 }
742 
743 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
744 
745 void HistorySvc::dumpState( const INamedInterface* in, std::ofstream& ofs ) const {
746 
747  HistoryObj* hist = nullptr;
748  IVersHistoryObj* vhist = nullptr;
749 
750  const IService* is = nullptr;
751  const Gaudi::Algorithm* ia = nullptr;
752  const IAlgTool* it = nullptr;
753  if ( ( is = dynamic_cast<const IService*>( in ) ) != nullptr ) {
754  ON_VERBOSE
755  verbose() << in->name() << " is Service" << endmsg;
756  ServiceHistory* o = getServiceHistory( *is );
757  hist = dynamic_cast<HistoryObj*>( o );
758  vhist = dynamic_cast<IVersHistoryObj*>( o );
759  } else if ( ( ia = dynamic_cast<const Gaudi::Algorithm*>( in ) ) != nullptr ) {
760  ON_VERBOSE
761  verbose() << in->name() << " is Alg" << endmsg;
762  AlgorithmHistory* o = getAlgHistory( *ia );
763  hist = dynamic_cast<HistoryObj*>( o );
764  vhist = dynamic_cast<IVersHistoryObj*>( o );
765  } else if ( ( it = dynamic_cast<const IAlgTool*>( in ) ) != nullptr ) {
766  ON_VERBOSE
767  verbose() << in->name() << " is AlgTool" << endmsg;
768  AlgToolHistory* o = getAlgToolHistory( *it );
769  hist = dynamic_cast<HistoryObj*>( o );
770  vhist = dynamic_cast<IVersHistoryObj*>( o );
771  } else {
772  error() << "Could not dcast interface to accepted History Obj type for " << in->name() << endmsg;
773  return;
774  }
775 
776  if ( !hist || !vhist ) {
777  error() << "Could not dcast recognized object to HistoryObj or IVersHistoryObj. This should never happen."
778  << endmsg;
779  return;
780  }
781 
782  if ( m_outputFileTypeXML ) {
783  hist->dump( ofs, true );
784  } else {
785  ofs << ">> " << vhist->name() << endl << *hist << endl;
786  }
787 }
StatusCode reinitialize() override
Definition: HistorySvc.cpp:77
virtual const std::string & name() const =0
AlgToolHistory * getAlgToolHistory(const IAlgTool &) const override
Definition: HistorySvc.cpp:629
StatusCode initialize() override
Definition: Service.cpp:60
const std::string & type() const
Access to the incident type.
Definition: Incident.h:38
StatusCode finalize() override
Definition: Service.cpp:164
StatusCode registerSvc(const IService &) override
Definition: HistorySvc.cpp:496
StatusCode registerAlgTool(const IAlgTool &) override
Definition: HistorySvc.cpp:564
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:635
std::string dumpProp(const Gaudi::Details::PropertyBase *, const bool isXML=false, int indent=0) const
Definition: HistorySvc.cpp:657
const std::string name() const
property name
Definition: Property.h:36
CLID id
Definition: HistorySvc.cpp:61
AlgorithmHistory class definition.
bool isSuccess() const
Definition: StatusCode.h:267
StatusCode initialize() override
Definition: HistorySvc.cpp:111
AlgorithmHistory * getAlgHistory(const Gaudi::Algorithm &) const override
Definition: HistorySvc.cpp:325
StatusCode listProperties() const override
Definition: HistorySvc.cpp:342
virtual StatusCode registerDataHistory(const CLID &id, const std::string &key, const std::string &store)
Definition: HistorySvc.cpp:435
T endl(T...args)
The IAlgManager is the interface implemented by the Algorithm Factory in the Application Manager to s...
Definition: IAlgManager.h:27
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
StatusCode stop() override
Definition: HistorySvc.cpp:234
STL namespace.
virtual void dump(std::ostream &, const bool isXML=false, int indent=0) const =0
Base class for History Objects.
Definition: HistoryObj.h:21
HistorySvc class definition.
Definition: HistorySvc.h:36
T end(T...args)
DHH(const CLID &i, std::string k)
Definition: HistorySvc.cpp:64
SmartIF< IFace > as()
Definition: ISvcLocator.h:103
const PropertyList & properties() const override
std::string key
Definition: HistorySvc.cpp:62
virtual std::string toString() const =0
value -> string
JobHistory class definition.
Definition: JobHistory.h:22
STL class.
bool isFailure() const
Definition: StatusCode.h:130
IAlgorithm * getCurrentIAlg() const
Definition: HistorySvc.cpp:399
void handle(const Incident &inc) override
Definition: HistorySvc.cpp:646
constexpr double second
STL class.
#define DECLARE_COMPONENT(type)
T push_back(T...args)
STL class.
Main interface for the JobOptions service.
struct GAUDI_API map
Parametrisation class for map-like implementation.
GAUDI_API ISvcLocator * svcLocator()
JobHistory * getJobHistory() const override
Definition: HistorySvc.cpp:396
General service interface definition.
Definition: IService.h:18
#define ON_DEBUG
Definition: HistorySvc.cpp:40
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
constexpr double m
Definition: SystemOfUnits.h:92
const PropertyList & properties() const override
DataHistory class definition.
Definition: DataHistory.h:23
const PropertyList & properties() const override
virtual std::vector< std::string > getClients() const =0
Get the list of clients.
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
virtual std::ostream & fillStream(std::ostream &) const
the printout of the property value
Definition: Property.cpp:49
unsigned int CLID
Class ID definition.
Definition: ClassID.h:8
STL class.
virtual const std::vector< const Gaudi::Details::PropertyBase * > * getProperties(const std::string &client) const =0
Get the properties associated to a given client.
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:28
T move(T...args)
T count(T...args)
StatusCode finalize() override
Definition: HistorySvc.cpp:257
AlgToolHistory class definition.
void dumpState(std::ofstream &) const
Definition: HistorySvc.cpp:674
IInterface compliant class extending IInterface with the name() method.
T find_if(T...args)
T size(T...args)
STL class.
bool operator<(DHH const &rhs) const
Definition: HistorySvc.cpp:66
const std::string & name() const override
Retrieve full identifying name of the concrete tool object.
Definition: AlgTool.cpp:58
virtual Out operator()(const vector_of_const_< In > &inputs) const =0
void dumpProperties(std::ofstream &) const
Definition: HistorySvc.cpp:378
DataHistory * createDataHistoryObj(const CLID &id, const std::string &key, const std::string &store) override
Definition: HistorySvc.cpp:408
T begin(T...args)
static std::string convert_string(const std::string &)
Definition: HistoryObj.cpp:20
Base class for all Incidents (computing events).
Definition: Incident.h:17
StatusCode registerJob() override
Definition: HistorySvc.cpp:339
#define SET(x)
Base class from which all the concrete tool classes should be derived.
Definition: AlgTool.h:47
std::string documentation() const
property documentation
Definition: Property.h:38
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:79
string s
Definition: gaudirun.py:312
virtual const std::list< IService * > & getServices() const =0
Get a reference to a service and create it if it does not exists.
constexpr static const auto FAILURE
Definition: StatusCode.h:86
ServiceHistory class definition.
#define ON_VERBOSE
Definition: HistorySvc.cpp:41
T transform(T...args)
T mem_fn(T...args)
Interface for Versioned History Objects.
T inserter(T...args)
StatusCode registerAlg(const Gaudi::Algorithm &) override
Definition: HistorySvc.cpp:276
T for_each(T...args)
void clearState()
Definition: HistorySvc.cpp:100
virtual StatusCode captureState()
Definition: HistorySvc.cpp:160
ServiceHistory * getServiceHistory(const IService &) const override
Definition: HistorySvc.cpp:523
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
virtual const std::string & name() const =0
Retrieve the name of the instance.
DataHistory * getDataHistory(const CLID &id, const std::string &key, const std::string &store) const override
Definition: HistorySvc.cpp:468