00001
00002
00003
00004
00006 #include "iostream.h"
00007
00008
00009 class StChain;
00010 StChain *chain=0;
00011
00012
00013
00014
00015 void doCopy(Int_t startEvent, Int_t nEvents,
00016 const Char_t *file,
00017 const Char_t *dirout = "QWE.dir");
00018
00019
00020
00021
00022 "void doCopy(Int_t startEvent, Int_t nEvents,
00023 const Char_t *file,
00024 const Char_t *dirout)
00025 {
00026 if (!dirout || !dirout[0]) dirout = "QWE.dir";
00027 const char *cwd = gSystem->WorkingDirectory();
00028
00029 if (strcmp(dirout,"./")==0 || strcmp(dirout,cwd)==0)
00030 { //Not allowed
00031 printf("doCopy: ERROR *** current dir not allowed for dirout ***");
00032 return;
00033 }
00034 gSystem->MakeDirectory(dirout);
00035
00036 cout << endl << endl <<" doCopy - input # events = " << nEvents << endl;
00037 Int_t ilist=0;
00038 cout << " doCopy - input file = " << file << endl;
00039 cout << " doCopy - ouput dir = " << dirout << endl;
00040
00041 //
00042 // First load some shared libraries we need
00043 //
00044
00045 gSystem->Load("St_base");
00046 gSystem->Load("StChain");
00047
00048 gSystem->Load("libgen_Tables");
00049 gSystem->Load("libsim_Tables");
00050 gSystem->Load("libglobal_Tables");
00051
00052 gSystem->Load("StUtilities");
00053 gSystem->Load("StIOMaker");
00054 gSystem->Load("StTreeMaker");
00055 gSystem->Load("StarClassLibrary");
00056 gSystem->Load("StEvent");
00057
00058 //
00059 // Handling depends on whether file is a ROOT file or XDF file
00060 //
00061 chain = new StChain("StChain");
00062 StFileI *setFiles =0;
00063 char *fileList[2];
00064 fileList[0] = file; fileList[1]=0;
00065
00066 setFiles= new StFile(fileList);
00067
00068
00069 StIOMaker *IOMk = new StIOMaker("IO","r",setFiles,"bfcTree");
00070 IOMk->SetIOMode("r");
00071 IOMk->SetBranch("dstBranch" ,0,"r");
00072 IOMk->SetBranch("geantBranch" ,0,"r");
00073 IOMk->SetBranch("histBranch" ,0,"r");
00074 IOMk->SetBranch("runcoBranch" ,0,"r");
00075 IOMk->SetBranch("eventBranch" ,0,"r");
00076 IOMk->SetDebug();
00077 if (startEvent>1) IOMk->Skip(startEvent-1);
00078
00079 // WriteOut
00080 TString basename = gSystem->BaseName(file);
00081 basename.ReplaceAll(".root","");
00082 char *outName = gSystem->ConcatFileName(dirout,basename);
00083
00084
00085 StTreeMaker *outMk = new StTreeMaker("EvOut",outName,"bfcTree");
00086 outMk->SetIOMode("w");
00087 outMk->IntoBranch("eventBranch","StEvent");
00088 outMk->IntoBranch("dstBranch" ,"dst");
00089 outMk->IntoBranch("histBranch" ,"hist");
00090 outMk->IntoBranch("runcoBranch","runco");
00091 outMk->IntoBranch("geantBranch","geant");
00092 outMk->SetDebug();
00093
00094 //
00095 // Initialize chain
00096 //
00097 Int_t iInit = chain->Init();
00098 if (iInit) chain->Fatal(iInit,"on init");
00099 chain->PrintInfo();
00100
00101
00102
00103 //
00104 // Event loop
00105 //
00106 int istat=0,i=1;
00107 EventLoop: if (i <= nEvents && istat!=2) {
00108
00109 cout << endl << "============================ Event " << i
00110 << " start ============================" << endl;
00111
00112 chain->Clear();
00113 istat = chain->Make(i);
00114
00115 if (istat==2)
00116 {cout << "Last event processed. Status = " << istat << endl; break;}
00117 if (istat==3)
00118 {cout << "Error event processed. Status = " << istat << endl;}
00119
00120 i++;
00121 goto EventLoop;
00122 }
00123
00124 i--;
00125 cout << endl << "============================ Event " << i
00126 << " finish ============================" << endl;
00127
00128 }