2 // Macro to create the "raw" data file with selected events
\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
7 // TGrid * alien = TGrid::Connect("alien://",0,0,"t");
\r
9 void rawmerge(const char *eventListFileName,
\r
10 const char *outputDirectoryURI,
\r
13 TGrid * alien = TGrid::Connect("alien://",0,0,"t");
\r
16 FILE *files=fopen(eventListFileName,"r");
\r
18 fprintf(stderr,"error: could not read event list file \"%s\". Exiting.\n",eventListFileName);
\r
30 Int_t ofilenumber=0;
\r
33 while (!feof(files)) {
\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
39 printf("> processing \"%s\" event %d...\n",iURI,ievent);
\r
40 if (ievent==eventold) { printf("duplicated continue\n"),continue;}
\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
47 fprintf(stderr,"warning: could not open file for event \"%s\", skipping it...\n",iURI);
\r
52 printf("OF: %s\n",iURI);
\r
56 TTree *itree=dynamic_cast<TTree*>(ifile->Get("RAW"));
\r
58 fprintf(stderr,"warning: could not find RAW tree for event \"%s\", skipping it...\n",iURI);
\r
62 // create (new) output file and tree
\r
63 if (!ofile || (osplit>0 && oevent%osplit==0)) {
\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
70 fprintf(stderr,"error: could not create output file: \"%s\" Exiting.\n",oURI);
\r
73 otree=itree->CloneTree(0);
\r
75 // copy event and write to file
\r
76 otree->CopyAddresses(itree);
\r
77 if (ievent==eventold) continue;
\r
78 itree->GetEntry(ievent);
\r
81 // otree->CopyEntries(itree,Form("Entry$==%d",ievent),1);
\r
86 itree->ResetBranchAddresses();
\r
89 printf("Merged %d events.\n",oevent);
\r