00001
00002
00003
00004
00005
00006
00007
00008 #include "BaBar/BaBar.hh"
00009
00010 #include "CdbBdbWrapper/CdbBdbWView.hh"
00011
00012 #include "CdbBase/CdbId.hh"
00013 #include "CdbBase/CdbStateId.hh"
00014 #include "CdbBase/CdbFolder.hh"
00015 #include "CdbBase/CdbPathName.hh"
00016 #include "CdbBase/CdbRevisionPolicy.hh"
00017
00018 #include "CdbBdbWrapper/CdbBdbWFolder.hh"
00019 #include "CdbBdbWrapper/CdbBdbWFolderItr.hh"
00020
00021 #include "BdbTime/BdbTime.hh"
00022 #include "BdbCond/BdbCondPath.hh"
00023 #include "BdbCond/BdbObsoleteDatabase.hh"
00024 #include "BdbCond/BdbCondRegistry.hh"
00025 #include "BdbCond/BdbCondRevision.hh"
00026
00027 #include "ErrLogger/ErrLog.hh"
00028 using std::endl;
00029
00030 namespace {
00031
00032
00033
00034
00035
00036 class CdbBdbWConfigItr : public CdbIItr<CdbConfigElement> {
00037
00038 private:
00039
00040 CdbBdbWConfigItr( );
00041
00042 CdbBdbWConfigItr& operator=( const CdbBdbWConfigItr& theItr );
00043
00044 protected:
00045
00046 CdbBdbWConfigItr( const CdbBdbWConfigItr& theItr ) :
00047 _isValid (theItr._isValid),
00048 _hasEverBeenAdvanced(theItr._hasEverBeenAdvanced),
00049 _value (theItr._value)
00050 { }
00051
00052 public:
00053
00054
00055 CdbBdbWConfigItr( const CdbConfigElement& theConfigElement ) :
00056 _isValid (false),
00057 _hasEverBeenAdvanced(false),
00058 _value (theConfigElement)
00059 { }
00060
00061 virtual ~CdbBdbWConfigItr( )
00062 { }
00063
00064 virtual CdbStatus reset( )
00065 {
00066 _isValid = false;
00067 _hasEverBeenAdvanced = false;
00068
00069 return CdbStatus::Success;
00070 }
00071
00072 virtual bool next( )
00073 {
00074 if( _hasEverBeenAdvanced ) {
00075 if( _isValid ) {
00076 _isValid = false;
00077 } else {
00078 ;
00079 }
00080 } else {
00081 _hasEverBeenAdvanced = true;
00082 _isValid = true;
00083 }
00084 return _isValid;
00085 }
00086
00087 virtual CdbConfigElement value( )
00088 {
00089 if( !isValid( )) ErrMsg(fatal) << "attempting to use a non-initialized iterator." << endmsg;
00090 return _value;
00091 }
00092
00093 virtual bool isValid( )
00094 {
00095 return _isValid;
00096 }
00097
00098 virtual CdbIItr<CdbConfigElement>* clone( ) const
00099 {
00100 return new CdbBdbWConfigItr( *this );
00101 }
00102
00103 private:
00104
00105 bool _isValid;
00106 bool _hasEverBeenAdvanced;
00107
00108 CdbConfigElement _value;
00109 };
00110 };
00111
00112 CdbView*
00113 CdbBdbWView::clone( ) const
00114 {
00115
00116
00117 CdbBdbWView* mySelf = const_cast<CdbBdbWView*>( this );
00118 return new CdbBdbWView( mySelf->parent( ),
00119 mySelf->name( ));
00120 }
00121
00122 CdbBdbWView::CdbBdbWView( const CdbDatabasePtr& thePtr,
00123 const char* theName ) :
00124 CdbView( thePtr,
00125 theName,
00126 CdbId( ))
00127 { }
00128
00129 CdbBdbWView::~CdbBdbWView( )
00130 { }
00131
00132 bool
00133 CdbBdbWView::isValid( )
00134 {
00135 return true;
00136 }
00137
00138 bool
00139 CdbBdbWView::isOpen( )
00140 {
00141 return true;
00142 }
00143
00144 CdbStatus
00145 CdbBdbWView::open( )
00146 {
00147 return CdbStatus::Success;
00148 }
00149
00150 CdbStatus
00151 CdbBdbWView::close( )
00152 {
00153 return CdbStatus::Success;
00154 }
00155
00156 BdbTime
00157 CdbBdbWView::minValidity( ) const
00158 {
00159 return BdbTime::minusInfinity;
00160 }
00161
00162 BdbTime
00163 CdbBdbWView::maxValidity( ) const
00164 {
00165 return BdbTime::plusInfinity;
00166 }
00167
00168 BdbTime
00169 CdbBdbWView::created( ) const
00170 {
00171 return BdbTime::minusInfinity;
00172 }
00173
00174 std::string
00175 CdbBdbWView::description( ) const
00176 {
00177 return std::string( "<not available in current implementation>" );
00178 }
00179
00180 bool
00181 CdbBdbWView::hasDefaultConfig( ) const
00182 {
00183 return false;
00184 }
00185
00186 bool
00187 CdbBdbWView::isLocal( ) const
00188 {
00189 return false;
00190 }
00191
00192 bool
00193 CdbBdbWView::isFrozen( ) const
00194 {
00195 return false;
00196 }
00197
00198 CdbStatus
00199 CdbBdbWView::findFolder( CdbFolderPtr& thePtr,
00200 const char* theName
00201 )
00202 {
00203 CdbStatus result = CdbStatus::Error;
00204
00205 thePtr = 0;
00206
00207 do {
00208
00209 if( 0 != strcmp( theName, CdbPathName::separator( ))) {
00210
00211 ErrMsg(error) << "no such folder in this implementation: \"" << theName << "\"" << endl
00212 << "The only name allowed is the rood one: \"" << CdbPathName::separator( ) << "\"" << endmsg;
00213
00214 break;
00215 }
00216
00217
00218
00219
00220
00221
00222 CdbViewPtr myPtr( this->clone( ));
00223 CdbFolderPtr fPtr( 0 );
00224
00225 thePtr = new CdbBdbWFolder( myPtr,
00226 fPtr,
00227 theName );
00228
00229 result = CdbStatus::Success;
00230
00231 } while( false );
00232
00233 return result;
00234 }
00235
00236 CdbStatus
00237 CdbBdbWView::folderIterator( CdbFolderItr& theItr )
00238 {
00239
00240
00241
00242
00243
00244
00245 theItr = CdbFolderItr( new CdbBdbWFolderItr( ));
00246
00247 return CdbStatus::Success;
00248 }
00249
00250 CdbStatus
00251 CdbBdbWView::getDefault( const BdbTime& theValidityTime,
00252 CdbConfigElement& theConfigElement ) const
00253 {
00254 return CdbStatus::NotFound;
00255 }
00256
00257 CdbStatus
00258 CdbBdbWView::defaultConfigIterator( CdbItr<CdbConfigElement>& theItr ) const
00259 {
00260 return CdbStatus::NotFound;
00261 }
00262
00263 CdbStatus
00264 CdbBdbWView::get( const char* theName,
00265 const BdbTime& theValidityTime,
00266 CdbConfigElement& theConfigElement ) const
00267 {
00268 CdbStatus result = CdbStatus::Error;
00269 do {
00270
00271
00272
00273 if( 0 == theName ) {
00274 ErrMsg(error) << "a null pointer instad of the condition pass passed into the method." << endmsg;
00275 break;
00276 }
00277
00278 CdbPathName fullPath( theName );
00279 CdbPathName detectorFolderPath( CdbPathName( fullPath.beforeLast( )).afterFirst( ));
00280 CdbPathName conditionPath( fullPath.last( ));
00281
00282 if( ! ( fullPath.isValid( ) &&
00283 fullPath.isAbsolute( ) &&
00284 fullPath.isComposite( ) &&
00285 detectorFolderPath.isValid( ) &&
00286 ! detectorFolderPath.isAbsolute( ) &&
00287 ! detectorFolderPath.isComposite( ) &&
00288 conditionPath.isValid( ) &&
00289 ! conditionPath.isAbsolute( ) &&
00290 ! conditionPath.isComposite( ))) {
00291
00292 ErrMsg(error) << "non supported format of the condition name. Fully qualified" << endl
00293 << "condition name including its folder path was expected." << endl
00294 << " fullPath: \"" << fullPath << "\"" << endl
00295 << " detectorFolderPath: \"" << detectorFolderPath << "\"" << endl
00296 << " conditionPath: \"" << conditionPath << "\"" << endl
00297 << " PATH: \"" << theName << "\"" << endmsg;
00298 break;
00299 }
00300
00301
00302
00303 bool useTopVersionFlag;
00304 d_ULong bdbRevisionId;
00305
00306 if( BdbcSuccess != BdbCondPath::instance( )->getRevision( detectorFolderPath.toString( ).c_str( ),
00307 conditionPath.toString( ).c_str( ),
00308 useTopVersionFlag,
00309 bdbRevisionId )) break;
00310
00311
00312
00313
00314 CdbRevisionPolicy policy;
00315
00316 if( useTopVersionFlag ) {
00317 policy = CdbRevisionPolicy( BdbTime::plusInfinity );
00318 } else {
00319
00320
00321
00322
00323 BdbTime rId;
00324
00325 bool wasFound = false;
00326 {
00327
00328 BdbObsoleteDatabase db( detectorFolderPath.toString( ).c_str( ));
00329
00330 BdbHandle(BdbCondRegistry) registryH;
00331 BdbItr(BdbCondRevision) revisionItr;
00332 BdbHandle(BdbCondRevision) revisionH;
00333
00334 if( BdbcSuccess != db.findRegistry( registryH,
00335 conditionPath.toString( ).c_str( ))) break;
00336
00337 registryH->setRevisionItr( revisionItr );
00338 while( revisionItr.next( )) {
00339
00340 revisionH = revisionItr;
00341
00342 if( bdbRevisionId == revisionH->id( )) {
00343
00344 BdbTime revisionCreationTime( revisionH->creationTime( ));
00345
00346 char revisionIdName[11];
00347 sprintf( revisionIdName, "%u", (unsigned int) revisionH->id( ));
00348
00349 rId = revisionCreationTime;
00350
00351 wasFound = true;
00352 break;
00353 }
00354 }
00355 }
00356 if( ! wasFound ) {
00357 ErrMsg(error) << "revision for the ID " << (unsigned int) bdbRevisionId << " was not found in the database." << endmsg;
00358 break;
00359 }
00360 policy = CdbRevisionPolicy( rId );
00361 }
00362
00363
00364
00365
00366 theConfigElement = CdbConfigElement( policy,
00367 BdbTime::minusInfinity,
00368 BdbTime::plusInfinity );
00369
00370
00371
00372 result = CdbStatus::Success;
00373
00374 } while( false );
00375
00376 return result;
00377 }
00378
00379 CdbStatus
00380 CdbBdbWView::configIterator( const char* theName,
00381 CdbItr<CdbConfigElement>& theItr ) const
00382 {
00383 CdbStatus result = CdbStatus::Error;
00384 do {
00385
00386
00387
00388
00389
00390 CdbConfigElement configElement;
00391
00392 if( CdbStatus::Success != get( theName,
00393 BdbTime::minusInfinity,
00394 configElement )) break;
00395
00396
00397
00398
00399 theItr = CdbItr<CdbConfigElement>( new CdbBdbWConfigItr( configElement ));
00400
00401
00402
00403 result = CdbStatus::Success;
00404
00405 } while( false );
00406
00407 return result;
00408 }
00409
00410 CdbStateId
00411 CdbBdbWView::currentStateId( const BdbTime& theValidityTime ) const
00412 {
00413
00414
00415
00416 return CdbStateId( id( ),
00417 BdbTime( ));
00418 }
00419
00420 CdbStatus
00421 CdbBdbWView::historyEventIterator( CdbHistoryEventItr& theItr,
00422 const BdbTime& theBeginTime,
00423 const BdbTime& theEndTime,
00424 const char** theEventsToSelect )
00425 {
00426 return CdbStatus::Error;
00427 }
00428
00429 CdbStatus
00430 CdbBdbWView::historyEventTypeIterator( CdbHistoryEventTypeItr& theItr )
00431 {
00432 return CdbStatus::Error;
00433 }
00434
00435
00436
00437