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