Gaudi Framework, version v23r2

Home   Generated: Thu Jun 28 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 // check the existence of objects in Gaudi Transient Store
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   // check the environment
00077   Assert( 0 != service , "exist():: IDataProvider* points to NULL!"      ) ;
00078   // check the data object
00079   Gaudi::Utils::CheckData<TYPE> checker ;
00080   return checker ( service,
00081                    fullTESLocation ( location , useRootInTES ) ) ;
00082 }
00083 // ============================================================================
00084 // get the existing object from Gaudi Event Transient store
00085 // or create new object register in in TES and return if object
00086 // does not exist
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   // check the environment
00096   Assert ( 0 != service , "getOrCreate():: svc points to NULL!" ) ;
00097   // get the helper object
00098   Gaudi::Utils::GetOrCreateData<TYPE,TYPE2> getter ;
00099   return getter ( *this                                     ,
00100                   service                                   ,
00101                   fullTESLocation( location, useRootInTES ) ,
00102                   location                                  ) ;
00103 }
00104 // ============================================================================
00105 // the useful method for location of tools.
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   // for empty names delegate to another method
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     // get the tool from Tool Service
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     // add the tool into list of known tools to be properly released
00131     addToToolList( Tool );
00132   }
00133   // return *VALID* located tool
00134   return Tool ;
00135 }
00136 // ============================================================================
00137 // the useful method for location of tools.
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   // check the environment
00146   Assert ( PBASE::toolSvc() != 0, "IToolSvc* points to NULL!" );
00147   // retrieve the tool from Tool Service
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   // add the tool into the list of known tools to be properly released
00156   addToToolList( Tool );
00157   // return *VALID* located tool
00158   return Tool ;
00159 }
00160 // ============================================================================
00161 // the useful method for location of services
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   // check if we already have this service
00171   Services::iterator it = m_services.find(name);
00172   if (it != m_services.end()) {
00173     // Try to get the requested interface
00174     s = it->second;
00175     // check the results
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     // Try to get the requested interface
00182     s = baseSvc;
00183     // check the results
00184     if ( !baseSvc.isValid() || !s.isValid() ) {
00185       Exception ("svc():: Could not retrieve Svc '" + name + "'", StatusCode::FAILURE);
00186     }
00187     // add the tool into list of known tools, to be properly released
00188     addToServiceList(baseSvc);
00189   }
00190   // return *VALID* located service
00191   return s;
00192 }
00193 // ============================================================================
00194 // Short-cut  to get a pointer to the UpdateManagerSvc
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 // predefined configurable message stream for the effective printouts
00206 // ============================================================================
00207 template <class PBASE>
00208 inline MsgStream&
00209 GaudiCommon<PBASE>::msgStream ( const MSG::Level level ) const
00210 {
00211   if ( !m_msgStream )
00212   { m_msgStream = new MsgStream ( PBASE::msgSvc() , this->name() ) ; }
00213   return *m_msgStream << level ;
00214 }
00215 // ============================================================================
00216 // Assertion - throw exception, if condition is not fulfilled
00217 // ============================================================================
00218 template <class PBASE>
00219 inline void GaudiCommon<PBASE>::Assert( const bool         ok  ,
00220                                         const std::string& msg ,
00221                                         const StatusCode   sc  ) const
00222 {
00223   if (!ok) Exception( msg , sc );
00224 }
00225 // ============================================================================
00226 // Delete the current message stream object
00227 // ============================================================================
00228 template <class PBASE>
00229 inline void GaudiCommon<PBASE>::resetMsgStream() const
00230 {
00231   if ( 0 != m_msgStream ) { delete m_msgStream; m_msgStream = 0; }
00232 }
00233 // ============================================================================
00234 // Assertion - throw exception, if condition is not fulfilled
00235 // ============================================================================
00236 template <class PBASE>
00237 inline void GaudiCommon<PBASE>::Assert( const bool        ok  ,
00238                                         const char*       msg ,
00239                                         const StatusCode  sc  ) const
00240 {
00241   if (!ok) Exception( msg , sc );
00242 }
00243 // ============================================================================
00257 // ============================================================================
00258 #define ALG_ERROR( message , code )                                     \
00259   ( Error( message                                   +                  \
00260            std::string             ( " [ at line " ) +                  \
00261            GaudiAlg::fileLine      (   __LINE__    ) +                  \
00262            std::string             ( " in file '"  ) +                  \
00263            std::string             (   __FILE__    ) + "']" , code ) )
00264 
00265 // ============================================================================
00266 // The END
00267 // ============================================================================
00268 #endif // GAUDIALG_GAUDICOMMONIMP_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Thu Jun 28 2012 23:27:14 for Gaudi Framework, version v23r2 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004