00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "BaBar/BaBar.hh"
00010
00011 #include "CdbRooReadonly/CdbRooRoViewR.hh"
00012 #include "CdbRooReadonly/CdbRooRoFolderR.hh"
00013 #include "CdbRooReadonly/CdbRooRoFolderRItr.hh"
00014 #include "CdbRooReadonly/CdbRooRoConditionAtFolderR.hh"
00015 #include "CdbRooReadonly/CdbRooRoConfigCollectionR.hh"
00016
00017 #include "CdbBase/CdbPathName.hh"
00018 #include "CdbBase/CdbTimeUtils.hh"
00019
00020 #include <assert.h>
00021
00022 using std::cout;
00023 using std::endl;
00024
00025 CdbRooRoViewR::CdbRooRoViewR( ) :
00026 _name (""),
00027 _id (0xFFFF),
00028 _description (""),
00029 _created (BdbTime::minusInfinity),
00030 _minValidityTime (BdbTime::minusInfinity),
00031 _maxValidityTime (BdbTime::minusInfinity),
00032 _useDefaultConfigPtr(false),
00033 _defaultConfigPtr (0),
00034 _useRootFolderPtr (false),
00035 _rootFolderPtr (0),
00036 _isFrozen (false)
00037 { }
00038
00039 CdbRooRoViewR::CdbRooRoViewR( const std::string& theName,
00040 UShort_t theId,
00041 const std::string& theDescription,
00042 const BdbTime& theCreationTime,
00043 const BdbTime& theMinValidityTime,
00044 const BdbTime& theMaxValidityTime,
00045 CdbRooRoConfigCollectionR* theDefaultConfigPtr ) :
00046 _name (theName),
00047 _id (theId),
00048 _description (theDescription),
00049 _created (theCreationTime),
00050 _minValidityTime (theMinValidityTime),
00051 _maxValidityTime (theMaxValidityTime),
00052 _useDefaultConfigPtr(0 != theDefaultConfigPtr),
00053 _defaultConfigPtr (theDefaultConfigPtr),
00054 _useRootFolderPtr (true),
00055 _rootFolderPtr (new CdbRooRoFolderR( CdbPathName::separator( ),
00056 "The ROOT folder of the current view",
00057 theCreationTime )),
00058 _isFrozen (false)
00059 {
00060 assert(( BdbTime::minusInfinity != theCreationTime ) && ( BdbTime::plusInfinity != theCreationTime ));
00061 }
00062
00063 CdbRooRoViewR::CdbRooRoViewR( const CdbRooRoViewR& theOther ) :
00064 _name (theOther._name),
00065 _id (theOther._id),
00066 _description (theOther._description),
00067 _created (theOther._created),
00068 _minValidityTime (theOther._minValidityTime),
00069 _maxValidityTime (theOther._maxValidityTime),
00070 _useDefaultConfigPtr(theOther._useDefaultConfigPtr),
00071 _defaultConfigPtr (( theOther._useDefaultConfigPtr ? new CdbRooRoConfigCollectionR( *(theOther._defaultConfigPtr)) : 0 )),
00072 _useRootFolderPtr (theOther._useRootFolderPtr),
00073 _rootFolderPtr (( theOther._useRootFolderPtr ? new CdbRooRoFolderR( *(theOther._rootFolderPtr)) : 0 )),
00074 _isFrozen (theOther._isFrozen)
00075 { }
00076
00077 CdbRooRoViewR::~CdbRooRoViewR( )
00078 {
00079 if( _useDefaultConfigPtr ) {
00080 delete _defaultConfigPtr;
00081 _defaultConfigPtr = 0;
00082 }
00083 if( _useRootFolderPtr ) {
00084 delete _rootFolderPtr;
00085 _rootFolderPtr = 0;
00086 }
00087 }
00088
00089 CdbRooRoViewR&
00090 CdbRooRoViewR::operator=( const CdbRooRoViewR& theOther )
00091 {
00092 if( this != &theOther ) {
00093
00094 if( _useDefaultConfigPtr ) delete _defaultConfigPtr;
00095 if( _useRootFolderPtr ) delete _rootFolderPtr;
00096
00097 _name = theOther._name;
00098 _id = theOther._id;
00099 _description = theOther._description;
00100 _created = theOther._created;
00101 _minValidityTime = theOther._minValidityTime;
00102 _maxValidityTime = theOther._maxValidityTime;
00103 _useDefaultConfigPtr = theOther._useDefaultConfigPtr;
00104 _defaultConfigPtr = ( theOther._useDefaultConfigPtr ? new CdbRooRoConfigCollectionR( *(theOther._defaultConfigPtr)) : 0 );
00105 _useRootFolderPtr = theOther._useRootFolderPtr;
00106 _rootFolderPtr = ( theOther._useRootFolderPtr ? new CdbRooRoFolderR( *(theOther._rootFolderPtr)) : 0 );
00107 _isFrozen = theOther._isFrozen;
00108 }
00109 return *this;
00110 }
00111
00112 CdbStatus
00113 CdbRooRoViewR::setDefaultConfig( CdbRooRoConfigCollectionR* theConfigPtr )
00114 {
00115 const char* errorStr = "CdbRooRoViewR::setDefaultConfig() - ERROR.";
00116
00117 CdbStatus result = CdbStatus::Error;
00118 do {
00119
00120
00121
00122 if( isFrozen( )) {
00123 cout << errorStr << endl
00124 << " This view is already frozen, which means that it can't be" << endl
00125 << " reconfigured anymore." << endl;
00126 break;
00127 }
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 if( 0 != defaultConfig( )) {
00138 if( theConfigPtr != defaultConfig( )) delete _defaultConfigPtr;
00139 }
00140 _useDefaultConfigPtr = true;
00141 _defaultConfigPtr = theConfigPtr;
00142
00143
00144
00145 result = CdbStatus::Success;
00146
00147 } while( false );
00148
00149 return result;
00150 }
00151
00152 CdbStatus
00153 CdbRooRoViewR::setConfig( const std::string& thePathName,
00154 CdbRooRoConfigCollectionR* theConfigPtr,
00155 bool dontDestroyConfigObject )
00156 {
00157 const char* errorStr = "CdbRooRoViewR::setConfig() - ERROR.";
00158
00159 CdbStatus result = CdbStatus::Error;
00160 do {
00161
00162
00163
00164 if( isFrozen( )) {
00165 cout << errorStr << endl
00166 << " This view is already frozen, which means that it can't be" << endl
00167 << " reconfigured anymore." << endl;
00168 break;
00169 }
00170
00171
00172
00173 CdbRooRoConditionAtFolderR* cPtr;
00174 if( CdbStatus::Success != findCondition( thePathName,
00175 cPtr )) {
00176 result = CdbStatus::NotFound;
00177 break;
00178 }
00179
00180
00181
00182 result = cPtr->setConfig( theConfigPtr,
00183 dontDestroyConfigObject );
00184
00185 } while( false );
00186
00187 return result;
00188 }
00189
00190 CdbStatus
00191 CdbRooRoViewR::createFolder( const std::string& thePathName,
00192 const std::string& theNewFolderName,
00193 const std::string& theDescription,
00194 const BdbTime& theCreationTime )
00195 {
00196 const char* errorStr = "CdbRooRoViewR::createFolder() - ERROR.";
00197
00198 CdbStatus result = CdbStatus::Error;
00199 do {
00200
00201
00202
00203 CdbPathName fPath( theNewFolderName.c_str( ));
00204
00205 if(( ! fPath.isValid( )) || fPath.isRoot( ) || fPath.isComposite( )) {
00206 cout << errorStr << endl
00207 << " Illegal new folder name passed to the procedure." << endl
00208 << " A non-composite and non-root folder name was expected." << endl
00209 << " PASSED NAME: \"" << theNewFolderName << "\"" << endl;
00210 break;
00211 }
00212
00213
00214
00215 if( isFrozen( )) {
00216 cout << errorStr << endl
00217 << " This view is already frozen, which means that it can't be" << endl
00218 << " reconfigured anymore." << endl;
00219 break;
00220 }
00221
00222
00223
00224 CdbRooRoFolderR* hPtr;
00225
00226 result = findFolder( thePathName, hPtr );
00227 if( CdbStatus::Success != result ) break;
00228
00229
00230
00231 CdbRooRoFolderR* fPtr = new CdbRooRoFolderR( theNewFolderName,
00232 theDescription,
00233 theCreationTime );
00234
00235
00236
00237
00238 result = hPtr->insert( fPtr );
00239 if( CdbStatus::Success != result ) delete fPtr;
00240
00241 } while( false );
00242
00243 return result;
00244 }
00245
00246 CdbStatus
00247 CdbRooRoViewR::createFolder( const std::string& theFullPathName,
00248 const std::string& theDescription,
00249 const BdbTime& theCreationTime )
00250 {
00251 const char* errorStr = "CdbRooRoViewR::createFolder(recursive) - ERROR.";
00252
00253 CdbStatus result = CdbStatus::Error;
00254 do {
00255
00256
00257
00258 CdbPathName fPath( theFullPathName );
00259
00260 if(( ! fPath.isValid( )) || ( ! fPath.isAbsolute( ))) {
00261 cout << errorStr << endl
00262 << " Illegal folder name passed to the procedure." << endl
00263 << " A valid, absolute folder name was expected." << endl
00264 << " PASSED NAME: \"" << theFullPathName << "\"" << endl;
00265 break;
00266 }
00267
00268
00269
00270 if( isFrozen( )) {
00271 cout << errorStr << endl
00272 << " This view is already frozen, which means that it can't be" << endl
00273 << " reconfigured anymore." << endl;
00274 break;
00275 }
00276
00277
00278
00279
00280 if( fPath.isRoot( )) {
00281 result = CdbStatus::Success;
00282 } else {
00283
00284
00285
00286
00287
00288
00289 result = rootFolder( )->createFolder( fPath.afterFirst( ).toString( ),
00290 theDescription,
00291 theCreationTime );
00292 }
00293
00294 } while( false );
00295
00296 return result;
00297 }
00298
00299 CdbStatus
00300 CdbRooRoViewR::createCondition( const std::string& thePathName,
00301 const std::string& theNewConditionName,
00302 const std::string& theDescription,
00303 const BdbTime& theCreationTime,
00304 const CdbRooRoIdR& theId,
00305 CdbRooRoConfigCollectionR* theConfigPtr )
00306 {
00307 CdbStatus result = CdbStatus::Error;
00308 do {
00309
00310
00311
00312 CdbPathName cPath( theNewConditionName );
00313
00314 if(( ! cPath.isValid( )) || cPath.isRoot( ) || cPath.isComposite( )) {
00315 cout << "CdbRooRoViewR::createCondition() - ERROR." << endl
00316 << " Illegal new condition name passed to the procedure." << endl
00317 << " A non-composite and non-root condition name was expected." << endl
00318 << " PASSED NAME: \"" << theNewConditionName << "\"" << endl;
00319 break;
00320 }
00321
00322
00323
00324 if( isFrozen( )) {
00325 cout << "CdbRooRoViewR::createCondition() - ERROR." << endl
00326 << " This view is already frozen, which means that it can't be" << endl
00327 << " reconfigured anymore." << endl;
00328 break;
00329 }
00330
00331
00332
00333 CdbRooRoFolderR* hPtr;
00334
00335 result = findFolder( thePathName, hPtr );
00336 if( CdbStatus::Success != result ) break;
00337
00338
00339
00340 CdbRooRoConditionAtFolderR* cPtr
00341 = new CdbRooRoConditionAtFolderR( theNewConditionName,
00342 theDescription,
00343 theCreationTime,
00344 theId,
00345 theConfigPtr );
00346
00347
00348
00349
00350 result = hPtr->insert( cPtr );
00351 if( CdbStatus::Success != result ) delete cPtr;
00352
00353 } while( false );
00354
00355 return result;
00356 }
00357
00358 CdbStatus
00359 CdbRooRoViewR::removeFolder( const std::string& thePathName,
00360 bool forceFlag )
00361 {
00362 const char* errorStr = "CdbRooRoViewR::removeFolder( ) - ERROR";
00363
00364 CdbStatus result = CdbStatus::Error;
00365 do {
00366
00367
00368
00369 CdbPathName fName( thePathName );
00370
00371 if( fName.isValid( ) && fName.isRoot( )) {
00372 cout << errorStr << endl
00373 << " The ROOT folder can't be deleted in this way. It can only be" << endl
00374 << " deleted with its host view." << endl;
00375 break;
00376 }
00377
00378
00379
00380 if( isFrozen( )) {
00381 cout << "CdbRooRoViewR::removeFolder() - ERROR." << endl
00382 << " This view is already frozen, which means that it can't be" << endl
00383 << " reconfigured anymore." << endl;
00384 break;
00385 }
00386
00387
00388
00389 CdbRooRoFolderR* fPtr;
00390
00391 result = findFolder( fName.beforeLast( ).toString( ), fPtr );
00392 if( CdbStatus::Success != result ) break;
00393
00394
00395
00396 result = fPtr->removeFolder( fName.last( ).toString( ),
00397 forceFlag );
00398
00399 } while( false );
00400
00401 return result;
00402 }
00403
00404 CdbStatus
00405 CdbRooRoViewR::removeCondition( const std::string& thePathName )
00406 {
00407 const char* errorStr = "CdbRooRoViewR::removeCondition( ) - ERROR";
00408
00409 CdbStatus result = CdbStatus::Error;
00410 do {
00411
00412
00413
00414 CdbPathName fName( thePathName );
00415
00416 if( fName.isValid( ) && fName.isRoot( )) {
00417 cout << errorStr << endl
00418 << " The ROOT name can't be passed to this procedure." << endl;
00419 break;
00420 }
00421
00422
00423
00424 if( isFrozen( )) {
00425 cout << "CdbRooRoViewR::removeCondition() - ERROR." << endl
00426 << " This view is already frozen, which means that it can't be" << endl
00427 << " reconfigured anymore." << endl;
00428 break;
00429 }
00430
00431
00432
00433 CdbRooRoFolderR* fPtr;
00434
00435 result = findFolder( fName.beforeLast( ).toString( ), fPtr );
00436 if( CdbStatus::Success != result ) break;
00437
00438
00439
00440 result = fPtr->removeCondition( fName.last( ).toString( ));
00441
00442 } while( false );
00443
00444 return result;
00445 }
00446
00447 CdbStatus
00448 CdbRooRoViewR::findFolder( const std::string& thePathName,
00449 CdbRooRoFolderR*& thePtr )
00450 {
00451 const char* errorStr = "CdbRooRoViewR::findFolder( ) - ERROR";
00452
00453 CdbStatus result = CdbStatus::Error;
00454 do {
00455
00456
00457
00458 CdbPathName fPath( thePathName );
00459
00460 if( ! ( fPath.isValid( ) && fPath.isAbsolute( ))) {
00461 cout << errorStr << endl
00462 << " Illegal path name passed to the procedure: " << thePathName << endl;
00463 break;
00464 }
00465
00466
00467
00468 if( fPath.isRoot( )) thePtr = rootFolder( );
00469 else
00470 return rootFolder( )->findFolder( fPath.afterFirst( ).toString( ),
00471 thePtr );
00472
00473
00474 result = CdbStatus::Success;
00475
00476 } while( false );
00477
00478 return result;
00479 }
00480
00481 CdbStatus
00482 CdbRooRoViewR::findCondition( const std::string& thePathName,
00483 CdbRooRoConditionAtFolderR*& thePtr )
00484 {
00485 const char* errorStr = "CdbRooRoViewR::findCondition( ) - ERROR";
00486
00487 CdbStatus result = CdbStatus::Error;
00488 do {
00489
00490
00491
00492 CdbPathName cPath( thePathName );
00493
00494 if( ! ( cPath.isValid( ) && cPath.isAbsolute( ) && ( ! cPath.isRoot( )))) {
00495 cout << errorStr << endl
00496 << " Illegal path name passed to the procedure: " << thePathName << endl;
00497 break;
00498 }
00499
00500
00501
00502 CdbRooRoFolderR* fPtr;
00503 if( CdbStatus::Success != findFolder( cPath.beforeLast( ).toString( ), fPtr )) {
00504 result = CdbStatus::NotFound;
00505 break;
00506 }
00507
00508
00509
00510 result = fPtr->findCondition( cPath.last( ).toString( ), thePtr );
00511
00512 } while( false );
00513
00514 return result;
00515 }
00516
00517 CdbStatus
00518 CdbRooRoViewR::folderIterator( CdbItr< const char* >& theItr ) const
00519 {
00520
00521
00522
00523
00524
00525
00526
00527 theItr = CdbItr< const char* >( new CdbRooRoFolderRItr( ));
00528 return CdbStatus::Success;
00529 }
00530
00531 void
00532 CdbRooRoViewR::dump( std::ostream& o ) const
00533 {
00534 o << " NAME: " << name( ) << endl
00535 << " ID: " << id( ) << endl
00536 << " DESCRIPTION: " << description( ) << endl
00537 << " CREATED: " << CdbTimeUtils::time2string( created( )) << " : " << created( ) << endl
00538 << " MIN.VALIDITY: " << CdbTimeUtils::time2string( minValidity( )) << " : " << minValidity( ) << endl
00539 << " MAX.VALIDITY: " << CdbTimeUtils::time2string( maxValidity( )) << " : " << maxValidity( ) << endl
00540 << " IS FROZEN: " << ( isFrozen( ) ? "Yes" : "No" ) << endl
00541 << "HAS DEFAULT CONFIG: " << ( defaultConfig( ) ? "Yes, see its dump below." : "No." ) << endl;
00542
00543 if( defaultConfig( )) {
00544 o << "......................................................." << endl
00545 << endl;
00546 defaultConfig( )->dump( o );
00547 o << "......................................................." << endl;
00548 }
00549 }
00550
00551
00552
00553