00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ROOT_TTable
00013 #define ROOT_TTable
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifdef __CINT__
00026 #pragma Ccomment on
00027 #endif
00028
00029 #include "Ttypes.h"
00030 #include "TDataSet.h"
00031 #include "tableDescriptor.h"
00032 #ifndef ROOT_TCut
00033 # include "TCut.h"
00034 #endif
00035
00036 # ifndef ROOT_Riosfwd
00037 # include "Riosfwd.h"
00038 # endif
00039
00040 #ifndef __CINT__
00041 # include <string.h>
00042 # include <assert.h>
00043 #endif
00044
00045 #include <vector>
00046
00047 class TTableDescriptor;
00048 class TH1;
00049 class TTableMap;
00050 typedef TTableMap* Ptr_t;
00051
00052 class TTable : public TDataSet {
00053 friend class TDataSet;
00054 friend class St_XDFFile;
00055 protected:
00056 Long_t fSize;
00057
00058 protected:
00059
00060 Int_t fN;
00061 Char_t *fTable;
00062 Long_t fMaxIndex;
00063
00064 Bool_t BoundsOk(const char *where, Int_t at) const;
00065 Bool_t OutOfBoundsError(const char *where, Int_t i) const;
00066
00067 void CopyStruct(Char_t *dest, const Char_t *src);
00068 Char_t *Create();
00069 virtual void Clear(Option_t *opt="");
00070 virtual void Delete(Option_t *opt="");
00071 virtual Bool_t EntryLoop(const Char_t *exprFileName,Int_t &action, TObject *obj, Int_t nentries=1000000000, Int_t firstentry=0, Option_t *option="");
00072 Int_t SetfN(Long_t len);
00073 void SetTablePointer(void *table);
00074 void SetUsedRows(Int_t n);
00075 virtual void SetType(const char *const type);
00076 void StreamerHeader(TBuffer &b,Version_t version=3);
00077 void StreamerTable(TBuffer &b,Version_t version=3);
00078 virtual TTableDescriptor *GetDescriptorPointer() const;
00079 virtual void SetDescriptorPointer(TTableDescriptor *list);
00080
00081 void ReAlloc(Int_t newsize);
00082 static const char *TableDictionary(const char *className,const char *structName,TTableDescriptor *&ColDescriptors);
00083
00084 public:
00085
00086 enum EColumnType {kNAN, kFloat, kInt, kLong, kShort, kDouble, kUInt
00087 ,kULong, kUShort, kUChar, kChar, kPtr, kBool
00088 ,kEndColumnType };
00089 enum ETableBits {
00090 kIsNotOwn = BIT(23)
00091
00092 };
00093 static const char *fgTypeName[kEndColumnType];
00094 TTable(const char *name=0, Int_t size=0);
00095 TTable(const char *name, Int_t n,Int_t size);
00096 TTable(const char *name, Int_t n, Char_t *array,Int_t size);
00097 TTable(const char *name, const char *type, Int_t n, Char_t *array, Int_t size);
00098 TTable(const TTable &table);
00099 TTable &operator=(const TTable &rhs);
00100 virtual ~TTable();
00101
00102 virtual void Adopt(Int_t n, void *array);
00103 virtual Int_t AddAt(const void *c);
00104 virtual void AddAt(const void *c, Int_t i);
00105 virtual void AddAt(TDataSet *dataset,Int_t idx=0);
00106 virtual Long_t AppendRows(const void *row, UInt_t nRows);
00107 virtual void AsString(void *buf, EColumnType type, Int_t width, ostream &out) const;
00108 const void *At(Int_t i) const;
00109 virtual void Browse(TBrowser *b);
00110 virtual void CopySet(TTable &array);
00111 Int_t CopyRows(const TTable *srcTable,Long_t srcRow=0, Long_t dstRow=0, Long_t nRows=0, Bool_t expand=kFALSE);
00112 virtual void DeleteRows(Long_t indx,UInt_t nRows=1);
00113 virtual void Draw(Option_t *opt);
00114 virtual TH1 *Draw(TCut varexp, TCut selection, Option_t *option=""
00115 ,Int_t nentries=1000000000, Int_t firstentry=0);
00116 virtual TH1 *Draw(const char *varexp, const char *selection, Option_t *option=""
00117 ,Int_t nentries=1000000000, Int_t firstentry=0);
00118 void *GetArray() const ;
00119 virtual TClass *GetRowClass() const ;
00120 Int_t GetSize() const { return fN; }
00121 virtual Long_t GetNRows() const;
00122 virtual Long_t GetRowSize() const;
00123 virtual Long_t GetTableSize() const;
00124 virtual TTableDescriptor *GetTableDescriptors() const;
00125 virtual TTableDescriptor *GetRowDescriptors() const;
00126 virtual const Char_t *GetType() const;
00127 virtual void Fit(const char *formula ,const char *varexp, const char *selection="",Option_t *option="" ,Option_t *goption=""
00128 ,Int_t nentries=1000000000, Int_t firstentry=0);
00129
00130 virtual Long_t HasData() const { return 1; }
00131 virtual Long_t InsertRows(const void *rows, Long_t indx, UInt_t nRows=1);
00132 virtual Bool_t IsFolder() const;
00133 Int_t NaN();
00134 static TTable *New(const Char_t *name, const Char_t *type, void *array, UInt_t size);
00135 virtual Char_t *MakeExpression(const Char_t *expressions[],Int_t nExpressions);
00136 virtual Char_t *Print(Char_t *buf,Int_t n) const ;
00137 virtual void Print(Option_t *opt="") const;
00138 virtual const Char_t *Print(Int_t row, Int_t rownumber=10,
00139 const Char_t *colfirst="", const Char_t *collast="") const;
00140 virtual void PrintContents(Option_t *opt="") const;
00141 virtual const Char_t *PrintHeader() const;
00142 virtual void Project(const char *hname, const char *varexp, const char *selection="", Option_t *option=""
00143 ,Int_t nentries=1000000000, Int_t firstentry=0);
00144
00145 virtual Int_t Purge(Option_t *opt="");
00146
00147 void *ReAllocate(Int_t newsize);
00148 void *ReAllocate();
00149 virtual void SavePrimitive(ostream &out, Option_t *option = "");
00150 virtual void Set(Int_t n);
00151 virtual void Set(Int_t n, Char_t *array);
00152 virtual void SetNRows(Int_t n);
00153 virtual void Reset(Int_t c=0);
00154 virtual void ResetMap(Bool_t wipe=kTRUE);
00155 virtual void Update();
00156 virtual void Update(TDataSet *set,UInt_t opt=0);
00157 void *operator[](Int_t i);
00158 const void *operator[](Int_t i) const;
00159
00160
00161
00162
00163 virtual Int_t GetColumnIndex(const Char_t *columnName) const;
00164 virtual const Char_t *GetColumnName(Int_t columnIndex) const;
00165 virtual const UInt_t *GetIndexArray(Int_t columnIndex) const;
00166 virtual UInt_t GetNumberOfColumns() const;
00167 virtual UInt_t GetOffset(Int_t columnIndex) const;
00168 virtual Int_t GetOffset(const Char_t *columnName=0) const;
00169 virtual UInt_t GetColumnSize(Int_t columnIndex) const;
00170 virtual Int_t GetColumnSize(const Char_t *columnName=0) const;
00171 virtual UInt_t GetTypeSize(Int_t columnIndex) const;
00172 virtual Int_t GetTypeSize(const Char_t *columnName=0) const ;
00173 virtual UInt_t GetDimensions(Int_t columnIndex) const;
00174 virtual Int_t GetDimensions(const Char_t *columnName=0) const ;
00175 virtual EColumnType GetColumnType(Int_t columnIndex) const;
00176 virtual EColumnType GetColumnType(const Char_t *columnName=0) const;
00177 virtual const Char_t *GetColumnComment(Int_t columnIndex) const;
00178
00179 static const char *GetTypeName(EColumnType type);
00180 static EColumnType GetTypeId(const char *typeName);
00181
00182
00183 class iterator {
00184 public:
00185 typedef std::vector<Long_t>::iterator vec_iterator;
00186 typedef std::vector<Long_t>::const_iterator vec_const_iterator;
00187 private:
00188 Long_t fRowSize;
00189 const TTable *fThisTable;
00190 vec_iterator fCurrentRow;
00191 public:
00192 iterator(): fRowSize(0), fThisTable(0) {;}
00193 iterator(const TTable &table, vec_iterator &arowPtr) :
00194 fRowSize(table.GetRowSize()), fThisTable(&table), fCurrentRow(arowPtr) {;}
00195 iterator(const TTable &table, vec_const_iterator &arowPtr) :
00196 fRowSize(table.GetRowSize()), fThisTable(&table),
00197 fCurrentRow(*(std::vector<Long_t>::iterator *)(void *)&arowPtr) {;}
00198
00199 iterator(const iterator& iter) : fRowSize (iter.fRowSize), fThisTable(iter.fThisTable),fCurrentRow(iter.fCurrentRow){}
00200 void operator=(const iterator& iter) { fRowSize = iter.fRowSize; fThisTable = iter.fThisTable; fCurrentRow=iter.fCurrentRow; }
00201 void operator++() { ++fCurrentRow; }
00202 void operator++(int) { fCurrentRow++; }
00203 void operator--() { --fCurrentRow; }
00204 void operator--(int) { fCurrentRow--; }
00205 iterator operator+(Int_t idx) { std::vector<Long_t>::iterator addition = fCurrentRow+idx; return iterator(*fThisTable,addition); }
00206 iterator operator-(Int_t idx) { std::vector<Long_t>::iterator subtraction = fCurrentRow-idx; return iterator(*fThisTable,subtraction); }
00207 void operator+=(Int_t idx) { fCurrentRow+=idx; }
00208 void operator-=(Int_t idx) { fCurrentRow-=idx; }
00209 void *rowPtr() const { return (void *)(((const char *)fThisTable->GetArray()) + (*fCurrentRow)*fRowSize ); }
00210 operator void *() const { return rowPtr(); }
00211 Int_t operator-(const iterator &it) const { return (*fCurrentRow)-(*(it.fCurrentRow)); }
00212 Long_t operator *() const { return *fCurrentRow; }
00213 Bool_t operator==(const iterator &t) const { return ( (fCurrentRow == t.fCurrentRow) && (fThisTable == t.fThisTable) ); }
00214 Bool_t operator!=(const iterator &t) const { return !operator==(t); }
00215
00216 const TTable &Table() const { return *fThisTable;}
00217 const Long_t &RowSize() const { return fRowSize;}
00218 #ifndef __CINT__
00219 const std::vector<Long_t>::iterator &Row() const { return fCurrentRow;}
00220 #endif
00221 };
00222
00223 #ifndef __CINT__
00224
00225
00226
00227
00228
00229
00230 class piterator {
00231 private:
00232 std::vector<ULong_t> fPtrs;
00233 UInt_t fCurrentRowIndex;
00234 UInt_t fCurrentColIndex;
00235 UInt_t fRowSize;
00236 const Char_t *fCurrentRowPtr;
00237 void **fCurrentColPtr;
00238
00239 protected:
00240 void **column() {return fCurrentColPtr = (void **)(fCurrentRowPtr + fPtrs[fCurrentColIndex]);}
00241
00242 public:
00243 piterator(const TTable *t=0,EColumnType type=kPtr);
00244 piterator(const piterator& iter);
00245 void operator=(const piterator& iter);
00246
00247 void operator++();
00248 void operator++(int);
00249 void operator--();
00250 void operator--(int);
00251
00252
00253 void **operator *();
00254
00255 Bool_t operator==(const piterator &t) const;
00256 Bool_t operator!=(const piterator &t) const;
00257
00258 UInt_t Row() const;
00259 UInt_t Column() const;
00260
00261 void MakeEnd(UInt_t lastRowIndex);
00262 };
00263
00264 piterator pbegin(){ return piterator(this); }
00265 piterator pend(){ piterator pLast(this); pLast.MakeEnd(GetNRows()); return pLast; }
00266 #endif
00267 static const char *TableDictionary() { return 0; };
00268 ClassDef(TTable,4)
00269 };
00270
00271
00272 inline void TTable::AddAt(TDataSet *dataset,Int_t idx)
00273 { TDataSet::AddAt(dataset,idx); }
00274
00275
00276 inline Bool_t TTable::BoundsOk(const char *where, Int_t at) const
00277 {
00278 return (at < 0 || at >= fN)
00279 ? OutOfBoundsError(where, at)
00280 : kTRUE;
00281 }
00282
00283
00284 inline void *TTable::GetArray() const { return (void *)fTable;}
00285
00286
00287 inline void TTable::Print(Option_t *) const { Print((Char_t *)0,Int_t(0)); }
00288
00289
00290 inline void TTable::SetUsedRows(Int_t n) { fMaxIndex = n;}
00291
00292 inline void TTable::SetNRows(Int_t n) {SetUsedRows(n);}
00293
00294
00295
00296 inline void *TTable::operator[](Int_t i)
00297 {
00298 if (!BoundsOk("TTable::operator[]", i))
00299 i = 0;
00300 return (void *)(fTable+i*fSize);
00301 }
00302
00303
00304 inline const void *TTable::operator[](Int_t i) const
00305 {
00306 if (!BoundsOk("TTable::operator[]", i))
00307 i = 0;
00308 return (const void *)(fTable+i*fSize);
00309 }
00310
00311
00312 inline void TTable::Draw(Option_t *opt)
00313 { Draw(opt, "", "", 1000000000, 0); }
00314
00315 #ifndef __CINT__
00316
00317 inline TTable::piterator::piterator(const piterator& iter) :
00318 fPtrs (iter.fPtrs),
00319 fCurrentRowIndex(iter.fCurrentRowIndex),
00320 fCurrentColIndex(iter.fCurrentColIndex),
00321 fRowSize(iter.fRowSize),
00322 fCurrentRowPtr(iter.fCurrentRowPtr),
00323 fCurrentColPtr(iter.fCurrentColPtr)
00324 {}
00325
00326 inline void TTable::piterator::operator=(const piterator& iter){
00327 fPtrs = iter.fPtrs;
00328 fCurrentRowIndex = iter.fCurrentRowIndex;
00329 fCurrentColIndex = iter.fCurrentColIndex;
00330 fRowSize = iter.fRowSize;
00331 fCurrentRowPtr = iter.fCurrentRowPtr;
00332 fCurrentColPtr = iter.fCurrentColPtr;
00333 }
00334
00335 inline void TTable::piterator::operator++()
00336 {
00337 ++fCurrentColIndex;
00338 if (fCurrentColIndex >= fPtrs.size()) {
00339 fCurrentColIndex = 0;
00340 ++fCurrentRowIndex;
00341 fCurrentRowPtr += fRowSize;
00342 }
00343 column();
00344 }
00345
00346 inline void TTable::piterator::operator++(int) { operator++(); }
00347
00348 inline void TTable::piterator::operator--()
00349 {
00350 if (fCurrentColIndex > 0) {
00351 fCurrentColIndex--;
00352 fCurrentColIndex = fPtrs.size()-1;
00353 --fCurrentRowIndex;
00354 fCurrentRowPtr -= fRowSize;
00355 } else {
00356 fCurrentColIndex--;
00357 }
00358 column();
00359 }
00360
00361 inline void TTable::piterator::operator--(int) { operator--(); }
00362
00363
00364
00365 inline void **TTable::piterator::operator *() { return fCurrentColPtr; }
00366
00367 inline Bool_t TTable::piterator::operator==(const piterator &t) const {
00368 return (
00369 (fCurrentRowIndex== t.fCurrentRowIndex)
00370 && (fCurrentColIndex == t.fCurrentColIndex)
00371
00372
00373 );
00374 }
00375
00376 inline Bool_t TTable::piterator::operator!=(const piterator &t) const { return !operator==(t); }
00377
00378 inline void TTable::piterator::MakeEnd(UInt_t lastRowIndex){fCurrentColIndex = 0; fCurrentRowIndex = lastRowIndex;}
00379
00380 inline UInt_t TTable::piterator::Row() const { return fCurrentRowIndex;}
00381
00382 inline UInt_t TTable::piterator::Column() const { return fCurrentColIndex;}
00383 #endif
00384 #include "TTableDescriptor.h"
00385
00386 #endif