TDbiValidityRecBuilder Class Reference

Concept Constructor for the set of effective TDbiValidityRec objects for the current query. More...

#include <TDbiValidityRecBuilder.hxx>

Collaboration diagram for TDbiValidityRecBuilder:
Collaboration graph
[legend]

List of all members.

Public Types

enum  { kMAX_AGGREGATE_NO = 1000 }

Public Member Functions

 TDbiValidityRecBuilder (const TDbiDBProxy &proxy, const TVldContext &vc, const TDbi::Task &task, Int_t selectDbNo=-1, Bool_t findFullTimeWindow=true)
 TDbiValidityRecBuilder (const TDbiDBProxy &proxy, const string &context, const TDbi::Task &task)
 TDbiValidityRecBuilder (const TDbiValidityRec &vr, const std::string tableName)
virtual ~TDbiValidityRecBuilder ()
std::string GetL2CacheName () const
TDbi::Task GetTask () const
UInt_t GetNumValidityRec () const
Int_t IndexOfAggno (Int_t aggNo) const
 Get index of AggNo or -1 if missing.
Bool_t IsExtendedContext () const
const TDbiValidityRecGetValidityRec (Int_t rowNo) const
const TDbiValidityRecGetValidityRecFromAggNo (Int_t aggNo) const
const TDbiValidityRecGetValidityRecFromSeqNo (UInt_t SeqNo) const
Bool_t NonAggregated () const

Private Member Functions

UInt_t AddNewAgg (const TDbiValidityRec &vrec, Int_t aggNo)
 Add new aggregate into tables and return its index.
UInt_t AddNewGap (Int_t aggNo)
 Add new aggregate gap into tables and return its index.
void MakeGapRec (const TVldContext &vc, const string &tableName, Bool_t findFullTimeWindow=true)

Private Attributes

TDbiValidityRec fGap
Bool_t fIsExtendedContext
 True for extended context query.
TDbi::Task fTask
std::vector< TDbiValidityRecfVRecs
std::map< Int_t, UInt_t > fAggNoToIndex
 Map of Aggregate number to index in fVRecs.

Detailed Description

Concept Constructor for the set of effective TDbiValidityRec objects for the current query.

Id
TDbiValidityRecBuilder.hxx,v 1.1 2011/01/18 05:49:20 finch Exp

Purpose Parse a TDbiInRowStream from a validity query and build TDbiValidityRecs for the best, with TVldRange trimmed by neighbouring validity records of higher priority. For non-aggregated tables there will only be one TDbiValidityRec, but for aggregated data, there will be one for each aggregate Contact: A.Finch@lancaster.ac.uk

Definition at line 39 of file TDbiValidityRecBuilder.hxx.


Member Enumeration Documentation

anonymous enum
Enumerator:
kMAX_AGGREGATE_NO 

Definition at line 47 of file TDbiValidityRecBuilder.hxx.

00047 { kMAX_AGGREGATE_NO = 1000 };


Constructor & Destructor Documentation

TDbiValidityRecBuilder::TDbiValidityRecBuilder ( const TDbiDBProxy proxy,
const TVldContext vc,
const TDbi::Task task,
Int_t  selectDbNo = -1,
Bool_t  findFullTimeWindow = true 
)
TDbiValidityRecBuilder::TDbiValidityRecBuilder ( const TDbiDBProxy proxy,
const string &  context,
const TDbi::Task task 
)

Definition at line 270 of file TDbiValidityRecBuilder.cxx.

References AddNewGap(), fAggNoToIndex, fGap, fTask, fVRecs, TDbiValidityRec::GetAggregateNo(), TDbiDBProxy::GetNumDb(), TDbiResultSetNonAgg::GetNumRows(), GetNumValidityRec(), TDbiDBProxy::GetTableName(), TDbiResultSetNonAgg::GetTableRow(), GetValidityRec(), TDbiDBProxy::QueryValidity(), SK_DBI_Trace, SK_DBI_Verbose, SK_DBI_Warn, and TDbiDBProxy::TableExists().

00272                                                                   :
00273 fIsExtendedContext(kTRUE),
00274 fTask(task)
00275 {
00276 //
00277 //  Purpose:  Constructor for extended context queries.
00278 //
00279 //  Arguments:
00280 //    proxy        in    Database proxy for this table.
00281 //    context      in    The SQL corresponding to the extended context for the query.
00282 //    task         in    The task of the query.
00283 //
00284 //  Return:    n/a
00285 //
00286 //  Contact:   N. West
00287 //
00288 //  Specification:-
00289 //  =============
00290 //
00291 //  o Create ValidityRecBuilder by applying a validity query to
00292 //    the database table and building a set of TDbiValidityRec
00293 //    objects from the resulting TDbiInRowStream.
00294 
00295 
00296 //  Program Notes:-
00297 //  =============
00298 
00299 //  None.
00300 
00301 
00302   SK_DBI_Trace( "Creating TDbiValidityRecBuilder"
00303                             << " for extended context " << context << "  ");
00304 
00305 // Prime fVRecs with a gap that will not be used but makes the result
00306 // look like an aggregated result.
00307 
00308   SK_DBI_Verbose( "Initialising with gap record " << fGap << "  ");
00309   this->AddNewGap(-1);
00310 
00311 // Check to see if table exists.
00312 
00313   unsigned int numVRecIn = 0;
00314 
00315   if ( ! proxy.TableExists() ) {
00316     SK_DBI_Warn(  "TDbiValidityRecBuilder::Query for table:"
00317          << proxy.GetTableName()
00318          << ", table does not exist!" << "  ");
00319   }
00320 
00321   else if ( context == "" ) {
00322     SK_DBI_Warn(  "TDbiValidityRecBuilder::Null query for table:"
00323          << proxy.GetTableName() << "  ");
00324   }
00325 
00326   else {
00327 
00328 //  Loop over all databases in cascade until valid data found.
00329 
00330     UInt_t numDb     = proxy.GetNumDb();
00331     Bool_t foundData = kFALSE;
00332 
00333     for ( UInt_t dbNo = 0; dbNo < numDb && ! foundData; ++dbNo ) {
00334 
00335 //    Apply validity query and build result set.
00336 
00337       TDbiInRowStream* rs = proxy.QueryValidity(context,fTask,dbNo);
00338 
00339 //    Build a result from the result set and drop result set.
00340 
00341       TDbiValidityRec tr;
00342       TDbiResultSetNonAgg result(rs,&tr,0,kFALSE);
00343       delete rs;
00344 
00345 //    Loop over all entries in TDbiResultSet and add them all to set.
00346 
00347       UInt_t numRows = result.GetNumRows();
00348       for (UInt_t row = 0; row < numRows; ++row) {
00349         const TDbiValidityRec* vr = dynamic_cast<const TDbiValidityRec*>(
00350                                           result.GetTableRow(row));
00351 
00352 //      Cannot use AddNewAgg - aggregate numbers may be duplicated.
00353         Int_t index = fVRecs.size();
00354         fVRecs.push_back(TDbiValidityRec(*vr));
00355         fAggNoToIndex[vr->GetAggregateNo()] = index;
00356         foundData = kTRUE;
00357         
00358 //      Fill in entry's database number - its not stored in the
00359 //      database table!
00360         fVRecs[index].SetDbNo(dbNo);
00361 
00362 //      Count the number used.
00363         ++numVRecIn;
00364       }
00365     }
00366   }
00367 
00368   // hand edit required
00369   // if( TSK_DBI_Log::GetLogLevel() >= TSK_DBI_Log::kLogLevel
00370   //    std::ostream& msg=TSK_DBI_Log::GetLogStream();
00371 
00372   SK_DBI_Verbose("TDbiValidityRecBuilder:" << endl
00373       << " Extended context query: " << context << endl
00374       << " found " << numVRecIn
00375       << " vrecs in database, for " << fVRecs.size()
00376                << " records:-.");
00377 
00378   for ( unsigned int irec = 0; irec < GetNumValidityRec(); ++irec ) {
00379     SK_DBI_Verbose(" " << irec << " " << GetValidityRec(irec));
00380   }
00381   return;
00382 
00383 
00384 
00385 }

Here is the call graph for this function:

TDbiValidityRecBuilder::TDbiValidityRecBuilder ( const TDbiValidityRec vr,
const std::string  tableName 
)

Definition at line 389 of file TDbiValidityRecBuilder.cxx.

References AddNewAgg(), TDbiValidityRec::GetAggregateNo(), TDbiValidityRec::GetVldRange(), MakeGapRec(), and SK_DBI_Trace.

00390                                                                        :
00391 fIsExtendedContext(kFALSE),
00392 fTask(vr.GetTask())
00393 {
00394 //
00395 //  Purpose:  Constructor for an existing query result.
00396 //
00397 //  Arguments:
00398 //    vr           in    The TDbiValidityRec from the query.
00399 //    tableName    in    The name of the table that satisfied the query
00400 
00401 
00402   SK_DBI_Trace( "Creating TDbiValidityRecBuilder" << "  ");
00403 
00404   const TVldRange&          vrange(vr.GetVldRange());
00405   // This is the only way I can find to handle Detector and SimFlag!
00406   TVldContext vc( (DbiDetector::Detector_t) vrange.GetDetectorMask(),
00407                  (DbiSimFlag::SimFlag_t) vrange.GetSimMask(),
00408                  vrange.GetTimeStart());
00409   this->MakeGapRec(vc,tableName);
00410   this->AddNewAgg(vr,vr.GetAggregateNo());
00411 
00412 }
//.....................................................................

Here is the call graph for this function:

TDbiValidityRecBuilder::~TDbiValidityRecBuilder (  )  [virtual]

Definition at line 415 of file TDbiValidityRecBuilder.cxx.

References SK_DBI_Trace.

00415                                                 {
00416 //
00417 //
00418 //  Purpose: Destructor
00419 //
00420 //  Arguments:
00421 //    None.
00422 //
00423 //  Return:    n/a
00424 //
00425 //  Contact:   N. West
00426 //
00427 //  Specification:-
00428 //  =============
00429 //
00430 //  o  Destroy ValidityRecBuilder.
00431 
00432 
00433 //  Program Notes:-
00434 //  =============
00435 
00436 //  None.
00437 
00438 
00439   SK_DBI_Trace(  "Destroying TDbiValidityRecBuilder" << "  ");
00440 
00441 }


Member Function Documentation

UInt_t TDbiValidityRecBuilder::AddNewAgg ( const TDbiValidityRec vrec,
Int_t  aggNo 
) [private]

Add new aggregate into tables and return its index.

Definition at line 491 of file TDbiValidityRecBuilder.cxx.

References fAggNoToIndex, fVRecs, and IndexOfAggno().

Referenced by AddNewGap(), and TDbiValidityRecBuilder().

00491                                                                                 {
00492 //
00493 //
00494 //  Purpose:   Add new aggregate into tables and return its index.
00495 //
00496 //  Program Notes:-
00497 //  =============
00498 //
00499 //  aggNo is passed in and not obtained from vrec, so that it can be the gap.
00500 
00501   //  Make sure it really doesn't exist.
00502   int index = this->IndexOfAggno(aggNo);
00503   if ( index >=0 ) return index;
00504 
00505   // It doesn't so add it.
00506   index = fVRecs.size();
00507   fVRecs.push_back(vrec);
00508   fAggNoToIndex[aggNo] = index;
00509   return index;
00510 
00511 }

Here is the call graph for this function:

Here is the caller graph for this function:

UInt_t TDbiValidityRecBuilder::AddNewGap ( Int_t  aggNo  )  [private]

Add new aggregate gap into tables and return its index.

Definition at line 515 of file TDbiValidityRecBuilder.cxx.

References AddNewAgg(), fGap, and fVRecs.

Referenced by TDbiValidityRecBuilder().

00515                                                     {
00516 //
00517 //
00518 //  Purpose:  Add new aggregate gap into tables and return its index
00519 
00520   UInt_t index = this->AddNewAgg(fGap,aggNo);
00521   fVRecs[index].SetAggregateNo(aggNo);
00522   return index;
00523 
00524 }

Here is the call graph for this function:

Here is the caller graph for this function:

std::string TDbiValidityRecBuilder::GetL2CacheName (  )  const

Definition at line 445 of file TDbiValidityRecBuilder.cxx.

References fVRecs, TDbiValidityRec::GetCreationDate(), TDbiValidityRec::GetSeqNo(), IsExtendedContext(), and TDbiValidityRec::IsGap().

Referenced by TDbiTableProxy::Query(), and TDbiTableProxy::RestoreFromL2Cache().

00445                                                        {
00446 //
00447 //
00448 //  Purpose:  Return the associated Level 2 Cache Name.
00449 //
00450 //  Specification:-
00451 //  =============
00452 //
00453 //  o For format see static TDbiValidityRec::GetL2CacheName.
00454 //
00455 //  Gaps are excluded (and if all are gaps the returned name is empty).
00456 
00457 
00458 // Extended Context queries are not L2 cached.
00459   if ( this->IsExtendedContext() ) return "";
00460 
00461   UInt_t seqLo = 0;
00462   UInt_t seqHi = 0;
00463   TVldTimeStamp ts;
00464   std::vector<TDbiValidityRec>::const_iterator itr = fVRecs.begin();
00465   std::vector<TDbiValidityRec>::const_iterator end = fVRecs.end();
00466 
00467   for (; itr != end; ++itr) {
00468     const TDbiValidityRec& vr = *itr;
00469     if ( ! vr.IsGap() ) {
00470       if ( seqLo == 0 ) {
00471         seqLo = vr.GetSeqNo();
00472         seqHi = vr.GetSeqNo();
00473         ts    = vr.GetCreationDate();
00474       }
00475       else {
00476         if ( seqLo < vr.GetSeqNo() )        seqLo = vr.GetSeqNo();
00477         if ( seqHi > vr.GetSeqNo() )        seqHi = vr.GetSeqNo();
00478         if ( ts    < vr.GetCreationDate() ) ts    = vr.GetCreationDate();
00479       }
00480     }
00481   }
00482 
00483   if ( seqLo == 0 ) return "";
00484 
00485   return TDbiValidityRec::GetL2CacheName(seqLo,seqHi,ts);
00486 
00487 }

Here is the call graph for this function:

Here is the caller graph for this function:

UInt_t TDbiValidityRecBuilder::GetNumValidityRec (  )  const [inline]

Definition at line 66 of file TDbiValidityRecBuilder.hxx.

References fVRecs.

Referenced by NonAggregated(), TDbiTableProxy::Query(), and TDbiValidityRecBuilder().

00066                                                 {
00067                                                  return fVRecs.size(); }

Here is the caller graph for this function:

TDbi::Task TDbiValidityRecBuilder::GetTask (  )  const [inline]

Definition at line 65 of file TDbiValidityRecBuilder.hxx.

References fTask.

00065 { return fTask; }

const TDbiValidityRec & TDbiValidityRecBuilder::GetValidityRec ( Int_t  rowNo  )  const

Definition at line 529 of file TDbiValidityRecBuilder.cxx.

References fGap, and fVRecs.

Referenced by GetValidityRecFromAggNo(), TDbiTableProxy::Query(), and TDbiValidityRecBuilder().

00529                                                                       {
00530 //
00531 //
00532 //  Purpose: Return validity record for supplied row number.
00533 
00534   return (rowNo < 0 || rowNo >= (int) fVRecs.size()) ? fGap : fVRecs[rowNo];
00535 }

Here is the caller graph for this function:

const TDbiValidityRec& TDbiValidityRecBuilder::GetValidityRecFromAggNo ( Int_t  aggNo  )  const [inline]

Definition at line 73 of file TDbiValidityRecBuilder.hxx.

References GetValidityRec(), and IndexOfAggno().

00073                                                                   {
00074                return this->GetValidityRec(this->IndexOfAggno(aggNo)); }

Here is the call graph for this function:

const TDbiValidityRec & TDbiValidityRecBuilder::GetValidityRecFromSeqNo ( UInt_t  SeqNo  )  const

Definition at line 540 of file TDbiValidityRecBuilder.cxx.

References fGap, and fVRecs.

Referenced by TDbiTableProxy::RestoreFromL2Cache().

00540                                                                                 {
00541 //
00542 //
00543 //  Purpose: Return validity record for supplied SeqNo.
00544 
00545   std::vector<TDbiValidityRec>::const_iterator itr = fVRecs.begin();
00546   std::vector<TDbiValidityRec>::const_iterator end = fVRecs.end();
00547 
00548   for (; itr != end; ++itr) if ( itr->GetSeqNo() == SeqNo ) return *itr;
00549   return fGap;
00550 }

Here is the caller graph for this function:

Int_t TDbiValidityRecBuilder::IndexOfAggno ( Int_t  aggNo  )  const

Get index of AggNo or -1 if missing.

Definition at line 554 of file TDbiValidityRecBuilder.cxx.

References fAggNoToIndex.

Referenced by AddNewAgg(), and GetValidityRecFromAggNo().

00554                                                             {
00555 //
00556 //
00557 //  Purpose:   Get index of AggNo or -1 if missing.
00558 
00559   std::map<Int_t,UInt_t>::const_iterator itr = fAggNoToIndex.find(aggNo);
00560   if ( itr == fAggNoToIndex.end() ) return -1;
00561   return itr->second;
00562 
00563 }

Here is the caller graph for this function:

Bool_t TDbiValidityRecBuilder::IsExtendedContext (  )  const [inline]

Definition at line 70 of file TDbiValidityRecBuilder.hxx.

References fIsExtendedContext.

Referenced by GetL2CacheName(), and NonAggregated().

00070                                                 {
00071                                             return fIsExtendedContext; }

Here is the caller graph for this function:

void TDbiValidityRecBuilder::MakeGapRec ( const TVldContext vc,
const string &  tableName,
Bool_t  findFullTimeWindow = true 
) [private]

Definition at line 567 of file TDbiValidityRecBuilder.cxx.

References fGap, fTask, TVldContext::GetDetector(), TVldTimeStamp::GetSec(), TVldContext::GetSimFlag(), TDbi::GetTimeGate(), and TVldContext::GetTimeStamp().

Referenced by TDbiValidityRecBuilder().

00569                                                                   {
00570 //
00571 //
00572 //  Purpose:  Construct Gap Record
00573 //
00574 //  Arguments:
00575 //    vc           in    The Validity Context for the query.
00576 //    tableName    in    The name of the table being queried.
00577 //    findFullTimeWindow
00578 //                 in    Attempt to find full validity of query
00579 //                        i.e. beyond TDbi::GetTimeGate
00580 //
00581 //  Return:        None.
00582 //
00583 //  Contact:   N. West
00584 //
00585 //  Specification:-
00586 //  =============
00587 //
00588 //  o Create the data member gap record fGap centered on the current
00589 //    query time.
00590 
00591 //  Program Notes:-
00592 //  =============
00593 
00594 //  None.
00595 
00596   Int_t timeGate = TDbi::GetTimeGate(tableName);
00597   time_t contextSec = vc.GetTimeStamp().GetSec() - timeGate;
00598   TVldTimeStamp startGate(contextSec,0);
00599   contextSec += 2*timeGate;
00600   TVldTimeStamp endGate(contextSec,0);
00601   if ( findFullTimeWindow ) {
00602     startGate = TVldTimeStamp(0,0);
00603     endGate   = TVldTimeStamp(0x7FFFFFFF,0);
00604   }
00605   TVldRange gapVR(vc.GetDetector(), vc.GetSimFlag(), startGate, endGate, "Gap");
00606   fGap =  TDbiValidityRec(gapVR, fTask, -2, 0, 0, kTRUE,TVldTimeStamp(0));
00607 }

Here is the call graph for this function:

Here is the caller graph for this function:

Bool_t TDbiValidityRecBuilder::NonAggregated (  )  const [inline]

Definition at line 76 of file TDbiValidityRecBuilder.hxx.

References GetNumValidityRec(), and IsExtendedContext().

Referenced by TDbiTableProxy::Query().

00076                                             {
00077                  return  ! this->IsExtendedContext()
00078                         && this->GetNumValidityRec() == 1; }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

std::map<Int_t,UInt_t> TDbiValidityRecBuilder::fAggNoToIndex [private]

Map of Aggregate number to index in fVRecs.

Definition at line 112 of file TDbiValidityRecBuilder.hxx.

Referenced by AddNewAgg(), IndexOfAggno(), and TDbiValidityRecBuilder().

True for extended context query.

Definition at line 100 of file TDbiValidityRecBuilder.hxx.

Referenced by IsExtendedContext().

Definition at line 101 of file TDbiValidityRecBuilder.hxx.

Referenced by GetTask(), MakeGapRec(), and TDbiValidityRecBuilder().

Table of effective ValidityRecs. For context specific queries indexed by row number 0,.. The first row is guaranteed to correspond to aggregate -1, although this may be a gap. Other aggregates may come in any order. For extended context queries first entry is a gap (to be consistent with aggregated query) and all entries are filled in the order they are loaded.

Definition at line 110 of file TDbiValidityRecBuilder.hxx.

Referenced by AddNewAgg(), AddNewGap(), GetL2CacheName(), GetNumValidityRec(), GetValidityRec(), GetValidityRecFromSeqNo(), and TDbiValidityRecBuilder().


The documentation for this class was generated from the following files:

Generated on 11 Aug 2013 for SKDatabase by  doxygen 1.6.1