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