]>
Commit | Line | Data |
---|---|---|
b45e5084 | 1 | /************************************************************************** |
2 | * Author: Panos Christakoglou. * | |
3 | * Contributors are mentioned in the code where appropriate. * | |
4 | * * | |
5 | * Permission to use, copy, modify and distribute this software and its * | |
6 | * documentation strictly for non-commercial purposes is hereby granted * | |
7 | * without fee, provided that the above copyright notice appears in all * | |
8 | * copies and that both the copyright notice and this permission notice * | |
9 | * appear in the supporting documentation. The authors make no claims * | |
10 | * about the suitability of this software for any purpose. It is * | |
11 | * provided "as is" without express or implied warranty. * | |
12 | **************************************************************************/ | |
13 | ||
14 | /* $Id$ */ | |
15 | ||
16 | //----------------------------------------------------------------- | |
17 | // AliTagCreator class | |
18 | // This is the class to deal with the tag creation (post process) | |
19 | // Origin: Panos Christakoglou, UOA-CERN, Panos.Christakoglou@cern.ch | |
20 | //----------------------------------------------------------------- | |
21 | ||
22 | //ROOT | |
c336835b | 23 | #include <Riostream.h> |
b45e5084 | 24 | #include <TFile.h> |
25 | #include <TString.h> | |
cb1645b7 | 26 | #include <TTree.h> |
4fd84456 | 27 | #include <TSystem.h> |
28 | #include <TChain.h> | |
2bdb9d38 | 29 | #include <TLorentzVector.h> |
b45e5084 | 30 | |
31 | //ROOT-AliEn | |
32 | #include <TGrid.h> | |
b45e5084 | 33 | #include <TGridResult.h> |
b45e5084 | 34 | |
35 | //AliRoot | |
36 | #include "AliRunTag.h" | |
37 | #include "AliEventTag.h" | |
b45e5084 | 38 | #include "AliLog.h" |
39 | ||
b45e5084 | 40 | #include "AliTagCreator.h" |
41 | ||
42 | ||
43 | ClassImp(AliTagCreator) | |
44 | ||
45 | ||
46 | //______________________________________________________________________________ | |
442646f2 | 47 | AliTagCreator::AliTagCreator() : |
48 | TObject(), | |
b2dc099f | 49 | fSE("ALICE::CERN::se"), |
442646f2 | 50 | fgridpath(""), |
51 | fStorage(0) | |
52 | { | |
b45e5084 | 53 | //==============Default constructor for a AliTagCreator================== |
b45e5084 | 54 | } |
55 | ||
b45e5084 | 56 | //______________________________________________________________________________ |
c336835b | 57 | AliTagCreator::~AliTagCreator() { |
b45e5084 | 58 | //================Default destructor for a AliTagCreator======================= |
59 | } | |
60 | ||
28afeb2e | 61 | //______________________________________________________________________________ |
c336835b | 62 | void AliTagCreator::SetStorage(Int_t storage) { |
cb1645b7 | 63 | // Sets correctly the storage: 0 for local, 1 for GRID |
28afeb2e | 64 | fStorage = storage; |
65 | if(fStorage == 0) | |
66 | AliInfo(Form("Tags will be stored locally....")); | |
67 | if(fStorage == 1) | |
68 | AliInfo(Form("Tags will be stored in the grid....")); | |
69 | if((fStorage != 0)&&(fStorage != 1)) | |
70 | { | |
71 | AliInfo(Form("Storage was not properly set!!!")); | |
72 | abort(); | |
73 | } | |
74 | } | |
75 | ||
4fd84456 | 76 | //__________________________________________________________________________ |
5b8d5d69 | 77 | Bool_t AliTagCreator::MergeTags(const char *type) { |
4fd84456 | 78 | //Merges the tags and stores the merged tag file |
79 | //locally if fStorage=0 or in the grid if fStorage=1 | |
80 | AliInfo(Form("Merging tags.....")); | |
81 | TChain *fgChain = new TChain("T"); | |
5b8d5d69 | 82 | TString tagPattern = type; tagPattern += ".tag.root"; |
4fd84456 | 83 | |
84 | if(fStorage == 0) { | |
4fd84456 | 85 | // Open the working directory |
86 | void * dirp = gSystem->OpenDirectory(gSystem->pwd()); | |
87 | const char * name = 0x0; | |
88 | // Add all files matching *pattern* to the chain | |
89 | while((name = gSystem->GetDirEntry(dirp))) { | |
22c08f55 | 90 | if (strstr(name,tagPattern)) fgChain->Add(name); |
4fd84456 | 91 | }//directory loop |
73bbf779 | 92 | AliInfo(Form("Chained tag files: %lld",fgChain->GetEntries())); |
4fd84456 | 93 | }//local mode |
94 | ||
95 | else if(fStorage == 1) { | |
96 | TString alienLocation = gGrid->Pwd(); | |
97 | alienLocation += fgridpath.Data(); | |
98 | alienLocation += "/"; | |
5b8d5d69 | 99 | TString queryPattern = "*."; queryPattern += tagPattern; |
100 | TGridResult *tagresult = gGrid->Query(alienLocation,queryPattern.Data(),"",""); | |
4fd84456 | 101 | Int_t nEntries = tagresult->GetEntries(); |
102 | for(Int_t i = 0; i < nEntries; i++) { | |
103 | TString alienUrl = tagresult->GetKey(i,"turl"); | |
104 | fgChain->Add(alienUrl); | |
105 | }//grid result loop | |
73bbf779 | 106 | AliInfo(Form("Chained tag files: %lld",fgChain->GetEntries())); |
4fd84456 | 107 | }//grid mode |
108 | ||
109 | AliRunTag *tag = new AliRunTag; | |
4fd84456 | 110 | fgChain->SetBranchAddress("AliTAG",&tag); |
b2dc099f | 111 | fgChain->GetEntry(0); |
442646f2 | 112 | TString localFileName = "Run"; localFileName += tag->GetRunId(); |
5b8d5d69 | 113 | localFileName += ".Merged."; localFileName += tagPattern.Data(); |
442646f2 | 114 | |
9b4aee57 | 115 | TString filename; |
442646f2 | 116 | |
117 | if(fStorage == 0) { | |
118 | filename = localFileName.Data(); | |
119 | AliInfo(Form("Writing merged tags to local file: %s",filename.Data())); | |
120 | } | |
121 | else if(fStorage == 1) { | |
122 | TString alienFileName = "/alien"; | |
123 | alienFileName += gGrid->Pwd(); | |
124 | alienFileName += fgridpath.Data(); | |
125 | alienFileName += "/"; | |
126 | alienFileName += localFileName; | |
127 | alienFileName += "?se="; | |
128 | alienFileName += fSE.Data(); | |
129 | filename = alienFileName.Data(); | |
130 | AliInfo(Form("Writing merged tags to grid file: %s",filename.Data())); | |
131 | } | |
442646f2 | 132 | |
b2dc099f | 133 | fgChain->Merge(filename); |
0e7ce776 | 134 | gSystem->Exec("rm Run*.Event*"); |
442646f2 | 135 | |
136 | return kTRUE; | |
137 | } | |
138 | ||
850d5792 | 139 | |
140 | //__________________________________________________________________________ | |
141 | Bool_t AliTagCreator::MergeTags(const char *type, const char *inflist) { | |
142 | //Merges the tags and stores the merged tag file | |
143 | //locally if fStorage=0 or in the grid if fStorage=1 | |
144 | AliInfo(Form("Merging tags.....")); | |
145 | TChain *fgChain = new TChain("T"); | |
146 | TString tagPattern = type; tagPattern += ".tag.root"; | |
147 | ||
148 | // if(fStorage == 0) { | |
149 | // // Open the working directory | |
150 | // void * dirp = gSystem->OpenDirectory(gSystem->pwd()); | |
151 | // const char * name = 0x0; | |
152 | // // Add all files matching *pattern* to the chain | |
153 | // while((name = gSystem->GetDirEntry(dirp))) { | |
154 | // if (strstr(name,tagPattern)) fgChain->Add(name); | |
155 | // }//directory loop | |
156 | // AliInfo(Form("Chained tag files: %d",fgChain->GetEntries())); | |
157 | // }//local mode | |
158 | ||
159 | // else if(fStorage == 1) { | |
160 | // TString alienLocation = gGrid->Pwd(); | |
161 | // alienLocation += fgridpath.Data(); | |
162 | // alienLocation += "/"; | |
163 | // TString queryPattern = "*."; queryPattern += tagPattern; | |
164 | // TGridResult *tagresult = gGrid->Query(alienLocation,queryPattern.Data(),"",""); | |
165 | // Int_t nEntries = tagresult->GetEntries(); | |
166 | // for(Int_t i = 0; i < nEntries; i++) { | |
167 | // TString alienUrl = tagresult->GetKey(i,"turl"); | |
168 | // fgChain->Add(alienUrl); | |
169 | // }//grid result loop | |
170 | // AliInfo(Form("Chained tag files: %d",fgChain->GetEntries())); | |
171 | // }//grid mode | |
172 | ||
173 | if (fStorage == 0) { | |
174 | ifstream *istr = new ifstream(inflist); | |
175 | char fname[200]; | |
176 | while (!(istr->eof())) { | |
177 | (*istr) >> fname; | |
178 | if (strstr(fname, tagPattern)) fgChain->Add(fname); | |
179 | } | |
73bbf779 | 180 | AliInfo(Form("Chained tag files: %lld",fgChain->GetEntries())); |
850d5792 | 181 | } |
182 | ||
183 | AliRunTag *tag = new AliRunTag; | |
184 | fgChain->SetBranchAddress("AliTAG",&tag); | |
185 | fgChain->GetEntry(0); | |
186 | TString localFileName = "Run"; localFileName += tag->GetRunId(); | |
187 | localFileName += ".Merged."; localFileName += tagPattern.Data(); | |
188 | ||
189 | TString filename; | |
190 | ||
191 | if(fStorage == 0) { | |
192 | filename = localFileName.Data(); | |
193 | AliInfo(Form("Writing merged tags to local file: %s",filename.Data())); | |
194 | } | |
195 | else if(fStorage == 1) { | |
196 | TString alienFileName = "/alien"; | |
197 | alienFileName += gGrid->Pwd(); | |
198 | alienFileName += fgridpath.Data(); | |
199 | alienFileName += "/"; | |
200 | alienFileName += localFileName; | |
201 | alienFileName += "?se="; | |
202 | alienFileName += fSE.Data(); | |
203 | filename = alienFileName.Data(); | |
204 | AliInfo(Form("Writing merged tags to grid file: %s",filename.Data())); | |
205 | } | |
206 | ||
207 | fgChain->Merge(filename); | |
208 | gSystem->Exec("rm Run*.Event*"); | |
209 | ||
210 | return kTRUE; | |
211 | } | |
212 | ||
442646f2 | 213 | //__________________________________________________________________________ |
5b8d5d69 | 214 | Bool_t AliTagCreator::MergeTags(const char *type, TGridResult *result) { |
442646f2 | 215 | //Merges the tags that are listed in the TGridResult |
216 | AliInfo(Form("Merging tags.....")); | |
217 | TChain *fgChain = new TChain("T"); | |
5b8d5d69 | 218 | TString tagPattern = "."; tagPattern += type; tagPattern += ".tag.root"; |
442646f2 | 219 | |
220 | Int_t nEntries = result->GetEntries(); | |
221 | ||
222 | TString alienUrl; | |
223 | for(Int_t i = 0; i < nEntries; i++) { | |
224 | alienUrl = result->GetKey(i,"turl"); | |
225 | fgChain->Add(alienUrl); | |
226 | } | |
73bbf779 | 227 | AliInfo(Form("Chained tag files: %lld",fgChain->GetEntries())); |
442646f2 | 228 | AliRunTag *tag = new AliRunTag; |
442646f2 | 229 | fgChain->SetBranchAddress("AliTAG",&tag); |
b2dc099f | 230 | fgChain->GetEntry(0); |
231 | ||
4fd84456 | 232 | TString localFileName = "Run"; localFileName += tag->GetRunId(); |
5b8d5d69 | 233 | localFileName += ".Merged"; localFileName += tagPattern.Data(); |
4fd84456 | 234 | |
9b4aee57 | 235 | TString filename; |
4fd84456 | 236 | |
237 | if(fStorage == 0) { | |
238 | filename = localFileName.Data(); | |
239 | AliInfo(Form("Writing merged tags to local file: %s",filename.Data())); | |
240 | } | |
c336835b | 241 | else if(fStorage == 1) { |
242 | TString alienFileName = "/alien"; | |
243 | alienFileName += gGrid->Pwd(); | |
244 | alienFileName += fgridpath.Data(); | |
245 | alienFileName += "/"; | |
246 | alienFileName += localFileName; | |
247 | alienFileName += "?se="; | |
248 | alienFileName += fSE.Data(); | |
4fd84456 | 249 | filename = alienFileName.Data(); |
250 | AliInfo(Form("Writing merged tags to grid file: %s",filename.Data())); | |
251 | } | |
252 | ||
b2dc099f | 253 | fgChain->Merge(filename); |
4fd84456 | 254 | |
255 | return kTRUE; | |
256 | } | |
850d5792 | 257 | |
258 | Bool_t AliTagCreator::MergeTagsForRun(const char* type) { | |
259 | //Merges the tags and stores the merged tag file | |
260 | //locally if fStorage=0 or in the grid if fStorage=1 | |
261 | AliInfo(Form("Merging tags.....")); | |
262 | TChain *fgChain = new TChain("T"); | |
263 | TString tagPattern = type; tagPattern += ".tag.root"; | |
264 | ||
265 | if(fStorage == 0) { | |
266 | // Open the working directory | |
267 | void * dirp = gSystem->OpenDirectory(gSystem->pwd()); | |
268 | const char * name = 0x0; | |
269 | // Add all files matching *pattern* to the chain | |
270 | while((name = gSystem->GetDirEntry(dirp))) { | |
271 | if (strstr(name,tagPattern)) fgChain->Add(name); | |
272 | }//directory loop | |
73bbf779 | 273 | AliInfo(Form("Chained tag files: %lld",fgChain->GetEntries())); |
850d5792 | 274 | }//local mode |
275 | ||
276 | else if(fStorage == 1) { | |
277 | TString alienLocation = gGrid->Pwd(); | |
278 | alienLocation += fgridpath.Data(); | |
279 | alienLocation += "/"; | |
280 | TString queryPattern = "*."; queryPattern += tagPattern; | |
281 | TGridResult *tagresult = gGrid->Query(alienLocation,queryPattern.Data(),"",""); | |
282 | Int_t nEntries = tagresult->GetEntries(); | |
283 | for(Int_t i = 0; i < nEntries; i++) { | |
284 | TString alienUrl = tagresult->GetKey(i,"turl"); | |
285 | fgChain->Add(alienUrl); | |
286 | }//grid result loop | |
73bbf779 | 287 | AliInfo(Form("Chained tag files: %lld",fgChain->GetEntries())); |
850d5792 | 288 | }//grid mode |
289 | ||
290 | AliRunTag *tag = new AliRunTag; | |
291 | fgChain->SetBranchAddress("AliTAG",&tag); | |
292 | fgChain->GetEntry(0); | |
293 | TString localFileName = "Run"; localFileName += tag->GetRunId(); | |
294 | localFileName += ".Merged."; localFileName += tagPattern.Data(); | |
295 | ||
296 | TString filename; | |
297 | ||
298 | if(fStorage == 0) { | |
299 | filename = localFileName.Data(); | |
300 | AliInfo(Form("Writing merged tags to local file: %s",filename.Data())); | |
301 | } | |
302 | else if(fStorage == 1) { | |
303 | TString alienFileName = "/alien"; | |
304 | alienFileName += gGrid->Pwd(); | |
305 | alienFileName += fgridpath.Data(); | |
306 | alienFileName += "/"; | |
307 | alienFileName += localFileName; | |
308 | alienFileName += "?se="; | |
309 | alienFileName += fSE.Data(); | |
310 | filename = alienFileName.Data(); | |
311 | AliInfo(Form("Writing merged tags to grid file: %s",filename.Data())); | |
312 | } | |
313 | ||
314 | // fgChain->Merge(filename); | |
315 | MergeToSingleRunTag(fgChain, filename); | |
316 | ||
317 | gSystem->Exec("rm Run*.Event*"); | |
318 | ||
319 | return kTRUE; | |
320 | } | |
321 | ||
322 | Bool_t AliTagCreator::MergeTagsForRun(const char* type, TGridResult *result) { | |
323 | //Merges the tags that are listed in the TGridResult | |
324 | AliInfo(Form("Merging tags.....")); | |
325 | TChain *fgChain = new TChain("T"); | |
326 | TString tagPattern = "."; tagPattern += type; tagPattern += ".tag.root"; | |
327 | ||
328 | Int_t nEntries = result->GetEntries(); | |
329 | ||
330 | TString alienUrl; | |
331 | for(Int_t i = 0; i < nEntries; i++) { | |
332 | alienUrl = result->GetKey(i,"turl"); | |
333 | fgChain->Add(alienUrl); | |
334 | } | |
73bbf779 | 335 | AliInfo(Form("Chained tag files: %lld",fgChain->GetEntries())); |
850d5792 | 336 | AliRunTag *tag = new AliRunTag; |
337 | fgChain->SetBranchAddress("AliTAG",&tag); | |
338 | fgChain->GetEntry(0); | |
339 | ||
340 | TString localFileName = "Run"; localFileName += tag->GetRunId(); | |
341 | localFileName += ".Merged"; localFileName += tagPattern.Data(); | |
342 | ||
343 | TString filename; | |
344 | ||
345 | if(fStorage == 0) { | |
346 | filename = localFileName.Data(); | |
347 | AliInfo(Form("Writing merged tags to local file: %s",filename.Data())); | |
348 | } | |
349 | else if(fStorage == 1) { | |
350 | TString alienFileName = "/alien"; | |
351 | alienFileName += gGrid->Pwd(); | |
352 | alienFileName += fgridpath.Data(); | |
353 | alienFileName += "/"; | |
354 | alienFileName += localFileName; | |
355 | alienFileName += "?se="; | |
356 | alienFileName += fSE.Data(); | |
357 | filename = alienFileName.Data(); | |
358 | AliInfo(Form("Writing merged tags to grid file: %s",filename.Data())); | |
359 | } | |
360 | ||
361 | // fgChain->Merge(filename); | |
362 | MergeToSingleRunTag(fgChain, filename); | |
363 | ||
364 | return kTRUE; | |
365 | } | |
366 | ||
367 | Bool_t AliTagCreator::MergeTagsForRun(const char* type, const char *inflist) { | |
368 | //Merges the tags and stores the merged tag file | |
369 | //locally if fStorage=0 or in the grid if fStorage=1 | |
370 | AliInfo(Form("Merging tags.....")); | |
371 | TChain *fgChain = new TChain("T"); | |
372 | TString tagPattern = type; tagPattern += ".tag.root"; | |
373 | ||
374 | // if(fStorage == 0) { | |
375 | // // Open the working directory | |
376 | // void * dirp = gSystem->OpenDirectory(gSystem->pwd()); | |
377 | // const char * name = 0x0; | |
378 | // // Add all files matching *pattern* to the chain | |
379 | // while((name = gSystem->GetDirEntry(dirp))) { | |
380 | // if (strstr(name,tagPattern)) fgChain->Add(name); | |
381 | // }//directory loop | |
382 | // AliInfo(Form("Chained tag files: %d",fgChain->GetEntries())); | |
383 | // }//local mode | |
384 | ||
385 | // else if(fStorage == 1) { | |
386 | // TString alienLocation = gGrid->Pwd(); | |
387 | // alienLocation += fgridpath.Data(); | |
388 | // alienLocation += "/"; | |
389 | // TString queryPattern = "*."; queryPattern += tagPattern; | |
390 | // TGridResult *tagresult = gGrid->Query(alienLocation,queryPattern.Data(),"",""); | |
391 | // Int_t nEntries = tagresult->GetEntries(); | |
392 | // for(Int_t i = 0; i < nEntries; i++) { | |
393 | // TString alienUrl = tagresult->GetKey(i,"turl"); | |
394 | // fgChain->Add(alienUrl); | |
395 | // }//grid result loop | |
396 | // AliInfo(Form("Chained tag files: %d",fgChain->GetEntries())); | |
397 | // }//grid mode | |
398 | ||
399 | if (fStorage == 0) { | |
400 | ifstream *istr = new ifstream(inflist); | |
401 | char fname[200]; | |
402 | while (!(istr->eof())) { | |
403 | (*istr) >> fname; | |
404 | if (strstr(fname, tagPattern)) fgChain->Add(fname); | |
405 | } | |
73bbf779 | 406 | AliInfo(Form("Chained tag files: %lld",fgChain->GetEntries())); |
850d5792 | 407 | } |
408 | ||
409 | AliRunTag *tag = new AliRunTag; | |
410 | fgChain->SetBranchAddress("AliTAG",&tag); | |
411 | fgChain->GetEntry(0); | |
412 | TString localFileName = "Run"; localFileName += tag->GetRunId(); | |
413 | localFileName += ".Merged."; localFileName += tagPattern.Data(); | |
414 | ||
415 | TString filename; | |
416 | ||
417 | if(fStorage == 0) { | |
418 | filename = localFileName.Data(); | |
419 | AliInfo(Form("Writing merged tags to local file: %s",filename.Data())); | |
420 | } | |
421 | else if(fStorage == 1) { | |
422 | TString alienFileName = "/alien"; | |
423 | alienFileName += gGrid->Pwd(); | |
424 | alienFileName += fgridpath.Data(); | |
425 | alienFileName += "/"; | |
426 | alienFileName += localFileName; | |
427 | alienFileName += "?se="; | |
428 | alienFileName += fSE.Data(); | |
429 | filename = alienFileName.Data(); | |
430 | AliInfo(Form("Writing merged tags to grid file: %s",filename.Data())); | |
431 | } | |
432 | ||
433 | // fgChain->Merge(filename); | |
434 | MergeToSingleRunTag(fgChain, filename); | |
435 | ||
436 | gSystem->Exec("rm Run*.Event*"); | |
437 | ||
438 | return kTRUE; | |
439 | } | |
440 | ||
441 | ||
442 | Bool_t AliTagCreator::MergeToSingleRunTag(TChain *chain, const char *filename) | |
443 | { | |
444 | // Merge all tags for a given run into a single RunTag | |
445 | TFile* ftag = TFile::Open(filename, "recreate"); | |
446 | ||
447 | AliRunTag *tag = new AliRunTag; | |
448 | TTree * ttag = new TTree("T","A Tree with event tags"); | |
04cb11d4 | 449 | TBranch * btag = ttag->Branch("AliTAG", &tag, 1000000); |
850d5792 | 450 | btag->SetCompressionLevel(9); |
04cb11d4 | 451 | ttag->AutoSave("10000"); |
850d5792 | 452 | |
453 | AliRunTag *rtag = new AliRunTag(); | |
454 | chain->SetBranchAddress("AliTAG", &rtag); | |
455 | ||
04cb11d4 | 456 | AliFileTag *evt; |
457 | ||
850d5792 | 458 | if (chain->GetEntries()) { |
459 | chain->GetEntry(0); | |
460 | tag->CopyStandardContent(rtag); | |
04cb11d4 | 461 | tag->Clear(); |
850d5792 | 462 | |
463 | int runno = rtag->GetRunId(); | |
464 | ||
465 | for (int iter=0; iter<chain->GetEntries(); iter++) { | |
466 | chain->GetEntry(iter); | |
467 | if (runno != rtag->GetRunId()) { | |
468 | AliInfo(Form("Run tag ID %i is different from the Run ID for the merged run: %i\n", rtag->GetRunId(), runno)); | |
469 | continue; | |
470 | } | |
471 | ||
04cb11d4 | 472 | for (int iev=0; iev<rtag->GetNFiles(); iev++) { |
473 | evt = (AliFileTag *) rtag->GetFileTag(iev); | |
474 | tag->AddFileTag(new AliFileTag(*evt)); | |
850d5792 | 475 | } |
476 | } | |
477 | } | |
478 | else { | |
479 | AliInfo("Found no tag files to merge."); | |
480 | return kFALSE; | |
481 | } | |
482 | ||
483 | ttag->Fill(); | |
484 | ||
485 | ftag->cd(); | |
486 | tag->Clear(); | |
487 | ttag->Write(); | |
488 | ftag->Close(); | |
489 | ||
490 | return kTRUE; | |
491 | } | |
492 | ||
493 |