// $Id: IDbiResultKey.cxx,v 1.1 2011/01/18 05:49:20 finch Exp $ #include #include #include #include "IDbiResultKey.hxx" #include #include using std::endl; ClassImp(COMET::IDbiResultKey) // Definition of static data members // ********************************* COMET::IDbiResultKey COMET::IDbiResultKey::fgEmptyKey; // Global Functions // **************** std::ostream& operator<<(std::ostream& os, const COMET::IDbiResultKey& key) { os << key.AsString() << endl; return os; } // Definition of member functions (alphabetical order) // *************************************************** //..................................................................... COMET::IDbiResultKey::IDbiResultKey(const COMET::IDbiResultKey* that /* =0 */) : fNumVRecKeys(0) { // // // Purpose: Default constructor // COMETTrace( "Creating COMET::IDbiResultKey" << " "); if ( that ) *this = *that; } ///..................................................................... COMET::IDbiResultKey::IDbiResultKey(std::string tableName, std::string rowName, UInt_t seqno, COMET::IVldTimeStamp ts) : fTableName(tableName), fRowName(rowName), fNumVRecKeys(0) { // // // Purpose: Standard constructor // // Contact: N. West // // Specification:- // ============= // // o Create COMET::IDbiResultKey. COMETTrace( "Creating COMET::IDbiResultKey" << " "); this->AddVRecKey(seqno,ts); } //..................................................................... COMET::IDbiResultKey::~IDbiResultKey() { // // // Purpose: Destructor // // Contact: N. West // // Specification:- // ============= // // o Destroy COMET::IDbiResultKey COMETTrace( "Destroying COMET::IDbiResultKey" << " "); } //..................................................................... void COMET::IDbiResultKey::AddVRecKey(UInt_t seqno, COMET::IVldTimeStamp ts) { // // // Purpose: Add a COMET::IDbiValidityRec key. // fVRecKeys.push_back(VRecKey(seqno,ts)); ++fNumVRecKeys; } //..................................................................... std::string COMET::IDbiResultKey::AsString() const { // // // Purpose: Return a string that summarises this key giving:- // 1) The table and row names. // 2) The number of validity records (aggregates) // 3) The range of SEQNOs // 4) The range of CREATIONDATEs. ostringstream os; os << "Table:" << fTableName << " row:" << fRowName; if ( fVRecKeys.empty() ) os << " No vrecs"; else { os << ". " << fNumVRecKeys << " vrec"; if ( fNumVRecKeys > 1 ) os << "s (seqno min..max;creationdate min..max):"; else os << " (seqno;creationdate):"; os << " "; std::list::const_iterator itr = fVRecKeys.begin(); std::list::const_iterator itrEnd = fVRecKeys.end(); UInt_t seqnoMin = itr->SeqNo; UInt_t seqnoMax = seqnoMin; COMET::IVldTimeStamp tsMin = itr->CreationDate; COMET::IVldTimeStamp tsMax = tsMin; ++itr; while ( itr != itrEnd ) { UInt_t seqno = itr->SeqNo; COMET::IVldTimeStamp ts = itr->CreationDate; if ( seqno < seqnoMin ) seqnoMin = seqno; if ( seqno > seqnoMax ) seqnoMax = seqno; if ( ts < tsMin ) tsMin = ts; if ( ts > tsMax ) tsMax = ts; ++itr; } os << seqnoMin; if ( seqnoMin < seqnoMax ) os << ".." << seqnoMax; os << ";" << tsMin.AsString("s"); if ( tsMin < tsMax ) os << ".." << tsMax.AsString("s"); } return string(os.str()); } //..................................................................... Float_t COMET::IDbiResultKey::Compare(const COMET::IDbiResultKey* that) const { // // // Purpose: Compare 2 COMET::TDbiResultKeys // // Return: = -2. Table names don't match. // = -1. Table names match but row names don't // i.e. contain different COMET::IDbiTableRow sub-classes. // >= f Table and row names match and fraction f of the // SEQNOs have same creation date. // So f = 1. = perfect match. // Program Notes:- // ============= // None. // Check in table and row names. if ( fTableName != that->fTableName ) return -2.; if ( fRowName != that->fRowName ) return -1.; // Pick the key with the most entries and compare the other to it. COMETDebug( "Comparing " << *this << " to " << *that << " "); const COMET::IDbiResultKey* keyBig = this; const COMET::IDbiResultKey* keySmall = that; if ( that->GetNumVrecs() > this->GetNumVrecs() ) { keyBig = that; keySmall = this; } int numVrecs = keyBig->GetNumVrecs(); if ( numVrecs == 0 ) return 0.; std::map seqnoToCreationDate; std::list::const_iterator itrEnd = keyBig->fVRecKeys.end(); for ( std::list::const_iterator itr = keyBig->fVRecKeys.begin(); itr != itrEnd; ++itr ) seqnoToCreationDate[itr->SeqNo] = itr->CreationDate; float match = 0; itrEnd = keySmall->fVRecKeys.end(); for ( std::list::const_iterator itr = keySmall->fVRecKeys.begin(); itr != itrEnd; ++itr ) { COMETDebug( "Comparing seqno " << itr->SeqNo << " with creation date " << itr->CreationDate << " to " << seqnoToCreationDate[itr->SeqNo] << " "); if ( seqnoToCreationDate[itr->SeqNo] == itr->CreationDate ) ++match; } COMETDebug( "Match results: " << match << " out of " << numVrecs << " "); return match/numVrecs; } //..................................................................... std::string COMET::IDbiResultKey::GetTableRowName() const { // // // Purpose: Return TableName::RowName ostringstream os; os << fTableName << "::" << fRowName; return os.str(); } /* Template for New Member Function //..................................................................... COMET::IDbiResultKey:: { // // // Purpose: // // Arguments: // xxxxxxxxx in yyyyyy // // Return: // // Contact: N. West // // Specification:- // ============= // // o // Program Notes:- // ============= // None. } */