Bdb packages | Design docs | Source docs | Guidelines | Recent releases

Search | Site Map .

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

/CdbBdbWrapper/CdbBdbWCondition.cc

Go to the documentation of this file.
00001 /// The implementation of the CdbBdbWCondition class.
00002 /**
00003   * @see CdbBdbWCondition
00004   */
00005 
00006 #include "BaBar/BaBar.hh"
00007 
00008 #include "CdbBdbWrapper/CdbBdbWCondition.hh"
00009 
00010 #include "CdbBase/Cdb.hh"
00011 #include "CdbBase/CdbDatabase.hh"
00012 #include "CdbBase/CdbView.hh"
00013 #include "CdbBase/CdbFolder.hh"
00014 #include "CdbBase/CdbRevisionPolicy.hh"
00015 #include "CdbBase/CdbObject.hh"
00016 #include "CdbBase/CdbObjectItr.hh"
00017 #include "CdbBase/CdbObjectFactoryBase.hh"
00018 
00019 #include "CdbBdb/CdbBdbObjectCreator.hh"
00020 #include "CdbBdb/CdbBdbObjectConvertor.hh"
00021 
00022 #include "CdbBdbWrapper/CdbBdbWRevision.hh"
00023 #include "CdbBdbWrapper/CdbBdbWRevisionIdItr.hh"
00024 #include "CdbBdbWrapper/CdbBdbWRevisionNameItr.hh"
00025 
00026 #include "BdbApplication/BdbDebug.hh"
00027 
00028 #include "BdbTime/BdbTime.hh"
00029 #include "BdbTime/BdbIntervalBase.hh"
00030 
00031 #include "BdbCond/BdbObject.hh"
00032 #include "BdbCond/BdbObsoleteDatabase.hh"
00033 #include "BdbCond/BdbCondRegistry.hh"
00034 #include "BdbCond/BdbCondRevision.hh"
00035 #include "BdbCond/BdbIntervalItr.hh"
00036 
00037 #include <assert.h>
00038 #include <stdio.h>
00039 #include <iostream.h>
00040 
00041 namespace {
00042 
00043 /////////////////////////////
00044 // Class: CdbBdbWObjectItr //
00045 /////////////////////////////
00046 
00047 class CdbBdbWObjectItr : public CdbObjectItr::InterfaceType {
00048  
00049 private:
00050  
00051   /// The default constructor (NOT IMPLEMENTED)
00052   /**
00053     * Is disabled...
00054     */
00055     CdbBdbWObjectItr( );
00056  
00057 public:
00058  
00059   /// The normal constructor
00060   /**
00061     * More details...
00062     */
00063     CdbBdbWObjectItr( const CdbConditionPtr& theParentPtr,          /**< a smart pointer onto the parent condition */
00064                       const BdbIntervalItr&  theInputItr,           /**< the source of information about objects */
00065                       const BdbTime&         theEndValidityTime     /**< a point beyond which we should stop iteration */
00066                     );
00067  
00068   /// The copy constructor
00069   /** 
00070     * More details to come...
00071     */ 
00072     CdbBdbWObjectItr( const CdbBdbWObjectItr& theItr );
00073  
00074   /// The assignment operator
00075   /** 
00076     * More details to come...
00077     */ 
00078     CdbBdbWObjectItr& operator=( const CdbBdbWObjectItr& theItr );
00079  
00080   /// The destructor
00081   /** 
00082     * Details...
00083     */ 
00084     virtual ~CdbBdbWObjectItr( );
00085  
00086   /// Reset an iterator to its initial state.
00087   /** 
00088     * This implements the corresponding method of the base class.
00089     * 
00090     * @see CdbIItr::reset
00091     * @see CdbStatus
00092     */ 
00093     virtual CdbStatus reset( );
00094  
00095   /// Advance an iterator to the next position.
00096   /** 
00097     * This implements the corresponding method of the base class.
00098     * 
00099     * @see CdbIItr::next()
00100     */ 
00101     virtual bool next( );
00102  
00103   /// Obtain the currently reffered value.
00104   /** 
00105     * This implements the corresponding method of the base class.
00106     * 
00107     * @see CdbIItr::value()
00108     * @see CdbIItr::ValueType
00109     * 
00110     * @return the current value the iterator is set on
00111     */ 
00112     virtual ValueType value( );
00113  
00114   /// Check if an iterator is valid.
00115   /** 
00116     * This implements the corresponding method of the base class.
00117     * 
00118     * @see CdbIItr::isValid()
00119     */ 
00120     virtual bool isValid( );
00121  
00122   /// Make a clone of itself
00123   /** 
00124     * @see CdbIItr::clone()
00125     */ 
00126     virtual InterfaceType* clone( ) const;
00127  
00128 private: 
00129  
00130   /// Set up current context from specified source
00131   /** 
00132     * More details...
00133     */ 
00134     void setUpSelf( const CdbBdbWObjectItr& theItr );
00135  
00136   /// Try to advance the iterator to the next position
00137   /** 
00138     * Return "true" if successful.
00139     */ 
00140     bool tryNext( );
00141  
00142 private: 
00143  
00144     bool _isValid;
00145     bool _hasEverBeenAdvanced;
00146  
00147     CdbConditionPtr _myParentPtr;
00148     BdbIntervalItr  _itr;
00149     BdbTime         _endTime;
00150  
00151     CdbObjectPtr _objectPtr;
00152 };
00153 
00154 CdbBdbWObjectItr::CdbBdbWObjectItr( const CdbConditionPtr& theParentPtr,
00155                                     const BdbIntervalItr&  theInputItr,
00156                                     const BdbTime&         theEndValidityTime ) :
00157     _isValid            (false),
00158     _hasEverBeenAdvanced(false),
00159     _myParentPtr        (theParentPtr),
00160     _itr                (theInputItr),
00161     _endTime            (theEndValidityTime),
00162     _objectPtr          (0)
00163 {
00164     assert( !theParentPtr.isNull( ));
00165 }
00166  
00167 CdbBdbWObjectItr::CdbBdbWObjectItr( const CdbBdbWObjectItr& theItr ) :
00168     _isValid            (theItr._isValid),
00169     _hasEverBeenAdvanced(theItr._hasEverBeenAdvanced),
00170     _myParentPtr        (theItr._myParentPtr),
00171     _itr                (theItr._itr),
00172     _endTime            (theItr._endTime),
00173     _objectPtr          (theItr._objectPtr)
00174 { }
00175  
00176 CdbBdbWObjectItr::~CdbBdbWObjectItr( )
00177 { }
00178 
00179 CdbBdbWObjectItr&
00180 CdbBdbWObjectItr::operator=( const CdbBdbWObjectItr& theItr )
00181 { 
00182     if( this != &theItr ) {
00183         _isValid             = theItr._isValid;
00184         _hasEverBeenAdvanced = theItr._hasEverBeenAdvanced;
00185         _myParentPtr         = theItr._myParentPtr;
00186         _itr                 = theItr._itr;
00187         _endTime             = theItr._endTime;
00188         _objectPtr           = theItr._objectPtr;
00189     } 
00190     return *this;
00191 } 
00192  
00193 CdbStatus 
00194 CdbBdbWObjectItr::reset( )
00195 { 
00196     _isValid             = false;
00197     _hasEverBeenAdvanced = false;
00198  
00199     _objectPtr = 0;
00200  
00201     _itr.reset( );
00202  
00203     return CdbStatus::Success;
00204 }
00205 
00206 bool 
00207 CdbBdbWObjectItr::tryNext( )
00208 { 
00209     bool result = _itr.next( );
00210     if( result ) {
00211  
00212       // Get to the current handle
00213  
00214         BdbHandle(BdbIntervalR) intervalH;
00215         intervalH = _itr;
00216  
00217       // Initialize a generic object
00218  
00219         CdbStatus status = CdbBdbObjectCreator::object( _objectPtr,
00220                                                         _myParentPtr,
00221                                                         intervalH->beginTime( ),
00222                                                         intervalH->endTime( ),
00223                                                         intervalH->getVersionTime( ),   // begin of 'duration' interval
00224                                                         BdbTime::plusInfinity,          // end   of 'duration' interval
00225                                                         intervalH->getVersionTime( ),
00226                                                         intervalH->getObject( ));
00227         result = ( CdbStatus::Success == status );
00228     } 
00229     if( !result ) {
00230         _objectPtr = 0;
00231     } 
00232     return result;
00233 }
00234 
00235 bool 
00236 CdbBdbWObjectItr::next( )
00237 { 
00238     if( _hasEverBeenAdvanced ) {
00239         if( _isValid ) {
00240  
00241           // Proceed only if the end time of the current object is not beyond the limit
00242           // passed to the constructor of the current class.
00243  
00244             if( _objectPtr->end( ) >= _endTime ) {
00245  
00246                 _objectPtr = 0;
00247  
00248                 _isValid = false;
00249  
00250             } else {
00251                 _isValid = tryNext( );
00252             }
00253  
00254         } else {
00255             ;       // leave iterator past the end of the collection
00256         } 
00257  
00258     } else { 
00259         _hasEverBeenAdvanced = true;
00260         _isValid             = tryNext( );
00261     } 
00262     return _isValid;
00263 }
00264 
00265 CdbBdbWObjectItr::ValueType
00266 CdbBdbWObjectItr::value( )
00267 { 
00268     return _objectPtr;
00269 } 
00270  
00271 bool 
00272 CdbBdbWObjectItr::isValid( )
00273 { 
00274     return _isValid;
00275 } 
00276  
00277 CdbBdbWObjectItr::InterfaceType*
00278 CdbBdbWObjectItr::clone( ) const
00279 { 
00280     return new CdbBdbWObjectItr( *this );
00281 }
00282 
00283 };
00284 
00285 /////////////////////////////
00286 // Class: CdbBdbWCondition //
00287 /////////////////////////////
00288 
00289 CdbCondition*
00290 CdbBdbWCondition::clone( ) const
00291 {
00292     CdbBdbWCondition* mySelf = const_cast<CdbBdbWCondition*>( this );
00293     return new CdbBdbWCondition( mySelf->parent( ),
00294                                  mySelf->name( ));
00295 }
00296 
00297 bool
00298 CdbBdbWCondition::isPartitionable( ) const
00299 {
00300     return false;
00301 }
00302 
00303 CdbStatus
00304 CdbBdbWCondition::findObject( CdbObjectPtr&  theObjectPtr,
00305                               const BdbTime& theValidityTime,
00306                               const BdbTime& theInsertionTime )
00307 {
00308 /******************************************************************
00309  *
00310  * IMPLEMENTATION NOTES:
00311  *
00312  * - THIS METHOD IGNORSE THE INSERTION TIME PASSED AS THE PARAMETER
00313  * - IT RELIES ON THE CURRENT REVISION PATH CONFIGURATION
00314  *
00315  ******************************************************************
00316  */
00317     CdbStatus result = CdbStatus::Error;
00318 
00319     theObjectPtr = 0;
00320 
00321     do {
00322 
00323       // Find the corresponding object and its parameters in the database.
00324       //
00325       // NOTE: We always rely on the revision configuration in
00326       //        the BdbCondRevisionPath.
00327 
00328         BdbObsoleteDatabase            db( parent( )->name( ));
00329         BdbHandle(BdbInterval) intervalH;
00330         BdbHandle(BdbObject)   objectH;
00331         BdbIntervalBase        bdbTransientInterval;
00332         BdbTime                bdbInsertionTime( 0 );
00333 
00334         COUT1 << "CDB_FETCH_: detector=" << parent( )->name( ) << " container=" << name( ) << " fetch_time=" << theValidityTime << endl;
00335 
00336         BdbStatus bdbStatus = db.fetch( objectH,
00337                                         bdbTransientInterval,
00338                                         bdbInsertionTime,
00339                                         name( ),
00340                                         theValidityTime );
00341         if( BdbcSuccess != bdbStatus ) break;
00342 
00343       // Create a transient object through the creator factory.
00344       //
00345       // DESIGN NOTE: We need to construct a smart pointer against a clone since
00346       //              we don't know a smart pointer pointing to the current
00347       //              instance, therefore we can't guarantee the lifetime
00348       //              of the current instance.
00349 
00350         CdbConditionPtr myPtr( this->clone( ));
00351         result = CdbBdbObjectCreator::object( theObjectPtr,
00352                                               myPtr,
00353                                               bdbTransientInterval.beginTime( ),
00354                                               bdbTransientInterval.endTime( ),
00355                                               bdbInsertionTime,         // begin of the 'duration' interval
00356                                               BdbTime::plusInfinity,    // end   of the 'duration' interval
00357                                               bdbInsertionTime,
00358                                               objectH );
00359 
00360     } while( false );
00361 
00362     return result;
00363 }
00364 
00365 CdbStatus
00366 CdbBdbWCondition::findObject( CdbObjectPtr&            theObjectPtr,
00367                               const CdbRevisionPolicy& thePolicy,
00368                               const BdbTime&           theValidityTime,
00369                               const BdbTime&           theInsertionTime )
00370 {
00371     return findObject( theObjectPtr,
00372                        theValidityTime,
00373                        theInsertionTime );
00374 }
00375 
00376 CdbStatus
00377 CdbBdbWCondition::objectIterator( CdbObjectItr&  theItr,
00378                                   const BdbTime& theBeginValidity,
00379                                   const BdbTime& theEndValidity )
00380 {
00381     const char* errorStr = "CdbBdbWCondition::objectIterator() -- ERROR.";
00382  
00383     CdbStatus result = CdbStatus::Error;
00384  
00385     do {
00386  
00387         const char* detectorName  = parent( )->name( );
00388         const char* conditionName = name( );
00389  
00390       // Verify parameters to make sure that at least one point of the validity
00391       // timeline is in the specified interval.
00392  
00393         if( theBeginValidity > theEndValidity ) {
00394             cout << errorStr << endl
00395                  << "    Illegal validity range for the iterator:" << endl
00396                  << "        DETECTOR   : \"" << detectorName << "\"" << endl
00397                  << "        CONDITION  : \"" << conditionName << "\"" << endl
00398                  << "        BEGIN TIME : "   << theBeginValidity << endl
00399                  << "        END   TIME : "   << theEndValidity << endl;
00400             break;
00401         }
00402  
00403       // Find out the revision information
00404  
00405         bool    useTopVersionFlag = true;
00406         d_ULong revisionId        = BdbCondRevision::BASELINE;
00407  
00408         if( BdbcSuccess != BdbCondPath::instance( )->getRevision( detectorName,
00409                                                                   conditionName,
00410                                                                   useTopVersionFlag,
00411                                                                   revisionId )) {
00412             cout << errorStr << endl
00413                  << "    Failed to obtain the revision configuration for:" << endl
00414                  << "        DETECTOR  : \"" << detectorName << "\"" << endl
00415                  << "        CONDITION : \"" << conditionName << "\"" << endl;
00416             break;
00417         }
00418 
00419       // Set up the iterator
00420  
00421         BdbIntervalItr itr;
00422         bool           itrWasSetup = false;
00423  
00424         if( useTopVersionFlag ) {
00425  
00426             itrWasSetup = itr.setTopmost( detectorName,
00427                                           conditionName,
00428                                           theBeginValidity );
00429         } else {
00430  
00431             if( BdbCondRevision::BASELINE == revisionId ) {
00432  
00433                 itrWasSetup = itr.setBaseline( detectorName,
00434                                                conditionName,
00435                                                theBeginValidity );
00436             } else {
00437  
00438                 itrWasSetup = itr.setRevision( detectorName,
00439                                                conditionName,
00440                                                revisionId,
00441                                                theBeginValidity );
00442             }
00443         } 
00444         if( !itrWasSetup ) {
00445             cout << errorStr << endl
00446                  << "    Failed to set up the iterator for:" << endl
00447                  << "        DETECTOR   : \"" << detectorName << "\"" << endl
00448                  << "        CONDITION  : \"" << conditionName << "\"" << endl
00449                  << "        BEGIN TIME : "   << theBeginValidity << endl;
00450             break;
00451         }
00452 
00453       // ATTENTION: This is not a memory leak - the created object
00454       //            will be destroyed by the iterator.
00455  
00456         CdbConditionPtr myPtr( this->clone( ));
00457         theItr = CdbObjectItr( new CdbBdbWObjectItr( myPtr,
00458                                                      itr,
00459                                                      theEndValidity ));
00460  
00461       // Done.
00462  
00463         result = CdbStatus::Success;
00464  
00465     } while( false );
00466  
00467     return result;
00468 }
00469 
00470 CdbStatus
00471 CdbBdbWCondition::storeObject( CdbObjectFactoryBase& theObjectFactory,
00472                                const BdbTime&        theBegin,
00473                                const BdbTime&        theEnd,
00474                                CdbObjectPtr&         theObjectPtr )
00475 {
00476     CdbStatus result = CdbStatus::Error;
00477 
00478     theObjectPtr = 0;
00479 
00480     do {
00481 
00482       // Invoke the object creator first.
00483 
00484         CdbConditionPtr myPtr( this->clone( ));
00485 
00486         if( CdbStatus::Success != create( theObjectFactory, theObjectPtr, myPtr, theBegin, theEnd )) break;
00487         if( theObjectPtr.isNull( )) break;
00488 
00489       // Get object handle
00490 
00491         BdbHandle(BdbObject) objectH;
00492 
00493         if( CdbStatus::Success != CdbBdbObjectConvertor::narrow( objectH, theObjectPtr )) break;
00494         if( BdbIsNull(objectH)) break;
00495 
00496       // Store the persistent object in the database.
00497 
00498         BdbObsoleteDatabase db( parent( )->name( ));
00499 
00500         if( BdbcSuccess != db.store( objectH, name( ), theBegin, theEnd )) break;
00501 
00502       // Done
00503 
00504         result = CdbStatus::Success;
00505 
00506     } while( false );
00507 
00508     return result;
00509 }
00510 
00511 CdbStatus
00512 CdbBdbWCondition::storeAndTruncateObject( CdbObjectFactoryBase& theObjectFactory,
00513                                           const BdbTime&        theStoreTime,
00514                                           const BdbTime&        theTruncateTime,
00515                                           CdbObjectPtr&         theObjectPtr )
00516 {
00517     CdbStatus result = CdbStatus::Error;
00518 
00519     theObjectPtr = 0;
00520 
00521     do {
00522 
00523       // Invoke the object creator first.
00524       //
00525       // NOTE: We're passing +Infinity instead of the "truncate" time because
00526       //       the newely created object can (if applied to teh LastInterval) be valid
00527       //       to +Infinity.
00528 
00529         CdbConditionPtr myPtr( this->clone( ));
00530 
00531         if( CdbStatus::Success != create( theObjectFactory, theObjectPtr, myPtr, theStoreTime, BdbTime::plusInfinity )) break;
00532         if( theObjectPtr.isNull( )) break;
00533 
00534       // Get object handle
00535 
00536         BdbHandle(BdbObject) objectH;
00537 
00538         if( CdbStatus::Success != CdbBdbObjectConvertor::narrow( objectH, theObjectPtr )) break;
00539         if( BdbIsNull(objectH)) break;
00540 
00541       // Store the persistent object in the database.
00542 
00543         BdbObsoleteDatabase db( parent( )->name( ));
00544 
00545         if( BdbcSuccess != db.storeAndTruncate( objectH, name( ), theStoreTime, theTruncateTime )) break;
00546 
00547       // Done
00548 
00549         result = CdbStatus::Success;
00550 
00551     } while( false );
00552 
00553     return result;
00554 }
00555 
00556 CdbStatus
00557 CdbBdbWCondition::split( const BdbTime& theTime )
00558 {
00559     const char* errorStr = "CdbBdbWCondition::split() -- ERROR.";
00560 
00561     CdbStatus result = CdbStatus::Error;
00562 
00563     do {
00564 
00565         const char* detectorName  = parent( )->name( );
00566         const char* conditionName = name( );
00567 
00568       // Find the LastInterval
00569 
00570         BdbObsoleteDatabase db( detectorName );
00571 
00572         BdbStatus status;
00573         BdbHandle(BdbIntervalR) lastIntervalH;
00574 
00575         status = db.lastInterval( lastIntervalH, conditionName ); 
00576         if( BdbcSuccess != status || BdbIsNull(lastIntervalH)) {
00577             cout << errorStr << endl
00578                  << "    Failed to locate the LastInterval for:" << endl
00579                  << "        DETECTOR   : \"" << detectorName  << "\"" << endl
00580                  << "        CONDITION  : \"" << conditionName << "\"" << endl;
00581             break;
00582         }
00583 
00584       // Do the actual split only if the specified time falls inside the last interval,
00585       // excluding its begin and end (+Infinity).
00586 
00587         if(( lastIntervalH->beginTime( ) < theTime ) && ( theTime < lastIntervalH->endTime( ))) {
00588             if( BdbcSuccess != db.split( conditionName, theTime )) {
00589                 cout << errorStr << endl
00590                      << "    Failed to split the LastInterval for:" << endl
00591                      << "        DETECTOR   : \"" << detectorName  << "\"" << endl
00592                      << "        CONDITION  : \"" << conditionName << "\"" << endl
00593                      << "        SPLIT TIME : \"" << theTime       << "\"" << endl;
00594                 break;
00595             }
00596         }
00597 
00598       // Done
00599 
00600         result = CdbStatus::Success;
00601 
00602     } while( false );
00603 
00604     return result;
00605 }
00606 
00607 CdbBdbWCondition::CdbBdbWCondition( const CdbFolderPtr& theFolderPtr,
00608                                     const char*         theName ) :
00609     CdbCondition( theFolderPtr,
00610                   theName )
00611 { }
00612 
00613 CdbBdbWCondition::~CdbBdbWCondition( )
00614 { }
00615 
00616 bool
00617 CdbBdbWCondition::isValid( )
00618 {
00619     return true;
00620 }
00621 
00622 bool
00623 CdbBdbWCondition::isOpen( )
00624 {
00625     return true;
00626 }
00627 
00628 CdbStatus
00629 CdbBdbWCondition::open( )
00630 {
00631     return CdbStatus::Success;
00632 }
00633 
00634 CdbStatus
00635 CdbBdbWCondition::close( )
00636 {
00637     return CdbStatus::Success;
00638 }
00639 
00640 CdbStatus
00641 CdbBdbWCondition::findRevision( CdbRevisionPtr& thePtr,
00642                                 const BdbTime&  theId,
00643                                 unsigned short  thePartitionId )
00644 {
00645     CdbStatus result = CdbStatus::Error;
00646 
00647     thePtr = 0;
00648 
00649     do {
00650 
00651       // Shortcat for the "TOPMOST" revision ID.
00652 
00653         if( BdbTime::plusInfinity == theId ) {
00654 
00655           // DESIGN NOTE: We need to construct a smart pointer against a clone since
00656           //              we don't know a smart pointer pointing to the current
00657           //              instance, therefore we can't guarantee the lifetime
00658           //              of the current instance.
00659 
00660             CdbConditionPtr myPtr( this->clone( ));
00661             thePtr = new CdbBdbWRevision( myPtr,
00662                                           theId,
00663                                           "<topmost>",
00664                                           BdbTime::plusInfinity,        // creation time
00665                                           "It's TOPMOST layer",         // description
00666                                           BdbCondRevision::ILLEGAL );   // "old" revision id
00667 
00668             result = CdbStatus::Success;
00669             break;
00670         }
00671 
00672       // Real revisions require to get to the persistent store.
00673 
00674       // Get to the Registry.
00675 
00676         BdbObsoleteDatabase                db( parent( )->name( ));
00677         BdbHandle(BdbCondRegistry) registryH;
00678 
00679         BdbStatus bdbStatus = db.findRegistry( registryH,
00680                                                name( ));
00681         if(( BdbcSuccess != bdbStatus ) || BdbIsNull(registryH)) break;
00682 
00683       // Check every single persistent revision if it matches
00684       // specified parameters.
00685 
00686         BdbItr(BdbCondRevision)    revisionItr;
00687         BdbHandle(BdbCondRevision) revisionH;
00688 
00689         registryH->setRevisionItr( revisionItr );
00690         while( revisionItr.next( )) {
00691 
00692             revisionH = revisionItr;
00693 
00694             BdbTime revisionCreationTime( revisionH->creationTime( ));
00695 
00696             char revisionIdName[11];
00697             sprintf( revisionIdName, "%u", (unsigned) revisionH->id( ));
00698 
00699           // "OLD" -> "NEW" mapping rules for revisions:
00700           //
00701           //    - We treat the creation time of the "old" revisions
00702           //      as the identifiers of the "new" ones.
00703           //
00704           //    - We also use the textual representation of the "old"
00705           //      revisions as the names of "new" revisions.
00706 
00707             if( theId == revisionCreationTime ) {
00708 
00709               // DESIGN NOTE: We need to construct a smart pointer against a clone since
00710               //              we don't know a smart pointer pointing to the current
00711               //              instance, therefore we can't guarantee the lifetime
00712               //              of the current instance.
00713 
00714                 CdbConditionPtr myPtr( this->clone( ));
00715                 thePtr = new CdbBdbWRevision( myPtr,
00716                                               theId,
00717                                               revisionIdName,
00718                                               revisionH->creationTime( ),
00719                                               revisionH->description( ),
00720                                               revisionH->id( ));
00721 
00722                 result = CdbStatus::Success;
00723                 break;
00724             }
00725         }
00726 
00727     } while( false );
00728 
00729     return result;
00730 }
00731 
00732 CdbStatus
00733 CdbBdbWCondition::findRevision( CdbRevisionPtr& thePtr,
00734                                 const char*     theName,
00735                                 unsigned short  thePartitionId )
00736 {
00737     CdbStatus result = CdbStatus::Error;
00738 
00739     thePtr = 0;
00740 
00741     do {
00742 
00743       // Shortcat for the "TOPMOST" revision ID.
00744 
00745         if( 0 == strcmp( "<topmost>", theName )) {
00746 
00747           // DESIGN NOTE: We need to construct a smart pointer against a clone since
00748           //              we don't know a smart pointer pointing to the current
00749           //              instance, therefore we can't guarantee the lifetime
00750           //              of the current instance.
00751 
00752             CdbConditionPtr myPtr( this->clone( ));
00753             thePtr = new CdbBdbWRevision( myPtr,
00754                                           BdbTime::plusInfinity,
00755                                           theName,
00756                                           BdbTime::plusInfinity,        // creation time
00757                                           "It's TOPMOST layer",         // description
00758                                           BdbCondRevision::ILLEGAL );   // "old" revision id
00759 
00760             result = CdbStatus::Success;
00761             break;
00762         }
00763 
00764       // Real revisions require to get to the persistent store.
00765 
00766       // Get to the Registry.
00767 
00768         BdbObsoleteDatabase                db( parent( )->name( ));
00769         BdbHandle(BdbCondRegistry) registryH;
00770 
00771         BdbStatus bdbStatus = db.findRegistry( registryH,
00772                                                name( ));
00773         if(( BdbcSuccess != bdbStatus ) || BdbIsNull(registryH)) break;
00774 
00775       // Check every single persistent revision if it matches
00776       // specified parameters.
00777 
00778         BdbItr(BdbCondRevision)    revisionItr;
00779         BdbHandle(BdbCondRevision) revisionH;
00780 
00781         registryH->setRevisionItr( revisionItr );
00782         while( revisionItr.next( )) {
00783 
00784             revisionH = revisionItr;
00785 
00786             BdbTime revisionCreationTime( revisionH->creationTime( ));
00787 
00788             char revisionIdName[11];
00789             sprintf( revisionIdName, "%u", (unsigned) revisionH->id( ));
00790 
00791           // "OLD" -> "NEW" mapping rules for revisions:
00792           //
00793           //    - We treat the creation time of the "old" revisions
00794           //      as the identifiers of the "new" ones.
00795           //
00796           //    - We also use the textual representation of the "old"
00797           //      revisions as the names of "new" revisions.
00798 
00799             if( 0 == strcmp( revisionIdName, theName )) {
00800 
00801               // DESIGN NOTE: We need to construct a smart pointer against a clone since
00802               //              we don't know a smart pointer pointing to the current
00803               //              instance, therefore we can't guarantee the lifetime
00804               //              of the current instance.
00805 
00806                 CdbConditionPtr myPtr( this->clone( ));
00807                 thePtr = new CdbBdbWRevision( myPtr,
00808                                               revisionH->creationTime( ),
00809                                               theName,
00810                                               revisionH->creationTime( ),
00811                                               revisionH->description( ),
00812                                               revisionH->id( ));
00813 
00814                 result = CdbStatus::Success;
00815                 break;
00816             }
00817         }
00818 
00819     } while( false );
00820 
00821     return result;
00822 }
00823 
00824 CdbStatus
00825 CdbBdbWCondition::revisionIdIterator( CdbItr<BdbTime>& theItr,
00826                                       unsigned short   thePartitionId )
00827 {
00828     CdbConditionPtr myPtr( this->clone( ));
00829 
00830   // ATTENTION: This is not a memory leak - the created object
00831   //            will be destroyed by the iterator.
00832 
00833     theItr = CdbItr<BdbTime>( new CdbBdbWRevisionIdItr( myPtr ));
00834 
00835     return CdbStatus::Success;
00836 }
00837 
00838 CdbStatus
00839 CdbBdbWCondition::revisionNameIterator( CdbItr<const char*>& theItr,
00840                                         unsigned short       thePartitionId )
00841 {
00842     CdbConditionPtr myPtr( this->clone( ));
00843 
00844   // ATTENTION: This is not a memory leak - the created object
00845   //            will be destroyed by the iterator.
00846 
00847     theItr = CdbItr<const char*>( new CdbBdbWRevisionNameItr( myPtr ));
00848 
00849     return CdbStatus::Success;
00850 }
00851 
00852 CdbStatus
00853 CdbBdbWCondition::historyEventIterator( CdbHistoryEventItr& theItr,
00854                                         const BdbTime&      theBeginTime,
00855                                         const BdbTime&      theEndTime,
00856                                         const char**        theEventsToSelect )
00857 {
00858     return CdbStatus::Error;
00859 }
00860 
00861 CdbStatus
00862 CdbBdbWCondition::historyEventTypeIterator( CdbHistoryEventTypeItr& theItr )
00863 {
00864     return CdbStatus::Error;
00865 }
00866 
00867 CdbStatus
00868 CdbBdbWCondition::hint( BdbRefAny&     theHint,
00869                         const BdbTime& theBegin,
00870                         const BdbTime& theEnd )
00871 {
00872   // Ignore tha validity range and condition name and get the hint
00873   // in the scope of the curren detector
00874 
00875     BdbObsoleteDatabase db( parent( )->name( ));
00876 
00877     theHint = db.updatedHint( );
00878 
00879     return CdbStatus::Success;
00880 }
00881 
00882 CdbStatus
00883 CdbBdbWCondition::verify( const BdbRefAny&         theHint,
00884                           const BdbRef(BdbObject)& theObjectRef )
00885 {
00886     CdbStatus result = CdbStatus::Error;
00887 
00888     do {
00889 
00890       // All we're going to check is to see if both the hint and
00891       // the objects are located in the same container.
00892 
00893         if( BdbIsNull( theHint ))      break;
00894         if( BdbIsNull( theObjectRef )) break;
00895 
00896         BdbRef(BdbContObj) hintContRef;
00897         BdbRef(BdbContObj) objectContRef;
00898 
00899         theHint.containedIn( hintContRef );
00900         theObjectRef.containedIn( objectContRef );
00901 
00902         if( BdbIsNull( hintContRef ))   break;
00903         if( BdbIsNull( objectContRef )) break;
00904 
00905         if( hintContRef == objectContRef ) result = CdbStatus::Success;
00906 
00907     } while( false );
00908 
00909     return result;
00910 }
00911 
00912 /////////////////
00913 // End Of File //
00914 /////////////////

 


BaBar Public Site | SLAC | News | Links | Who's Who | Contact Us

Page Owner: Jacek Becla
Last Update: October 04, 2002