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