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