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