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