Gaudi Framework, version v20r4

Generated: 8 Jan 2009

DataOnDemandSvc.cpp

Go to the documentation of this file.
00001 // $Id: DataOnDemandSvc.cpp,v 1.16 2008/10/01 14:33:07 marcocle Exp $
00002 // ============================================================================
00003 // CVS tag $Name:  $ 
00004 // ============================================================================
00005 // Incldue files 
00006 // ============================================================================
00007 // STD & STL 
00008 // ============================================================================
00009 #include <string>
00010 #include <set>
00011 #include <map>
00012 #include <math.h>
00013 // ============================================================================
00014 // GaudiKernel
00015 // ============================================================================
00016 #include "GaudiKernel/MsgStream.h"
00017 #include "GaudiKernel/Tokenizer.h"
00018 #include "GaudiKernel/DataObject.h"
00019 #include "GaudiKernel/IAlgorithm.h"
00020 #include "GaudiKernel/ISvcLocator.h"
00021 #include "GaudiKernel/IAlgManager.h"
00022 #include "GaudiKernel/IIncidentSvc.h"
00023 #include "GaudiKernel/DataIncident.h"
00024 #include "GaudiKernel/IDataProviderSvc.h"
00025 #include "GaudiKernel/ListItem.h"
00026 #include "GaudiKernel/ToStream.h"
00027 #include "DataOnDemandSvc.h"
00028 // ============================================================================
00029 // Boost 
00030 // ============================================================================
00031 #include "boost/format.hpp"
00032 #include "boost/lexical_cast.hpp"
00033 // ============================================================================
00034 
00035 // ============================================================================
00036 // Constructors and Destructor
00037 // ============================================================================
00038 DataOnDemandSvc::DataOnDemandSvc 
00039 ( const std::string& name, ISvcLocator* svc )
00040   : Service(name, svc)
00041   , m_incSvc   ( 0 )
00042   , m_algMgr   ( 0 )
00043   , m_dataSvc  ( 0 )
00044   //
00045   , m_trapType    ( "DataFault")
00046   , m_dataSvcName ( "EventDataSvc" )
00047   , m_partialPath ( true  ) 
00048   , m_dump        ( false )
00049   //
00050   , m_algMapping  () 
00051   , m_nodeMapping () 
00052   //
00053   , m_algMap   (   ) 
00054   , m_nodeMap  (   )  
00055   //
00056   , m_updateRequired ( true )
00057   , m_prefix         ( "/Event/" )
00058   , m_log      ( 0 )
00059   , m_total    (   ) 
00060   , m_statAlg  ( 0 ) 
00061   , m_statNode ( 0 ) 
00062   , m_stat     ( 0 )
00063 {
00064   // ==========================================================================
00065   declareProperty ( "IncidentName"       , m_trapType    ) ;
00066   declareProperty ( "DataSvc"            , m_dataSvcName ) ;
00067   declareProperty ( "UsePreceedingPath"  , m_partialPath ) ;
00068   declareProperty ( "Dump"               , m_dump        ) ;
00069   //
00070   declareProperty ( "Algorithms"         , m_algMapping  )  ->
00071     declareUpdateHandler ( &DataOnDemandSvc::update_2 , this ) ;
00072   declareProperty ( "Nodes"              , m_nodeMapping ) ->
00073     declareUpdateHandler ( &DataOnDemandSvc::update_3 , this ) ;
00074   //
00075   declareProperty ( "AlgMap"  , m_algMap  ) ->  
00076     declareUpdateHandler ( &DataOnDemandSvc::update_1 , this ) ;
00077   declareProperty ( "NodeMap" , m_nodeMap ) ->  
00078     declareUpdateHandler ( &DataOnDemandSvc::update_1 , this ) ;
00079   //
00080   declareProperty ( "Prefix"             , m_prefix      ) ;
00081   // ==========================================================================
00082 } 
00083 // ============================================================================
00084 // Update handler 
00085 // ============================================================================
00086 void DataOnDemandSvc::update_1 ( Property& p ) 
00087 {
00088   stream() << MSG::VERBOSE << " I am update handler for property " << p << endreq ;
00089   // force update 
00090   m_updateRequired = true ;
00091 } 
00092 // ============================================================================
00093 // Update handler 
00094 // ============================================================================
00095 void DataOnDemandSvc::update_3 ( Property& /* p */ ) 
00096 {
00097   stream() << MSG::WARNING 
00098            << "The property 'Nodes'      is obsolete, switch to map-like 'NodeMap' "
00099            << " = { 'data' : 'type'      } "
00100            << endreq ;
00101   // force update 
00102   m_updateRequired = true ;
00103 } 
00104 // ============================================================================
00105 // Update handler 
00106 // ============================================================================
00107 void DataOnDemandSvc::update_2 ( Property& /* p */ ) 
00108 {
00109   stream() << MSG::WARNING 
00110            << "The property 'Algorithms' is obsolete, switch to map-like 'AlgMap'  " 
00111            << " = { 'data' : 'algorithm' } "
00112            << endreq ;
00113   // force update 
00114   m_updateRequired = true ;
00115 }
00116 // ============================================================================
00117 // anonymous namespace to hide few local functions 
00118 // ============================================================================
00119 namespace 
00120 {
00121   // ==========================================================================
00127   inline std::string no_prefix 
00128   ( const std::string& value  , 
00129     const std::string& prefix )
00130   {
00131     return 
00132       !prefix.empty() && 0 == value.find(prefix) ? 
00133       std::string( value , prefix.size() ) : value ;
00134   }
00135   // ==========================================================================
00142   template <class MAP>
00143   inline size_t add_prefix ( MAP& _map , const std::string& prefix ) 
00144   {
00145     // empty  prefix 
00146     if ( prefix.empty() ) { return 0 ; }                    // RETURN 
00148     for ( typename MAP::iterator it = _map.begin() ; _map.end() != it ; ++it ) 
00149     {
00150       if ( 0 != it->first.find(prefix) )  // valid prefix? 
00151       { 
00152         std::string key   = prefix + it->first ;
00153         std::string value = it->second ;
00154         _map.erase ( it ) ;
00155         _map[ key ] = value  ;
00156         return 1 + add_prefix ( _map , prefix ) ;    // RETURN, recursion
00157       }
00158     }
00159     //
00160     return 0 ;
00161   }
00162   // ==========================================================================
00168   template <class SET>
00169   inline size_t get_dir ( const std::string& object , SET& _set ) 
00170   {
00171     std::string::size_type ifind = object.rfind('/') ;
00172     // stop recursion 
00173     if ( std::string::npos == ifind ) { return 0 ; } // RETURN 
00174     if ( 0 == ifind                 ) { return 0 ; }
00175     //
00176     const std::string top = std::string( object , 0 , ifind) ;
00177     _set.insert( top ) ;
00178     return 1 + get_dir ( top , _set ) ;   // RETURN, recursion 
00179   }
00180   // ==========================================================================
00186   template <class MAP, class SET>
00187   inline size_t get_dirs ( const MAP& _map, SET& _set ) 
00188   {
00189     size_t size = _set.size() ;
00190     for ( typename MAP::const_iterator item = _map.begin() ; 
00191           _map.end() != item ; ++item ) {  get_dir ( item->first , _set ) ; }
00192     return _set.size() - size ;
00193   } 
00194   // ==========================================================================
00195 } // end of anonymous namespace
00196 // ============================================================================
00197 // update the content of Data-On-Demand actions 
00198 // ============================================================================
00199 StatusCode DataOnDemandSvc::update () 
00200 {
00201   StatusCode sc = StatusCode::SUCCESS ;
00203   sc = setupNodeHandlers() ; // convert "Nodes"      new "NodeMap"
00204   if ( sc.isFailure() ) 
00205   {
00206     stream() << MSG::ERROR << "Failed to setup old \"Nodes\""      << endreq ;
00207     return sc ;
00208   }
00210   sc = setupAlgHandlers()   ; // convert "Algorithms" into "AlgMap"
00211   if ( sc.isFailure() ) 
00212   {
00213     stream() << MSG::ERROR << "Failed to setup old \"Algorithms\"" << endreq ;
00214     return sc ;
00215   }
00217   add_prefix ( m_algMap  , m_prefix ) ;
00219   add_prefix ( m_nodeMap , m_prefix ) ;
00221   typedef std::set<std::string> Set ; 
00222   Set dirs ;
00223   if ( m_partialPath ){ get_dirs ( m_algMap  , dirs ) ; }
00224   if ( m_partialPath ){ get_dirs ( m_nodeMap , dirs ) ; }
00225   //
00226   Set::iterator _e = dirs.find("/Event") ;
00227   if ( dirs.end() != _e ) { dirs.erase( _e ) ; }
00228   // add all directories as nodes 
00229   for ( Set::const_iterator dir = dirs.begin() ; dirs.end() != dir ; ++dir ) 
00230   {
00231     if ( m_algMap  .end () != m_algMap  .find ( *dir ) ) { continue ; }
00232     if ( m_nodeMap .end () != m_nodeMap .find ( *dir ) ) { continue ; }    
00233     m_nodeMap [*dir] = "DataObject" ;  
00234   }
00235   //
00236   m_algs  .clear  () ;
00237   m_nodes .clear  () ;
00238   //
00240   for ( Map::const_iterator ialg = m_algMap.begin() ; 
00241         m_algMap.end() != ialg ; ++ialg )
00242   {
00243     ListItem alg ( ialg->second ) ;
00244     m_algs[ialg->first] =  Leaf( alg.type() , alg.name() ) ;
00245   }
00247   for ( Map::const_iterator inode = m_nodeMap.begin() ; 
00248         m_nodeMap.end() != inode ; ++inode ) 
00249   {
00250     ClassH cl = ROOT::Reflex::Type::ByName( inode->second ) ;
00251     if ( !cl ) 
00252     {
00253       stream() << MSG::WARNING 
00254                << "Failed to access dictionary class for "
00255                << inode->first << " of type:" << inode->second << endmsg;
00256     }
00257     m_nodes[inode->first] = Node ( cl , false , inode->second ) ;
00258   }
00260   m_updateRequired = false ;
00261   //
00262   return StatusCode::SUCCESS ;
00263 }
00264 // ============================================================================
00265 // destructor 
00266 // ============================================================================
00267 DataOnDemandSvc::~DataOnDemandSvc() 
00268 { if ( 0 != m_log      ) { delete m_log      ; m_log      = 0 ; } }
00269 //=============================================================================
00270 // Inherited Service overrides:
00271 //=============================================================================
00272 StatusCode DataOnDemandSvc::initialize() 
00273 {
00274   // initialize the Service Base class
00275   StatusCode sc = Service::initialize();
00276   if ( sc.isFailure() )  { return sc; }
00277   sc = setup();
00278   if ( sc.isFailure() )  { return sc; }
00279   //
00280   if      ( m_dump )                      { dump ( MSG::INFO  ) ; }
00281   else if ( MSG::DEBUG >= outputLevel() ) { dump ( MSG::DEBUG ) ; }
00282   //
00283   return StatusCode::SUCCESS ;
00284 }
00285 // ============================================================================
00286 /* dump the content of DataOnDemand service 
00287  *  @param level the printout level
00288  *  @param mode  the printout mode 
00289  */
00290 // ============================================================================
00291 void DataOnDemandSvc::dump
00292 ( const MSG::Level level , 
00293   const bool       mode  )  const 
00294 {
00295   if ( m_algs.empty()  &&  m_nodes.empty() ) { return ; }
00296 
00297   typedef std::pair<std::string,std::string> Pair ;
00298   typedef std::map<std::string,Pair>         PMap ;
00299   
00300   PMap _m ;
00301   for ( AlgMap::const_iterator alg = m_algs.begin() ; 
00302         m_algs.end() != alg ; ++alg )
00303   {
00304     PMap::const_iterator check = _m.find(alg->first) ;
00305     if ( _m.end() != check ) 
00306     { 
00307       stream() 
00308         << MSG::WARNING 
00309         << " The data item is activated for '"
00310         << check->first << "' as '" << check->second.first << "'" << endreq ;
00311     }
00312     const Leaf& l = alg->second ;
00313     std::string nam = ( l.name == l.type ? l.type  : (l.type+"/"+l.name) ) ;
00314     //
00315     if ( !mode && 0 == l.num ) { continue ; }
00316     //
00317     std::string val ;
00318     if ( mode ) { val = ( 0 == l.algorithm ) ? "F" : "T" ; }
00319     else { val = boost::lexical_cast<std::string>( l.num ) ; }
00320     //
00321     _m[ no_prefix ( alg->first , m_prefix ) ] = std::make_pair ( nam , val ) ;
00322   }
00323   // nodes:
00324   for ( NodeMap::const_iterator node = m_nodes.begin() ; 
00325         m_nodes.end() != node ; ++node )
00326   {
00327     PMap::const_iterator check = _m.find(node->first) ;
00328     if ( _m.end() != check ) 
00329     {
00330       stream()
00331         << MSG::WARNING 
00332         << " The data item is already activated for '"
00333         << check->first << "' as '" << check->second.first << "'" << endreq ;
00334     }
00335     const Node& n = node->second ;
00336     std::string nam = "'" + n.name + "'"  ; 
00337     //
00338     std::string val ;
00339 
00340     if ( !mode && 0 == n.num ) { continue ; }
00341     
00342     if ( mode ) { val = ( 0 == n.clazz ) ? "F" : "T" ; }
00343     else { val = boost::lexical_cast<std::string>( n.num ) ; }    
00344     //
00345     _m[ no_prefix ( node->first , m_prefix ) ] = std::make_pair ( nam , val ) ;
00346   }
00347   //
00348   if ( _m.empty() ) { return ; }
00349   
00350   // find the correct formats 
00351   size_t n1 = 0 ;
00352   size_t n2 = 0 ;
00353   size_t n3 = 0 ;
00354   for  ( PMap::const_iterator it = _m.begin() ; _m.end() != it ; ++it ) 
00355   {
00356     n1 = std::max ( n1 , it->first.size()         ) ;
00357     n2 = std::max ( n2 , it->second.first.size()  ) ;    
00358     n3 = std::max ( n3 , it->second.second.size() ) ;
00359   }
00360   if ( 10 > n1 ) { n1 = 10 ; } 
00361   if ( 10 > n2 ) { n2 = 10 ; } 
00362   if ( 60 < n1 ) { n1 = 60 ; } 
00363   if ( 60 < n2 ) { n2 = 60 ; } 
00364   //
00365   
00366   const std::string _f = " | %%1$-%1%.%1%s | %%2$-%2%.%2%s | %%3$%3%.%3%s |" ;
00367   boost::format _ff ( _f ) ;
00368   _ff % n1 % n2 % n3 ;
00369   
00370   const std::string _format  = _ff.str() ;
00371   
00372   MsgStream& msg = stream() << level ;
00373   
00374   if ( mode ) { msg << "Data-On-Demand Actions enabled for:"       ; }
00375   else        { msg << "Data-On-Demand Actions has been used for:" ; }
00376   
00377   boost::format fmt1( _format)  ;
00378   fmt1 % "Address" % "Creator" % ( mode ? "S" : "#" ) ;
00379   //
00380   const std::string header = fmt1.str() ;
00381   std::string line = std::string( header.size() , '-' ) ;
00382   line[0] = ' ' ;
00383   
00384   msg << std::endl << line 
00385       << std::endl << header 
00386       << std::endl << line ;
00387   
00388   // make the actual printout:
00389   for ( PMap::const_iterator item = _m.begin() ; 
00390         _m.end() != item ; ++item ) 
00391   {    
00392     boost::format fmt( _format)  ;
00393     msg << std::endl << 
00394       ( fmt % item->first % item->second.first % item->second.second ) ;
00395   }
00396   
00397   msg << std::endl << line << endreq ;
00398 
00399 }  
00400 // ============================================================================
00401 // finalization of the service 
00402 // ============================================================================
00403 StatusCode DataOnDemandSvc::finalize() 
00404 {
00405   //
00406   stream ()
00407     << MSG::INFO 
00408     << "Handled \"" << m_trapType << "\" incidents: "
00409     << m_statAlg  << "/" << m_statNode << "/" << m_stat << "(Alg/Node/Total)."
00410     << endreq ;
00411   if ( m_dump || MSG::DEBUG >= outputLevel() ) 
00412   {
00413     stream ()
00414       << MSG::INFO 
00415       << m_total.outputUserTime 
00416       ( "Algorithm timing: Mean(+-rms)/Min/Max:%3%(+-%4%)/%6%/%7%[ms] " , System::milliSec ) 
00417       << m_total.outputUserTime ( "Total:%2%[s]" , System::Sec ) << endreq ;  
00418   }
00419   // dump it! 
00420   if      ( m_dump )                      { dump ( MSG::INFO  , false ) ; }
00421   else if ( MSG::DEBUG >= outputLevel() ) { dump ( MSG::DEBUG , false ) ; }
00422   //
00423   if ( m_incSvc )  
00424   {
00425     m_incSvc->removeListener(this, m_trapType);
00426     m_incSvc->release();
00427     m_incSvc = 0;
00428   }
00429   if ( 0 != m_algMgr  ) { m_algMgr   -> release () ; m_algMgr  = 0 ; }
00430   if ( 0 != m_dataSvc ) { m_dataSvc  -> release () ; m_dataSvc = 0 ; }
00431   //
00432   return Service::finalize();
00433 }
00434 // ============================================================================
00436 // ============================================================================
00437 StatusCode DataOnDemandSvc::reinitialize() 
00438 {
00439   // reinitialize the Service Base class
00440   if ( 0 != m_incSvc )  
00441   {
00442     m_incSvc -> removeListener ( this , m_trapType );
00443     m_incSvc -> release ();
00444     m_incSvc = 0;
00445   }
00446   if ( 0 != m_algMgr  ) { m_algMgr   -> release() ; m_algMgr  = 0 ; }
00447   if ( 0 != m_dataSvc ) { m_dataSvc  -> release() ; m_dataSvc = 0 ; }
00448   if ( 0 != m_log     ) { delete m_log ; m_log = 0 ; }
00449   //
00450   StatusCode sc = Service::reinitialize();
00451   if ( sc.isFailure() )  { return sc; }
00452   //
00453   sc = setup() ;
00454   if ( sc.isFailure() )  { return sc; }
00455   //
00456   if ( m_dump ) { dump ( MSG::INFO ) ; }
00457   else if ( MSG::DEBUG >= outputLevel() ) { dump ( MSG::DEBUG  ) ; }
00458   //
00459   return StatusCode::SUCCESS ;
00460 }
00461 // ============================================================================
00462 // query interface 
00463 // ============================================================================
00464 StatusCode DataOnDemandSvc::queryInterface
00465 ( const InterfaceID& riid, 
00466   void** ppvInterface ) 
00467 {
00468   if ( IIncidentListener::interfaceID() == riid )    
00469   {
00470     *ppvInterface = static_cast<IIncidentListener*>(this);
00471     addRef();
00472     return StatusCode::SUCCESS;
00473   }
00474   // Interface is not directly available: try out a base class
00475   return Service::queryInterface(riid, ppvInterface);
00476 }
00477 // ============================================================================
00478 // setup service 
00479 // ============================================================================
00480 StatusCode DataOnDemandSvc::setup() 
00481 {
00482   m_algMgr = 0;
00483   StatusCode sc = 
00484     serviceLocator()->queryInterface(IID_IAlgManager, pp_cast<void>(&m_algMgr));
00485   if ( sc.isFailure () )  
00486   {
00487     stream() 
00488       << MSG::ERROR
00489       << "Failed to retrieve the IAlgManager interface." << endmsg;
00490     return sc;
00491   }
00492   sc = service("IncidentSvc", m_incSvc, true);
00493   if ( sc.isFailure () )  
00494   {
00495     stream() 
00496       << MSG::ERROR << "Failed to retrieve Incident service." << endmsg;
00497     return sc;
00498   }
00499   m_incSvc->addListener(this, m_trapType);
00500   sc = service(m_dataSvcName, m_dataSvc, true);
00501   if ( sc.isFailure () )  
00502   {
00503     stream() 
00504       << MSG::ERROR
00505       << "Failed to retrieve the data provider interface of "
00506       << m_dataSvcName << endmsg;
00507     return sc;
00508   }
00509   return update() ;
00510 }
00511 // ============================================================================
00512 // setup node handlers 
00513 // ============================================================================
00514 StatusCode DataOnDemandSvc::setupNodeHandlers()  
00515 {
00516   Setup::const_iterator j;
00517   std::string nam, typ, tag;
00518   StatusCode sc = StatusCode::SUCCESS;
00519   // Setup for node leafs, where simply a constructor is called...
00520   for ( j=m_nodeMapping.begin(); j != m_nodeMapping.end(); ++j) 
00521   {
00522     Tokenizer tok(true);
00523     tok.analyse(*j, " ", "", "", "=", "'", "'");
00524     for ( Tokenizer::Items::iterator i = tok.items().begin(); 
00525           i != tok.items().end(); i++ )   {
00526       const std::string& t = (*i).tag();
00527       const std::string& v = (*i).value();
00528       switch( ::toupper(t[0]) )    {
00529       case 'D':
00530         tag = v;
00531         break;
00532       case 'T':
00533         nam = v;
00534         break;
00535       }
00536     } 
00537     if ( m_algMap  .end () != m_algMap  .find ( tag ) || 
00538          m_nodeMap .end () != m_nodeMap .find ( tag ) )
00539     {
00540       stream() 
00541         << MSG::WARNING 
00542         << "The obsolete property 'Nodes' redefines the action for '" 
00543         + tag + "' to be '" +nam+"'"
00544         << endreq ;
00545     }
00546     m_nodeMap[tag] = nam ; 
00547   }
00548   //
00549   m_updateRequired = true ;
00550   //
00551   return sc;
00552 }
00553 // ============================================================================
00554 // setup algorithm  handlers 
00555 // ============================================================================
00556 StatusCode DataOnDemandSvc::setupAlgHandlers()  
00557 {
00558   Setup::const_iterator j;
00559   std::string typ, tag;
00560   
00561   for(j=m_algMapping.begin(); j != m_algMapping.end(); ++j)  
00562   {
00563     Tokenizer tok(true);
00564     tok.analyse(*j, " ", "", "", "=", "'", "'");
00565     for(Tokenizer::Items::iterator i = tok.items().begin(); i != tok.items().end(); i++ )   {
00566       const std::string& t = (*i).tag();
00567       const std::string& v = (*i).value();
00568       switch( ::toupper(t[0]) )    {
00569       case 'D':
00570         tag = v;
00571         break;
00572       case 'T':
00573         typ = v;
00574         break;
00575       }
00576     }
00577     ListItem item(typ);
00578     if ( m_algMap  .end () != m_algMap  .find ( tag ) || 
00579          m_nodeMap .end () != m_nodeMap .find ( tag ) )
00580     {
00581       stream() 
00582         << MSG::WARNING 
00583         << "The obsolete property 'Algorithms' redefines the action for '" 
00584         + tag + "' to be '" +item.type() +"/"+item.name()+"'"
00585         << endreq ;
00586     }
00587     m_algMap[tag] = item.type() + "/" + item.name() ;
00588   }
00589   m_updateRequired = true ;
00590   return StatusCode::SUCCESS;
00591 }
00592 // ============================================================================
00594 // ============================================================================
00595 StatusCode DataOnDemandSvc::configureHandler(Leaf& l)  
00596 {
00597   if ( 0 == m_algMgr  ) { return StatusCode::FAILURE ; }
00598   StatusCode sc = m_algMgr->getAlgorithm(l.name, l.algorithm);
00599   if ( sc.isFailure() ) 
00600   {
00601     sc = m_algMgr->createAlgorithm(l.type, l.name, l.algorithm, true );
00602     if ( sc.isFailure() ) 
00603     {
00604       stream()  
00605         << MSG::ERROR 
00606         << "Failed to create algorithm "
00607         << l.type << "('" << l.name<< "')" << endmsg; 
00608     }
00609   }
00610   return sc;
00611 }
00612 // ===========================================================================
00614 // ===========================================================================
00615 void DataOnDemandSvc::handle ( const Incident& incident )
00616 { 
00617   ++m_stat ;
00618   // proper incident type? 
00619   if ( incident.type() != m_trapType ) { return ; }             // RETURN
00620   const DataIncident* inc = dynamic_cast<const DataIncident*>(&incident);
00621   if ( 0 == inc                      ) { return ; }             // RETURN
00622   // update if needed! 
00623   if ( m_updateRequired ) { update() ; }
00624   const std::string& tag = inc->tag();
00625   if ( MSG::VERBOSE >= outputLevel() ) 
00626   {
00627     stream()
00628       << MSG::VERBOSE 
00629       << "Incident: [" << incident.type   () << "] " 
00630       << " = "         << incident.source ()
00631       << " Location:"  << tag  << endmsg;
00632   }
00633   // ==========================================================================
00634   NodeMap::iterator icl = m_nodes.find ( tag ) ;
00635   if ( icl != m_nodes.end() )  
00636   {
00637     StatusCode sc = execHandler ( tag , icl->second ) ;
00638     if ( sc.isSuccess() ) { ++m_statNode ; } 
00639     return ;                                                        // RETURN 
00640   }
00641   // ==========================================================================
00642   AlgMap::iterator ialg = m_algs.find ( tag ) ;
00643   if ( ialg != m_algs.end() )  
00644   {
00645     StatusCode sc = execHandler ( tag , ialg->second ) ;
00646     if ( sc.isSuccess() ) { ++m_statAlg ; }
00647     return ;                                                        // RETURN 
00648   }
00649 }
00650 // ===========================================================================
00651 // ecxecute the handler 
00652 // ===========================================================================
00653 StatusCode 
00654 DataOnDemandSvc::execHandler(const std::string& tag, Node& n)  
00655 {
00656   if ( n.executing ) { return StatusCode::FAILURE ; }            // RETURN 
00657  
00658   // try to recover the handler 
00659   if ( !n.clazz  ) { n.clazz = ROOT::Reflex::Type::ByName(n.name) ; }
00660   if ( !n.clazz  ) 
00661   {
00662     stream() 
00663       << MSG::ERROR 
00664       << "Failed to get dictionary for class '"
00665       << n.name  
00666       << "' for location:" << tag << endmsg;
00667     return StatusCode::FAILURE ;                               // RETURN 
00668   }
00669   
00670   ROOT::Reflex::Object obj = n.clazz.Construct();
00671   DataObject* pO = (DataObject*)obj.Address();
00672   if ( !pO )
00673   {
00674     stream() 
00675       << MSG::ERROR 
00676       << "Failed to create an object of type:"
00677       << n.clazz.Name(ROOT::Reflex::SCOPED) << " for location:" << tag 
00678       << endmsg;  
00679     return StatusCode::FAILURE  ;                               // RETURN 
00680   }
00681   //
00682   Protection p(n.executing);
00683   StatusCode sc = m_dataSvc->registerObject(tag, pO);
00684   if ( sc.isFailure() ) 
00685   {
00686     stream() 
00687       << MSG::ERROR << "Failed to register an object of type:"
00688       << n.clazz.Name(ROOT::Reflex::SCOPED) << " at location:" << tag 
00689       << endmsg;
00690     return sc ;                                                  // RETURN 
00691   }
00692   ++n.num ;
00693   //
00694   return StatusCode::SUCCESS ;
00695 }
00696 // ===========================================================================
00697 // execute the handler 
00698 // ===========================================================================
00699 StatusCode 
00700 DataOnDemandSvc::execHandler(const std::string& tag, Leaf& l)  
00701 {
00702   //
00703   if ( l.executing ) { return StatusCode::FAILURE ; }             // RETURN  
00704   //
00705   if ( 0 == l.algorithm ) 
00706   {
00707     StatusCode sc = configureHandler ( l ) ;
00708     if ( sc.isFailure() ) 
00709     {
00710       stream()  
00711         << MSG::ERROR 
00712         << "Failed to configure handler for: "
00713         << l.name << "[" << l.type << "] " << tag << endmsg; 
00714       return sc ;                                                 // RETURN 
00715     }
00716   }
00717   //
00718   Timer timer ( m_total ) ;
00719   //
00720   Protection p(l.executing);
00721   StatusCode sc = l.algorithm->sysExecute();
00722   if ( sc.isFailure() )  
00723   {
00724     stream() << MSG::ERROR 
00725              << "Failed to execute the algorithm:"
00726              << l.algorithm->name() << " for location:" << tag << endmsg;
00727     return sc ;                                                       // RETURN 
00728   }
00729   ++l.num ;
00730   //
00731   return StatusCode::SUCCESS ;
00732 }
00733 // ============================================================================
00737 DECLARE_SERVICE_FACTORY(DataOnDemandSvc)
00738 // ============================================================================
00739   
00740 // ============================================================================
00741 // The END 
00742 // ============================================================================

Generated at Thu Jan 8 17:44:23 2009 for Gaudi Framework, version v20r4 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004