00001
00002
00003
00004
00005
00006
00007
00008 #include "BaBar/BaBar.hh"
00009
00010 #include "CdbBase/CdbTranslatorsDict.hh"
00011 #include "CdbBase/CdbObjectTranslator.hh"
00012 #include "CdbBase/CdbDebugStream.hh"
00013
00014 #include <iostream>
00015 using std::endl;
00016
00017 CdbTranslatorsDict::CdbTranslatorsDict( ) :
00018 CdbTranslatorsDictBase( )
00019 { }
00020
00021 CdbTranslatorsDict::~CdbTranslatorsDict( )
00022 { }
00023
00024 CdbStatus
00025 CdbTranslatorsDict::add( const CdbCPtr< CdbObjectTranslator >& theTranslatorPtr )
00026 {
00027 const char* context = "CdbTranslatorsDict::add()";
00028
00029 if( theTranslatorPtr.isNull( )) return CdbStatus::IllegalParameters;
00030
00031 CDB_DEBUG_STREAM << context << ": trying transientTypeId=" << theTranslatorPtr->transientTypeId( )
00032 << ", persistentTypeName='" << theTranslatorPtr->persistentTypeName( )
00033 << "', address=" << theTranslatorPtr.get( ) << endl;
00034
00035
00036
00037
00038 if( !find( theTranslatorPtr->transientTypeId( ),
00039 theTranslatorPtr->persistentTypeName( )).isNull( )) {
00040 CDB_DEBUG_STREAM << context << ": refused because transient already exists." << endl;
00041 return CdbStatus::Error;
00042 }
00043
00044
00045
00046 if( _byTransient.find( theTranslatorPtr->transientTypeId( )) == _byTransient.end( )) {
00047 _byTransient[theTranslatorPtr->transientTypeId( )] = Persistent( );
00048 }
00049 _byTransient[theTranslatorPtr->transientTypeId( )]._byPersistent[theTranslatorPtr->persistentTypeName( )] = theTranslatorPtr;
00050
00051 CDB_DEBUG_STREAM << context << ": accepted." << endl;
00052
00053 return CdbStatus::Success;
00054 }
00055
00056 CdbCPtr< CdbObjectTranslator >
00057 CdbTranslatorsDict::find( unsigned int theTranseintTypeId,
00058 const std::string& thePersistentTypeName ) const
00059 {
00060 const char* context = "CdbTranslatorsDict::find()";
00061
00062 std::map< unsigned int, CdbTranslatorsDict::Persistent >::const_iterator tItr = _byTransient.find( theTranseintTypeId );
00063 if( tItr == _byTransient.end( )) return 0;
00064
00065 std::map< std::string, CdbCPtr< CdbObjectTranslator > >::const_iterator pItr = (*tItr).second._byPersistent.find( thePersistentTypeName );
00066 if (pItr != (*tItr).second._byPersistent.end( )) {
00067 CDB_DEBUG_STREAM << context << ": found transientTypeId=" << theTranseintTypeId
00068 << ", persistentTypeName='" << thePersistentTypeName
00069 << "', address=" << pItr->second.get( ) << endl;
00070 }
00071 CdbCPtr< CdbObjectTranslator > resultPtr;
00072 if( pItr != (*tItr).second._byPersistent.end( )) resultPtr = (*pItr).second;
00073 return resultPtr;
00074
00075
00076
00077
00078
00079 }
00080
00081
00082
00083