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/BdbEnvProxy.cc

Go to the documentation of this file.
00001 #ifndef BDBENVPROXY_CC
00002 #define BDBENVPROXY_CC
00003 
00004 #include "BaBar/BaBar.hh"
00005 #include "ProxyDict/AbsArgCast.hh"
00006 #include "ProxyDict/IfdKey.hh"
00007 #include "BdbTime/BdbIntervalBase.hh"
00008 #include "BdbCond/BdbEnvProxy.hh"
00009 #include "BdbCond/BdbInterval.hh"
00010 #include "BdbCond/BdbConditions.hh"
00011 #include "BdbCond/BdbObject.hh"
00012 #include "BdbCond/BdbObsoleteDatabase.hh"
00013 #include "BdbCond/BdbCondDefStrategy.hh"
00014 #include "EidData/EidCondKeyTriplet.hh"
00015 #include "ErrLogger/ErrLog.hh"
00016 #include <string>
00017 using std::string;
00018 
00019 template< class T, class TP >
00020 BdbEnvProxy< T, TP >::BdbEnvProxy( const std::string& container,
00021                                    const std::string& dbName,
00022                                    BdbCondDefStrategy *strategy)
00023  : _container ( container ),
00024   _dbName( dbName ),
00025   _transient( 0 ),
00026   _db( 0 ),
00027   _strategy(strategy)
00028 {
00029 }
00030 
00031 template< class T, class TP  >
00032 BdbEnvProxy< T, TP >::~BdbEnvProxy()
00033 {
00034 }
00035 
00036 template< class T, class TP  >
00037 T*
00038 BdbEnvProxy< T, TP >::faultHandler( IfdProxyDict* thedict,
00039                                     const IfdKey& thekey,
00040                                     AbsArg& timearg)
00041 {
00042   // local variables to optimise database access
00043   // Decode the time from the AbsArg
00044   BdbTime t;
00045   if (_strategy.get()==0) { // go for the specified time
00046     BdbTime* time = AbsArgCast< BdbTime >::value( timearg );
00047     if (time==0) ErrMsg(fatal) << "you _must_ specify a time " << endmsg;
00048     t = *time;
00049   } else { // ignore any external time
00050     t = _strategy->defaultKey().key();
00051   }
00052   if ( _transient.get() == 0 || ! _transientInterval.inInterval( t ) ) {
00053     startTransaction() ;
00054     if( _db.get() == 0 ) _db.reset( new BdbObsoleteDatabase( _dbName.c_str() ) );
00055     // get a handle to the persistent object and its transient validity interval
00056     // in a single call.
00057     BdbHandle ( TP ) handle;
00058     _db->fetch( handle, _transientInterval, _container.c_str(), t );
00059     _transient.reset( handle.isValid() ? handle->transient() : 0 );
00060     endTransaction() ;
00061     if (_transient.get() == 0) {
00062               ErrMsg(fatal) << "Could not find Persistent object in container " << _container
00063                             << " for time: " << t << endmsg;
00064     }
00065 //    ErrMsg(warning) << "Fetched "
00066 //                    << (*_transient)
00067 //                    << " for time " <<  time
00068 //                    << " from container " << _container
00069 //                    << " with validity " << _valid << endmsg;
00070   }
00071   setCacheIsValid(); // validate the cache
00072   return _transient.get(); // return the cache
00073 }
00074 
00075 template< class T, class TP  >
00076 void BdbEnvProxy< T, TP >::storeHandler( IfdProxyDict*, const IfdKey&, AbsArg&, T* )
00077 {
00078   ErrMsg(warning) << "Cannot directly store a transient Object" << endmsg;
00079 }
00080 
00081 template< class T, class TP  >
00082 void BdbEnvProxy< T, TP >::testCache()
00083 {
00084   setCacheInvalid();
00085 }
00086 
00087 #endif // BDBENVPROXY_CC

 


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

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