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