Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

DbiResultKey.cxx

Go to the documentation of this file.
00001 // $Id: DbiResultKey.cxx,v 1.7 2007/01/03 15:00:45 west Exp $
00002 
00003 #include <iostream>
00004 #include <map>
00005 #include <sstream>
00006 
00007 #include "DatabaseInterface/DbiResultKey.h"
00008 #include "LeakChecker/Lea.h"
00009 #include "MessageService/MsgService.h"
00010 
00011 ClassImp(DbiResultKey)
00012 
00013 
00014 //   Definition of static data members
00015 //   *********************************
00016 
00017 CVSID("$Id: DbiResultKey.cxx,v 1.7 2007/01/03 15:00:45 west Exp $");
00018 
00019 DbiResultKey DbiResultKey::fgEmptyKey;
00020 
00021 //   Global Functions
00022 //   ****************
00023 
00024 std::ostream& operator<<(std::ostream& os, const DbiResultKey& key) {
00025   os << key.AsString() << endl;
00026   return os;
00027 }
00028 
00029 
00030 // Definition of member functions (alphabetical order)
00031 // ***************************************************
00032 
00033 //.....................................................................
00034 
00035 DbiResultKey::DbiResultKey(const DbiResultKey* that /* =0 */) :
00036 fNumVRecKeys(0)
00037 {
00038 //
00039 //
00040 //  Purpose:  Default constructor
00041 //
00042 
00043   LEA_CTOR    //Leak Checker
00044 
00045   MSG("Dbi", Msg::kVerbose) << "Creating DbiResultKey" << endl;
00046   if ( that ) *this = *that;
00047 }
00048 
00050 
00051 DbiResultKey::DbiResultKey(std::string tableName,
00052                            std::string rowName,
00053                            UInt_t seqno, 
00054                            VldTimeStamp ts) :
00055 fTableName(tableName),
00056 fRowName(rowName),
00057 fNumVRecKeys(0)
00058 {
00059 //
00060 //
00061 //  Purpose:  Standard constructor
00062 //
00063 //  Contact:   N. West
00064 //
00065 //  Specification:-
00066 //  =============
00067 //
00068 //  o  Create DbiResultKey.
00069 
00070   LEA_CTOR    //Leak Checker
00071 
00072   MSG("Dbi", Msg::kVerbose) << "Creating DbiResultKey" << endl;
00073 
00074   this->AddVRecKey(seqno,ts);
00075 }
00076 
00077 //.....................................................................
00078 
00079 DbiResultKey::~DbiResultKey() {
00080 //
00081 //
00082 //  Purpose: Destructor
00083 //
00084 //  Contact:   N. West
00085 //
00086 //  Specification:-
00087 //  =============
00088 //
00089 //  o  Destroy DbiResultKey
00090 
00091   LEA_DTOR    //Leak Checker
00092 
00093   MSG("Dbi", Msg::kVerbose) << "Destroying DbiResultKey" << endl;
00094 
00095 }
00096 
00097 //.....................................................................
00098 
00099 void DbiResultKey::AddVRecKey(UInt_t seqno, VldTimeStamp ts) {
00100 //
00101 //
00102 //  Purpose:  Add a DbiValidityRec key.
00103 //
00104 
00105   fVRecKeys.push_back(VRecKey(seqno,ts));
00106   ++fNumVRecKeys;
00107 
00108 }
00109 
00110 //.....................................................................
00111 
00112 std::string DbiResultKey::AsString() const {
00113 //
00114 //
00115 //  Purpose:  Return a string that summarises this key giving:-
00116 //            1)  The table and row names.
00117 //            2)  The number of validity records (aggregates)
00118 //            3)  The range of SEQNOs
00119 //            4)  The range of CREATIONDATEs.
00120 
00121   ostringstream os;
00122   os << "Table:" << fTableName << " row:" << fRowName;
00123   if ( fVRecKeys.empty() ) os << " No vrecs";
00124   else {
00125     os << ".  " << fNumVRecKeys << " vrec";
00126     if ( fNumVRecKeys > 1 ) os << "s (seqno min..max;creationdate min..max):";
00127     else                    os << " (seqno;creationdate):";
00128     os << " ";
00129     std::list<VRecKey>::const_iterator itr    = fVRecKeys.begin();
00130     std::list<VRecKey>::const_iterator itrEnd = fVRecKeys.end();
00131     UInt_t seqnoMin    = itr->SeqNo;
00132     UInt_t seqnoMax    = seqnoMin;
00133     VldTimeStamp tsMin = itr->CreationDate;
00134     VldTimeStamp tsMax = tsMin;
00135     ++itr;
00136     while ( itr != itrEnd ) {
00137       UInt_t       seqno = itr->SeqNo;
00138       VldTimeStamp ts    = itr->CreationDate;
00139       if ( seqno < seqnoMin ) seqnoMin = seqno;
00140       if ( seqno > seqnoMax ) seqnoMax = seqno;
00141       if (    ts < tsMin    ) tsMin    = ts;
00142       if (    ts > tsMax    ) tsMax    = ts;
00143       ++itr;
00144     }
00145     os << seqnoMin;
00146     if ( seqnoMin < seqnoMax ) os << ".." << seqnoMax;
00147     os << ";" << tsMin.AsString("s");
00148     if ( tsMin < tsMax ) os << ".." <<  tsMax.AsString("s");
00149   }
00150   return string(os.str());
00151 
00152 }
00153 //.....................................................................
00154 
00155 Float_t DbiResultKey::Compare(const DbiResultKey* that) const {
00156 //
00157 //
00158 //  Purpose:  Compare 2 DbiResultKeys
00159 //
00160 //  Return:    = -2. Table names don't match.
00161 //             = -1. Table names match but row names don't 
00162 //                   i.e. contain different DbiTableRow sub-classes.
00163 //             >= f  Table and row names match and fraction f of the
00164 //                   SEQNOs have same creation date.
00165 //                   So f = 1.  = perfect match.
00166 
00167 //  Program Notes:-
00168 //  =============
00169 
00170 //  None.
00171 
00172   // Check in table and row names.
00173   if ( fTableName != that->fTableName ) return -2.;
00174   if ( fRowName   != that->fRowName   ) return -1.;
00175 
00176   // Pick the key with the most entries and compare the other to it.
00177 
00178   MSG("Dbi",Msg::kDebug) << "Comparing " << *this << " to " 
00179                         << *that << endl;
00180 
00181   const DbiResultKey* keyBig   = this;
00182   const DbiResultKey* keySmall = that;
00183   if ( that->GetNumVrecs() > this->GetNumVrecs() ) {
00184     keyBig   = that;
00185     keySmall = this;
00186   }
00187   int numVrecs = keyBig->GetNumVrecs();
00188   if ( numVrecs == 0 ) return 0.;
00189 
00190   std::map<UInt_t,VldTimeStamp> seqnoToCreationDate;
00191   std::list<DbiResultKey::VRecKey>::const_iterator itrEnd = keyBig->fVRecKeys.end();
00192   for (  std::list<DbiResultKey::VRecKey>::const_iterator itr = keyBig->fVRecKeys.begin();
00193          itr != itrEnd;
00194          ++itr ) seqnoToCreationDate[itr->SeqNo] = itr->CreationDate;
00195   float match = 0;
00196   itrEnd = keySmall->fVRecKeys.end();
00197   for (  std::list<DbiResultKey::VRecKey>::const_iterator itr = keySmall->fVRecKeys.begin();
00198          itr != itrEnd;
00199          ++itr ) {
00200     MSG("Dbi",Msg::kDebug) << "Comparing seqno " << itr->SeqNo << " with creation date " << itr->CreationDate
00201                          << " to " <<  seqnoToCreationDate[itr->SeqNo] << endl;
00202     if ( seqnoToCreationDate[itr->SeqNo] == itr->CreationDate ) ++match;
00203   }
00204   MSG("Dbi",Msg::kDebug) << "Match results: " << match << " out of " << numVrecs << endl;
00205 
00206   return match/numVrecs;
00207 
00208 }
00209 
00210 //.....................................................................
00211 
00212 std::string DbiResultKey::GetTableRowName() const {
00213 //
00214 //
00215 //  Purpose:  Return TableName::RowName
00216 
00217   ostringstream os;
00218   os << fTableName << "::" << fRowName;
00219   return os.str();
00220 
00221 }
00222 /*    Template for New Member Function
00223 
00224 //.....................................................................
00225 
00226 DbiResultKey:: {
00227 //
00228 //
00229 //  Purpose:  
00230 //
00231 //  Arguments: 
00232 //    xxxxxxxxx    in    yyyyyy
00233 //
00234 //  Return:    
00235 //
00236 //  Contact:   N. West
00237 //
00238 //  Specification:-
00239 //  =============
00240 //
00241 //  o 
00242 
00243 //  Program Notes:-
00244 //  =============
00245 
00246 //  None.
00247 
00248 
00249 }
00250 
00251 */
00252 

Generated on Mon Feb 15 11:06:34 2010 for loon by  doxygen 1.3.9.1