2 // Macro to create the "raw" data file with selected events
4 void rawmerge( TString inputFileName="wn.xml",
5 TString fullEventListFileName="event.list",
6 TString outputFileNameTMP="filtered.root")
8 // Create the filtered raw data files using a file with list of raw chunks with event numbers.
9 // inputFileName - either the text file with chunkname+event number+triggerType or
11 // fullEventListFileName - if 1st arg is an xml collection, this is the full list of
12 // chunks and events to be filtered acoording the xml contents
14 // format of the event list: /path/to/chunk eventNumber offlineTriggerType
16 // e.g. /alice/data/2013/LHC13b/000195390/raw/13000195390000.10.root 218 V0s
17 // /alice/data/2013/LHC13b/000195390/raw/13000195390000.10.root 219 highPt
18 // /alice/data/2013/LHC13b/000195390/raw/13000195390000.10.root 246 V0s
20 // triggerType can be: highPt, V0s, CosmicPairs, Laser
23 // if the file list is an xml collection (for running on alien),
24 // first extract the available chunks and event numbers from the
25 // reference file, and use that as input
26 if (inputFileName.Contains(".xml"))
28 TString tmp=inputFileName+".list";
29 makeAlienInputEventList(tmp,fullEventListFileName,inputFileName);
33 TGrid * alien = TGrid::Connect("alien://",0,0,"t");
37 files.open(inputFileName.Data());
40 fprintf(stderr,"error: could not read event list file \"%s\". Exiting.\n",inputFileName.Data());
44 //TSeqCollection* listOfFiles = (TSeqCollection*)gROOT->GetListOfFiles();
45 TList* listOfFiles = new TList();
46 TString outputFileName;
63 //read the line, do some checks
65 TObjArray* entries = line.Tokenize(" ");
66 TObjString* iURIobjstr = (TObjString*)entries->At(0);
68 if (iURIobjstr) iURI=iURIobjstr->String();
69 TObjString* ieventobjstr = (TObjString*)entries->At(1);
70 if (ieventobjstr) ievent = ieventobjstr->String().Atoi();
71 if (iURI.IsNull() || !ieventobjstr)
73 printf("malformed line: %s, skipping...\n",line.Data());
76 TObjString* triggerTypeobjstr = (TObjString*)entries->At(2);
78 if (triggerTypeobjstr) triggerType=triggerTypeobjstr->String();
80 printf("> processing \"%s\" event %d trigger \"%s\"...\n",iURI.Data(),ievent,triggerType.Data());
81 if (ievent==eventold && iURI==iURIold)
83 printf("duplicated continue\n");
87 if (!iURIold.Contains(iURI.Data()))
89 //if a new file - open it
90 printf("new file: %s\n",iURI.Data());
93 ifile=TFile::Open(iURI.Data());
96 fprintf(stderr,"warning: could not open file for event \"%s\", skipping it...\n",iURI.Data());
102 //if same file, reuse it
103 printf("using already open file: %s\n",iURI.Data());
107 TTree *itree=dynamic_cast<TTree*>(ifile->Get("RAW"));
110 fprintf(stderr,"warning: could not find RAW tree for event \"%s\", skipping it...\n",iURI.Data());
114 // manage output files
115 if (!triggerType.IsNull()) triggerType.Prepend("_");
116 outputFileName=outputFileNameTMP;
117 outputFileName.ReplaceAll(".root","");
118 outputFileName+=triggerType;
119 outputFileName+=".root";
121 ofile=dynamic_cast<TFile*>(listOfFiles->FindObject(outputFileName.Data()));
124 printf("< creating output file \"%s\"\n",outputFileName.Data());
125 ofile=TFile::Open(outputFileName,"recreate");
128 fprintf(stderr,"error: could not create output file: \"%s\" Exiting.\n",outputFileName.Data());
131 listOfFiles->Add(ofile);
134 otree=dynamic_cast<TTree*>(ofile->Get("RAW"));
137 otree=itree->CloneTree(0);
140 otree->CopyAddresses(itree);
141 itree->GetEntry(ievent);
143 printf("filling event %i in file %s\n",ievent,ofile->GetName());
145 //otree->CopyEntries(itree,Form("Entry$==%d",ievent),1);
148 itree->ResetBranchAddresses();
152 for (Int_t i=0; i<listOfFiles->GetEntries(); i++)
154 ofile=dynamic_cast<TFile*>(listOfFiles->At(i));
155 if (!ofile) {continue;}
156 otree=dynamic_cast<TTree*>(ofile->Get("RAW"));
158 if (otree) { nEntries = otree->GetEntries(); }
160 //write the file and close
162 printf("closing file: %s with %i entries\n",ofile->GetName(),nEntries);
168 gSystem->Unlink(ofile->GetName());
173 Bool_t makeAlienInputEventList( TString outputFileName="wn.list",
174 TString referenceFileName="filteredEvents.list",
175 TString inputCollectionName="wn.xml" )
177 TAlienCollection *coll = TAlienCollection::Open(inputCollectionName);
180 ::Error("makeAlienInputEventList", "Cannot open collection from %s", xmlfile);
186 ifstream referenceFile;
187 referenceFile.open(referenceFileName.Data());
188 if (!referenceFile.is_open())
190 printf("could not open %s\n",referenceFileName.Data());
193 gSystem->Unlink(outputFileName);
195 outputFile.open(outputFileName.Data());
196 if (!outputFile.is_open())
198 printf("could not open %s\n",referenceFileName.Data());
204 chunkPath = coll->GetTURL();
205 TObjArray* a = chunkPath.Tokenize("/");
206 TObjString* objstr = dynamic_cast<TObjString*>(a->At(a->GetEntries()-1));
209 printf("empty chunkPath from collection!\n");
212 TString chunkName = objstr->String();
213 chunkName.ReplaceAll("alien://","");
214 while (referenceFile.good())
216 configLine.ReadLine(referenceFile);
217 if (configLine.Contains(chunkName))
219 configLine=configLine.Strip(TString::kBoth);
220 if (!configLine.BeginsWith("alien://"))
222 configLine.Prepend("alien://");
224 outputFile << configLine << endl;
225 cout << configLine << endl;
228 //jump to beginning and clear flags
229 referenceFile.clear();
230 referenceFile.seekg(0,ios::beg);
233 referenceFile.close();