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 bool GaudiCommon<PBASE>::exist( IDataProviderSvc* service ,
00073 const std::string& location ,
00074 const bool useRootInTES ) const
00075 {
00076
00077 Assert( 0 != service , "exist():: IDataProvider* points to NULL!" ) ;
00078
00079 Gaudi::Utils::CheckData<TYPE> checker ;
00080 return checker ( service,
00081 fullTESLocation ( location , useRootInTES ) ) ;
00082 }
00083
00084
00085
00086
00087
00088 template <class PBASE>
00089 template <class TYPE,class TYPE2>
00090 inline typename Gaudi::Utils::GetData<TYPE>::return_type
00091 GaudiCommon<PBASE>::getOrCreate( IDataProviderSvc* service ,
00092 const std::string& location ,
00093 const bool useRootInTES ) const
00094 {
00095
00096 Assert ( 0 != service , "getOrCreate():: svc points to NULL!" ) ;
00097
00098 Gaudi::Utils::GetOrCreateData<TYPE,TYPE2> getter ;
00099 return getter ( *this ,
00100 service ,
00101 fullTESLocation( location, useRootInTES ) ,
00102 location ) ;
00103 }
00104
00105
00106
00107 template < class PBASE >
00108 template < class TOOL >
00109 inline TOOL* GaudiCommon<PBASE>::tool( const std::string& type ,
00110 const std::string& name ,
00111 const IInterface* parent ,
00112 bool create ) const
00113 {
00114 TOOL* Tool = 0 ;
00115
00116 if ( name.empty() )
00117 {
00118 Tool = tool<TOOL>( type , parent , create ) ;
00119 }
00120 else
00121 {
00122 Assert( this->toolSvc() != 0, "tool():: IToolSvc* points to NULL!" ) ;
00123
00124 const StatusCode sc =
00125 this->toolSvc()->retrieveTool ( type , name , Tool , parent , create ) ;
00126 if ( sc.isFailure() )
00127 { Exception("tool():: Could not retrieve Tool '" + type + "'/'" + name + "'", sc ) ; }
00128 if ( 0 == Tool )
00129 { Exception("tool():: Could not retrieve Tool '" + type + "'/'" + name + "'" ) ; }
00130
00131 addToToolList( Tool );
00132 }
00133
00134 return Tool ;
00135 }
00136
00137
00138
00139 template < class PBASE >
00140 template < class TOOL >
00141 inline TOOL* GaudiCommon<PBASE>::tool( const std::string& type ,
00142 const IInterface* parent ,
00143 bool create ) const
00144 {
00145
00146 Assert ( PBASE::toolSvc() != 0, "IToolSvc* points to NULL!" );
00147
00148 TOOL* Tool = 0 ;
00149 const StatusCode sc =
00150 this->toolSvc() -> retrieveTool ( type, Tool, parent , create );
00151 if ( sc.isFailure() )
00152 { Exception("tool():: Could not retrieve Tool '" + type + "'", sc ) ; }
00153 if ( 0 == Tool )
00154 { Exception("tool():: Could not retrieve Tool '" + type + "'" ) ; }
00155
00156 addToToolList( Tool );
00157
00158 return Tool ;
00159 }
00160
00161
00162
00163 template < class PBASE >
00164 template < class SERVICE >
00165 inline SmartIF<SERVICE> GaudiCommon<PBASE>::svc( const std::string& name ,
00166 const bool create ) const
00167 {
00168 Assert ( this->svcLoc() != 0, "ISvcLocator* points to NULL!" );
00169 SmartIF<SERVICE> s;
00170
00171 Services::iterator it = m_services.find(name);
00172 if (it != m_services.end()) {
00173
00174 s = it->second;
00175
00176 if ( !s.isValid() ) {
00177 Exception ("svc():: Could not retrieve Svc '" + name + "'", StatusCode::FAILURE);
00178 }
00179 } else {
00180 SmartIF<IService>& baseSvc = this->svcLoc()->service(name, create);
00181
00182 s = baseSvc;
00183
00184 if ( !baseSvc.isValid() || !s.isValid() ) {
00185 Exception ("svc():: Could not retrieve Svc '" + name + "'", StatusCode::FAILURE);
00186 }
00187
00188 addToServiceList(baseSvc);
00189 }
00190
00191 return s;
00192 }
00193
00194
00195
00196 template <class PBASE>
00197 inline IUpdateManagerSvc *
00198 GaudiCommon<PBASE>::updMgrSvc() const
00199 {
00200 if ( !m_updMgrSvc )
00201 { m_updMgrSvc = svc<IUpdateManagerSvc>("UpdateManagerSvc",true); }
00202 return m_updMgrSvc ;
00203 }
00204
00205
00206
00207 template <class PBASE>
00208 inline IDataProviderSvc *
00209 GaudiCommon<PBASE>::fastContainersSvc() const
00210 {
00211 if ( !m_fastContainersSvc )
00212 { m_fastContainersSvc = svc<IDataProviderSvc>("FastContainersSvc",true); }
00213 return m_fastContainersSvc ;
00214 }
00215
00216
00217
00218 template < class PBASE >
00219 template < class T >
00220 inline TransientFastContainer<T> *
00221 GaudiCommon<PBASE>::getFastContainer( const std::string &location,
00222 typename TransientFastContainer<T>::size_type initial )
00223 {
00224 typedef TransientFastContainer<T> container_type;
00225
00226 IDataProviderSvc* svc = fastContainersSvc();
00227 Assert( 0 != svc , "getFastContainer(): cannot get FastContainersSvc" );
00228
00229 container_type *ptr = NULL;
00230 SmartDataPtr<container_type> obj( svc, location );
00231 if (!obj){
00232 ptr = new container_type(initial);
00233 StatusCode status = svc->registerObject(location,ptr);
00234 if ( !status.isSuccess() ){
00235 Exception("getFastContainer(): cannot register '" +
00236 System::typeinfoName( typeid( *ptr ) ) +
00237 "' at address '" + location + "'" , status );
00238 }
00239 } else {
00240 ptr = obj;
00241 if ( !ptr ){
00242 Exception("getFastContainer(): No valid container at '" + location + "'");
00243 }
00244 }
00245
00246 return ptr;
00247 }
00248
00249
00250
00251 template <class PBASE>
00252 inline MsgStream&
00253 GaudiCommon<PBASE>::msgStream ( const MSG::Level level ) const
00254 {
00255 if ( !m_msgStream )
00256 { m_msgStream = new MsgStream ( PBASE::msgSvc() , this->name() ) ; }
00257 return *m_msgStream << level ;
00258 }
00259
00260
00261
00262 template <class PBASE>
00263 inline void GaudiCommon<PBASE>::Assert( const bool ok ,
00264 const std::string& msg ,
00265 const StatusCode sc ) const
00266 {
00267 if (!ok) Exception( msg , sc );
00268 }
00269
00270
00271
00272 template <class PBASE>
00273 inline void GaudiCommon<PBASE>::resetMsgStream() const
00274 {
00275 if ( 0 != m_msgStream ) { delete m_msgStream; m_msgStream = 0; }
00276 }
00277
00278
00279
00280 template <class PBASE>
00281 inline void GaudiCommon<PBASE>::Assert( const bool ok ,
00282 const char* msg ,
00283 const StatusCode sc ) const
00284 {
00285 if (!ok) Exception( msg , sc );
00286 }
00287
00301
00302 #define ALG_ERROR( message , code ) \
00303 ( Error( message + \
00304 std::string ( " [ at line " ) + \
00305 GaudiAlg::fileLine ( __LINE__ ) + \
00306 std::string ( " in file '" ) + \
00307 std::string ( __FILE__ ) + "']" , code ) )
00308
00309
00310
00311
00312 #endif // GAUDIALG_GAUDICOMMONIMP_H