![]() |
|
|
Bdb packages | Design docs | Source docs | Guidelines | Recent releases |
|
Main Page Modules Namespace List Class Hierarchy Alphabetical List Compound List File List Compound Members File Members /BdbScribes/BdbConversionManager.cc
Go to the documentation of this file.00001 #if !defined(BDBCONVERSIONMANAGER_CC) 00002 #define BDBCONVERSIONMANAGER_CC 00003 //-------------------------------------------------------------------------- 00004 // File and Version Information: 00005 // $Id: BdbConversionManager.cc,v 1.17 2002/07/03 05:54:10 ryd Exp $ 00006 // 00007 // Description: 00008 // Class BdbConversionManager 00009 // 00010 // Environment: 00011 // Software developed for the BaBar Detector at the SLAC B-Factory. 00012 // 00013 // Author List: 00014 // Simon Patton Originator 00015 // 00016 // Copyright Information: 00017 // Copyright (C) 1999 LBNL 00018 // 00019 //------------------------------------------------------------------------ 00020 00021 //----------------------- 00022 // This Class's Header -- 00023 //----------------------- 00024 #include "BdbScribes/BdbConversionManager.hh" 00025 00026 //------------- 00027 // C Headers -- 00028 //------------- 00029 extern "C" { 00030 #include <assert.h> 00031 } 00032 00033 //--------------- 00034 // C++ Headers -- 00035 //--------------- 00036 00037 //---------------- 00038 // BaBar Header -- 00039 //---------------- 00040 #include "BaBar/BaBar.hh" 00041 00042 //------------------------------- 00043 // Collaborating Class Headers -- 00044 //------------------------------- 00045 #include "BdbScribes/BdbGenericScribe.hh" 00046 #include "BdbScribes/BdbEvtObjLocReg.hh" 00047 #include "BdbUtil/Bdb.hh" 00048 #include <vector> 00049 using std::vector; 00050 #include <algorithm> 00051 00052 //------------------------------------ 00053 // Collaborating Class Declarations -- 00054 //------------------------------------ 00055 00056 //----------------------------------------------------------------------- 00057 // Local Macros, Typedefs, Structures, Unions and Forward Declarations -- 00058 //----------------------------------------------------------------------- 00059 00060 // ----------------------------------------------- 00061 // -- Static Data & Function Member Definitions -- 00062 // ----------------------------------------------- 00063 00064 // --------------------------------- 00065 // -- Member Function Definitions -- 00066 // --------------------------------- 00067 00068 //---------------- 00069 // Constructors -- 00070 //---------------- 00071 00072 BdbConversionManager::BdbConversionManager( size_t*& aHighestInputCount , 00073 size_t*& aHighestOutputCount ) 00074 : _inputScribes( new vector< BdbGenericScribe* > ) , 00075 _inputRegistry( new BdbEvtObjLocReg( aHighestInputCount ) ) , 00076 _outputScribes( new vector< BdbGenericScribe* > ) , 00077 _bulkOutputRegistry( new BdbEvtObjLocReg( aHighestOutputCount , 00078 _inputRegistry ) ), 00079 _outputRegistry( new BdbEvtObjLocReg( aHighestOutputCount , 00080 _bulkOutputRegistry ) ), 00081 _aHighestOutputCount( aHighestOutputCount ) 00082 { 00083 } 00084 00085 // BdbConversionManager::BdbConversionManager( const BdbConversionManager& aRhs ) 00086 // { 00087 // } 00088 00089 //-------------- 00090 // Destructor -- 00091 //-------------- 00092 00093 BdbConversionManager::~BdbConversionManager() 00094 { 00095 // Reset all the Scribes as this manager no longer manages them. 00096 const size_t finishedOutput( _outputScribes->size() ) ; 00097 for ( size_t outScribeCount( 0 ) ; 00098 finishedOutput != outScribeCount ; 00099 ++outScribeCount ) { 00100 BdbGenericScribe* scribe( (*_outputScribes)[ outScribeCount ] ) ; 00101 if( std::find(_inputScribes->begin(),_inputScribes->end(),scribe)==_inputScribes->end() ) { 00102 scribe->reset() ; 00103 scribe->removeManager( this ) ; 00104 } 00105 } 00106 _outputScribes->clear(); 00107 delete _outputScribes ; 00108 delete _bulkOutputRegistry ; 00109 delete _outputRegistry ; 00110 00111 size_t finishedInput( _inputScribes->size() ) ; 00112 for ( size_t inScribeCount( 0 ) ; 00113 finishedInput != inScribeCount; 00114 ++inScribeCount ) { 00115 BdbGenericScribe* scribe( (*_inputScribes)[ inScribeCount ] ) ; 00116 scribe->reset() ; 00117 scribe->removeManager( this ) ; 00118 } 00119 _inputScribes->clear(); 00120 delete _inputScribes ; 00121 delete _inputRegistry; 00122 } 00123 00124 //------------- 00125 // Operators -- 00126 //------------- 00127 00128 // const BdbConversionManager& BdbConversionManager::operator=( const BdbConversionManager& aRhs ) 00129 // { 00130 // } 00131 00132 //------------- 00133 // Selectors -- 00134 //------------- 00135 00136 bool 00137 BdbConversionManager::convertToPersistent( const AbsEvent& aTEvent , 00138 const BdbAbsPlacementManager& aPlacementManager , 00139 BdbEventT& aPEvent , 00140 bool aReplacePersistentMappings, 00141 bool notBulk ) const 00142 { 00143 bool success( true ) ; 00144 00145 if ( aReplacePersistentMappings ) { 00146 _bulkOutputRegistry->setReplaceMode() ; 00147 _outputRegistry->setReplaceMode() ; 00148 } 00149 00150 const size_t finishedOutput( _outputScribes->size() ) ; 00151 size_t outScribeCount( 0 ) ; 00152 for ( outScribeCount = 0 ; 00153 finishedOutput != outScribeCount ; 00154 ++outScribeCount ) { 00155 BdbGenericScribe* aScribe = (*_outputScribes)[ outScribeCount ]; 00156 BdbEvtObjLocReg* regToUse = 0; 00157 bool isBulk = aScribe->isBulk( aPlacementManager ); 00158 if ( isBulk ) regToUse = _bulkOutputRegistry; 00159 else regToUse = _outputRegistry; 00160 00161 if ( !(notBulk && isBulk) ) // check we want to write bulk 00162 { 00163 bool result( aScribe->attemptPersistent( aTEvent , 00164 aPlacementManager , 00165 aPEvent , 00166 *regToUse ) ) ; 00167 // If no failures up until now then update success flag. 00168 if ( success ) { 00169 success = result ; 00170 } 00171 } 00172 } 00173 00174 for ( outScribeCount = 0 ; 00175 finishedOutput != outScribeCount ; 00176 ++outScribeCount ) { 00177 BdbGenericScribe* aScribe = (*_outputScribes)[ outScribeCount ]; 00178 bool isBulk = aScribe->isBulk( aPlacementManager ); 00179 if ( !(notBulk && isBulk) ) // check we want to write bulk 00180 { 00181 bool result( (*_outputScribes)[ outScribeCount ]->fillRefs() ) ; 00182 00183 // If no failures up until now then update success flag. 00184 if ( success ) { 00185 success = result ; 00186 } 00187 } 00188 } 00189 00190 _bulkOutputRegistry->clearReplaceMode() ; 00191 _outputRegistry->clearReplaceMode() ; 00192 00193 return( success ) ; 00194 } 00195 00196 bool 00197 BdbConversionManager::convertToTransient( const BdbEventT& aPEvent , 00198 AbsEvent& aTEvent ) const 00199 { 00200 bool success( true ) ; 00201 00202 const size_t finishedInput( _inputScribes->size() ) ; 00203 size_t inScribeCount( 0 ) ; 00204 for ( inScribeCount = 0 ; 00205 finishedInput != inScribeCount ; 00206 ++inScribeCount ) { 00207 bool result ( (*_inputScribes)[ inScribeCount ]->attemptTransient( aPEvent , 00208 aTEvent , 00209 *_inputRegistry ) ) ; 00210 00211 // If no failures up until now then update success flag. 00212 if ( success ) { 00213 success = result ; 00214 } 00215 00216 } 00217 00218 for ( inScribeCount = 0 ; 00219 finishedInput != inScribeCount ; 00220 ++inScribeCount ) { 00221 bool result( (*_inputScribes)[ inScribeCount ]->fillPointers() ) ; 00222 00223 // If no failures up until now then update success flag. 00224 if ( success ) { 00225 success = result ; 00226 } 00227 } 00228 return( success ) ; 00229 } 00230 00231 bool 00232 BdbConversionManager::outputRequired() const 00233 { 00234 return( 0 != _outputScribes->size() ) ; 00235 } 00236 00237 bool 00238 BdbConversionManager::inputRequired() const 00239 { 00240 return( 0 != _inputScribes->size() ) ; 00241 } 00242 00243 //------------- 00244 // Modifiers -- 00245 //------------- 00246 00247 void 00248 BdbConversionManager::addScribeForOutput( BdbGenericScribe& aScribe ) 00249 { 00250 _outputScribes->push_back( &aScribe ) ; 00251 aScribe.addManager( this ) ; 00252 } 00253 00254 void 00255 BdbConversionManager::removeScribeForOutput( BdbGenericScribe& aScribe ) 00256 { 00257 vector< BdbGenericScribe* >::iterator pos=std::find(_outputScribes->begin(),_outputScribes->end(), &aScribe); 00258 if (pos!=_outputScribes->end()){ 00259 _outputScribes->erase(pos) ; 00260 } 00261 if( std::find(_inputScribes->begin(),_inputScribes->end(),&aScribe )==_inputScribes->end() ) { 00262 aScribe.removeManager( this ) ; 00263 } 00264 } 00265 00266 void 00267 BdbConversionManager::addScribeForInput( BdbGenericScribe& aScribe ) 00268 { 00269 _inputScribes->push_back( &aScribe ) ; 00270 aScribe.addManager( this ) ; 00271 } 00272 00273 void 00274 BdbConversionManager::removeScribeForInput( BdbGenericScribe& aScribe ) 00275 { 00276 vector< BdbGenericScribe* >::iterator pos=std::find(_inputScribes->begin(),_inputScribes->end(), &aScribe); 00277 if (pos!=_inputScribes->end()){ 00278 _inputScribes->erase(pos) ; 00279 } 00280 if( std::find(_outputScribes->begin(),_outputScribes->end(),&aScribe )==_outputScribes->end() ) { 00281 aScribe.removeManager( this ) ; 00282 } 00283 } 00284 00285 bool 00286 BdbConversionManager::resetOutputRegistry( BdbCMResetLevel resetLevel, 00287 const BdbAbsPlacementManager& placement ) 00288 { 00289 assert( resetLevel == full || resetLevel == partial ); 00290 00291 // Delete old registry 00292 delete _outputRegistry; 00293 _outputRegistry = 0; 00294 00295 if ( resetLevel == full ) 00296 { 00297 // Delete old registry 00298 delete _bulkOutputRegistry; 00299 _bulkOutputRegistry = 0; 00300 00301 // Create new one 00302 _bulkOutputRegistry = new BdbEvtObjLocReg( _aHighestOutputCount, 00303 _inputRegistry ); 00304 assert( _bulkOutputRegistry != 0 ); 00305 00306 // As we've reset the output registry we also need to reset the output 00307 // scribes 00308 size_t i=0, length=_outputScribes->size(); 00309 for ( i=0; i<length; i++ ) (*_outputScribes)[i]->reset(); 00310 } 00311 else 00312 { 00313 // As we've reset the output registry we also need to reset the output 00314 // scribes which are used at the micro/mini level 00315 size_t i=0, length=_outputScribes->size(); 00316 for ( i=0; i<length; i++ ) 00317 { 00318 BdbGenericScribe* aScribe = (*_outputScribes)[i]; 00319 if ( !aScribe->isBulk( placement ) ) aScribe->reset(); 00320 } 00321 } 00322 00323 // Create new one 00324 _outputRegistry = new BdbEvtObjLocReg( _aHighestOutputCount, 00325 _bulkOutputRegistry ); 00326 assert( _outputRegistry != 0 ); 00327 00328 return true; 00329 } 00330 00331 #endif // BDBCONVERSIONMANAGER_CC 00332 00333 00334
BaBar Public Site | SLAC | News | Links | Who's Who | Contact Us
Page Owner: Jacek Becla
Last Update: October 04, 2002