Concept Object to query a specific database table. More...
#include <TDbiTableProxy.hxx>
Public Member Functions | |
const TDbiDBProxy & | GetDBProxy () const |
TDbiCascader & | GetCascader () |
const TDbiTableMetaData & | GetMetaData () const |
const TDbiTableMetaData & | GetMetaValid () const |
string | GetRowName () const |
string | GetTableName () const |
TDbiCache * | GetCache () |
const TDbiResultSet * | Query (const TVldContext &vc, const TDbi::Task &task, Bool_t findFullTimeWindow=true) |
const TDbiResultSet * | Query (const string &context, const TDbi::Task &task, const string &data, const string &fillOpts) |
const TDbiResultSet * | Query (UInt_t seqNo, UInt_t dbNo) |
const TDbiResultSet * | Query (const TDbiValidityRec &vrec, Bool_t canReuse=kTRUE) |
TVldTimeStamp | QueryOverlayCreationDate (const TDbiValidityRec &vrec, UInt_t dbNo) |
void | RefreshMetaData () |
void | SetSqlCondition (const string &sql) |
Bool_t | TableExists () const |
Protected Member Functions | |
TDbiTableProxy (TDbiCascader *cascader, const string &tableName, const TDbiTableRow *tableRow) | |
virtual | ~TDbiTableProxy () |
Private Member Functions | |
TDbiTableProxy (const TDbiTableProxy &) | |
TDbiTableProxy & | operator= (const TDbiTableProxy &) |
Bool_t | CanReadL2Cache () const |
Level 2 (disk) cache management. | |
Bool_t | CanWriteL2Cache () const |
Bool_t | RestoreFromL2Cache (const TDbiValidityRecBuilder &builder) |
Bool_t | SaveToL2Cache (const string &name, TDbiResultSet &res) |
Private Attributes | |
TDbiCascader * | fCascader |
Pointer to one and only cascader. | |
TDbiTableMetaData | fMetaData |
Meta data for main(data) table. | |
TDbiTableMetaData | fMetaValid |
Meta data for aux. (validity)table. | |
Bool_t | fCanL2Cache |
True if row supports L2 cache. | |
TDbiCache * | fCache |
Associated cache for result. | |
TDbiDBProxy | fDBProxy |
Proxy to database. | |
Bool_t | fExists |
true if table exists; | |
string | fTableName |
Table Name. | |
TDbiTableRow * | fTableRow |
Pet object used to create new rows. | |
Friends | |
class | TDbiDatabaseManager |
Concept Object to query a specific database table.
Purpose A TDbiTableProxy is an object that knows how to send queries to a specific database table. Internally it uses a cache to minimise I/O. Contact: A.Finch@lancaster.ac.uk
Definition at line 43 of file TDbiTableProxy.hxx.
TDbiTableProxy::TDbiTableProxy | ( | TDbiCascader * | cascader, | |
const string & | tableName, | |||
const TDbiTableRow * | tableRow | |||
) | [protected] |
Constructors (protected because created and owned by TDbiDatabaseManager).
Purpose: Constructor Arguments: in cascader Reference to one and only cascader in tableName Table name. in tableRow Example table row object. Return: n/a Contact: N. West Specification:- ============= o Create table proxy for supplied table name.
TDbiTableProxy::~TDbiTableProxy | ( | ) | [protected, virtual] |
Definition at line 89 of file TDbiTableProxy.cxx.
References fCache, fTableName, fTableRow, and SK_DBI_Trace.
00089 { 00090 // 00091 // 00092 // Purpose: Destructor 00093 // 00094 // Arguments: 00095 // None. 00096 // 00097 // Return: n/a 00098 // 00099 // Contact: N. West 00100 // 00101 // Specification:- 00102 // ============= 00103 // 00104 // o Destroy object. 00105 00106 00107 // Program Notes:- 00108 // ============= 00109 00110 // None. 00111 00112 00113 SK_DBI_Trace( "Destroying TDbiTableProxy " 00114 << fTableName << " at " << this 00115 << " "); 00116 delete fCache; 00117 delete fTableRow; 00118 00119 }
TDbiTableProxy::TDbiTableProxy | ( | const TDbiTableProxy & | ) | [private] |
Bool_t TDbiTableProxy::CanReadL2Cache | ( | ) | const [private] |
Level 2 (disk) cache management.
Definition at line 122 of file TDbiTableProxy.cxx.
References fCanL2Cache.
Referenced by Query(), and RestoreFromL2Cache().
00122 { 00123 // 00124 00125 return fCanL2Cache && TDbiBinaryFile::CanReadL2Cache(); 00126 00127 }
Bool_t TDbiTableProxy::CanWriteL2Cache | ( | ) | const [private] |
Definition at line 128 of file TDbiTableProxy.cxx.
References fCanL2Cache.
Referenced by SaveToL2Cache().
00128 { 00129 // 00130 00131 return fCanL2Cache && TDbiBinaryFile::CanWriteL2Cache(); 00132 00133 }
TDbiCache* TDbiTableProxy::GetCache | ( | ) | [inline] |
Definition at line 59 of file TDbiTableProxy.hxx.
References fCache.
Referenced by TDbiDatabaseManager::PurgeCaches().
00059 { return fCache;}
TDbiCascader& TDbiTableProxy::GetCascader | ( | ) | [inline] |
Definition at line 52 of file TDbiTableProxy.hxx.
References fCascader.
Referenced by TDbiLogEntry::Write().
00052 { return *fCascader; }
const TDbiDBProxy& TDbiTableProxy::GetDBProxy | ( | ) | const [inline] |
Definition at line 51 of file TDbiTableProxy.hxx.
References fDBProxy.
Referenced by ClassImp(), fCreationDate(), and TDbiSqlValPacket::Store().
00051 { return fDBProxy; }
const TDbiTableMetaData& TDbiTableProxy::GetMetaData | ( | ) | const [inline] |
Definition at line 53 of file TDbiTableProxy.hxx.
References fMetaData.
Referenced by TDbiSqlValPacket::AddRow(), and TDbiSqlValPacket::SetMetaData().
00053 { return fMetaData; }
const TDbiTableMetaData& TDbiTableProxy::GetMetaValid | ( | ) | const [inline] |
Definition at line 54 of file TDbiTableProxy.hxx.
References fMetaValid.
Referenced by TDbiSqlValPacket::AddRow(), TDbiSqlValPacket::Recreate(), and TDbiSqlValPacket::SetMetaData().
00054 { return fMetaValid; }
string TDbiTableProxy::GetRowName | ( | ) | const [inline] |
Definition at line 55 of file TDbiTableProxy.hxx.
References fTableRow.
Referenced by RestoreFromL2Cache(), and SaveToL2Cache().
string TDbiTableProxy::GetTableName | ( | ) | const [inline] |
Definition at line 57 of file TDbiTableProxy.hxx.
References fTableName.
Referenced by TDbiSqlValPacket::AddRow(), TDbiDatabaseManager::ApplySqlCondition(), Query(), TDbiDatabaseManager::RefreshMetaData(), RestoreFromL2Cache(), SaveToL2Cache(), and TDbiConfigStream::Write().
00057 { return fTableName;}
TDbiTableProxy& TDbiTableProxy::operator= | ( | const TDbiTableProxy & | ) | [private] |
const TDbiResultSet * TDbiTableProxy::Query | ( | const TDbiValidityRec & | vrec, | |
Bool_t | canReuse = kTRUE | |||
) |
Purpose: Apply non-agregate query to database table and return result. Arguments: vrec in The validity record that satisfies the query. canReuse in True if result is to be cached. Return: Query result (never zero even if query fails). Contact: N. West Specification:- ============= o Apply non-aggregated query to main database table. Cache if required, and return result.
Definition at line 347 of file TDbiTableProxy.cxx.
References TDbiCache::Adopt(), TDbiResultSet::CaptureExceptionLog(), fCache, fCascader, fDBProxy, fTableRow, TDbiValidityRec::GetDbNo(), TDbiExceptionLog::GetGELog(), TDbiValidityRec::GetL2CacheName(), TDbiValidityRec::GetSeqNo(), GetTableName(), TDbiValidityRec::GetTableProxy(), TDbiDBProxy::QuerySeqNo(), RestoreFromL2Cache(), SaveToL2Cache(), TDbiCache::Search(), TDbiResultSet::SetCanReuse(), TDbiExceptionLog::Size(), and SK_DBI_Severe.
00348 { 00349 // 00350 // 00351 // Purpose: Apply non-agregate query to database table and return result. 00352 // 00353 // Arguments: 00354 // vrec in The validity record that satisfies the query. 00355 // canReuse in True if result is to be cached. 00356 // 00357 // Return: Query result (never zero even if query fails). 00358 // 00359 // Contact: N. West 00360 // 00361 // Specification:- 00362 // ============= 00363 // 00364 // o Apply non-aggregated query to main database table. Cache if required, 00365 // and return result. 00366 00367 00368 // See if it can be recovered from the level 2 disk cache. 00369 00370 TDbiConnectionMaintainer cm(fCascader); //Stack object to hold connections 00371 00372 // Make Global Exception Log bookmark 00373 UInt_t startGEL = TDbiExceptionLog::GetGELog().Size()+1; 00374 00375 if ( canReuse ) { 00376 TDbiValidityRecBuilder builder(vrec,this->GetTableName()); 00377 if ( this->RestoreFromL2Cache(builder) ) { 00378 const TDbiResultSet* res = fCache->Search(vrec); 00379 if ( res ) return res; 00380 } 00381 } 00382 00383 unsigned int seqNo = vrec.GetSeqNo(); 00384 TDbiResultSet* result = 0; 00385 00386 // If no records, create an empty TDbiResultSet. 00387 if ( ! seqNo ) { 00388 result = new TDbiResultSetNonAgg(0,0,&vrec); 00389 } 00390 00391 // If query does not apply to this table, report error and 00392 // produce an empty TDbiResultSet. 00393 00394 else if (vrec.GetTableProxy()->GetTableName() != GetTableName() ) { 00395 SK_DBI_Severe( "Unable to satisfy TDbiValidityRec keyed query:" << " " 00396 << vrec 00397 << " was filled by " << vrec.GetTableProxy()->GetTableName() 00398 << " not by this TDbiTableProxy (" 00399 << GetTableName() << ")" << " "); 00400 result = new TDbiResultSetNonAgg(0,0,&vrec); 00401 } 00402 00403 else { 00404 00405 00406 // Apply query, and build DiResult from its TDbiInRowStream. 00407 00408 TDbiInRowStream* rs = fDBProxy.QuerySeqNo(seqNo,vrec.GetDbNo()); 00409 result = new TDbiResultSetNonAgg(rs,fTableRow,&vrec); 00410 delete rs; 00411 } 00412 00413 // Record latest entries from Global Exception Log. 00414 result->CaptureExceptionLog(startGEL); 00415 00416 // Cache in memory and on disk if required and return the results. 00417 00418 fCache->Adopt(result); 00419 if ( canReuse ) this->SaveToL2Cache(vrec.GetL2CacheName(),*result); 00420 else result->SetCanReuse(kFALSE); 00421 00422 return result; 00423 00424 }
const TDbiResultSet * TDbiTableProxy::Query | ( | UInt_t | seqNo, | |
UInt_t | dbNo | |||
) |
Purpose: Apply non-agregate query to database table and return result. Arguments: seqNo in The sequence number of validity record that satisfies the query. dbNo in Database number in the cascade. Return: Query result (never zero even if query fails).
Definition at line 301 of file TDbiTableProxy.cxx.
References TDbiCache::Adopt(), TDbiResultSet::CaptureExceptionLog(), fCache, fCascader, fDBProxy, TDbiExceptionLog::GetGELog(), TDbiResultSetNonAgg::GetNumRows(), TDbiResultSetNonAgg::GetTableRow(), Query(), TDbiDBProxy::QueryValidity(), and TDbiExceptionLog::Size().
00301 { 00302 // 00303 // 00304 // Purpose: Apply non-agregate query to database table and return result. 00305 // 00306 // Arguments: 00307 // seqNo in The sequence number of validity record that satisfies the query. 00308 // dbNo in Database number in the cascade. 00309 // 00310 // Return: Query result (never zero even if query fails). 00311 00312 TDbiConnectionMaintainer cm(fCascader); //Stack object to hold connections 00313 00314 // Make Global Exception Log bookmark 00315 UInt_t startGEL = TDbiExceptionLog::GetGELog().Size()+1; 00316 00317 // Apply SEQNO query to cascade member. 00318 TDbiInRowStream* rs = fDBProxy.QueryValidity(seqNo,dbNo); 00319 TDbiValidityRec tr; 00320 TDbiResultSetNonAgg result(rs,&tr,0,kFALSE); 00321 delete rs; 00322 00323 // If query failed, return an empty result. 00324 if ( result.GetNumRows() == 0 ) { 00325 TDbiResultSetNonAgg* empty = new TDbiResultSetNonAgg(); 00326 // Record latest entries from Global Exception Log. 00327 empty->CaptureExceptionLog(startGEL); 00328 fCache->Adopt(empty); 00329 return empty; 00330 } 00331 00332 // Otherwise perform a validity rec query, but don't 00333 // allow result to be used; it's validity has not been trimmed 00334 // by neighbouring records. 00335 00336 const TDbiValidityRec* vrec 00337 = dynamic_cast<const TDbiValidityRec*>(result.GetTableRow(0)); 00338 // Force off const - we haven't finished with TDbiResultSet yet! 00339 TDbiResultSet* res = const_cast<TDbiResultSet*>(Query(*vrec,kFALSE)); 00340 // Record latest entries from Global Exception Log. 00341 res->CaptureExceptionLog(startGEL); 00342 return res; 00343 00344 }
const TDbiResultSet * TDbiTableProxy::Query | ( | const string & | context, | |
const TDbi::Task & | task, | |||
const string & | data, | |||
const string & | fillOpts | |||
) |
Purpose: Apply extended context query to database table and return result. Arguments: context in The Validity Context (see TDbiSqlContext) task in The task of the query. data in Optional SQL extension to secondary query. fillOpts in Optional fill options (available to TDbiTableRow) Return: Query result (never zero even if query fails). Contact: N. West Specification:- ============= o Apply extended context query to database table and return result. o Don't save/restore to L2 cache: encoding the query name as a file name would be cumbersome and in any case extended queries are abnormal so optimisation is unwarranted. Construct the query's "SQL Qualifiers" by forming the 3 strings (which task encoded into the context) into a single semi-colon separated string.
Definition at line 229 of file TDbiTableProxy.cxx.
References TDbiCache::Adopt(), TDbiResultSet::CaptureExceptionLog(), fCache, fCascader, fDBProxy, fTableName, fTableRow, TDbiExceptionLog::GetGELog(), TDbi::kAnyTask, TDbiCache::Search(), TDbiExceptionLog::Size(), and SK_DBI_Verbose.
00232 { 00233 // 00234 // 00235 // Purpose: Apply extended context query to database table and return result. 00236 // 00237 // Arguments: 00238 // context in The Validity Context (see TDbiSqlContext) 00239 // task in The task of the query. 00240 // data in Optional SQL extension to secondary query. 00241 // fillOpts in Optional fill options (available to TDbiTableRow) 00242 // 00243 // Return: Query result (never zero even if query fails). 00244 // 00245 // Contact: N. West 00246 // 00247 // Specification:- 00248 // ============= 00249 // 00250 // o Apply extended context query to database table and return result. 00251 // 00252 // o Don't save/restore to L2 cache: encoding the query name as a file name 00253 // would be cumbersome and in any case extended queries are abnormal 00254 // so optimisation is unwarranted. 00255 00256 00257 // Construct the query's "SQL Qualifiers" by forming the 3 strings 00258 // (which task encoded into the context) into a single semi-colon 00259 // separated string. 00260 00261 std::ostringstream os; 00262 os << context; 00263 if ( task != TDbi::kAnyTask 00264 ) os << " and Task = " << task; 00265 os << ';' << data << ';' << fillOpts; 00266 string sqlQualifiers = os.str(); 00267 00268 SK_DBI_Verbose( "Extended query: sqlQualifiers: " << sqlQualifiers << " "); 00269 00270 // See if there is one already in the cache. 00271 00272 if ( const TDbiResultSet* result = fCache->Search(sqlQualifiers) 00273 ) return result; 00274 00275 TDbiConnectionMaintainer cm(fCascader); //Stack object to hold connections 00276 00277 // Make Global Exception Log bookmark 00278 UInt_t startGEL = TDbiExceptionLog::GetGELog().Size()+1; 00279 00280 // Build a complete set of effective validity records from the database. 00281 TDbiValidityRecBuilder builder(fDBProxy,context,task); 00282 00283 // For extended context queries, TDbiValidityRecBuilder will always 00284 // assemble a result that has to be represented by a TDbiResultSetAgg 00285 00286 TDbiResultSet* result = new TDbiResultSetAgg(fTableName, 00287 fTableRow, 00288 fCache, 00289 &builder, 00290 &fDBProxy, 00291 sqlQualifiers); 00292 // Record latest entries from Global Exception Log. 00293 result->CaptureExceptionLog(startGEL); 00294 00295 fCache->Adopt(result); 00296 return result; 00297 00298 }
const TDbiResultSet * TDbiTableProxy::Query | ( | const TVldContext & | vc, | |
const TDbi::Task & | task, | |||
Bool_t | findFullTimeWindow = true | |||
) |
Purpose: Apply context specific query to database table and return result. Arguments: vc in The Validity Context for the query. task in The task of the query. findFullTimeWindow in Attempt to find full validity of query i.e. beyond TDbi::GetTimeGate Return: Query result (never zero even if query fails). Contact: N. West Specification:- ============= o Apply query to database table and return result. Program Notes:- ============= None. See if there is one already in the cache for universal aggregate no.
Definition at line 137 of file TDbiTableProxy.cxx.
References TDbiCache::Adopt(), CanReadL2Cache(), TDbiResultSet::CaptureExceptionLog(), fCache, fCascader, fDBProxy, fTableName, fTableRow, TDbiExceptionLog::GetGELog(), TDbiValidityRecBuilder::GetL2CacheName(), TDbiValidityRecBuilder::GetNumValidityRec(), TDbiValidityRecBuilder::GetValidityRec(), TDbiValidityRec::IsGap(), TDbiValidityRecBuilder::NonAggregated(), RestoreFromL2Cache(), SaveToL2Cache(), TDbiCache::Search(), TDbiExceptionLog::Size(), and SK_DBI_Info.
Referenced by Query().
00139 { 00140 // 00141 // 00142 // Purpose: Apply context specific query to database table and return result. 00143 // 00144 // Arguments: 00145 // vc in The Validity Context for the query. 00146 // task in The task of the query. 00147 // findFullTimeWindow 00148 // in Attempt to find full validity of query 00149 // i.e. beyond TDbi::GetTimeGate 00150 // 00151 // Return: Query result (never zero even if query fails). 00152 // 00153 // Contact: N. West 00154 // 00155 // Specification:- 00156 // ============= 00157 // 00158 // o Apply query to database table and return result. 00159 00160 // Program Notes:- 00161 // ============= 00162 00163 // None. 00164 00165 // See if there is one already in the cache for universal aggregate no. 00166 00167 if ( const TDbiResultSet* result = fCache->Search(vc,task) 00168 ) return result; 00169 00170 TDbiConnectionMaintainer cm(fCascader); //Stack object to hold connections 00171 00172 // Make Global Exception Log bookmark 00173 UInt_t startGEL = TDbiExceptionLog::GetGELog().Size()+1; 00174 00175 // Build a complete set of effective validity record from the database. 00176 TDbiValidityRecBuilder builder(fDBProxy,vc,task,-1,findFullTimeWindow); 00177 00178 // Deal with non-aggregated data. 00179 00180 if ( builder.NonAggregated() ) { 00181 00182 TDbiValidityRec effVRec = builder.GetValidityRec(0); 00183 // Force off const - we haven't finished with TDbiResultSet yet! 00184 TDbiResultSet* result = const_cast<TDbiResultSet*>(Query(effVRec)); 00185 // Record latest entries from Global Exception Log. 00186 result->CaptureExceptionLog(startGEL); 00187 return result; 00188 } 00189 00190 // Deal with aggregated data. 00191 00192 // Don't look in the level 2 cache if more than half of the 00193 // component aggregates are already in the cache; 00194 // for in this case, the chances are that we have just 00195 // crossed a validity boundary in only a few aggregates and 00196 // we don't want to waste time loading in a full set only to throw 00197 // it away again. 00198 00199 if ( this->CanReadL2Cache() ) { 00200 UInt_t numPresent = 0; 00201 UInt_t numRequired = 0; 00202 Int_t maxRow = builder.GetNumValidityRec() - 1; 00203 for ( Int_t rowNo = 1; rowNo <= maxRow; ++rowNo ) { 00204 const TDbiValidityRec& vrec = builder.GetValidityRec(rowNo); 00205 if ( fCache->Search(vrec) ) ++numPresent; 00206 else if ( ! vrec.IsGap() ) ++numRequired; 00207 } 00208 if ( numRequired < numPresent ) SK_DBI_Info( "Skipping search of L2 cache; already have " 00209 << numPresent << " aggregates, and only require a further " 00210 << numRequired << " "); 00211 else this->RestoreFromL2Cache(builder); 00212 } 00213 00214 TDbiResultSet* result = new TDbiResultSetAgg(fTableName, 00215 fTableRow, 00216 fCache, 00217 &builder, 00218 &fDBProxy); 00219 // Record latest entries from Global Exception Log. 00220 result->CaptureExceptionLog(startGEL); 00221 00222 fCache->Adopt(result); 00223 this->SaveToL2Cache(builder.GetL2CacheName(),*result); 00224 return result; 00225 00226 }
TVldTimeStamp TDbiTableProxy::QueryOverlayCreationDate | ( | const TDbiValidityRec & | vrec, | |
UInt_t | dbNo | |||
) |
Purpose: Determine a suitable Creation Date so that this validity record, if written to the selected DB, will overlay correctly. Specification:- ============= o Determine optimal Creation Date to overlay new data. See Program Notes. Program Notes:- ============= It is normal practice, particularly for calibration data, to have overlapping the validity records. Each time a new set of runs are processed the start time of the validity is set to the start time of the first run and the end time is set beyond the start time by an interval that characterises the stability of the constants. So long as a new set of constants is created before the end time is reached there will be no gap. Where there is an overlap the Creation Date is used to select the later constants on the basis that later is better. However, if reprocessing old data it is also normal practice to process recent data first and in this case the constants for earlier data get later creation dates and overlay works the wrong way. To solve this, the creation date is faked as follows:- 1. For new data i.e. data that does not overlay any existing data, the creation date is set to the validity start time. 2. For replacement data i.e. data that does overlay existing data, the creation date is set to be one minute greater than the Creation Date on the current best data. This scheme ensures that new data will overlay existing data at the start of its validity but will be itself overlaid by data that has a later start time (assuming validity record start times are more than a few minutes apart)
Definition at line 440 of file TDbiTableProxy.cxx.
References fCascader, fDBProxy, TDbiValidityRec::GetAggregateNo(), TDbiValidityRec::GetTask(), TDbiValidityRec::GetVldRange(), and SK_DBI_Debug.
00442 { 00443 // 00444 // Purpose: Determine a suitable Creation Date so that this validity 00445 // record, if written to the selected DB, will overlay 00446 // correctly. 00447 // 00448 // Specification:- 00449 // ============= 00450 // 00451 // o Determine optimal Creation Date to overlay new data. See Program Notes. 00452 00453 // Program Notes:- 00454 // ============= 00455 00456 00457 // It is normal practice, particularly for calibration data, to have 00458 // overlapping the validity records. Each time a new set of runs are 00459 // processed the start time of the validity is set to the start time of 00460 // the first run and the end time is set beyond the start time by an 00461 // interval that characterises the stability of the constants. So long 00462 // as a new set of constants is created before the end time is reached 00463 // there will be no gap. Where there is an overlap the Creation Date is 00464 // used to select the later constants on the basis that later is better. 00465 // However, if reprocessing old data it is also normal practice to 00466 // process recent data first and in this case the constants for earlier 00467 // data get later creation dates and overlay works the wrong way. To 00468 // solve this, the creation date is faked as follows:- 00469 // 00470 // 00471 // 1. For new data i.e. data that does not overlay any existing data, 00472 // the creation date is set to the validity start time. 00473 // 00474 // 2. For replacement data i.e. data that does overlay existing data, 00475 // the creation date is set to be one minute greater than the Creation 00476 // Date on the current best data. 00477 // 00478 // This scheme ensures that new data will overlay existing data at the 00479 // start of its validity but will be itself overlaid by data that has 00480 // a later start time (assuming validity record start times are more 00481 // than a few minutes apart) 00482 00483 00484 // Create a context that corresponds to the start time of the validity 00485 // range. Note that it is O.K. to use SimFlag and Detector masks 00486 // even though this could make the context ambiguous because the 00487 // context is only to be used to query the database and the SimFlag and 00488 // Detector values will be ORed against existing data so will match 00489 // all possible data that this validity range could overlay which is 00490 // just what we want. 00491 00492 const TVldRange& vr(vrec.GetVldRange()); 00493 TVldContext vc((DbiDetector::Detector_t) vr.GetDetectorMask(), 00494 (DbiSimFlag::SimFlag_t) vr.GetSimMask(), 00495 vr.GetTimeStart()); 00496 00497 TDbiConnectionMaintainer cm(fCascader); //Stack object to hold connections 00498 00499 // Build a complete set of effective validity records from the 00500 // selected database. 00501 TDbiValidityRecBuilder builder(fDBProxy,vc,vrec.GetTask(),dbNo); 00502 00503 // Pick up the validity record for the current aggregate. 00504 const TDbiValidityRec& vrecOvlay(builder.GetValidityRecFromAggNo(vrec.GetAggregateNo())); 00505 00506 // If its a gap i.e. nothing is overlayed, return the start time, otherwise 00507 // return its Creation Date plus one minute. 00508 TVldTimeStamp ovlayTS(vr.GetTimeStart()); 00509 if ( ! vrecOvlay.IsGap() ) { 00510 time_t overlaySecs = vrecOvlay.GetCreationDate().GetSec(); 00511 ovlayTS = TVldTimeStamp(overlaySecs + 60,0); 00512 } 00513 00514 SK_DBI_Debug( "Looking for overlay creation date for: " 00515 << vrec << "found it would overlap: " 00516 << vrecOvlay << " so overlay creation date set to " 00517 << ovlayTS.AsString("s") << " "); 00518 return ovlayTS; 00519 00520 }
void TDbiTableProxy::RefreshMetaData | ( | ) |
Purpose: Refresh meta data for table.
Definition at line 428 of file TDbiTableProxy.cxx.
References fDBProxy, fMetaData, fMetaValid, and TDbiDBProxy::StoreMetaData().
Referenced by TDbiDatabaseManager::RefreshMetaData().
00428 { 00429 // 00430 // 00431 // Purpose: Refresh meta data for table. 00432 // 00433 00434 fDBProxy.StoreMetaData(fMetaData); 00435 fDBProxy.StoreMetaData(fMetaValid); 00436 00437 }
Bool_t TDbiTableProxy::RestoreFromL2Cache | ( | const TDbiValidityRecBuilder & | builder | ) | [private] |
Purpose: Restore results from named level 2 disk cache into memory cache. Returns true if anything restored Specification:- ============= o Restore to cache but only if enabled and exists.
Definition at line 523 of file TDbiTableProxy.cxx.
References TDbiCache::Adopt(), CanReadL2Cache(), fCache, TDbiValidityRecBuilder::GetL2CacheName(), GetRowName(), TDbiValidityRec::GetSeqNo(), GetTableName(), TDbiResultSet::GetValidityRec(), TDbiValidityRecBuilder::GetValidityRecFromSeqNo(), TDbiTimerManager::gTimerManager, TDbiTimerManager::RecMainQuery(), TDbiCache::Search(), SK_DBI_Debug, SK_DBI_Info, and SK_DBI_Warn.
Referenced by Query().
00523 { 00524 // 00525 // 00526 // Purpose: Restore results from named level 2 disk cache into memory cache. 00527 // Returns true if anything restored 00528 00529 // Specification:- 00530 // ============= 00531 // 00532 // o Restore to cache but only if enabled and exists. 00533 00534 const string name(builder.GetL2CacheName()); 00535 SK_DBI_Debug( "Request to restore query result " << name 00536 << " "); 00537 if ( ! this->CanReadL2Cache() ) return kFALSE; 00538 string cacheFileName; 00539 if ( name != "" 00540 ) cacheFileName = this->GetTableName() + "_" 00541 + this->GetRowName() + "_" 00542 + name + ".dbi_cache"; 00543 TDbiBinaryFile bf(cacheFileName.c_str()); 00544 if ( ! bf.IsOK() ) { 00545 SK_DBI_Debug( "Caching disabled or cannot open " 00546 << bf.GetFileName() << " "); 00547 return kFALSE; 00548 } 00549 00550 static bool warnOnce = true; 00551 if ( warnOnce ) { 00552 SK_DBI_Warn( "\n\n\n" 00553 << " WARNING: Reading from the Level 2 cache has been activated.\n" 00554 << " ******* This should only be used for development and never for production !!!\n\n\n"); 00555 warnOnce = false; 00556 } 00557 00558 SK_DBI_Info( "Restoring query result from " << bf.GetFileName() << " "); 00559 TDbiTimerManager::gTimerManager.RecMainQuery(); 00560 00561 TDbiResultSet* result = 0; 00562 unsigned numRowsRest = 0; 00563 unsigned numRowsIgn = 0; 00564 UInt_t numNonAgg = 0; 00565 bf >> numNonAgg; 00566 00567 while ( numNonAgg-- ) { 00568 if ( ! bf.IsOK() ) break; 00569 if ( ! result ) result = new TDbiResultSetNonAgg; 00570 bf >> *result; 00571 00572 // The original query may have had a validity range truncated by 00573 // the time window, so replace its TDbiValidityRec with the one 00574 // just obtained from the database. 00575 const TDbiValidityRec& vrec = result->GetValidityRec(); 00576 UInt_t seqNo = vrec.GetSeqNo(); 00577 SK_DBI_Debug( "Fix up L2 cache TDbiValidityRec, by replacing: " << vrec 00578 << " with: " << builder.GetValidityRecFromSeqNo(seqNo) << " "); 00579 // Sneaky end-run round const to fix-up TDbiValidityRec. 00580 (const_cast<TDbiValidityRec&>(vrec)) = builder.GetValidityRecFromSeqNo(seqNo); 00581 00582 // Adopt only if not already in memory cache. 00583 if ( ! fCache->Search(vrec) ) { 00584 numRowsRest += result->GetNumRows(); 00585 fCache->Adopt(result); 00586 result = 0; 00587 } 00588 else numRowsIgn += result->GetNumRows(); 00589 } 00590 SK_DBI_Info( " a total of " << numRowsRest << " were restored (" 00591 << numRowsIgn << " ignored - already in memory)" << " "); 00592 00593 delete result; 00594 result = 0; 00595 00596 return numRowsRest > 0; 00597 00598 }
Bool_t TDbiTableProxy::SaveToL2Cache | ( | const string & | name, | |
TDbiResultSet & | res | |||
) | [private] |
Purpose: Save result to named level 2 cache. Returns true if saved. Specification:- ============= o Save to cache but only if enabled and suitable.
Definition at line 601 of file TDbiTableProxy.cxx.
References TDbiResultSet::CanSave(), CanWriteL2Cache(), TDbiBinaryFile::CanWriteL2Cache(), fCanL2Cache, TDbiResultSet::GetNumRows(), GetRowName(), GetTableName(), TDbiTimerManager::gTimerManager, TDbiTimerManager::RecMainQuery(), TDbiResultSet::ResultsFromDb(), SK_DBI_Debug, and SK_DBI_Info.
Referenced by Query().
00601 { 00602 // 00603 // 00604 // Purpose: Save result to named level 2 cache. Returns true if saved. 00605 00606 // Specification:- 00607 // ============= 00608 // 00609 // o Save to cache but only if enabled and suitable. 00610 00611 SK_DBI_Debug( "Request to save query result as " << name 00612 << " ; row supports L2 cache ?"<<fCanL2Cache 00613 << " ; binary file can write L2 Cache?"<< TDbiBinaryFile::CanWriteL2Cache() 00614 << " ; data from DB? " << res.ResultsFromDb() 00615 << " ; can be saved? " << res.CanSave() << " "); 00616 if ( ! this->CanWriteL2Cache() || ! res.ResultsFromDb() || ! res.CanSave() ) return kFALSE; 00617 00618 string cacheFileName; 00619 if ( name != "" 00620 ) cacheFileName = this->GetTableName() + "_" 00621 + this->GetRowName() + "_" 00622 + name + ".dbi_cache"; 00623 TDbiBinaryFile bf(cacheFileName.c_str(),kFALSE); 00624 if ( bf.IsOK() ) { 00625 SK_DBI_Info( "Saving query result (" << res.GetNumRows() 00626 << " rows) to " << bf.GetFileName() << " "); 00627 TDbiTimerManager::gTimerManager.RecMainQuery(); 00628 00629 // if writing a TDbiResultSetNonAgg, add leading count of 1. (if writing 00630 // a TDbiResultSetAgg it will writes its one leading count. 00631 if ( dynamic_cast<TDbiResultSetNonAgg*>(&res) ) { 00632 UInt_t numNonAgg = 1; 00633 bf << numNonAgg; 00634 } 00635 bf << res; 00636 return kTRUE; 00637 } 00638 SK_DBI_Debug( "Caching disabled or cannot open " 00639 << bf.GetFileName() << " "); 00640 return kFALSE; 00641 00642 }
void TDbiTableProxy::SetSqlCondition | ( | const string & | sql | ) |
Purpose: Apply Sql condition to its TDbiDBProxy. Arguments: sql in SQL condition string (excluding where). Return: n/a Contact: N. West Specification:- ============= o Apply Sql condition to its TDbiDBProxy. Program Notes:- ============= None.
Definition at line 645 of file TDbiTableProxy.cxx.
References fDBProxy, and TDbiDBProxy::SetSqlCondition().
Referenced by TDbiDatabaseManager::ApplySqlCondition().
00645 { 00646 // 00647 // 00648 // Purpose: Apply Sql condition to its TDbiDBProxy. 00649 // 00650 // Arguments: 00651 // sql in SQL condition string (excluding where). 00652 // 00653 // Return: n/a 00654 // 00655 // Contact: N. West 00656 // 00657 // Specification:- 00658 // ============= 00659 // 00660 // o Apply Sql condition to its TDbiDBProxy. 00661 00662 // Program Notes:- 00663 // ============= 00664 00665 // None. 00666 00667 fDBProxy.SetSqlCondition(sql); 00668 00669 }
Bool_t TDbiTableProxy::TableExists | ( | ) | const [inline] |
friend class TDbiDatabaseManager [friend] |
Definition at line 46 of file TDbiTableProxy.hxx.
TDbiCache* TDbiTableProxy::fCache [private] |
Associated cache for result.
Definition at line 307 of file TDbiTableProxy.hxx.
Referenced by GetCache(), Query(), RestoreFromL2Cache(), and ~TDbiTableProxy().
Bool_t TDbiTableProxy::fCanL2Cache [private] |
True if row supports L2 cache.
Definition at line 304 of file TDbiTableProxy.hxx.
Referenced by CanReadL2Cache(), CanWriteL2Cache(), and SaveToL2Cache().
TDbiCascader* TDbiTableProxy::fCascader [private] |
Pointer to one and only cascader.
Definition at line 295 of file TDbiTableProxy.hxx.
Referenced by GetCascader(), Query(), and QueryOverlayCreationDate().
TDbiDBProxy TDbiTableProxy::fDBProxy [private] |
Proxy to database.
Definition at line 310 of file TDbiTableProxy.hxx.
Referenced by GetDBProxy(), Query(), QueryOverlayCreationDate(), RefreshMetaData(), and SetSqlCondition().
Bool_t TDbiTableProxy::fExists [private] |
true if table exists;
Definition at line 313 of file TDbiTableProxy.hxx.
Referenced by TableExists().
TDbiTableMetaData TDbiTableProxy::fMetaData [private] |
Meta data for main(data) table.
Definition at line 298 of file TDbiTableProxy.hxx.
Referenced by GetMetaData(), and RefreshMetaData().
TDbiTableMetaData TDbiTableProxy::fMetaValid [private] |
Meta data for aux. (validity)table.
Definition at line 301 of file TDbiTableProxy.hxx.
Referenced by GetMetaValid(), and RefreshMetaData().
string TDbiTableProxy::fTableName [private] |
Table Name.
Definition at line 316 of file TDbiTableProxy.hxx.
Referenced by GetTableName(), Query(), and ~TDbiTableProxy().
TDbiTableRow* TDbiTableProxy::fTableRow [private] |
Pet object used to create new rows.
Definition at line 319 of file TDbiTableProxy.hxx.
Referenced by GetRowName(), Query(), and ~TDbiTableProxy().