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  

/BdbClustering/BdbCustomClustH.cc

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // File:
00003 //      BdbCustomClustH.cc
00004 //
00005 // Description:
00006 //      Clustering hint class which allows a user to specify both 
00007 //      database and container name.
00008 //
00009 // Environment:
00010 //      Software developed for the BaBar Detector at the SLAC B-Factory
00011 //
00012 // Author List:
00013 //      Jacek Becla                Original Author
00014 //
00015 // Copyright Information:
00016 //      Copyright (C) 1997-98      Stanford Linear Accelerator Center
00017 //
00018 //------------------------------------------------------------------------------
00019 
00020 // -------------------------
00021 // -- This Class's Header --
00022 // -------------------------
00023 
00024 #include "BdbClustering/BdbCustomClustH.hh"
00025 
00026 // ---------------------------------
00027 // -- Collaborating Class Headers --
00028 // ---------------------------------
00029 #include "BdbApplication/BdbDomain.hh"
00030 #include "BdbApplication/BdbErrorSignal.hh"
00031 #include "BdbAccess/BdbFSMgr.hh"
00032 #include "BdbClustering/BdbClusteringErrors.hh"
00033 #include "BdbClustering/BdbComponent.hh"
00034 
00035 // ---------------
00036 // -- C Headers --
00037 // ---------------
00038 
00039 extern "C" {
00040 #include <assert.h>
00041 }
00042 
00043 // -------------------------------
00044 // -- Constructors / Destructor --
00045 // -------------------------------
00046 
00047 BdbCustomClustH::BdbCustomClustH(const BdbDomain& domain, 
00048                                  const char* compName, 
00049                                  const char* dbName, 
00050                                  d_ULong maxWaitTime, 
00051                                  d_Boolean quiet)
00052                 : BdbAbsBaseClustH(domain, maxWaitTime, quiet),
00053                   _useDefaultFS(d_False)
00054 {
00055     if ( compName != 0 ) {
00056         setComponent(compName) ;
00057     }
00058     if ( dbName != 0 ) {
00059         setDatabaseName(dbName) ;
00060     }
00061 
00062     resetHints() ;
00063 }
00064 
00065 
00066 BdbCustomClustH::~BdbCustomClustH()
00067 {
00068 }
00069 
00070 
00071 
00072 BdbStatus 
00073 BdbCustomClustH::setComponent(const char* name)
00074 {
00075     if ( BdbAbsBaseClustH::setComponent(name) != BdbcSuccess ) {
00076         return _es->BdbESig(BdbClusteringErrFunctionFailed, 
00077                 "BdbCustomClustH::setComponent", "in BdbAbsBaseClustH::setComponent") ;
00078     }
00079     
00080     _changeAuthLevel = d_True ;
00081 
00082     return BdbcSuccess ;
00083 }
00084 
00085 
00086 
00087 /**  
00088  **  Input:  name of a database
00089  **         
00090  **  Output: error status (BdbcSuccess or BdbcError)
00091  **
00092  **  Modifier. The function sets database name.
00093  **            After this call, next call to hint() function
00094  **            will close current database and open 
00095  **            or create a new database with the name
00096  **            specified here.
00097  **/
00098 
00099 BdbStatus
00100 BdbCustomClustH::setDatabaseName(const char* dbName)
00101 {
00102     if ( dbName == (char*)0) { 
00103         _es->BdbESig(BdbClusteringErrNameNotValid, 0, 
00104                   "BdbCustomClustH::setDatabaseName") ;
00105     }
00106 
00107     _dbName.resize(strlen(dbName)+1) ;
00108     _dbName = dbName ;
00109 
00110     _rebuildDb = 1 ;
00111 
00112     return BdbcSuccess ;
00113 }
00114 
00115 
00116 
00117 /**  
00118  **  Input:  name of a container
00119  **         
00120  **  Output: error status (BdbcSuccess or BdbcError)
00121  **
00122  **  Modifier. The function sets container name.
00123  **            After this call, next call to hint() function
00124  **            will close current container and create 
00125  **            container with the name specified here
00126  **            (in current database).
00127  **/
00128 
00129 BdbStatus
00130 BdbCustomClustH::setContainerName(const char* contName)
00131 {
00132     if ( contName == (char*)0) { 
00133         _es->BdbESig(BdbClusteringErrNameNotValid, 
00134                   "BdbCustomClustH::setContainerName") ;
00135     }
00136 
00137     _contName.resize(strlen(contName)+1) ;
00138     _contName = contName ;
00139     
00140     _rebuildCont = 1 ;
00141 
00142     return BdbcSuccess ;
00143 }
00144 
00145 
00146 
00147 
00148 
00149 
00150 
00151 BdbRefAny 
00152 BdbCustomClustH::updatedHint()
00153 {
00154     if ( compObj()->isIllegal() ) {
00155         _es->BdbESig(BdbClusteringErrComponentNotValid, 
00156                   "BdbCustomClustH::updatedHint") ;
00157         assert(0) ;
00158     }
00159 
00160     if ( _changeAuthLevel ) {
00161         if ( changeAuthL(BdbDomain::Group, compObj()->name()) != BdbcSuccess ) {
00162             _es->BdbESig(BdbClusteringErrFunctionFailed, 
00163                       "BdbCustomClustH::updatedHint", "in changeAuthL") ;
00164             assert(0) ;
00165         }
00166     }
00167 
00168     BdbApplicationOrDomain* theApp = BdbApplicationOrDomain::activeInstance();
00169     d_Long oldWait = theApp->lockWait();
00170     if ( oldWait != maxWaitTime() ) {
00171         theApp->setLockWait( maxWaitTime() );
00172     }
00173 
00174     if ( compObj()->componentChanged() || authLevelChanged() || authNameChanged() ) {
00175         if ( fsMgr()->rebuildFSInfo( domain()->domainName(), 
00176                                      domain()->authLevelName(),
00177                                      domain()->authName(), 
00178                                      ccompObj()->name()) != BdbcSuccess ) {
00179             ;  // be quiet on errors
00180         }
00181         _rebuildDb = 1 ;
00182     }
00183 
00184     refreshCurrentAuthLevel() ;
00185     refreshCurrentAuthName();
00186 
00187     if ( _rebuildDb ) {
00188         resetHints() ;
00189     }
00190 
00191     resetContHint() ;
00192 
00193     if ( reload() != BdbcSuccess ) {
00194         theApp->setLockWait(oldWait);
00195         _es->BdbESig(BdbClusteringErrFunctionFailed, 
00196                   "BdbCustomClustH::updatedHint", "in reload") ;
00197         resetContHint();
00198         return contHint();
00199     }
00200     
00201     if ( BdbIsNull(contHint()) ) {
00202         theApp->setLockWait(oldWait);
00203         _es->BdbESig(BdbClusteringErrHandleNotValid, 
00204                   "BdbCustomClustH::updatedHint") ;
00205         resetContHint();
00206         return contHint(); 
00207     }
00208 
00209     theApp->setLockWait(oldWait);
00210 
00211     oovTopDB = dbHint() ;
00212     return contHint() ;
00213 }
00214 
00215 
00216 
00217 
00218 
00219 BdbStatus 
00220 BdbCustomClustH::reload()
00221 {
00222     if ( localDbName() == 0 ) {
00223         return _es->BdbESig(BdbClusteringErrInvDbName, 
00224                          "BdbCustomClustH::reload") ;
00225     }
00226     if ( localContName() == 0 ) {
00227         return _es->BdbESig(BdbClusteringErrInvContName, 
00228                          "BdbCustomClustH::reload") ;
00229     }
00230 
00231     if ( rebuildDbHint() != BdbcSuccess ) {
00232         return _es->BdbESig(BdbClusteringErrFunctionFailed,
00233                          "BdbCustomClustH::reload", "in rebuildDbHint") ;
00234     }
00235 
00236     if ( rebuildContHint() != BdbcSuccess ) {
00237         return _es->BdbESig(BdbClusteringErrFunctionFailed,
00238                          "BdbCustomClustH::reload", "in rebuildContHint") ;  
00239     }
00240    
00241     compObj()->resetComponentChanged() ;
00242     _rebuildDb   = 0 ;
00243     _rebuildCont = 0 ;
00244 
00245     return BdbcSuccess ;
00246 }
00247 
00248 
00249 
00250 BdbStatus 
00251 BdbCustomClustH::rebuildDirectories()
00252 {
00253   // Set catalogFS/defaultFS switch if enabled
00254 
00255     d_Boolean defaultFS = d_False ;
00256     if ( _useDefaultFS ) {
00257         defaultFS = allowRemoteFS() ;
00258     }
00259 
00260     ooVString dbName( currentDbName() ) ;    // this function should not alter _currentDbName
00261     ooVString path( currentPath() ) ;        // this function should not alter _currentPath
00262 
00263     if ( buildBaseDirectories(defaultFS) != BdbcSuccess ) { // catalogFS or defaultFS
00264         return _es->BdbESig(BdbClusteringErrFunctionFailed, 
00265                          "BdbCustomClustH::rebuildDirectories", "in buildBaseDirectories()") ;
00266     }
00267 
00268   // Now we have to check if we use the components sub-dirs in
00269   // current domain.
00270   
00271     if (((BdbDomain*) domain())->getDBFSUseComponentSubDir()) {
00272         strcatPath( compObj()->name() ) ;
00273         if ( fsMgr()->mkDir(currentPath(), defaultFS) != BdbcSuccess ) { // catalogFS or defaultFS
00274             return _es->BdbESig(BdbClusteringErrFunctionFailed, 
00275                          "BdbCustomClustH::rebuildDirectories", "in mkDir") ;
00276         }
00277     }
00278 
00279   // Restore previous values of the path and database name.
00280 
00281     strcpyDbName( dbName.head() ) ;
00282     strcpyPath( path.head() ) ;
00283 
00284     return BdbcSuccess ;
00285 }
00286 
00287 
00288 
00289 BdbStatus 
00290 BdbCustomClustH::rebuildDbHint()
00291 {
00292     if ( ! BdbIsNull(dbHint()) ) {
00293         return BdbcSuccess ;
00294     }
00295 
00296     if ( rebuildDirectories() != BdbcSuccess ) {
00297         return _es->BdbESig(BdbClusteringErrFunctionFailed, 
00298                          "BdbCustomClustH::rebuildDbHint", "in rebuildDirectories") ;
00299     }
00300 
00301     if ( prepareDbName() != BdbcSuccess ) {
00302         return _es->BdbESig(BdbClusteringErrFunctionFailed,
00303                          "BdbCustomClustH::rebuildDbHint", "in prepareDbName") ;
00304     }
00305 
00306 
00307     if ( newDb() != BdbcSuccess ) {
00308         return _es->BdbESig(BdbClusteringErrFunctionFailed,
00309                          "BdbCustomClustH::rebuildDbHint", "in newDb") ;  
00310     }
00311     return BdbcSuccess ;
00312 }
00313 
00314 
00315 
00316 BdbStatus 
00317 BdbCustomClustH::rebuildContHint()
00318 {
00319     if ( newContainer(localContName()) != BdbcSuccess ) {
00320         return _es->BdbESig(BdbClusteringErrFunctionFailed, 
00321                          "BdbCustomClustH::rebuildContHint", "in newContainer") ;
00322     }
00323 
00324     return BdbcSuccess ;
00325 }
00326 
00327 
00328 
00329 BdbStatus 
00330 BdbCustomClustH::prepareDbName()
00331 {
00332   // Set catalogFS/defaultFS switch if enabled
00333 
00334     d_Boolean defaultFS = d_False ;
00335     if ( _useDefaultFS ) {
00336         defaultFS = allowRemoteFS() ;
00337     }
00338 
00339     if ( prepareNameSpec(defaultFS) != BdbcSuccess ) { // d_False: catalogFS or defaultFS
00340         return _es->BdbESig(BdbClusteringErrFunctionFailed, 
00341                          "BdbCustomClustH::prepareDbName", "in prepareNameSpec") ;
00342     }
00343 
00344 // WARNING: This line wqs commented out because it seems to be unnessesary.
00345 //
00346 //    strcatBoth( compObj()->name() ) ;
00347 
00348     strcatDbName( localDbName(), d_True) ;
00349 
00350     return BdbcSuccess ;
00351 }

 


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

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