00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "BaBar/BaBar.hh"
00010
00011 #include "CdbBdb/CdbBdbProxyBase.hh"
00012
00013 #include "CdbBase/CdbStateId.hh"
00014 #include "CdbBase/CdbTransaction.hh"
00015
00016 #include "BdbCond/BdbCondDefEventKey.hh"
00017
00018 #include "AbsEnv/AbsEnv.hh"
00019 #include "GenEnv/GenEnv.hh"
00020
00021 #include "ProxyDict/AbsArgCast.hh"
00022
00023 #include "EidData/EidCondKeyTriplet.hh"
00024 #include "ErrLogger/ErrLog.hh"
00025
00026 #include <assert.h>
00027
00028
00029
00030
00031
00032 template< class T >
00033 CdbBdbProxyBase<T>::CdbBdbProxyBase( BdbCondDefStrategy* theStrategy ) :
00034 CdbBdbProxyCache( ),
00035 _strategy (theStrategy),
00036 _transient(0)
00037 {
00038
00039
00040
00041 if( 0 == strategy( )) setStrategy( new BdbCondDefEventKey( ));
00042 }
00043
00044 template< class T >
00045 CdbBdbProxyBase<T>::~CdbBdbProxyBase( )
00046 { }
00047
00048 template< class T >
00049 T*
00050 CdbBdbProxyBase<T>::faultHandler( IfdProxyDict* theDict,
00051 const IfdKey& theKey,
00052 AbsArg& theArg )
00053 {
00054
00055
00056 BdbTime validityTime( 0 );
00057 if( 0 != strategy( )) {
00058 validityTime = strategy( )->defaultKey( ).key( );
00059 } else {
00060 BdbTime* t = AbsArgCast< BdbTime >::value( theArg );
00061 if( 0 == t ) ErrMsg(fatal) << "unable to determine the validity time." << endmsg;
00062 validityTime = *t;
00063 }
00064
00065
00066
00067
00068 if( 0 == transientCache( ) || !isCacheValid( validityTime )) {
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 {
00082 CdbTransaction transaction;
00083
00084
00085
00086 std::vector<CdbBdbProxyElement> elements;
00087 bool gotit = false ;
00088 do {
00089
00090
00091
00092 CdbStateId stateId( CdbId( 0, 0 ), BdbTime( 0 ));
00093
00094 if( CdbStatus::Success != updateCache( validityTime,
00095 stateId,
00096 elements )) {
00097
00098
00099
00100 ErrMsg(error) << "failure to access conditions information: no transient returned" << endmsg;
00101
00102 invalidateTransientCache( );
00103
00104 gotit = true;
00105
00106 } else {
00107
00108
00109
00110
00111 T* newtransient = this->redefinedFaultHandler( elements );
00112
00113 if ( 0 != newtransient ) {
00114
00115
00116
00117 gotit = true;
00118
00119 } else {
00120
00121
00122
00123 BdbTime anotherTime;
00124 if ( tryAnotherTime( validityTime,
00125 elements,
00126 anotherTime )) {
00127
00128
00129
00130 validityTime = anotherTime;
00131
00132 } else {
00133
00134
00135
00136 gotit = true;
00137 }
00138 }
00139
00140
00141
00142 if( transientCache( ) != newtransient ) setTransientCache( newtransient );
00143 }
00144
00145 } while ( !gotit );
00146 }
00147 }
00148 setCacheIsValid();
00149
00150
00151
00152 return transientCache( );
00153 }
00154
00155 template< class T >
00156 void
00157 CdbBdbProxyBase<T>::storeHandler( IfdProxyDict* theDict,
00158 const IfdKey& theKey,
00159 AbsArg& theArg,
00160 T* theObject )
00161 {
00162 ErrMsg(warning) << "this is just a dummy method. It does nothing except printing this message." << endmsg;
00163 }
00164
00165 template< class T >
00166 void
00167 CdbBdbProxyBase<T>::testCache( )
00168 {
00169 setCacheInvalid( );
00170 }
00171
00172 template< class T >
00173 BdbTime
00174 CdbBdbProxyBase<T>::faultTime( ) const
00175 {
00176 assert( 0 != strategy( ));
00177
00178
00179 return strategy( )->defaultKey( ).key( );
00180 }
00181
00182 template< class T >
00183 bool
00184 CdbBdbProxyBase<T>::tryAnotherTime( const BdbTime& theOriginalTime,
00185 const std::vector<CdbBdbProxyElement>& theListOfElements,
00186 BdbTime& TheOtherTime )
00187 {
00188 return false;
00189 }
00190
00191
00192
00193
00194
00195
00196 template< class T >
00197 CdbBdbProxyBaseUsingRevision<T>::CdbBdbProxyBaseUsingRevision( const std::string& theRevisionName,
00198 unsigned int thePartitionId,
00199 BdbCondDefStrategy* theStrategy ) :
00200 CdbBdbProxyBase<T>( theStrategy ),
00201 _revisionName(theRevisionName),
00202 _partitionId (thePartitionId)
00203 { }
00204
00205 template< class T >
00206 CdbBdbProxyBaseUsingRevision<T>::~CdbBdbProxyBaseUsingRevision( )
00207 { }
00208
00209 template< class T >
00210 T*
00211 CdbBdbProxyBaseUsingRevision<T>::faultHandler( IfdProxyDict* theDict,
00212 const IfdKey& theKey,
00213 AbsArg& theArg )
00214 {
00215
00216
00217 BdbTime validityTime( 0 );
00218 if( 0 != strategy( )) {
00219 validityTime = strategy( )->defaultKey( ).key( );
00220 } else {
00221 BdbTime* t = AbsArgCast< BdbTime >::value( theArg );
00222 if( 0 == t ) ErrMsg(fatal) << "unable to determine the validity time." << endmsg;
00223 validityTime = *t;
00224 }
00225
00226
00227
00228
00229 if( 0 == transientCache( ) || !isCacheValid( validityTime )) {
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242 {
00243 CdbTransaction transaction;
00244
00245
00246
00247 std::vector<CdbBdbProxyElement> elements;
00248 bool gotit = false ;
00249 do {
00250
00251
00252
00253 if( CdbStatus::Success != updateCache( validityTime,
00254 _revisionName.c_str( ),
00255 _partitionId,
00256 elements )) {
00257
00258
00259
00260 ErrMsg(error) << "failure to access conditions information: no transient returned" << endmsg;
00261
00262 invalidateTransientCache( );
00263
00264 gotit = true;
00265
00266 } else {
00267
00268
00269
00270
00271 T* newtransient = this->redefinedFaultHandler( elements );
00272
00273 if ( 0 != newtransient ) {
00274
00275
00276
00277 gotit = true;
00278
00279 } else {
00280
00281
00282
00283 BdbTime anotherTime;
00284 if ( tryAnotherTime( validityTime,
00285 elements,
00286 anotherTime )) {
00287
00288
00289
00290 validityTime = anotherTime;
00291
00292 } else {
00293
00294
00295
00296 gotit = true;
00297 }
00298 }
00299
00300
00301
00302 if( transientCache( ) != newtransient ) setTransientCache( newtransient );
00303 }
00304
00305 } while ( !gotit );
00306 }
00307 }
00308 setCacheIsValid();
00309
00310
00311
00312 return transientCache( );
00313 }
00314
00315
00316
00317