00001
00002
00003
00004
00005
00006
00007
00008 #include "BaBar/BaBar.hh"
00009
00010 #include "CdbBase/Cdb.hh"
00011 #include "CdbBase/CdbEnvironment.hh"
00012 #include "CdbBase/CdbTranslatorsDict.hh"
00013
00014 #include "ErrLogger/ErrLog.hh"
00015 using std::endl;
00016
00017 Cdb::Cdb( ) :
00018 _myTranslatorsDict( new CdbTranslatorsDict( ))
00019 { }
00020
00021 Cdb::~Cdb( )
00022 { }
00023
00024 CdbStatus
00025 Cdb::set( CdbPtr& thePtr )
00026 {
00027 return CdbEnvironment::set( thePtr );
00028 }
00029
00030 CdbStatus
00031 Cdb::get( CdbPtr& thePtr,
00032 const char* theTechnologyName,
00033 const char* theImplementationName )
00034 {
00035 return CdbEnvironment::get( thePtr,
00036 theTechnologyName,
00037 theImplementationName );
00038 }
00039
00040 CdbPtr
00041 Cdb::instance( const char* theTechnologyName,
00042 const char* theImplementationName )
00043 {
00044
00045
00046 std::string defaultTechnologyName;
00047 if( CdbStatus::Success != CdbEnvironment::getDefaultTechnology( defaultTechnologyName)) {
00048
00049 ErrMsg(error) << "The Condition/DB configuration problem has been detected." << endl
00050 << "It's not possible to obtain the information about default technology" << endl
00051 << "of the Condition/DB API." << endmsg;
00052 return 0;
00053 }
00054
00055 std::string techName = defaultTechnologyName;
00056 if( 0 != theTechnologyName ) techName = theTechnologyName;
00057
00058
00059
00060 std::string defaultImplementationName;
00061 if( CdbStatus::Success != CdbEnvironment::getDefaultImplementation( defaultImplementationName,
00062 techName.c_str( ))) {
00063
00064 ErrMsg(error) << "The Condition/DB configuration problem has been detected." << endl
00065 << "It's not possible to obtain the information about default implementation" << endl
00066 << "of the Condition/DB API for the following technology: \"" << techName.c_str( ) << "\"" << endmsg;
00067 return 0;
00068 }
00069
00070 std::string implName = defaultImplementationName;
00071 if( 0 != theImplementationName ) implName = theImplementationName;
00072
00073
00074
00075 CdbPtr ptr;
00076 if( CdbStatus::Success != CdbEnvironment::get( ptr,
00077 techName.c_str( ),
00078 implName.c_str( ))) {
00079
00080 ErrMsg(error) << "Failed to find the Condition/DB API for:" << endl
00081 << " TECHNOLOGY: \"" << techName.c_str( ) << "\"" << endl
00082 << " IMPLEMENTATION: \"" << implName.c_str( ) << "\"" << endl
00083 << "The current application may be inproperly configured." << endmsg;
00084 return 0;
00085 }
00086 return ptr;
00087 }
00088
00089 CdbStatus
00090 Cdb::registerTranslator( CdbObjectTranslator* theTranslatorPtr )
00091 {
00092 return _myTranslatorsDict->add( theTranslatorPtr );
00093 }
00094
00095 CdbStatus
00096 Cdb::findTranslator( CdbCPtr<CdbObjectTranslator>& theTranslatorPtr,
00097 unsigned int theTransientTypeId,
00098 const std::string& thePersistentTypeName ) const
00099 {
00100 theTranslatorPtr = _myTranslatorsDict->find( theTransientTypeId,
00101 thePersistentTypeName );
00102
00103 return ( theTranslatorPtr.isNull( ) ? CdbStatus::NotFound : CdbStatus::Success );
00104 }
00105
00106
00107
00108