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