![]() |
|
|
Generated: 18 Jul 2008 |
00001 // $Id: GaudiCommonImp.h,v 1.10 2008/01/18 15:11:17 marcocle Exp $ 00002 // ============================================================================ 00003 #ifndef GAUDIALG_GAUDICOMMONIMP_H 00004 #define GAUDIALG_GAUDICOMMONIMP_H 1 00005 // ============================================================================ 00006 // Include files 00007 // ============================================================================ 00008 // GaudiAlg 00009 // ============================================================================ 00010 #include "GaudiAlg/GaudiCommon.h" 00011 // ============================================================================ 00012 00013 // ============================================================================ 00021 // ============================================================================ 00022 00023 // ============================================================================ 00024 // Returns the full correct event location given the rootInTes settings 00025 // ============================================================================ 00026 template < class PBASE > 00027 inline const std::string 00028 GaudiCommon<PBASE>::fullTESLocation( const std::string & location, 00029 const bool useRootInTES ) const 00030 { 00031 // The logic is: 00032 // if no R.I.T., give back location 00033 // if R.I.T., this is the mapping: 00034 // (note that R.I.T. contains a trailing '/') 00035 // location -> result 00036 // ------------------------------------------------- 00037 // "" -> R.I.T.[:-1] ("rit") 00038 // "/Event" -> R.I.T.[:-1] ("rit") 00039 // "/Event/MyObj" -> R.I.T. + "MyObj" ("rit/MyObj") 00040 // "MyObj" -> R.I.T. + "MyObj" ("rit/MyObj") 00041 return ( !useRootInTES || rootInTES().empty() ? 00042 location 00043 : 00044 location.empty() || ( location == "/Event" ) ? 00045 rootInTES().substr(0,rootInTES().size()-1) 00046 : 00047 0 == location.find("/Event/") ? 00048 rootInTES() + location.substr(7) 00049 : 00050 rootInTES() + location ); 00051 } 00052 // ============================================================================ 00053 00054 // ============================================================================ 00055 // Templated access to the data in Gaudi Transient Store 00056 // ============================================================================ 00057 template < class PBASE > 00058 template < class TYPE > 00059 inline TYPE* GaudiCommon<PBASE>::get( IDataProviderSvc* service , 00060 const std::string& location, 00061 const bool useRootInTES ) const 00062 { 00063 // check the environment 00064 Assert( 0 != service , "get():: IDataProvider* points to NULL!" ) ; 00065 const std::string & fullLoc = fullTESLocation( location, useRootInTES ); 00066 SmartDataPtr<TYPE> obj( service , fullLoc ) ; 00067 //if ( !obj ) { Exception ( "get():: No valid data at '" + fullLoc + "'" ) ; } 00068 TYPE* aux = obj ; 00069 if ( !aux ) { Exception ( "get():: No valid data at '" + fullLoc + "'" ) ; } 00070 if ( msgLevel( MSG::DEBUG ) ) 00071 { this-> debug() << "The object of type '" 00072 << System::typeinfoName(typeid(*aux)) 00073 << "' has been retrieved from TS at address '" 00074 << fullLoc << "'" << endreq ; } 00075 // return located *VALID* data 00076 return aux ; 00077 } 00078 // ============================================================================ 00079 00080 // ============================================================================ 00081 // check the existence of objects in Gaudi Transient Store 00082 // ============================================================================ 00083 template < class PBASE > 00084 template < class TYPE > 00085 inline bool GaudiCommon<PBASE>::exist( IDataProviderSvc* service , 00086 const std::string& location , 00087 const bool useRootInTES ) const 00088 { 00089 // check the environment 00090 Assert( 0 != service , "exist():: IDataProvider* points to NULL!" ) ; 00091 // check the data object 00092 const std::string & fullLoc = fullTESLocation( location, useRootInTES ); 00093 SmartDataPtr<TYPE> obj( service , fullLoc ) ; 00094 return obj ? true : false ; 00095 } 00096 // ============================================================================ 00097 00098 // ============================================================================ 00099 // get the existing object from Gaudi Event Transient store 00100 // or create new object register in in TES and return if object 00101 // does not exist 00102 // ============================================================================ 00103 template <class PBASE> 00104 template <class TYPE,class TYPE2> 00105 inline TYPE* GaudiCommon<PBASE>::getOrCreate( IDataProviderSvc* svc , 00106 const std::string& location , 00107 const bool useRootInTES ) const 00108 { 00109 // check the environment 00110 Assert( 0 != svc , "getOrCreate():: svc points to NULL!" ) ; 00111 const std::string & fullLoc = fullTESLocation( location, useRootInTES ); 00112 SmartDataPtr<TYPE> obj ( svc , fullLoc ) ; 00113 if ( !obj ) 00114 { 00115 TYPE2* o = new TYPE2() ; 00116 put ( svc , o , location ) ; // do not use fullLoc here as put recreates it 00117 return o ; 00118 } 00119 TYPE* aux = obj ; 00120 if( !aux ) 00121 { Exception ( "getOrCreate():: No valid data at '" + fullLoc + "'" ) ; } 00122 // return located *VALID* data 00123 return aux ; 00124 } 00125 // ============================================================================ 00126 00127 // ============================================================================ 00128 // the useful method for location of tools. 00129 // ============================================================================ 00130 template < class PBASE > 00131 template < class TOOL > 00132 inline TOOL* GaudiCommon<PBASE>::tool( const std::string& type , 00133 const std::string& name , 00134 const IInterface* parent , 00135 bool create ) const 00136 { 00137 TOOL* Tool = 0 ; 00138 // for empty names delegate to another method 00139 if ( name.empty() ) 00140 { 00141 Tool = tool<TOOL>( type , parent , create ) ; 00142 } 00143 else 00144 { 00145 Assert( 0 != this->toolSvc() , "tool():: IToolSvc* points to NULL!" ) ; 00146 // get the tool from Tool Service 00147 const StatusCode sc = 00148 this->toolSvc()->retrieveTool ( type , name , Tool , parent , create ) ; 00149 if ( sc.isFailure() ) 00150 { Exception("tool():: Could not retrieve Tool '" + type + "'/'" + name + "'", sc ) ; } 00151 if ( 0 == Tool ) 00152 { Exception("tool():: Could not retrieve Tool '" + type + "'/'" + name + "'" ) ; } 00153 // add the tool into list of known tools to be properly released 00154 addToToolList( Tool ); 00155 } 00156 // return *VALID* located tool 00157 return Tool ; 00158 } 00159 // ============================================================================ 00160 00161 // ============================================================================ 00162 // the useful method for location of tools. 00163 // ============================================================================ 00164 template < class PBASE > 00165 template < class TOOL > 00166 inline TOOL* GaudiCommon<PBASE>::tool( const std::string& type , 00167 const IInterface* parent , 00168 bool create ) const 00169 { 00170 // check the environment 00171 Assert ( 0 != PBASE::toolSvc() , "IToolSvc* points to NULL!" ); 00172 // retrieve the tool from Tool Service 00173 TOOL* Tool = 0 ; 00174 const StatusCode sc = 00175 this->toolSvc() -> retrieveTool ( type, Tool, parent , create ); 00176 if ( sc.isFailure() ) 00177 { Exception("tool():: Could not retrieve Tool '" + type + "'", sc ) ; } 00178 if ( 0 == Tool ) 00179 { Exception("tool():: Could not retrieve Tool '" + type + "'" ) ; } 00180 // add the tool into the list of known tools to be properly released 00181 addToToolList( Tool ); 00182 // return *VALID* located tool 00183 return Tool ; 00184 } 00185 // ============================================================================ 00186 00187 // ============================================================================ 00188 // the useful method for location of services 00189 // ============================================================================ 00190 template < class PBASE > 00191 template < class SERVICE > 00192 inline SERVICE* GaudiCommon<PBASE>::svc( const std::string& name , 00193 const bool create ) const 00194 { 00195 SERVICE* s = 0 ; 00196 Assert ( 0 != this->svcLoc() , "ISvcLocator* points to NULL!" ); 00197 // retrieve the service using templated method Algorithm::service 00198 StatusCode sc = this->svcLoc() -> service( name , s , create ) ; 00199 // check the results 00200 if ( sc.isFailure() ) 00201 { Exception ( "svc():: Could not retrieve Svc '" + name + "'", sc ) ; } 00202 if ( 0 == s ) 00203 { Exception ( "svc():: Could not retrieve Svc '" + name + "'" ) ; } 00204 // add the tool into list of known tools, to be properly released 00205 addToServiceList( s, name ) ; 00206 // return *VALID* located service 00207 return s ; 00208 } 00209 // ============================================================================ 00210 00211 // ============================================================================ 00212 // Short-cut to get a pointer to the UpdateManagerSvc 00213 // ============================================================================ 00214 template <class PBASE> 00215 inline IUpdateManagerSvc * 00216 GaudiCommon<PBASE>::updMgrSvc() const 00217 { 00218 if ( !m_updMgrSvc ) 00219 { m_updMgrSvc = svc<IUpdateManagerSvc>("UpdateManagerSvc",true); } 00220 return m_updMgrSvc ; 00221 } 00222 // ============================================================================ 00223 00224 // ============================================================================ 00225 // Short-cut to get a pointer to the 00226 // ============================================================================ 00227 template <class PBASE> 00228 inline IDataProviderSvc * 00229 GaudiCommon<PBASE>::fastContainersSvc() const 00230 { 00231 if ( !m_fastContainersSvc ) 00232 { m_fastContainersSvc = svc<IDataProviderSvc>("FastContainersSvc",true); } 00233 return m_fastContainersSvc ; 00234 } 00235 00236 // ============================================================================ 00237 // Get a fast container 00238 // ============================================================================ 00239 template < class PBASE > 00240 template < class T > 00241 inline TransientFastContainer<T> * 00242 GaudiCommon<PBASE>::getFastContainer( const std::string &location, 00243 typename TransientFastContainer<T>::size_type initial ) 00244 { 00245 typedef TransientFastContainer<T> container_type; 00246 00247 IDataProviderSvc* svc = fastContainersSvc(); 00248 Assert( 0 != svc , "getFastContainer(): cannot get FastContainersSvc" ); 00249 00250 container_type *ptr = NULL; 00251 SmartDataPtr<container_type> obj( svc, location ); 00252 if (!obj){ 00253 ptr = new container_type(initial); 00254 StatusCode status = svc->registerObject(location,ptr); 00255 if ( !status.isSuccess() ){ 00256 Exception("getFastContainer(): cannot register '" + 00257 System::typeinfoName( typeid( *ptr ) ) + 00258 "' at address '" + location + "'" , status ); 00259 } 00260 } else { 00261 ptr = obj; 00262 if ( !ptr ){ 00263 Exception("getFastContainer(): No valid container at '" + location + "'"); 00264 } 00265 } 00266 00267 return ptr; 00268 } 00269 // ============================================================================ 00270 00271 // ============================================================================ 00272 // predefined configurable message stream for the effective printouts 00273 // ============================================================================ 00274 template <class PBASE> 00275 inline MsgStream& 00276 GaudiCommon<PBASE>::msgStream ( const MSG::Level level ) const 00277 { 00278 if ( !m_msgStream ) 00279 { m_msgStream = new MsgStream ( PBASE::msgSvc() , this->name() ) ; } 00280 return *m_msgStream << level ; 00281 } 00282 // ============================================================================ 00283 00284 // ============================================================================ 00285 // Assertion - throw exception, if condition is not fulfilled 00286 // ============================================================================ 00287 template <class PBASE> 00288 inline StatusCode GaudiCommon<PBASE>::Assert( const bool OK , 00289 const std::string& msg , 00290 const StatusCode sc ) const 00291 { 00292 return ( OK ? StatusCode(StatusCode::SUCCESS, true) : Exception( msg , sc ) ) ; 00293 } 00294 // ============================================================================ 00295 00296 // ============================================================================ 00297 // Delete the current message stream object 00298 // ============================================================================ 00299 template <class PBASE> 00300 inline void GaudiCommon<PBASE>::resetMsgStream() const 00301 { 00302 if ( 0 != m_msgStream ) { delete m_msgStream; m_msgStream = 0; } 00303 } 00304 // ============================================================================ 00305 00306 // ============================================================================ 00307 // Assertion - throw exception, if condition is not fulfilled 00308 // ============================================================================ 00309 template <class PBASE> 00310 inline StatusCode 00311 GaudiCommon<PBASE>::Assert( const bool OK , 00312 const char* msg , 00313 const StatusCode sc ) const 00314 { 00315 return OK ? StatusCode(StatusCode::SUCCESS, true) : Exception( msg , sc ) ; 00316 } 00317 // ============================================================================ 00318 00319 // ============================================================================ 00333 // ============================================================================ 00334 #define ALG_ERROR( message , code ) \ 00335 ( Error( message + \ 00336 std::string ( " [ at line " ) + \ 00337 GaudiAlg::fileLine ( __LINE__ ) + \ 00338 std::string ( " in file '" ) + \ 00339 std::string ( __FILE__ ) + "']" , code ) ) 00340 00341 // ============================================================================ 00342 00343 #endif // GAUDIALG_GAUDICOMMONIMP_H