StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TestSorter.C
1 // $Id: TestSorter.C,v 1.10 2006/08/15 21:43:05 jeromel Exp $
2 // $Log: TestSorter.C,v $
3 // Revision 1.10 2006/08/15 21:43:05 jeromel
4 // Fix rhic -> rhic.bnl.gov
5 //
6 // Revision 1.9 2000/06/05 18:14:13 fine
7 // Adjuested to ROOT 2.24
8 //
9 // Revision 1.8 2000/01/19 21:00:40 kathy
10 // update macros to use standard default xdf files in /afs/rhic.bnl.gov/star/data/samples
11 //
12 // Revision 1.7 2000/01/12 02:20:19 fine
13 // test check new St_TableSorter ctors
14 //
15 // Revision 1.6 1999/12/01 13:57:42 fine
16 // Second test to check operator [] has been introduced
17 //
18 // Revision 1.5 1999/05/21 15:33:55 kathy
19 // made sure Log & Id are in each file and also put in standard comment line with name of owner
20 //
21 //=======================================================================
22 // owner: Valery Fine
23 // what it does:
24 //=======================================================================
25 class TTableSorter;
26 class St_particle;
27 TTableSorter *sorter = 0;
28 St_particle *table=0;
29 void Load() {
30  if (gSystem.Load("xdf2root")) printf(" Loading DLL \"xdf2root\" failed \n");
31  if (gSystem.Load("St_Tables")) printf(" Loading DLL \"St_Tables\" failed \n");
32 }
33 void TestSorter(Char_t *xdffilename="/afs/rhic.bnl.gov/star/data/samples/test.xdf",const Char_t *col="phep[3]")
34 {
35  // Read XDF file
36  Load();
37  St_XDFFile xdf(xdffilename);
38  TDataSet *event = xdf.NextEventGet();
39  if (!event) { printf(" NO events \n"); return;}
40  table=0;
41  TDataSetIter root(event);
42  table = (St_particle *)root["/evgen/particle"]; // [] means we are looking for the "real" table/ not just a St_DataSet
43  if (table) {
44  TString colName = col;
45  sorter = new TTableSorter(table,colName,1,5);
46 // sorter = new TTableSorter(*table,colName,1,5);
47  table->Print(0,6);
48  int cols = sorter->GetFirstRow() + sorter->GetNRows() -1;
49  cout << " Result of the ordering the table: " << endl
50  << "<" << sorter->GetTableName() <<" : " << sorter->GetTableType() << "[" << sorter->GetFirstRow() << "]> - "
51  << "<" << sorter->GetTableName()
52  <<" : " << sorter->GetTableType()
53  << "[" << cols << "]> "
54  << " along: \"" << sorter->GetName() << "\" column" << endl;
55  cout << "This table contains " << sorter->CountKeys() << " different keys" << endl;
56  int i;
57 
58  cout << "Index:";
59  for (i=0; i < sorter->GetNRows(); i++) cout << " [" << sorter->GetIndex(i) << "] ";
60  cout << endl;
61 
62  cout << "Value: " ;
63  particle_st *particle = table->GetTable();
64  for (i=0; i < sorter->GetNRows(); i++) cout << particle[sorter->GetIndex(i)]->phep[3] << " ";
65  cout << endl;
66 
67  cout << " Binary Search test:"<< endl;
68  for (i=sorter->GetNRows()-1; i >= 0 ; i--) {
69  Float_t ph = particle[sorter->GetIndex(i)]->phep[3];
70  Int_t lastFound = sorter->BinarySearch(ph);
71  cout << i << ". " << ph << " == " << lastFound << " : " << sorter->GetLastFound() << endl;
72  }
73 
74 // Int_t key2Count = 1;
75 // cout << " Key: " << key2Count << " found " << sorter->CountKey(&key2Count) << " times" << endl;
76 // key2Count = 10;
77 // cout << " Key: " << key2Count << " found " << sorter->CountKey(&key2Count) << " times" << endl;
78  }
79  // second sample:
80  // /afs/rhic.bnl.gov/star/data/samples/set0027_03_49evts_dst.xdf
81  cout << " Second pass " << endl;
82  St_XDFFile xd("/afs/rhic.bnl.gov/star/data/samples/gstar.dst.xdf");
83  event = xd.NextEventGet();
84  if (event) {
85  St_dst_vertex *table=0;
86  table = (St_dst_vertex *)event->FindByName("vertex");
87  if (table) {
88  TString colName = "vtx_id";
89  sorter = new TTableSorter(table,colName,1,5);
90 // sorter = new TTableSorter(*table,colName,1,5);
91 // sorter = new TTableSorter(table->GetHeader(),colName,1,5);
92  TTableSorter &sort = *sorter;
93  table->Print(0,6);
94  int cols = sorter->GetFirstRow() + sorter->GetNRows() - 1;
95  cout << " Result of the ordering the table: " << endl
96  << "<" << sorter->GetTableName() <<" : " << sorter->GetTableType() << "[" << sorter->GetFirstRow() << "]> - "
97  << "<" << sorter->GetTableName()
98  <<" : " << sorter->GetTableType()
99  << "[" << cols << "]> "
100  << " along: \"" << sorter->GetName() << "\" column" << endl;
101  cout << "This table contains " << sorter->CountKeys() << " different keys" << endl;
102 
103  cout << "Index:";
104  for (i=0; i < sorter->GetNRows(); i++) cout << " [" << sorter->GetIndex(i) << "] ";
105  cout << endl;
106 
107  cout << "Value: " ;
108  dst_vertex_st *vertex = table->GetTable();
109  for (i=0; i < sorter->GetNRows(); i++) cout << vertex[sorter->GetIndex(i)]->vtx_id << " ";
110  cout << endl;
111  for (i=0; i < sorter->GetNRows(); i++) cout << vertex[sorter->GetIndex(i)]->z << " ";
112  cout << endl;
113 
114  cout << " Binary Search test:"<< endl;
115  Int_t nrows = sorter->GetNRows() - 1;
116  for (i=nrows; i >= 0 ; i--) {
117  Short_t vtx = vertex[sorter->GetIndex(i)]->vtx_id;
118  Int_t lastFound = sorter->BinarySearch(vtx);
119  cout << i << ". " << vtx << " == " << lastFound << " : " << sorter->GetLastFound() << endl;
120  if (sort[vtx] != lastFound)
121  cout << " *** Error **** " << lastFound << " != " << sorter[vtx] << endl;
122 // printf(" *** Error **** %d != %d \n" lastFound,sorter[vtx]);
123  }
124 
125 // Int_t key2Count = 1;
126 // cout << " Key: " << key2Count << " found " << sorter->CountKey(&key2Count) << " times" << endl;
127 // key2Count = 10;
128 // cout << " Key: " << key2Count << " found " << sorter->CountKey(&key2Count) << " times" << endl;
129  }
130  }
131  else cout << " NO events" << endl;
132 }
Int_t GetIndex(UInt_t sortedIndex) const
returns the original index of the row by its sorted index
virtual const char * GetTableType() const
to be documented
virtual const char * GetTableName() const
to be documented
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
virtual Int_t CountKeys() const