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