![]() |
|
|
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 /CdbBdb/CdbBdbProxyCache.cc
Go to the documentation of this file.00001 /// The implementation of the CdbBdbProxyCache class. 00002 /** 00003 * @see CdbBdbProxyCache 00004 */ 00005 #include "BaBar/BaBar.hh" 00006 00007 #include "CdbBdb/CdbBdbProxyCache.hh" 00008 #include "CdbBdb/CdbBdbProxyElement.hh" 00009 #include "CdbBdb/CdbBdbObjectConvertor.hh" 00010 00011 #include "CdbBase/CdbStateId.hh" 00012 #include "CdbBase/CdbObject.hh" 00013 #include "CdbBase/CdbCondition.hh" 00014 00015 #include "BdbTime/BdbTime.hh" 00016 00017 #include <assert.h> 00018 00019 CdbBdbProxyCache::CdbBdbProxyCache( const char* theFullConditionPath ) 00020 { 00021 if( 0 != theFullConditionPath ) { 00022 _elements.push_back( CdbBdbProxyElement( std::string( theFullConditionPath ), 00023 0, 00024 BdbIntervalBase( BdbTime::minusInfinity, 00025 BdbTime::plusInfinity ), 00026 false )); 00027 } 00028 } 00029 00030 CdbBdbProxyCache::~CdbBdbProxyCache( ) 00031 { } 00032 00033 void 00034 CdbBdbProxyCache::subscribeCondition( const char* theFullPath ) 00035 { 00036 assert( 0 != theFullPath ); 00037 00038 _elements.push_back( CdbBdbProxyElement( std::string( theFullPath ), 00039 0, 00040 BdbIntervalBase( BdbTime::minusInfinity, 00041 BdbTime::plusInfinity ), 00042 false )); 00043 } 00044 00045 void 00046 CdbBdbProxyCache::subscribeCondition( const std::string& theFullPath ) 00047 { 00048 subscribeCondition(theFullPath.c_str()); 00049 } 00050 00051 00052 void 00053 CdbBdbProxyCache::unSubscribeCondition( const char* theFullPath ) 00054 { 00055 std::vector<CdbBdbProxyElement>::iterator itr; 00056 for( itr = _elements.begin( ); itr < _elements.end( ); ++itr ) { 00057 if((*itr).name( ) == theFullPath ) { 00058 _elements.erase( itr ); 00059 } 00060 } 00061 } 00062 00063 void 00064 CdbBdbProxyCache::unSubscribeCondition( const std::string& theFullPath ) 00065 { 00066 unSubscribeCondition(theFullPath.c_str()); 00067 } 00068 00069 void 00070 CdbBdbProxyCache::unSubscribeAllConditions( ) 00071 { 00072 _elements.clear( ); 00073 } 00074 00075 bool 00076 CdbBdbProxyCache::isCacheValid( const BdbTime& theValidityTime ) const 00077 { 00078 bool result = true; 00079 { 00080 std::vector<CdbBdbProxyElement>::const_iterator itr; 00081 for( itr = _elements.begin( ); itr < _elements.end( ); ++itr ) { 00082 00083 // The cache is not valid if an element has 0-0-0-0 persistent 00084 // reference or the specified time is not in the validity interval 00085 // of the object. 00086 00087 if( BdbIsNull((*itr).objectRef( )) || 00088 !(*itr).validity( ).inInterval( theValidityTime )) { 00089 00090 result = false; 00091 break; 00092 } 00093 } 00094 } 00095 return result; 00096 } 00097 00098 CdbStatus 00099 CdbBdbProxyCache::updateCache( const BdbTime& theValidityTime, 00100 const CdbStateId& theStateId, 00101 std::vector<CdbBdbProxyElement>& theListOfElements ) 00102 { 00103 CdbStatus result = CdbStatus::Error; 00104 00105 // Remove all elements from the passed vector 00106 00107 theListOfElements.clear( ); 00108 00109 do { 00110 00111 // Update elements, which need to be updated 00112 00113 bool failed = false; 00114 { 00115 unsigned int num = _elements.size( ); 00116 for( unsigned int idx = 0; idx < num; ++idx ) { 00117 00118 // The cache is not valid if an element has 0-0-0-0 persistent 00119 // reference or the specified time is not in the validity interval 00120 // of the object. 00121 00122 if( BdbIsNull(_elements[idx].objectRef( )) || 00123 !_elements[idx].validity( ).inInterval( theValidityTime )) { 00124 00125 // Reload condition 00126 00127 CdbConditionPtr cPtr; 00128 if( CdbStatus::Success != CdbCondition::instance( cPtr, 00129 _elements[idx].name( ).c_str( ))) { 00130 00131 cout << "CdbBdbProxyCache::updateCache() - ERROR." << endl 00132 << " Failed to find a condition for:" << endl 00133 << " CONDITION: " << _elements[idx].name( ).c_str( ) << endl; 00134 00135 failed = true; 00136 break; 00137 } 00138 CdbObjectPtr oPtr; 00139 if( CdbStatus::Success != cPtr->findObject( oPtr, 00140 theValidityTime )) { 00141 00142 cout << "CdbBdbProxyCache::updateCache() - ERROR." << endl 00143 << " Failed to find a condition object for:" << endl 00144 << " CONDITION: " << _elements[idx].name( ).c_str( ) << endl 00145 << " VALIDITY TIME: " << theValidityTime << endl; 00146 00147 failed = true; 00148 break; 00149 } 00150 00151 BdbHandle(BdbObject) objectH; 00152 if( CdbStatus::Success != CdbBdbObjectConvertor::narrow( objectH, oPtr )) { 00153 00154 cout << "CdbBdbProxyCache::updateCache() - ERROR." << endl 00155 << " Failed to narrow the loaded condition object into BdbObject type." << endl 00156 << " This might be an indication of inproper job configuration." << endl; 00157 00158 failed = true; 00159 break; 00160 } 00161 00162 // Update cache 00163 00164 _elements[idx] = CdbBdbProxyElement( _elements[idx].name( ), 00165 objectH, 00166 BdbIntervalBase( oPtr->begin( ), 00167 oPtr->end( )), 00168 true ); 00169 } else { 00170 00171 // The cache for this elements is up-to-data. Just make sure 00172 // that there is no "update" flag at theis element. This flag 00173 // could be set before. 00174 00175 if( _elements[idx].updated( )) { 00176 _elements[idx] = CdbBdbProxyElement( _elements[idx].name( ), 00177 _elements[idx].objectRef( ), 00178 _elements[idx].validity( ), 00179 false ); 00180 } 00181 } 00182 00183 // Fill up the record in the output vector 00184 00185 theListOfElements.push_back( _elements[idx] ); 00186 } 00187 } 00188 if( failed ) break; 00189 00190 // Done 00191 00192 result = CdbStatus::Success; 00193 00194 } while( false ); 00195 00196 return result; 00197 } 00198 00199 ///////////////// 00200 // End Of File // 00201 /////////////////
BaBar Public Site | SLAC | News | Links | Who's Who | Contact Us
Page Owner: Jacek Becla
Last Update: October 04, 2002