// @(#)root/table:$Id$
// Author: Valery Fine(fine@bnl.gov)   30/06/2001

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/


#include "TGenericTable.h"

//////////////////////////////////////////////////////////////////////////
//                                                                      //
//  TGenericTable                                                       //
//                                                                      //
//  This is the class to represent the array of C-struct                //
//  defined at run-time                                                 //
//                                                                      //
//   Example: see $ROOTSYS/tutorials/tree/staff.C                       //
//   -------                                                            //
// !{
// !//   example of macro to read data from an ascii file and
// !//   create a root file with an histogram and an ntuple.
// !//   A'la the famous ROOT/PAW staff data example
// !//   ( see PAW - Long write up, CERN, page33. )
// !
// !   gROOT->Reset();
// !   gSystem->Load("libRootKernel");
// !
// !   struct staff_t {
// !                Int_t cat;
// !                Int_t division;
// !                Int_t flag;
// !                Int_t age;
// !                Int_t service;
// !                Int_t children;
// !                Int_t grade;
// !                Int_t step;
// !                Int_t nation;
// !                Int_t hrweek;
// !                Int_t cost;
// !    };
// !
// !   staff_t staff;
// !
// !   // open ASCII data file
// !   FILE *fp = fopen("staff.dat","r");
// !
// !   char line[81];
// !
// !   // Create the generic table for 1000 rows (it may grow then)
// !   TGenericTable *allStaff = new TGenericTable("staff_t","Staff-data",1000);
// !
// !   // Fill the memory resident table
// !   while (fgets(&line,80,fp)) {
// !      sscanf(&line[0] ,"%d%d%d%d", &staff.cat,&staff.division,&staff.flag,&staff.age);
// !      sscanf(&line[13],"%d%d%d%d", &staff.service,&staff.children,&staff.grade,&staff.step);
// !      sscanf(&line[24],"%d%d%d",   &staff.nation,&staff.hrweek,&staff.cost);
// !      allStaff->AddAt(&staff);
// !   }
// !   fclose(fp);
// !   // Delete unused space;
// !   allStaff->Purge();
// !
// !   allStaff->Print(0,10);
// !
// !//  Create ROOT file
// !   TFile *f = new TFile("aptuple.root","RECREATE");
// !          allStaff->Write();
// !   f->Write();
// !
// !   // We should close  TFile otherwise all histograms we create below
// !   // may be written to the file too occasionaly
// !   f->Close();
// !
// !//  Create ROOT Browser
// !   new TBrowser("staff",allStaff);
// !
// !//  Create couple of the histograms
// !   TCanvas *canva = new TCanvas("Staff","CERN Population",600,600);
// !   canva->Divide(1,2);
// !
// !
// !// one can use 2 meta variable:
// !//  n$ - the total number of the rows in the table
// !//  i$ - stands for the current row index i = [0 -> (n$-1)]
// !
// !   gStyle->SetHistFillColor(10);
// !   gStyle->SetHistFillStyle(3013);
// !   canva->cd(1);
// !   allStaff->Draw("age");
// !   canva->Update();
// !   canva->cd(2);
// !   allStaff->Draw("cost");
// !   canva->Update();
// !}
//
//////////////////////////////////////////////////////////////////////////

   ClassImp(TGenericTable)
   TableClassStreamerImp(TGenericTable)

// Create TGenericTable by TTableDescriptor pointer
//______________________________________________________________________________
TGenericTable::TGenericTable(const TTableDescriptor &dsc, const char *name) : TTable(name,dsc.Sizeof()),fColDescriptors(0)
{
  ///////////////////////////////////////////////////////////
  //
  //   Create TGenericTable by TTableDescriptor pointer:
  //
  //   dsc   - Pointer to the table descriptor
  //   name  - The name of this object
  //
  ///////////////////////////////////////////////////////////

   // Create a private copy of the descriptor provided;
   SetDescriptorPointer(new TTableDescriptor(dsc));
   SetGenericType();
}
//______________________________________________________________________________
TGenericTable::TGenericTable(const TTableDescriptor &dsc, Int_t n) : TTable("TGenericTable",n,dsc.Sizeof()),fColDescriptors(0)
{
  ///////////////////////////////////////////////////////////
  //
  //   Create TGenericTable by TTableDescriptor pointer:
  //
  //   dsc   - Pointer to the table descriptor
  //   name  - "TGenericTable"
  //   n     - The initial number of allocated rows
  //
  ///////////////////////////////////////////////////////////

  // Create a provate copy of the descriptor provided;
   SetDescriptorPointer(new TTableDescriptor(dsc));
   SetGenericType();
}

//______________________________________________________________________________
TGenericTable::TGenericTable(const TTableDescriptor &dsc,const char *name,Int_t n) : TTable(name,n,dsc.Sizeof()),fColDescriptors(0)
{
  ///////////////////////////////////////////////////////////
  //
  //   Create TGenericTable by TTableDescriptor pointer:
  //
  //   dsc   - Pointer to the table descriptor
  //   name  - The name of this object
  //   n     - The initial number of allocated rows
  //
  ///////////////////////////////////////////////////////////

  // Create a provate copy of the descriptor provided;
   SetDescriptorPointer(new TTableDescriptor(dsc));
   SetGenericType();
}

// Create TGenericTable by C structure name provided
//______________________________________________________________________________
TGenericTable::TGenericTable(const char *structName, const char *name) : TTable(name,-1),fColDescriptors(0)
{
  ///////////////////////////////////////////////////////////
  //
  //  Create TGenericTable by C structure name provided:
  //
  //   dsc   - Pointer to the table descriptor
  //   name  - The name of this object
  //   n     - The initial number of allocated rows
  //
  ///////////////////////////////////////////////////////////
   TTableDescriptor *dsc = TTableDescriptor::MakeDescriptor(structName);
   if (dsc) {
      SetDescriptorPointer(dsc);
      fSize = dsc->Sizeof();
   }
   if ( !dsc || !fSize) Warning("TGenericTable","Wrong table format");
   SetGenericType();
}
//______________________________________________________________________________
TGenericTable::TGenericTable(const char *structName, Int_t n) : TTable("TGenericTable",-1),fColDescriptors(0)
{
  ///////////////////////////////////////////////////////////
  //
  //  Create TGenericTable by C structure name provided:
  //
  //   dsc   - Pointer to the table descriptor
  //   name  - The name of this object
  //   n     - The initial number of allocated rows
  //
  ///////////////////////////////////////////////////////////

   TTableDescriptor *dsc = TTableDescriptor::MakeDescriptor(structName);
   if (dsc) {
      SetDescriptorPointer(dsc);
      fSize = dsc->Sizeof();
   }
   if ( !dsc || !fSize) Warning("TGenericTable","Wrong table format");
   if (n > 0) Set(n);
   SetGenericType();
}
//______________________________________________________________________________
TGenericTable::TGenericTable(const char *structName, const char *name,Int_t n) : TTable(name,-1),fColDescriptors(0)
{
  ///////////////////////////////////////////////////////////
  //
  //   Create TGenericTable by C structure name provided:
  //
  //   dsc   - Pointer to the table descriptor
  //   name  - The name of this object
  //   n     - The initial number of allocated rows
  //
  ///////////////////////////////////////////////////////////

   TTableDescriptor *dsc = TTableDescriptor::MakeDescriptor(structName);
   if (dsc) {
      SetDescriptorPointer(dsc);
      fSize = dsc->Sizeof();
   }
   if ( !dsc || !fSize) Warning("TGenericTable","Wrong table format dsc=0x%lx, size=%ld",(Long_t)dsc,fSize);
   if (n > 0) Set(n);
   SetGenericType();
}

//______________________________________________________________________________
TGenericTable::~TGenericTable()
{
   //destructor
   delete fColDescriptors;
}
 TGenericTable.cxx:1
 TGenericTable.cxx:2
 TGenericTable.cxx:3
 TGenericTable.cxx:4
 TGenericTable.cxx:5
 TGenericTable.cxx:6
 TGenericTable.cxx:7
 TGenericTable.cxx:8
 TGenericTable.cxx:9
 TGenericTable.cxx:10
 TGenericTable.cxx:11
 TGenericTable.cxx:12
 TGenericTable.cxx:13
 TGenericTable.cxx:14
 TGenericTable.cxx:15
 TGenericTable.cxx:16
 TGenericTable.cxx:17
 TGenericTable.cxx:18
 TGenericTable.cxx:19
 TGenericTable.cxx:20
 TGenericTable.cxx:21
 TGenericTable.cxx:22
 TGenericTable.cxx:23
 TGenericTable.cxx:24
 TGenericTable.cxx:25
 TGenericTable.cxx:26
 TGenericTable.cxx:27
 TGenericTable.cxx:28
 TGenericTable.cxx:29
 TGenericTable.cxx:30
 TGenericTable.cxx:31
 TGenericTable.cxx:32
 TGenericTable.cxx:33
 TGenericTable.cxx:34
 TGenericTable.cxx:35
 TGenericTable.cxx:36
 TGenericTable.cxx:37
 TGenericTable.cxx:38
 TGenericTable.cxx:39
 TGenericTable.cxx:40
 TGenericTable.cxx:41
 TGenericTable.cxx:42
 TGenericTable.cxx:43
 TGenericTable.cxx:44
 TGenericTable.cxx:45
 TGenericTable.cxx:46
 TGenericTable.cxx:47
 TGenericTable.cxx:48
 TGenericTable.cxx:49
 TGenericTable.cxx:50
 TGenericTable.cxx:51
 TGenericTable.cxx:52
 TGenericTable.cxx:53
 TGenericTable.cxx:54
 TGenericTable.cxx:55
 TGenericTable.cxx:56
 TGenericTable.cxx:57
 TGenericTable.cxx:58
 TGenericTable.cxx:59
 TGenericTable.cxx:60
 TGenericTable.cxx:61
 TGenericTable.cxx:62
 TGenericTable.cxx:63
 TGenericTable.cxx:64
 TGenericTable.cxx:65
 TGenericTable.cxx:66
 TGenericTable.cxx:67
 TGenericTable.cxx:68
 TGenericTable.cxx:69
 TGenericTable.cxx:70
 TGenericTable.cxx:71
 TGenericTable.cxx:72
 TGenericTable.cxx:73
 TGenericTable.cxx:74
 TGenericTable.cxx:75
 TGenericTable.cxx:76
 TGenericTable.cxx:77
 TGenericTable.cxx:78
 TGenericTable.cxx:79
 TGenericTable.cxx:80
 TGenericTable.cxx:81
 TGenericTable.cxx:82
 TGenericTable.cxx:83
 TGenericTable.cxx:84
 TGenericTable.cxx:85
 TGenericTable.cxx:86
 TGenericTable.cxx:87
 TGenericTable.cxx:88
 TGenericTable.cxx:89
 TGenericTable.cxx:90
 TGenericTable.cxx:91
 TGenericTable.cxx:92
 TGenericTable.cxx:93
 TGenericTable.cxx:94
 TGenericTable.cxx:95
 TGenericTable.cxx:96
 TGenericTable.cxx:97
 TGenericTable.cxx:98
 TGenericTable.cxx:99
 TGenericTable.cxx:100
 TGenericTable.cxx:101
 TGenericTable.cxx:102
 TGenericTable.cxx:103
 TGenericTable.cxx:104
 TGenericTable.cxx:105
 TGenericTable.cxx:106
 TGenericTable.cxx:107
 TGenericTable.cxx:108
 TGenericTable.cxx:109
 TGenericTable.cxx:110
 TGenericTable.cxx:111
 TGenericTable.cxx:112
 TGenericTable.cxx:113
 TGenericTable.cxx:114
 TGenericTable.cxx:115
 TGenericTable.cxx:116
 TGenericTable.cxx:117
 TGenericTable.cxx:118
 TGenericTable.cxx:119
 TGenericTable.cxx:120
 TGenericTable.cxx:121
 TGenericTable.cxx:122
 TGenericTable.cxx:123
 TGenericTable.cxx:124
 TGenericTable.cxx:125
 TGenericTable.cxx:126
 TGenericTable.cxx:127
 TGenericTable.cxx:128
 TGenericTable.cxx:129
 TGenericTable.cxx:130
 TGenericTable.cxx:131
 TGenericTable.cxx:132
 TGenericTable.cxx:133
 TGenericTable.cxx:134
 TGenericTable.cxx:135
 TGenericTable.cxx:136
 TGenericTable.cxx:137
 TGenericTable.cxx:138
 TGenericTable.cxx:139
 TGenericTable.cxx:140
 TGenericTable.cxx:141
 TGenericTable.cxx:142
 TGenericTable.cxx:143
 TGenericTable.cxx:144
 TGenericTable.cxx:145
 TGenericTable.cxx:146
 TGenericTable.cxx:147
 TGenericTable.cxx:148
 TGenericTable.cxx:149
 TGenericTable.cxx:150
 TGenericTable.cxx:151
 TGenericTable.cxx:152
 TGenericTable.cxx:153
 TGenericTable.cxx:154
 TGenericTable.cxx:155
 TGenericTable.cxx:156
 TGenericTable.cxx:157
 TGenericTable.cxx:158
 TGenericTable.cxx:159
 TGenericTable.cxx:160
 TGenericTable.cxx:161
 TGenericTable.cxx:162
 TGenericTable.cxx:163
 TGenericTable.cxx:164
 TGenericTable.cxx:165
 TGenericTable.cxx:166
 TGenericTable.cxx:167
 TGenericTable.cxx:168
 TGenericTable.cxx:169
 TGenericTable.cxx:170
 TGenericTable.cxx:171
 TGenericTable.cxx:172
 TGenericTable.cxx:173
 TGenericTable.cxx:174
 TGenericTable.cxx:175
 TGenericTable.cxx:176
 TGenericTable.cxx:177
 TGenericTable.cxx:178
 TGenericTable.cxx:179
 TGenericTable.cxx:180
 TGenericTable.cxx:181
 TGenericTable.cxx:182
 TGenericTable.cxx:183
 TGenericTable.cxx:184
 TGenericTable.cxx:185
 TGenericTable.cxx:186
 TGenericTable.cxx:187
 TGenericTable.cxx:188
 TGenericTable.cxx:189
 TGenericTable.cxx:190
 TGenericTable.cxx:191
 TGenericTable.cxx:192
 TGenericTable.cxx:193
 TGenericTable.cxx:194
 TGenericTable.cxx:195
 TGenericTable.cxx:196
 TGenericTable.cxx:197
 TGenericTable.cxx:198
 TGenericTable.cxx:199
 TGenericTable.cxx:200
 TGenericTable.cxx:201
 TGenericTable.cxx:202
 TGenericTable.cxx:203
 TGenericTable.cxx:204
 TGenericTable.cxx:205
 TGenericTable.cxx:206
 TGenericTable.cxx:207
 TGenericTable.cxx:208
 TGenericTable.cxx:209
 TGenericTable.cxx:210
 TGenericTable.cxx:211
 TGenericTable.cxx:212
 TGenericTable.cxx:213
 TGenericTable.cxx:214
 TGenericTable.cxx:215
 TGenericTable.cxx:216
 TGenericTable.cxx:217
 TGenericTable.cxx:218
 TGenericTable.cxx:219
 TGenericTable.cxx:220
 TGenericTable.cxx:221
 TGenericTable.cxx:222
 TGenericTable.cxx:223
 TGenericTable.cxx:224
 TGenericTable.cxx:225
 TGenericTable.cxx:226
 TGenericTable.cxx:227
 TGenericTable.cxx:228
 TGenericTable.cxx:229
 TGenericTable.cxx:230