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

CdbRooRoFolder.cc

Go to the documentation of this file.
00001 // File and Version Information:
00002 //      $Id: CdbRooRoFolder.cc,v 1.2 2004/12/03 14:36:15 gapon Exp $
00003 
00004 /// The implementation of the CdbRooRoFolder class.
00005 /**
00006   * @see CdbRooRoFolder
00007   */
00008 
00009 #include "BaBar/BaBar.hh"
00010 
00011 #include "CdbRooReadonly/CdbRooRoFolder.hh"
00012 #include "CdbRooReadonly/CdbRooRoCondition.hh"
00013 #include "CdbRooReadonly/CdbRooRoConditionR.hh"
00014 #include "CdbRooReadonly/CdbRooRoConditionCollectionR.hh"
00015 #include "CdbRooReadonly/CdbRooRoConditionAtFolderR.hh"
00016 #include "CdbRooReadonly/CdbRooRoIdR.hh"
00017 
00018 #include "CdbBase/CdbPathName.hh"
00019 #include "CdbBase/CdbDatabase.hh"
00020 #include "CdbBase/CdbView.hh"
00021 
00022 #include <iostream>
00023 using std::cout;
00024 using std::endl;
00025 
00026 CdbFolder*
00027 CdbRooRoFolder::clone( ) const
00028 {
00029     CdbRooRoFolder* mySelf = const_cast<CdbRooRoFolder*>( this );
00030     return new CdbRooRoFolder( mySelf->parentView( ),
00031                                mySelf->parentFolder( ),
00032                                mySelf->name( ),
00033                                _persistentFolderPtr,
00034                                _masterRegistryPtr,
00035                                _localRegistryPtr );
00036 }
00037 
00038 CdbRooRoFolder::CdbRooRoFolder( const CdbViewPtr&                  theViewPtr,
00039                                 const CdbFolderPtr&                theFolderPtr,
00040                                 const char*                        theName,
00041                                 CdbRooRoFolderR*                   thePersistentFolderPtr,
00042                                 const CdbCPtr< CdbRooRoRegistry >& theMasterRegistryPtr,
00043                                 const CdbCPtr< CdbRooRoRegistry >& theLocalRegistryPtr ) :
00044     CdbFolder( theViewPtr,
00045                theFolderPtr,
00046                theName ),
00047     _persistentFolderPtr(thePersistentFolderPtr),
00048     _masterRegistryPtr  (theMasterRegistryPtr),
00049     _localRegistryPtr   (theLocalRegistryPtr)
00050 { }
00051 
00052 CdbRooRoFolder::~CdbRooRoFolder( )
00053 { }
00054 
00055 bool
00056 CdbRooRoFolder::isValid( )
00057 {
00058     return true;
00059 }
00060 
00061 bool
00062 CdbRooRoFolder::isOpen( )
00063 {
00064     return true;
00065 }
00066 
00067 CdbStatus
00068 CdbRooRoFolder::open( )
00069 {
00070     return CdbStatus::Success;
00071 }
00072 
00073 CdbStatus
00074 CdbRooRoFolder::close( )
00075 {
00076     return CdbStatus::Success;
00077 }
00078 
00079 BdbTime
00080 CdbRooRoFolder::created( ) const
00081 {
00082     return _persistentFolderPtr->created( );
00083 }
00084 
00085 std::string
00086 CdbRooRoFolder::description( ) const
00087 {
00088     return _persistentFolderPtr->description( );
00089 }
00090 
00091 CdbStatus
00092 CdbRooRoFolder::findFolder( CdbFolderPtr& thePtr,
00093                             const char*   theName )
00094 {
00095     const char* errorStr = "CdbRooRoFolder::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       // IMPLEMENTATION NOTE:
00129       //
00130       //    The persistent pointer below lives in a scope of (is ownd by) a persistent view
00131       //    the current CDB API object is associated with. Therefore we can safely use this
00132       //    pointer in child CDB API folders of the current CDB API view. There shouldn't be
00133       //    any memory management problems.
00134 
00135         CdbRooRoFolderR* persistentFolderPtr;
00136         if( CdbStatus::Success != _persistentFolderPtr->findFolder( theName,
00137                                                                     persistentFolderPtr )) {
00138             result = CdbStatus::NotFound;
00139             break;
00140         }
00141 
00142       // DESIGN NOTE: We need to construct a smart pointer against a clone since
00143       //              we don't know a smart pointer pointing to the current
00144       //              instance, therefore we can't guarantee the lifetime
00145       //              of the current instance.
00146 
00147         thePtr = new CdbRooRoFolder( parentView( ),
00148                                      CdbFolderPtr( this->clone( )),
00149                                      theName,
00150                                      persistentFolderPtr,
00151                                      _masterRegistryPtr,
00152                                      _localRegistryPtr );
00153 
00154       // Done.
00155 
00156         result = CdbStatus::Success;
00157 
00158     } while( false );
00159 
00160     return result;
00161 }
00162 
00163 CdbStatus
00164 CdbRooRoFolder::folderIterator( CdbFolderItr& theItr )
00165 {
00166     return _persistentFolderPtr->folderIterator( theItr );
00167 }
00168 
00169 CdbStatus
00170 CdbRooRoFolder::findCondition( CdbConditionPtr& thePtr,
00171                                const char*      theName )
00172 {
00173     const char* errorStr = "CdbRooRoFolder::findCondition() -- ERROR";
00174 
00175     CdbStatus result = CdbStatus::Error;
00176 
00177     thePtr = 0;
00178 
00179     do {
00180 
00181       // Verify parameters
00182 
00183         if( 0 == theName ) {
00184             cout << errorStr << endl
00185                  << "    Non 0 pointer onto a condition name was expected." << endl;
00186             break;
00187         }
00188 
00189         CdbPathName cPath( theName );
00190 
00191         if( ! ( cPath.isValid( ) &&
00192                 ! cPath.isRoot( ) &&
00193                 ! cPath.isAbsolute( ) &&
00194                 ! cPath.isComposite( ))) {
00195 
00196             cout << errorStr << endl
00197                  << "    Unsupported format of the condition name. Simple non-root" << endl
00198                  << "    name was expected." << endl
00199                  << "        Passed condition name:  \"" << theName << "\"" << endl
00200                  << "        Current folder name:    \"" << name( ) << "\"" << endl;
00201             break;
00202         }
00203 
00204       // Find out persistent condition (at folder) for specified name
00205       //
00206       // IMPLEMENTATION NOTE:
00207       //
00208       //    The persistent pointer below lives in a scope of (is ownd by) a persistent view
00209       //    the current CDB API object is associated with. Therefore we can safely use this
00210       //    pointer in child CDB API folders of the current CDB API view. There shouldn't be
00211       //    any memory management problems.
00212 
00213         CdbRooRoConditionAtFolderR* persistentConditionAtFolderPtr;
00214         if( CdbStatus::Success != _persistentFolderPtr->findCondition( theName,
00215                                                                        persistentConditionAtFolderPtr )) {
00216             result = CdbStatus::NotFound;
00217             break;
00218         }
00219 
00220       // Find out the "physical" condition corresponding to the found one
00221 
00222         CdbRooRoIdR conditionId = persistentConditionAtFolderPtr->id( );
00223 
00224         CdbCPtr< CdbRooRoConditionR > persistentConditionPtr;
00225         {
00226             CdbCPtr< CdbRooRoConditionCollectionR > conditionCollPtr;
00227             {
00228                 CdbCPtr< CdbRooRoRegistry > registryPtr;
00229                 if     ( _masterRegistryPtr->originId( ) == conditionId.origin )
00230                     registryPtr = _masterRegistryPtr;
00231 
00232                 else if( _localRegistryPtr->originId( ) == conditionId.origin )
00233                     registryPtr = _localRegistryPtr;
00234 
00235                 else {
00236 
00237                     if( CdbStatus::Success != CdbRooRoRegistry::findByOrigin( registryPtr,
00238                                                                               conditionId.origin )) {
00239                         cout << errorStr << endl
00240                              << "    Failed to find the registry for origin: " << conditionId.origin << endl
00241                              << "    The database may not be properly initialized/loaded." << endl;
00242                         break;
00243                     }
00244                 }
00245                 conditionCollPtr = registryPtr->conditionCollection( );
00246             }
00247             if( CdbStatus::Success != conditionCollPtr->find( conditionId.local,
00248                                                               persistentConditionPtr )) {
00249                     cout << errorStr << endl
00250                          << "    Failed to find the condition object for identifier: " << conditionId << endl
00251                          << "    The database may not be properly initialized/loaded." << endl;
00252                     break;
00253             }
00254         }
00255 
00256       // DESIGN NOTE: We need to construct a smart pointer against a clone since
00257       //              we don't know a smart pointer pointing to the current
00258       //              instance, therefore we can't guarantee the lifetime
00259       //              of the current instance.
00260 
00261 
00262         thePtr = new CdbRooRoCondition( CdbFolderPtr( this->clone( )),
00263                                         parentView( )->parent( ),
00264                                         theName,
00265                                         conditionId.transient( ),
00266                                         persistentConditionAtFolderPtr,
00267                                         persistentConditionPtr,
00268                                         _masterRegistryPtr,
00269                                         _localRegistryPtr );
00270 
00271       // Done.
00272 
00273         result = CdbStatus::Success;
00274 
00275     } while( false );
00276 
00277     return result;
00278 }
00279 
00280 CdbStatus
00281 CdbRooRoFolder::conditionIterator( CdbConditionItr& theItr )
00282 {
00283     return _persistentFolderPtr->conditionIterator( theItr );
00284 }
00285 
00286 /////////////////
00287 // End Of File //
00288 /////////////////

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