Concept Summarises the composition of a single TDbiResultSet. More...
#include <TDbiResultKey.hxx>
Classes | |
struct | VRecKey |
Container for a SeqNo and CreationDate pair. More... | |
Public Member Functions | |
TDbiResultKey (const TDbiResultKey *that=0) | |
TDbiResultKey (std::string tableName, std::string rowName, UInt_t seqno, TVldTimeStamp ts) | |
..................................................................... | |
virtual | ~TDbiResultKey () |
std::string | AsString () const |
Float_t | Compare (const TDbiResultKey *that) const |
Int_t | GetNumVrecs () const |
std::string | GetTableRowName () const |
Bool_t | IsEqualTo (const TDbiResultKey *that) const |
void | AddVRecKey (UInt_t seqno, TVldTimeStamp ts) |
Static Public Member Functions | |
static const TDbiResultKey * | GetEmptyKey () |
Private Attributes | |
std::string | fTableName |
Name of database table. | |
std::string | fRowName |
Name of row objects. | |
std::list< TDbiResultKey::VRecKey > | fVRecKeys |
Key for individual TDbiValidityRec. | |
Int_t | fNumVRecKeys |
Optimisation: list::size() is slow! | |
Static Private Attributes | |
static TDbiResultKey | fgEmptyKey |
Concept Summarises the composition of a single TDbiResultSet.
Purpose To serve as summary of a single query. Contact: A.Finch@lancaster.ac.uk
Definition at line 34 of file TDbiResultKey.hxx.
TDbiResultKey::TDbiResultKey | ( | const TDbiResultKey * | that = 0 |
) |
Definition at line 35 of file TDbiResultKey.cxx.
References SK_DBI_Trace.
00035 : 00036 fNumVRecKeys(0) 00037 { 00038 // 00039 // 00040 // Purpose: Default constructor 00041 // 00042 00043 00044 SK_DBI_Trace( "Creating TDbiResultKey" << " "); 00045 if ( that ) *this = *that; 00046 }
TDbiResultKey::TDbiResultKey | ( | std::string | tableName, | |
std::string | rowName, | |||
UInt_t | seqno, | |||
TVldTimeStamp | ts | |||
) |
.....................................................................
Definition at line 50 of file TDbiResultKey.cxx.
References AddVRecKey(), and SK_DBI_Trace.
00053 : 00054 fTableName(tableName), 00055 fRowName(rowName), 00056 fNumVRecKeys(0) 00057 { 00058 // 00059 // 00060 // Purpose: Standard constructor 00061 // 00062 // Contact: N. West 00063 // 00064 // Specification:- 00065 // ============= 00066 // 00067 // o Create TDbiResultKey. 00068 00069 00070 SK_DBI_Trace( "Creating TDbiResultKey" << " "); 00071 00072 this->AddVRecKey(seqno,ts); 00073 }
TDbiResultKey::~TDbiResultKey | ( | ) | [virtual] |
Definition at line 77 of file TDbiResultKey.cxx.
References SK_DBI_Trace.
00077 { 00078 // 00079 // 00080 // Purpose: Destructor 00081 // 00082 // Contact: N. West 00083 // 00084 // Specification:- 00085 // ============= 00086 // 00087 // o Destroy TDbiResultKey 00088 00089 00090 SK_DBI_Trace( "Destroying TDbiResultKey" << " "); 00091 00092 }
void TDbiResultKey::AddVRecKey | ( | UInt_t | seqno, | |
TVldTimeStamp | ts | |||
) |
Definition at line 96 of file TDbiResultKey.cxx.
References fNumVRecKeys, and fVRecKeys.
Referenced by TDbiResultSetAgg::CreateKey(), and TDbiResultKey().
00096 { 00097 // 00098 // 00099 // Purpose: Add a TDbiValidityRec key. 00100 // 00101 00102 fVRecKeys.push_back(VRecKey(seqno,ts)); 00103 ++fNumVRecKeys; 00104 00105 }
std::string TDbiResultKey::AsString | ( | ) | const |
Definition at line 109 of file TDbiResultKey.cxx.
References TVldTimeStamp::AsString(), fNumVRecKeys, fRowName, fTableName, and fVRecKeys.
00109 { 00110 // 00111 // 00112 // Purpose: Return a string that summarises this key giving:- 00113 // 1) The table and row names. 00114 // 2) The number of validity records (aggregates) 00115 // 3) The range of SEQNOs 00116 // 4) The range of CREATIONDATEs. 00117 00118 ostringstream os; 00119 os << "Table:" << fTableName << " row:" << fRowName; 00120 if ( fVRecKeys.empty() ) os << " No vrecs"; 00121 else { 00122 os << ". " << fNumVRecKeys << " vrec"; 00123 if ( fNumVRecKeys > 1 ) os << "s (seqno min..max;creationdate min..max):"; 00124 else os << " (seqno;creationdate):"; 00125 os << " "; 00126 std::list<VRecKey>::const_iterator itr = fVRecKeys.begin(); 00127 std::list<VRecKey>::const_iterator itrEnd = fVRecKeys.end(); 00128 UInt_t seqnoMin = itr->SeqNo; 00129 UInt_t seqnoMax = seqnoMin; 00130 TVldTimeStamp tsMin = itr->CreationDate; 00131 TVldTimeStamp tsMax = tsMin; 00132 ++itr; 00133 while ( itr != itrEnd ) { 00134 UInt_t seqno = itr->SeqNo; 00135 TVldTimeStamp ts = itr->CreationDate; 00136 if ( seqno < seqnoMin ) seqnoMin = seqno; 00137 if ( seqno > seqnoMax ) seqnoMax = seqno; 00138 if ( ts < tsMin ) tsMin = ts; 00139 if ( ts > tsMax ) tsMax = ts; 00140 ++itr; 00141 } 00142 os << seqnoMin; 00143 if ( seqnoMin < seqnoMax ) os << ".." << seqnoMax; 00144 os << ";" << tsMin.AsString("s"); 00145 if ( tsMin < tsMax ) os << ".." << tsMax.AsString("s"); 00146 } 00147 return string(os.str()); 00148 00149 }
Float_t TDbiResultKey::Compare | ( | const TDbiResultKey * | that | ) | const |
Definition at line 152 of file TDbiResultKey.cxx.
References fRowName, fTableName, fVRecKeys, GetNumVrecs(), and SK_DBI_Debug.
Referenced by IsEqualTo().
00152 { 00153 // 00154 // 00155 // Purpose: Compare 2 TDbiResultKeys 00156 // 00157 // Return: = -2. Table names don't match. 00158 // = -1. Table names match but row names don't 00159 // i.e. contain different TDbiTableRow sub-classes. 00160 // >= f Table and row names match and fraction f of the 00161 // SEQNOs have same creation date. 00162 // So f = 1. = perfect match. 00163 00164 // Program Notes:- 00165 // ============= 00166 00167 // None. 00168 00169 // Check in table and row names. 00170 if ( fTableName != that->fTableName ) return -2.; 00171 if ( fRowName != that->fRowName ) return -1.; 00172 00173 // Pick the key with the most entries and compare the other to it. 00174 00175 SK_DBI_Debug( "Comparing " << *this << " to " 00176 << *that << " "); 00177 00178 const TDbiResultKey* keyBig = this; 00179 const TDbiResultKey* keySmall = that; 00180 if ( that->GetNumVrecs() > this->GetNumVrecs() ) { 00181 keyBig = that; 00182 keySmall = this; 00183 } 00184 int numVrecs = keyBig->GetNumVrecs(); 00185 if ( numVrecs == 0 ) return 0.; 00186 00187 std::map<UInt_t,TVldTimeStamp> seqnoToCreationDate; 00188 std::list<TDbiResultKey::VRecKey>::const_iterator itrEnd = keyBig->fVRecKeys.end(); 00189 for ( std::list<TDbiResultKey::VRecKey>::const_iterator itr = keyBig->fVRecKeys.begin(); 00190 itr != itrEnd; 00191 ++itr ) seqnoToCreationDate[itr->SeqNo] = itr->CreationDate; 00192 float match = 0; 00193 itrEnd = keySmall->fVRecKeys.end(); 00194 for ( std::list<TDbiResultKey::VRecKey>::const_iterator itr = keySmall->fVRecKeys.begin(); 00195 itr != itrEnd; 00196 ++itr ) { 00197 SK_DBI_Debug( "Comparing seqno " << itr->SeqNo << " with creation date " << itr->CreationDate 00198 << " to " << seqnoToCreationDate[itr->SeqNo] << " "); 00199 if ( seqnoToCreationDate[itr->SeqNo] == itr->CreationDate ) ++match; 00200 } 00201 SK_DBI_Debug( "Match results: " << match << " out of " << numVrecs << " "); 00202 00203 return match/numVrecs; 00204 00205 }
static const TDbiResultKey* TDbiResultKey::GetEmptyKey | ( | ) | [inline, static] |
Definition at line 53 of file TDbiResultKey.hxx.
References fgEmptyKey.
Referenced by TDbiResultSet::GetKey().
00053 { return &fgEmptyKey; }
Int_t TDbiResultKey::GetNumVrecs | ( | ) | const [inline] |
Definition at line 54 of file TDbiResultKey.hxx.
References fNumVRecKeys.
Referenced by Compare().
00054 { return fNumVRecKeys; }
std::string TDbiResultKey::GetTableRowName | ( | ) | const |
Definition at line 209 of file TDbiResultKey.cxx.
References fRowName, and fTableName.
00209 { 00210 // 00211 // 00212 // Purpose: Return TableName::RowName 00213 00214 ostringstream os; 00215 os << fTableName << "::" << fRowName; 00216 return os.str(); 00217 00218 }
Bool_t TDbiResultKey::IsEqualTo | ( | const TDbiResultKey * | that | ) | const [inline] |
Definition at line 56 of file TDbiResultKey.hxx.
References Compare().
00056 { 00057 return this->Compare(that) == 1.; }
TDbiResultKey TDbiResultKey::fgEmptyKey [static, private] |
Definition at line 75 of file TDbiResultKey.hxx.
Referenced by GetEmptyKey().
Int_t TDbiResultKey::fNumVRecKeys [private] |
Optimisation: list::size() is slow!
Definition at line 89 of file TDbiResultKey.hxx.
Referenced by AddVRecKey(), AsString(), and GetNumVrecs().
std::string TDbiResultKey::fRowName [private] |
Name of row objects.
Definition at line 83 of file TDbiResultKey.hxx.
Referenced by AsString(), Compare(), and GetTableRowName().
std::string TDbiResultKey::fTableName [private] |
Name of database table.
Definition at line 80 of file TDbiResultKey.hxx.
Referenced by AsString(), Compare(), and GetTableRowName().
std::list<TDbiResultKey::VRecKey> TDbiResultKey::fVRecKeys [private] |
Key for individual TDbiValidityRec.
Definition at line 86 of file TDbiResultKey.hxx.
Referenced by AddVRecKey(), AsString(), and Compare().