00001 // @(#)root/table:$Id: TIndexTable.cxx 36254 2010-10-10 10:44:50Z brun $ 00002 // Author: Valery Fine(fine@bnl.gov) 01/03/2001 00003 00004 /************************************************************************* 00005 * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. * 00006 * Copyright (C) 2001 [BNL] Brookhaven National Laboratory. * 00007 * All rights reserved. * 00008 * * 00009 * For the licensing terms see $ROOTSYS/LICENSE. * 00010 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00011 *************************************************************************/ 00012 00013 #include "TIndexTable.h" 00014 00015 ////////////////////////////////////////////////////////////////////////////// 00016 // TIndexTable class is helper class to keep the list of the referencs to the 00017 // TTable rows and iterate over it. 00018 // TIndexTable is a persistent class. 00019 // The pointer to the TIndexTable object may be used as an element 00020 // of the TTable row and saved with the table all together. 00021 // 00022 // For example, the track table may contain a member to the "map" of the hits 00023 // struct { 00024 // float helix; 00025 // TIndexTable *hits; 00026 // } tracks_t; 00027 // 00028 // // Create track table: 00029 // LArTrackTable *tracks = new LArTrackTable(...); 00030 // 00031 // // Get pointer to the hit table 00032 // LArHitTable *hits = GiveMeHits(); 00033 // // Loop over all tracks 00034 // LArTrackTable::iterator track = tracks->begin(); 00035 // LArTrackTable::iterator last = tracks->end(); 00036 // for (;track != last;track++) { 00037 // // Find all hits of this track 00038 // LArHitTable::iterator hit = hits->begin(); 00039 // LArHitTable::iterator lastHit = hits->end(); 00040 // Long_t hitIndx = 0; 00041 // // Create an empty list of this track hits 00042 // (*track).hits = new TIndexTable(hits); 00043 // for(;hit != lastHit;hit++,hitIndx) { 00044 // if (IsMyHit(*hit)) { // add this hit index to the current track 00045 // (*track).hits->push_back(hitIndx); 00046 // } 00047 // } 00048 // } 00049 //___________________________________________________________________ 00050 00051 // TableClassImpl(TIndexTable,int); 00052 TTableDescriptor *TIndexTable::fgColDescriptors = TIndexTable::CreateDescriptor(); 00053 ClassImp(TIndexTable) 00054 00055 #if 0 00056 void TIndexTable::Dictionary() 00057 { 00058 //to be documented 00059 TClass *c = CreateClass(_QUOTE_(className), Class_Version(), 00060 DeclFileName(), ImplFileName(), 00061 DeclFileLine(), ImplFileLine()); 00062 00063 int nch = strlen(_QUOTE2_(structName,.h))+2; 00064 char *structBuf = new char[nch]; 00065 strlcpy(structBuf,_QUOTE2_(structName,.h),nch); 00066 char *s = strstr(structBuf,"_st.h"); 00067 if (s) { *s = 0; strlcat(structBuf,".h",nch); } 00068 TClass *r = CreateClass(_QUOTE_(structName), Class_Version(), 00069 structBuf, structBuf, 1, 1 ); 00070 fgIsA = c; 00071 fgColDescriptors = new TTableDescriptor(r); 00072 } 00073 _TableClassImp_(TIndexTable,int) 00074 #endif 00075 TableClassStreamerImp(TIndexTable) 00076 00077 //___________________________________________________________________ 00078 TIndexTable::TIndexTable(const TTable *table):TTable("Index",-1), fRefTable(table) 00079 { 00080 //to be documented 00081 if (!fgColDescriptors) CreateDescriptor(); 00082 fSize = fgColDescriptors->Sizeof(); 00083 // Add refered table to this index. 00084 // yf if (table) Add((TDataSet *)table); 00085 } 00086 //___________________________________________________________________ 00087 TTableDescriptor *TIndexTable::CreateDescriptor() 00088 { 00089 //to be documented 00090 if (!fgColDescriptors) { 00091 // Set an empty descriptor 00092 fgColDescriptors= new TTableDescriptor("int"); 00093 // Create one 00094 if (fgColDescriptors) { 00095 TTableDescriptor &dsc = *fgColDescriptors; 00096 tableDescriptor_st row; 00097 00098 memset(&row,0,sizeof(row)); 00099 strlcpy(row.fColumnName,"index",sizeof(row.fColumnName)); 00100 00101 row.fType = kInt; 00102 row.fTypeSize = sizeof(Int_t); 00103 row.fSize = row.fTypeSize; 00104 dsc.AddAt(&row); 00105 } 00106 } 00107 return fgColDescriptors; 00108 } 00109 00110 //___________________________________________________________________ 00111 TTableDescriptor *TIndexTable::GetDescriptorPointer() const 00112 { 00113 //return column descriptor 00114 return fgColDescriptors; 00115 } 00116 00117 //___________________________________________________________________ 00118 void TIndexTable::SetDescriptorPointer(TTableDescriptor *list) 00119 { 00120 //set table descriptor 00121 fgColDescriptors = list; 00122 } 00123 00124 //___________________________________________________________________ 00125 00126 //___________________________________________________________________ 00127 const TTable *TIndexTable::Table() const 00128 { 00129 //to be documented 00130 return fRefTable; 00131 }