Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

CdbRooObjectTranslatorRT.cc

Go to the documentation of this file.
00001 // File and Version Information:
00002 //      $Id: CdbRooObjectTranslatorRT.cc,v 1.1 2005/05/03 21:23:49 gapon Exp $
00003 
00004 #include "BaBar/BaBar.hh"
00005 
00006 #include "CdbRoo/CdbRooObjectTranslatorRT.hh"
00007 #include "CdbRoo/CdbRooObjectR.hh"
00008 #include "CdbRoo/CdbRooObjectConvertor.hh"
00009 
00010 #include "CdbBase/CdbObject.hh"
00011 #include "CdbBase/CdbTransaction.hh"
00012 
00013 #include "ErrLogger/ErrLog.hh"
00014 
00015 #include "TClass.h"
00016 
00017 #include <iostream>
00018 using std::endl;
00019 
00020 template< class R,
00021           class T >
00022 std::string 
00023 CdbRooObjectTranslatorRT<R,T>::persistentType2Name( )
00024 {
00025     const char* fatalStr = "CdbRooObjectTranslatorRT<R,T>::persistentType2Name( ) -- FATAL";
00026 
00027   // Get and verify the 'R' type name
00028 
00029     std::string rTypeName = "";
00030     {
00031       // To get types we need a transaction.
00032 
00033         CdbTransaction readOnlyTransaction;
00034 
00035       // ATTENTION: If 'R' is not a valid persistent type then the compilations
00036       //            will abort below.
00037 
00038         rTypeName = R::Class( )->GetName( );
00039 
00040         if( !R::Class( )->InheritsFrom( CdbRooObjectR::Class( )))
00041             ErrMsg(fatal) << fatalStr << endl
00042                           << "    The passed as a parameter of the template type \"" << rTypeName << "\"" << endl
00043                           << "    doesn't correspond to a persistent class deriving from CdbRooObjectR, which is" << endl
00044                           << "    the very base class of payload objects of the current persistnet technology." << endmsg;
00045     }
00046     return rTypeName;
00047 }
00048 
00049 template< class R,
00050           class T >
00051 CdbRooObjectTranslatorRT<R,T>::CdbRooObjectTranslatorRT( ) :
00052     CdbObjectTranslatorT<T>( persistentType2Name( ))
00053 { }
00054 
00055 template< class R,
00056           class T >
00057 CdbStatus
00058 CdbRooObjectTranslatorRT<R,T>::toTransientT( T*&                 theTransientPtr,
00059                                             const CdbObjectPtr& theObjectPtr ) const
00060 {
00061     const char* errorStr = "CdbRooObjectTranslatorRT<R,T>::toTransientT( ) -- ERROR";
00062 
00063   // Translate the metadata object pointer into a persistent handle
00064   // This will also check if the metadata pointer is of the correct technology.
00065 
00066     CdbStatus result = CdbStatus::Error;
00067 
00068     CdbCPtr<R> persObjectPtr;
00069 
00070     if( CdbStatus::Success != ( result = CdbRooObjectConvertor::typeSafeNarrow( persObjectPtr,
00071                                                                                 theObjectPtr ))) {
00072         ErrMsg(error) << errorStr << endl
00073                       << "    Failed to obtain a persistent handle out of the passed metadata object." << endl
00074                       << "        OBJECT ID: " << theObjectPtr->id( ) << endmsg;
00075         return result;
00076     }
00077 
00078   // Proceed to a user defined translation method
00079 
00080     return toTransientRT( theTransientPtr,
00081                           persObjectPtr );
00082 }
00083 
00084 /////////////////
00085 // End Of File //
00086 /////////////////

Generated on Mon Dec 5 18:22:09 2005 for CDB by doxygen1.3-rc3