00001
00002
00003 #ifndef GAUDIALG_GAUDICOMMONIMP_H
00004 #define GAUDIALG_GAUDICOMMONIMP_H 1
00005
00006
00007
00008
00009
00010 #include "GaudiAlg/GetData.h"
00011 #include "GaudiAlg/GaudiCommon.h"
00012
00020
00021
00022
00023 template < class PBASE >
00024 inline const std::string
00025 GaudiCommon<PBASE>::fullTESLocation( const std::string & location,
00026 const bool useRootInTES ) const
00027 {
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 return ( !useRootInTES || rootInTES().empty() ?
00039 location
00040 :
00041 location.empty() || ( location == "/Event" ) ?
00042 rootInTES().substr(0,rootInTES().size()-1)
00043 :
00044 0 == location.find("/Event/") ?
00045 rootInTES() + location.substr(7)
00046 :
00047 rootInTES() + location );
00048 }
00049
00050
00051
00052 template < class PBASE >
00053 template < class TYPE >
00054 inline typename Gaudi::Utils::GetData<TYPE>::return_type
00055 GaudiCommon<PBASE>::get( IDataProviderSvc* service ,
00056 const std::string& location,
00057 const bool useRootInTES ) const
00058 {
00059
00060 Assert( 0 != service , "get():: IDataProvider* points to NULL!" ) ;
00061
00062 Gaudi::Utils::GetData<TYPE> getter ;
00063 return getter ( *this ,
00064 service ,
00065 fullTESLocation ( location , useRootInTES ) ) ;
00066 }
00067
00068
00069
00070 template < class PBASE >
00071 template < class TYPE >
00072 inline typename Gaudi::Utils::GetData<TYPE>::return_type
00073 GaudiCommon<PBASE>::getIfExists( IDataProviderSvc* service ,
00074 const std::string& location,
00075 const bool useRootInTES ) const
00076 {
00077
00078 Assert( 0 != service , "get():: IDataProvider* points to NULL!" ) ;
00079
00080 Gaudi::Utils::GetData<TYPE> getter ;
00081 return getter ( *this ,
00082 service ,
00083 fullTESLocation ( location , useRootInTES ),
00084 false) ;
00085 }
00086
00087
00088
00089 template < class PBASE >
00090 template < class TYPE >
00091 inline bool GaudiCommon<PBASE>::exist( IDataProviderSvc* service ,
00092 const std::string& location ,
00093 const bool useRootInTES ) const
00094 {
00095
00096 Assert( 0 != service , "exist():: IDataProvider* points to NULL!" ) ;
00097
00098 Gaudi::Utils::CheckData<TYPE> checker ;
00099 return checker ( service,
00100 fullTESLocation ( location , useRootInTES ) ) ;
00101 }
00102
00103
00104
00105
00106
00107 template <class PBASE>
00108 template <class TYPE,class TYPE2>
00109 inline typename Gaudi::Utils::GetData<TYPE>::return_type
00110 GaudiCommon<PBASE>::getOrCreate( IDataProviderSvc* service ,
00111 const std::string& location ,
00112 const bool useRootInTES ) const
00113 {
00114
00115 Assert ( 0 != service , "getOrCreate():: svc points to NULL!" ) ;
00116
00117 Gaudi::Utils::GetOrCreateData<TYPE,TYPE2> getter ;
00118 return getter ( *this ,
00119 service ,
00120 fullTESLocation( location, useRootInTES ) ,
00121 location ) ;
00122 }
00123
00124
00125
00126 template < class PBASE >
00127 template < class TOOL >
00128 inline TOOL* GaudiCommon<PBASE>::tool( const std::string& type ,
00129 const std::string& name ,
00130 const IInterface* parent ,
00131 bool create ) const
00132 {
00133 TOOL* Tool = 0 ;
00134
00135 if ( name.empty() )
00136 {
00137 Tool = tool<TOOL>( type , parent , create ) ;
00138 }
00139 else
00140 {
00141 Assert( this->toolSvc() != 0, "tool():: IToolSvc* points to NULL!" ) ;
00142
00143 const StatusCode sc =
00144 this->toolSvc()->retrieveTool ( type , name , Tool , parent , create ) ;
00145 if ( sc.isFailure() )
00146 { Exception("tool():: Could not retrieve Tool '" + type + "'/'" + name + "'", sc ) ; }
00147 if ( 0 == Tool )
00148 { Exception("tool():: Could not retrieve Tool '" + type + "'/'" + name + "'" ) ; }
00149
00150 addToToolList( Tool );
00151 }
00152
00153 return Tool ;
00154 }
00155
00156
00157
00158 template < class PBASE >
00159 template < class TOOL >
00160 inline TOOL* GaudiCommon<PBASE>::tool( const std::string& type ,
00161 const IInterface* parent ,
00162 bool create ) const
00163 {
00164
00165 Assert ( PBASE::toolSvc() != 0, "IToolSvc* points to NULL!" );
00166
00167 TOOL* Tool = 0 ;
00168 const StatusCode sc =
00169 this->toolSvc() -> retrieveTool ( type, Tool, parent , create );
00170 if ( sc.isFailure() )
00171 { Exception("tool():: Could not retrieve Tool '" + type + "'", sc ) ; }
00172 if ( 0 == Tool )
00173 { Exception("tool():: Could not retrieve Tool '" + type + "'" ) ; }
00174
00175 addToToolList( Tool );
00176
00177 return Tool ;
00178 }
00179
00180
00181
00182 template < class PBASE >
00183 template < class SERVICE >
00184 inline SmartIF<SERVICE> GaudiCommon<PBASE>::svc( const std::string& name ,
00185 const bool create ) const
00186 {
00187 Assert ( this->svcLoc() != 0, "ISvcLocator* points to NULL!" );
00188 SmartIF<SERVICE> s;
00189
00190 Services::iterator it = m_services.find(name);
00191 if (it != m_services.end()) {
00192
00193 s = it->second;
00194
00195 if ( !s.isValid() ) {
00196 Exception ("svc():: Could not retrieve Svc '" + name + "'", StatusCode::FAILURE);
00197 }
00198 } else {
00199 SmartIF<IService>& baseSvc = this->svcLoc()->service(name, create);
00200
00201 s = baseSvc;
00202
00203 if ( !baseSvc.isValid() || !s.isValid() ) {
00204 Exception ("svc():: Could not retrieve Svc '" + name + "'", StatusCode::FAILURE);
00205 }
00206
00207 addToServiceList(baseSvc);
00208 }
00209
00210 return s;
00211 }
00212
00213
00214
00215 template <class PBASE>
00216 inline IUpdateManagerSvc *
00217 GaudiCommon<PBASE>::updMgrSvc() const
00218 {
00219 if ( !m_updMgrSvc )
00220 { m_updMgrSvc = svc<IUpdateManagerSvc>("UpdateManagerSvc",true); }
00221 return m_updMgrSvc ;
00222 }
00223
00224
00225
00226 template <class PBASE>
00227 inline MsgStream&
00228 GaudiCommon<PBASE>::msgStream ( const MSG::Level level ) const
00229 {
00230 if ( !m_msgStream )
00231 { m_msgStream = new MsgStream ( PBASE::msgSvc() , this->name() ) ; }
00232 return *m_msgStream << level ;
00233 }
00234
00235
00236
00237 template <class PBASE>
00238 inline void GaudiCommon<PBASE>::Assert( const bool ok ,
00239 const std::string& msg ,
00240 const StatusCode sc ) const
00241 {
00242 if (!ok) Exception( msg , sc );
00243 }
00244
00245
00246
00247 template <class PBASE>
00248 inline void GaudiCommon<PBASE>::resetMsgStream() const
00249 {
00250 if ( 0 != m_msgStream ) { delete m_msgStream; m_msgStream = 0; }
00251 }
00252
00253
00254
00255 template <class PBASE>
00256 inline void GaudiCommon<PBASE>::Assert( const bool ok ,
00257 const char* msg ,
00258 const StatusCode sc ) const
00259 {
00260 if (!ok) Exception( msg , sc );
00261 }
00262
00276
00277 #define ALG_ERROR( message , code ) \
00278 ( Error( message + \
00279 std::string ( " [ at line " ) + \
00280 GaudiAlg::fileLine ( __LINE__ ) + \
00281 std::string ( " in file '" ) + \
00282 std::string ( __FILE__ ) + "']" , code ) )
00283
00284
00285
00286
00287 #endif // GAUDIALG_GAUDICOMMONIMP_H