00001
00002
00003
00004
00005
00006
00007 #include <ostream>
00008 #include <sstream>
00009
00010
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
00022
00023 #include "Kernel/Inspectors.h"
00024
00025
00026
00027 #include "boost/format.hpp"
00028
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 void Gaudi::Utils::properties
00046 ( const IInterface* cmp ,
00047 const Gaudi::Utils::Names& names ,
00048 Gaudi::Utils::Properties& output )
00049 {
00050
00051 output.clear () ;
00052
00053 if ( 0 == cmp || names.empty() ) { return ; }
00054
00055 for ( Gaudi::Utils::Names::const_iterator item = names.begin() ;
00056 names.end() != item ; ++item )
00057 {
00058
00059 const Property* p = Gaudi::Utils::getProperty ( cmp , *item ) ;
00060 if ( 0 == p ) { continue ; }
00061
00062 output.push_back ( p ) ;
00063 }
00064 }
00065
00066
00067
00068
00069
00070
00071
00072
00073
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 ;
00084 }
00085
00086
00087
00088 namespace
00089 {
00090
00091 const std::string s_fmt1 = "%-2d%s%-30.30s%|45t|%-30.30s" ;
00092
00093 const std::string s_fmt2 = "%s%|65t|%s" ;
00094
00095 }
00096
00097
00098
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
00112
00113
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 ) ; }
00131
00132
00133 boost::format fmt1 ( s_fmt1 ) ;
00134
00135 fmt1 % level ;
00136 fmt1 % std::string( 3*level + 1 , ' ' ) ;
00137 {
00138
00139 IInterface* _cmp = const_cast<IInterface*> ( component ) ;
00140 SmartIF<INamedInterface> inamed ( _cmp ) ;
00141 if ( !inamed ){ fmt1 % "<UNKNOWN>" ; }
00142 else { fmt1 % inamed -> name () ; }
00143 }
00144 fmt1 % System::typeinfoName( typeid( *component ) ) ;
00145
00146 std::string part1 = fmt1.str() ;
00147
00148 Gaudi::Utils::Properties props = Gaudi::Utils::properties ( component , m_names ) ;
00149
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
00165 Gaudi::Utils::Properties members =
00166 Gaudi::Utils::properties ( component , m_members ) ;
00167
00168 if ( members.empty() )
00169 { return StatusCode ( StatusCode::SUCCESS , true ) ; }
00170
00171
00172 if ( !m_algMgr )
00173 {
00174 ISvcLocator* svcLoc = Gaudi::svcLocator () ;
00175 if ( 0 == svcLoc ) { return StatusCode ( 501 ) ; }
00176 m_algMgr = svcLoc ;
00177 }
00178 if ( !m_algMgr ) { return StatusCode ( 502 ) ; }
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 ; }
00185
00186 typedef std::vector<std::string> Members ;
00187 SimpleProperty<Members> vm ;
00188
00189 vm.assign ( *m ) ;
00190
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() ; }
00201 if ( 0 == alg ) { return 503 ; }
00202
00203
00204 sc = inspect ( alg , stream , level + 1 ) ;
00205 if ( sc.isFailure() ) { return sc ; }
00206 }
00207 }
00208
00209 return StatusCode( StatusCode::SUCCESS , true ) ;
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
00224
00225
00226
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
00241