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

CdbBdbSFolder.cc

Go to the documentation of this file.
00001 // File and Version Information:
00002 //      $Id: CdbBdbSFolder.cc,v 1.7 2004/12/08 09:26:54 gapon Exp $
00003 
00004 /// The implementation of the CdbBdbSFolder class.
00005 /**
00006   * @see CdbBdbSFolder
00007   */
00008 
00009 #include "BaBar/BaBar.hh"
00010 
00011 #include "CdbBdbShared/CdbBdbSFolder.hh"
00012 #include "CdbBdbShared/CdbBdbSCondition.hh"
00013 #include "CdbBdbShared/CdbBdbSConditionP.hh"
00014 #include "CdbBdbShared/CdbBdbSConditionCollectionP.hh"
00015 #include "CdbBdbShared/CdbBdbSConditionAtFolderP.hh"
00016 
00017 #include "CdbBase/CdbPathName.hh"
00018 #include "CdbBase/CdbDatabase.hh"
00019 #include "CdbBase/CdbView.hh"
00020 
00021 #include <iostream>
00022 using std::cout;
00023 using std::endl;
00024 
00025 CdbFolder*
00026 CdbBdbSFolder::clone( ) const
00027 {
00028     CdbBdbSFolder* mySelf = const_cast<CdbBdbSFolder*>( this );
00029     return new CdbBdbSFolder( mySelf->parentView( ),
00030                               mySelf->parentFolder( ),
00031                               mySelf->name( ),
00032                               _folderH,
00033                               _masterRegistryH,
00034                               _localRegistryH );
00035 }
00036 
00037 CdbBdbSFolder::CdbBdbSFolder( const CdbViewPtr&                  theViewPtr,
00038                               const CdbFolderPtr&                theFolderPtr,
00039                               const char*                        theName,
00040                               const BdbHandle(CdbBdbSFolderP)&   theFolderH,
00041                               const BdbHandle(CdbBdbSRegistryP)& theMasterRegistryH,
00042                               const BdbHandle(CdbBdbSRegistryP)& theLocalRegistryH ) :
00043     CdbFolder( theViewPtr,
00044                theFolderPtr,
00045                theName ),
00046     _folderH(theFolderH),
00047     _masterRegistryH(theMasterRegistryH),
00048     _localRegistryH(theLocalRegistryH)
00049 { }
00050 
00051 CdbBdbSFolder::~CdbBdbSFolder( )
00052 { }
00053 
00054 bool
00055 CdbBdbSFolder::isValid( )
00056 {
00057     return true;
00058 }
00059 
00060 bool
00061 CdbBdbSFolder::isOpen( )
00062 {
00063     return true;
00064 }
00065 
00066 CdbStatus
00067 CdbBdbSFolder::open( )
00068 {
00069     return CdbStatus::Success;
00070 }
00071 
00072 CdbStatus
00073 CdbBdbSFolder::close( )
00074 {
00075     return CdbStatus::Success;
00076 }
00077 
00078 BdbTime
00079 CdbBdbSFolder::created( ) const
00080 {
00081     return _folderH->created( );
00082 }
00083 
00084 std::string
00085 CdbBdbSFolder::description( ) const
00086 {
00087     return std::string( _folderH->description( ).head( ));
00088 }
00089 
00090 CdbStatus
00091 CdbBdbSFolder::findFolder( CdbFolderPtr& thePtr,
00092                            const char*   theName
00093                          )
00094 {
00095     const char* errorStr = "CdbBdbSFolder::findFolder() -- ERROR";
00096 
00097     CdbStatus result = CdbStatus::Error;
00098 
00099     thePtr = 0;
00100 
00101     do {
00102 
00103       // Verify parameters
00104 
00105         if( 0 == theName ) {
00106             cout << errorStr << endl
00107                  << "    Non 0 pointer onto a folder name was expected." << endl;
00108             break;
00109         }
00110 
00111         CdbPathName fPath( theName );
00112 
00113         if( ! ( fPath.isValid( ) &&
00114                 ! fPath.isRoot( ) &&
00115                 ! fPath.isAbsolute( ) &&
00116                 ! fPath.isComposite( ))) {
00117 
00118             cout << errorStr << endl
00119                  << "    Unsupported format of the folder name. Simple non-root folder" << endl
00120                  << "    name was expected." << endl
00121                  << "        Passed folder name:  \"" << theName << "\"" << endl
00122                  << "        Current folder name: \"" << name( ) << "\"" << endl;
00123             break;
00124         }
00125 
00126        // Find out persistent folder for specified name
00127 
00128         BdbRef(CdbBdbSFolderP) fRef;
00129         if( CdbStatus::Success != _folderH->findFolder( CdbPathName( theName ),
00130                                                         fRef )) {
00131             result = CdbStatus::NotFound;
00132             break;
00133         }
00134 
00135       // DESIGN NOTE: We need to construct a smart pointer against a clone since
00136       //              we don't know a smart pointer pointing to the current
00137       //              instance, therefore we can't guarantee the lifetime
00138       //              of the current instance.
00139 
00140         CdbFolderPtr myPtr( this->clone( ));
00141 
00142         thePtr = new CdbBdbSFolder( parentView( ),
00143                                     myPtr,
00144                                     theName,
00145                                     fRef,
00146                                     _masterRegistryH,
00147                                     _localRegistryH );
00148 
00149       // Done.
00150 
00151         result = CdbStatus::Success;
00152 
00153     } while( false );
00154 
00155     return result;
00156 }
00157 
00158 CdbStatus
00159 CdbBdbSFolder::folderIterator( CdbFolderItr& theItr )
00160 {
00161     return _folderH->folderIterator( theItr );
00162 }
00163 
00164 CdbStatus
00165 CdbBdbSFolder::findCondition( CdbConditionPtr& thePtr,
00166                               const char*      theName
00167                             )
00168 {
00169     const char* errorStr = "CdbBdbSFolder::findCondition() -- ERROR";
00170 
00171     CdbStatus result = CdbStatus::Error;
00172 
00173     thePtr = 0;
00174 
00175     do {
00176 
00177       // Verify parameters
00178 
00179         if( 0 == theName ) {
00180             cout << errorStr << endl
00181                  << "    Non 0 pointer onto a condition name was expected." << endl;
00182             break;
00183         }
00184 
00185         CdbPathName cPath( theName );
00186 
00187         if( ! ( cPath.isValid( ) &&
00188                 ! cPath.isRoot( ) &&
00189                 ! cPath.isAbsolute( ) &&
00190                 ! cPath.isComposite( ))) {
00191 
00192             cout << errorStr << endl
00193                  << "    Unsupported format of the condition name. Simple non-root" << endl
00194                  << "    name was expected." << endl
00195                  << "        Passed condition name:  \"" << theName << "\"" << endl
00196                  << "        Current folder name:    \"" << name( ) << "\"" << endl;
00197             break;
00198         }
00199 
00200        // Find out persistent condition (at folder) for specified name
00201 
00202         BdbRef(CdbBdbSConditionAtFolderP) cAtFolderRef;
00203         if( CdbStatus::Success != _folderH->findCondition( CdbPathName( theName ),
00204                                                            cAtFolderRef )) {
00205             result = CdbStatus::NotFound;
00206             break;
00207         }
00208 
00209       // Find out the "physical" condition corresponding to the found one
00210 
00211         CdbBdbSId cId = cAtFolderRef->id( );
00212 
00213         BdbRef(CdbBdbSConditionP) cRef;
00214         {
00215             BdbRef(CdbBdbSConditionCollectionP) cCollRef;
00216             {
00217                 BdbHandle(CdbBdbSRegistryP) rH;
00218                 if     ( _masterRegistryH->originId( ) == cId.origin )
00219                     rH = _masterRegistryH;
00220 
00221                 else if( _localRegistryH->originId( ) == cId.origin )
00222                     rH = _localRegistryH;
00223 
00224                 else {
00225 
00226                     if( CdbStatus::Success != CdbBdbSRegistryP::findByOrigin( rH,
00227                                                                               cId.origin )) {
00228                         cout << errorStr << endl
00229                              << "    Failed to find the registry for origin: " << cId.origin << endl
00230                              << "    The database may not be properly initialized/loaded." << endl;
00231                         break;
00232                     }
00233                 }
00234                 cCollRef = rH->conditionCollection( );
00235                 assert( !BdbIsNull(cCollRef));
00236             }
00237             if( CdbStatus::Success != cCollRef->find( cId.local,
00238                                                       cRef )) {
00239                     cout << errorStr << endl
00240                          << "    Failed to find the condition object for identifier: " << cId << endl
00241                          << "    The database may not be properly initialized/loaded." << endl;
00242                     break;
00243             }
00244         }
00245 
00246       // DESIGN NOTE: We need to construct a smart pointer against a clone since
00247       //              we don't know a smart pointer pointing to the current
00248       //              instance, therefore we can't guarantee the lifetime
00249       //              of the current instance.
00250 
00251 
00252         CdbFolderPtr myPtr( this->clone( ));
00253 
00254         thePtr = new CdbBdbSCondition( myPtr,
00255                                        parentView( )->parent( ),
00256                                        theName,
00257                                        cId,
00258                                        cAtFolderRef,
00259                                        cRef,
00260                                        _masterRegistryH,
00261                                        _localRegistryH );
00262 
00263       // Done.
00264 
00265         result = CdbStatus::Success;
00266 
00267     } while( false );
00268 
00269     return result;
00270 }
00271 
00272 CdbStatus
00273 CdbBdbSFolder::conditionIterator( CdbConditionItr& theItr )
00274 {
00275     return _folderH->conditionIterator( theItr );
00276 }
00277 
00278 /////////////////
00279 // End Of File //
00280 /////////////////

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