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