Removing warnings (icc)
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisGoodies.cxx
CommitLineData
b86ddfbb 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15//_________________________________________________________________________
16// Various utilities usefull for analysis
17//
18//*-- Yves Schutz
19//////////////////////////////////////////////////////////////////////////////
20
21#include "AliAnalysisDataContainer.h"
22#include "AliTagAnalysis.h"
23#include "AliEventTagCuts.h"
24#include "AliRunTagCuts.h"
25#include "AliXMLCollection.h"
26#include "AliAnalysisGoodies.h"
27#include "AliAnalysisManager.h"
28#include "AliAnalysisTask.h"
29 //#include "AliPhotonAnalysisTask.h"
30#include "AliLog.h"
31
32#include <Riostream.h>
9c0977a1 33#ifdef WITHALIEN
b86ddfbb 34#include <TAlienCollection.h>
9c0977a1 35#endif
b86ddfbb 36#include <TChain.h>
37#include <TFileMerger.h>
38#include <TGrid.h>
39#include <TROOT.h>
40#include <TSystem.h>
d775a1d2 41#include <TEntryList.h>
b86ddfbb 42
43//______________________________________________________________________________
44AliAnalysisGoodies::AliAnalysisGoodies() :
45 fESDTreeName("esdTree"),
46 fnumberOfTasks(0),
47 fTaskList(0),
48 fTaskInType(0),
49 fTaskOuType(0)
50{
51 fTimer.Reset() ;
52
53 TString token = gSystem->Getenv("GRID_TOKEN") ;
54
55 if ( token == "OK" )
56 TGrid::Connect("alien://");
57 else
58 AliInfo("You are not connected to the GRID") ;
59}
60
61//______________________________________________________________________________
62void AliAnalysisGoodies::Help() const
63{
64 AliInfo("Analysis utilities:\n") ;
003ca69e 65 printf(" *** Alien2Local : copy files ESD files listed in an xml collection from AliEn catalog to local storage and creates a local xml collection \n") ;
66 printf(" usage: Alien2Local(in, out)\n") ;
b86ddfbb 67 printf(" in: a xml esd collection file name \n") ;
68 printf(" ou: the local directory where to save the esd root files \n") ;
69 printf(" *** Make : makes esd collection from tags \n") ;
70 printf(" usage: Make(tags, esds)\n") ;
71 printf(" tags: is either a tag root file or an xml tag collection \n") ;
72 printf(" esds: is an esd collection \n") ;
73 printf(" *** Merge : merges files listed in a xml collection \n") ;
74 printf(" usage Merge(collection, outputDile)\n") ;
75 printf(" collection: is a xml collection \n") ;
76 printf(" *** Process : process the events with an Analysis Task \n") ;
77 printf(" usage: Process(esdFile, tagCuts) \n") ;
78 printf(" esdFile: can be a root file with the ESD Tree ( ex: esd?AliESDs.root) \n") ;
79 printf(" or a root file with the Tag Tree ( ex: tag?Run100.Event0_100.ESD.tag.root) \n") ;
80 printf(" or a local or alien xml file with the ESD collection ( ex: esd?esdCollection.xml) \n") ;
81 printf(" or a local or alien xml file with the TAG collection ( ex: tag?tagCollection.xml) \n") ;
82 printf(" or a TChain of esd TTrees \n") ;
83 printf(" tagCuts: is the AliEventTagCuts (needed only for tag? cases \n") ;
84 printf(" *** Register: register files already stored in a MSS into the AliEn catalog\n") ;
85 printf(" usage: Register(lfndir, pfndir, pfnFileName) \n") ;
86 printf(" lfndir : AliEn directory ( ex: /alice/data/2006/LHC06c/PHOS_TestBeam/\n") ;
87 printf(" pfndir : MSS directory ( ex: /castor/cern.ch/alice/testbeam/phos/2006 \n") ;
88 printf(" file : text file with a list of the file names to be registered\n ") ;
89
90}
91
92//______________________________________________________________________
93const Bool_t AliAnalysisGoodies::Alien2Local(const TString collectionNameIn, const TString localDir)
94{
95 // copy files ESD files listed in an xml collection from AliEn catalog to local storage and creates a local xml collection
96 // usage: Alien2Local(in, out)
97 // in: a xml esd collection file name
98 // ou: the local directory where to save the esd root files
99
100 Bool_t rv = kTRUE ;
101
102 fTimer.Start() ;
103
104 AliXMLCollection * collectionIn = AliXMLCollection::Open(collectionNameIn) ;
105 collectionIn->Reset() ;
106
107 AliXMLCollection * collectionOu = new AliXMLCollection() ;
108 TString collectionNameOu(collectionIn->GetCollectionName()) ;
109 collectionNameOu.Append("Local") ;
110 collectionOu->SetCollectionName(collectionNameOu) ;
111 collectionOu->WriteHeader() ;
112
113 TFileMerger merger ;
114
115 const char* ocwd = gSystem->WorkingDirectory();
116
c16bb9ed 117 Int_t counter = 1 ;
b86ddfbb 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 ;
d775a1d2 128 dir += evtsNumber ;
129 char line[1024] ;
130 sprintf(line, ".! mkdir -p %s", dir.Data()) ;
131 gROOT->ProcessLine(line) ;
132 printf("***************************%s\n", line) ;
b86ddfbb 133 TEntryList * list = collectionIn->GetEventList("") ;
d775a1d2 134 if (!list)
135 list = new TEntryList() ;
d775a1d2 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())) ;
c16bb9ed 140 collectionOu->WriteBody(counter, collectionIn->GetGUID(""), collectionIn->GetLFN(""), dir, list) ;
141 counter++ ;
b86ddfbb 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//______________________________________________________________________
154const 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//______________________________________________________________________
182const 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//______________________________________________________________________
203const 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);
9c0977a1 211
212#ifdef WITHALIEN
b86ddfbb 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
9c0977a1 221#else
d775a1d2 222 rv = kFALSE;
9c0977a1 223#endif
d775a1d2 224 return rv ;
b86ddfbb 225}
226
227//______________________________________________________________________
228const 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
9c0977a1 239#ifdef WITHALIEN
240
b86ddfbb 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
9c0977a1 248 return rv ;
249#else
250 return kFALSE;
251#endif
b86ddfbb 252}
253
254//______________________________________________________________________
255const 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
9c0977a1 275#ifdef WITHALIEN
276
b86ddfbb 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
9c0977a1 313 return rv ;
314#else
315 return kFALSE;
316#endif
b86ddfbb 317}
318
319//______________________________________________________________________
320const Bool_t AliAnalysisGoodies::Process(TChain * chain)
321{
322 // process events starting from a chain of esd Trees
323 Bool_t rv = kFALSE ;
b86ddfbb 324 fTimer.Start() ;
325
326 rv = ProcessChain(chain) ;
327
328 fTimer.Stop();
329 fTimer.Print();
330
331 return rv ;
332}
333
334//______________________________________________________________________
335const Bool_t AliAnalysisGoodies::Process(const char * inFile)
336{
337 // process the events with an Analysis Task
338 // usage Process(esdFile)
339 // esdFile: is of the form opt?file_lfn
340 Bool_t rv = kFALSE ;
341 AliRunTagCuts * runCuts = 0x0 ;
342 AliEventTagCuts * evtCuts = 0x0 ;
343
344 rv = Process(inFile, runCuts, evtCuts) ;
345
346 return rv ;
347}
348
349//______________________________________________________________________
350const Bool_t AliAnalysisGoodies::Process(const char * inFile, AliRunTagCuts *runCuts, AliEventTagCuts * evtCuts )
351{
352 // process the events with an Analysis Task
353 // usage Process(esdFile, runtagCuts, evtTagCuts)
354 // esdFile: is of the form opt?file_lfn
355
356 Bool_t rv = kFALSE ;
357
358 fTimer.Start() ;
359
360 TString file(inFile) ;
361 if ( file.Contains("esd?") && file.Contains(".root") ) {
362 file.ReplaceAll("esd?", "") ;
363 rv = ProcessEsdFile(file.Data()) ;
364
365 } else if ( file.Contains("esd?") && file.Contains(".xml") ) {
366 file.ReplaceAll("esd?", "") ;
367 rv = ProcessEsdXmlCollection(file.Data()) ;
368
369 } else if (file.Contains("tag?") && file.Contains(".root") ) {
370 file.ReplaceAll("tag?", "") ;
371 rv = ProcessTagFile(file.Data(), runCuts, evtCuts) ;
372
373 } else if (file.Contains("tag?") && file.Contains(".xml") ) {
374 file.ReplaceAll("tag?", "") ;
375 rv = ProcessTagXmlCollection(file.Data(), runCuts, evtCuts) ;
376
377 } else {
378 AliError(Form("%s is not a valid file format", inFile)) ;
379 rv = kFALSE ;
380 }
381
382 fTimer.Stop();
383 fTimer.Print();
384
385 return rv ;
386}
387
388//______________________________________________________________________
389const Bool_t AliAnalysisGoodies::Process(const char * inFile, const char * runCuts, const char * evtCuts)
390{
391 // process the events with an Analysis Task
392 // usage Process(esdFile, runtagCuts, evtTagCuts)
393 // esdFile: is of the form opt?file_lfn
394
395 Bool_t rv = kFALSE ;
396
397 fTimer.Start() ;
398
399 TString file(inFile) ;
400 if ( file.Contains("esd?") && file.Contains(".root") ) {
401 file.ReplaceAll("esd?", "") ;
402 rv = ProcessEsdFile(file.Data()) ;
403
404 } else if ( file.Contains("esd?") && file.Contains(".xml") ) {
405 file.ReplaceAll("esd?", "") ;
406 rv = ProcessEsdXmlCollection(file.Data()) ;
407
408 } else if (file.Contains("tag?") && file.Contains(".root") ) {
409 file.ReplaceAll("tag?", "") ;
410 rv = ProcessTagFile(file.Data(), runCuts, evtCuts) ;
411
412 } else if (file.Contains("tag?") && file.Contains(".xml") ) {
413 file.ReplaceAll("tag?", "") ;
414 rv = ProcessTagXmlCollection(file.Data(), runCuts, evtCuts) ;
415
416 } else {
417 AliError(Form("%s is not a valid file format", inFile)) ;
418 rv = kFALSE ;
419 }
420
421 fTimer.Stop();
422 fTimer.Print();
423
424 return rv ;
425}
426
427//______________________________________________________________________
428const Bool_t AliAnalysisGoodies::ProcessChain(TChain * chain) const
429{
430 // Procees a TChain.
431
432 Bool_t rv = kTRUE ;
433
434 if (! fTaskList ) {
435 AliError("No tasks defined") ;
436 return kFALSE ;
437 }
3d868cda 438
b86ddfbb 439 // Make the analysis manager
3d868cda 440 AliAnalysisManager * mgr = new AliAnalysisManager("Goodies Manager", "Analysis manager created by AliAnalysisGoodies") ;
b86ddfbb 441
442 // Make tasks
443 // The top input must be common to all top tasks
444 TClass * classIn = fTaskInType[0] ;
c52c2132 445 AliAnalysisDataContainer * taskInput = mgr->CreateContainer("InputContainer", classIn, AliAnalysisManager::kInputContainer) ;
b86ddfbb 446 Int_t index ;
447 for (index = 0; index < fnumberOfTasks; index++) {
448 AliAnalysisTask * task = fTaskList[index] ;
449 mgr->AddTask(task) ;
450
451 // Create containers for input/output
452 TClass * classOu = fTaskOuType[index] ;
c52c2132 453 AliAnalysisDataContainer * taskOutput = mgr->CreateContainer(Form("OutputContainer%d",index), classOu, AliAnalysisManager::kOutputContainer,
454 Form("%s.root",task->GetName())) ;
b86ddfbb 455 mgr->ConnectInput (task, 0, taskInput);
456 mgr->ConnectOutput(task, 0, taskOutput);
457 }
458
459 // Open data
c52c2132 460// taskInput->SetData(chain);
b86ddfbb 461
462 if (mgr->InitAnalysis()) {
463 mgr->PrintStatus();
c52c2132 464// chain->Process(mgr);
465 mgr->StartAnalysis("local",chain);
b86ddfbb 466 } else
467 rv = kFALSE ;
468
469 return rv ;
470}
471
472//______________________________________________________________________
473const Bool_t AliAnalysisGoodies::ProcessEsdFile(const char * esdFile) const
474{
475 // process the events in a single ESD file with an Analysis Task
476 // usage ProcessLocalEsdFile(esdFile)
477 // esdFile: is the root file (local or in alien) with the ESD Tree ( ex: AliESDs.root)
478
479 Bool_t rv = kTRUE ;
480
481 printf("*** Process ***\n");
482 printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory());
483 printf("*** Coll = |%s| \n",esdFile);
484
485 // Makes the ESD chain
486 printf("*** Getting the Chain ***\n");
487 TChain* analysisChain = new TChain(fESDTreeName) ;
488 analysisChain->AddFile(esdFile);
489
490 // Process the events
491 rv = ProcessChain(analysisChain) ;
492
493 return rv;
494}
495
496//______________________________________________________________________
497const Bool_t AliAnalysisGoodies::ProcessTagFile(const char * tagFile, AliRunTagCuts *runCuts, AliEventTagCuts *evtCuts) const
498{
499 // process the events in a single Tag file with an Analysis Task
500 // usage ProcessLocalEsdFile(tagFile)
501 // tagFile: is the root file (local or in alien) with the Tag Tree (ex: Run102.Event0_100.ESD.tag.root)
502
503 Bool_t rv = kTRUE ;
504
505 if ( !evtCuts && !runCuts ) {
506 AliError("No Tag cuts provided") ;
507 return kFALSE ;
508 }
509
510 printf("*** Process ***\n");
511 printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory());
512 printf("*** Coll = |%s| \n",tagFile);
513
514 AliTagAnalysis * tagAna = new AliTagAnalysis();
515 rv = tagAna->AddTagsFile(tagFile);
516 if ( ! rv )
517 return rv ;
518
519 // Query the tag file and make the analysis chain
520 TChain * analysisChain = new TChain(fESDTreeName) ;
521 analysisChain = tagAna->QueryTags(runCuts, evtCuts);
522
523 // Process the events
524 rv = ProcessChain(analysisChain) ;
525
526 return rv;
527}
528
529//______________________________________________________________________
530const Bool_t AliAnalysisGoodies::ProcessTagFile(const char * tagFile, const char * runCuts, const char * evtCuts) const
531{
532 // process the events in a single Tag file with an Analysis Task
533 // usage ProcessLocalEsdFile(tagFile)
534 // tagFile: is the root file (local or in alien) with the Tag Tree (ex: Run102.Event0_100.ESD.tag.root)
535
536 Bool_t rv = kTRUE ;
537
538
539 if ( !evtCuts && !runCuts ) {
540 AliError("No Tag cuts provided") ;
541 return kFALSE ;
542 }
543
544 printf("*** Process ***\n");
545 printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory());
546 printf("*** Coll = |%s| \n",tagFile);
547
548 AliTagAnalysis * tagAna = new AliTagAnalysis();
549 rv = tagAna->AddTagsFile(tagFile);
550 if ( ! rv )
551 return rv ;
552
553 // Query the tag file and make the analysis chain
554 TChain * analysisChain = new TChain(fESDTreeName) ;
555 analysisChain = tagAna->QueryTags(runCuts, evtCuts);
556
557 // Process the events
558 rv = ProcessChain(analysisChain) ;
559
560 return rv;
561}
562
563//______________________________________________________________________
564const Bool_t AliAnalysisGoodies::ProcessEsdXmlCollection(const char * xmlFile) const
565{
566 // process the events in a xml ESD collection with an Analysis Task
567 // usage ProcessLocalEsdFile(xmlFile)
568 // xmlFile: is the local xml file with the ESD collection ( ex: esdCollection.xml)
569
570 Bool_t rv = kTRUE ;
571
572 printf("*** Process ***\n");
573 printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory());
574 printf("*** Coll = |%s| \n",xmlFile);
575
9c0977a1 576#ifdef WITHALIEN
577
b86ddfbb 578 TAlienCollection * collection = TAlienCollection::Open(xmlFile) ;
579 if (! collection) {
580 AliError(Form("%s not found", xmlFile)) ;
581 return kFALSE ;
582 }
583
584 TGridResult* result = collection->GetGridResult("");
585 TList* analysisfilelist = result->GetFileInfoList();
586
587 // Makes the ESD chain
588 printf("*** Getting the Chain ***\n");
589 TChain* analysisChain = new TChain(fESDTreeName);
590 analysisChain->AddFileInfoList(analysisfilelist);
591
592 // Process the events
593 rv = ProcessChain(analysisChain) ;
594
595 return rv ;
9c0977a1 596#else
597 return kFALSE;
598#endif
b86ddfbb 599}
600
601//______________________________________________________________________
602const Bool_t AliAnalysisGoodies::ProcessTagXmlCollection(const char * xmlFile, AliRunTagCuts *runCuts, AliEventTagCuts * evtCuts) const
603{
604 // process the events in a xml ESD collection with an Analysis Task
605 // usage ProcessLocalEsdFile(xmlFile)
606 // xmlFile: is the local xml file with the tag collection ( ex: tagCollection.xml)
607
608 Bool_t rv = kTRUE ;
609
610 if ( !evtCuts && !runCuts ) {
611 AliError("No Tag cuts provided") ;
612 return kFALSE ;
613 }
614
615 printf("*** Process ***\n");
616 printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory());
617 printf("*** Coll = |%s| \n",xmlFile);
618
619 // check if file is local or alien
620 if ( gSystem->AccessPathName(xmlFile) )
621 TGrid::Connect("alien://");
622
9c0977a1 623#ifdef WITHALIEN
624
b86ddfbb 625 TAlienCollection * collection = TAlienCollection::Open(xmlFile) ;
626 if (! collection) {
627 AliError(Form("%s not found", xmlFile)) ;
628 return kFALSE ;
629 }
630
631 TGridResult* result = collection->GetGridResult("");
632 AliTagAnalysis * tagAna = new AliTagAnalysis();
633 tagAna->ChainGridTags(result);
634
635 // Query the tag file and make the analysis chain
636 TChain * analysisChain = new TChain(fESDTreeName) ;
637 analysisChain = tagAna->QueryTags(runCuts, evtCuts);
638
639 // Process the events
640 rv = ProcessChain(analysisChain) ;
641
642 return rv ;
9c0977a1 643#else
644 return kFALSE;
645#endif
b86ddfbb 646}
647
648//______________________________________________________________________
649const Bool_t AliAnalysisGoodies::ProcessTagXmlCollection(const char * xmlFile, const char * runCuts, const char * evtCuts) const
650{
651 // process the events in a xml ESD collection with an Analysis Task
652 // usage ProcessLocalEsdFile(xmlFile)
653 // xmlFile: is the local xml file with the tag collection ( ex: tagCollection.xml)
654
655 Bool_t rv = kTRUE ;
656
657 if ( !evtCuts && !runCuts ) {
658 AliError("No Tag cuts provided") ;
659 return kFALSE ;
660 }
661
662 printf("*** Process ***\n");
663 printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory());
664 printf("*** Coll = |%s| \n",xmlFile);
665
9c0977a1 666#ifdef WITHALIEN
667
b86ddfbb 668 // check if file is local or alien
669 if ( gSystem->AccessPathName(xmlFile) )
670 TGrid::Connect("alien://");
671
672 TAlienCollection * collection = TAlienCollection::Open(xmlFile) ;
673 if (! collection) {
674 AliError(Form("%s not found", xmlFile)) ;
675 return kFALSE ;
676 }
677
678 TGridResult* result = collection->GetGridResult("");
679 AliTagAnalysis * tagAna = new AliTagAnalysis();
680 tagAna->ChainGridTags(result);
681
682 // Query the tag file and make the analysis chain
683 TChain * analysisChain = new TChain(fESDTreeName) ;
684 analysisChain = tagAna->QueryTags(runCuts, evtCuts);
685
686 // Process the events
687 rv = ProcessChain(analysisChain) ;
688
689 return rv ;
9c0977a1 690#else
691 return kFALSE;
692#endif
b86ddfbb 693}
694
695//______________________________________________________________________
696const Bool_t AliAnalysisGoodies::Register( const char * lfndir, const char * pfndir, const char * file)
697{
698 // register files already stored in a MSS into the AliEn catalog
699 // usage: Register(lfndir, pfndir, pfnFileName)
700 // lfndir : AliEn directory ( ex: /alice/data/2006/LHC06c/PHOS_TestBeam/ )
701 // pfndir : MSS directory ( ex: /castor/cern.ch/alice/testbeam/phos/2006 )
702 // file : text file with a list of the file names to be registered
703
704 Bool_t rv = kTRUE ;
705 fTimer.Start() ;
706
707 ifstream in;
708 in.open(file);
709 if ( in.bad() ) {
710 AliError(Form("Cannot open file %s\n", file)) ;
711 return kFALSE ;
712 }
713
714 TGrid::Connect("alien://");
715
716 char fileName[1024] ;
717
718 while (1) {
719 in >> fileName ;
720 if (!in.good())
721 break;
722 char lfn[1024] ;
723
724 sprintf(lfn, "%s/%s", lfndir, fileName) ;
725
726 char pfn[1024] ;
727
728 sprintf(pfn, "castor://Alice::CERN::Castor2/%s/%s", pfndir, fileName) ;
729
730 printf("Register %s as %s\n", pfn, lfn) ;
731
732 gGrid->Register(lfn, pfn) ;
733 }
734
735 fTimer.Stop();
736 fTimer.Print();
737
738 return rv;
739}
740
741//______________________________________________________________________
742void AliAnalysisGoodies::SetTasks(Int_t nb, AliAnalysisTask ** taskList, TClass ** inputType, TClass ** outputType)
743{
744 // define a task with its output and input type
745
746
747 fnumberOfTasks= nb;
748 fTaskList = taskList ;
749 fTaskInType = inputType ;
750 fTaskOuType = outputType ;
751}