]>
Commit | Line | Data |
---|---|---|
1 | /************************************************************************** | |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | //_________________________________________________________________________ | |
16 | // Various utilities usefull for analysis | |
17 | // | |
18 | //*-- Yves Schutz | |
19 | ////////////////////////////////////////////////////////////////////////////// | |
20 | ||
21 | #include "AliAnalysisDataContainer.h" | |
22 | #include "AliTagAnalysis.h" | |
23 | #include "AliEventTagCuts.h" | |
24 | #include "AliRunTagCuts.h" | |
25 | #include "AliXMLCollection.h" | |
26 | #include "AliAnalysisGoodies.h" | |
27 | #include "AliAnalysisManager.h" | |
28 | #include "AliAnalysisTask.h" | |
29 | #include "AliLog.h" | |
30 | ||
31 | #include <Riostream.h> | |
32 | #ifdef WITHALIEN | |
33 | #include <TGridResult.h> | |
34 | #include <TFileMerger.h> | |
35 | #endif | |
36 | #include <TChain.h> | |
37 | #include <TGrid.h> | |
38 | #include <TROOT.h> | |
39 | #include <TSystem.h> | |
40 | #include <TEntryList.h> | |
41 | ||
42 | //______________________________________________________________________________ | |
43 | AliAnalysisGoodies::AliAnalysisGoodies() : | |
44 | TObject(), | |
45 | fTimer(), | |
46 | fESDTreeName("esdTree"), | |
47 | fnumberOfTasks(0), | |
48 | fTaskList(0), | |
49 | fTaskInType(0), | |
50 | fTaskOuType(0) | |
51 | { | |
52 | fTimer.Reset() ; | |
53 | ||
54 | TString token = gSystem->Getenv("GRID_TOKEN") ; | |
55 | ||
56 | if ( token == "OK" ) | |
57 | TGrid::Connect("alien://"); | |
58 | else | |
59 | AliInfo("You are not connected to the GRID") ; | |
60 | } | |
61 | ||
62 | //______________________________________________________________________________ | |
63 | AliAnalysisGoodies::AliAnalysisGoodies(const AliAnalysisGoodies& ag) : | |
64 | TObject(), | |
65 | fTimer(), | |
66 | fESDTreeName(""), | |
67 | fnumberOfTasks(0), | |
68 | fTaskList(0), | |
69 | fTaskInType(0), | |
70 | fTaskOuType(0) | |
71 | { | |
72 | ||
73 | fESDTreeName = ag.fESDTreeName ; | |
74 | TString token = gSystem->Getenv("GRID_TOKEN") ; | |
75 | ||
76 | if ( token == "OK" ) | |
77 | TGrid::Connect("alien://"); | |
78 | else | |
79 | AliInfo("You are not connected to the GRID") ; | |
80 | } | |
81 | ||
82 | //______________________________________________________________________________ | |
83 | void AliAnalysisGoodies::Help() const | |
84 | { | |
85 | AliInfo("Analysis utilities:\n") ; | |
86 | printf(" *** Alien2Local : copy files ESD files listed in an xml collection from AliEn catalog to local storage and creates a local xml collection \n") ; | |
87 | printf(" usage: Alien2Local(in, out)\n") ; | |
88 | printf(" in: a xml esd collection file name \n") ; | |
89 | printf(" ou: the local directory where to save the esd root files \n") ; | |
90 | printf(" *** Make : makes esd collection from tags \n") ; | |
91 | printf(" usage: Make(tags, esds)\n") ; | |
92 | printf(" tags: is either a tag root file or an xml tag collection \n") ; | |
93 | printf(" esds: is an esd collection \n") ; | |
94 | printf(" *** Merge : merges files listed in a xml collection \n") ; | |
95 | printf(" usage Merge(collection, outputDile)\n") ; | |
96 | printf(" collection: is a xml collection \n") ; | |
97 | printf(" *** Process : process the events with an Analysis Task \n") ; | |
98 | printf(" usage: Process(esdFile, tagCuts) \n") ; | |
99 | printf(" esdFile: can be a root file with the ESD Tree ( ex: esd?AliESDs.root) \n") ; | |
100 | printf(" or a root file with the Tag Tree ( ex: tag?Run100.Event0_100.ESD.tag.root) \n") ; | |
101 | printf(" or a local or alien xml file with the ESD collection ( ex: esd?esdCollection.xml) \n") ; | |
102 | printf(" or a local or alien xml file with the TAG collection ( ex: tag?tagCollection.xml) \n") ; | |
103 | printf(" or a TChain of esd TTrees \n") ; | |
104 | printf(" tagCuts: is the AliEventTagCuts (needed only for tag? cases \n") ; | |
105 | printf(" *** Register: register files already stored in a MSS into the AliEn catalog\n") ; | |
106 | printf(" usage: Register(lfndir, pfndir, pfnFileName) \n") ; | |
107 | printf(" lfndir : AliEn directory ( ex: /alice/data/2006/LHC06c/PHOS_TestBeam/\n") ; | |
108 | printf(" pfndir : MSS directory ( ex: /castor/cern.ch/alice/testbeam/phos/2006 \n") ; | |
109 | printf(" file : text file with a list of the file names to be registered\n ") ; | |
110 | ||
111 | } | |
112 | ||
113 | //______________________________________________________________________ | |
114 | Bool_t AliAnalysisGoodies::Alien2Local(const TString collectionNameIn, const TString localDir) | |
115 | { | |
116 | // copy files ESD files listed in an xml collection from AliEn catalog to local storage and creates a local xml collection | |
117 | // usage: Alien2Local(in, out) | |
118 | // in: a xml esd collection file name | |
119 | // ou: the local directory where to save the esd root files | |
120 | ||
121 | #ifdef WITHALIEN | |
122 | Bool_t rv = kTRUE ; | |
123 | ||
124 | fTimer.Start() ; | |
125 | ||
126 | AliXMLCollection * collectionIn = AliXMLCollection::Open(collectionNameIn) ; | |
127 | collectionIn->Reset() ; | |
128 | ||
129 | AliXMLCollection * collectionOu = new AliXMLCollection() ; | |
130 | TString collectionNameOu(collectionIn->GetCollectionName()) ; | |
131 | collectionNameOu.Append("Local") ; | |
132 | collectionOu->SetCollectionName(collectionNameOu) ; | |
133 | collectionOu->WriteHeader() ; | |
134 | ||
135 | TFileMerger merger ; | |
136 | ||
137 | const char* ocwd = gSystem->WorkingDirectory(); | |
138 | ||
139 | Int_t counter = 1 ; | |
140 | while ( collectionIn->Next() ) { | |
141 | gSystem->ChangeDirectory(localDir) ; | |
142 | TString fileTURL = collectionIn->GetTURL("") ; | |
143 | ||
144 | TString tempo(fileTURL) ; | |
145 | tempo.Remove(tempo.Last('/'), tempo.Length()) ; | |
146 | TString evtsNumber = tempo(tempo.Last('/')+1, tempo.Length())+"/"; | |
147 | tempo.Remove(tempo.Last('/'), tempo.Length()) ; | |
148 | TString runNumber = tempo(tempo.Last('/')+1, tempo.Length())+"/" ; | |
149 | TString dir = localDir + runNumber ; | |
150 | dir += evtsNumber ; | |
151 | char line[1024] ; | |
152 | sprintf(line, ".! mkdir -p %s", dir.Data()) ; | |
153 | gROOT->ProcessLine(line) ; | |
154 | printf("***************************%s\n", line) ; | |
155 | TEntryList * list = collectionIn->GetEventList("") ; | |
156 | if (!list) | |
157 | list = new TEntryList() ; | |
158 | tempo = fileTURL ; | |
159 | TString filename = tempo(tempo.Last('/')+1, tempo.Length()) ; | |
160 | dir += filename ; | |
161 | AliInfo(Form("Copying %s to %s\n", fileTURL.Data(), dir.Data())) ; | |
162 | collectionOu->WriteBody(counter, collectionIn->GetGUID(""), collectionIn->GetLFN(""), dir, list) ; | |
163 | counter++ ; | |
164 | merger.Cp(fileTURL, dir) ; | |
165 | } | |
166 | collectionOu->Export() ; | |
167 | gSystem->ChangeDirectory(ocwd) ; | |
168 | ||
169 | fTimer.Stop(); | |
170 | fTimer.Print(); | |
171 | ||
172 | return rv ; | |
173 | #else | |
174 | return kFALSE; | |
175 | #endif | |
176 | } | |
177 | ||
178 | //______________________________________________________________________ | |
179 | Bool_t AliAnalysisGoodies::Make(AliRunTagCuts *runCuts, AliLHCTagCuts *lhcCuts, AliDetectorTagCuts *detCuts, AliEventTagCuts *evtCuts, const char * in, const char * out) const | |
180 | { | |
181 | // makes esd collection from tags | |
182 | // usage Make(tags, esds) | |
183 | // tags: is either a tag root file or an xml tag collection | |
184 | // esds: is an esd collection | |
185 | ||
186 | Bool_t rv = kTRUE ; | |
187 | ||
188 | if ( !evtCuts && !runCuts ) { | |
189 | AliError("No Tag cuts provided") ; | |
190 | return kFALSE ; | |
191 | } | |
192 | ||
193 | TString file(in) ; | |
194 | if ( file.Contains(".root") ) | |
195 | rv = MakeEsdCollectionFromTagFile(runCuts, lhcCuts, detCuts, evtCuts, file.Data(), out) ; | |
196 | else if ( file.Contains(".xml") ) | |
197 | rv = MakeEsdCollectionFromTagCollection(runCuts, lhcCuts, detCuts, evtCuts, file.Data(), out) ; | |
198 | else { | |
199 | AliError(Form("%s is not a valid file format", in)) ; | |
200 | rv = kFALSE ; | |
201 | } | |
202 | ||
203 | return rv ; | |
204 | } | |
205 | ||
206 | //______________________________________________________________________ | |
207 | Bool_t AliAnalysisGoodies::MakeEsdCollectionFromTagFile(AliRunTagCuts *runCuts, AliLHCTagCuts *lhcCuts, AliDetectorTagCuts *detCuts, AliEventTagCuts *evtCuts, const char * in, const char * out) const | |
208 | { | |
209 | // Makes an esd collection from a root tag file | |
210 | Bool_t rv = kTRUE ; | |
211 | // Open the file collection | |
212 | printf("*** Create Collection ***\n"); | |
213 | printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory()); | |
214 | printf("*** file = |%s| \n",in); | |
215 | ||
216 | AliTagAnalysis * tagAna = new AliTagAnalysis(); | |
217 | rv = tagAna->AddTagsFile(in); | |
218 | if ( ! rv ) | |
219 | return rv ; | |
220 | ||
221 | tagAna->CreateXMLCollection(out, runCuts, lhcCuts, detCuts, evtCuts) ; | |
222 | ||
223 | return rv ; | |
224 | ||
225 | } | |
226 | ||
227 | //______________________________________________________________________ | |
228 | Bool_t AliAnalysisGoodies::MakeEsdCollectionFromTagCollection(AliRunTagCuts *runCuts, AliLHCTagCuts *lhcCuts, AliDetectorTagCuts *detCuts, AliEventTagCuts *evtCuts, const char * in, const char * out) const | |
229 | { | |
230 | // Makes an esd collection from a xml tag collection | |
231 | Bool_t rv = kTRUE ; | |
232 | // Open the file collection | |
233 | printf("*** Create Collection ***\n"); | |
234 | printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory()); | |
235 | printf("*** Coll = |%s| \n",in); | |
236 | ||
237 | #ifdef WITHALIEN | |
238 | ||
239 | TGridCollection * collection = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(\"%s\", 0)",in)); | |
240 | TGridResult* result = collection->GetGridResult("", 0, 0); | |
241 | AliTagAnalysis * tagAna = new AliTagAnalysis(); | |
242 | tagAna->ChainGridTags(result); | |
243 | ||
244 | tagAna->CreateXMLCollection(out, runCuts, lhcCuts, detCuts, evtCuts) ; | |
245 | ||
246 | #else | |
247 | rv = kFALSE; | |
248 | #endif | |
249 | return rv ; | |
250 | } | |
251 | ||
252 | //______________________________________________________________________ | |
253 | Bool_t AliAnalysisGoodies::MakeEsdCollectionFromTagCollection(const char * runCuts, const char *lhcCuts, const char *detCuts, const char * evtCuts, const char * in, const char * out) const | |
254 | { | |
255 | // Makes an esd collection from a xml tag collection | |
256 | ||
257 | Bool_t rv = kTRUE ; | |
258 | ||
259 | // Open the file collection | |
260 | printf("*** Create Collection ***\n"); | |
261 | printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory()); | |
262 | printf("*** Coll = |%s| \n",in); | |
263 | ||
264 | #ifdef WITHALIEN | |
265 | ||
266 | TGridCollection * collection = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(\"%s\", 0)",in)); | |
267 | TGridResult* result = collection->GetGridResult("", 0, 0); | |
268 | AliTagAnalysis * tagAna = new AliTagAnalysis(); | |
269 | tagAna->ChainGridTags(result); | |
270 | ||
271 | tagAna->CreateXMLCollection(out, runCuts, lhcCuts, detCuts, evtCuts) ; | |
272 | ||
273 | #else | |
274 | rv = kFALSE; | |
275 | #endif | |
276 | return rv ; | |
277 | } | |
278 | ||
279 | //______________________________________________________________________ | |
280 | Bool_t AliAnalysisGoodies::Merge(const char * collectionFile, const char * subFile, const char * outFile) | |
281 | { | |
282 | // merges files listed in a xml collection | |
283 | // usage Merge(collection, outputFile)) | |
284 | // collection: is a xml collection | |
285 | ||
286 | Bool_t rv = kFALSE ; | |
287 | ||
288 | if ( strstr(collectionFile, ".xml") == 0 ) { | |
289 | AliError("Input collection file must be an \".xml\" file\n") ; | |
290 | return kFALSE ; | |
291 | } | |
292 | ||
293 | fTimer.Start() ; | |
294 | ||
295 | // Open the file collection | |
296 | printf("*** Create Collection ***\n"); | |
297 | printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory()); | |
298 | printf("*** Coll = |%s| \n",collectionFile); | |
299 | ||
300 | #ifdef WITHALIEN | |
301 | ||
302 | TGridCollection * collection = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(\"%s\", 0)",collectionFile)); | |
303 | TGridResult* result = collection->GetGridResult("", 0, 0); | |
304 | ||
305 | Int_t index = 0 ; | |
306 | const char * turl ; | |
307 | TFileMerger merger ; | |
308 | if (!outFile) { | |
309 | TString tempo(collectionFile) ; | |
310 | if ( subFile) | |
311 | tempo.ReplaceAll(".xml", subFile) ; | |
312 | else | |
313 | tempo.ReplaceAll(".xml", "_Merged.root") ; | |
314 | outFile = tempo.Data() ; | |
315 | } | |
316 | merger.OutputFile(outFile) ; | |
317 | ||
318 | while ( (turl = result->GetKey(index, "turl")) ) { | |
319 | char file[2048] ; | |
320 | if ( subFile ) | |
321 | sprintf(file, "%s#%s", turl, subFile) ; | |
322 | else | |
323 | sprintf(file, "%s", turl) ; | |
324 | ||
325 | printf("%s\n", file) ; | |
326 | merger.AddFile(file) ; | |
327 | index++ ; | |
328 | } | |
329 | ||
330 | if (index) | |
331 | merger.Merge() ; | |
332 | ||
333 | AliInfo(Form("Files merged into %s\n", outFile)) ; | |
334 | ||
335 | fTimer.Stop(); | |
336 | fTimer.Print(); | |
337 | ||
338 | #else | |
339 | rv = kFALSE; | |
340 | #endif | |
341 | return rv ; | |
342 | } | |
343 | ||
344 | //______________________________________________________________________ | |
345 | Bool_t AliAnalysisGoodies::Process(TChain * chain) | |
346 | { | |
347 | // process events starting from a chain of esd Trees | |
348 | Bool_t rv = kFALSE ; | |
349 | fTimer.Start() ; | |
350 | ||
351 | rv = ProcessChain(chain) ; | |
352 | ||
353 | fTimer.Stop(); | |
354 | fTimer.Print(); | |
355 | ||
356 | return rv ; | |
357 | } | |
358 | ||
359 | //______________________________________________________________________ | |
360 | Bool_t AliAnalysisGoodies::Process(const char * inFile) | |
361 | { | |
362 | // process the events with an Analysis Task | |
363 | // usage Process(esdFile) | |
364 | // esdFile: is of the form opt?file_lfn | |
365 | Bool_t rv = kFALSE ; | |
366 | AliRunTagCuts * runCuts = 0x0 ; | |
367 | AliLHCTagCuts * lhcCuts = 0x0 ; | |
368 | AliDetectorTagCuts * detCuts = 0x0 ; | |
369 | AliEventTagCuts * evtCuts = 0x0 ; | |
370 | ||
371 | rv = Process(inFile, runCuts, lhcCuts, detCuts, evtCuts) ; | |
372 | ||
373 | return rv ; | |
374 | } | |
375 | ||
376 | //______________________________________________________________________ | |
377 | Bool_t AliAnalysisGoodies::Process(const char * inFile, AliRunTagCuts *runCuts, AliLHCTagCuts *lhcCuts, AliDetectorTagCuts *detCuts, AliEventTagCuts * evtCuts ) | |
378 | { | |
379 | // process the events with an Analysis Task | |
380 | // usage Process(esdFile, runtagCuts, evtTagCuts) | |
381 | // esdFile: is of the form opt?file_lfn | |
382 | ||
383 | Bool_t rv = kFALSE ; | |
384 | ||
385 | fTimer.Start() ; | |
386 | ||
387 | TString file(inFile) ; | |
388 | if ( file.Contains("esd?") && file.Contains(".root") ) { | |
389 | file.ReplaceAll("esd?", "") ; | |
390 | rv = ProcessEsdFile(file.Data()) ; | |
391 | ||
392 | } else if ( file.Contains("esd?") && file.Contains(".xml") ) { | |
393 | file.ReplaceAll("esd?", "") ; | |
394 | rv = ProcessEsdXmlCollection(file.Data()) ; | |
395 | ||
396 | } else if (file.Contains("tag?") && file.Contains(".root") ) { | |
397 | file.ReplaceAll("tag?", "") ; | |
398 | rv = ProcessTagFile(file.Data(), runCuts, lhcCuts, detCuts, evtCuts) ; | |
399 | ||
400 | } else if (file.Contains("tag?") && file.Contains(".xml") ) { | |
401 | file.ReplaceAll("tag?", "") ; | |
402 | rv = ProcessTagXmlCollection(file.Data(), runCuts, lhcCuts, detCuts, evtCuts) ; | |
403 | ||
404 | } else { | |
405 | AliError(Form("%s is not a valid file format", inFile)) ; | |
406 | rv = kFALSE ; | |
407 | } | |
408 | ||
409 | fTimer.Stop(); | |
410 | fTimer.Print(); | |
411 | ||
412 | return rv ; | |
413 | } | |
414 | ||
415 | //______________________________________________________________________ | |
416 | Bool_t AliAnalysisGoodies::Process(const char * inFile, const char * runCuts, const char * lhcCuts, const char * detCuts, const char * evtCuts) | |
417 | { | |
418 | // process the events with an Analysis Task | |
419 | // usage Process(esdFile, runtagCuts, evtTagCuts) | |
420 | // esdFile: is of the form opt?file_lfn | |
421 | ||
422 | Bool_t rv = kFALSE ; | |
423 | ||
424 | fTimer.Start() ; | |
425 | ||
426 | TString file(inFile) ; | |
427 | if ( file.Contains("esd?") && file.Contains(".root") ) { | |
428 | file.ReplaceAll("esd?", "") ; | |
429 | rv = ProcessEsdFile(file.Data()) ; | |
430 | ||
431 | } else if ( file.Contains("esd?") && file.Contains(".xml") ) { | |
432 | file.ReplaceAll("esd?", "") ; | |
433 | rv = ProcessEsdXmlCollection(file.Data()) ; | |
434 | ||
435 | } else if (file.Contains("tag?") && file.Contains(".root") ) { | |
436 | file.ReplaceAll("tag?", "") ; | |
437 | rv = ProcessTagFile(file.Data(), runCuts, lhcCuts, detCuts, evtCuts) ; | |
438 | ||
439 | } else if (file.Contains("tag?") && file.Contains(".xml") ) { | |
440 | file.ReplaceAll("tag?", "") ; | |
441 | rv = ProcessTagXmlCollection(file.Data(), runCuts, lhcCuts, detCuts, evtCuts) ; | |
442 | ||
443 | } else { | |
444 | AliError(Form("%s is not a valid file format", inFile)) ; | |
445 | rv = kFALSE ; | |
446 | } | |
447 | ||
448 | fTimer.Stop(); | |
449 | fTimer.Print(); | |
450 | ||
451 | return rv ; | |
452 | } | |
453 | ||
454 | //______________________________________________________________________ | |
455 | Bool_t AliAnalysisGoodies::ProcessChain(TChain * chain) const | |
456 | { | |
457 | // Procees a TChain. | |
458 | ||
459 | Bool_t rv = kTRUE ; | |
460 | ||
461 | if (! fTaskList ) { | |
462 | AliError("No tasks defined") ; | |
463 | return kFALSE ; | |
464 | } | |
465 | ||
466 | // Make the analysis manager | |
467 | AliAnalysisManager * mgr = new AliAnalysisManager("Goodies Manager", "Analysis manager created by AliAnalysisGoodies") ; | |
468 | ||
469 | // Make tasks | |
470 | // The top input must be common to all top tasks | |
471 | TClass * classIn = fTaskInType[0] ; | |
472 | AliAnalysisDataContainer * taskInput = mgr->CreateContainer("InputContainer", classIn, AliAnalysisManager::kInputContainer) ; | |
473 | Int_t index ; | |
474 | for (index = 0; index < fnumberOfTasks; index++) { | |
475 | ||
476 | TClass * classOu = fTaskOuType[index] ; | |
477 | AliAnalysisTask * task = fTaskList[index] ; | |
478 | ||
479 | AliAnalysisDataContainer * taskOutput = mgr->CreateContainer(Form("OutputContainer%d",index), classOu, AliAnalysisManager::kOutputContainer, Form("%s.root",task->GetName())) ; | |
480 | mgr->AddTask(task) ; | |
481 | ||
482 | // Create containers for input/output | |
483 | ||
484 | rv = mgr->ConnectInput (task, 0, taskInput); | |
485 | if (!rv) | |
486 | AliFatal(Form("Error while connecting %s to %s", task->GetName(), taskInput->GetName())) ; | |
487 | rv = mgr->ConnectOutput(task, 0, taskOutput); | |
488 | if (!rv) | |
489 | AliFatal(Form("Error while connecting %s to %s", task->GetName(), taskOutput->GetName())) ; | |
490 | } | |
491 | ||
492 | // start processing | |
493 | ||
494 | if (mgr->InitAnalysis()) { | |
495 | mgr->PrintStatus(); | |
496 | mgr->StartAnalysis("local",chain); | |
497 | } else | |
498 | rv = kFALSE ; | |
499 | ||
500 | return rv ; | |
501 | } | |
502 | ||
503 | //______________________________________________________________________ | |
504 | Bool_t AliAnalysisGoodies::ProcessEsdFile(const char * esdFile) const | |
505 | { | |
506 | // process the events in a single ESD file with an Analysis Task | |
507 | // usage ProcessLocalEsdFile(esdFile) | |
508 | // esdFile: is the root file (local or in alien) with the ESD Tree ( ex: AliESDs.root) | |
509 | ||
510 | Bool_t rv = kTRUE ; | |
511 | ||
512 | printf("*** Process ***\n"); | |
513 | printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory()); | |
514 | printf("*** Coll = |%s| \n",esdFile); | |
515 | ||
516 | // Makes the ESD chain | |
517 | printf("*** Getting the Chain ***\n"); | |
518 | TChain* analysisChain = new TChain(fESDTreeName) ; | |
519 | analysisChain->AddFile(esdFile); | |
520 | ||
521 | // Process the events | |
522 | rv = ProcessChain(analysisChain) ; | |
523 | ||
524 | return rv; | |
525 | } | |
526 | ||
527 | //______________________________________________________________________ | |
528 | Bool_t AliAnalysisGoodies::ProcessTagFile(const char * tagFile, AliRunTagCuts *runCuts, AliLHCTagCuts *lhcCuts, AliDetectorTagCuts *detCuts, AliEventTagCuts *evtCuts) const | |
529 | { | |
530 | // process the events in a single Tag file with an Analysis Task | |
531 | // usage ProcessLocalEsdFile(tagFile) | |
532 | // tagFile: is the root file (local or in alien) with the Tag Tree (ex: Run102.Event0_100.ESD.tag.root) | |
533 | ||
534 | Bool_t rv = kTRUE ; | |
535 | ||
536 | if ( !evtCuts && !runCuts ) { | |
537 | AliError("No Tag cuts provided") ; | |
538 | return kFALSE ; | |
539 | } | |
540 | ||
541 | printf("*** Process ***\n"); | |
542 | printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory()); | |
543 | printf("*** Coll = |%s| \n",tagFile); | |
544 | ||
545 | AliTagAnalysis * tagAna = new AliTagAnalysis(); | |
546 | rv = tagAna->AddTagsFile(tagFile); | |
547 | if ( ! rv ) | |
548 | return rv ; | |
549 | ||
550 | // Query the tag file and make the analysis chain | |
551 | TChain * analysisChain = new TChain(fESDTreeName) ; | |
552 | analysisChain = tagAna->QueryTags(runCuts, lhcCuts, detCuts, evtCuts); | |
553 | ||
554 | // Process the events | |
555 | rv = ProcessChain(analysisChain) ; | |
556 | ||
557 | return rv; | |
558 | } | |
559 | ||
560 | //______________________________________________________________________ | |
561 | Bool_t AliAnalysisGoodies::ProcessTagFile(const char * tagFile, const char * runCuts, const char * lhcCuts, const char * detCuts, const char * evtCuts) const | |
562 | { | |
563 | // process the events in a single Tag file with an Analysis Task | |
564 | // usage ProcessLocalEsdFile(tagFile) | |
565 | // tagFile: is the root file (local or in alien) with the Tag Tree (ex: Run102.Event0_100.ESD.tag.root) | |
566 | ||
567 | Bool_t rv = kTRUE ; | |
568 | ||
569 | ||
570 | if ( !evtCuts && !runCuts ) { | |
571 | AliError("No Tag cuts provided") ; | |
572 | return kFALSE ; | |
573 | } | |
574 | ||
575 | printf("*** Process ***\n"); | |
576 | printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory()); | |
577 | printf("*** Coll = |%s| \n",tagFile); | |
578 | ||
579 | AliTagAnalysis * tagAna = new AliTagAnalysis(); | |
580 | rv = tagAna->AddTagsFile(tagFile); | |
581 | if ( ! rv ) | |
582 | return rv ; | |
583 | ||
584 | // Query the tag file and make the analysis chain | |
585 | TChain * analysisChain = new TChain(fESDTreeName) ; | |
586 | analysisChain = tagAna->QueryTags(runCuts, lhcCuts, detCuts, evtCuts); | |
587 | ||
588 | // Process the events | |
589 | rv = ProcessChain(analysisChain) ; | |
590 | ||
591 | return rv; | |
592 | } | |
593 | ||
594 | //______________________________________________________________________ | |
595 | Bool_t AliAnalysisGoodies::ProcessEsdXmlCollection(const char * xmlFile) const | |
596 | { | |
597 | // process the events in a xml ESD collection with an Analysis Task | |
598 | // usage ProcessLocalEsdFile(xmlFile) | |
599 | // xmlFile: is the local xml file with the ESD collection ( ex: esdCollection.xml) | |
600 | ||
601 | Bool_t rv = kTRUE ; | |
602 | ||
603 | printf("*** Process ***\n"); | |
604 | printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory()); | |
605 | printf("*** Coll = |%s| \n",xmlFile); | |
606 | ||
607 | #ifdef WITHALIEN | |
608 | //AliXMLCollection * collection = AliXMLCollection::Open(xmlFile,0) ; | |
609 | TGridCollection * collection = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(\"%s\", 0)", xmlFile)); | |
610 | if (! collection) { | |
611 | AliError(Form("%s not found", xmlFile)) ; | |
612 | return kFALSE ; | |
613 | } | |
614 | ||
615 | TGridResult* result = collection->GetGridResult("",0 ,0); | |
616 | TList* analysisfilelist = result->GetFileInfoList(); | |
617 | ||
618 | // Makes the ESD chain | |
619 | printf("*** Getting the Chain ***\n"); | |
620 | TChain* analysisChain = new TChain(fESDTreeName); | |
621 | analysisChain->AddFileInfoList(analysisfilelist); | |
622 | ||
623 | // Process the events | |
624 | rv = ProcessChain(analysisChain) ; | |
625 | ||
626 | #else | |
627 | rv = kFALSE; | |
628 | ||
629 | #endif | |
630 | ||
631 | return rv ; | |
632 | } | |
633 | ||
634 | //______________________________________________________________________ | |
635 | Bool_t AliAnalysisGoodies::ProcessTagXmlCollection(const char * xmlFile, AliRunTagCuts *runCuts, AliLHCTagCuts *lhcCuts, AliDetectorTagCuts *detCuts, AliEventTagCuts * evtCuts) const | |
636 | { | |
637 | // process the events in a xml ESD collection with an Analysis Task | |
638 | // usage ProcessLocalEsdFile(xmlFile) | |
639 | // xmlFile: is the local xml file with the tag collection ( ex: tagCollection.xml) | |
640 | ||
641 | Bool_t rv = kTRUE ; | |
642 | ||
643 | if ( !evtCuts && !runCuts ) { | |
644 | AliError("No Tag cuts provided") ; | |
645 | return kFALSE ; | |
646 | } | |
647 | ||
648 | printf("*** Process ***\n"); | |
649 | printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory()); | |
650 | printf("*** Coll = |%s| \n",xmlFile); | |
651 | ||
652 | // check if file is local or alien | |
653 | if ( gSystem->AccessPathName(xmlFile) ) | |
654 | TGrid::Connect("alien://"); | |
655 | ||
656 | #ifdef WITHALIEN | |
657 | ||
658 | TGridCollection * collection = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(\"%s\", 0)",xmlFile)); | |
659 | if (! collection) { | |
660 | AliError(Form("%s not found", xmlFile)) ; | |
661 | return kFALSE ; | |
662 | } | |
663 | ||
664 | TGridResult* result = collection->GetGridResult("", 0, 0); | |
665 | AliTagAnalysis * tagAna = new AliTagAnalysis(); | |
666 | tagAna->ChainGridTags(result); | |
667 | ||
668 | // Query the tag file and make the analysis chain | |
669 | TChain * analysisChain = new TChain(fESDTreeName) ; | |
670 | analysisChain = tagAna->QueryTags(runCuts, lhcCuts, detCuts, evtCuts); | |
671 | ||
672 | // Process the events | |
673 | rv = ProcessChain(analysisChain) ; | |
674 | ||
675 | #else | |
676 | rv = kFALSE; | |
677 | #endif | |
678 | return rv ; | |
679 | } | |
680 | ||
681 | //______________________________________________________________________ | |
682 | Bool_t AliAnalysisGoodies::ProcessTagXmlCollection(const char * xmlFile, const char * runCuts, const char * lhcCuts, const char * detCuts, const char * evtCuts) const | |
683 | { | |
684 | // process the events in a xml ESD collection with an Analysis Task | |
685 | // usage ProcessLocalEsdFile(xmlFile) | |
686 | // xmlFile: is the local xml file with the tag collection ( ex: tagCollection.xml) | |
687 | ||
688 | Bool_t rv = kTRUE ; | |
689 | ||
690 | if ( !evtCuts && !runCuts ) { | |
691 | AliError("No Tag cuts provided") ; | |
692 | return kFALSE ; | |
693 | } | |
694 | ||
695 | printf("*** Process ***\n"); | |
696 | printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory()); | |
697 | printf("*** Coll = |%s| \n",xmlFile); | |
698 | ||
699 | #ifdef WITHALIEN | |
700 | ||
701 | // check if file is local or alien | |
702 | if ( gSystem->AccessPathName(xmlFile) ) | |
703 | TGrid::Connect("alien://"); | |
704 | ||
705 | TGridCollection * collection = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(\"%s\", 0)",xmlFile)); | |
706 | if (! collection) { | |
707 | AliError(Form("%s not found", xmlFile)) ; | |
708 | return kFALSE ; | |
709 | } | |
710 | ||
711 | TGridResult* result = collection->GetGridResult("", 0, 0); | |
712 | AliTagAnalysis * tagAna = new AliTagAnalysis(); | |
713 | tagAna->ChainGridTags(result); | |
714 | ||
715 | // Query the tag file and make the analysis chain | |
716 | TChain * analysisChain = new TChain(fESDTreeName) ; | |
717 | analysisChain = tagAna->QueryTags(runCuts, lhcCuts, detCuts, evtCuts); | |
718 | ||
719 | // Process the events | |
720 | rv = ProcessChain(analysisChain) ; | |
721 | ||
722 | #else | |
723 | rv = kFALSE; | |
724 | #endif | |
725 | return rv ; | |
726 | } | |
727 | ||
728 | //______________________________________________________________________ | |
729 | Bool_t AliAnalysisGoodies::Register( const char * lfndir, const char * pfndir, const char * file) | |
730 | { | |
731 | // register files already stored in a MSS into the AliEn catalog | |
732 | // usage: Register(lfndir, pfndir, pfnFileName) | |
733 | // lfndir : AliEn directory ( ex: /alice/data/2006/LHC06c/PHOS_TestBeam/ ) | |
734 | // pfndir : MSS directory ( ex: /castor/cern.ch/alice/testbeam/phos/2006 ) | |
735 | // file : text file with a list of the file names to be registered | |
736 | ||
737 | Bool_t rv = kTRUE ; | |
738 | fTimer.Start() ; | |
739 | ||
740 | ifstream in; | |
741 | in.open(file); | |
742 | if ( in.bad() ) { | |
743 | AliError(Form("Cannot open file %s\n", file)) ; | |
744 | return kFALSE ; | |
745 | } | |
746 | ||
747 | TGrid::Connect("alien://"); | |
748 | ||
749 | char fileName[1024] ; | |
750 | ||
751 | while (1) { | |
752 | in >> fileName ; | |
753 | if (!in.good()) | |
754 | break; | |
755 | char lfn[1024] ; | |
756 | ||
757 | sprintf(lfn, "%s/%s", lfndir, fileName) ; | |
758 | ||
759 | char pfn[1024] ; | |
760 | ||
761 | sprintf(pfn, "castor://Alice::CERN::Castor2/%s/%s", pfndir, fileName) ; | |
762 | ||
763 | printf("Register %s as %s\n", pfn, lfn) ; | |
764 | ||
765 | gGrid->Register(lfn, pfn) ; | |
766 | } | |
767 | ||
768 | fTimer.Stop(); | |
769 | fTimer.Print(); | |
770 | ||
771 | return rv; | |
772 | } | |
773 | ||
774 | //______________________________________________________________________ | |
775 | void AliAnalysisGoodies::SetTasks(Int_t nb, AliAnalysisTask ** taskList, TClass ** inputType, TClass ** outputType) | |
776 | { | |
777 | // define a task with its output and input type | |
778 | ||
779 | ||
780 | fnumberOfTasks= nb; | |
781 | fTaskList = taskList ; | |
782 | fTaskInType = inputType ; | |
783 | fTaskOuType = outputType ; | |
784 | } |