Fix bug in building local list of valid files.
[u/mrichter/AliRoot.git] / ANALYSIS / AliTagAnalysis.cxx
CommitLineData
d08133e6 1/**************************************************************************
2 * Author: Panos Christakoglou. *
3 * Contributors are mentioned in the code where appropriate. *
4 * *
5 * Permission to use, copy, modify and distribute this software and its *
6 * documentation strictly for non-commercial purposes is hereby granted *
7 * without fee, provided that the above copyright notice appears in all *
8 * copies and that both the copyright notice and this permission notice *
9 * appear in the supporting documentation. The authors make no claims *
10 * about the suitability of this software for any purpose. It is *
11 * provided "as is" without express or implied warranty. *
12 **************************************************************************/
13
14/* $Id$ */
15
16//-----------------------------------------------------------------
17// AliTagAnalysis class
18// This is the class to deal with the tag analysis
19// Origin: Panos Christakoglou, UOA-CERN, Panos.Christakoglou@cern.ch
20//-----------------------------------------------------------------
21
22//ROOT
cd305eb1 23#include <Riostream.h>
d08133e6 24#include <TSystem.h>
25#include <TChain.h>
26#include <TFile.h>
27#include <TEventList.h>
28#include <TEntryList.h>
29#include <TTreeFormula.h>
f0f29480 30#include <TMap.h>
d08133e6 31
32//ROOT-AliEn
33#include <TGridResult.h>
34
35#include "AliLog.h"
36
37#include "AliRunTag.h"
38#include "AliEventTag.h"
39#include "AliTagAnalysis.h"
40#include "AliEventTagCuts.h"
2ec6a1d3 41#include "AliDetectorTagCuts.h"
42#include "AliLHCTagCuts.h"
d08133e6 43#include "AliRunTagCuts.h"
44#include "AliXMLCollection.h"
45
46class TTree;
47
48ClassImp(AliTagAnalysis)
49
50//___________________________________________________________________________
51AliTagAnalysis::AliTagAnalysis():
52 TObject(),
53 ftagresult(0x0),
54 fTagDirName(),
6cfbb923 55 fChain(0x0),
cd305eb1 56 fAnalysisType(),
57 fGlobalList(0) {
d08133e6 58 //Default constructor for a AliTagAnalysis
59}
60
61//___________________________________________________________________________
6cfbb923 62AliTagAnalysis::AliTagAnalysis(const char* type):
63 TObject(),
64 ftagresult(0x0),
65 fTagDirName(),
66 fChain(0x0),
cd305eb1 67 fAnalysisType(type),
68 fGlobalList(0) {
6cfbb923 69 //constructor for a AliTagAnalysis
70}
71
72//___________________________________________________________________________
d08133e6 73AliTagAnalysis::~AliTagAnalysis() {
cd305eb1 74 //Default destructor for a AliTagAnalysis
75 if(ftagresult) delete ftagresult;
76 if(fChain) delete fChain;
77 if(fGlobalList) delete fGlobalList;
d08133e6 78}
79
80//___________________________________________________________________________
0bf3148c 81Bool_t
82AliTagAnalysis::AddTagsFile(const char* alienUrl, Bool_t checkFile)
83{
84 /// Add a single tags file to the chain
85 ///
86 /// If checkFile=kTRUE (default) the file is opened to check
87 /// it can be and that it contains data.
88 /// It's safer but a lot longer...
89
90 if (!fChain) fChain = new TChain("T");
d08133e6 91
0bf3148c 92 if ( checkFile )
93 {
94 return ( fChain->AddFile(alienUrl,-1) > 0 );
95 }
96 else
97 {
98 return ( fChain->AddFile(alienUrl) > 0 );
99 }
d08133e6 100
d08133e6 101}
102
103//___________________________________________________________________________
104void AliTagAnalysis::ChainLocalTags(const char *dirname) {
105 //Searches the entries of the provided direcory
106 //Chains the tags that are stored locally
107 fTagDirName = dirname;
108 TString fTagFilename;
109
110 if (! fChain) fChain = new TChain("T");
6cfbb923 111 const char * tagPattern = 0x0;
112 if(fAnalysisType == "ESD") tagPattern = "ESD.tag.root";
113 else if(fAnalysisType == "AOD") tagPattern = "AOD.tag.root";
114 else AliFatal("Only ESD and AOD type is implemented!!!");
115
d08133e6 116 // Open the working directory
117 void * dirp = gSystem->OpenDirectory(fTagDirName);
118 const char * name = 0x0;
119 // Add all files matching *pattern* to the chain
120 while((name = gSystem->GetDirEntry(dirp))) {
9daedfd1 121 if (tagPattern && strstr(name,tagPattern)) {
d08133e6 122 fTagFilename = fTagDirName;
123 fTagFilename += "/";
124 fTagFilename += name;
125
126 fChain->Add(fTagFilename);
68550043 127 printf("Tag file %s\n", fTagFilename.Data());
128
d08133e6 129 }//pattern check
130 }//directory loop
0c57b780 131 //AliInfo(Form("Chained tag files: %d ",fChain->GetEntries()));
132 // AliDebug(Form("Chained tag files: %d ",fChain->GetEntries()));
68550043 133 fChain->ls();
134
d08133e6 135}
136
137
138//___________________________________________________________________________
727d922c 139TChain * AliTagAnalysis::ChainGridTags(TGridResult *res) {
d08133e6 140 //Loops overs the entries of the TGridResult
215dee2d 141 //Chains the tags that are stored in the GRID
d08133e6 142 ftagresult = res;
143 Int_t nEntries = ftagresult->GetEntries();
144
145 if (! fChain) fChain = new TChain("T");
146
147 TString gridname = "alien://";
148 TString alienUrl;
149
150 for(Int_t i = 0; i < nEntries; i++) {
151 alienUrl = ftagresult->GetKey(i,"turl");
152 fChain->Add(alienUrl);
727d922c 153 }//grid result loop
154 return fChain;
d08133e6 155}
156
157
158//___________________________________________________________________________
cd305eb1 159TChain *AliTagAnalysis::QueryTags(AliRunTagCuts *runTagCuts,
160 AliLHCTagCuts *lhcTagCuts,
161 AliDetectorTagCuts *detTagCuts,
162 AliEventTagCuts *evTagCuts) {
d08133e6 163 //Queries the tag chain using the defined
164 //event tag cuts from the AliEventTagCuts object
165 //and returns a TChain along with the associated TEventList
166 AliInfo(Form("Querying the tags........"));
b97856f9 167
68550043 168 TString aliceFile;
169 if(fAnalysisType == "ESD") aliceFile = "esdTree";
215dee2d 170 else if(fAnalysisType == "AOD") aliceFile = "aodTree";
6cfbb923 171 else AliFatal("Only ESD and AOD type is implemented!!!");
b97856f9 172
d08133e6 173 //ESD file chain
68550043 174 TChain *esdChain = new TChain(aliceFile.Data());
b97856f9 175 //global entry list
cd305eb1 176 fGlobalList = new TEntryList();
d08133e6 177
178 //Defining tag objects
5a561fa0 179 AliRunTag *tag = new AliRunTag;
1435c1da 180 // AliEventTag *evTag = 0x0;
04cb11d4 181 AliFileTag *flTag = 0x0;
182
d08133e6 183 fChain->SetBranchAddress("AliTAG",&tag);
184
9b4aee57 185 TString guid;
186 TString turl;
187 TString path;
d08133e6 188
9ce6b490 189 TEntryList* localList = new TEntryList();
68550043 190
d08133e6 191 Int_t iAccepted = 0;
68550043 192
215dee2d 193 for(Int_t iEntry = 0; iEntry < fChain->GetEntries(); iEntry++) {
194 fChain->GetEntry(iEntry);
04cb11d4 195 evTagCuts->InitializeTriggerClasses(tag->GetActiveTriggerClasses());
68550043 196
2ec6a1d3 197 if(runTagCuts->IsAccepted(tag)) {
198 if(lhcTagCuts->IsAccepted(tag->GetLHCTag())) {
199 if(detTagCuts->IsAccepted(tag->GetDetectorTags())) {
215dee2d 200 localList->Reset();
2ec6a1d3 201 Int_t iEvents = tag->GetNEvents();
04cb11d4 202
203 for (int i = 0; i < iEvents; i++) {
204 // evTag = tag->GetEventTag(i);
205 flTag = tag->GetFileTagForEvent(i);
206 guid = flTag->GetGUID();
207 turl = flTag->GetTURL();
208 path = flTag->GetPath();
209 localList->SetTreeName(aliceFile.Data());
210 if(turl!="") localList->SetFileName(turl.Data());
211 else localList->SetFileName(path.Data());
212
213 if(evTagCuts->IsAccepted(tag->GetEventTag(i))) localList->Enter(i);
214 }
215
216// const TClonesArray *tagList = tag->GetEventTags();
217// for(Int_t i = 0; i < iEvents; i++) {
218// evTag = (AliEventTag *) tagList->At(i);
219// guid = evTag->GetGUID();
220// turl = evTag->GetTURL();
221// path = evTag->GetPath();
222// localList->SetTreeName(aliceFile.Data());
223// if(turl!="") localList->SetFileName(turl.Data());
224// else localList->SetFileName(path.Data());
215dee2d 225
04cb11d4 226// if(evTagCuts->IsAccepted(evTag)) localList->Enter(i);
227// }//event loop
215dee2d 228 iAccepted += localList->GetN();
229 if(turl != "") esdChain->AddFile(turl);
230 else if(path != "") esdChain->AddFile(path);
231 fGlobalList->Add(localList);
2ec6a1d3 232 }//detector tag cuts
233 }//lhc tag cuts
d08133e6 234 }//run tags cut
5a561fa0 235 tag->Clear();
d08133e6 236 }//tag file loop
215dee2d 237 AliInfo(Form("Accepted events: %d", iAccepted));
5d0e8364 238 esdChain->ls();
68550043 239 esdChain->SetEntryList(fGlobalList,"ne");
9ce6b490 240 delete tag;
0c57b780 241 delete localList;
9ce6b490 242
68550043 243 return esdChain;
d08133e6 244}
245
246//___________________________________________________________________________
cd305eb1 247TChain *AliTagAnalysis::QueryTags(const char *fRunCut,
248 const char *fLHCCut,
249 const char *fDetectorCut,
250 const char *fEventCut) {
d08133e6 251 //Queries the tag chain using the defined
252 //event tag cuts from the AliEventTagCuts object
253 //and returns a TChain along with the associated TEventList
254 AliInfo(Form("Querying the tags........"));
215dee2d 255
68550043 256 TString aliceFile;
257 if(fAnalysisType == "ESD") aliceFile = "esdTree";
215dee2d 258 else if(fAnalysisType == "AOD") aliceFile = "aodTree";
6cfbb923 259 else AliFatal("Only ESD and AOD type is implemented!!!");
b97856f9 260
215dee2d 261
b97856f9 262 //ESD file chain
68550043 263 TChain *esdChain = new TChain(aliceFile.Data());
b97856f9 264 //global entry list
cd305eb1 265 fGlobalList = new TEntryList();
d08133e6 266
267 //Defining tag objects
940b4031 268 AliRunTag *tag = new AliRunTag;
1435c1da 269 // AliEventTag *evTag = 0x0;
d08133e6 270 fChain->SetBranchAddress("AliTAG",&tag);
271
9b4aee57 272 TString guid;
273 TString turl;
274 TString path;
d08133e6 275
276 TTreeFormula *fRunFormula = new TTreeFormula("fRun",fRunCut,fChain);
2ec6a1d3 277 TTreeFormula *fLHCFormula = new TTreeFormula("fLHC",fLHCCut,fChain);
278 TTreeFormula *fDetectorFormula = new TTreeFormula("fDetector",fDetectorCut,fChain);
279 TTreeFormula *fEventFormula = new TTreeFormula("fEvent",fEventCut,fChain);
d08133e6 280
940b4031 281 TEntryList* localList = new TEntryList();
68550043 282
215dee2d 283 Int_t current = -1;
d08133e6 284 Int_t iAccepted = 0;
215dee2d 285
cd305eb1 286 for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
d08133e6 287 fChain->GetEntry(iTagFiles);
288 if (current != fChain->GetTreeNumber()) {
289 fRunFormula->UpdateFormulaLeaves();
2ec6a1d3 290 fLHCFormula->UpdateFormulaLeaves();
291 fDetectorFormula->UpdateFormulaLeaves();
d08133e6 292 fEventFormula->UpdateFormulaLeaves();
293 current = fChain->GetTreeNumber();
294 }
215dee2d 295
d08133e6 296 if(fRunFormula->EvalInstance(iTagFiles) == 1) {
2ec6a1d3 297 if(fLHCFormula->EvalInstance(iTagFiles) == 1) {
68550043 298 if(fDetectorFormula->EvalInstance(iTagFiles) == 1) {
215dee2d 299 localList->Reset();
1435c1da 300 // Int_t iEvents = fEventFormula->GetNdata();
04cb11d4 301 // *** FIXME ***
302
303// const TClonesArray *tagList = tag->GetEventTags();
304// for(Int_t i = 0; i < iEvents; i++) {
305// evTag = (AliEventTag *) tagList->At(i);
306// guid = evTag->GetGUID();
307// turl = evTag->GetTURL();
308// path = evTag->GetPath();
309// localList->SetTreeName(aliceFile.Data());
310// localList->SetFileName(turl.Data());
311// if(fEventFormula->EvalInstance(i) == 1) localList->Enter(i);
312// }//event loop
68550043 313
215dee2d 314 if(path != "") esdChain->AddFile(path);
315 else if(turl != "") esdChain->AddFile(turl);
316 fGlobalList->Add(localList);
317 iAccepted += localList->GetN();
2ec6a1d3 318 }//detector tag cuts
319 }//lhc tag cuts
d08133e6 320 }//run tag cut
68550043 321 tag->Clear();
d08133e6 322 }//tag file loop
215dee2d 323 AliInfo(Form("Accepted events: %d", iAccepted));
68550043 324 esdChain->SetEntryList(fGlobalList,"ne");
940b4031 325
326 delete tag;
0c57b780 327 delete localList;
68550043 328 return esdChain;
d08133e6 329}
330
331//___________________________________________________________________________
0bf3148c 332Bool_t
333AliTagAnalysis::CreateXMLCollection(const char* name,
334 AliRunTagCuts *runTagCuts,
335 AliLHCTagCuts *lhcTagCuts,
336 AliDetectorTagCuts *detTagCuts,
337 AliEventTagCuts *evTagCuts)
338{
339 /// Queries the tag chain using the defined run, lhc, detector and event tag objects
340 /// and create a XML collection named "name.xml"
341 /// if any of the runTagCuts, lhcTagCuts, detTagCuts or evTagCuts is NULL
342 /// check on that object will be skipped.
343
d08133e6 344 AliInfo(Form("Creating the collection........"));
0bf3148c 345
346 if (!fChain)
347 {
348 AliError("fChain is NULL. Cannot make a collection from that !");
349 return kFALSE;
350 }
351
0bf3148c 352 AliXMLCollection collection;
353 collection.SetCollectionName(name);
354 collection.WriteHeader();
355
9b4aee57 356 TString guid;
357 TString turl;
358 TString lfn;
d08133e6 359
0bf3148c 360 TEntryList localList;
68550043 361 Int_t iAccepted = 0;
215dee2d 362
f0f29480 363 Int_t iRejectedRun = 0;
364 Int_t iRejectedLHC = 0;
365 Int_t iRejectedDet = 0;
366 Int_t iRejectedEvt = 0;
0bf3148c 367
f0f29480 368 Int_t iTotalEvents = 0;
0bf3148c 369
f0f29480 370 Int_t iAcceptedEvtInFile = 0;
371 Int_t iRejectedEvtInFile = 0;
0bf3148c 372
d08133e6 373 //Defining tag objects
0bf3148c 374 AliRunTag* tag = new AliRunTag;
d08133e6 375 fChain->SetBranchAddress("AliTAG",&tag);
04cb11d4 376
377 Int_t iTagFiles = 0;
0bf3148c 378
1435c1da 379 // AliEventTag *evTag = 0x0;
04cb11d4 380 AliFileTag *flTag = 0x0;
381
382 // for(Int_t iTagFiles = 0; iTagFiles < fChain->GetListOfFiles()->GetEntries(); ++iTagFiles)
383 for(Int_t iRunTags = 0; iRunTags < fChain->GetEntries(); ++iRunTags)
0bf3148c 384 {
04cb11d4 385 fChain->GetEntry(iRunTags);
68550043 386 //Event list
f0f29480 387 iTotalEvents += tag->GetNEvents();
215dee2d 388 localList.Reset();
389
04cb11d4 390 evTagCuts->InitializeTriggerClasses(tag->GetActiveTriggerClasses());
391
0bf3148c 392 if ( !runTagCuts || ( runTagCuts && runTagCuts->IsAccepted(tag) ) )
0bf3148c 393 {
215dee2d 394 if ( !lhcTagCuts || ( lhcTagCuts && lhcTagCuts->IsAccepted(tag->GetLHCTag())) )
395 {
396 if ( !detTagCuts || ( detTagCuts && detTagCuts->IsAccepted(tag->GetDetectorTags())) )
397 {
04cb11d4 398 for (int iChunk = 0; iChunk < tag->GetNFiles(); iChunk++, iTagFiles++)
215dee2d 399 {
04cb11d4 400 iRejectedEvtInFile = 0;
401 iAcceptedEvtInFile = 0;
402
061af452 403 localList.Reset();
404
04cb11d4 405 flTag = tag->GetFileTag(iChunk);
406 guid = flTag->GetGUID();
407 turl = flTag->GetTURL();
215dee2d 408 lfn = turl(8,turl.Length());
061af452 409
04cb11d4 410 for (int i = 0; i<flTag->GetNEvents(); i++)
215dee2d 411 {
04cb11d4 412 // evTag = flTag->GetEventTag(i);
061af452 413
04cb11d4 414 if( !evTagCuts || ( evTagCuts && evTagCuts->IsAccepted(flTag->GetEventTag(i))) )
415 {
416 localList.Enter(i);
417 iAcceptedEvtInFile++;
418 }
419 else
420 {
421 ++iRejectedEvt;
422 ++iRejectedEvtInFile;
423 }
215dee2d 424 }
061af452 425 // *** FIXME ***
04cb11d4 426// Int_t i(0);
427
428// TIter next(tag->GetEventTags());
429// AliEventTag* evTag(0x0);
430// iRejectedEvtInFile = 0;
431// iAcceptedEvtInFile = 0;
432// while ( ( evTag = static_cast<AliEventTag*>(next()) ) )
433// {
434// guid = evTag->GetGUID();
435// turl = evTag->GetTURL();
436// lfn = turl(8,turl.Length());
437// if( !evTagCuts || ( evTagCuts && evTagCuts->IsAccepted(evTag)) )
438// {
439// localList.Enter(i);
440// iAcceptedEvtInFile++;
441// }
442// else
443// {
444// ++iRejectedEvt;
445// ++iRejectedEvtInFile;
446// }
447// ++i;
448// }//event loop
449 iAccepted += localList.GetN();
450 collection.WriteBody(iTagFiles+1,guid,lfn,turl,&localList,iAcceptedEvtInFile,iRejectedEvtInFile);
451 } // chunk loop
215dee2d 452 }//detector tag cuts
453 else {
454 iRejectedDet += tag->GetNEvents();
455 }
456 }//lhc tag cuts
457 else {
458 iRejectedLHC += tag->GetNEvents();
459 }
460 }//run tag cuts
f0f29480 461 else {
462 iRejectedRun += tag->GetNEvents();
463 }
5a561fa0 464 tag->Clear();
0bf3148c 465 } //tag file loop
466
467 collection.WriteSummary(iTotalEvents, iAccepted, iRejectedRun, iRejectedLHC, iRejectedDet, iRejectedEvt);
468 collection.Export();
940b4031 469
d08133e6 470 return kTRUE;
471}
472
473//___________________________________________________________________________
cd305eb1 474Bool_t AliTagAnalysis::CreateXMLCollection(const char* name,
475 const char *fRunCut,
476 const char *fLHCCut,
477 const char *fDetectorCut,
478 const char *fEventCut) {
d08133e6 479 //Queries the tag chain using the defined
480 //event tag cuts from the AliEventTagCuts object
481 //and returns a XML collection
482 AliInfo(Form("Creating the collection........"));
483
68550043 484
d08133e6 485 AliXMLCollection *collection = new AliXMLCollection();
486 collection->SetCollectionName(name);
487 collection->WriteHeader();
488
9b4aee57 489 TString guid;
490 TString turl;
491 TString lfn;
940b4031 492 TEntryList* localList = new TEntryList();
d08133e6 493
68550043 494 Int_t iAccepted = 0;
cd305eb1 495
f0f29480 496 Int_t iRejectedRun = 0;
497 Int_t iRejectedLHC = 0;
498 Int_t iRejectedDet = 0;
499 Int_t iRejectedEvt = 0;
500
501 Int_t iTotalEvents = 0;
502
503 Int_t iAcceptedEvtInFile = 0;
504 Int_t iRejectedEvtInFile = 0;
505
cd305eb1 506 //Defining tag objects
940b4031 507 AliRunTag *tag = new AliRunTag;
1435c1da 508 // AliEventTag *evTag = 0x0;
cd305eb1 509 fChain->SetBranchAddress("AliTAG",&tag);
510
511 TTreeFormula *fRunFormula = new TTreeFormula("fRun",fRunCut,fChain);
512 TTreeFormula *fLHCFormula = new TTreeFormula("fLHC",fLHCCut,fChain);
513 TTreeFormula *fDetectorFormula = new TTreeFormula("fDetector",fDetectorCut,fChain);
514 TTreeFormula *fEventFormula = new TTreeFormula("fEvent",fEventCut,fChain);
215dee2d 515
cd305eb1 516 Int_t current = -1;
215dee2d 517
cd305eb1 518 for(Int_t iTagFiles = 0; iTagFiles < fChain->GetEntries(); iTagFiles++) {
68550043 519
cd305eb1 520 fChain->GetEntry(iTagFiles);
521 if (current != fChain->GetTreeNumber()) {
522 fRunFormula->UpdateFormulaLeaves();
523 fLHCFormula->UpdateFormulaLeaves();
524 fDetectorFormula->UpdateFormulaLeaves();
525 fEventFormula->UpdateFormulaLeaves();
526 current = fChain->GetTreeNumber();
215dee2d 527 }
528
529 //Event list
f0f29480 530 iTotalEvents += tag->GetNEvents();
215dee2d 531 localList->Reset();
cd305eb1 532 if(fRunFormula->EvalInstance(iTagFiles) == 1) {
533 if(fLHCFormula->EvalInstance(iTagFiles) == 1) {
534 if(fDetectorFormula->EvalInstance(iTagFiles) == 1) {
1435c1da 535 // Int_t iEvents = fEventFormula->GetNdata();
04cb11d4 536 // *** FIXME ***
537
538
539// const TClonesArray *tagList = tag->GetEventTags();
540// iRejectedEvtInFile = 0;
541// iAcceptedEvtInFile = 0;
542// for(Int_t i = 0; i < iEvents; i++) {
543// evTag = (AliEventTag *) tagList->At(i);
544// guid = evTag->GetGUID();
545// turl = evTag->GetTURL();
546// lfn = turl(8,turl.Length());
547// if(fEventFormula->EvalInstance(i) == 1) {
548// localList->Enter(i);
549// iAcceptedEvtInFile++;
550// }
551// else {
552// iRejectedEvt++;
553// iRejectedEvtInFile++;
554// }
555// }//event loop
556
215dee2d 557 collection->WriteBody(iTagFiles+1,guid,lfn,turl,localList,iAcceptedEvtInFile, iRejectedEvtInFile);
558 iAccepted += localList->GetN();
cd305eb1 559 }//detector tag cuts
f0f29480 560 else {
561 iRejectedDet += tag->GetNEvents();
562 }
cd305eb1 563 }//lhc tag cuts
f0f29480 564 else {
565 iRejectedLHC += tag->GetNEvents();
566 }
cd305eb1 567 }//run tag cuts
f0f29480 568 else {
569 iRejectedRun += tag->GetNEvents();
570 }
cd305eb1 571 }//tag file loop
f0f29480 572 collection->WriteSummary(iTotalEvents, iAccepted, iRejectedRun, iRejectedLHC, iRejectedDet, iRejectedEvt);
68550043 573 collection->Export();
215dee2d 574
940b4031 575 delete tag;
cd305eb1 576 return kTRUE;
577}
578
579//___________________________________________________________________________
d08133e6 580TChain *AliTagAnalysis::GetInputChain(const char* system, const char *wn) {
581 //returns the chain+event list - used in batch sessions
582 // this function will be removed once the new root
583 // improvements are committed
584 TString fsystem = system;
585 Int_t iAccepted = 0;
6cfbb923 586
88fb0edc 587 TChain *fAnalysisChain = 0;
588 if(fAnalysisType == "ESD") fAnalysisChain = new TChain("esdTree");
589 else if(fAnalysisType == "AOD") fAnalysisChain = new TChain("aodTree");
6cfbb923 590 else AliFatal("Only ESD and AOD type is implemented!!!");
591
d08133e6 592 //Event list
593 TEventList *fEventList = new TEventList();
594 AliXMLCollection *collection = AliXMLCollection::Open(wn);
595
596 collection->Reset();
597 while (collection->Next()) {
598 AliInfo(Form("Adding: %s",collection->GetTURL("")));
9daedfd1 599 if (fAnalysisChain) fAnalysisChain->Add(collection->GetTURL(""));
d08133e6 600 TEntryList *list = (TEntryList *)collection->GetEventList("");
601 for(Int_t i = 0; i < list->GetN(); i++) fEventList->Enter(iAccepted+list->GetEntry(i));
602
603 if(fsystem == "pp") iAccepted += 100;
604 else if(fsystem == "PbPb") iAccepted += 1;
605 }
606
9daedfd1 607 if (fAnalysisChain) fAnalysisChain->SetEventList(fEventList);
d08133e6 608
609 AliInfo(Form("Number of selected events: %d",fEventList->GetN()));
610
6cfbb923 611 return fAnalysisChain;
d08133e6 612}
613
614//___________________________________________________________________________
0bf3148c 615TChain*
616AliTagAnalysis::CreateChainFromCollection(const char* collectionname, const char* treename)
617{
618 /// Build a TChain (with its TEntryList object attached) from an XML collection.
619 /// Returned chain must be deleted by the client.
620
621 TString streename(treename);
622 if ( streename != "esdTree" && streename != "aodTree" )
623 {
624 AliErrorClass("Only esdTree and aodTree implemented so far...");
625 return 0x0;
626 }
627
628 TChain* chain = new TChain(streename.Data());
6cfbb923 629
0bf3148c 630 // create the event list for the chain. Will be attached to the chain
631 // which thus becomes the owner of it.
632 TEntryList* elist = new TEntryList;
633
634 AliXMLCollection* collection = AliXMLCollection::Open(collectionname);
d08133e6 635
f0f29480 636 // Tag selection summary per file
0bf3148c 637 TMap* tagCutSummary = new TMap();
f0f29480 638 tagCutSummary->SetName("TagCutSumm");
639
0bf3148c 640 Int_t iAccepted = 0;
641
d08133e6 642 collection->Reset();
0bf3148c 643
644 while (collection->Next())
645 {
646 AliDebugClass(1,Form("Adding: %s",collection->GetTURL("")));
647 chain->Add(collection->GetTURL(""));
648 TEntryList *list = collection->GetEventList("");
649 list->SetTreeName(streename.Data());
d08133e6 650 list->SetFileName(collection->GetTURL(""));
0bf3148c 651 elist->Add(list);
d08133e6 652 iAccepted += list->GetN();
f0f29480 653 if (collection->GetCutSumm())
0bf3148c 654 {
f0f29480 655 tagCutSummary->Add(new TObjString(collection->GetTURL("")), new TObjString(collection->GetCutSumm()));
0bf3148c 656 }
d08133e6 657 }
658
0bf3148c 659 chain->SetEntryList(elist,"ne"); // ne => do not expand tree name and/or file names
d08133e6 660
0bf3148c 661 AliDebugClass(1,Form("Number of selected events: %d",iAccepted));
d08133e6 662
0bf3148c 663 TList *aUserInfo = chain->GetUserInfo();
f0f29480 664 aUserInfo->Add(tagCutSummary);
665
666 Int_t iAccEv;
667 Int_t iTotalEvents;
668 Int_t iRejRun;
669 Int_t iRejLHC;
670 Int_t iRejDet;
671 Int_t iRejEvt;
672
673 collection->GetCollectionSummary(&iTotalEvents, &iAccEv, &iRejRun, &iRejLHC, &iRejDet, &iRejEvt);
674
675 char nstr[2000];
676
accb0197 677 snprintf(nstr, 2000, "TotalEvents=%i", iTotalEvents);
f0f29480 678 TObjString *iTotStr = new TObjString(nstr);
679 aUserInfo->Add(iTotStr);
680
accb0197 681 snprintf(nstr, 2000, "AcceptedEvents=%i", iAccepted);
f0f29480 682 TObjString *iAccStr = new TObjString(nstr);
683 aUserInfo->Add(iAccStr);
684
accb0197 685 snprintf(nstr, 2000, "RejectedRun=%i", iRejRun);
f0f29480 686 TObjString *iRejRunStr = new TObjString(nstr);
687 aUserInfo->Add(iRejRunStr);
688
accb0197 689 snprintf(nstr, 2000, "RejectedLHC=%i", iRejLHC);
f0f29480 690 TObjString *iRejLHCStr = new TObjString(nstr);
691 aUserInfo->Add(iRejLHCStr);
692
accb0197 693 snprintf(nstr, 2000, "RejectedDet=%i", iRejDet);
f0f29480 694 TObjString *iRejDetStr = new TObjString(nstr);
695 aUserInfo->Add(iRejDetStr);
696
accb0197 697 snprintf(nstr, 2000, "RejectedEvt=%i", iRejEvt);
f0f29480 698 TObjString *iRejEvtStr = new TObjString(nstr);
699 aUserInfo->Add(iRejEvtStr);
700
0bf3148c 701 return chain;
d08133e6 702}