StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Example_read_dst_print_tables.C
1 // $Id: Example_read_dst_print_tables.C,v 1.9 2006/08/15 21:42:55 jeromel Exp $
2 // $Log: Example_read_dst_print_tables.C,v $
3 // Revision 1.9 2006/08/15 21:42:55 jeromel
4 // Fix rhic -> rhic.bnl.gov
5 //
6 // Revision 1.8 2000/06/05 16:35:35 kathy
7 // remove use of member function GetHeader since it is no longer available - now use memb functions of TTable
8 //
9 // Revision 1.7 2000/04/18 20:37:25 kathy
10 // St_DataSet,St_DataSetIter,St_Table classes are nowchanged to TDataSet,TDataSetIter,TTable
11 //
12 // Revision 1.6 2000/04/13 21:46:21 kathy
13 // remove loading of libtpc_Tables since l3Track table is now dst_track type from global
14 //
15 // Revision 1.5 2000/04/12 16:13:40 kathy
16 // have changed so that macro loads only table libraries needed instead of all table libraries
17 //
18 // Revision 1.4 2000/01/19 15:46:04 kathy
19 // change default input files to point to ones in /afs/rhic.bnl.gov/star/data/samples
20 //
21 // Revision 1.3 1999/11/30 20:04:17 kathy
22 // fix Example macros so that they work from .dst.root files or .dst.xdf files & update documentation; also had to change which values printed in *read_dst_print_tables* macro since the names have changed in dst tables
23 //
24 // Revision 1.2 1999/11/03 16:57:00 kathy
25 // fix macros to use StIOMaker instead of StTreeMaker
26 //
27 // Revision 1.1 1999/10/11 17:17:57 kathy
28 // changed names of some macros to make them more standard; changed default input file to MakeHists since previous no longer existed; combined some macros so that the one example will show all functionality
29 //
30 //
31 //======================================================================
32 // owner: Kathy Turner
33 // what it does:
34 // Kathy's notes (10/11/99):
35 // - read dstbranch from *.dst.root or *.dst.xdf file
36 // - read 1 event and print out information from the tables
37 //======================================================================
38 
39 class StChain;
40 StChain *chain;
41 
42 class TDataSet;
44 
45 void Example_read_dst_print_tables(
46  Int_t nevents=1,
47  const char *MainFile=
48 "/afs/rhic.bnl.gov/star/data/samples/gstar.dst.root")
49 {
50 //
51  gSystem->Load("St_base");
52  gSystem->Load("StChain");
53 
54  gSystem->Load("libglobal_Tables");
55  gSystem->Load("libgen_Tables");
56  gSystem->Load("libsim_Tables");
57  gSystem->Load("libtpc_Tables");
58 
59  gSystem->Load("StIOMaker");
60  gSystem->Load("StarClassLibrary");
61 
62  cout << " .. Example_read_dst_print_tables.C, have loaded libraries " << endl;
63 
64 // Setup top part of chain
65  chain = new StChain("bfc");
66  chain->SetDebug();
67 
68 //
69 // setup chain with IOMaker - can read in .dst.root, .dst.xdf files
70  StIOMaker *IOMk = new StIOMaker("IO","r",MainFile,"bfcTree");
71  IOMk->SetDebug();
72  IOMk->SetIOMode("r");
73  IOMk->SetBranch("*",0,"0"); //deactivate all branches
74 // IOMk->SetBranch("tpc_tracks",0,"r"); //activate tpc_tracks Branch
75 // IOMk->SetBranch("geantBranch",0,"r"); //activate geant Branch
76  IOMk->SetBranch("dstBranch",0,"r"); //activate dst Branch
77 
78 
79 // --- now execute chain member functions
80  chain->Init();
81 
82  for (int iev=0;iev<nevents; iev++)
83  {
84  chain->Clear();
85  int iret = chain->Make();
86  if (iret) break;
87 
88  cout << endl << endl <<
89  " !!! Now print info about event # " << iev << endl;
90 
91 // ------ List all tables -----------
92 // GetDataSet is a member function of St_Maker
93  Event = chain->GetDataSet("dst");
94 
95 // ls() returns a virtual void, so don't have to set it = to anything
96  if (Event) Event->ls();
97 
98 
99 // ---------------------- globtrk table ---------------------
100 // get dataset for globtrk
101 TDataSet *ds=chain->GetDataSet("dst/globtrk");
102 
103 if (ds) {
104 
105  cout << " Now print info about globtrk table " << endl;
106 
107 // create iterator for the dataset
108 TDataSetIter globtrkiter(ds);
109 
110 // Du,Pwd return things, but we choose not to keep the return value
111 globtrkiter.Du();
112 globtrkiter.Pwd();
113 
114 // find the table
115 St_dst_track *glob = (St_dst_track *) globtrkiter.Find("globtrk");
116 
117 // print out info about it
118 // using ls() from TDataSetIter
119 glob->ls();
120 
121 // Print() is a member function of TTable
122 //glob->Print(9,1);
123 //glob->Print(8,1);
124 //glob->Print(8,2);
125 //glob->Print(1,1);
126 glob->Print(0,5);
127 
128 
129 // can't use this method anymore!!! 5June00 Kathy
130 // get the table header data using member function of TTable
131 //table_head_st *tdt_h = glob->GetHeader();
132 // cout << " header name = " << tdt_h->name << endl;
133 // cout << " header type = " << tdt_h->type << endl;
134 // cout << " header maxlen = " << tdt_h->maxlen << endl;
135 // cout << " header nok = " << tdt_h->nok << endl;
136 
137 
138 // get the table header data using member functions of TTable
139  cout << " table header info: name = " << glob->GetName() << endl;
140  cout << " table header info: type = " << glob->GetType() << endl;
141  cout << " table header info: #rows used = " << glob->GetNRows() << endl;
142  cout << " table header info: #rows allocated = " << glob->GetTableSize() << endl;
143  cout << " table header info: row size (bytes) = " << glob->GetRowSize() << endl;
144  cout << " table header info: #columns = " << glob->GetNumberOfColumns() << endl;
145 
146 // get the table and print out info about it (it's printing row 0)
147  dst_track_st *sth = glob->GetTable();
148  cout << " globtrk: row0 " << endl;
149  cout << " r0 = " << sth->r0 << endl;
150  cout << " impact = " << sth->impact << endl;
151  cout << " invpt = " << sth->invpt << endl;
152  cout << " z0 = " << sth->z0 << endl;
153 
154 // now go to next row
155 // - just increment the pointer to do this (probably just STAR-specific
156 // way - can't always increment pointers and get to right place!
157 
158  sth++;
159  cout << " globtrk: row1 " << endl;
160  cout << " r0 = " << sth->r0 << endl;
161  cout << " impact = " << sth->impact << endl;
162  cout << " invpt = " << sth->invpt << endl;
163  cout << " z0 = " << sth->z0 << endl;
164 
165 }
166 
167 //--------------------------------------------------------
168  }
169 
170  chain->Finish();
171 
172 }
173 
174 
175 
176 
177 
178 
virtual void SetIOMode(Option_t *iomode="w")
number of transactions
Definition: StIOInterFace.h:35
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StChain.cxx:77
virtual Int_t Finish()
Definition: StChain.cxx:85
virtual void ls(Option_t *option="") const
Definition: TDataSet.cxx:495
virtual Int_t Make()
Definition: StChain.cxx:110
Definition: AgUStep.h:26