TDbiResultKey.cxx
Go to the documentation of this file.00001
00002
00003 #include <iostream>
00004 #include <map>
00005 #include <sstream>
00006
00007 #include "TDbiResultKey.hxx"
00008 #include <TSK_DBI_Log.hxx>
00009 #include <MsgFormat.h>
00010 using std::endl;
00011
00012 ClassImp(TDbiResultKey)
00013
00014
00015
00016
00017
00018
00019 TDbiResultKey TDbiResultKey::fgEmptyKey;
00020
00021
00022
00023
00024 std::ostream& operator<<(std::ostream& os, const TDbiResultKey& key) {
00025 os << key.AsString() << endl;
00026 return os;
00027 }
00028
00029
00030
00031
00032
00033
00034
00035 TDbiResultKey::TDbiResultKey(const TDbiResultKey* that ) :
00036 fNumVRecKeys(0)
00037 {
00038
00039
00040
00041
00042
00043
00044 SK_DBI_Trace( "Creating TDbiResultKey" << " ");
00045 if ( that ) *this = *that;
00046 }
00047
00048
00049
00050 TDbiResultKey::TDbiResultKey(std::string tableName,
00051 std::string rowName,
00052 UInt_t seqno,
00053 TVldTimeStamp ts) :
00054 fTableName(tableName),
00055 fRowName(rowName),
00056 fNumVRecKeys(0)
00057 {
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070 SK_DBI_Trace( "Creating TDbiResultKey" << " ");
00071
00072 this->AddVRecKey(seqno,ts);
00073 }
00074
00075
00076
00077 TDbiResultKey::~TDbiResultKey() {
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 SK_DBI_Trace( "Destroying TDbiResultKey" << " ");
00091
00092 }
00093
00094
00095
00096 void TDbiResultKey::AddVRecKey(UInt_t seqno, TVldTimeStamp ts) {
00097
00098
00099
00100
00101
00102 fVRecKeys.push_back(VRecKey(seqno,ts));
00103 ++fNumVRecKeys;
00104
00105 }
00106
00107
00108
00109 std::string TDbiResultKey::AsString() const {
00110
00111
00112
00113
00114
00115
00116
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 }
00150
00151
00152 Float_t TDbiResultKey::Compare(const TDbiResultKey* that) const {
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 if ( fTableName != that->fTableName ) return -2.;
00171 if ( fRowName != that->fRowName ) return -1.;
00172
00173
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 }
00206
00207
00208
00209 std::string TDbiResultKey::GetTableRowName() const {
00210
00211
00212
00213
00214 ostringstream os;
00215 os << fTableName << "::" << fRowName;
00216 return os.str();
00217
00218 }
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250