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