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