Gaudi Framework, version v23r4

Home   Generated: Mon Sep 17 2012

GaudiCommonImp.h

Go to the documentation of this file.
00001 // $Id: GaudiCommonImp.h,v 1.11 2008/10/10 08:06:33 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/GetData.h"
00011 #include "GaudiAlg/GaudiCommon.h"
00012 // ============================================================================
00020 // ============================================================================
00021 // Returns the full correct event location given the rootInTes settings
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   // The logic is:
00029   // if no R.I.T., give back location
00030   // if R.I.T., this is the mapping:
00031   // (note that R.I.T. contains a trailing '/')
00032   //  location       -> result
00033   //  -------------------------------------------------
00034   //  ""             -> R.I.T.[:-1]      ("rit")
00035   //  "/Event"       -> R.I.T.[:-1]      ("rit")
00036   //  "/Event/MyObj" -> R.I.T. + "MyObj" ("rit/MyObj")
00037   //  "MyObj"        -> R.I.T. + "MyObj" ("rit/MyObj")
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 // Templated access to the data in Gaudi Transient Store
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   // check the environment
00060   Assert( 0 != service ,    "get():: IDataProvider* points to NULL!"      ) ;
00061   // get the helper object:
00062   Gaudi::Utils::GetData<TYPE> getter ;
00063   return getter ( *this    ,
00064                   service  ,
00065                   fullTESLocation ( location , useRootInTES ) ) ;
00066 }
00067 // ============================================================================
00068 // Templated access to the data in Gaudi Transient Store, no check on the content
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   // check the environment
00078   Assert( 0 != service ,    "get():: IDataProvider* points to NULL!"      ) ;
00079   // get the helper object:
00080   Gaudi::Utils::GetData<TYPE> getter ;
00081   return getter ( *this    ,
00082                   service  ,
00083                   fullTESLocation ( location , useRootInTES ),
00084                   false) ;
00085 }
00086 // ============================================================================
00087 // check the existence of objects in Gaudi Transient Store
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   // check the environment
00096   Assert( 0 != service , "exist():: IDataProvider* points to NULL!"      ) ;
00097   // check the data object
00098   Gaudi::Utils::CheckData<TYPE> checker ;
00099   return checker ( service,
00100                    fullTESLocation ( location , useRootInTES ) ) ;
00101 }
00102 // ============================================================================
00103 // get the existing object from Gaudi Event Transient store
00104 // or create new object register in in TES and return if object
00105 // does not exist
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   // check the environment
00115   Assert ( 0 != service , "getOrCreate():: svc points to NULL!" ) ;
00116   // get the helper object
00117   Gaudi::Utils::GetOrCreateData<TYPE,TYPE2> getter ;
00118   return getter ( *this                                     ,
00119                   service                                   ,
00120                   fullTESLocation( location, useRootInTES ) ,
00121                   location                                  ) ;
00122 }
00123 // ============================================================================
00124 // the useful method for location of tools.
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   // for empty names delegate to another method
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     // get the tool from Tool Service
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     // add the tool into list of known tools to be properly released
00150     addToToolList( Tool );
00151   }
00152   // return *VALID* located tool
00153   return Tool ;
00154 }
00155 // ============================================================================
00156 // the useful method for location of tools.
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   // check the environment
00165   Assert ( PBASE::toolSvc() != 0, "IToolSvc* points to NULL!" );
00166   // retrieve the tool from Tool Service
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   // add the tool into the list of known tools to be properly released
00175   addToToolList( Tool );
00176   // return *VALID* located tool
00177   return Tool ;
00178 }
00179 // ============================================================================
00180 // the useful method for location of services
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   // check if we already have this service
00190   Services::iterator it = m_services.find(name);
00191   if (it != m_services.end()) {
00192     // Try to get the requested interface
00193     s = it->second;
00194     // check the results
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     // Try to get the requested interface
00201     s = baseSvc;
00202     // check the results
00203     if ( !baseSvc.isValid() || !s.isValid() ) {
00204       Exception ("svc():: Could not retrieve Svc '" + name + "'", StatusCode::FAILURE);
00205     }
00206     // add the tool into list of known tools, to be properly released
00207     addToServiceList(baseSvc);
00208   }
00209   // return *VALID* located service
00210   return s;
00211 }
00212 // ============================================================================
00213 // Short-cut  to get a pointer to the UpdateManagerSvc
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 // predefined configurable message stream for the effective printouts
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 // Assertion - throw exception, if condition is not fulfilled
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 // Delete the current message stream object
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 // Assertion - throw exception, if condition is not fulfilled
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 // The END
00286 // ============================================================================
00287 #endif // GAUDIALG_GAUDICOMMONIMP_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Mon Sep 17 2012 13:49:25 for Gaudi Framework, version v23r4 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004