StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
GenericTable.C
1  {
2  // Copyright(c) 2001 [BNL] Brookhaven National Laboratory, Valeri Fine (fine@bnl.gov). All right reserved",
3  // TGenericTable and TIndexTable test macro
4  int problemCounter = 0;
5  gSystem->Load("libTable");
6  struct hit {
7  float energy; /* energy */
8  int detectorId; /* geometry id */
9  };
10 
11  TGenericTable *allHits = new TGenericTable("hit","hits",1000);
12  allHits->Print();
13  hit a;
14  memset(&a,0,sizeof(a));
15  int i = 0;
16  for (i=0; i<100; i++) {
17  a.energy = sin(i*0.1);
18  a.detectorId = i;
19  allHits->AddAt(&a);
20  }
21  allHits->Print();
22  // Draw the histogram for the selected column
23  allHits->Draw("energy");
24  // Print the table descriptor
25  printf("\n\n Print out the hit table descriptor: \n");
26  allHits->GetTableDescriptors()->Print(0,10);
27  TFile ff("generic.root","RECREATE");
28  allHits->Write();
29  ff.Write();
30  ff.Close();
31  allHits->Print(0,10);
32  // Create an index table
33  TRandom rndIndex;
34  TIndexTable indxRandom(allHits);
35  TIndexTable indxSeq(allHits);
36  if ( indxRandom.GetRowSize() != sizeof(int) ) {
37  printf(" The empty index table has been created. The row size = %d\n",indxRandom.GetRowSize());
38  problemCounter++;
39  }
40  for (i=0; i<100; i++) {
41  indxRandom.push_back(rndIndex.Integer(100));
42  indxSeq.push_back(i);
43  }
44  TIndexTable::iterator first = indxRandom.begin();
45  TIndexTable::iterator last = indxRandom.end();
46  i = 0;
47  hit *nextRow = 0;
48  for (;first != last; ++first,i++) {
49  if ( (int)first != ((hit *)*first)->detectorId )
50  {
51  printf(" *** Error ***. %d-th index does point to right row of %s table. It points to %d:%d row instead\n",
52  i,indxRandom.GetName(),((hit *)*first)->detectorId,(int)first);
53  problemCounter++;
54  break;
55  }
56  }
57  first = indxSeq.begin();
58  last = indxSeq.end();
59  i = 0;
60  hit *nextRow = 0;
61  for (;first != last; ++first,i++) {
62  if ( i != ((hit *)*first)->detectorId )
63  {
64  printf(" *** Error ***. %d-th index does point to right row of %s table. It points to energy= %f; id=%d:%d row instead\n",
65  i,indxSeq.GetName(),((hit *)*first)->energy, ((hit *)*first)->detectorId,(int)first);
66  problemCounter++;
67  break;
68  }
69  }
70  if (problemCounter) printf("There were several problem detected !!!\n");
71  else printf(" no problem have been found\n");
72  }
73 
virtual Long_t GetRowSize() const
Returns the size (in bytes) of one table row.
Definition: TTable.cxx:1395
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Definition: TDataSet.cxx:893
virtual Int_t AddAt(const void *c)
Definition: TTable.cxx:1122
TTableDescriptor * GetTableDescriptors() const
protected: create a new TTableDescriptor descriptor for this table
Definition: TGenericTable.h:63
virtual Char_t * Print(Char_t *buf, Int_t n) const
Create IDL table defintion (to be used for XDF I/O)
Definition: TTable.cxx:1548