DataOnDemandSvc.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // Include files
3 // ============================================================================
4 // STD & STL
5 // ============================================================================
6 #include <string>
7 #include <set>
8 #include <map>
9 #include <math.h>
10 // ============================================================================
11 // GaudiKernel
12 // ============================================================================
13 #include "GaudiKernel/MsgStream.h"
15 #include "GaudiKernel/DataObject.h"
16 #include "GaudiKernel/IAlgorithm.h"
22 #include "GaudiKernel/IToolSvc.h"
24 #include "GaudiKernel/ToStream.h"
25 #include "GaudiKernel/Chrono.h"
27 #include "GaudiKernel/Property.h"
28 // ============================================================================
29 // Local
30 // ============================================================================
31 #include "DataOnDemandSvc.h"
32 // ============================================================================
33 // Boost
34 // ============================================================================
35 #include "boost/format.hpp"
36 #include "boost/algorithm/string/predicate.hpp"
37 // ============================================================================
38 // Constructors and Destructor
39 // ============================================================================
41 ( const std::string& name, ISvcLocator* svc )
42  : base_class( name, svc )
43 {
44  // ==========================================================================
45  declareProperty
46  ( "IncidentName" ,
47  m_trapType ,
48  "The type of handled Incident" ) ;
49  //
50  declareProperty ( "DataSvc" , m_dataSvcName ) ;
51  //
52  declareProperty ( "UsePreceedingPath" , m_partialPath ) ;
53  declareProperty
54  ( "Dump" ,
55  m_dump ,
56  "Dump the configuration and stastics" ) ->
57  declareUpdateHandler ( &DataOnDemandSvc::update_dump , this ) ;
58  //
59  declareProperty
60  ( "PreInitialize" ,
61  m_init ,
62  "Flag to (pre)initialize all algorithms" ) ;
63  declareProperty
64  ( "AllowPreInitializeFailure" ,
65  m_allowInitFailure ,
66  "Allow (pre)initialization of algorithms to fail without stopping the application" ) ;
67  //
68  declareProperty ( "Algorithms" , m_algMapping ) ->
69  declareUpdateHandler ( &DataOnDemandSvc::update_2 , this ) ;
70  declareProperty ( "Nodes" , m_nodeMapping ) ->
71  declareUpdateHandler ( &DataOnDemandSvc::update_3 , this ) ;
72  //
73  declareProperty ( "AlgMap" , m_algMap ) ->
74  declareUpdateHandler ( &DataOnDemandSvc::update_1 , this ) ;
75  declareProperty ( "NodeMap" , m_nodeMap ) ->
76  declareUpdateHandler ( &DataOnDemandSvc::update_1 , this ) ;
77 
78  declareProperty ( "Prefix" , m_prefix ) ;
79 
80  declareProperty("NodeMappingTools", m_nodeMapTools,
81  "List of tools of type IDODNodeMapper");
82  declareProperty("AlgMappingTools", m_algMapTools,
83  "List of tools of type IDODAlgMapper");
84  // ==========================================================================
85 }
86 // ============================================================================
87 // Update handler
88 // ============================================================================
90 {
91  verbose() << " I am update handler for property " << p << endmsg ;
92  // force update
93  m_updateRequired = true ;
94 }
95 // ============================================================================
96 // Update handler
97 // ============================================================================
99 {
100  warning()
101  << "The property 'Nodes' is obsolete, switch to map-like 'NodeMap' "
102  << " = { 'data' : 'type' } "
103  << endmsg ;
104  // force update
105  m_updateRequired = true ;
106 }
107 // ============================================================================
108 // Update handler
109 // ============================================================================
111 {
112  warning()
113  << "The property 'Algorithms' is obsolete, switch to map-like 'AlgMap' "
114  << " = { 'data' : 'algorithm' } "
115  << endmsg ;
116  // force update
117  m_updateRequired = true ;
118 }
119 // ============================================================================
120 // Update handler
121 // ============================================================================
123 {
124  // no action if not yet initialized
125  if ( FSMState() < Gaudi::StateMachine::INITIALIZED ) { return ; }
126  // dump the configuration:
127  if ( m_dump ) { dump ( MSG::ALWAYS ) ; }
128 }
129 // ============================================================================
130 // anonymous namespace to hide few local functions
131 // ============================================================================
132 namespace
133 {
134  // ==========================================================================
140  inline std::string no_prefix
141  ( const std::string& value ,
142  const std::string& prefix )
143  {
144  return boost::algorithm::starts_with(value,prefix) ?
145  value.substr( prefix.size() ) : value ;
146  }
147  // ==========================================================================
154  template <class MAP>
155  inline size_t add_prefix ( MAP& _map , const std::string& prefix )
156  {
157  // empty prefix
158  if ( prefix.empty() ) { return 0 ; } // RETURN
160  auto it = std::find_if_not( _map.begin(), _map.end(),
161  [&](typename MAP::const_reference i) {
162  return boost::algorithm::starts_with(i.first,prefix);
163  } );
164  if ( it == _map.end() ) return 0 ;
165  std::string key = prefix + it->first ;
166  std::string value = std::move(it->second); // steal the value we're about to erase..
167  _map.erase ( it ) ;
168  _map[ key ] = std::move(value); // and move it into its new location
169  return 1 + add_prefix ( _map , prefix ) ; // RETURN, recursion
170  //
171  }
172  // ==========================================================================
178  template <class SET>
179  inline size_t get_dir ( const std::string& object , SET& _set )
180  {
181  std::string::size_type ifind = object.rfind('/') ;
182  // stop recursion
183  if ( std::string::npos == ifind ) { return 0 ; } // RETURN
184  if ( 0 == ifind ) { return 0 ; }
185  //
186  const std::string top = std::string( object , 0 , ifind) ;
187  _set.insert( top ) ;
188  return 1 + get_dir ( top , _set ) ; // RETURN, recursion
189  }
190  // ==========================================================================
196  template <class MAP, class SET>
197  inline size_t get_dirs ( const MAP& _map, SET& _set )
198  {
199  size_t size = _set.size() ;
200  for ( const auto& item : _map )
201  { get_dir ( item.first , _set ) ; }
202  return _set.size() - size ;
203  }
204  // ==========================================================================
205 } // end of anonymous namespace
206 
208  ClassH cl = TClass::GetClass(type.c_str()) ;
209  if (!cl) {
210  warning()
211  << "Failed to access dictionary class for "
212  << name << " of type:" << type << endmsg;
213  }
214  m_nodes[name] = Node(cl, false, type);
215 }
216 
218  Leaf leaf(alg.type(), alg.name());
219  if (m_init)
220  {
222  if (sc.isFailure()) {
223  if (m_allowInitFailure) {
224  // re-store the content of the leaf object to try again to initialize
225  // the algorithm later (on demand)
226  leaf = Leaf(alg.type(), alg.name());
227  }
228  else
229  return sc;
230  }
231  }
232  m_algs[name] = leaf;
233  return StatusCode::SUCCESS;
234 }
235 
236 // ============================================================================
237 // update the content of Data-On-Demand actions
238 // ============================================================================
240 {
241  if ( !m_updateRequired ) { return StatusCode::SUCCESS ; }
242 
244  StatusCode sc = setupNodeHandlers() ; // convert "Nodes" new "NodeMap"
245  if ( sc.isFailure() )
246  {
247  error() << "Failed to setup old \"Nodes\"" << endmsg ;
248  return sc ;
249  }
251  sc = setupAlgHandlers() ; // convert "Algorithms" into "AlgMap"
252  if ( sc.isFailure() )
253  {
254  error() << "Failed to setup old \"Algorithms\"" << endmsg ;
255  return sc ;
256  }
258  add_prefix ( m_algMap , m_prefix ) ;
260  add_prefix ( m_nodeMap , m_prefix ) ;
262  std::set<std::string> dirs ;
263  if ( m_partialPath ){ get_dirs ( m_algMap , dirs ) ; }
264  if ( m_partialPath ){ get_dirs ( m_nodeMap , dirs ) ; }
265  //
266  auto _e = dirs.find("/Event") ;
267  if ( dirs.end() != _e ) { dirs.erase( _e ) ; }
268  // add all directories as nodes
269  for ( const auto& dir : dirs )
270  {
271  if ( m_algMap .end () == m_algMap .find ( dir ) &&
272  m_nodeMap .end () == m_nodeMap .find ( dir ) )
273  m_nodeMap [dir] = "DataObject" ;
274  }
275  //
276  m_algs .clear () ;
277  m_nodes .clear () ;
278  //
280  for ( const auto& alg : m_algMap )
281  {
282  if (i_setAlgHandler(alg.first, alg.second).isFailure())
283  return StatusCode::FAILURE;
284  }
286  for ( const auto& node : m_nodeMap )
287  {
288  i_setNodeHandler(node.first, node.second);
289  }
291  m_updateRequired = false ;
292  //
293  return StatusCode::SUCCESS ;
294 }
295 //=============================================================================
296 // Inherited Service overrides:
297 //=============================================================================
299 {
300  // initialize the Service Base class
302  if ( sc.isFailure() ) { return sc; }
303  sc = setup();
304  if ( sc.isFailure() ) { return sc; }
305  //
306  if ( m_dump ) { dump ( MSG::INFO ) ; }
307  else if ( msgLevel(MSG::DEBUG) ) { dump ( MSG::DEBUG ) ; }
308  //
309  if ( m_init ) { return update () ; }
310  //
311  return StatusCode::SUCCESS ;
312 }
313 // ============================================================================
314 // finalization of the service
315 // ============================================================================
317 {
318  //
319  info()
320  << "Handled \"" << m_trapType << "\" incidents: "
321  << m_statAlg << "/" << m_statNode << "/" << m_stat << "(Alg/Node/Total)."
322  << endmsg ;
323  if ( m_dump || msgLevel(MSG::DEBUG) )
324  {
325  info()
327  ( "Algorithm timing: Mean(+-rms)/Min/Max:%3%(+-%4%)/%6%/%7%[ms] " , System::milliSec )
328  << m_total.outputUserTime ( "Total:%2%[s]" , System::Sec ) << endmsg ;
329  info()
331  ( "Nodes timing: Mean(+-rms)/Min/Max:%3%(+-%4%)/%6%/%7%[ms] " , System::milliSec )
332  << m_timer_nodes.outputUserTime ( "Total:%2%[s]" , System::Sec ) << endmsg ;
333  info()
335  ( "Algs timing: Mean(+-rms)/Min/Max:%3%(+-%4%)/%6%/%7%[ms] " , System::milliSec )
336  << m_timer_algs .outputUserTime ( "Total:%2%[s]" , System::Sec ) << endmsg ;
337  info()
339  ( "All timing: Mean(+-rms)/Min/Max:%3%(+-%4%)/%6%/%7%[ms] " , System::milliSec )
340  << m_timer_all .outputUserTime ( "Total:%2%[s]" , System::Sec ) << endmsg ;
341  }
342  // dump it!
343  if ( m_dump ) { dump ( MSG::INFO , false ) ; }
344  else if ( msgLevel(MSG::DEBUG) ) { dump ( MSG::DEBUG , false ) ; }
345  //
346  if ( m_incSvc )
347  {
349  m_incSvc.reset();
350  }
351  m_algMgr.reset();
352  m_dataSvc.reset();
353  if (m_toolSvc) { // we may not have retrieved the ToolSvc
354  // Do not call releaseTool if the ToolSvc was already finalized.
356  for(const auto& i : m_nodeMappers ) m_toolSvc->releaseTool(i).ignore();
357  for(const auto& i : m_algMappers ) m_toolSvc->releaseTool(i).ignore();
358  } else {
359  warning() << "ToolSvc already finalized: cannot release tools. Check options." << endmsg;
360  }
363  m_toolSvc.reset();
364  }
365  return Service::finalize();
366 }
367 // ============================================================================
369 // ============================================================================
371 {
372  // reinitialize the Service Base class
373  if ( m_incSvc )
374  {
375  m_incSvc -> removeListener ( this , m_trapType );
376  m_incSvc.reset();
377  }
378  m_algMgr.reset();
379  m_dataSvc.reset();
380  for(const auto& i : m_nodeMappers ) m_toolSvc->releaseTool(i).ignore();
381  m_nodeMappers.clear();
382  for(const auto& i : m_algMappers ) m_toolSvc->releaseTool(i).ignore();
383  m_algMappers.clear();
384  m_toolSvc.reset();
385  //
387  if ( sc.isFailure() ) { return sc; }
388  //
389  sc = setup() ;
390  if ( sc.isFailure() ) { return sc; }
391  //
392  if ( m_dump ) { dump ( MSG::INFO ) ; }
393  else if ( msgLevel(MSG::DEBUG) ) { dump ( MSG::DEBUG ) ; }
394  //
395  return StatusCode::SUCCESS ;
396 }
397 // ============================================================================
398 // setup service
399 // ============================================================================
401 {
402  if ( !(m_algMgr = serviceLocator()) ) // assignment meant
403  {
404  error() << "Failed to retrieve the IAlgManager interface." << endmsg;
405  return StatusCode::FAILURE;
406  }
407 
408  if ( !(m_incSvc = serviceLocator()->service("IncidentSvc")) ) // assignment meant
409  {
410  error() << "Failed to retrieve Incident service." << endmsg;
411  return StatusCode::FAILURE;
412  }
414 
415  if ( !(m_dataSvc = serviceLocator()->service(m_dataSvcName)) ) // assignment meant
416  {
417  error()
418  << "Failed to retrieve the data provider interface of "
419  << m_dataSvcName << endmsg;
420  return StatusCode::FAILURE;
421  }
422 
423  // No need to get the ToolSvc if we are not using tools
424  if (!(m_nodeMapTools.empty() && m_algMapTools.empty())) {
425  if ( !(m_toolSvc = serviceLocator()->service("ToolSvc")) ) // assignment meant
426  {
427  error() << "Failed to retrieve ToolSvc" << endmsg;
428  return StatusCode::FAILURE;
429  }
430 
431  // load the node mapping tools
432  IDODNodeMapper *nodetool = nullptr;
433  for(const auto& i : m_nodeMapTools) {
434  const StatusCode sc = m_toolSvc->retrieveTool(i, nodetool);
435  if (sc.isFailure()) return sc;
436  m_nodeMappers.push_back(nodetool);
437  }
438  IDODAlgMapper *algtool = nullptr;
439  for(const auto& i : m_algMapTools) {
440  const StatusCode sc = m_toolSvc->retrieveTool(i, algtool);
441  if (sc.isFailure()) return sc;
442  m_algMappers.push_back(algtool);
443  }
444  }
445  return update();
446 }
447 // ============================================================================
448 // setup node handlers
449 // ============================================================================
451 {
452  std::string nam, typ, tag;
454  // Setup for node leafs, where simply a constructor is called...
455  for (auto node: m_nodeMapping)
456  {
457  using Parser = Gaudi::Utils::AttribStringParser;
458  for (auto attrib: Parser(node)) {
459  switch( ::toupper(attrib.tag[0]) ) {
460  case 'D':
461  tag = std::move(attrib.value);
462  break;
463  case 'T':
464  nam = std::move(attrib.value);
465  break;
466  }
467  }
468  if ( m_algMap .end () != m_algMap .find ( tag ) ||
469  m_nodeMap .end () != m_nodeMap .find ( tag ) )
470  {
471  warning()
472  << "The obsolete property 'Nodes' redefines the action for '"
473  + tag + "' to be '" +nam+"'"
474  << endmsg ;
475  }
476  m_nodeMap[tag] = nam ;
477  }
478  //
479  m_updateRequired = true ;
480  //
481  return sc;
482 }
483 // ============================================================================
484 // setup algorithm handlers
485 // ============================================================================
487 {
488  std::string typ, tag;
489 
490  for (auto alg: m_algMapping)
491  {
492  using Parser = Gaudi::Utils::AttribStringParser;
493  for (auto attrib: Parser(alg)) {
494  switch( ::toupper(attrib.tag[0]) ) {
495  case 'D':
496  tag = std::move(attrib.value);
497  break;
498  case 'T':
499  typ = std::move(attrib.value);
500  break;
501  }
502  }
504  if ( m_algMap .end () != m_algMap .find ( tag ) ||
505  m_nodeMap .end () != m_nodeMap .find ( tag ) )
506  {
507  warning()
508  << "The obsolete property 'Algorithms' redefines the action for '"
509  + tag + "' to be '" +item.type() +"/"+item.name()+"'"
510  << endmsg ;
511  }
512  m_algMap[tag] = item.type() + "/" + item.name() ;
513  }
514  m_updateRequired = true ;
515  return StatusCode::SUCCESS;
516 }
517 // ============================================================================
519 // ============================================================================
521 {
522  if ( l.algorithm ) { return StatusCode::SUCCESS ; }
523  if ( ! m_algMgr ) { return StatusCode::FAILURE ; }
524  l.algorithm = m_algMgr->algorithm(l.name, false);
525  if ( l.algorithm ) { return StatusCode::SUCCESS ; }
526  // create it!
527  StatusCode sc = m_algMgr->createAlgorithm ( l.type , l.name , l.algorithm , true ) ;
528  if ( sc.isFailure() )
529  {
530  error()
531  << "Failed to create algorithm "
532  << l.type << "('" << l.name<< "')" << endmsg;
533  l.algorithm = nullptr ;
534  return sc ; // RETURN
535  }
536  if ( l.algorithm->isInitialized() ) { return StatusCode:: SUCCESS ;}
537  // initialize it!
538  sc = l.algorithm -> sysInitialize () ;
539  if ( sc.isFailure() )
540  {
541  error()
542  << "Failed to initialize algorithm "
543  << l.type << "('" << l.name<< "')" << endmsg;
544  l.algorithm = nullptr ;
545  return sc ; // RETURN
546  }
547  if ( Gaudi::StateMachine::RUNNING == l.algorithm->FSMState() )
548  { return StatusCode::SUCCESS ; }
549  // run it!
550  sc = l.algorithm->sysStart() ;
551  if ( sc.isFailure() )
552  {
553  error()
554  << "Failed to 'run' algorithm "
555  << l.type << "('" << l.name<< "')" << endmsg;
556  l.algorithm = nullptr ;
557  return sc ; // RETURN
558  }
559  return StatusCode::SUCCESS ;
560 }
561 
562 // local algorithms
563 namespace {
566  struct ToolGetter {
570  ToolGetter(std::string _path): path(std::move(_path)) {}
572  inline std::string operator() (IDODNodeMapper *t) const {
573  return t->nodeTypeForPath(path);
574  }
576  inline Gaudi::Utils::TypeNameString operator() (IDODAlgMapper *t) const {
577  return t->algorithmForPath(path);
578  }
579  };
580 
583  inline bool isGood(const std::string& r) {return !r.empty();}
584  inline bool isGood(const Gaudi::Utils::TypeNameString& r) {return !r.name().empty();}
586 
589  class Finder {
590  const ToolGetter getter;
591  const std::vector<IDODNodeMapper*> &nodes;
592  const std::vector<IDODAlgMapper*> &algs;
594  template <class R, class C>
595  R find(const C& l) const {
596  for(auto& i : l ){
597  auto result = getter(i);
598  if (isGood(result)) return result;
599  }
600  return R{""};
601  }
602  public:
604  Finder(std::string _path,
605  const std::vector<IDODNodeMapper*> &_nodes,
606  const std::vector<IDODAlgMapper*> &_algs)
607  : getter(std::move(_path)), nodes(_nodes), algs(_algs) {
608  }
610  inline std::string node() const {
611  return find<std::string>(nodes);
612  }
614  inline Gaudi::Utils::TypeNameString alg() const {
615  return find<Gaudi::Utils::TypeNameString>(algs);
616  }
617 
618  };
619 
620 }
621 
622 // ===========================================================================
623 // IIncidentListener interfaces overrides: incident handling
624 // ===========================================================================
625 void DataOnDemandSvc::handle ( const Incident& incident )
626 {
627 
629 
630  ++m_stat ;
631  // proper incident type?
632  if ( incident.type() != m_trapType ) { return ; } // RETURN
633  const DataIncident* inc = dynamic_cast<const DataIncident*>(&incident);
634  if ( ! inc ) { return ; } // RETURN
635  // update if needed!
636  if ( m_updateRequired ) { update() ; }
637 
638  if ( msgLevel(MSG::VERBOSE) )
639  {
640  verbose()
641  << "Incident: [" << incident.type () << "] "
642  << " = " << incident.source ()
643  << " Location:" << inc->tag() << endmsg;
644  }
645  // ==========================================================================
646  Gaudi::StringKey tag ( inc->tag() ) ;
647  // ==========================================================================
648  auto icl = m_nodes.find ( tag ) ;
649  if ( icl != m_nodes.end() )
650  {
651  StatusCode sc = execHandler ( tag , icl->second ) ;
652  if ( sc.isSuccess() ) { ++m_statNode ; }
653  return ; // RETURN
654  }
655  // ==========================================================================
656  auto ialg = m_algs.find ( tag ) ;
657  if ( ialg != m_algs.end() )
658  {
659  StatusCode sc = execHandler ( tag , ialg->second ) ;
660  if ( sc.isSuccess() ) { ++m_statAlg ; }
661  return ; // RETURN
662  }
663  // ==========================================================================
664  // Fall back on the tools
665  if (m_toolSvc) {
666  if ( msgLevel(MSG::VERBOSE))
667  verbose() << "Try to find mapping with mapping tools" << endmsg;
668  Finder finder(no_prefix(inc->tag(), m_prefix), m_nodeMappers, m_algMappers);
669  // - try the node mappers
670  std::string node = finder.node();
671  if (isGood(node)) {
672  // if one is found update the internal node mapping and try again.
673  if (msgLevel(MSG::VERBOSE))
674  verbose() << "Found Node handler: " << node << endmsg;
675  i_setNodeHandler(inc->tag(), node);
676  handle(incident);
677  --m_stat; // avoid double counting because of recursion
678  return;
679  }
680  // - try alg mappings
681  Gaudi::Utils::TypeNameString alg = finder.alg();
682  if (isGood(alg)) {
683  // we got an algorithm, update alg map and try to handle again
684  if (msgLevel(MSG::VERBOSE))
685  verbose() << "Found Algorithm handler: " << alg << endmsg;
686  i_setAlgHandler(inc->tag(), alg).ignore();
687  handle(incident);
688  --m_stat; // avoid double counting because of recursion
689  return;
690  }
691  }
692 }
693 // ===========================================================================
694 // execute the handler
695 // ===========================================================================
698 {
699 
701 
702  if ( n.executing ) { return StatusCode::FAILURE ; } // RETURN
703 
704  Protection p(n.executing);
705 
707 
708  if ( n.dataObject ) { object.reset( new DataObject() ) ; }
709  else
710  {
711  // try to recover the handler
712  if ( !n.clazz ) { n.clazz = TClass::GetClass(n.name.c_str()) ; }
713  if ( !n.clazz )
714  {
715  error()
716  << "Failed to get dictionary for class '"
717  << n.name
718  << "' for location:" << tag << endmsg;
719  return StatusCode::FAILURE ; // RETURN
720  }
721 
722  object.reset( reinterpret_cast<DataObject*>(n.clazz->New()) );
723 
724  if ( !object )
725  {
726  error()
727  << "Failed to create an object of type:"
728  << n.clazz->GetName() << " for location:" << tag
729  << endmsg;
730  return StatusCode::FAILURE ; // RETURN
731  }
732  }
733  //
734  StatusCode sc = m_dataSvc->registerObject(tag, object.release() );
735  if ( sc.isFailure() )
736  {
737  error() << "Failed to register an object of type:"
738  << n.name << " at location:" << tag
739  << endmsg;
740  return sc ; // RETURN
741  }
742  ++n.num ;
743  //
744  return StatusCode::SUCCESS ;
745 }
746 // ===========================================================================
747 // execute the handler
748 // ===========================================================================
751 {
753  //
754  if ( l.executing ) { return StatusCode::FAILURE ; } // RETURN
755  //
756  if ( ! l.algorithm )
757  {
758  StatusCode sc = configureHandler ( l ) ;
759  if ( sc.isFailure() )
760  {
761  error()
762  << "Failed to configure handler for: "
763  << l.name << "[" << l.type << "] " << tag << endmsg;
764  return sc ; // RETURN
765  }
766  }
767  //
768  Chrono atimer ( m_total ) ;
769  //
770  Protection p(l.executing);
772  if ( sc.isFailure() )
773  {
774  error() << "Failed to execute the algorithm:"
775  << l.algorithm->name() << " for location:" << tag << endmsg;
776  return sc ; // RETURN
777  }
778  ++l.num ;
779  //
780  return StatusCode::SUCCESS ;
781 }
782 // ============================================================================
783 /* dump the content of DataOnDemand service
784  * @param level the printout level
785  * @param mode the printout mode
786  */
787 // ============================================================================
789 ( const MSG::Level level ,
790  const bool mode ) const
791 {
792  if ( m_algs.empty() && m_nodes.empty() ) { return ; }
793 
796  for ( auto& alg : m_algs )
797  {
798  auto check = _m.find(alg.first) ;
799  if ( _m.end() != check )
800  {
801  warning() << " The data item is activated for '"
802  << check->first << "' as '" << check->second.first << "'" << endmsg ;
803  }
804  const Leaf& l = alg.second ;
805  std::string nam = ( l.name == l.type ? l.type : (l.type+"/"+l.name) ) ;
806  //
807  if ( !mode && 0 == l.num ) { continue ; }
808  //
809  std::string val ;
810  if ( mode ) { val = ( ! l.algorithm ) ? "F" : "T" ; }
811  else { val = std::to_string( l.num ) ; }
812  //
813  _m[ no_prefix ( alg.first , m_prefix ) ] = { nam , val } ;
814  }
815  // nodes:
816  for ( const auto& node : m_nodes )
817  {
818  auto check = _m.find(node.first) ;
819  if ( _m.end() != check )
820  {
821  warning() << " The data item is already activated for '"
822  << check->first << "' as '" << check->second.first << "'" << endmsg ;
823  }
824  const Node& n = node.second ;
825  std::string nam = "'" + n.name + "'" ;
826  //
827  std::string val ;
828 
829  if ( !mode && 0 == n.num ) { continue ; }
830 
831  if ( mode ) { val = ( 0 == n.clazz ) ? "F" : "T" ; }
832  else { val = std::to_string( n.num ) ; }
833  //
834  _m[ no_prefix ( node.first , m_prefix ) ] = { nam , val } ;
835  }
836  //
837  if ( _m.empty() ) { return ; }
838 
839  // find the correct formats
840  size_t n1 = 0 ;
841  size_t n2 = 0 ;
842  size_t n3 = 0 ;
843  for ( const auto& i : _m )
844  {
845  n1 = std::max ( n1 , i.first.size() ) ;
846  n2 = std::max ( n2 , i.second.first.size() ) ;
847  n3 = std::max ( n3 , i.second.second.size() ) ;
848  }
849  if ( 10 > n1 ) { n1 = 10 ; }
850  if ( 10 > n2 ) { n2 = 10 ; }
851  if ( 60 < n1 ) { n1 = 60 ; }
852  if ( 60 < n2 ) { n2 = 60 ; }
853  //
854 
855  const std::string _f = " | %%1$-%1%.%1%s | %%2$-%2%.%2%s | %%3$%3%.%3%s |" ;
856  boost::format _ff ( _f ) ;
857  _ff % n1 % n2 % n3 ;
858 
859  const std::string _format = _ff.str() ;
860 
861  auto& msg = msgStream(level);
862 
863  if ( mode ) { msg << "Data-On-Demand Actions enabled for:" ; }
864  else { msg << "Data-On-Demand Actions has been used for:" ; }
865 
866  boost::format fmt1( _format) ;
867  fmt1 % "Address" % "Creator" % ( mode ? "S" : "#" ) ;
868  //
869  const std::string header = fmt1.str() ;
870  std::string line = std::string( header.size() , '-' ) ;
871  line[0] = ' ' ;
872 
873  msg << '\n' << line
874  << '\n' << header
875  << '\n' << line ;
876 
877  // make the actual printout:
878  for ( const auto& item : _m )
879  {
880  boost::format fmt( _format) ;
881  msg << '\n' <<
882  ( fmt % item.first % item.second.first % item.second.second ) ;
883  }
884 
885  msg << '\n' << line << endmsg ;
886 
887 }
888 // ============================================================================
893 // ============================================================================
894 
895 // ============================================================================
896 // The END
897 // ============================================================================
void i_setNodeHandler(const std::string &name, const std::string &type)
Internal method to initialize a node handler.
Parse attribute strings allowing iteration over the various attributes.
virtual SmartIF< IAlgorithm > & algorithm(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)=0
Returns a smart pointer to a service.
ChronoEntity m_timer_all
StatusCode initialize() override
Definition: Service.cpp:68
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:324
T empty(T...args)
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
const std::string & type() const
Access to the incident type.
Definition: Incident.h:41
The DataOnDemandSvc listens to incidents typically triggered by the data service of the configurable ...
StatusCode finalize() override
Definition: Service.cpp:193
virtual StatusCode sysStart()=0
Startup method invoked by the framework.
ChronoEntity m_timer_algs
Gaudi::StateMachine::State FSMState() const override
Definition: Service.h:57
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
const std::string & source() const
Access to the source of the incident.
Definition: Incident.h:47
std::vector< IDODNodeMapper * > m_nodeMappers
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
SmartIF< IIncidentSvc > m_incSvc
Incident service.
void handle(const Incident &incident) override
IIncidentListener interfaces overrides: incident handling.
T to_string(T...args)
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
virtual StatusCode createAlgorithm(const std::string &algtype, const std::string &algname, IAlgorithm *&alg, bool managed=false, bool checkIfExists=true)=0
Create an instance of a algorithm type that has been declared beforehand and assigns to it a name...
std::vector< std::string > m_algMapTools
std::string m_trapType
Trap name.
STL namespace.
std::string m_dataSvcName
Data service name.
T end(T...args)
Setup m_nodeMapping
Mapping to nodes.
A small utility class for chronometry of user codes.
Definition: Chrono.h:25
Map m_algMap
the major configuration property { 'data' : 'algorithm' }
#define SET(x)
StatusCode initialize() override
Inherited Service overrides: Service initialization.
STL class.
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
StatusCode retrieveTool(const std::string &type, T *&tool, const IInterface *parent=nullptr, bool createIf=true)
Retrieve specified tool sub-type with tool dependent part of the name automatically assigned...
Definition: IToolSvc.h:145
The helper class to represent the efficient "key" for access.
Definition: StringKey.h:35
virtual StatusCode sysExecute()=0
System execution. This method invokes the execute() method of a concrete algorithm.
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
STL class.
SmartIF< IDataProviderSvc > m_dataSvc
Data provider reference.
ulonglong m_statNode
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:78
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:319
ClassH clazz
the actual class
T push_back(T...args)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Interface of tools used by the DataOnDemandSvc to choose the type of node to be created at a path...
Setup m_algMapping
Mapping to algorithms.
iterator end()
Definition: Map.h:132
Helper class to parse a string of format "type/name".
Definition: TypeNameString.h:9
string type
Definition: gaudirun.py:151
StatusCode setup()
Setup routine (called by (re-) initialize.
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
bool m_allowInitFailure
flag to allow DataOnDemand initialization to succeed even if the (pre)initialization of the algorithm...
StatusCode execHandler(const std::string &tag, Leaf &leaf)
Execute leaf handler (algorithm)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
void update_dump(Property &)
update handler for 'Dump' property
StatusCode setupNodeHandlers()
Initialize node handlers.
T erase(T...args)
iterator find(const key_type &key)
Definition: Map.h:149
Helper class of the DataOnDemandSvc.
virtual Gaudi::Utils::TypeNameString algorithmForPath(const std::string &path)=0
For the given path, returns a TypeNameString object identifying the algorithm to be run to produce th...
std::vector< std::string > m_nodeMapTools
NodeMap m_nodes
Map of "empty" objects to be placed as intermediate nodes.
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
std::string m_prefix
StatusCode reinitialize() override
Definition: Service.cpp:282
void dump(const MSG::Level level, const bool mode=true) const
dump the content of DataOnDemand service
T clear(T...args)
T max(T...args)
T move(T...args)
GAUDI_API std::string path(const AIDA::IBaseHistogram *aida)
get the path in THS for AIDA histogram
dictionary l
Definition: gaudirun.py:421
bool m_partialPath
Flag to allow for the creation of partial leaves.
std::string outputUserTime() const
print the chrono ;
T find_if_not(T...args)
T size(T...args)
std::vector< IDODAlgMapper * > m_algMappers
Interface of tools used by the DataOnDemandSvc to choose the algorithm to be run to produce the data ...
Definition: IDODAlgMapper.h:17
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
SmartIF< IAlgManager > m_algMgr
Algorithm manager.
STL class.
SmartIF< IToolSvc > m_toolSvc
Data provider reference.
Helper object, useful for measurement of CPU-performance of highly-recursive structures, e.g.
Definition: LockedChrono.h:52
AlgMap m_algs
Map of algorithms to handle incidents.
bool m_dump
flag to force the printout
bool m_init
flag to warm up the configuration
const std::string & type() const
ChronoEntity m_timer_nodes
T c_str(T...args)
Base class for all Incidents (computing events).
Definition: Incident.h:17
virtual void addListener(IIncidentListener *lis, const std::string &type="", long priority=0, bool rethrow=false, bool singleShot=false)=0
Add listener.
bool dataObject
trivial object? DataObject?
DataOnDemandSvc(const std::string &name, ISvcLocator *svc)
Standard initializing service constructor.
StatusCode finalize() override
Inherited Service overrides: Service finalization.
tuple item
print s1,s2
Definition: ana.py:146
T substr(T...args)
void clear()
Definition: Map.h:178
StatusCode service(const std::string &name, const T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
Definition: Service.h:144
virtual StatusCode releaseTool(IAlgTool *tool)=0
Release the tool.
ChronoEntity m_total
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:88
virtual bool isInitialized() const =0
check if the algorithm is initialized properly
Map m_nodeMap
the major configuration property { 'data' : 'type' }
virtual void removeListener(IIncidentListener *lis, const std::string &type="")=0
Remove listener.
Data service incident class.
const std::string & name() const
implementation of various functions for streaming.
void ignore() const
Definition: StatusCode.h:108
list header
Definition: Test.py:33
StatusCode setupAlgHandlers()
Initialize leaf handlers.
Helper class of the DataOnDemandSvc.
virtual std::string nodeTypeForPath(const std::string &path)=0
For the given path, returns a the type name of the object to be created at the path.
virtual StatusCode registerObject(const std::string &fullPath, DataObject *pObject)=0
Register object with the data store.
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
list i
Definition: ana.py:128
StatusCode i_setAlgHandler(const std::string &name, const Gaudi::Utils::TypeNameString &alg)
Internal method to initialize an algorithm handler.
StatusCode configureHandler(Leaf &leaf)
Configure handler for leaf.
void update_2(Property &p)
void toupper(std::string &s)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
void update_3(Property &p)
void update_1(Property &p)
StatusCode reinitialize() override
Inherited Service overrides: Service reinitialization.
StatusCode update()
update the handlers
StatusCode sysInitialize() override
Initialize Service.
Definition: Service.cpp:26