StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
doHists.C
1 //
3 // $Id: doHists.C,v 3.4 2006/08/15 21:42:44 jeromel Exp $
4 //
5 // Description:
6 // Chain to read production histgrams from files or database and acculuate it across all files read
7 // what it does: reads .hist.root then runs StHistCollectorMaker
8 // to merge the valus if all similar histograms
9 //
10 // Environment:
11 // Software developed for the STAR Detector at Brookhaven National Laboratory
12 //
13 // Ways to run:
14 // If you specify a path, all DST files below that path will be
15 // found, and the first 'nevents' events in the file set will be
16 // analyzed.
17 // The type of DST files searched for is taken from the 'file' parameter.
18 // If 'file ends in '.hist.root', ROOT histBranch 'es of the STAR bfc.C production
19 // are searched for.
20 //
21 // If path begins with '-', 'file' will be taken to be a single file
22 // to be processed.
23 //
24 // example ROOT file invocation:
25 // .x doHists.C(10,"-","some_directory/some_hist_file.root")
26 //
27 // example multi-ROOT file invocation:
28 // .x doHists.C(9999,"some_directory","*.hist.root")
29 //
31 //
32 // Author: Valeri Fine, BNL 11/2000
33 // (This macro based on doEvents.C by Torre Wenaus and Victor Perevoztchikov)
34 //
35 // inputs:
36 // nevents = # events to process
37 // path = a. directory you want files from
38 // b. "-" to get just the one file you want
39 // file = a. file names in directory (takes all files)
40 // b. the 1 particular full file name (with directory) you want
41 // qaflag = "off" - doesn't do anything now
42 // wrStEOut = flag to turn on=1, off=0 writing of output test.event.root
43 // file --- set to off by default
44 //
46 
47 Int_t usePath = 0;
48 Int_t nFile = 0;
49 TString thePath;
50 TString theFileName;
51 TString originalPath;
52 class StChain;
53 StChain *chain=0;
54 class StEventDisplayMaker;
55 StEventDisplayMaker *dsMaker = 0;
56 TBrowser *b=0;
57 
58 const char *dstFile = 0;
59 const char *xdfFile = 0;
60 const char *mdcFile = 0;
61 const char *fileList[] = {dstFile,xdfFile,mdcFile,0};
62 
63 void Help()
64 {
65  cout << "Usage: doHists.C(nevents,\"-\",\"some_directory/some_dst_file.xdf\")" << endl;
66  cout << " doHists.C(nevents,\"-\",\"some_directory/some_dst_file.root\")" << endl;
67  cout << " doHists.C(nevents,\"some_directory\",\"*.dst.root\")" << endl;
68 }
69 
70 
71 void doHists(Int_t, const Char_t **, const Char_t *qaflag = "");
72 
73 void doHists(Int_t nevents=2,
74  const Char_t *path="/afs/rhic.bnl.gov/star/data/samples/gstar.hist.root",
75  const Char_t *file="",
76  const Char_t *qaflag = "off",
77  const Int_t wrStEOut = 0);
78 
79 // ------------------ Here is the actual method -----------------------------------------
80 void doHists(Int_t nevents, const Char_t **fileList, const Char_t *qaflag, const Int_t wrStEOut)
81 {
82 
83  cout << endl << endl <<" doHists - input # events = " << nevents << endl;
84  Int_t ilist=0;
85  while(fileList[ilist]){
86  cout << " doHists - input fileList = " << fileList[ilist] << endl;
87  ilist++;
88  }
89  cout << " doHists - input qaflag = " << qaflag << endl;
90  cout << " doHists - input wrStEOut = " << wrStEOut << endl << endl << endl;
91 
92  //
93  // First load some shared libraries we need
94  //
95 
96  gSystem->Load("St_base");
97  gSystem->Load("StChain");
98 
99  gSystem->Load("libgen_Tables");
100  gSystem->Load("libsim_Tables");
101  gSystem->Load("libglobal_Tables");
102 
103  gSystem->Load("StUtilities");
104  gSystem->Load("StIOMaker");
105  gSystem->Load("StTreeMaker");
106  gSystem->Load("StAnalysisUtilities");
107 
108  //
109  // Handling depends on whether file is a ROOT file or XDF file
110  //
111  chain = new StChain("StChain");
112  StFileI *setFiles =0;
113  if (fileList) { //Normal case
114  setFiles= new StFile(fileList);
115  } else { //Grand Challenge
116  gSystem->Load("StChallenger");
117  setFiles = StChallenger::Challenge();
118  setFiles->SetDebug();
119  const char *Argv[]= {
120  "-s","dst runco", // list of components needed
121  "-q","numberOfPrimaryTracks>1500", // example of user query
122  "-c","/afs/rhic.bnl.gov/star/incoming/GCA/daq/stacs.rc" // pointer to GC servers for daq
123  };
124  Int_t Argc=sizeof(Argv)/4;
125  setFiles->Init(Argc,Argv);
126  }
127  StIOMaker *IOMk = new StIOMaker("IO","r",setFiles,"bfcTree");
128  IOMk->SetIOMode("r");
129  IOMk->SetBranch("*",0,"0"); //deactivate all branches
130  IOMk->SetBranch("histBranch",0,"r");
131  IOMk->SetMaxEvent(1);
132  IOMk->SetDebug();
133 
134  //
135  // Maker to read events from file or database into StEvent
136  //
137 
138 
139  //
140 
141  //
142  // Sample analysis maker
143  //
144  StHistCollectorMaker *histsMaker = new StHistCollectorMaker("merged");
145 
146  // WriteOut Hist Merged
147  if (wrStEOut) {
148  cout << "!!!! doHists: will write out .event.root file !!" << endl << endl;
149  StTreeMaker *outMk = new StTreeMaker("mergeOut","","mergeTree");
150  outMk->SetIOMode ("w");
151  outMk->SetBranch ("mergeBranch","test.merge.root","w","const");
152  outMk->IntoBranch("mergeBranch","Merged");
153  }
154  //
155  // Initialize chain
156  //
157  Int_t iInit = chain->Init();
158  if (iInit) chain->Fatal(iInit,"on init");
159  chain->PrintInfo();
160 
161 
162  //
163  // Event loop
164  //
165  int istat=0,i=1;
166  EventLoop: if (i <= nevents && istat!=2) {
167 
168  cout << endl << "============================ Event " << i
169  << " start ============================" << endl;
170 
171  chain->Clear();
172  istat = chain->Make(i);
173 
174  if (istat==2)
175  {cout << "Last event processed. Status = " << istat << endl;}
176  if (istat==3)
177  {cout << "Error event processed. Status = " << istat << endl;}
178  i++;
179  goto EventLoop;
180  }
181 
182  i--;
183  cout << endl << "============================ Event " << i
184  << " finish ============================" << endl;
185  new TBrowser("AccumulatedHistograms",histsMaker->FindByName(".const"));
186 
187 }
188 
189 //--------------------------------------------------------------------------
190 
191 void doHists(const Int_t nevents, const Char_t *path, const Char_t *file,
192  const Char_t *qaflag, const Int_t wrStEOut)
193 {
194  if (nevents==-1) { Help(); return;}
195  const char *fileListQQ[]={0,0};
196  if (strncmp(path,"GC",2)==0) {
197  fileListQQ=0;
198  } else if (path[0]=='-') {
199  fileListQQ[0]=file;
200  } else if (!file[0]) {
201  fileListQQ[0]=path;
202  } else {
203  fileListQQ[0] = gSystem->ConcatFileName(path,file);
204  }
205  doHists(nevents,fileListQQ,qaflag,wrStEOut);
206 }
207 
209 //
210 // $Log: doHists.C,v $
211 // Revision 3.4 2006/08/15 21:42:44 jeromel
212 // Fix rhic -> rhic.bnl.gov
213 //
214 // Revision 3.3 2001/02/14 18:19:36 perev
215 // add write mode
216 //
217 // Revision 3.2 2000/12/12 23:11:05 perev
218 // Add write of merged histos
219 //
220 // Revision 3.1 2000/11/30 19:35:13 fine
221 // New analysis utility to collect all histogram from all histBranh production branches
222 //
224 
225 
226 
227 
228 
229 
Definition: StTree.h:125
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 Make()
Definition: StChain.cxx:110
virtual TDataSet * FindByName(const char *name, const char *path="", Option_t *opt="") const
Definition: TDataSet.cxx:378