00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "BaBar/BaBar.hh"
00010
00011 #include "CdbBase/CdbDatabase.hh"
00012 #include "CdbBase/Cdb.hh"
00013 #include "CdbBase/CdbCondition.hh"
00014 #include "CdbBase/CdbId.hh"
00015 #include "CdbBase/CdbCompositeName.hh"
00016
00017 #include "ErrLogger/ErrLog.hh"
00018 using std::endl;
00019
00020 CdbStatus
00021 CdbDatabase::instance( CdbDatabasePtr& theDatabasePtr,
00022 const char* theDatabaseName,
00023 const char* theImplementationName,
00024 const char* theTechnologyName )
00025 {
00026 const char* errorStr = "CdbDatabase::instance() -- ERROR";
00027
00028 CdbStatus result = CdbStatus::Error;
00029
00030 theDatabasePtr = 0;
00031
00032 do {
00033
00034
00035
00036 CdbPtr cdbPtr = Cdb::instance( theTechnologyName,
00037 theImplementationName );
00038 if( cdbPtr.isNull( )) {
00039 ErrMsg(error) << errorStr << endl
00040 << " Failed to find the top-level CDB API component for:" << endl
00041 << " TECHNOLOGY: \"" << theTechnologyName << "\"" << endl
00042 << " IMPLEMENTATION: \"" << theImplementationName << "\"" << endl
00043 << " The problem can be caused either by the logic of your application" << endl
00044 << " passing (either directly or indirectly) invalid values of the parameters" << endl
00045 << " or by inproperly instantiated CDB API implementations." << endmsg;
00046 break;
00047 }
00048
00049
00050
00051 result = cdbPtr->findDatabase( theDatabasePtr,
00052 theDatabaseName );
00053
00054 } while( false );
00055
00056 return result;
00057 }
00058
00059 CdbDatabase::CdbDatabase( const CdbPtr& theCdbPtr,
00060 const char* theName ) :
00061 _myParentPtr(theCdbPtr),
00062 _myName(theName)
00063 { }
00064
00065 CdbDatabase::CdbDatabase( const CdbDatabase& theDatabase )
00066 {
00067 _myParentPtr = theDatabase._myParentPtr;
00068 _myName = theDatabase._myName;
00069 }
00070
00071 CdbDatabase::~CdbDatabase( )
00072 { }
00073
00074 CdbDatabase&
00075 CdbDatabase::operator=( const CdbDatabase& theDatabase )
00076 {
00077 if( this != &theDatabase ) {
00078 _myParentPtr = theDatabase._myParentPtr;
00079 _myName = theDatabase._myName;
00080 }
00081 return *this;
00082 }
00083
00084 const CdbPtr&
00085 CdbDatabase::parent( ) const
00086 {
00087 return _myParentPtr;
00088 }
00089
00090 const char*
00091 CdbDatabase::name( ) const
00092 {
00093 return _myName.c_str( );
00094 }
00095
00096 CdbStatus
00097 CdbDatabase::physicalConditionName2Id( CdbId& theId,
00098 const CdbCompositeName& theName )
00099 {
00100 const char* errorStr = "CdbDatabase::physicalConditionName2Id() -- ERROR";
00101
00102 if( !theName.isValid( )) return CdbStatus::IllegalParameters;
00103
00104 CdbStatus result = CdbStatus::Error;
00105
00106 CdbConditionPtr conditionPtr;
00107 if( CdbStatus::Success != ( result = this->findCondition( conditionPtr,
00108 theName ))) {
00109 if( CdbStatus::NotFound != result ) {
00110 ErrMsg(error) << errorStr << endl
00111 << " An error occured when trying to find a 'physical' condition by global name. " << endl
00112 << " CONDITION NAME: \"" << theName.getName( ) << "\"." << endmsg;
00113 }
00114 return result;
00115 }
00116 theId = conditionPtr->physicalId( );
00117
00118 return CdbStatus::Success;
00119 }
00120
00121 CdbStatus
00122 CdbDatabase::physicalConditionId2Name( CdbCompositeName& theName ,
00123 const CdbId& theId )
00124 {
00125 const char* errorStr = "CdbDatabase::physicalConditionId2Name() -- ERROR";
00126
00127 CdbStatus result = CdbStatus::Error;
00128
00129 CdbConditionPtr conditionPtr;
00130 if( CdbStatus::Success != ( result = this->findCondition( conditionPtr,
00131 theId ))) {
00132 if( CdbStatus::NotFound != result ) {
00133 ErrMsg(error) << errorStr << endl
00134 << " An error occured when trying to find a 'physical' condition by global identifier. " << endl
00135 << " CONDITION ID: " << theId << endmsg;
00136 }
00137 return result;
00138 }
00139 theName = conditionPtr->physicalName( );
00140
00141 return CdbStatus::Success;
00142 }
00143
00144
00145
00146