]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGPP/macros/rawmerge.C
Attempt to monitor what file is read and merged by what job
[u/mrichter/AliRoot.git] / PWGPP / macros / rawmerge.C
CommitLineData
1535e362 1//\r
2// Macro to create the "raw" data file with selected events\r
3// Paramaters:\r
4// eventListFileName - input ascii file with list of chunks and event numbers - two collumns\r
5// osplit - split the file after given threhshold value\r
6//\r
3dc94049 7// TGrid * alien = TGrid::Connect("alien://",0,0,"t");\r
8\r
1535e362 9void rawmerge(const char *eventListFileName,\r
10 const char *outputDirectoryURI,\r
11 Long64_t osplit=-1)\r
12{\r
3dc94049 13 TGrid * alien = TGrid::Connect("alien://",0,0,"t");\r
14 \r
1535e362 15 Int_t eventNumber;\r
16 FILE *files=fopen(eventListFileName,"r");\r
17 if (!files) {\r
18 fprintf(stderr,"error: could not read event list file \"%s\". Exiting.\n",eventListFileName);\r
19 return;\r
20 }\r
21 char iURI[1000];\r
3dc94049 22 TString iURIold;\r
1535e362 23 char oURI[1000];\r
24 TFile *ifile=0;\r
25 TFile *ofile=0;\r
26 TTree *itree=0;\r
27 TTree *otree=0;\r
28 Long64_t ievent;\r
29 Long64_t oevent;\r
30 Int_t ofilenumber=0;\r
31 Int_t line=0;\r
3dc94049 32 Int_t eventold=0;\r
1535e362 33 while (!feof(files)) {\r
1535e362 34 ++line;\r
35 if (fscanf(files,"%s %d\n",iURI,&ievent)!=2) {\r
36 fprintf(stderr,"warning: corrupted event line (%d) in input file, skipping it...\n",line);\r
37 continue;\r
3dc94049 38 } \r
1535e362 39 printf("> processing \"%s\" event %d...\n",iURI,ievent);\r
3dc94049 40 if (ievent==eventold) { printf("duplicated continue\n"),continue;}\r
41 //\r
42 if (iURIold.Contains(iURI)==0){ \r
43 printf("NF: %s\n",iURI);\r
44 delete ifile;ifile=0;\r
45 ifile=TFile::Open(iURI);\r
46 if (!ifile) {\r
47 fprintf(stderr,"warning: could not open file for event \"%s\", skipping it...\n",iURI);\r
48 continue;\r
49 }\r
50 iURIold=iURI;\r
51 }else{\r
52 printf("OF: %s\n",iURI);\r
53 iURIold=iURI; \r
1535e362 54 }\r
3dc94049 55 //\r
1535e362 56 TTree *itree=dynamic_cast<TTree*>(ifile->Get("RAW"));\r
57 if (!itree) {\r
58 fprintf(stderr,"warning: could not find RAW tree for event \"%s\", skipping it...\n",iURI);\r
59 continue;\r
60 }\r
61\r
62 // create (new) output file and tree\r
63 if (!ofile || (osplit>0 && oevent%osplit==0)) {\r
64 delete ofile;\r
65 ++ofilenumber;\r
66 sprintf(oURI,"%s/merged_%d.root",outputDirectoryURI,ofilenumber);\r
67 printf("< creating output file \"%s\"\n",oURI);\r
68 ofile=TFile::Open(oURI,"RECREATE");\r
69 if (!ofile) {\r
70 fprintf(stderr,"error: could not create output file: \"%s\" Exiting.\n",oURI);\r
71 break;\r
72 }\r
73 otree=itree->CloneTree(0);\r
74 }\r
1535e362 75 // copy event and write to file\r
76 otree->CopyAddresses(itree);\r
3dc94049 77 if (ievent==eventold) continue;\r
1535e362 78 itree->GetEntry(ievent);\r
3dc94049 79 eventold=ievent; \r
1535e362 80 otree->Fill();\r
81// otree->CopyEntries(itree,Form("Entry$==%d",ievent),1);\r
82 ofile->Write();\r
83 ++oevent;\r
84\r
85 // reset input\r
86 itree->ResetBranchAddresses();\r
87 }\r
88\r
89 printf("Merged %d events.\n",oevent);\r
90 delete ifile;\r
91 delete ofile;\r
92}\r
93\r