StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
doCopy.C
1 //
3 // $Id: doCopy.C,v 1.2 2011/07/19 20:11:25 perev Exp $
4 //
6 #include "iostream.h"
7 
8 
9 class StChain;
10 StChain *chain=0;
11 
12 
13 // ProtoTypes
14 
15 void doCopy(Int_t startEvent, Int_t nEvents,
16  const Char_t *file,
17  const Char_t *dirout = "QWE.dir");
18 
19 
20 // ------------------ Here is the actual method -----------------------------------------
21 
22 "void doCopy(Int_t startEvent, Int_t nEvents,
23  const Char_t *file,
24  const Char_t *dirout)
25 {
26  if (!dirout || !dirout[0]) dirout = "QWE.dir";
27  const char *cwd = gSystem->WorkingDirectory();
28 
29  if (strcmp(dirout,"./")==0 || strcmp(dirout,cwd)==0)
30  { //Not allowed
31  printf("doCopy: ERROR *** current dir not allowed for dirout ***");
32  return;
33  }
34  gSystem->MakeDirectory(dirout);
35 
36  cout << endl << endl <<" doCopy - input # events = " << nEvents << endl;
37  Int_t ilist=0;
38  cout << " doCopy - input file = " << file << endl;
39  cout << " doCopy - ouput dir = " << dirout << endl;
40 
41  //
42  // First load some shared libraries we need
43  //
44 
45  gSystem->Load("St_base");
46  gSystem->Load("StChain");
47 
48  gSystem->Load("libgen_Tables");
49  gSystem->Load("libsim_Tables");
50  gSystem->Load("libglobal_Tables");
51 
52  gSystem->Load("StUtilities");
53  gSystem->Load("StIOMaker");
54  gSystem->Load("StTreeMaker");
55  gSystem->Load("StarClassLibrary");
56  gSystem->Load("StEvent");
57 
58  //
59  // Handling depends on whether file is a ROOT file or XDF file
60  //
61  chain = new StChain("StChain");
62  StFileI *setFiles =0;
63  char *fileList[2];
64  fileList[0] = file; fileList[1]=0;
65 
66  setFiles= new StFile(fileList);
67 
68 
69  StIOMaker *IOMk = new StIOMaker("IO","r",setFiles,"bfcTree");
70  IOMk->SetIOMode("r");
71  IOMk->SetBranch("dstBranch" ,0,"r");
72  IOMk->SetBranch("geantBranch" ,0,"r");
73  IOMk->SetBranch("histBranch" ,0,"r");
74  IOMk->SetBranch("runcoBranch" ,0,"r");
75  IOMk->SetBranch("eventBranch" ,0,"r");
76  IOMk->SetDebug();
77  if (startEvent>1) IOMk->Skip(startEvent-1);
78 
79  // WriteOut
80  TString basename = gSystem->BaseName(file);
81  basename.ReplaceAll(".root","");
82  char *outName = gSystem->ConcatFileName(dirout,basename);
83 
84 
85  StTreeMaker *outMk = new StTreeMaker("EvOut",outName,"bfcTree");
86  outMk->SetIOMode("w");
87  outMk->IntoBranch("eventBranch","StEvent");
88  outMk->IntoBranch("dstBranch" ,"dst");
89  outMk->IntoBranch("histBranch" ,"hist");
90  outMk->IntoBranch("runcoBranch","runco");
91  outMk->IntoBranch("geantBranch","geant");
92  outMk->SetDebug();
93 
94  //
95  // Initialize chain
96  //
97  Int_t iInit = chain->Init();
98  if (iInit) chain->Fatal(iInit,"on init");
99  chain->PrintInfo();
100 
101 
102 
103  //
104  // Event loop
105  //
106  int istat=0,i=1;
107  EventLoop: if (i <= nEvents && istat!=2) {
108 
109  cout << endl << "============================ Event " << i
110  << " start ============================" << endl;
111 
112  chain->Clear();
113  istat = chain->Make(i);
114 
115  if (istat==2)
116  {cout << "Last event processed. Status = " << istat << endl; break;}
117  if (istat==3)
118  {cout << "Error event processed. Status = " << istat << endl;}
119 
120  i++;
121  goto EventLoop;
122  }
123 
124  i--;
125  cout << endl << "============================ Event " << i
126  << " finish ============================" << endl;
127 
128 }
Definition: FJcore.h:367
Definition: IO.h:20
virtual TDataSet * Last() const
Return the last object in the list. Returns 0 when list is empty.
Definition: TDataSet.cxx:437
Definition: AgUStep.h:26