#ifndef VEGA_VHashTable #define VEGA_VHashTable //*-- Author : Damir Buskulic 20/05/99 ////////////////////////////////////////////////////////////////////////// // // // VHashTable // // // // Special hash table for quick frame file determination // // Instead of generating a hash value for each stored object, // // this table stores lists of names of frame file descriptors. // // (The name of frame file descriptors is defined by the start time // // of the first frame in the file) // // The hashing is done with respect to the start time of // // the first frame in a file. Global duration represented by // // the database is simply cut into equal portions, each file being // // assigned to one portion. So, after the build of the database, // // each portion contains a list of files for which the first frame // // begins inside the given time portion. // // On retrieval, one asks for information on a given time and gets // // a list of files that may contain the requested time. // // The average collision rate is the average number of files in each // // slot. The optimum average collision rate is decided by the user, it // // may not be 1. This depends on the frame seek time and is experimental// // // ////////////////////////////////////////////////////////////////////////// #include "TObjArray.h" #include "TNamed.h" #include "TMath.h" class VHashTable : public TNamed { private: Double_t mGlobalStartTime; // Start time of the database Double_t mGlobalEndTime; // End time of the database TObjArray** mFilesHashTable; //! Time hash table of file informations // the same info may appear in more than one slot Int_t mCapacity; // Capacity of the hash table Int_t mUsedSlots; // Number of used slots Int_t mSize; // Size (number of elements) pointed by the table // may be more than number of files due to // files spanning more than one slot Int_t mNFiles; // Number of files pointed by the table TObjArray* mFilesUnique; // Info of files entered. Unique info for each file Int_t mOptimalCollision; // Optimal collision rate decided by user public : VHashTable(); VHashTable(Int_t capacity, Double_t gstart=0, Double_t gend=1000, Int_t optcol = 5); ~VHashTable(); virtual void Add(Double_t filestart, Double_t fileend, Int_t firstindex, Int_t lastindex, Int_t condindex, Int_t firstgroup, Int_t lastgroup); virtual Float_t AverageCollisions() const; virtual void Delete(Option_t* option=""); virtual void Expand(Double_t gend); virtual TObjArray* GetFilesInfo(Double_t time) const; virtual TObjArray* GetFilesInfoDirect(Int_t hashval) const; Int_t GetSize() {return mSize;} Int_t GetNFiles() {return mNFiles;} Int_t GetCapacity() {return mCapacity;} Double_t GetGlobalStartTime() {return mGlobalStartTime;} Double_t GetGlobalEndTime() {return mGlobalEndTime;} Int_t GetHashValue(Double_t time) const; Int_t GetHashValueExclude(Double_t time) const; Double_t GetSlotBegin(Int_t hashval) const; Double_t GetSlotEnd(Int_t hashval) const; virtual void Print(Option_t* opt=""); virtual void SetGlobalStartTime(Double_t gstart); virtual void SetGlobalEndTime(Double_t gend); virtual void Rehash(Int_t newCapacity, Double_t gstart, Double_t gend); ClassDef(VHashTable,1) // Hash table for frame file search }; //______________________________________________________________________________ // Inlines //______________________________________________________________________________ inline Float_t VHashTable::AverageCollisions() const { if (mUsedSlots) return ((Float_t)mSize)/mUsedSlots; else return 0.0; } inline Int_t VHashTable::GetHashValue(Double_t time) const { Int_t i = (Int_t)(mCapacity*(time - mGlobalStartTime)/(mGlobalEndTime-mGlobalStartTime)); // need intermediary i for Linux g++ return (time>=mGlobalEndTime || time=mGlobalEndTime || time<=mGlobalStartTime) ? -1 : i; } inline Double_t VHashTable::GetSlotBegin(Int_t hashval) const { Double_t beg = mGlobalStartTime + hashval*(mGlobalEndTime-mGlobalStartTime)/mCapacity; // need intermediary b for Linux g++ return beg; } inline Double_t VHashTable::GetSlotEnd(Int_t hashval) const { Double_t end = mGlobalStartTime + (hashval+1)*(mGlobalEndTime-mGlobalStartTime)/mCapacity; // need intermediary b for Linux g++ return end; } #endif