StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
bfcread_histBranch.C
1 // $Id: bfcread_histBranch.C,v 1.7 2006/08/15 21:43:12 jeromel Exp $
2 // $Log $
3 
4 //======================================================================
5 // owner: Kathy Turner
6 // what it does: reads .dst.root file produced from bfc & then goes to
7 // the hist.root branch
8 // - finds data set "hist"
9 // - loops over and prints out list of objects
10 // - then for each object (which is a directory)
11 // prints out all objects (which are histograms)
12 // inside it
13 //
14 // - the hist branch only has 1 "event" per dst run!
15 //
16 // Inputs to macro:
17 // nevents - # events to process (should always leave at 1 !!)
18 // MainFile - input *.dst.root file (you can use any branch here)
19 // fname - output file name with qa info
20 //
21 //=======================================================================
22 
23 class StChain;
24 StChain *chain;
25 
26 void bfcread_histBranch(
27  Int_t nevents=1,
28  const char *MainFile=
29  "/afs/rhic.bnl.gov/star/data/samples/gstar.dst.root",
30  const char *fname="qa_hist.out")
31 {
32 //
33  cout << " events to process = " << nevents << endl;
34  cout << " Input File Name = " << MainFile << endl;
35  cout << " Output file containing printouts = " << fname << endl;
36 
37  ofstream fout(fname);
38 
39  fout << " Running: bfcread_histBranch.C " << endl;
40  fout << " events to process = " << nevents << endl;
41  fout << " Input File Name = " << MainFile << endl;
42  fout << " Output file containing printouts = " << fname << endl;
43  fout << endl << endl;
44 
45  gSystem->Load("St_base");
46  gSystem->Load("StChain");
47  gSystem->Load("StIOMaker");
48  gSystem->Load("libglobal_Tables");
49 
50 // Setup top part of chain
51  chain = new StChain("bfc");
52  chain->SetDebug();
53 
54  StIOMaker *IOMk = new StIOMaker("IO","r",MainFile,"bfcTree");
55  IOMk->SetDebug();
56  IOMk->SetIOMode("r");
57  IOMk->SetBranch("*",0,"0"); //deactivate all branches
58  IOMk->SetBranch("histBranch",0,"r"); //activate hist Branch
59 
60 // --- now execute chain member functions
61  chain->Init();
62 
63  TDataSet *ds=0;
64  TDataSet *obj=0;
65 
66  int istat=0;
67  int i=0;
68  int countev=0;
69  int countevhds=0;
70 
71 // Event loop
72 EventLoop: if (i < nevents && !istat) {
73 
74  chain->Clear();
75  istat = chain->Make(i);
76 
77 // count # times Make is called
78  i++;
79 
80 // Now look at the data in the event:
81  int countObj=0;
82  int countHist=0;
83 
84  if (!istat) {
85 
86  countev++;
87 
88  cout << " start event # " << countev << endl;
89 
90  ds=chain->GetDataSet("hist");
91  TDataSetIter tabiter(ds);
92  if (ds) {
93 
94  countevhds++;
95 
96  TDataSetIter nextHistList(ds);
97  St_ObjectSet *histContainer = 0;
98  TList *dirList = 0;
99 
100 // loop over directories:
101  while (histContainer = (St_ObjectSet *)nextHistList()) {
102  dirList = (TList *) histContainer->GetObject();
103 
104  cout << " QAInfo: found directory: " <<
105  histContainer->GetName() << endl;
106  fout << " QAInfo: found directory: " <<
107  histContainer->GetName() << endl;
108 
109  countObj++;
110 
111 // Notes for future reference (if we want to generalize this...)
112 // dirList is returned 0 for non-histogram file
113 // in that case, use GetList instead of GetObject
114 
115  TIter nextHist(dirList);
116  TObject *o = 0;
117 
118 // loop over histograms in the directory:
119  while (o= nextHist()) {
120  countHist++;
121  cout << " QAInfo: Hist name: " << o->GetName() <<
122  " ==> Title: " << o->GetTitle() << endl;
123  fout << " QAInfo: Hist name: " << o->GetName() <<
124  " ==> Title: " << o->GetTitle() << endl;
125 
126  } // nextHist
127  } // histContainer
128  } // ds
129 
130  cout << " QAInfo: event # " << countev
131  << ", # directories found = " << countObj
132  << ", # hist found = " << countHist
133  << endl << endl;
134 
135 
136  fout << " QAInfo: event # " << countev
137  << ", # directories found = " << countObj
138  << ", # hist found = " << countHist
139  << endl << endl;
140 
141 
142  } // istat
143 
144  else // if (istat)
145  {
146  cout << "Last event processed. Status = " << istat << endl;
147  }
148 
149 
150  goto EventLoop;
151 } //EventLoop
152 
153  cout << endl;
154  cout << "QAInfo: End of Job " << endl;
155  cout << "QAInfo: # times Make called = " << i << endl;
156  cout << "QAInfo: # events read = " << countev << endl;
157  cout << "QAInfo: # events with hist dataset = " << countevhds << endl;
158 
159  fout << endl;
160  fout << "QAInfo: End of Job " << endl;
161  fout << "QAInfo: # times Make called = " << i << endl;
162  fout << "QAInfo: # events read = " << countev << endl;
163  fout << "QAInfo: # events with hist dataset = " << countevhds << endl;
164 
165  chain->Finish();
166 }
167 
168 
169 
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 Int_t Make()
Definition: StChain.cxx:110
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
Definition: TObjectSet.h:56