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