StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
doEvents.C
1 //
3 // $Id: doEvents.C,v 1.1 2002/04/02 20:51:16 jklay Exp $
4 //
5 // Description:
6 // Chain to read events from files or database into StEvent and analyze.
7 // what it does: reads .dst.root or .xdf files and then runs StEventMaker
8 // to fill StEvent and StAnalysisMaker to show example of analysis
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 '.dst.root', ROOT DSTs are searched for.
19 // If 'file ends in '.xdf', XDF DSTs 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 invocation:
25 // .x doEvents.C(10,"-","some_directory/some_dst_file.xdf")
26 //
27 // example ROOT file invocation:
28 // .x doEvents.C(10,"-","some_directory/some_dst_file.root")
29 //
30 // example multi-ROOT file invocation:
31 // .x doEvents.C(9999,"some_directory","*.dst.root")
32 //
34 //
35 // Author List: Torre Wenaus, BNL 2/99
36 // Victor Perevoztchikov
37 //
38 // inputs:
39 // nevents = # events to process
40 // path = a. directory you want files from
41 // b. "-" to get just the one file you want
42 // file = a. file names in directory (takes all files)
43 // b. the 1 particular full file name (with directory) you want
44 // qaflag = "off" - doesn't do anything now
45 // wrStEOut = flag to turn on=1, off=0 writing of output test.event.root
46 // file --- set to off by default
47 //
49 Int_t debug=1;
50 Int_t doIt=1; //Yes, Store HITS!
51 Int_t usePath = 0;
52 Int_t nFile = 0;
53 TString thePath;
54 TString theFileName;
55 TString originalPath;
56 class StChain;
57 StChain *chain=0;
58 class StEventDisplayMaker;
59 StEventDisplayMaker *dsMaker = 0;
60 TBrowser *b=0;
61 
62 const char *dstFile = 0;
63 const char *xdfFile = 0;
64 const char *mdcFile = 0;
65 const char *fileList[] = {dstFile,xdfFile,mdcFile,0};
66 
67 void Help()
68 {
69  cout << "Usage: doEvents.C(nevents,\"-\",\"some_directory/some_dst_file.xdf\")" << endl;
70  cout << " doEvents.C(nevents,\"-\",\"some_directory/some_dst_file.root\")" << endl;
71  cout << " doEvents.C(nevents,\"some_directory\",\"*.dst.root\")" << endl;
72 }
73 
74 
75 void doEvents(Int_t, const Char_t **, const Char_t *qaflag = "");
76 
77 void doEvents(Int_t nevents=5,
78  const Char_t *path=
79  "links/P02gc.productionCentral.FullField.2001.313.dst/",
80  const Char_t *file=
81  "st_physics_2313048_raw_0237.event.root",
82  const Char_t* outDir = "./",
83  const Char_t *qaflag = "off",
84  const Int_t wrStEOut = 0);
85 
86 // ------------------ Here is the actual method -----------------------------------------
87 void doEvents(Int_t nevents, const Char_t **fileList,const Char_t* outDir,
88  const Char_t *qaflag, const Int_t wrStEOut)
89 {
90 
91  cout << endl << endl <<" doEvents - input # events = " << nevents << endl;
92  Int_t ilist=0;
93  while(fileList[ilist]){
94  cout << " doEvents - input fileList = " << fileList[ilist] << endl;
95  ilist++;
96  }
97  cout << " doEvents - input qaflag = " << qaflag << endl;
98  cout << " doEvents - input wrStEOut = " << wrStEOut << endl << endl << endl;
99 
100  //
101  // First load some shared libraries we need
102  //
103 
104  gSystem->Load("St_base");
105  gSystem->Load("StChain");
106  // gSystem->Load("St_Tables");
107 
108  gSystem->Load("libgen_Tables");
109  gSystem->Load("libsim_Tables");
110  gSystem->Load("libglobal_Tables");
111 
112  gSystem->Load("StUtilities");
113  gSystem->Load("StarClassLibrary");
114 
115  gSystem->Load("StTpcDb");
116  gSystem->Load("StEvent");
117  gSystem->Load("StEventMaker");
118 
119  gSystem->Load("StIOMaker");
120  gSystem->Load("StHiMicroEvent");
121  gSystem->Load("StHiMicroMaker");
122 
123  // create a new instance of the chain
124  chain = new StChain("StChain");
125  chain->SetDebug();
126 
127  StFileI *setFiles = new StFile(fileList);
128 
129  TString mainBranch;
130  if(fileList && fileList[0] && strstr(fileList[0],".root")){
131  mainBranch = fileList[0];
132  mainBranch.ReplaceAll(".root","");
133  int idot = strrchr((char*)mainBranch,'.') - mainBranch.Data();
134  mainBranch.Replace(0,idot+1,"");
135  mainBranch+="Branch";
136  }
137 
138 
139  StIOMaker* ioMaker = new StIOMaker("IO","r",setFiles,"bfcTree");
140  cout << "\t created" << endl;
141  ioMaker->SetDebug();
142  ioMaker->SetIOMode("r");
143  ioMaker->SetBranch("*",0,"0"); //deactivate all branches
144  // ioMaker->SetBranch("geantBranch",0,"r"); //activate geant Branch
145  // ioMaker->SetBranch("dstBranch",0,"r"); //activate Event Branch
146  // ioMaker->SetBranch("runcoBranch",0,"r"); //activate runcoBranch
147  if(!mainBranch.IsNull()) ioMaker->SetBranch(mainBranch,0,"r");
148 
149  if(mainBranch=="dstBranch"){
150  cout << "Creating event.root" << endl;
151  StEventMaker* eventReader = new StEventMaker("events","title");
152  eventReader->doPrintEventInfo = 0;
153  }
154 
155  //
156  StHiMicroMaker* hiPt = new StHiMicroMaker;
157  hiPt->setOutDir(outDir);
158  hiPt->setDebug(debug);
159  hiPt->setHitLoop(doIt);
160 
161 
162  //
163  // Initialize chain
164  //
165 
166  Int_t iInit = chain->Init();
167  if (iInit) chain->Fatal(iInit,"on init");
168  chain->PrintInfo();
169 
170 
171  //
172  // Event loop
173  //
174  int istat=0,i=1;
175  EventLoop: if (i <= nevents && istat!=2) {
176 
177  cout << endl << "============================ Event " << i
178  << " start ============================" << endl;
179 
180  chain->Clear();
181  istat = chain->Make(i);
182 
183  if (istat==2)
184  {cout << "Last event processed. Status = " << istat << endl;}
185  if (istat==3)
186  {cout << "Error event processed. Status = " << istat << endl;}
187 
188 
189 //------------------
190 
191  i++;
192  goto EventLoop;
193  }
194 
195  i--;
196  cout << endl << "============================ Event " << i
197  << " finish ============================" << endl;
198 
199 }
200 
201 //--------------------------------------------------------------------------
202 
203 void doEvents(const Int_t nevents, const Char_t *path, const Char_t *file,
204  const Char_t *outDir,
205  const Char_t *qaflag, const Int_t wrStEOut)
206 {
207  if (nevents==-1) { Help(); return;}
208  const char *fileListQQ[]={0,0};
209  if (strncmp(path,"GC",2)==0) {
210  fileListQQ=0;
211  } else if (path[0]=='-') {
212  fileListQQ[0]=file;
213  } else if (!file[0]) {
214  fileListQQ[0]=path;
215  } else {
216  fileListQQ[0] = gSystem->ConcatFileName(path,file);
217  }
218  doEvents(nevents,fileListQQ,outDir,qaflag,wrStEOut);
219 }
220 
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