ROOT » MISC » TABLE » TTableSorter

class TTableSorter: public TNamed


  TTableSorter  - Is an "observer" class to sort the TTable objects
                    The class provides an interface to the standard "C/C++"

 qsort and bsearch subroutines (for further information see your local C/C++ docs)
 =====     =======

  - This class DOESN'T change / touch the "host" table  itself
    For any TTable object one can create as many different "sorter"
    as one finds useful for one's code
  - Any instance of this class is meaningful as long as the "host" object
    "TTable" does exist and is not changed
  - Any attempt to access this TTableSorter after the "host" object deleted
    causes the program abnormal termination
  - Any attempt to access this TTableSorter after the "host" object been changed
    causes an unpredictable result
  - Any instance (object) of this class is NOT deleted "by automatic" just
    the "host object "TTable" deleted. It is the responsibility of the user's code
    keeping TTableSorter and the the "host" TTable objects consistent.

 "To do" list

  1. A separate method to provide lexicographical sort if the "sorted" column is a kind of array

  Usage:
    1. Create an instance of the sorter for the selected column of your table

        new TTableSorter(TTable &table, TString &colName,Int_t firstRow,Int_t numberRows)

        All sort actions are performed within TTableSorter ctor.
        This means one needs no extra effort to SORT table. "Sorter" contains
        the "sorted index array" as soon as you create the sorter

        TTableSorter sorter(MyTable,"id",20, 34);
          - Creates a sorter for MyTable column "id" ordering
            its 34 rows from 20 row with standard "C" qsort subroutine

    2.  You may use this instance to search any "id" value with operator []
          to get the table row index as follows:

          Int_t id = 5;
          Int_t index =  sorter[id]; // Look for the row index with id = 5
                                     // using the standard "C"  "bsearch" binary search
                                     // subroutine
          Int_t index =  sorter(id); // Look for the row index with id "nearest" to 5
                                     // using the internal "BinarySearch" method

    3. Some useful methods of this class:

        3.1. CountKeys()
        3.2  CountKey(const void *key, Int_t firstIndx=0,Bool_t bSearch=kTRUE,Int_t *firstRow=0)
        3.3. FindFirstKey(const void *key)
        3.4. GetIndex(UInt_t sortedIndex)


Function Members (Methods)

public:
virtual~TTableSorter()
voidTObject::AbstractMethod(const char* method) const
virtual voidTObject::AppendPad(Option_t* option = "")
Int_tBinarySearch(Float_t value) const
Int_tBinarySearch(Int_t value) const
Int_tBinarySearch(ULong_t value) const
Int_tBinarySearch(Long_t value) const
Int_tBinarySearch(UInt_t value) const
Int_tBinarySearch(Short_t value) const
Int_tBinarySearch(Double_t value) const
Int_tBinarySearch(UShort_t value) const
Int_tBinarySearch(UChar_t value) const
Int_tBinarySearch(Char_t value) const
Int_tBinarySearch(Bool_t value) const
virtual voidTObject::Browse(TBrowser* b)
static TClass*Class()
virtual const char*TObject::ClassName() const
virtual voidTNamed::Clear(Option_t* option = "")
virtual TObject*TNamed::Clone(const char* newname = "") const
virtual Int_tTNamed::Compare(const TObject* obj) const
virtual voidTNamed::Copy(TObject& named) const
virtual Int_tCountKey(const void* key, Int_t firstIndx = 0, Bool_t bSearch = kTRUE, Int_t* firstRow = 0) const
virtual Int_tCountKeys() const
virtual voidTObject::Delete(Option_t* option = "")MENU
virtual Int_tTObject::DistancetoPrimitive(Int_t px, Int_t py)
virtual voidTObject::Draw(Option_t* option = "")
virtual voidTObject::DrawClass() constMENU
virtual TObject*TObject::DrawClone(Option_t* option = "") constMENU
virtual voidTObject::Dump() constMENU
virtual voidTObject::Error(const char* method, const char* msgfmt) const
virtual voidTObject::Execute(const char* method, const char* params, Int_t* error = 0)
virtual voidTObject::Execute(TMethod* method, TObjArray* params, Int_t* error = 0)
virtual voidTObject::ExecuteEvent(Int_t event, Int_t px, Int_t py)
virtual voidTObject::Fatal(const char* method, const char* msgfmt) const
virtual voidTNamed::FillBuffer(char*& buffer)
virtual Int_tFindFirstKey(const void* key) const
virtual TObject*TObject::FindObject(const char* name) const
virtual TObject*TObject::FindObject(const TObject* obj) const
virtual const char*GetColumnName() const
virtual Option_t*TObject::GetDrawOption() const
static Long_tTObject::GetDtorOnly()
virtual Int_tGetFirstRow() const
virtual const char*TObject::GetIconName() const
Int_tGetIndex(UInt_t sortedIndex) const
virtual const void*GetKeyAddress(Int_t indx)
virtual Int_tGetLastFound() const
virtual const char*TNamed::GetName() const
virtual Int_tGetNRows() const
virtual char*TObject::GetObjectInfo(Int_t px, Int_t py) const
static Bool_tTObject::GetObjectStat()
virtual Option_t*TObject::GetOption() const
virtual TTable*GetTable() const
virtual const char*GetTableName() const
virtual const char*GetTableTitle() const
virtual const char*GetTableType() const
virtual const char*TNamed::GetTitle() const
virtual UInt_tTObject::GetUniqueID() const
virtual Bool_tTObject::HandleTimer(TTimer* timer)
virtual ULong_tTNamed::Hash() const
virtual voidTObject::Info(const char* method, const char* msgfmt) const
virtual Bool_tTObject::InheritsFrom(const char* classname) const
virtual Bool_tTObject::InheritsFrom(const TClass* cl) const
virtual voidTObject::Inspect() constMENU
voidTObject::InvertBit(UInt_t f)
virtual TClass*IsA() const
virtual Bool_tTObject::IsEqual(const TObject* obj) const
virtual Bool_tTObject::IsFolder() const
Bool_tTObject::IsOnHeap() const
virtual Bool_tTNamed::IsSortable() const
Bool_tTObject::IsZombie() const
virtual voidTNamed::ls(Option_t* option = "") const
voidTObject::MayNotUse(const char* method) const
virtual Bool_tTObject::Notify()
voidTObject::Obsolete(const char* method, const char* asOfVers, const char* removedFromVers) const
voidTObject::operator delete(void* ptr)
voidTObject::operator delete(void* ptr, void* vp)
voidTObject::operator delete[](void* ptr)
voidTObject::operator delete[](void* ptr, void* vp)
void*TObject::operator new(size_t sz)
void*TObject::operator new(size_t sz, void* vp)
void*TObject::operator new[](size_t sz)
void*TObject::operator new[](size_t sz, void* vp)
Int_toperator()(Float_t value)
Int_toperator()(Int_t value)
Int_toperator()(Long_t value)
Int_toperator()(Double_t value)
Int_toperator[](Int_t value) const
Int_toperator[](Long_t value) const
Int_toperator[](Double_t value) const
Int_toperator[](void* value) const
virtual voidTObject::Paint(Option_t* option = "")
virtual voidTObject::Pop()
virtual voidTNamed::Print(Option_t* option = "") const
virtual Int_tTObject::Read(const char* name)
virtual voidTObject::RecursiveRemove(TObject* obj)
voidTObject::ResetBit(UInt_t f)
virtual voidTObject::SaveAs(const char* filename = "", Option_t* option = "") constMENU
virtual voidTObject::SavePrimitive(ostream& out, Option_t* option = "")
voidTObject::SetBit(UInt_t f)
voidTObject::SetBit(UInt_t f, Bool_t set)
virtual voidTObject::SetDrawOption(Option_t* option = "")MENU
static voidTObject::SetDtorOnly(void* obj)
virtual voidTNamed::SetName(const char* name)MENU
virtual voidTNamed::SetNameTitle(const char* name, const char* title)
static voidTObject::SetObjectStat(Bool_t stat)
virtual voidTNamed::SetTitle(const char* title = "")MENU
virtual voidTObject::SetUniqueID(UInt_t uid)
virtual voidShowMembers(TMemberInspector& insp) const
virtual Int_tTNamed::Sizeof() const
virtual voidStreamer(TBuffer&)
voidStreamerNVirtual(TBuffer& ClassDef_StreamerNVirtual_b)
virtual voidTObject::SysError(const char* method, const char* msgfmt) const
Bool_tTObject::TestBit(UInt_t f) const
Int_tTObject::TestBits(UInt_t f) const
TTableSorter()
TTableSorter(const TTable& table, TString& colName, Int_t firstRow = 0, Int_t numbeRows = 0)
TTableSorter(const TTable* table, TString& colName, Int_t firstRow = 0, Int_t numbeRows = 0)
TTableSorter(const Float_t* simpleArray, Int_t arraySize, Int_t firstRow = 0, Int_t numberRows = 0)
TTableSorter(const Double_t* simpleArray, Int_t arraySize, Int_t firstRow = 0, Int_t numberRows = 0)
TTableSorter(const Long_t* simpleArray, Int_t arraySize, Int_t firstRow = 0, Int_t numberRows = 0)
TTableSorter(const TTable& table, SEARCHMETHOD search, COMPAREMETHOD compare, Int_t firstRow = 0, Int_t numbeRows = 0)
TTableSorter(const TTable* table, SEARCHMETHOD search, COMPAREMETHOD compare, Int_t firstRow = 0, Int_t numbeRows = 0)
virtual voidTObject::UseCurrentStyle()
virtual voidTObject::Warning(const char* method, const char* msgfmt) const
virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0)
virtual Int_tTObject::Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0) const
protected:
const char*At(Int_t i) const
Int_tBSearch(const void* value) const
Int_tBSearch(Float_t value) const
Int_tBSearch(Int_t value) const
Int_tBSearch(ULong_t value) const
Int_tBSearch(Long_t value) const
Int_tBSearch(UInt_t value) const
Int_tBSearch(Short_t value) const
Int_tBSearch(Double_t value) const
Int_tBSearch(UShort_t value) const
Int_tBSearch(UChar_t value) const
Int_tBSearch(Char_t value) const
Int_tBSearch(Bool_t value) const
voidBuildSorter(TString& colName, Int_t firstRow, Int_t numberRows)
static intCompareBool_t(const void**, const void**)
static intCompareChar_t(const void**, const void**)
static intCompareDouble_t(const void**, const void**)
static intCompareFloat_t(const void**, const void**)
static intCompareInt_t(const void**, const void**)
static intCompareLong_t(const void**, const void**)
static intCompareShort_t(const void**, const void**)
static intCompareUChar_t(const void**, const void**)
static intCompareUInt_t(const void**, const void**)
static intCompareULong_t(const void**, const void**)
static intCompareUShort_t(const void**, const void**)
virtual voidTObject::DoError(int level, const char* location, const char* fmt, va_list va) const
Bool_tFillIndexArray()
Long_tGetRowSize()
voidLearnTable()
voidTObject::MakeZombie()
voidQSort()
static intSearchBool_t(const void*, const void**)
static intSearchChar_t(const void*, const void**)
static intSearchDouble_t(const void*, const void**)
static intSearchFloat_t(const void*, const void**)
static intSearchInt_t(const void*, const void**)
static intSearchLong_t(const void*, const void**)
static intSearchShort_t(const void*, const void**)
static intSearchUChar_t(const void*, const void**)
static intSearchUInt_t(const void*, const void**)
static intSearchULong_t(const void*, const void**)
static intSearchUShort_t(const void*, const void**)
Int_tSelectSearch(Float_t value) const
Int_tSelectSearch(Int_t value) const
Int_tSelectSearch(ULong_t value) const
Int_tSelectSearch(Long_t value) const
Int_tSelectSearch(UInt_t value) const
Int_tSelectSearch(Short_t value) const
Int_tSelectSearch(Double_t value) const
Int_tSelectSearch(UShort_t value) const
Int_tSelectSearch(UChar_t value) const
Int_tSelectSearch(Char_t value) const
Int_tSelectSearch(Bool_t value) const
voidSetSearchMethod()
voidSetSimpleArray(Int_t arraySize, Int_t firstRow, Int_t numberRows)

Data Members

public:
static TObject::(anonymous)TObject::kBitMask
static TObject::EStatusBitsTObject::kCanDelete
static TObject::EStatusBitsTObject::kCannotPick
static TObject::EStatusBitsTObject::kHasUUID
static TObject::EStatusBitsTObject::kInvalidObject
static TObject::(anonymous)TObject::kIsOnHeap
static TObject::EStatusBitsTObject::kIsReferenced
static TObject::EStatusBitsTObject::kMustCleanup
static TObject::EStatusBitsTObject::kNoContextMenu
static TObject::(anonymous)TObject::kNotDeleted
static TObject::EStatusBitsTObject::kObjInCanvas
static TObject::(anonymous)TObject::kOverwrite
static TObject::(anonymous)TObject::kSingleKey
static TObject::(anonymous)TObject::kWriteDelete
static TObject::(anonymous)TObject::kZombie
protected:
Int_tfColDimensionsThe number of the dimensions for array (=-1 means it is a "simple" array)
TStringfColName
Int_tfColOffset
Int_tfColSizeThe size of the selected column in bytes
TTable::EColumnTypefColTypedata type of the selected column
COMPAREMETHODfCompareMethodFunction to sort the original array
const char*fFirstParentRow! pointer to the internal array of TTable object;
Int_tfFirstRowfirst row of the table to be sorted
Int_t*fIndexArray"parsed" indecis
Int_tfLastFoundThe index of the last found index within fSortIndex
TStringTNamed::fNameobject identifier
Int_tfNumberOfRowsnumber of rows of the table to be sorted
Long_tfParentRowSizeTo be filled from TTable::GetRowSize() method
const TTable*fParentTable!- the back pointer to the sorted table
SEARCHMETHODfSearchMethodFunction selected to search values
void**fSortIndexArray of pointers to columns of the sorted table
TStringTNamed::fTitleobject title
const Char_t*fsimpleArrayPointer to the "simple" array;
private:
union(anonymous)fValue

Class Charts

Inheritance Chart:
TObject
TNamed
TTableSorter

Function documentation

TTableSorter()
 default ctor for RootCint dictionary
TTableSorter(const TTable& table, TString& colName, Int_t firstRow = 0, Int_t numbeRows = 0)
 TTableSorter ctor sorts the input table along its column defined with colName

    - colName    - may be followed by the square brackets with integer number inside,
                   if that columm is an array (for example "phys[3]").
                   NO expression inside of [], only a single integer number allowed !
    - firstRow   - the first table row to sort from (=0 by default)
    - numberRows - the number of the table rows to sort (=0 by default)
                   = 0 means sort all rows from the "firstRow" by the end of table

TTableSorter(const TTable* table, TString& colName, Int_t firstRow = 0, Int_t numbeRows = 0)
 TTableSorter ctor sorts the input table along its column defined with colName

    - colName    - may be followed by the square brackets with integer number inside,
                   if that columm is an array (for example "phys[3]").
                   NO expression inside of [], only a single integer number allowed !
    - firstRow   - the first table row to sort from (=0 by default)
    - numberRows - the number of the table rows to sort (=0 by default)
                   = 0 means sort all rows from the "firstRow" by the end of table

TTableSorter(const TTable& table, SEARCHMETHOD search, COMPAREMETHOD compare, Int_t firstRow = 0, Int_t numbeRows = 0)
 TTableSorter ctor sorts the input table according the function "search"

    - search     - the function to compare the "key" and the table rows during sorting
                   typedef Int_t (*SEARCHMETHOD) (const void *, const void **);

    - compare    - the function to compare two table rows during searching
                   typedef Int_t (*COMPAREMETHOD)(const void **, const void **);

    - firstRow   - the first table row to sort from (=0 by default)
    - numberRows - the number of the table rows to sort (=0 by default)
                   = 0 means sort all rows from the "firstRow" by the end of table
  Note:  This is a base class. If one fears it is not safe
  -----  to allow "void *" one may potect the end-user code
         providing a derived class with the appropriated type
         of the parameters.

TTableSorter(const TTable* table, SEARCHMETHOD search, COMPAREMETHOD compare, Int_t firstRow = 0, Int_t numbeRows = 0)
 TTableSorter ctor sorts the input table according the function "search"

    - search     - the function to compare the "key" and the table rows during sorting
                   typedef Int_t (*SEARCHMETHOD) (const void *, const void **);

    - compare    - the function to compare two table rows during searching
                   typedef Int_t (*COMPAREMETHOD)(const void **, const void **);

    - firstRow   - the first table row to sort from (=0 by default)
    - numberRows - the number of the table rows to sort (=0 by default)
                   = 0 means sort all rows from the "firstRow" by the end of table
  Note:  This is a base class. If one fears it is not safe
  -----  to allow "void *" one may potect the end-user code
         providing a derived class with the appropriated type
         of the parameters.

void BuildSorter(TString& colName, Int_t firstRow, Int_t numberRows)
 BuildSorter backs TTableSorter ctor

    - colName    - may be followed by the square brackets with integer number inside,
                   if that columm is an array (for example "phys[3]").
                   NO expression inside of [], only a single integer number allowed !
    - firstRow   - the first table row to sort from (=0 by default)
    - numberRows - the number of the table rows to sort (=0 by default)
                   = 0 means sort all rows from the "firstRow" by the end of table

TTableSorter(const Float_t* simpleArray, Int_t arraySize, Int_t firstRow = 0, Int_t numberRows = 0)
 TTableSorter ctor sort the input "simpleArray"

    - arraySize  - the size of the full array
    - firstRow   - the first table row to sort from (=0 by default)
    - numberRows - the number of the table rows to sort (=0 by default)
                   = 0 means sort all rows from the "firstRow" by the end of table

TTableSorter(const Double_t* simpleArray, Int_t arraySize, Int_t firstRow = 0, Int_t numberRows = 0)
 TTableSorter ctor sort the input "simpleArray"

    - arraySize  - the size of the full array
    - firstRow   - the first table row to sort from (=0 by default)
    - numberRows - the number of the table rows to sort (=0 by default)
                   = 0 means sort all rows from the "firstRow" by the end of table

TTableSorter(const Long_t* simpleArray, Int_t arraySize, Int_t firstRow = 0, Int_t numberRows = 0)
 TTableSorter ctor sort the input "simpleArray"

    - arraySize  - the sie of the full array
    - firstRow   - the first table row to sort from (=0 by default)
    - numberRows - the number of the table rows to sort (=0 by default)
                   = 0 means sort all rows from the "firstRow" by the end of table

void SetSimpleArray(Int_t arraySize, Int_t firstRow, Int_t numberRows)
 Set some common parameteres for the "simple" arrays
~TTableSorter()
to be documented
Int_t BSearch(valuetype value)
Int_t SelectSearch(valuetype value)
Int_t BSearch(const void* value) const
to be documented
Int_t GetIndex(UInt_t sortedIndex) const
 returns the original index of the row by its sorted index
Int_t CountKey(const void* key, Int_t firstIndx = 0, Bool_t bSearch = kTRUE, Int_t* firstRow = 0) const
  CountKey counts the number of rows with the key value equal "key"

  key      - it is a POINTER to the key value
  fistIndx - the first index within sorted array to star search
              = 0 by default
  bSearch  = kTRUE - binary search (by default) is used otherwise linear one

Int_t CountKeys() const
 Counts the number of different key values

Bool_t FillIndexArray()
 File the array of the pointers and check whether
 the original table has been sorted to avoid an extra job.

 Return: kTRUE  - the table has been sorted
         kFALSE - otherwise

Int_t FindFirstKey(const void* key) const
 Looks for the first index of the "key"
 within SORTED table AFTER sorting

 Returns: = -1 if the "key" was not found

 Note: This method has no sense for
 ====  the float and double key

       To get the index within the original
       unsorted table the GetIndex() method
       may be used like this:
       GetIndex(FindFirstKey(key))

const char * GetTableName() const
to be documented
const char * GetTableTitle() const
to be documented
const char * GetTableType() const
to be documented
TTable * GetTable() const
to be documented
void SetSearchMethod()
 Select search function at once
void QSort()
 Call the standard C run-time library "qsort" function

void LearnTable()
  LearnTable() allows the TTableSorter to learn the structure of the
  tables used to fill the ntuple.
  table     - the name of the table
  buildTree - if kTRUE, then add TBranches to the TTree for each table
              column (default=kFALSE)

const char * At(Int_t i) const
Long_t GetRowSize()
{ return fParentRowSize; }
Int_t operator[](Int_t value) const
{ return BSearch(value); }
Int_t operator[](Long_t value) const
{ return BSearch(value); }
Int_t operator[](Double_t value) const
{ return BSearch(value); }
Int_t operator[](void* value) const
{ return BSearch(value); }
Int_t operator()(Float_t value)
{ return BinarySearch(value); }
Int_t operator()(Int_t value)
{ return BinarySearch(value); }
Int_t operator()(Long_t value)
{ return BinarySearch(value); }
Int_t operator()(Double_t value)
{ return BinarySearch(value); }
TTableSorter(const TTableSorter& )
TTableSorter & operator=(const TTableSorter& )
int CompareFloat_t(const void** , const void** )
int CompareInt_t(const void** , const void** )
int CompareLong_t(const void** , const void** )
int CompareULong_t(const void** , const void** )
int CompareUInt_t(const void** , const void** )
int CompareShort_t(const void** , const void** )
int CompareDouble_t(const void** , const void** )
int CompareUShort_t(const void** , const void** )
int CompareUChar_t(const void** , const void** )
int CompareChar_t(const void** , const void** )
int CompareBool_t(const void** , const void** )
Int_t BSearch(const void* value) const
Int_t BSearch(Float_t value) const
Int_t BSearch(Int_t value) const
Int_t BSearch(ULong_t value) const
Int_t BSearch(Long_t value) const
Int_t BSearch(UInt_t value) const
Int_t BSearch(Short_t value) const
Int_t BSearch(Double_t value) const
Int_t BSearch(UShort_t value) const
Int_t BSearch(UChar_t value) const
int SearchFloat_t(const void* , const void** )
int SearchInt_t(const void* , const void** )
int SearchULong_t(const void* , const void** )
int SearchLong_t(const void* , const void** )
int SearchUInt_t(const void* , const void** )
int SearchShort_t(const void* , const void** )
int SearchDouble_t(const void* , const void** )
int SearchUShort_t(const void* , const void** )
int SearchUChar_t(const void* , const void** )
int SearchChar_t(const void* , const void** )
int SearchBool_t(const void* , const void** )
Int_t SelectSearch(Float_t value) const
Int_t SelectSearch(Int_t value) const
Int_t SelectSearch(ULong_t value) const
Int_t SelectSearch(Long_t value) const
Int_t SelectSearch(UInt_t value) const
Int_t SelectSearch(Short_t value) const
Int_t SelectSearch(Double_t value) const
Int_t SelectSearch(UShort_t value) const
Int_t SelectSearch(UChar_t value) const
Int_t SelectSearch(Char_t value) const
Int_t BinarySearch(Float_t value) const
Int_t BinarySearch(Int_t value) const
Int_t BinarySearch(ULong_t value) const
Int_t BinarySearch(Long_t value) const
Int_t BinarySearch(UInt_t value) const
Int_t BinarySearch(Short_t value) const
Int_t BinarySearch(Double_t value) const
Int_t BinarySearch(UShort_t value) const
Int_t BinarySearch(UChar_t value) const
Int_t BinarySearch(Char_t value) const
Int_t BinarySearch(Bool_t value) const
const char * GetColumnName() const
{ return fColName.Data();}
const void * GetKeyAddress(Int_t indx)
{ return (fSortIndex && indx >= 0) ?fSortIndex[indx]:(void *)(-1);}
Int_t GetLastFound() const
{ return fLastFound; }
Int_t GetNRows() const
{ return fNumberOfRows;}
Int_t GetFirstRow() const
{ return fFirstRow;}