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

CdbBdbWFolder.cc

Go to the documentation of this file.
00001 // File and Version Information:
00002 //      $Id: CdbBdbWFolder.cc,v 1.14 2004/12/08 09:15:13 gapon Exp $
00003 
00004 /// The implementation of the CdbBdbWFolder class.
00005 /**
00006   * @see CdbBdbWFolder
00007   */
00008 
00009 #include "BaBar/BaBar.hh"
00010 
00011 #include "CdbBdbWrapper/CdbBdbWFolder.hh"
00012 
00013 #include "CdbBase/Cdb.hh"
00014 #include "CdbBase/CdbPathName.hh"
00015 #include "CdbBase/CdbDatabase.hh"
00016 
00017 #include "CdbBdbWrapper/CdbBdbWListOfDetectors.hh"
00018 #include "CdbBdbWrapper/CdbBdbWFolderItr.hh"
00019 #include "CdbBdbWrapper/CdbBdbWCondition.hh"
00020 #include "CdbBdbWrapper/CdbBdbWConditionItr.hh"
00021 
00022 #include "BdbCond/BdbCondDatabaseMgr.hh"
00023 
00024 #include "ErrLogger/ErrLog.hh"
00025 
00026 CdbFolder*
00027 CdbBdbWFolder::clone( ) const
00028 {
00029     CdbBdbWFolder* mySelf = const_cast<CdbBdbWFolder*>( this );
00030     return new CdbBdbWFolder( mySelf->parentView( ),
00031                               mySelf->parentFolder( ),
00032                               mySelf->name( ));
00033 }
00034 
00035 CdbBdbWFolder::CdbBdbWFolder( const CdbViewPtr&   theViewPtr,
00036                               const CdbFolderPtr& theFolderPtr,
00037                               const char*         theName ) :
00038     CdbFolder( theViewPtr,
00039                theFolderPtr,
00040                theName )
00041 { }
00042 
00043 CdbBdbWFolder::~CdbBdbWFolder( )
00044 { }
00045 
00046 bool
00047 CdbBdbWFolder::isValid( )
00048 {
00049     return true;
00050 }
00051 
00052 bool
00053 CdbBdbWFolder::isOpen( )
00054 {
00055     return true;
00056 }
00057 
00058 CdbStatus
00059 CdbBdbWFolder::open( )
00060 {
00061     return CdbStatus::Success;
00062 }
00063 
00064 CdbStatus
00065 CdbBdbWFolder::close( )
00066 {
00067     return CdbStatus::Success;
00068 }
00069 
00070 BdbTime
00071 CdbBdbWFolder::created( ) const
00072 {
00073     return BdbTime::minusInfinity;
00074 }
00075 
00076 std::string
00077 CdbBdbWFolder::description( ) const
00078 {
00079     return std::string( "<not available in current implementation>" );
00080 }
00081 
00082 CdbStatus
00083 CdbBdbWFolder::findFolder( CdbFolderPtr& thePtr,
00084                            const char*   theName
00085                          )
00086 {
00087     CdbStatus result = CdbStatus::Error;
00088 
00089     thePtr = 0;
00090 
00091     do {
00092 
00093         if( !parentFolder( ).isNull( )) {
00094             ErrMsg(error) << "this implementation does not support folders of specified depth." << endmsg;
00095             break;
00096         }
00097 /**
00098  ** IMPLEMENTATION NOTE: The following check has been disabled to provide
00099  **                      beckward behavioral compatibility with the old
00100  **                      Condition/DB, which allows non-existing container creation
00101  **                      on a very first request to BdbDatabase::store methods.
00102  **                      The BdbDatabase::find/fetch methods will fail anyway.
00103  **
00104  **     CdbBdbWListOfDetectors listOfDetectors;
00105  **     size_t                 elements = listOfDetectors.elements( );
00106  **
00107  **     for( size_t i = 0; i < elements; i++ ) {
00108  **
00109  **         if( 0 == strcmp( theName, listOfDetectors[i] )) {
00110  **/
00111               // DESIGN NOTE: We need to construct a smart pointer against a clone since
00112               //              we don't know a smart pointer pointing to the current
00113               //              instance, therefore we can't guarantee the lifetime
00114               //              of the current instance.
00115 
00116                 CdbFolderPtr myPtr( this->clone( ));
00117 
00118                 thePtr = new CdbBdbWFolder( parentView( ),
00119                                             myPtr,
00120                                             theName );
00121 
00122                 result = CdbStatus::Success;
00123 /**
00124  **             break;
00125  **         }
00126  **     }
00127  **/
00128         if( CdbStatus::Success != result ) {
00129             ErrMsg(error) << "specified folder was not found in the database." << endmsg;
00130             break;
00131         }
00132 
00133     } while( false );
00134 
00135     return result;
00136 }
00137 
00138 CdbStatus
00139 CdbBdbWFolder::folderIterator( CdbFolderItr& theItr )
00140 {
00141     CdbFolderPtr myPtr( this->clone( ));
00142 
00143   // ATTENTION: This is not a memory leak - the created object
00144   //            will be destroyed by the iterator.
00145 
00146     theItr = CdbFolderItr( new CdbBdbWFolderItr( myPtr ));
00147 
00148     return CdbStatus::Success;
00149 }
00150 
00151 CdbStatus
00152 CdbBdbWFolder::findCondition( CdbConditionPtr& thePtr,
00153                               const char*      theName
00154                             )
00155 {
00156     CdbStatus result = CdbStatus::Error;
00157 
00158     thePtr = 0;
00159 
00160     do {
00161 
00162       // Evaluate if the current folder is allowed to have conditions, that is
00163       // it (folder) has the following name:
00164       //
00165       //    "/<detector>/<condition>"
00166       //
00167       // and that specified condition has simple non-composite name:
00168       //
00169       //    "<condition>"
00170 
00171         if( ! ( !parentFolder( ).isNull( ) &&
00172                 !parentFolder( )->parentView( ).isNull( ))) {
00173 
00174             ErrMsg(error) << "this implementation only allows conditions at in detector/subsystem folders." << endmsg;
00175             break;
00176         }
00177 
00178         CdbPathName detectorName( name( ));
00179         CdbPathName conditionName( theName );
00180 
00181         if( ! ( detectorName.isValid( )       &&
00182                 conditionName.isValid( )      &&
00183                 ! conditionName.isAbsolute( ) &&
00184                 ! conditionName.isComposite( ))) {
00185 
00186             ErrMsg(error) << "invalid condition name passed. Simple non-composite name was expected." << endmsg;
00187             break;
00188         }
00189 /**
00190  ** IMPLEMENTATION NOTE: The following check has been disabled to provide
00191  **                      beckward behavioral compatibility with the old
00192  **                      Condition/DB, which allows non-existing container creation
00193  **                      on a very first request to BdbDatabase::store methods.
00194  **                      The BdbDatabase::find/fetch methods will fail anyway.
00195  ** 
00196  **
00197  **   // Check the presence of the condition itself
00198  **   //
00199  **   // WARNING: This operation can possibly be replaced with further request
00200  **   //          to the DETECTOR/SUBSYSTEM level folder.
00201  **
00202  **     bool existsFlag = false;
00203  **
00204  **     BdbCondDatabaseMgr condDbMg;
00205  **     if( BdbcSuccess != condDbMg.evaluateIntervalContainer( detectorName,
00206  **                                                            conditionName,
00207  **                                                            existsFlag )) {
00208  **
00209  **         ErrMsg(error) << "failed to evaluate the presence of specified condition." << endmsg;
00210  **         break;
00211  **     }
00212  **     if( ! existsFlag ) {
00213  **         ErrMsg(error) << "specified condition does not exist in the database." << endmsg;
00214  **         break;
00215  **     }
00216  **
00217  **/
00218       // DESIGN NOTE: We need to construct a smart pointer against a clone since
00219       //              we don't know a smart pointer pointing to the current
00220       //              instance, therefore we can't guarantee the lifetime
00221       //              of the current instance.
00222 
00223       // NOTE: The resulting condition object gets as its parameter the condition name
00224       //       only rather than its full path.
00225 
00226       // NOTE: The owner database API object is not set.
00227 
00228         CdbFolderPtr myPtr( this->clone( ));
00229 
00230         CdbDatabasePtr databasePtr = 0;
00231 
00232         thePtr = new CdbBdbWCondition( myPtr,
00233                                        databasePtr,
00234                                        conditionName.toString( ).c_str( ));
00235 
00236         result = CdbStatus::Success;
00237 
00238     } while( false );
00239 
00240     return result;
00241 }
00242 
00243 CdbStatus
00244 CdbBdbWFolder::conditionIterator( CdbConditionItr& theItr )
00245 {
00246     CdbFolderPtr myPtr( this->clone( ));
00247 
00248   // ATTENTION: This is not a memory leak - the created object
00249   //            will be destroyed by the iterator.
00250 
00251     theItr = CdbConditionItr( new CdbBdbWConditionItr( myPtr ));
00252 
00253     return CdbStatus::Success;
00254 }
00255 
00256 /////////////////
00257 // End Of File //
00258 /////////////////

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