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