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