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