Fixes for Coverity defects
[u/mrichter/AliRoot.git] / PHOS / AliPHOSLoader.cxx
CommitLineData
88cb7938 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
803d1ab0 16/* $Id$ */
88cb7938 17
702ab87e 18/* History of cvs commits:
19 *
20 * $Log$
3f7dbdb7 21 * Revision 1.18 2006/08/28 10:01:56 kharlov
22 * Effective C++ warnings fixed (Timur Pocheptsov)
23 *
3663622c 24 * Revision 1.17 2006/08/25 16:00:53 kharlov
25 * Compliance with Effective C++AliPHOSHit.cxx
26 *
e2429969 27 * Revision 1.16 2006/08/01 12:15:04 cvetan
28 * Adding a constructor from TFolder. Needed by AliReconstruction plugin scheme
29 *
e15840a7 30 * Revision 1.15 2005/07/12 20:07:35 hristov
31 * Changes needed to run simulation and reconstrruction in the same AliRoot session
32 *
7c193632 33 * Revision 1.14 2005/05/28 14:19:04 schutz
34 * Compilation warnings fixed by T.P.
35 *
702ab87e 36 */
37
88cb7938 38//_________________________________________________________________________
39// A singleton. This class should be used in the analysis stage to get
40// reconstructed objects: Digits, RecPoints, TrackSegments and RecParticles,
41// instead of directly reading them from galice.root file. This container
42// ensures, that one reads Digits, made of these particular digits, RecPoints,
43// made of these particular RecPoints, TrackSegments and RecParticles.
44// This becomes non trivial if there are several identical branches, produced with
45// different set of parameters.
46//
47// An example of how to use (see also class AliPHOSAnalyser):
48// for(Int_t irecp = 0; irecp < gime->NRecParticles() ; irecp++)
49// AliPHOSRecParticle * part = gime->RecParticle(1) ;
50// ................
51// please->GetEvent(event) ; // reads new event from galice.root
52//
bfae5a5d 53//-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
54//-- Completely redesigned by Dmitri Peressounko March 2001
88cb7938 55//
bfae5a5d 56//-- YS June 2001 : renamed the original AliPHOSIndexToObject and make
57//-- systematic usage of TFolders without changing the interface
88cb7938 58//////////////////////////////////////////////////////////////////////////////
59
60
61// --- ROOT system ---
62
63#include "TFile.h"
64#include "TTree.h"
65#include "TROOT.h"
88cb7938 66
67// --- Standard library ---
88cb7938 68
69// --- AliRoot header files ---
a9bbb414 70#include "AliObjectLoader.h"
351dd634 71#include "AliLog.h"
88cb7938 72#include "AliPHOSLoader.h"
73#include "AliPHOS.h"
e957fea8 74#include "AliPHOSHit.h"
88cb7938 75
76ClassImp(AliPHOSLoader)
77
78
79const TString AliPHOSLoader::fgkHitsName("HITS");//Name for TClonesArray with hits from one event
80const TString AliPHOSLoader::fgkSDigitsName("SDIGITS");//Name for TClonesArray
81const TString AliPHOSLoader::fgkDigitsName("DIGITS");//Name for TClonesArray
82const TString AliPHOSLoader::fgkEmcRecPointsName("EMCRECPOINTS");//Name for TClonesArray
83const TString AliPHOSLoader::fgkCpvRecPointsName("CPVRECPOINTS");//Name for TClonesArray
84const TString AliPHOSLoader::fgkTracksName("TRACKS");//Name for TClonesArray
85const TString AliPHOSLoader::fgkRecParticlesName("RECPARTICLES");//Name for TClonesArray
86
87const TString AliPHOSLoader::fgkEmcRecPointsBranchName("PHOSEmcRP");//Name for branch with EMC Reconstructed Points
88const TString AliPHOSLoader::fgkCpvRecPointsBranchName("PHOSCpvRP");//Name for branch with CPV Reconstructed Points
89const TString AliPHOSLoader::fgkTrackSegmentsBranchName("PHOSTS");//Name for branch with TrackSegments
90const TString AliPHOSLoader::fgkRecParticlesBranchName("PHOSRP");//Name for branch with Reconstructed Particles
91//____________________________________________________________________________
daf018d5 92AliPHOSLoader::AliPHOSLoader() : fBranchTitle(), fDebug(0), fTmpHits(0x0)
3663622c 93{
94 //def ctor
8d8258f6 95 fTmpHits = new TClonesArray("AliPHOSHit",1000);
3663622c 96}
88cb7938 97//____________________________________________________________________________
3663622c 98AliPHOSLoader::AliPHOSLoader(const Char_t *detname,const Char_t *eventfoldername) :
99 AliLoader(detname, eventfoldername),
daf018d5 100 fBranchTitle(), fDebug(0), fTmpHits(0x0)
88cb7938 101{
3663622c 102 //ctor
88cb7938 103}
104//____________________________________________________________________________
e15840a7 105AliPHOSLoader::AliPHOSLoader(const Char_t *detname,TFolder *topfolder):
8d8258f6 106 AliLoader(detname,topfolder),
daf018d5 107 fBranchTitle(), fDebug(0), fTmpHits(0x0)
3663622c 108
e15840a7 109{
3663622c 110 //ctor
8d8258f6 111 fTmpHits = new TClonesArray("AliPHOSHit",1000);
e15840a7 112}
dc86eb51 113
e2429969 114//____________________________________________________________________________
88cb7938 115
116AliPHOSLoader::~AliPHOSLoader()
117{
118 //remove and delete arrays
119 Clean(fgkHitsName);
120 Clean(fgkSDigitsName);
121 Clean(fgkDigitsName);
122 Clean(fgkEmcRecPointsName);
123 Clean(fgkCpvRecPointsName);
124 Clean(fgkTracksName);
125 Clean(fgkRecParticlesName);
0ef40383 126 CleanFolders() ;
88cb7938 127}
88cb7938 128
bb30e79d 129//____________________________________________________________________________
88cb7938 130void AliPHOSLoader::CleanFolders()
131 {
132 CleanRecParticles();
133 AliLoader::CleanFolders();
134 }
88cb7938 135
bb30e79d 136//____________________________________________________________________________
88cb7938 137Int_t AliPHOSLoader::SetEvent()
138{
139//Cleans loaded stuff and and sets Files and Directories
140// do not post any data to folder/tasks
141
142
143 Int_t retval = AliLoader::SetEvent();
144 if (retval)
145 {
351dd634 146 AliError("returned error");
88cb7938 147 return retval;
148 }
149
150
151 if (Hits()) Hits()->Clear();
152 if (SDigits()) SDigits()->Clear();
153 if (Digits()) Digits()->Clear();
154 if (EmcRecPoints()) EmcRecPoints()->Clear();
155 if (CpvRecPoints()) CpvRecPoints()->Clear();
156 if (TrackSegments()) TrackSegments()->Clear();
157 if (RecParticles()) RecParticles()->Clear();
158
159 return 0;
160}
88cb7938 161
bb30e79d 162//____________________________________________________________________________
88cb7938 163Int_t AliPHOSLoader::GetEvent()
164{
165//Overloads GetEvent method called by AliRunLoader::GetEvent(Int_t) method
166//to add Rec Particles specific for PHOS
167
168//First call the original method to get whatever from std. setup is needed
169 Int_t retval;
170
171 retval = AliLoader::GetEvent();
172 if (retval)
173 {
351dd634 174 AliError("returned error");
88cb7938 175 return retval;
176 }
177
178 if (GetHitsDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadHits();
179 if (GetSDigitsDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadSDigits();
180 if (GetDigitsDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadDigits();
181 if (GetRecPointsDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadRecPoints();
182 if (GetTracksDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadTracks();
183 if (GetRecParticlesDataLoader()->GetBaseDataLoader()->IsLoaded()) ReadRecParticles();
184
185
186//Now, check if RecPart were loaded
187 return 0;
188}
88cb7938 189
ba999b0a 190// //____________________________________________________________________________
191// const AliPHOS * AliPHOSLoader::PHOS()
192// {
193// // returns the PHOS object
194// AliPHOS * phos = dynamic_cast<AliPHOS*>(GetModulesFolder()->FindObject(fDetectorName));
195// if ( phos == 0x0)
196// if (fDebug)
197// cout << "WARNING: AliPHOSLoader::PHOS -> PHOS module not found in Folders" << endl ;
198// return phos ;
199// }
88cb7938 200
201//____________________________________________________________________________
88cb7938 202Int_t AliPHOSLoader::LoadHits(Option_t* opt)
203{
204//------- Hits ----------------------
205//Overload (extends) LoadHits implemented in AliLoader
206//
207 Int_t res;
208
209 //First call the AliLoader's method to send the TreeH to folder
210 res = AliLoader::LoadHits(opt);
211
212 if (res)
213 {//oops, error
351dd634 214 AliError("returned error");
88cb7938 215 return res;
216 }
217
218 //read the data from tree in folder and send it to folder
219 res = ReadHits();
220 return 0;
221}
222
223
224//____________________________________________________________________________
225Int_t AliPHOSLoader::LoadSDigits(Option_t* opt)
89308175 226{
227 //---------- SDigits -------------------------
88cb7938 228 Int_t res;
229 //First call the AliLoader's method to send the TreeS to folder
230 res = AliLoader::LoadSDigits(opt);
231 if (res)
232 {//oops, error
351dd634 233 AliError("returned error");
88cb7938 234 return res;
235 }
236 return ReadSDigits();
237
238}
239//____________________________________________________________________________
240Int_t AliPHOSLoader::LoadDigits(Option_t* opt)
241{
89308175 242 //---------- Digits -------------------------
88cb7938 243 Int_t res;
244 //First call the AliLoader's method to send the TreeS to folder
245 res = AliLoader::LoadDigits(opt);
246 if (res)
247 {//oops, error
351dd634 248 AliError("returned error");
88cb7938 249 return res;
250 }
251 return ReadDigits();
252}
253//____________________________________________________________________________
254Int_t AliPHOSLoader::LoadRecPoints(Option_t* opt)
89308175 255{
256 // -------------- RecPoints -------------------------------------------
88cb7938 257 Int_t res;
258 //First call the AliLoader's method to send the TreeR to folder
259 res = AliLoader::LoadRecPoints(opt);
260 if (res)
261 {//oops, error
351dd634 262 AliError("returned error");
88cb7938 263 return res;
264 }
265
266 TFolder * phosFolder = GetDetectorDataFolder();
267 if ( phosFolder == 0x0 )
268 {
351dd634 269 AliError("Can not get detector data folder");
88cb7938 270 return 1;
271 }
272 return ReadRecPoints();
273}
274//____________________________________________________________________________
275
276Int_t AliPHOSLoader::LoadTracks(Option_t* opt)
277{
278 //Loads Tracks: Open File, Reads Tree and posts, Read Data and Posts
351dd634 279 AliDebug(1, Form("opt = %s",opt));
88cb7938 280 Int_t res;
281 res = AliLoader::LoadTracks(opt);
282 if (res)
283 {//oops, error
351dd634 284 AliError("returned error");
88cb7938 285 return res;
286 }
287 return ReadTracks();
288}
289
290//____________________________________________________________________________
291Int_t AliPHOSLoader::LoadRecParticles(Option_t* opt)
89308175 292{
293 // -------------- RecPoints -------------------------------------------
88cb7938 294 Int_t res;
295 //First call the AliLoader's method to send the TreeT to folder
296 res = AliLoader::LoadRecParticles(opt);
297 if (res)
298 {//oops, error
351dd634 299 AliError("returned error");
88cb7938 300 return res;
301 }
302 return ReadRecParticles();
303}
304
305//____________________________________________________________________________
702ab87e 306//PostHits etc. PostXXX must be const - not to hide virtual functions
307//from base class AliLoader, but they call non-constant functions ReadXXX
308//so I have to const_cast this pointer
309Int_t AliPHOSLoader::PostHits()const
88cb7938 310{
89308175 311 // -------------- Hits -------------------------------------------
88cb7938 312 Int_t reval = AliLoader::PostHits();
313 if (reval)
314 {
351dd634 315 AliError("returned error");
88cb7938 316 return reval;
317 }
702ab87e 318
319 return const_cast<AliPHOSLoader *>(this)->ReadHits();
88cb7938 320}
321//____________________________________________________________________________
322
702ab87e 323Int_t AliPHOSLoader::PostSDigits()const
88cb7938 324{
89308175 325 // -------------- SDigits -------------------------------------------
88cb7938 326 Int_t reval = AliLoader::PostSDigits();
327 if (reval)
328 {
351dd634 329 AliError("returned error");
88cb7938 330 return reval;
331 }
702ab87e 332 return const_cast<AliPHOSLoader *>(this)->ReadSDigits();
88cb7938 333}
334//____________________________________________________________________________
335
702ab87e 336Int_t AliPHOSLoader::PostDigits()const
88cb7938 337{
89308175 338 // -------------- Digits -------------------------------------------
88cb7938 339 Int_t reval = AliLoader::PostDigits();
340 if (reval)
341 {
351dd634 342 AliError("returned error");
88cb7938 343 return reval;
344 }
702ab87e 345 return const_cast<AliPHOSLoader *>(this)->ReadDigits();
88cb7938 346}
347//____________________________________________________________________________
348
702ab87e 349Int_t AliPHOSLoader::PostRecPoints()const
88cb7938 350{
89308175 351 // -------------- RecPoints -------------------------------------------
88cb7938 352 Int_t reval = AliLoader::PostRecPoints();
353 if (reval)
354 {
351dd634 355 AliError("returned error");
88cb7938 356 return reval;
357 }
702ab87e 358 return const_cast<AliPHOSLoader *>(this)->ReadRecPoints();
88cb7938 359}
360
361//____________________________________________________________________________
362
702ab87e 363Int_t AliPHOSLoader::PostRecParticles()const
88cb7938 364{
89308175 365 // -------------- RecParticles -------------------------------------------
88cb7938 366 Int_t reval = AliLoader::PostRecParticles();
367 if (reval)
368 {
351dd634 369 AliError("returned error");
88cb7938 370 return reval;
371 }
702ab87e 372 return const_cast<AliPHOSLoader *>(this)->ReadRecParticles();
88cb7938 373}
374//____________________________________________________________________________
375
702ab87e 376Int_t AliPHOSLoader::PostTracks()const
88cb7938 377{
89308175 378 // -------------- Tracks -------------------------------------------
88cb7938 379 Int_t reval = AliLoader::PostTracks();
380 if (reval)
381 {
351dd634 382 AliError("returned error");
88cb7938 383 return reval;
384 }
702ab87e 385 return const_cast<AliPHOSLoader *>(this)->ReadTracks();
88cb7938 386}
387//____________________________________________________________________________
388
389
390
391//____________________________________________________________________________
392Int_t AliPHOSLoader::ReadHits()
393{
394// If there is no Clones Array in folder creates it and sends to folder
395// then tries to read
396// Reads the first entry of PHOS branch in hit tree TreeH()
397// Reads data from TreeH and stores it in TClonesArray that sits in DetectorDataFolder
398//
399 TObject** hitref = HitsRef();
8d8258f6 400 if(hitref == 0x0) {
401 MakeHitsArray();
402 hitref = HitsRef();
403 }
88cb7938 404
405 TClonesArray* hits = dynamic_cast<TClonesArray*>(*hitref);
406
407 TTree* treeh = TreeH();
408
8d8258f6 409 if(treeh == 0) {
351dd634 410 AliError("Cannot read TreeH from folder");
88cb7938 411 return 1;
412 }
413
414 TBranch * hitsbranch = treeh->GetBranch(fDetectorName);
8d8258f6 415 if (hitsbranch == 0) {
351dd634 416 AliError("Cannot find branch PHOS");
88cb7938 417 return 1;
418 }
351dd634 419
420 AliDebug(1, "Reading Hits");
88cb7938 421
8d8258f6 422 if (hitsbranch->GetEntries() > 1) {
88cb7938 423
8d8258f6 424 hitsbranch->SetAddress(&fTmpHits);
88cb7938 425 Int_t index = 0 ;
8d8258f6 426 for (Int_t i = 0 ; i < hitsbranch->GetEntries(); i++) {
88cb7938 427 hitsbranch->GetEntry(i) ;
8d8258f6 428 for (Int_t j = 0 ; j < fTmpHits->GetEntriesFast() ; j++) {
429 AliPHOSHit* hit = (AliPHOSHit*)fTmpHits->At(j);
430 new((*hits)[index]) AliPHOSHit( *hit ) ;
431 index++ ;
432 }
433 }
434 fTmpHits->Clear();
435 }
436 else {
88cb7938 437 hitsbranch->SetAddress(hitref);
438 hitsbranch->GetEntry(0) ;
8d8258f6 439 }
440
88cb7938 441 return 0;
442}
443//____________________________________________________________________________
444Int_t AliPHOSLoader::ReadSDigits()
445{
446// Read the summable digits tree TreeS():
447// Check if TClones is in folder
448// if not create and add to folder
449// connect to tree if available
450// Read the data
451
452 TObject** sdref = SDigitsRef();
453 if(sdref == 0x0)
454 {
455 MakeSDigitsArray();
456 sdref = SDigitsRef();
457 }
458
459 TTree * treeS = TreeS();
460 if(treeS==0)
461 {
462 //May happen if file is truncated or new in LoadSDigits
351dd634 463 //AliError("There is no SDigit Tree");
88cb7938 464 return 0;
465 }
466
467 TBranch * branch = treeS->GetBranch(fDetectorName);
468 if (branch == 0)
469 {//easy, maybe just a new tree
351dd634 470 //AliError("Cannot find branch PHOS");
88cb7938 471 return 0;
472 }
473
474 branch->SetAddress(SDigitsRef());
475 branch->GetEntry(0);
476 return 0;
477}
478
479//____________________________________________________________________________
480Int_t AliPHOSLoader::ReadDigits()
481{
482// Read the summable digits tree TreeS():
483// Check if TClones is in folder
484// if not create and add to folder
485// connect to tree if available
486// Read the data
487
488 TObject** dref = DigitsRef();
489 if(dref == 0x0)
490 {//if there is not array in folder, create it and put it there
491 MakeDigitsArray();
492 dref = DigitsRef();
493 }
494
495 TTree * treeD = TreeD();
496 if(treeD==0)
497 {
498 //May happen if file is truncated or new in LoadSDigits
351dd634 499 //AliError("There is no Digit Tree");
88cb7938 500 return 0;
501 }
502
503 TBranch * branch = treeD->GetBranch(fDetectorName);
504 if (branch == 0)
505 {//easy, maybe just a new tree
351dd634 506 //AliError("Cannot find branch ",fDetectorName.Data());
88cb7938 507 return 0;
508 }
509
510 branch->SetAddress(dref);//connect branch to buffer sitting in folder
511 branch->GetEntry(0);//get first event
512
513 return 0;
514}
515
516//____________________________________________________________________________
517
518void AliPHOSLoader::Track(Int_t itrack)
519{
520// Read the first entry of PHOS branch in hit tree gAlice->TreeH()
521 if(TreeH()== 0)
522 {
523 if (LoadHits())
524 {
351dd634 525 AliError("Can not load hits.");
88cb7938 526 return;
527 }
528 }
529
530 TBranch * hitsbranch = dynamic_cast<TBranch*>(TreeH()->GetListOfBranches()->FindObject("PHOS")) ;
531 if ( !hitsbranch ) {
532 if (fDebug)
533 cout << "WARNING: AliPHOSLoader::ReadTreeH -> Cannot find branch PHOS" << endl ;
534 return ;
535 }
536 if(!Hits()) PostHits();
537
538 hitsbranch->SetAddress(HitsRef());
539 hitsbranch->GetEntry(itrack);
540
541}
88cb7938 542
543//____________________________________________________________________________
544Int_t AliPHOSLoader::ReadRecPoints()
545{
546//Creates and posts to folder an array container,
547//connects branch in tree (if exists), and reads data to array
548
549 MakeRecPointsArray();
550
551 TObjArray * cpva = 0x0 ;
552 TObjArray * emca = 0x0 ;
553
554 TTree * treeR = TreeR();
555
556 if(treeR==0)
557 {
558 //May happen if file is truncated or new in LoadSDigits
559 return 0;
560 }
561
562 Int_t retval = 0;
563 TBranch * emcbranch = treeR->GetBranch(fgkEmcRecPointsBranchName);
564
565 if (emcbranch == 0x0)
566 {
351dd634 567 AliError(Form("Can not get branch with EMC Rec. Points named %s",
568 fgkEmcRecPointsBranchName.Data()));
88cb7938 569 retval = 1;
570 }
571 else
572 {
573 emcbranch->SetAddress(&emca) ;
574 emcbranch->GetEntry(0) ;
575 }
576 TBranch * cpvbranch = treeR->GetBranch(fgkCpvRecPointsBranchName);
577 if (cpvbranch == 0x0)
578 {
351dd634 579 AliError(Form("Can not get branch with CPV Rec. Points named %s",
580 fgkCpvRecPointsBranchName.Data()));
88cb7938 581 retval = 2;
582 }
583 else
584 {
585 cpvbranch->SetAddress(&cpva);
586 cpvbranch->GetEntry(0) ;
587 }
588
589 Int_t ii ;
590 Int_t maxemc = emca->GetEntries() ;
591 for ( ii= 0 ; ii < maxemc ; ii++ )
592 EmcRecPoints()->Add(emca->At(ii)) ;
593
594 Int_t maxcpv = cpva->GetEntries() ;
595 for ( ii= 0 ; ii < maxcpv ; ii++ )
596 CpvRecPoints()->Add(cpva->At(ii)) ;
597
598 return retval;
599}
600
601//____________________________________________________________________________
602Int_t AliPHOSLoader::ReadTracks()
603{
604//Creates and posts to folder an array container,
605//connects branch in tree (if exists), and reads data to arry
606
607 TObject** trkref = TracksRef();
608 if ( trkref == 0x0 )
609 {//Create and post array
610 MakeTrackSegmentsArray();
611 trkref = TracksRef();
612 }
613
614 TTree * treeT = TreeT();
615 if(treeT==0)
616 {
617 //May happen if file is truncated or new in LoadSDigits, or the file is in update mode,
618 //but tracking was not performed yet for a current event
351dd634 619 //AliError("There is no Tree with Tracks");
88cb7938 620 return 0;
621 }
622
623 TBranch * branch = treeT->GetBranch(fgkTrackSegmentsBranchName);
3f7dbdb7 624// AliInfo(Form("Branch named %s is opened: 0x%z",
625// fgkTrackSegmentsBranchName.Data(),branch));
88cb7938 626 if (branch == 0)
627 {//easy, maybe just a new tree
351dd634 628 AliError(Form("Cannot find branch named %s",
629 fgkTrackSegmentsBranchName.Data()));
88cb7938 630 return 0;
631 }
632
633 branch->SetAddress(trkref);//connect branch to buffer sitting in folder
634 branch->GetEntry(0);//get first event
635
636 return 0;
637}
638//____________________________________________________________________________
639
640Int_t AliPHOSLoader::ReadRecParticles()
641{
642//Reads Reconstructed Particles from file
643//Creates and posts to folder an array container,
644//connects branch in tree (if exists), and reads data to arry
645
646 TObject** recpartref = RecParticlesRef();
647
648 if ( recpartref == 0x0 )
649 {//Create and post array
650 MakeRecParticlesArray();
651 recpartref = RecParticlesRef();
652 }
653
654 TTree * treeP = TreeP();
655 if(treeP==0)
656 {
657 //May happen if file is truncated or new in LoadSDigits,
658 //or the file is in update mode,
659 //but tracking was not performed yet for a current event
351dd634 660 // AliError("There is no Tree with Tracks and Reconstructed Particles");
88cb7938 661 return 0;
662 }
663
664 TBranch * branch = treeP->GetBranch(fgkRecParticlesBranchName);
665 if (branch == 0)
666 {//easy, maybe just a new tree
351dd634 667 AliError(Form("Cannot find branch %s",
668 fgkRecParticlesBranchName.Data()));
88cb7938 669 return 0;
670 }
671
672 branch->SetAddress(recpartref);//connect branch to buffer sitting in folder
673 branch->GetEntry(0);//get first event
674
675 return 0;
676}
677
678
88cb7938 679/***************************************************************************************/
680
681AliPHOSLoader* AliPHOSLoader::GetPHOSLoader(const char* eventfoldername)
682{
89308175 683 // Return PHOS loader
88cb7938 684 AliRunLoader* rn = AliRunLoader::GetRunLoader(eventfoldername);
351dd634 685 if (rn == 0x0) {
686 printf("Can not find Run Loader in folder %s", eventfoldername);
687 return 0x0 ;
688 }
88cb7938 689 return dynamic_cast<AliPHOSLoader*>(rn->GetLoader("PHOSLoader"));
690}
691/***************************************************************************************/
692
693Bool_t AliPHOSLoader::BranchExists(const TString& recName)
89308175 694{
695 // Check if a branch named redName exists
88cb7938 696 if (fBranchTitle.IsNull()) return kFALSE;
697 TString dataname, zername ;
698 TTree* tree;
699 if(recName == "SDigits")
700 {
701 tree = TreeS();
702 dataname = GetDetectorName();
703 zername = "AliPHOSSDigitizer" ;
704 }
705 else
706 if(recName == "Digits"){
707 tree = TreeD();
708 dataname = GetDetectorName();
709 zername = "AliPHOSDigitizer" ;
710 }
711 else
712 if(recName == "RecPoints"){
713 tree = TreeR();
714 dataname = fgkEmcRecPointsBranchName;
715 zername = "AliPHOSClusterizer" ;
716 }
717 else
718 if(recName == "TrackSegments"){
719 tree = TreeT();
720 dataname = fgkTrackSegmentsBranchName;
721 zername = "AliPHOSTrackSegmentMaker";
722 }
723 else
724 if(recName == "RecParticles"){
725 tree = TreeP();
726 dataname = fgkRecParticlesBranchName;
727 zername = "AliPHOSPID";
728 }
729 else
730 return kFALSE ;
731
732
733 if(!tree )
734 return kFALSE ;
735
736 TObjArray * lob = static_cast<TObjArray*>(tree->GetListOfBranches()) ;
737 TIter next(lob) ;
738 TBranch * branch = 0 ;
739 TString titleName(fBranchTitle);
740 titleName+=":";
741
742 while ((branch = (static_cast<TBranch*>(next())))) {
743 TString branchName(branch->GetName() ) ;
744 TString branchTitle(branch->GetTitle() ) ;
745 if ( branchName.BeginsWith(dataname) && branchTitle.BeginsWith(fBranchTitle) ){
351dd634 746 AliWarning(Form("branch %s with title %s ",
747 dataname.Data(),fBranchTitle.Data()));
88cb7938 748 return kTRUE ;
749 }
750 if ( branchName.BeginsWith(zername) && branchTitle.BeginsWith(titleName) ){
351dd634 751 AliWarning(Form("branch AliPHOS... with title %s ",
752 branch->GetTitle()));
88cb7938 753 return kTRUE ;
754 }
755 }
756 return kFALSE ;
757
758 }
759
760void AliPHOSLoader::SetBranchTitle(const TString& btitle)
89308175 761{
762 // Set branch title
88cb7938 763 if (btitle.CompareTo(fBranchTitle) == 0) return;
764 fBranchTitle = btitle;
765 ReloadAll();
766 }
702ab87e 767
88cb7938 768//____________________________________________________________________________
702ab87e 769//Again, must be const not to hide virtual functions from AliLoader
770//but there are calls to non-const functions, so I have to const_cast this pointer
771void AliPHOSLoader::CleanHits()const
88cb7938 772{
89308175 773 // Clean Hits array
88cb7938 774 AliLoader::CleanHits();
775 //Clear an array
702ab87e 776 TClonesArray* hits = const_cast<AliPHOSLoader *>(this)->Hits();
88cb7938 777 if (hits) hits->Clear();
778}
779//____________________________________________________________________________
780
702ab87e 781void AliPHOSLoader::CleanSDigits()const
88cb7938 782{
89308175 783 // Clean SDigits array
88cb7938 784 AliLoader::CleanSDigits();
702ab87e 785 TClonesArray* sdigits = const_cast<AliPHOSLoader *>(this)->SDigits();
88cb7938 786 if (sdigits) sdigits->Clear();
787
788}
789//____________________________________________________________________________
790
702ab87e 791void AliPHOSLoader::CleanDigits()const
88cb7938 792{
89308175 793 // Clean Digits array
88cb7938 794 AliLoader::CleanDigits();
702ab87e 795 TClonesArray* digits = const_cast<AliPHOSLoader *>(this)->Digits();
88cb7938 796 if (digits) digits->Clear();
797}
798//____________________________________________________________________________
799
702ab87e 800void AliPHOSLoader::CleanRecPoints()const
88cb7938 801{
89308175 802 // Clean RecPoints array
88cb7938 803 AliLoader::CleanRecPoints();
702ab87e 804 TObjArray* recpoints = const_cast<AliPHOSLoader *>(this)->EmcRecPoints();
88cb7938 805 if (recpoints) recpoints->Clear();
702ab87e 806 recpoints = const_cast<AliPHOSLoader *>(this)->CpvRecPoints();
88cb7938 807 if (recpoints) recpoints->Clear();
808}
809//____________________________________________________________________________
810
702ab87e 811void AliPHOSLoader::CleanTracks()const
88cb7938 812{
89308175 813 //Cleans Tracks stuff
88cb7938 814 AliLoader::CleanTracks();//tree
815
816 //and clear the array
702ab87e 817 TClonesArray* tracks = const_cast<AliPHOSLoader *>(this)->TrackSegments();
88cb7938 818 if (tracks) tracks->Clear();
819
820}
821//____________________________________________________________________________
822
823void AliPHOSLoader::CleanRecParticles()
824 {
89308175 825 // Clean RecParticles array
88cb7938 826 TClonesArray *recpar = RecParticles();
827 if (recpar) recpar->Clear();
828
829
830 }
831//____________________________________________________________________________
832
88cb7938 833void AliPHOSLoader::MakeHitsArray()
834{
89308175 835 // Add Hits array to the data folder
88cb7938 836 if (Hits()) return;
837 TClonesArray* hits = new TClonesArray("AliPHOSHit",1000);
838 hits->SetName(fgkHitsName);
839 GetDetectorDataFolder()->Add(hits);
840}
841
842//____________________________________________________________________________
843void AliPHOSLoader::MakeSDigitsArray()
844{
89308175 845 // Add SDigits array to the data folder
88cb7938 846 if ( SDigits()) return;
847 TClonesArray* sdigits = new TClonesArray("AliPHOSDigit",1);
848 sdigits->SetName(fgkSDigitsName);
849 GetDetectorDataFolder()->Add(sdigits);
850}
851
852//____________________________________________________________________________
853void AliPHOSLoader::MakeDigitsArray()
854{
89308175 855 // Add Digits array to the data folder
88cb7938 856 if ( Digits()) return;
857 TClonesArray* digits = new TClonesArray("AliPHOSDigit",1);
858 digits->SetName(fgkDigitsName);
859 GetDetectorDataFolder()->Add(digits);
860
861}
862
863//____________________________________________________________________________
864void AliPHOSLoader::MakeRecPointsArray()
865{
89308175 866 // Add RecPoints array to the data folder
88cb7938 867 if ( EmcRecPoints() == 0x0)
868 {
351dd634 869 AliDebug(9, "Making array for EMC");
88cb7938 870 TObjArray* emc = new TObjArray(100) ;
871 emc->SetName(fgkEmcRecPointsName) ;
872 GetDetectorDataFolder()->Add(emc);
873 }
874
875 if ( CpvRecPoints() == 0x0)
351dd634 876 {
877 AliDebug(9, "Making array for CPV");
878 TObjArray* cpv = new TObjArray(100) ;
879 cpv->SetName(fgkCpvRecPointsName);
880 GetDetectorDataFolder()->Add(cpv);
88cb7938 881 }
882}
883
884//____________________________________________________________________________
885void AliPHOSLoader::MakeTrackSegmentsArray()
886{
89308175 887 // Add TrackSegments array to the data folder
88cb7938 888 if ( TrackSegments()) return;
889 TClonesArray * ts = new TClonesArray("AliPHOSTrackSegment",100) ;
890 ts->SetName(fgkTracksName);
891 GetDetectorDataFolder()->Add(ts);
892
893}
894
895//____________________________________________________________________________
896void AliPHOSLoader::MakeRecParticlesArray()
897{
89308175 898 // Add RecParticles array to the data folder
88cb7938 899 if ( RecParticles()) return;
900 TClonesArray * rp = new TClonesArray("AliPHOSRecParticle",100) ;
901 rp->SetName(fgkRecParticlesName);
902 GetDetectorDataFolder()->Add(rp);
903}