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  

/BdbCond/BdbCondDirectAccessor.cc

Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 //
00003 // File and Version Information:
00004 //      $Id: BdbCondDirectAccessor.cc,v 1.4 2001/03/06 17:50:11 gapon Exp $
00005 //
00006 // Description:
00007 //      This class implements an interface of its base class BdbCondAccessor.
00008 //
00009 //      The current implementation provides direct access to the methadata
00010 //      through Objectivity/API.
00011 //
00012 // Environment:
00013 //      Software developed for the BaBar Detector at the SLAC B-Factory.
00014 //
00015 // Author List:
00016 //      Igor A. Gaponenko       Original Author
00017 //
00018 // Copyright Information:
00019 //      Copyright (C) 2000      Lawrence Berkeley Laboratory
00020 //
00021 //-----------------------------------------------------------------------------
00022 
00023 // -------------------------
00024 // -- This Class's Header --
00025 // -------------------------
00026 
00027 #include "BdbCond/BdbCondDirectAccessor.hh"
00028 
00029 // -------------------------
00030 // -- Objectivity Headers --
00031 // -------------------------
00032 
00033 #include <ooIndex.h>
00034 
00035 // -------------------
00036 // -- BaBar Headers --
00037 // -------------------
00038 
00039 // ----------------------------
00040 // -- BaBar Database Headers --
00041 // ----------------------------
00042 
00043 #include "BdbCond/BdbDatabase.hh"
00044  
00045 // ---------------
00046 // -- C Headers --
00047 // ---------------
00048 
00049 extern "C" {
00050 #include <assert.h>
00051 }
00052 
00053 // ---------------------------------
00054 // -- Collaborating Class Headers --
00055 // ---------------------------------
00056 
00057 #include "ErrLogger/ErrLog.hh"
00058 
00059 // --------------------------------------------------------------------------
00060 // -- Local Macros, Typedefs, Structures, Unions, and Forward Declarations --
00061 // --------------------------------------------------------------------------
00062 
00063 static const char  rcsid[] = "$Id: BdbCondDirectAccessor.cc,v 1.4 2001/03/06 17:50:11 gapon Exp $";
00064 
00065 // --------------------
00066 // -- Static methods --
00067 // --------------------
00068 
00069 // ------------------
00070 // -- Constructors --
00071 // ------------------
00072 
00073 BdbCondDirectAccessor::BdbCondDirectAccessor( ) :
00074     BdbCondAccessor( )
00075 {
00076 }
00077 
00078 // ----------------
00079 // -- Destructor --
00080 // ----------------
00081 
00082 BdbCondDirectAccessor::~BdbCondDirectAccessor( )
00083 {
00084 }
00085 
00086 // ----------------
00087 // -- Operations --
00088 // ----------------
00089 
00090 BdbStatus
00091 BdbCondDirectAccessor::findObject( BdbDatabase*          theDatabasePtr,
00092                                    BdbHandle(BdbObject)& theObjectH,        
00093                                    const char*           theContainerName,  
00094                                    const BdbTime&        theTime )
00095 {
00096   // NOTE: all external comunications of this method go via
00097   //       its caller for the following two purposes:
00098   //
00099   //         - stay in the correct context;
00100   //         - provide the consistent change in the caller's context.
00101 
00102     assert( 0 != theDatabasePtr );
00103     assert( 0 != theContainerName );
00104 
00105     BdbStatus status;
00106 
00107     theObjectH = 0;
00108   
00109   // Find an appropriate interval.
00110 
00111     BdbHandle(BdbInterval) BdbIntervalH;
00112     status = theDatabasePtr->findInterval( BdbIntervalH,
00113                                            theContainerName,
00114                                            theTime );
00115     if (( BdbcSuccess != status ) || BdbIsNull(BdbIntervalH)) {
00116         return BdbcError;
00117     }
00118 
00119   // Get an object from the interval.
00120 
00121     theObjectH = BdbIntervalH->getObject( );
00122 
00123     return BdbcSuccess;
00124 }
00125 
00126 BdbStatus
00127 BdbCondDirectAccessor::findObject( BdbDatabase*          theDatabasePtr,
00128                                    BdbHandle(BdbObject)& theObjectH, 
00129                                    BdbIntervalBase&      theIntervalBase,
00130                                    BdbTime&              theVersionTime,
00131                                    const char*           theContainerName,
00132                                    const BdbTime&        theTime )
00133 {
00134   // NOTE: all external comunications of this method go via
00135   //       its caller for the following two purposes:
00136   //
00137   //         - stay in the correct context;
00138   //         - provide the consistent change in the caller's context.
00139 
00140     assert( 0 != theDatabasePtr );
00141     assert( 0 != theContainerName );
00142 
00143     BdbStatus status;
00144 
00145     theObjectH = 0;
00146 
00147     theIntervalBase.setBeginTime( BdbTime::minusInfinity );
00148     theIntervalBase.setEndTime  ( BdbTime::plusInfinity );
00149   
00150   // Find an appropriate interval.
00151 
00152     BdbHandle(BdbInterval) BdbIntervalH;
00153     status = theDatabasePtr->findInterval( BdbIntervalH,
00154                                            theContainerName,
00155                                            theTime );
00156     if (( BdbcSuccess != status ) || BdbIsNull(BdbIntervalH)) {
00157         return BdbcError;
00158     }
00159 
00160   // Get an object, its validity period and its version time from
00161   // the found interval.
00162 
00163     theObjectH = BdbIntervalH->getObject( );
00164     theIntervalBase = *BdbIntervalH;
00165 
00166     theVersionTime = BdbIntervalH->getVersionTime( );
00167 
00168     return BdbcSuccess;
00169 }
00170 
00171 BdbStatus
00172 BdbCondDirectAccessor::findInterval( BdbDatabase*            theDatabasePtr,
00173                                      BdbHandle(BdbInterval)& theIntervalH,
00174                                      const char*             theContainerName,
00175                                      const BdbTime&          theTime )
00176 {
00177   // NOTE: all external comunications of this method go via
00178   //       its caller for the following two purposes:
00179   //
00180   //         - stay in the correct context;
00181   //         - provide the consistent change in the caller's context.
00182 
00183     const char* errorString = "BdbCondDirectAccessor::findInterval() -- ERROR.";
00184 
00185     BdbStatus status;
00186 
00187     assert( 0 != theDatabasePtr );
00188     assert( 0 != theContainerName );
00189 
00190     theIntervalH = 0;
00191 
00192   // Get a handle to the interval container
00193 
00194     BdbHandle(BdbContObj) intervalContH;
00195 
00196     status = theDatabasePtr->findIntervalCont( intervalContH, theContainerName );
00197     if (( BdbcSuccess != status ) || BdbIsNull(intervalContH)) {
00198         return BdbcError;
00199     }
00200 
00201   // A simplest optimization: check the FIRST and LAST intervals.
00202 
00203     status = theDatabasePtr->firstInterval( theIntervalH, theContainerName );
00204     if ( BdbcSuccess != status )              return status;
00205     if ( theIntervalH->inInterval( theTime )) return BdbcSuccess;
00206 
00207     status = theDatabasePtr->lastInterval( theIntervalH, theContainerName );
00208     if ( BdbcSuccess != status )              return status;
00209     if ( theIntervalH->inInterval( theTime )) return BdbcSuccess;
00210 
00211   // look up the interval
00212 
00213     d_ULong gmtTheTime = theTime.getGmtSec( );
00214 
00215     ooLookupKey lookupKey( ooTypeN(BdbInterval), 2 );
00216               
00217     ooLessThanEqualLookupField lessThanEqual( ooTypeN(BdbInterval),
00218                                               "_beginTime._gmtSec",
00219                                               & gmtTheTime );
00220     lookupKey.addField( lessThanEqual );
00221 
00222     ooGreaterThanLookupField greaterThan( ooTypeN(BdbInterval),
00223                                           "_endTime._gmtSec",
00224                                           & gmtTheTime );
00225     lookupKey.addField( greaterThan );
00226 
00227     BdbItr(BdbInterval) theIntervalItr;
00228     theIntervalItr.scan( intervalContH, lookupKey, BdbcRead );
00229 
00230   // Select an interval search method. We use a revision description
00231   // path in order to do make a decision.
00232   //
00233   // NOTE: We always use both the original TLA and the original container
00234   //       name as lookup keys for the revision ID enquiry.
00235 
00236     bool    useTopVersionFlag;
00237     d_ULong theRevisionId;
00238 
00239     status = theDatabasePtr->_revisionPath->getRevision( theDatabasePtr->subsystemTLA( ),
00240                                                          theContainerName,
00241                                                          useTopVersionFlag,
00242                                                          theRevisionId );
00243     if ( BdbcSuccess != status ) {
00244         ErrMsg(error) << errorString << endl
00245                       << "    Failed to determine a revision number." << endl
00246                       << "        DETECTOR  -> " << theDatabasePtr->subsystemTLA( ) << endl
00247                       << "        CONTAINER -> " << theContainerName << endmsg;
00248         return status;
00249     }
00250 
00251   // Call appropriate search algorithm.
00252 
00253     if ( useTopVersionFlag ) {
00254     
00255         status = theDatabasePtr->findTopInterval( theIntervalH,
00256                                                   theIntervalItr );
00257     } else {
00258 
00259         status = theDatabasePtr->findRevisedInterval( theIntervalH,
00260                                                       theIntervalItr,
00261                                                       theRevisionId );
00262     }
00263 
00264     return status;
00265 }
00266 
00267 BdbStatus
00268 BdbCondDirectAccessor::firstInterval( BdbDatabase*            theDatabasePtr,
00269                                       BdbHandle(BdbInterval)& theIntervalH,
00270                                       const char*             theContainerName )
00271 {
00272   // NOTE: all external comunications of this method go via
00273   //       its caller for the following two purposes:
00274   //
00275   //         - stay in the correct context;
00276   //         - provide the consistent change in the caller's context.
00277 
00278     const char* errorString = "BdbCondDirectAccessor::firstInterval() -- ERROR.";
00279 
00280     BdbStatus status;
00281 
00282     assert( 0 != theDatabasePtr );
00283     assert( 0 != theContainerName );
00284 
00285     theIntervalH = 0;
00286 
00287   // Locate the interval container.
00288 
00289     BdbHandle(BdbContObj) intervalContH;
00290 
00291     status = theDatabasePtr->findIntervalCont( intervalContH, theContainerName );
00292     if (( BdbcSuccess != status ) || BdbIsNull(intervalContH)) {
00293         ErrMsg(error) << errorString << endl
00294                       << "    Can not find the interval container." << endl
00295                       << "        DETECTOR ->  " << theDatabasePtr->subsystemTLA( ) << endl
00296                       << "        CONTAINER -> " << theContainerName << endmsg;
00297         return BdbcError;
00298     }
00299 
00300   // Locate the FIRST interval in the container.
00301 
00302     theIntervalH.lookupObj( intervalContH, "FirstInterval" );
00303     if ( BdbIsNull(theIntervalH)) {
00304         ErrMsg(error) << errorString << endl
00305                       << "    Can not find the FIRST interval in this container." << endl
00306                       << "        DETECTOR ->  " << theDatabasePtr->subsystemTLA( ) << endl
00307                       << "        CONTAINER -> " << theContainerName << endmsg;
00308         return BdbcError;
00309     }
00310 
00311     return BdbcSuccess;
00312 }
00313 
00314 BdbStatus
00315 BdbCondDirectAccessor::lastInterval(  BdbDatabase*            theDatabasePtr,
00316                                       BdbHandle(BdbInterval)& theIntervalH,
00317                                       const char*             theContainerName )
00318 {
00319   // NOTE: all external comunications of this method go via
00320   //       its caller for the following two purposes:
00321   //
00322   //         - stay in the correct context;
00323   //         - provide the consistent change in the caller's context.
00324 
00325     const char* errorString = "BdbCondDirectAccessor::lastInterval() -- ERROR.";
00326 
00327     BdbStatus status;
00328 
00329     assert( 0 != theDatabasePtr );
00330     assert( 0 != theContainerName );
00331 
00332     theIntervalH = 0;
00333 
00334   // Locate the interval container.
00335 
00336     BdbHandle(BdbContObj) intervalContH;
00337 
00338     status = theDatabasePtr->findIntervalCont( intervalContH, theContainerName );
00339     if (( BdbcSuccess != status ) || BdbIsNull(intervalContH)) {
00340         ErrMsg(error) << errorString << endl
00341                       << "    Can not find the interval container." << endl
00342                       << "        DETECTOR ->  " << theDatabasePtr->subsystemTLA( ) << endl
00343                       << "        CONTAINER -> " << theContainerName << endmsg;
00344         return BdbcError;
00345     }
00346 
00347   // Locate the LAST interval in the container.
00348 
00349     theIntervalH.lookupObj( intervalContH, "LastInterval" );
00350     if ( BdbIsNull(theIntervalH)) {
00351         ErrMsg(error) << errorString << endl
00352                       << "    Can not find the LAST interval in this container." << endl
00353                       << "        DETECTOR ->  " << theDatabasePtr->subsystemTLA( ) << endl
00354                       << "        CONTAINER -> " << theContainerName << endmsg;
00355         return BdbcError;
00356     }
00357 
00358     return BdbcSuccess;
00359 }
00360 
00361 void
00362 BdbCondDirectAccessor::reset( )
00363 {
00364   // We have nothing to clear in this brand of accessor.
00365 }
00366 
00367 /////////////////
00368 // End Of File //
00369 /////////////////

 


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

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