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