| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Inspectors.cpp

Go to the documentation of this file.
00001 // $Id: Inspectors.cpp,v 1.2 2008/08/03 16:46:38 ibelyaev Exp $
00002 // ============================================================================
00003 // Include files 
00004 // ============================================================================
00005 // STD & STL 
00006 // ============================================================================
00007 #include <ostream>
00008 #include <sstream>
00009 // ============================================================================
00010 // GaudiKernel
00011 // ============================================================================
00012 #include "GaudiKernel/System.h"
00013 #include "GaudiKernel/Property.h"
00014 #include "GaudiKernel/INamedInterface.h"
00015 #include "GaudiKernel/IAlgorithm.h"
00016 #include "GaudiKernel/ListItem.h"
00017 #include "GaudiKernel/IAlgManager.h"
00018 #include "GaudiKernel/ISvcLocator.h"
00019 #include "GaudiKernel/Bootstrap.h"
00020 // ============================================================================
00021 // LHcbKernel
00022 // ============================================================================
00023 #include "Kernel/Inspectors.h"
00024 // ============================================================================
00025 // Boost
00026 // ============================================================================
00027 #include "boost/format.hpp"
00028 // ============================================================================
00034 // ============================================================================
00035 /*  simple function to extract from the given component 
00036  *  the list of properties, specified by name
00037  *
00038  *  @param cmp the component 
00039  *  @param name list of property names 
00040  *  @param output (OUTPUT) the list of properties 
00041  *  @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl
00042  *  @date 2008-08-02
00043  */
00044 // ============================================================================
00045 void Gaudi::Utils::properties
00046 ( const IInterface*          cmp    , 
00047   const Gaudi::Utils::Names& names  , 
00048   Gaudi::Utils::Properties&  output ) 
00049 {
00050   // 1) clear the output container 
00051   output.clear () ;
00052   // 2) check arguments 
00053   if ( 0 == cmp || names.empty() ) { return ; }                      // RETURN 
00054   // 3) fill the output container
00055   for ( Gaudi::Utils::Names::const_iterator item = names.begin() ; 
00056         names.end() != item ; ++item ) 
00057   {
00058     // get the property
00059     const Property* p = Gaudi::Utils::getProperty ( cmp , *item ) ;
00060     if ( 0 == p ) { continue ; }                                    // CONTINUE 
00061     // put the proeprty into the output container 
00062     output.push_back ( p ) ;
00063   }
00064 }
00065 // ============================================================================
00066 /* simple function to extract from the given component 
00067  *  the list of properties, specified by name
00068  *
00069  *  @param cmp the component 
00070  *  @param name list of property names 
00071  *  @retutn the list of properties 
00072  *  @author Vanya BELYAEV Ivan.BElyaev@nikhef.nl
00073  *  @date 2008-08-02
00074  */
00075 // ============================================================================
00076 Gaudi::Utils::Properties 
00077 Gaudi::Utils::properties 
00078 ( const IInterface*          cmp   , 
00079   const Gaudi::Utils::Names& names ) 
00080 {
00081   Gaudi::Utils::Properties props ;
00082   Gaudi::Utils::properties ( cmp , names , props ) ;
00083   return props ;                                                     // RETURN 
00084 }
00085 // ============================================================================
00086 // Inspectors 
00087 // ============================================================================
00088 namespace 
00089 {
00090   // own printout             1   2 3             4  
00091   const std::string s_fmt1 = "%-2d%s%-30.30s%|45t|%-30.30s" ;
00092   // global layout            1       2
00093   const std::string s_fmt2 = "%s%|65t|%s" ;
00094   // ==========================================================================
00095 }
00096 // ============================================================================
00097 /*  constructor the list of properties 
00098  *  @param props   list of properties to be inspected 
00099  */
00100 // ============================================================================
00101 LHCb::Inspector::Inspector 
00102 ( const Gaudi::Utils::Names& props ) 
00103   : m_members () 
00104   , m_names   ( props ) 
00105   , m_algMgr  ()
00106 {
00107   m_members.push_back ( "Members" ) ;
00108   m_members.push_back ( "TopAlg"  ) ;  
00109 }
00110 // ============================================================================
00111 /* constructor the list of properties 
00112  *  @param props   list of properties to be inspected 
00113  *  @param members list of structural properties
00114  */
00115 // ============================================================================
00116 LHCb::Inspector::Inspector 
00117 ( const Gaudi::Utils::Names& props   ,    
00118   const Gaudi::Utils::Names& members ) 
00119   : m_members ( members ) 
00120   , m_names   ( props ) 
00121   , m_algMgr  ()
00122 {}
00123 // ============================================================================
00124 StatusCode  
00125 LHCb::Inspector::inspect 
00126 ( const IInterface*      component , 
00127   std::ostream&          stream    , 
00128   const size_t           level     ) const 
00129 {
00130   if ( 0 == component ) { return StatusCode ( 500 ) ; }               // REUTRN 
00131   // ==========================================================================
00132   // create the format object:
00133   boost::format fmt1 ( s_fmt1 ) ;
00134   // start the formatting 
00135   fmt1 % level ;                                            // 1) # level  
00136   fmt1 % std::string( 3*level + 1 , ' ' ) ;                 // 2) indentation 
00137   {
00138     // get the name 
00139     IInterface* _cmp = const_cast<IInterface*> ( component ) ;
00140     SmartIF<INamedInterface> inamed ( _cmp ) ;
00141     if ( !inamed ){ fmt1 % "<UNKNOWN>"       ; }
00142     else          { fmt1 % inamed -> name () ; }            // 3) name 
00143   }
00144   fmt1 % System::typeinfoName( typeid( *component ) ) ;     // 4) type 
00145   // ==========================================================================
00146   std::string part1 = fmt1.str() ;  
00147   // check own properties
00148   Gaudi::Utils::Properties props = Gaudi::Utils::properties ( component , m_names ) ; 
00149   // print properties
00150   if ( props.empty() ) 
00151   {
00152     boost::format fmt2 ( s_fmt2 ) ;
00153     fmt2 % part1 % "" ;
00154     stream << fmt2 << std::endl ;
00155   }
00156   for ( Gaudi::Utils::Properties::const_iterator ip = props.begin() ; 
00157         props.end() != ip ; ++ip ) 
00158   {
00159     boost::format fmt2 ( s_fmt2 ) ;
00160     fmt2 % part1 %  (**ip) ;
00161     stream << fmt2 << std::endl ;
00162     part1.clear() ;
00163   }
00164   // check the structural properties 
00165   Gaudi::Utils::Properties members = 
00166     Gaudi::Utils::properties ( component , m_members ) ;
00167   // no structural properties ?
00168   if ( members.empty() ) 
00169   { return StatusCode ( StatusCode::SUCCESS , true ) ; }            // REUTRN 
00170   //
00171   // at this point we need to get the algorithm manager 
00172   if ( !m_algMgr ) 
00173   {
00174     ISvcLocator* svcLoc = Gaudi::svcLocator () ;
00175     if ( 0 == svcLoc ) { return StatusCode ( 501 ) ; }                // REUTRN 
00176     m_algMgr = svcLoc ;
00177   }
00178   if ( !m_algMgr  ) { return StatusCode ( 502 ) ; }                   // RETURN
00179   //
00180   for ( Gaudi::Utils::Properties::const_iterator im = members.begin() ; 
00181         members.end() != im ; ++im ) 
00182   {
00183     const Property* m = *im ;
00184     if ( 0 == m ) { continue ; }                                 // CONTINUE 
00185     // get the property
00186     typedef std::vector<std::string> Members ;
00187     SimpleProperty<Members> vm ;
00188     // assign from the source:
00189     vm.assign ( *m ) ;                                    // ASSIGN PROPERTY
00190     // Loop over all "members" (or "TopAlgs") 
00191     const Members& vct = vm.value () ;
00192     for ( Members::const_iterator id = vct.begin() ; 
00193           vct.end () != id ; ++id ) 
00194     {
00196       ListItem item ( *id ) ;
00198       IAlgorithm* alg = 0 ;
00199       StatusCode sc = m_algMgr->getAlgorithm ( item.name() , alg ) ;
00200       if ( sc.isFailure() ) { return 510 + sc.getCode() ; }      // RETURN  
00201       if ( 0 == alg       ) { return 503                ; }      // RETURN 
00202       // 
00203       // start the recursion here!!
00204       sc = inspect  ( alg , stream , level + 1 ) ;
00205       if ( sc.isFailure() ) { return sc ; }                      // RETURN 
00206     } // end of the loop over "members/topalgs" 
00207   } // end of the loop over structural properties 
00208   //
00209   return StatusCode( StatusCode::SUCCESS , true ) ;              // RETURN 
00210 }
00211 // ============================================================================
00212 StatusCode LHCb::Inspector::setAlgManager 
00213 ( const IInterface* mgr ) 
00214 {
00215   if ( 0 == mgr ) { return StatusCode ( 504 ) ; }
00216   IInterface* _cmp = const_cast<IInterface*> ( mgr ) ;
00217   m_algMgr = _cmp ;
00218   return !m_algMgr ? 
00219     StatusCode ( 505 ) : 
00220     StatusCode ( StatusCode::SUCCESS , true ) ;
00221 }
00222 // ============================================================================
00223 /*  inspect the component 
00224  *  @param component the component to be inspected 
00225  *  @param level the recursion level
00226  *  @return the inspection result 
00227  */
00228 // ============================================================================
00229 std::string LHCb::Inspector::inspect 
00230 ( const IInterface* component , 
00231   const size_t      level     ) const 
00232 {
00233   std::ostringstream out ;
00234   StatusCode sc = inspect ( component , out , level ) ;
00235   if ( sc.isFailure() ) { out << "StatusCode: "  << sc << std::endl ; }
00236   return out.str() ;
00237 }
00238 
00239 // ============================================================================
00240 // The END 
00241 // ============================================================================
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:03:13 2011 for LHCbKernel by doxygen 1.4.7