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