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