]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALGetter.cxx
40cbc9fad6c65d9b190bd7bc1346a8c273c66799
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALGetter.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 /* $Log:
18    29.05.2001 Yuri Kharlov:
19               Everywhere reading the treese TTree->GetEvent(i)
20               is replaced by reading the branches TBranch->GetEntry(0)
21 */
22
23 /* $Log:
24    08.2002 Dmitri Peressounko:
25 */
26
27 //_________________________________________________________________________
28 //  A singleton. This class should be used in the analysis stage to get 
29 //  reconstructed objects: Digits, RecPoints, TrackSegments and RecParticles,
30 //  instead of directly reading them from galice.root file. This container 
31 //  ensures, that one reads Digits, made of these particular digits, RecPoints,
32 //  made of these particular RecPoints, TrackSegments and RecParticles. 
33 //  This becomes non trivial if there are several identical branches, produced with
34 //  different set of parameters. 
35 //
36 //  An example of how to use (see also class AliEMCALAnalyser):
37 //  AliEMCALGetter * gime = AliEMCALGetter::GetInstance("galice.root","test") ;
38 //  for(Int_t irecp = 0; irecp < gime->NRecParticles() ; irecp++)
39 //     AliEMCALRecParticle * part = gime->RecParticle(1) ;
40 //     ................
41 //  please->GetEvent(event) ;    // reads new event from galice.root
42 //                  
43 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
44 //*--         Completely redesigned by Dmitri Peressounko March 2001  
45 //
46 //*-- YS June 2001 : renamed the original AliEMCALIndexToObject and make
47 //*--         systematic usage of TFolders without changing the interface     
48 //*-- YS August 2002 : clone PHOS as closely as possible and intoduction
49 //                     of new  IO (à la PHOS)
50
51 //////////////////////////////////////////////////////////////////////////////
52
53
54
55 // --- ROOT system ---
56
57 #include "TFile.h"
58 #include "TTree.h"
59 #include "TROOT.h"
60 #include "TObjString.h"
61 #include "TFolder.h"
62 #include "TParticle.h"
63
64 // --- Standard library ---
65
66 #include <Riostream.h>
67
68 // --- AliRoot header files ---
69
70 #include "AliRun.h"
71 #include "AliConfig.h"
72 #include "AliEMCALGetter.h"
73 #include "AliEMCAL.h"
74 #include "AliEMCALDigitizer.h"
75 #include "AliEMCALSDigitizer.h"
76 #include "AliEMCALClusterizerv1.h"
77 #include "AliEMCALGeometry.h"
78
79 ClassImp(AliEMCALGetter)
80
81   AliEMCALGetter * AliEMCALGetter::fgObjGetter = 0 ; 
82   TFile * AliEMCALGetter::fFile = 0 ; 
83
84 //____________________________________________________________________________ 
85
86 AliEMCALGetter::AliEMCALGetter(const char* headerFile, const char* branchTitle, const Bool_t toSplit)
87 {
88   // This is the ctor called by GetInstance and the only one that can be used 
89
90   if ( fHeaderFile.Contains("_") ) {
91     Fatal("AliEMCALGetter","Invalid file name (_ not allowed) %s",fHeaderFile.Data()) ;
92   }
93
94   //Initialize  all data
95
96   fFailed = kFALSE ;   
97   fDebug  = 0 ; 
98   fToSplit    = toSplit ;
99   fHeaderFile = headerFile ; 
100
101   fPrimaries = new TObjArray(1) ;
102
103   fModuleFolder    = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Configuration/Modules")); 
104   fPrimariesFolder = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/RunMC/Event/Data")); 
105   fHitsFolder      = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/RunMC/Event/Data/Hits")); 
106   fSDigitsFolder   = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/RunMC/Event/Data/SDigits")); 
107   fDigitsFolder    = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Event/Data")); 
108   fRecoFolder      = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Event/RecData")); 
109   //fQAFolder      = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Conditions/QA")); 
110   fTasksFolder     = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Tasks")) ; 
111
112   //Set titles to branches and create PHOS specific folders
113
114   SetTitle(branchTitle) ;
115
116   if ( fHeaderFile != "aliroot"  ) { // to call the getter without a file
117
118     //open headers file
119
120     fFile = static_cast<TFile*>(gROOT->GetFile(fHeaderFile.Data() ) ) ;
121
122     if(!fFile){    //if file was not opened yet, read gAlice
123       fFile = TFile::Open(fHeaderFile.Data(), "update") ;   
124       if (!fFile->IsOpen()) {
125         Error("AliEMCALGetter","Cannot open %s",fHeaderFile.Data()) ; 
126         fFailed = kTRUE ;
127         return ;  
128       }
129       gAlice = static_cast<AliRun *>(fFile->Get("gAlice")) ;
130     }
131   }
132
133   if (!gAlice) {
134     Error("AliEMCALGetter","Cannot find gAlice in %s",fHeaderFile.Data()) ; 
135     fFailed = kTRUE ;
136     return ; 
137   }
138
139   if (!EMCAL()) {
140     if (fDebug)
141       Info("AliEMCALGetter","Posting EMCAL to Folders") ; 
142
143     if (gAlice->GetDetector("EMCAL")) {
144       AliConfig * conf = AliConfig::Instance() ;
145       conf->Add(static_cast<AliDetector*>(gAlice->GetDetector("EMCAL"))) ; 
146       conf->Add(static_cast<AliModule*>(gAlice->GetDetector("EMCAL"))) ;
147     }
148     else 
149       Error("AliEMCALGetter"," Detector EMCAL not found");
150   }
151
152   fDebug=0;
153 }
154
155 //____________________________________________________________________________ 
156
157 AliEMCALGetter::~AliEMCALGetter()
158 {
159   if (fPrimaries) {
160     fPrimaries->Delete() ; 
161     delete fPrimaries ; 
162   }
163
164   TFolder * emcalF = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject("EMCAL")) ;
165   TCollection * folderslist = emcalF->GetListOfFolders() ; 
166   TIter next(folderslist) ; 
167   TFolder * folder = 0 ; 
168
169   while ( (folder = static_cast<TFolder*>(next())) ) 
170     emcalF->Remove(folder) ; 
171
172   if (fFile) { 
173     fFile->Close() ;  
174     delete fFile ; 
175     fFile = 0 ;
176   }
177
178   fgObjGetter = 0 ; 
179 }
180
181 //____________________________________________________________________________ 
182
183 void AliEMCALGetter::CloseFile()
184 {
185   delete gAlice ;  
186   gAlice = 0 ; 
187 }
188
189 //____________________________________________________________________________ 
190
191 const TFolder * AliEMCALGetter::Folder(const TString what) const {
192
193   // returns the EMCAL folder required by what
194   // what = hits, sdigits, digits
195
196   if ( what == "hits" ) 
197     return dynamic_cast<const TFolder *>(fHitsFolder->FindObject("EMCAL")) ; 
198   else if ( what == "sdigits" ) 
199     return  dynamic_cast<const TFolder *>(fSDigitsFolder->FindObject("EMCAL")) ; 
200   else if ( what == "digits" ) 
201     return  dynamic_cast<const TFolder *>(fDigitsFolder->FindObject("EMCAL")) ;
202   else {
203     Error("GetFolder","%s illegal option (hits, sdigits, digits) ", what.Data()) ; 
204     return 0 ; 
205   }
206 }
207
208 //____________________________________________________________________________ 
209
210 AliEMCALGetter * AliEMCALGetter::GetInstance()
211 {
212   // Returns the pointer of the unique instance already defined
213
214   if ( fgObjGetter ) {
215     return fgObjGetter ;
216   }
217   else {
218     return 0 ;
219   }
220 }
221
222 //____________________________________________________________________________ 
223
224 AliEMCALGetter * AliEMCALGetter::GetInstance(const char* headerFile,
225                                              const char* branchTitle,
226                                              const Bool_t toSplit)
227 {
228   // Creates and returns the pointer of the unique instance
229   // Must be called only when the environment has changed 
230
231   if(!fgObjGetter){
232     fgObjGetter = new AliEMCALGetter(headerFile,branchTitle,toSplit) ;
233     if(fgObjGetter->fFailed)
234       return 0;
235     else
236       return fgObjGetter ;
237   }
238
239   //First checks, if header file already opened
240
241   if(!fgObjGetter->fFile){
242      fgObjGetter = new AliEMCALGetter(headerFile,branchTitle,toSplit) ;
243     if(fgObjGetter->fFailed)
244       return 0;
245     else
246       return fgObjGetter ;
247   }
248
249   if(fgObjGetter->fHeaderFile.CompareTo(headerFile)==0){ //Opened the same header file   
250     if((fgObjGetter->fBranchTitle.CompareTo(branchTitle) == 0)&&   //Open the same branch title
251        (toSplit==fgObjGetter->fToSplit)){                          //Nothing should be cleaned
252     }
253     else{ //Clean all data and AliEMCAL...zers
254       if(fgObjGetter->fToSplit)
255         fgObjGetter->CloseSplitFiles() ;          
256       fgObjGetter->CleanWhiteBoard() ;
257       fgObjGetter->fToSplit = toSplit ;
258       fgObjGetter->SetTitle(branchTitle) ;
259     }
260   }
261   else{  //Close already opened files, clean memory and open new header file
262     if(gAlice)
263       delete gAlice ;
264     gAlice= 0;
265     if(fgObjGetter->fFile){
266       fgObjGetter->fFile->Close() ;
267       fgObjGetter->fFile=0;
268     }
269     if(fgObjGetter->fToSplit)
270       fgObjGetter->CloseSplitFiles() ;
271     fgObjGetter->CleanWhiteBoard() ;    
272     fgObjGetter = new AliEMCALGetter(headerFile,branchTitle,toSplit) ;
273   }
274
275   return fgObjGetter ; 
276
277 }
278
279 //____________________________________________________________________________ 
280
281 const Bool_t AliEMCALGetter::BranchExists(const TString recName) const
282 {
283   //Looks in the tree Tree"name" if branch with current name olready exists
284
285   TString filename("") ;
286   TString name, dataname, zername;
287   if(recName == "SDigits"){
288     filename=fSDigitsFileName ;
289     name = "TreeS0" ;
290     dataname = "EMCAL" ;
291     zername = "AliEMCALSDigitizer" ;
292   }
293   else if(recName == "Digits"){
294     filename=fDigitsFileName ;
295     name = "TreeD0" ;
296     dataname = "EMCAL" ;
297     zername = "AliEMCALDigitizer" ;
298   }
299   else if(recName =="RecPoints"){
300         filename=fRecPointsFileName ;
301         name = "TreeR0" ;
302         dataname = "EMCALEmcRP" ;
303         zername = "AliEMCALClusterizer" ;
304   }
305   else if(recName == "TrackSegments"){
306     filename=fTrackSegmentsFileName ;
307     name = "TreeR0" ;
308     dataname = "EMCALTS" ;
309     zername = "AliEMCALTrackSegmentMaker" ;
310   }      
311   else if(recName == "RecParticles"){
312     filename= fRecParticlesFileName ;
313     name = "TreeR0" ;
314     dataname = "EMCALRP" ;
315     zername = "AliEMCALPID" ;
316   }
317   else
318     return kFALSE ;
319
320   TFile * file ;
321   TTree * tree ;
322   if(fToSplit){
323     file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
324     if(!file)
325       file = TFile::Open(fSDigitsFileName.Data(),"update");
326   }
327   else
328     file = fFile ;
329
330   tree = (TTree *)file->Get(name.Data()) ;
331
332   if(!tree ) 
333     return kFALSE ;
334
335   TObjArray * lob = static_cast<TObjArray*>(tree->GetListOfBranches()) ;
336   TIter next(lob) ; 
337   TBranch * branch = 0 ;  
338   TString titleName(fBranchTitle);
339   titleName+=":";
340
341   while ((branch = (static_cast<TBranch*>(next())))) {
342     TString branchName(branch->GetName() ) ; 
343     TString branchTitle(branch->GetTitle() ) ;  
344     if ( branchName.BeginsWith(dataname) && branchTitle.BeginsWith(fBranchTitle) ){  
345       Warning("BranchExists", "branch %s with title %s already exits in %s", dataname.Data(), fBranchTitle.Data(), name.Data());
346       return kTRUE ;
347     }
348
349     if ( branchName.BeginsWith(zername) &&  branchTitle.BeginsWith(titleName) ){
350       Warning("BranchExists","Branch AliEMCAL... with title %s already exits in %s",branch->GetTitle(), name.Data());     
351       return kTRUE ; 
352     }
353   }
354
355     //We can't delete three if gAlice points to it... To be redisigned somehow???!!!
356
357   if(!fToSplit){
358     if(name.Contains("TreeS"))
359       if(tree!=gAlice->TreeS())
360         tree->Delete();
361     if(name.Contains("TreeD"))
362       if(tree!=gAlice->TreeD())
363         tree->Delete();
364     if(name.Contains("TreeR"))
365       if(tree!=gAlice->TreeR())
366         tree->Delete();    
367   }
368
369   return kFALSE ;
370 }
371
372 //____________________________________________________________________________ 
373
374 void AliEMCALGetter::ListBranches(Int_t event) const  
375 {
376   TBranch * branch = 0 ; 
377   if (gAlice->GetEvent(event) == -1)
378     return ; 
379
380   TTree * t =  gAlice->TreeH() ; 
381
382   if(t){
383     Info("ListBranches"," -> ****** Hits    : "); 
384     TObjArray * lob = t->GetListOfBranches() ;
385     TIter next(lob) ; 
386
387     while ( (branch = static_cast<TBranch*>(next())) )
388       Info("ListBranches","         %s", branch->GetName());
389
390   } else 
391     Warning("ListBranches"," -> TreeH not found for event %d",event);  
392
393   t = gAlice->TreeS() ;
394
395   if(t){
396     Info("ListBranches"," -> ****** SDigits : "); 
397     TObjArray * lob = t->GetListOfBranches() ;
398     TIter next(lob) ; 
399
400     while ( (branch = static_cast<TBranch*>(next())) )
401       Info("ListBranches","             %s %s",branch->GetName(),branch->GetTitle()); 
402   } else 
403     Warning("ListBranches"," -> TreeS not found for event %d",event);  
404
405   t = gAlice->TreeD() ;
406
407   if(t){
408     Info("ListBranches"," -> ****** Digits  : "); 
409     TObjArray * lob = t->GetListOfBranches() ;
410     TIter next(lob) ; 
411
412     while ( (branch = static_cast<TBranch*>(next())) )
413       Info("             %s %s", branch->GetName(), branch->GetTitle()); 
414   } else 
415     Warning("ListBranches"," -> TreeD not found for event %d", event);  
416
417   t = gAlice->TreeR() ;
418
419   if(t){
420     Info("ListBranches"," -> ****** Recon   : "); 
421     TObjArray * lob = t->GetListOfBranches() ;
422     TIter next(lob) ; 
423     while ( (branch = static_cast<TBranch*>(next())) )
424       Info("             %s %s", branch->GetName(), branch->GetTitle()); 
425   } else 
426     Warning("ListBranches"," -> TreeR not found for event %d",event);  
427 }
428
429 //____________________________________________________________________________ 
430
431 void AliEMCALGetter::NewBranch(TString name, Int_t event)  
432 {
433   fBranchTitle = fSDigitsTitle = fDigitsTitle = fRecPointsTitle = fTrackSegmentsTitle = fRecParticlesTitle =  name ; 
434   Event(event) ; 
435 }
436
437 //____________________________________________________________________________ 
438
439 Bool_t AliEMCALGetter::NewFile(TString name)  
440 {
441   fHeaderFile = name ; 
442   fFile->Close() ; 
443   fFailed = kFALSE; 
444
445   fFile = static_cast<TFile*>(gROOT->GetFile(fHeaderFile.Data() ) ) ;
446
447   if(!fFile) {    //if file was not opened yet, read gAlice
448     fFile = TFile::Open(fHeaderFile.Data(),"update") ;
449     if (!fFile->IsOpen()) {
450       Error("NewFile", " -> Cannot open %s", fHeaderFile.Data()); 
451       fFailed = kTRUE ;
452       return fFailed ;  
453     }
454     gAlice = static_cast<AliRun *>(fFile->Get("gAlice")) ;
455   } 
456
457   if (!gAlice) {
458     Error("NewFile"," -> Cannot find gAlice in %s", fHeaderFile.Data());
459     fFailed = kTRUE ;
460     return fFailed ; 
461   }
462   return fFailed ; 
463 }
464
465 //____________________________________________________________________________ 
466
467 const AliEMCAL * AliEMCALGetter::EMCAL() 
468 {
469   // returns the EMCAL object 
470
471   AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(fModuleFolder->FindObject("EMCAL")) ;  
472
473   if (!emcal) 
474     if (fDebug)
475       Warning("EMCAL"," -> EMCAL module not found in Folders" );
476   return emcal ; 
477 }  
478
479 //____________________________________________________________________________ 
480
481 AliEMCALGeometry * AliEMCALGetter::EMCALGeometry() 
482 {
483   AliEMCALGeometry * rv = 0 ; 
484   if (EMCAL() )
485     rv =  EMCAL()->GetGeometry() ;
486   return rv ; 
487
488
489 //____________________________________________________________________________ 
490
491 const Bool_t AliEMCALGetter::PostPrimaries(void) const 
492 {  
493   //------- Primaries ----------------------
494   // the hierarchy is //Folders/RunMC/Event/Data/Primaries
495
496   TFolder * primariesFolder = dynamic_cast<TFolder*>(fPrimariesFolder->FindObject("Primaries")) ; 
497   if ( !primariesFolder ) {
498     if (fDebug) {
499       Warning("PostPrimaries", "-> Folder //%s/Primaries/ not found!", fPrimariesFolder->GetName());
500       Info("PostPrimaries", "-> Adding Folder //%s/Primaries/",fPrimariesFolder->GetName());
501     }
502     primariesFolder = fPrimariesFolder->AddFolder("Primaries", "Primaries particles from TreeK") ; 
503   }    
504
505   TClonesArray *primaries=  new TClonesArray("TParticle",1000) ;
506   primaries->SetName("Primaries") ;
507   primariesFolder->Add(primaries) ; 
508
509   return kTRUE;
510
511
512 //____________________________________________________________________________ 
513
514 TObject** AliEMCALGetter::PrimariesRef(void) const 
515 {  
516   //------- Primaries ----------------------
517   // the hierarchy is //Folders/RunMC/Event/Data/Primaries
518
519   if ( !fPrimariesFolder ) {
520     Fatal("PrimariesRef", "-> Folder //%s not found!",fPrimariesFolder);
521   }    
522
523   TFolder * primariesFolder = dynamic_cast<TFolder *>(fPrimariesFolder->FindObject("Primaries")) ;
524
525   if ( !primariesFolder ) {
526     Fatal("PrimariesRef", "-> Folder //%s/Primaries/ not found!",fPrimariesFolder);  
527   }
528
529   TObject * p = primariesFolder->FindObject("Primaries") ;
530
531   if(!p) {
532     Fatal("PrimariesRef", "-> %s/Primaries not found !",primariesFolder->GetName()); 
533   }
534
535   return primariesFolder->GetListOfFolders()->GetObjectRef(p) ;
536 }
537
538 //____________________________________________________________________________ 
539
540 const Bool_t AliEMCALGetter::PostHits(void) const 
541 {  
542   //------- Hits ----------------------
543   // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/Hits
544
545   TFolder * emcalFolder = dynamic_cast<TFolder*>(fHitsFolder->FindObject("EMCAL")) ; 
546
547   if ( !emcalFolder ) {
548     if (fDebug) {
549       Warning("PostHits", "-> Folder //%s/EMCAL/ not found!", fHitsFolder);
550       Info("PostHits", "-> Adding Folder //%s/EMCAL/",fHitsFolder);
551     }
552     emcalFolder = fHitsFolder->AddFolder("EMCAL", "Hits from EMCAL") ; 
553   }    
554
555   TClonesArray *hits=  new TClonesArray("AliEMCALHit",1000) ;
556   hits->SetName("Hits") ;
557   emcalFolder->Add(hits) ; 
558
559   return kTRUE;
560
561
562 //____________________________________________________________________________ 
563
564 TObject ** AliEMCALGetter::HitsRef(void) const 
565 {  
566   //------- Hits ----------------------
567   // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/Hits
568
569   if ( !fHitsFolder ) {
570     Error("HitsRef", "-> Folder //%s not found!",fHitsFolder);
571     return 0;
572   }    
573
574   TFolder * emcalFolder = dynamic_cast<TFolder *>(fHitsFolder->FindObject("EMCAL")) ;
575   if ( !emcalFolder ) {
576     Error("HitsRef", "-> Folder //%s/EMCAL/ not found!",fHitsFolder);
577     return 0;
578   }
579
580   TObject * h = emcalFolder->FindObject("Hits") ;
581
582   if(!h) {
583     Error("HitsRef", "-> %s/Hits not found !",emcalFolder->GetName());
584     return 0 ;
585   }
586   else
587     return emcalFolder->GetListOfFolders()->GetObjectRef(h) ;
588 }
589
590 //____________________________________________________________________________ 
591
592 const Bool_t AliEMCALGetter::PostSDigits(const char * name, const char * headerFile) const 
593 {  
594   //---------- SDigits -------------------------
595   // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/SDigits/headerFile/sdigitsname
596   // because you can have sdigits from several hit files for mixing
597
598   TFolder * emcalFolder = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
599
600   if ( !emcalFolder ) {
601     if (fDebug) {
602       Warning("PostSDigits", "-> Folder //%s/EMCAL/ not found!", fSDigitsFolder);
603       Info("PostSDigits", "-> Adding Folder //%s/EMCAL/",fHitsFolder);
604     }
605     emcalFolder = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ; 
606   }    
607
608   TString subdir(headerFile) ;
609   subdir.ReplaceAll("/", "_") ; 
610   TFolder * emcalSubFolder = dynamic_cast<TFolder*>(emcalFolder->FindObject(subdir)) ; 
611   if ( !emcalSubFolder ) 
612     emcalSubFolder = emcalFolder->AddFolder(subdir, ""); 
613
614   TObject * sd  = emcalSubFolder->FindObject(name); 
615
616   if ( !sd ) {
617     TClonesArray * sdigits = new TClonesArray("AliEMCALDigit",1) ;
618     sdigits->SetName(name) ;
619     emcalSubFolder->Add(sdigits) ;
620   }
621
622   return kTRUE;
623
624
625 //____________________________________________________________________________ 
626
627 TObject ** AliEMCALGetter::SDigitsRef(const char * name, const char * file) const 
628 {  
629   //------- SDigits ----------------------
630   // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/SDigits/filename/SDigits
631
632   if ( !fSDigitsFolder ) {
633     Fatal("SDigitsRef", "-> Folder //%s not found!", fSDigitsFolder);
634   }    
635
636   TFolder * emcalFolder = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject("EMCAL")) ;
637
638   if ( !emcalFolder ) {
639     Fatal("SDigitsRef", "-> Folder //%s/EMCAL/ not found!", fSDigitsFolder);
640   }
641
642   TFolder * emcalSubFolder = 0 ;
643
644   if(file)
645     emcalSubFolder = dynamic_cast<TFolder *>(emcalFolder->FindObject(file)) ;
646   else
647     emcalSubFolder = dynamic_cast<TFolder *>(emcalFolder->FindObject(fHeaderFile)) ;
648
649   if(!emcalSubFolder) {
650     Fatal("SDigitsRef", "-> Folder //Folders/RunMC/Event/Data/EMCAL/%s not found!", file);
651   }
652
653   TObject * dis = emcalSubFolder->FindObject(name) ;
654
655   if(!dis) {
656     Fatal("SDigitsRef", "-> object %s not found!", name);
657   }
658
659   return emcalSubFolder->GetListOfFolders()->GetObjectRef(dis) ;
660 }
661
662 //____________________________________________________________________________ 
663
664 const Bool_t AliEMCALGetter::PostSDigitizer(AliEMCALSDigitizer * sdigitizer) const 
665 {  
666   //---------- SDigitizer -------------------------
667   // the hierarchy is //Folders/Tasks/SDigitizer/EMCAL/sdigitsname
668
669   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ; 
670
671   if ( !sd ) {
672     Error("PostSDigitizer", "-> Task //%s/SDigitizer not found!",fTasksFolder);
673     return kFALSE ;
674   }        
675
676   TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ; 
677
678   if ( !emcal )  {
679     if (fDebug) {
680       Warning("PostSDigitizer", "->//%s/SDigitizer/EMCAL/ not found!",fTasksFolder);
681       Info("PostSDigitizer", "-> Adding //%s/SDigitizer/EMCAL/", fTasksFolder);
682     }
683     emcal = new TTask("EMCAL", "") ; 
684     sd->Add(emcal) ; 
685   } 
686
687   AliEMCALSDigitizer * emcalsd  = dynamic_cast<AliEMCALSDigitizer *>(emcal->GetListOfTasks()->FindObject( sdigitizer->GetName() )); 
688
689   if (emcalsd) { 
690     if (fDebug)
691       Info("PostSDigitizer", "-> Task %s already exists",sdigitizer->GetName());
692     emcal->GetListOfTasks()->Remove(emcalsd) ;
693   }
694
695   emcal->Add(sdigitizer) ;      
696
697   return kTRUE; 
698 }
699
700 //____________________________________________________________________________ 
701
702 TObject ** AliEMCALGetter::SDigitizerRef(const char * name) const 
703 {  
704   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ; 
705
706   if ( !sd ) {
707     Fatal("SDigitizerRef", "-> Task //%s/SDigitizer not found!", fTasksFolder);
708   }        
709
710   TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ; 
711
712   if ( !emcal )  {
713     Fatal("SDigitizerRef", "->  //%s/SDigitizer/EMCAL not found!", fTasksFolder);
714   }        
715
716   TTask * task = dynamic_cast<TTask*>(emcal->GetListOfTasks()->FindObject(name)) ; 
717
718   return emcal->GetListOfTasks()->GetObjectRef(task) ;
719 }
720
721 //____________________________________________________________________________ 
722
723 const Bool_t AliEMCALGetter::PostSDigitizer(const char * name, const char * file) const 
724 {  
725   //---------- SDigitizer -------------------------
726   // the hierarchy is //Folders/Tasks/SDigitizer/EMCAL/sdigitsname
727
728   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ; 
729
730   if ( !sd ) {
731     Error("PostSDigitizer", "-> Task //%s/SDigitizer not found!", fTasksFolder);
732     return kFALSE ;
733   }        
734
735   TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ; 
736
737   if ( !emcal )  {
738     if (fDebug) {
739       Warning("PostSDigitizer", "->  //%s/SDigitizer/EMCAL/ not found!", fTasksFolder);
740
741       Info("PostSDigitizer", "-> Adding  //%s/SDigitizer/EMCAL", fTasksFolder);
742
743     }
744     emcal = new TTask("EMCAL", "") ; 
745     sd->Add(emcal) ; 
746   } 
747
748   TString sdname(name) ;
749   sdname.Append(":") ;
750   sdname.Append(file);
751   sdname.ReplaceAll("/","_") ; 
752   AliEMCALSDigitizer * emcalsd  = dynamic_cast<AliEMCALSDigitizer *>(emcal->GetListOfTasks()->FindObject( sdname )); 
753
754   if (!emcalsd) {
755     emcalsd = new AliEMCALSDigitizer() ;  
756
757     //Note, we can not call constructor with parameters: it will call Getter and screw up everething
758
759     emcalsd->SetName(sdname) ;
760     emcalsd->SetTitle(file) ;
761     emcal->Add(emcalsd) ;       
762   }
763
764   return kTRUE; 
765 }
766
767 //____________________________________________________________________________ 
768
769 const Bool_t AliEMCALGetter::PostDigits(const char * name) const 
770 {  
771   //---------- Digits -------------------------
772   // the hierarchy is //Folders/Run/Event/Data/EMCAL/SDigits/name
773
774   TFolder * emcalFolder  = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ;
775
776   if ( !emcalFolder ) {
777     if (fDebug) {
778       Warning("PostDigits", "-> Folder //%s/EMCAL/ not found!", fDigitsFolder);
779       Info("PostDigits", "-> Adding Folder //%s/EMCAL/", fDigitsFolder);
780     }
781     emcalFolder = fDigitsFolder->AddFolder("EMCAL", "Digits from EMCAL") ;  
782   }    
783
784   TObject*  dig = emcalFolder->FindObject( name ) ;
785
786   if ( !dig ) {
787     TClonesArray * digits = new TClonesArray("AliEMCALDigit",1000) ;
788     digits->SetName(name) ;
789     emcalFolder->Add(digits) ;  
790   }
791
792   return kTRUE; 
793 }
794
795 //____________________________________________________________________________ 
796
797 TObject ** AliEMCALGetter::DigitsRef(const char * name) const 
798
799   //------- Digits ----------------------
800   // the hierarchy is //Folders/Run/Event/Data/EMCAL/Digits/name
801
802   if ( !fDigitsFolder ) {
803     Fatal("DigitsRef", "-> Folder //%s not found!", fDigitsFolder);
804   }    
805
806   TFolder * emcalFolder  = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ; 
807
808   if ( !emcalFolder ) {
809     Fatal("DigitsRef", "-> Folder //%s/EMCAL/ not found!", fDigitsFolder);
810   }    
811
812   TObject * d = emcalFolder->FindObject(name) ;
813
814   if(!d) {
815     Fatal("DigitsRef", "-> object %s not found!", name);
816   }   
817
818   return emcalFolder->GetListOfFolders()->GetObjectRef(d) ;
819 }
820
821 //____________________________________________________________________________ 
822
823 const Bool_t AliEMCALGetter::PostDigitizer(AliEMCALDigitizer * digitizer) const
824 {  
825   //---------- Digitizer -------------------------
826
827   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ; 
828
829   if ( !sd ) {
830     Error("PostDigitizer", "-> Task //%s/Digitizer not found!", fTasksFolder);
831     return kFALSE ;
832   }        
833
834   TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ; 
835
836   if ( !emcal )  {
837     if (fDebug) {
838       Warning("PostDigitizer", "->  //%s/Digitizer/EMCAL not found!", fTasksFolder);
839       Info("PostDigitizer", "-> Adding //%s/Digitizer/EMCAL", fTasksFolder);
840     }
841     emcal = new TTask("EMCAL", "") ; 
842     sd->Add(emcal) ; 
843   } 
844
845     AliEMCALDigitizer * emcald = dynamic_cast<AliEMCALDigitizer*>(emcal->GetListOfTasks()->FindObject(digitizer->GetName())) ; 
846
847     if (emcald) { 
848       emcald->Delete() ;
849       emcal->GetListOfTasks()->Remove(emcald) ;
850     }
851
852     emcal->Add(digitizer) ; 
853
854     return kTRUE; 
855 }  
856
857 //____________________________________________________________________________ 
858
859 const Bool_t AliEMCALGetter::PostDigitizer(const char * name) const 
860 {  
861   //---------- Digitizer -------------------------
862   // the hierarchy is //Folders/Tasks/SDigitizer/EMCAL/sdigitsname
863
864   TTask * d  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ; 
865
866   if ( !d ) {
867
868     Error("PostDigitizer", "-> Task //%s/Digitizer not found!", fTasksFolder);
869     return kFALSE ;
870   }        
871
872   TTask * emcal = dynamic_cast<TTask*>(d->GetListOfTasks()->FindObject("EMCAL")) ; 
873
874   if ( !emcal )  {
875     if (fDebug) {
876       Warning("PostDigitizer", "-> //%s/Digitizer/EMCAL not found!", fTasksFolder);
877
878       Info("PostDigitizer", "-> Adding //%s/Digitizer/EMCAL", fTasksFolder);
879     }
880     emcal = new TTask("EMCAL", "") ; 
881     d->Add(emcal) ; 
882
883
884   AliEMCALDigitizer * emcald = dynamic_cast<AliEMCALDigitizer*>(emcal->GetListOfTasks()->FindObject(name)) ; 
885
886   if (!emcald) { 
887     emcald = new AliEMCALDigitizer() ;
888     emcald->SetName(fDigitsTitle) ;
889     emcald->SetTitle(fHeaderFile) ;
890     emcal->Add(emcald) ;
891   }
892
893   return kTRUE;  
894 }
895
896 //____________________________________________________________________________ 
897
898 TObject ** AliEMCALGetter::DigitizerRef(const char * name) const 
899 {  
900
901   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ; 
902
903   if ( !sd ) {
904     Fatal("DigitizerRef", "-> Task //%s/Digitizer not found!", fTasksFolder->GetName());
905   }        
906
907   TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ; 
908
909   if ( !emcal )  {
910     Fatal("DigitizerRef", "->  //%s/Digitizer/EMCAL", fTasksFolder->GetName());
911   }        
912
913   TTask * task = dynamic_cast<TTask*>(emcal->GetListOfTasks()->FindObject(name)) ; 
914
915   return emcal->GetListOfTasks()->GetObjectRef(task) ;
916 }
917
918 //____________________________________________________________________________ 
919
920 const Bool_t AliEMCALGetter::PostRecPoints(const char * name) const 
921
922   // -------------- RecPoints -------------------------------------------
923   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/TowerRecPoints/name
924   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/PreShowerRecPoints/name
925
926   TFolder * emcalFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL")) ; 
927
928   if ( !emcalFolder ) {
929     if (fDebug) {
930       Warning("PostRecPoints", "-> Folder //%s/EMCAL/ not found!", fRecoFolder);
931       Info("PostRecPoints", "-> Adding Folder //%s/EMCAL/", fRecoFolder);
932     }
933     emcalFolder = fRecoFolder->AddFolder("EMCAL", "Reconstructed data from EMCAL") ;  
934   }    
935
936   // Tower RecPoints 
937
938   TFolder * emcalRPoTowerFolder  = dynamic_cast<TFolder*>(emcalFolder->FindObject("TowerRecPoints")) ;
939
940   if ( !emcalRPoTowerFolder ) {
941     if (fDebug) {
942
943       Warning("PostRecPoints", "-> Folder //%s/EMCAL/TowerRecPoints/ not found!", fRecoFolder);
944       Info("PostRecPoints", "-> Adding Folder //%s/EMCAL/TowerRecPoints not found!", fRecoFolder);
945     }
946     emcalRPoTowerFolder = emcalFolder->AddFolder("TowerRecPoints", "Tower RecPoints from EMCAL") ;  
947   }    
948
949   TObject * erp = emcalFolder->FindObject( name ) ;
950
951   if ( !erp )   {
952     TObjArray * towerrp = new TObjArray(100) ;
953     towerrp->SetName(name) ;
954     emcalRPoTowerFolder->Add(towerrp) ;  
955   }
956
957   // Pre Shower RecPoints 
958
959   TFolder * emcalRPoPreShoFolder  = dynamic_cast<TFolder*>(emcalFolder->FindObject("PreShowerRecPoints")) ;
960
961   if ( !emcalRPoPreShoFolder ) {
962     if (fDebug) {
963       Warning("PostRecPoints", "-> Folder //%s/EMCAL/PreShowerRecPoints/ not found!", fRecoFolder);
964       Info("PostRecPoints", "-> Adding Folder //%s/EMCAL/PreShowerRecPoints/", fRecoFolder);
965     }
966     emcalRPoPreShoFolder = emcalFolder->AddFolder("PreShowerRecPoints", "PreSho RecPoints from EMCAL") ;  
967   }    
968
969   TObject * crp =  emcalRPoPreShoFolder->FindObject( name ) ;
970
971   if ( !crp )   {
972     TObjArray * preshorp = new TObjArray(100) ;
973     preshorp->SetName(name) ;
974     emcalRPoPreShoFolder->Add(preshorp) ;  
975   }
976
977   return kTRUE; 
978 }
979
980 //____________________________________________________________________________ 
981
982 TObject ** AliEMCALGetter::TowerRecPointsRef(const char * name) const 
983
984   // -------------- RecPoints -------------------------------------------
985   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/TowerRecPoints/name
986
987   if ( !fRecoFolder ) {
988     Fatal("TowerRecPointsRef", "-> Folder //%s not found!", fRecoFolder);
989   }    
990
991   TFolder * towerFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/TowerRecPoints")) ; 
992
993   if ( !towerFolder ) {
994     Fatal("TowerRecPointsRef", "-> Folder //%s/EMCAL/TowerRecPoints/ not found!", fRecoFolder);
995   }    
996
997   TObject * trp = towerFolder->FindObject(name ) ;
998
999   if ( !trp )   {
1000     Fatal("TowerRecPointsRef", "-> Object %s not found!", name);
1001   }
1002
1003   return towerFolder->GetListOfFolders()->GetObjectRef(trp) ;
1004
1005
1006 //____________________________________________________________________________ 
1007
1008 TObject ** AliEMCALGetter::PreShowerRecPointsRef(const char * name) const 
1009
1010   // -------------- RecPoints -------------------------------------------
1011   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/PreShowerRecPoints/name
1012
1013   if ( !fRecoFolder ) {
1014     Fatal("PreShowerRecPointsRef", "-> Folder //%s not found!", fRecoFolder);
1015   }    
1016
1017   TFolder * preshoFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/PreShowerRecPoints")) ; 
1018
1019   if ( !preshoFolder ) {
1020     Fatal("PreShowerRecPointsRef", "-> Folder //%s/EMCAL/PreShowerRecPoints/", fRecoFolder);
1021   }    
1022
1023
1024
1025   TObject * prp = preshoFolder->FindObject(name ) ;
1026
1027   if ( !prp )   {
1028     Fatal("PreShowerRecPointsRef", "-> Object %s not found!", name);
1029   }
1030
1031   return preshoFolder->GetListOfFolders()->GetObjectRef(prp) ;
1032
1033
1034 //____________________________________________________________________________ 
1035
1036 const Bool_t AliEMCALGetter::PostClusterizer(AliEMCALClusterizer * clu) const 
1037
1038   // ------------------ AliEMCALClusterizer ------------------------
1039   // the hierarchy is //Folders/Tasks/Reconstructioner/EMCAL/sdigitsname
1040
1041   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
1042
1043   if ( !tasks ) {
1044     Error("PostClusterizer", "-> Task //%s/Reconstructioner not found!", fTasksFolder);
1045     return kFALSE ;
1046   }        
1047
1048   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
1049
1050   if ( !emcal )  {
1051     if (fDebug) {
1052       Warning("PostClusterizer", "-> //%s/ReconstructionerEMCAL not found!", fTasksFolder);
1053       Info("PostClusterizer", "-> Adding //%s/Reconstructioner/EMCAL", fTasksFolder);
1054     }
1055     emcal = new TTask("EMCAL", "") ; 
1056     tasks->Add(emcal) ; 
1057   } 
1058
1059   AliEMCALClusterizerv1 * emcalcl = dynamic_cast<AliEMCALClusterizerv1*>(emcal->GetListOfTasks()->FindObject(clu->GetName())) ; 
1060
1061   if (emcalcl) { 
1062     if (fDebug)
1063       Info("PostClusterizer", "-> Task %s already exists", clu->GetName());
1064     emcalcl->Delete() ; 
1065     emcal->GetListOfTasks()->Remove(emcalcl) ;
1066   }
1067   emcal->Add(clu) ;      
1068
1069   return kTRUE; 
1070
1071
1072 //____________________________________________________________________________ 
1073
1074 TObject ** AliEMCALGetter::ClusterizerRef(const char * name) const 
1075
1076   // ------------------ AliEMCALClusterizer ------------------------
1077
1078   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
1079
1080   if ( !tasks ) {
1081     Fatal("ClusterizerRef", "-> Task //%s/Reconstructioner not found!", fTasksFolder->GetName());
1082   }        
1083
1084   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
1085
1086   if ( !emcal )  {
1087     Fatal("ClusterizerRef", "-> //%s/Reconstructioner/EMCAL", fTasksFolder->GetName());
1088   }   
1089
1090   TList * l = emcal->GetListOfTasks() ; 
1091   TIter it(l) ;
1092   TTask * task ;
1093   TTask * clu = 0 ;
1094   TString cluname(name) ;
1095   cluname+=":clu-" ;
1096
1097   while((task = static_cast<TTask *>(it.Next()) )){
1098     TString taskname(task->GetName()) ;
1099     if(taskname.BeginsWith(cluname)){
1100       clu = task ;
1101       break ;
1102     }
1103   }
1104
1105   if(!clu) {
1106     Fatal("ClusterizerRef", "-> task %s not found!", task->GetName());
1107   }
1108
1109   return l->GetObjectRef(clu) ;
1110 }
1111
1112 //____________________________________________________________________________ 
1113
1114 const Bool_t AliEMCALGetter::PostClusterizer(const char * name) const 
1115
1116   // ------------------ AliEMCALClusterizer ------------------------
1117   // the hierarchy is //Folders/Tasks/Reconstructioner/EMCAL/sdigitsname
1118   
1119
1120   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
1121
1122   if ( !tasks ) {
1123     Error("PostClusterizer", "-> Task //%s/Reconstructioner not found!", fTasksFolder->GetName());
1124     return kFALSE ;
1125   }        
1126
1127   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
1128
1129   if ( !emcal )  {
1130     if (fDebug) {
1131       Warning("PostClusterizer", "-> //%s/Reconstructioner/EMCAL not found!", fTasksFolder);
1132       Info("PostClusterizer", "-> Adding //%s/Reconstructioner/EMCAL", fTasksFolder);
1133     }
1134     emcal = new TTask("EMCAL", "") ; 
1135     tasks->Add(emcal) ; 
1136   } 
1137
1138   TList * l = emcal->GetListOfTasks() ;   
1139   TIter it(l) ;
1140   TString clun(name) ;
1141   clun+=":clu" ; 
1142   TTask * task ;
1143
1144   while((task = static_cast<TTask *>(it.Next()) )){
1145     TString taskname(task->GetName()) ;
1146
1147     if(taskname.BeginsWith(clun))
1148       return kTRUE ;
1149   }
1150
1151   AliEMCALClusterizerv1 * emcalcl = new AliEMCALClusterizerv1() ;
1152
1153   clun+="-v1" ; 
1154   emcalcl->SetName(clun) ;
1155   emcalcl->SetTitle(fHeaderFile) ; 
1156   emcal->Add(emcalcl) ;
1157
1158   return kTRUE; 
1159 }
1160
1161 //____________________________________________________________________________ 
1162
1163 TTree * AliEMCALGetter::TreeK(TString filename)  
1164 {
1165   // returns TreeK from file filename
1166   // usefull in case of split file
1167
1168   if ( filename.IsNull() ) 
1169     filename = fHeaderFile ; 
1170
1171   TFile * file = 0 ; 
1172
1173   file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
1174
1175   if (!file)  {  // file not yet open 
1176     file = TFile::Open(filename.Data(), "read") ; 
1177   }    
1178
1179   TString treeName("TreeK") ; 
1180   treeName += EventNumber()  ; 
1181   TTree * tree = static_cast<TTree *>(file->Get(treeName.Data())) ;
1182
1183   if (!tree && fDebug)  
1184     Warning("TreeK", "-> %s not found in %s", treeName.Data(),filename.Data());
1185
1186   return tree ;                       
1187 }
1188
1189 //____________________________________________________________________________ 
1190
1191 TTree * AliEMCALGetter::TreeH(TString filename)  
1192 {
1193   // returns TreeH from file filename
1194   // usefull in case of split file
1195
1196   if ( filename.IsNull() ) 
1197     filename = fHeaderFile ; 
1198
1199   TFile * file = 0 ; 
1200   file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
1201
1202   if (!file) { // file not open yet
1203     file = TFile::Open(filename.Data(), "read") ; 
1204   }
1205
1206   TString treeName("TreeH") ; 
1207   treeName += EventNumber()  ; 
1208   TTree * tree = static_cast<TTree *>(file->Get(treeName.Data())) ;
1209
1210   if (!tree && fDebug)  
1211     Warning("TreeH", "-> %s not found in %s", treeName.Data(), filename.Data());
1212   return tree ;                       
1213 }
1214
1215 //____________________________________________________________________________ 
1216
1217 TTree * AliEMCALGetter::TreeS(TString filename)  
1218 {
1219   // returns TreeS from file filename
1220   // usefull in case of split file
1221
1222   if ( filename.IsNull() ) 
1223     filename = fHeaderFile ; 
1224
1225   TFile * file = 0 ; 
1226   file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
1227
1228   if (!file) { // file not open yet
1229     file = TFile::Open(filename.Data(), "read") ; 
1230   }
1231
1232   TString treeName("TreeS") ; 
1233   treeName += EventNumber()  ; 
1234   TTree * tree = static_cast<TTree *>(file->Get(treeName.Data())) ;
1235
1236   if (!tree && fDebug)  
1237     Warning("TreeS", "-> %s not found in %s", treeName.Data(), filename.Data());
1238   return tree ;                       
1239 }
1240
1241 //____________________________________________________________________________ 
1242
1243 TTree * AliEMCALGetter::TreeD(TString filename)  
1244 {
1245   // returns TreeD from file filename
1246   // usefull in case of split file
1247
1248   if ( filename.IsNull() ) 
1249     filename = fHeaderFile ; 
1250
1251   TFile * file = 0 ; 
1252   file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
1253
1254   if (!file) { // file not open yet
1255     file = TFile::Open(filename.Data(), "read") ; 
1256   }
1257
1258   TString treeName("TreeD") ; 
1259   treeName += EventNumber()  ; 
1260   TTree * tree = static_cast<TTree *>(file->Get(treeName.Data())) ;
1261
1262   if (!tree && fDebug)  
1263     Warning("TreeD", "-> %s not found in %s", treeName.Data(), filename.Data());
1264   return tree ;                       
1265 }
1266
1267 //____________________________________________________________________________ 
1268
1269 const TParticle * AliEMCALGetter::Primary(Int_t index) const
1270 {
1271   // Return primary particle numbered by <index>
1272
1273   if(index < 0) 
1274     return 0 ;
1275
1276   TParticle *  p = 0 ;
1277   p = gAlice->Particle(index) ; 
1278   
1279   return p ; 
1280 }
1281
1282 //____________________________________________________________________________ 
1283
1284 const TParticle * AliEMCALGetter::Secondary(TParticle* p, Int_t index) const
1285 {
1286   // Return first (index=1) or second (index=2) secondary particle of primary particle p 
1287
1288   if(index <= 0) 
1289     return 0 ;
1290   if(index > 2)
1291     return 0 ;
1292
1293   if(p) {
1294     Int_t daughterIndex = p->GetDaughter(index-1) ; 
1295     return  gAlice->Particle(daughterIndex) ; 
1296   }
1297   else
1298     return 0 ;
1299 }
1300
1301 //____________________________________________________________________________ 
1302
1303 Int_t AliEMCALGetter::ReadTreeD(const Int_t event)
1304 {
1305   // Read the digit tree gAlice->TreeD()  
1306
1307   TTree * treeD ;
1308   if(fToSplit){
1309     TFile * file = static_cast<TFile*>(gROOT->GetFile(fDigitsFileName)); 
1310     if(!file) 
1311       file = TFile::Open(fDigitsFileName) ;      
1312
1313     // Get Digits Tree header from file
1314
1315     TString treeName("TreeD") ;
1316     treeName += event ; 
1317     treeD = dynamic_cast<TTree*>(file->Get(treeName.Data()));
1318
1319     if(!treeD){ // TreeD not found in header file
1320       if (fDebug)
1321         Warning("ReadTreeD", "-> Cannot find TreeD in %s", fDigitsFileName.Data());
1322       return 1;
1323     }
1324   }
1325   else
1326     treeD = gAlice->TreeD() ;
1327
1328   TObjArray * lob = static_cast<TObjArray*>(treeD->GetListOfBranches()) ;
1329   TIter next(lob) ; 
1330   TBranch * branch = 0 ; 
1331   TBranch * digitsbranch = 0 ; 
1332   TBranch * digitizerbranch = 0 ; 
1333
1334   Bool_t emcalfound = kFALSE, digitizerfound = kFALSE ; 
1335
1336   while ( (branch = static_cast<TBranch*>(next())) && (!emcalfound || !digitizerfound) ) {
1337     if ( (strcmp(branch->GetName(), "EMCAL")==0) && (strcmp(branch->GetTitle(), fDigitsTitle)==0) ) {
1338       digitsbranch = branch ; 
1339       emcalfound = kTRUE ;
1340     }
1341     else if ( (strcmp(branch->GetName(), "AliEMCALDigitizer")==0) && (strcmp(branch->GetTitle(), fDigitsTitle)==0) ) {
1342       digitizerbranch = branch ; 
1343       digitizerfound = kTRUE ; 
1344     }
1345   }
1346
1347   if ( !emcalfound || !digitizerfound ) {
1348     if (fDebug)
1349       Warning("ReadTreeD", "-> Cannot find Digits and/or Digitizer with name %s", fDigitsTitle.Data());
1350     return 2; 
1351   }   
1352
1353   //read digits
1354
1355   if(!Digits(fDigitsTitle) ) 
1356     PostDigits(fDigitsTitle);
1357   digitsbranch->SetAddress(DigitsRef(fDigitsTitle)) ;
1358   digitsbranch->GetEntry(0) ;
1359
1360   // read  the Digitizer
1361
1362   RemoveTask("D", fDigitsTitle) ; // I do not understand why I need that 
1363   if(!Digitizer(fDigitsTitle))
1364     PostDigitizer(fDigitsTitle) ;
1365   digitizerbranch->SetAddress(DigitizerRef(fDigitsTitle)) ;
1366   digitizerbranch->GetEntry(0) ;
1367
1368   lob->Delete();
1369
1370   if(gAlice->TreeD()!=treeD)
1371     treeD->Delete();
1372
1373   return 0 ; 
1374 }
1375
1376 //____________________________________________________________________________ 
1377
1378 Int_t AliEMCALGetter::ReadTreeH()
1379 {
1380   // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
1381
1382   TTree * treeH = gAlice->TreeH() ;
1383
1384   if(!treeH) {// TreeH not found in header file
1385     if (fDebug) 
1386       Warning("ReadTreeH", "-> Cannot find TreeH in %s", fHeaderFile.Data());
1387
1388     TString searchFileName("EMCAL.HITS") ; 
1389     if((strcmp(fBranchTitle.Data(),"Default")!=0)&&(strcmp(fBranchTitle.Data(),"")!=0)){
1390       searchFileName+="." ;
1391       searchFileName += fBranchTitle ;
1392     }
1393
1394     searchFileName+=".root" ;
1395
1396     if ( (treeH = TreeH(searchFileName)) ) { //found TreeH in the file which contains the hits
1397       if (fDebug) 
1398         Info("ReadTreeH", "-> TreeH found in %s", searchFileName.Data());
1399     } else {
1400       Error("ReadTreeH", "-> TreeH not found "); 
1401       return 1;
1402     }  
1403   }
1404
1405   TBranch * hitsbranch = static_cast<TBranch*>(gAlice->TreeH()->GetBranch("EMCAL")) ;
1406
1407   if ( !hitsbranch ) {
1408     if (fDebug)
1409       Warning("ReadTreeH", "-> Cannot find branch EMCAL"); 
1410     return 2;
1411   }
1412
1413   if(!Hits())
1414     PostHits() ;
1415
1416   if (hitsbranch->GetEntries() > 1 ) {
1417     (dynamic_cast<TClonesArray*> (*HitsRef()))->Clear() ;
1418     TClonesArray * tempo =  new TClonesArray("AliEMCALHit",1000) ;
1419     TClonesArray * hits = dynamic_cast<TClonesArray*>(*HitsRef()) ; 
1420     hitsbranch->SetAddress(&tempo) ;
1421
1422     Int_t index = 0 ; 
1423     Int_t i = 0 ;
1424
1425     for (i = 0 ; i < hitsbranch->GetEntries() ; i++) {
1426       hitsbranch->GetEntry(i) ;
1427       Int_t j = 0 ; 
1428       for ( j = 0 ; j < tempo->GetEntries() ; j++) { 
1429         const AliEMCALHit * hit = static_cast<const AliEMCALHit *>(tempo->At(j)) ; 
1430         new((*hits)[index]) AliEMCALHit( *hit ) ;
1431         index++ ; 
1432       }
1433     }
1434     delete tempo ; 
1435   }
1436   else {
1437     (dynamic_cast<TClonesArray*> (*HitsRef()))->Clear() ;
1438     hitsbranch->SetAddress(HitsRef()) ;
1439     hitsbranch->GetEntry(0) ;
1440   }
1441   return 0 ; 
1442 }
1443
1444 //____________________________________________________________________________ 
1445
1446 void AliEMCALGetter::Track(const Int_t itrack)
1447 {
1448   // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
1449   if(gAlice->TreeH()== 0){
1450     Error("ReadTreeH", "-> Cannot read TreeH ");
1451     return ;
1452   }
1453
1454   TBranch * hitsbranch = dynamic_cast<TBranch*>(gAlice->TreeH()->GetListOfBranches()->FindObject("EMCAL")) ;
1455
1456   if ( !hitsbranch ) {
1457     if (fDebug)
1458       Warning("ReadTreeH", "-> Cannot find branch EMCAL"); 
1459     return ;
1460   }  
1461
1462   if(!Hits())
1463     PostHits() ;
1464
1465   (dynamic_cast<TClonesArray*> (*HitsRef()))->Clear() ;
1466   hitsbranch->SetAddress(HitsRef()) ;
1467   hitsbranch->GetEntry(itrack) ;
1468 }
1469
1470 //____________________________________________________________________________ 
1471
1472 void AliEMCALGetter::ReadTreeQA()
1473 {
1474   if (fDebug)
1475     Warning("ReadTreeQA", "-> %s not implemented", ClassName());
1476 }
1477
1478   
1479
1480 //____________________________________________________________________________ 
1481
1482 Int_t AliEMCALGetter::ReadTreeR(const Int_t event)
1483
1484 {
1485   // Read the reconstrunction tree gAlice->TreeR()
1486   // A particularity has been introduced here :
1487   //  if gime->Event(ievent,"R") is called branches with the current title are read, the current title
1488   //   being for example give in AliEMCALPID(fileName, title)
1489   //  if gime(Event(ievent, "RA") is called the title of the branches is not checked anymore, "A" stands for any
1490   // This is a feature needed by PID to be able to reconstruct several times particles (each time a ther title is given)
1491   // from a given set of TrackSegments (with a given name)
1492   // This is why any is NOT used to read the branch of RecParticles
1493   // any migh have become obsolete : to be checked
1494   // See AliEMCALPIDv1    
1495
1496   TTree * treeR ;
1497
1498   if(fToSplit){
1499     TFile * file = static_cast<TFile*>(gROOT->GetFile(fRecPointsFileName)); 
1500     if(!file) 
1501       file = TFile::Open(fRecPointsFileName) ;      
1502     Info("ReadTreeR", "file=%s\n",fRecPointsFileName.Data()); 
1503     // Get Digits Tree header from file
1504
1505     TString treeName("TreeR") ;
1506     treeName += event ; 
1507     treeR = dynamic_cast<TTree*>(file->Get(treeName.Data()));
1508
1509     if(!treeR){ // TreeR not found in header file
1510       if (fDebug)
1511         Warning("ReadTreeD", "-> Cannot find TreeR in %s", fRecPointsFileName.Data());
1512       return 1;
1513     }
1514   }
1515   else
1516     treeR = gAlice->TreeR() ;
1517
1518   // RecPoints 
1519
1520   TObjArray * lob = static_cast<TObjArray*>(treeR->GetListOfBranches()) ;
1521   TIter next(lob) ; 
1522   TBranch * branch = 0 ; 
1523   TBranch * towerbranch = 0 ; 
1524   TBranch * preshowerbranch = 0 ; 
1525   TBranch * clusterizerbranch = 0 ; 
1526
1527   Bool_t emcalTowerRPfound = kFALSE, emcalPreShoRPfound = kFALSE, clusterizerfound = kFALSE ; 
1528
1529   while ( (branch = static_cast<TBranch*>(next())) && (!emcalTowerRPfound || !emcalPreShoRPfound || !clusterizerfound) ) {
1530     if(strcmp(branch->GetTitle(), fRecPointsTitle)==0 ) {
1531       if ( strcmp(branch->GetName(), "EMCALTowerRP")==0) {
1532         towerbranch = branch ; 
1533         emcalTowerRPfound = kTRUE ;
1534       }
1535       else if ( strcmp(branch->GetName(), "EMCALPreShoRP")==0) {
1536         preshowerbranch = branch ; 
1537         emcalPreShoRPfound = kTRUE ;
1538       }
1539       else if(strcmp(branch->GetName(), "AliEMCALClusterizer")==0){
1540         clusterizerbranch = branch ; 
1541         clusterizerfound = kTRUE ; 
1542       }
1543     }
1544   }
1545
1546   if ( !emcalTowerRPfound || !emcalPreShoRPfound || !clusterizerfound) {
1547     if (fDebug)
1548       Warning("ReadTreeR", "-> Cannot find RecPoints and/or Clusterizer with name %s", fRecPointsTitle.Data());
1549   } 
1550   else { 
1551     if(!TowerRecPoints(fRecPointsTitle) ) 
1552       PostRecPoints(fRecPointsTitle) ;
1553     towerbranch->SetAddress(TowerRecPointsRef(fRecPointsTitle)) ;
1554     towerbranch->GetEntry(0) ;
1555
1556     preshowerbranch->SetAddress(PreShowerRecPointsRef(fRecPointsTitle)) ; 
1557     preshowerbranch->GetEntry(0) ;  
1558
1559     if(!Clusterizer(fRecPointsTitle) )
1560       PostClusterizer(fRecPointsTitle) ;
1561
1562     clusterizerbranch->SetAddress(ClusterizerRef(fRecPointsTitle)) ;
1563     clusterizerbranch->GetEntry(0) ;
1564   }
1565
1566   if(gAlice->TreeR()!=treeR)
1567     treeR->Delete();
1568   return 0 ; 
1569 }
1570
1571 //____________________________________________________________________________ 
1572
1573 Int_t AliEMCALGetter::ReadTreeS(const Int_t event)
1574 {
1575   // Reads the SDigits treeS from all files  
1576   // Files, which should be opened are listed in emcalF
1577   // So, first get list of files
1578
1579   TFolder * emcalF = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject("EMCAL")) ;
1580
1581   if (!emcalF) 
1582     emcalF = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ; 
1583
1584   TCollection * folderslist = emcalF->GetListOfFolders() ; 
1585
1586   // Now iterate over the list of files and read TreeS into Whiteboard
1587
1588   TIter next(folderslist) ; 
1589   TFolder * folder = 0 ; 
1590   TFile * file; 
1591   TTree * treeS = 0;
1592
1593   while ( (folder = static_cast<TFolder*>(next())) ) {
1594     TString fileName("") ;
1595     if(fToSplit)
1596       fileName = folder->GetTitle() ;
1597     else
1598       fileName = folder->GetName() ; 
1599
1600     fileName.ReplaceAll("_","/") ; 
1601     file = static_cast<TFile*>(gROOT->GetFile(fileName)); 
1602
1603     if(!file) 
1604       file = TFile::Open(fileName) ;      
1605
1606     // Get SDigits Tree header from file
1607
1608     TString treeName("TreeS") ;
1609     treeName += event ; 
1610     treeS = dynamic_cast<TTree*>(file->Get(treeName.Data()));
1611
1612     if(!treeS){ // TreeS not found in header file
1613       if (fDebug)
1614         Warning("ReadTreeS", "-> Cannot find TreeS in %s", fileName.Data());
1615       return 1;
1616     }
1617
1618     //set address of the SDigits and SDigitizer
1619
1620     TBranch   * sdigitsBranch    = 0;
1621     TBranch   * sdigitizerBranch = 0;
1622     TBranch   * branch           = 0 ;  
1623     TObjArray * lob = static_cast<TObjArray*>(treeS->GetListOfBranches()) ;
1624     TIter next(lob) ; 
1625
1626     Bool_t emcalfound = kFALSE, sdigitizerfound = kFALSE ; 
1627
1628     while ( (branch = static_cast<TBranch*>(next())) && (!emcalfound || !sdigitizerfound) ) {
1629       if ( (strcmp(branch->GetName(), "EMCAL")==0) && (strcmp(branch->GetTitle(), fSDigitsTitle)==0) ) {
1630         emcalfound = kTRUE ;
1631         sdigitsBranch = branch ; 
1632       }
1633       else if ( (strcmp(branch->GetName(), "AliEMCALSDigitizer")==0) && 
1634                 (strcmp(branch->GetTitle(), fSDigitsTitle)==0) ) {
1635         sdigitizerfound = kTRUE ; 
1636         sdigitizerBranch = branch ;
1637       }
1638     }
1639     if ( !emcalfound || !sdigitizerfound ) {
1640       if (fDebug)
1641         Warning("ReadSDigits", "-> Digits and/or Digitizer branch with name %s not found", GetName());
1642       return 2; 
1643     }   
1644
1645     if ( !folder->FindObject(fSDigitsTitle) )  
1646       PostSDigits(fSDigitsTitle,folder->GetName()) ;
1647
1648     ((TClonesArray*) (*SDigitsRef(fSDigitsTitle,folder->GetName())))->Clear() ;
1649
1650     sdigitsBranch->SetAddress(SDigitsRef(fSDigitsTitle,folder->GetName())) ;
1651     sdigitsBranch->GetEntry(0) ;
1652
1653     TString sdname(fSDigitsTitle) ;
1654     sdname+=":" ;
1655     sdname+=folder->GetName() ;
1656
1657     if(!SDigitizer(sdname) ) 
1658       PostSDigitizer(fSDigitsTitle,folder->GetName()) ;
1659
1660     sdigitizerBranch->SetAddress(SDigitizerRef(sdname)) ;
1661     sdigitizerBranch->GetEntry(0) ; 
1662
1663     if(gAlice->TreeS()!=treeS)
1664       treeS->Delete();
1665   }    
1666    return 0 ;  
1667 }
1668
1669 //____________________________________________________________________________ 
1670
1671 void AliEMCALGetter::ReadTreeS(TTree * treeS, Int_t input)
1672 {  
1673   // Read the summable digits fron treeS()  
1674
1675   TString filename("mergefile") ;
1676   filename+= input ;
1677
1678   TFolder * emcalFolder = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ; 
1679   if ( !emcalFolder ) { 
1680     emcalFolder = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ; 
1681   } 
1682
1683   TFolder * folder=(TFolder*)emcalFolder->FindObject(filename) ;
1684
1685   //set address of the SDigits and SDigitizer
1686
1687   TBranch   * sdigitsBranch    = 0;
1688   TBranch   * sdigitizerBranch = 0;
1689   TBranch   * branch           = 0 ;  
1690   TObjArray * lob = (TObjArray*)treeS->GetListOfBranches() ;
1691   TIter next(lob) ; 
1692
1693   Bool_t emcalfound = kFALSE, sdigitizerfound = kFALSE ; 
1694
1695   while ( (branch = (TBranch*)next()) && (!emcalfound || !sdigitizerfound) ) {
1696     if ( strcmp(branch->GetName(), "EMCAL")==0) {
1697       emcalfound = kTRUE ;
1698       sdigitsBranch = branch ; 
1699     }
1700     else if ( strcmp(branch->GetName(), "AliEMCALSDigitizer")==0) {
1701       sdigitizerfound = kTRUE ; 
1702       sdigitizerBranch = branch ;
1703     }
1704   }
1705
1706   if ( !emcalfound || !sdigitizerfound ) {
1707     if (fDebug)
1708       Warning("ReadTreeS", "-> Digits and/or Digitizer branch not found");
1709     return ; 
1710   }   
1711
1712   if (!folder || !(folder->FindObject(sdigitsBranch->GetTitle()) ) )
1713     PostSDigits(sdigitsBranch->GetTitle(),filename) ;
1714
1715   sdigitsBranch->SetAddress(SDigitsRef(sdigitsBranch->GetTitle(),filename)) ;
1716   sdigitsBranch->GetEntry(0) ;
1717
1718   TString sdname(sdigitsBranch->GetTitle()) ;
1719   sdname+=":" ;
1720   sdname+=filename ;
1721
1722   if(!SDigitizer(sdigitsBranch->GetTitle()) )
1723     PostSDigitizer(sdigitsBranch->GetTitle(),filename) ;
1724
1725   sdigitizerBranch->SetAddress(SDigitizerRef(sdname)) ;
1726   sdigitizerBranch->GetEntry(0) ;
1727
1728   if(gAlice->TreeS()!=treeS)
1729     treeS->Delete();
1730 }    
1731
1732 //____________________________________________________________________________ 
1733
1734 void AliEMCALGetter::ReadPrimaries()
1735 {
1736
1737   // Reads specific branches of primaries
1738
1739   TClonesArray * ar = 0  ; 
1740
1741   if(! (ar = Primaries()) ) { 
1742     PostPrimaries() ;
1743     ar = Primaries() ; 
1744   }
1745
1746   ar->Delete() ; 
1747
1748   if (TreeK(fHeaderFile)) { // treeK found in header file
1749     if (fDebug) 
1750       Info("ReadPrimaries", "-> TreeK found in %s", fHeaderFile.Data());
1751     fNPrimaries = gAlice->GetNtrack() ; 
1752   } 
1753   else { // treeK not found in header file
1754     Error("ReadPrimaries", "-> TreeK not  found ");
1755     return ;
1756   }
1757
1758   Int_t index = 0 ; 
1759
1760   for (index = 0 ; index < fNPrimaries; index++) { 
1761     new ((*ar)[index]) TParticle(*(Primary(index)));
1762   }
1763 }
1764
1765 //____________________________________________________________________________ 
1766
1767 void AliEMCALGetter::Event(const Int_t event, const char* opt)
1768 {
1769   // Reads the content of all Tree's S, D and R
1770
1771   if (event >= gAlice->TreeE()->GetEntries() ) {
1772     Error("Event", "-> %d not found in TreeE!", event);
1773     return ; 
1774   }
1775
1776   Bool_t any = kFALSE ; 
1777
1778   if (strstr(opt,"A") ) // do not check the title of the branches
1779     any = kTRUE; 
1780
1781   gAlice->GetEvent(event) ; 
1782
1783   if( strstr(opt,"R") )
1784     ReadTreeR(event) ;
1785
1786   if( strstr(opt,"D") )
1787     ReadTreeD(event) ;
1788
1789   if(strstr(opt,"S") )
1790     ReadTreeS(event) ;
1791
1792   if(strstr(opt,"H") )
1793     ReadTreeH() ;
1794
1795   if( strstr(opt,"Q") )
1796     ReadTreeQA() ;
1797
1798   if( strstr(opt,"P") )
1799     ReadPrimaries() ;
1800 }
1801
1802 //____________________________________________________________________________ 
1803
1804 TObject * AliEMCALGetter::ReturnO(TString what, TString name, TString file) const 
1805 {
1806   // get the object named "what" from the folder
1807   // folders are named like //Folders
1808
1809   if ( file.IsNull() ) 
1810     file = fHeaderFile ; 
1811
1812   TFolder * folder = 0 ;
1813   TObject * emcalO  = 0 ; 
1814
1815   if ( what.CompareTo("Primaries") == 0 ) {
1816     folder = dynamic_cast<TFolder *>(fPrimariesFolder->FindObject("Primaries")) ; 
1817     if (folder) 
1818       emcalO  = dynamic_cast<TObject *>(folder->FindObject("Primaries")) ;  
1819     else 
1820       return 0 ; 
1821   }
1822   else if ( what.CompareTo("Hits") == 0 ) {
1823     folder = dynamic_cast<TFolder *>(fHitsFolder->FindObject("EMCAL")) ; 
1824     if (folder) 
1825       emcalO  = dynamic_cast<TObject *>(folder->FindObject("Hits")) ;  
1826   }
1827   else if ( what.CompareTo("SDigits") == 0 ) { 
1828     file.ReplaceAll("/","_") ; 
1829     TString path = "EMCAL/" + file  ; 
1830     folder = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject(path.Data())) ; 
1831     if (folder) { 
1832       if (name.IsNull())
1833         name = fSDigitsTitle ; 
1834       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
1835     }
1836   }
1837   else if ( what.CompareTo("Digits") == 0 ){
1838     folder = dynamic_cast<TFolder *>(fDigitsFolder->FindObject("EMCAL")) ; 
1839     if (folder) { 
1840       if (name.IsNull())
1841         name = fDigitsTitle ; 
1842       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
1843     } 
1844   }
1845   else if ( what.CompareTo("TowerRecPoints") == 0 ) {
1846     folder = dynamic_cast<TFolder *>(fRecoFolder->FindObject("EMCAL/TowerRecPoints")) ; 
1847     if (folder) { 
1848       if (name.IsNull())
1849         name = fRecPointsTitle ; 
1850       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
1851     } 
1852   }
1853   else if ( what.CompareTo("PreShowerRecPoints") == 0 ) {
1854     folder = dynamic_cast<TFolder *>(fRecoFolder->FindObject("EMCAL/PreShowerRecPoints")) ; 
1855     if (folder) { 
1856       if (name.IsNull())
1857         name = fRecPointsTitle ; 
1858       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
1859     }   
1860   }
1861
1862   if (!emcalO) {
1863     if(fDebug)
1864       Warning("ReturnO", "-> Object %s  not found in %s", what.Data(), folder->GetName());
1865     return 0 ;
1866   }
1867
1868   return emcalO ;
1869 }
1870
1871 //____________________________________________________________________________ 
1872
1873 const TTask * AliEMCALGetter::ReturnT(TString what, TString name) const 
1874 {
1875   // get the TTask named "what" from the folder
1876   // folders are named like //Folders/Tasks/what/EMCAL/name
1877
1878   TString search(what) ; 
1879   if ( what.CompareTo("Clusterizer") == 0 ) 
1880     search = "Reconstructioner" ; 
1881   else if ( what.CompareTo("TrackSegmentMaker") == 0 ) 
1882     search = "Reconstructioner" ; 
1883   else if ( what.CompareTo("PID") == 0 ) 
1884     search = "Reconstructioner" ; 
1885   else if ( what.CompareTo("QATasks") == 0 ) 
1886     search = "QA" ; 
1887   
1888   TTask * tasks = dynamic_cast<TTask*>(fTasksFolder->FindObject(search)) ; 
1889
1890   if (!tasks) {
1891     Error("AliReturnT", "-> Task %s not found!", what.Data());
1892     return 0 ; 
1893   }
1894
1895   TTask * emcalT = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
1896
1897   if (!emcalT) { 
1898     Error("ReturnT", "-> Task %s/EMCAL not found!", what.Data());
1899     return 0 ; 
1900   }
1901
1902   TList * list = emcalT->GetListOfTasks() ; 
1903
1904   if (what.CompareTo("SDigitizer") == 0) {  
1905     if ( name.IsNull() )
1906       name =  fSDigitsTitle ; 
1907   }
1908   else  if (what.CompareTo("Digitizer") == 0){ 
1909     if ( name.IsNull() )
1910       name =  fDigitsTitle ;
1911   }
1912   else  if (what.CompareTo("Clusterizer") == 0){ 
1913     if ( name.IsNull() )
1914       name =  fRecPointsTitle ;
1915     name.Append(":clu") ;
1916   }
1917
1918   TIter it(list) ;
1919   TTask * task = 0 ; 
1920
1921   while((task = static_cast<TTask *>(it.Next()) )){
1922     TString taskname(task->GetName()) ;
1923     if(taskname.BeginsWith(name)){
1924     return task ;}
1925   }
1926
1927   if(fDebug)
1928     Warning("ReturnT", "-> Task %s/%s not found!", search.Data(), name.Data());
1929   return 0 ;
1930 }
1931
1932 //____________________________________________________________________________ 
1933
1934 void AliEMCALGetter::RemoveTask(TString opt, TString name) const 
1935
1936 {
1937   // remove a task from the folder
1938   // path is fTasksFolder/SDigitizer/EMCAL/name
1939
1940   TTask * task  = 0 ; 
1941   TTask * emcal = 0 ; 
1942   TList * lofTasks = 0 ; 
1943
1944   if (opt == "S") { // SDigitizer
1945     task = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ;
1946     if (!task) 
1947       return ; 
1948   } 
1949   else if (opt == "D") { // Digitizer
1950     task = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ;
1951     if (!task) 
1952       return ; 
1953   }
1954   else if (opt == "C") { // Clusterizer
1955     task = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ;
1956     if (!task) 
1957       return ; 
1958   }
1959   else {
1960     Warning("RemoveTask", "-> Unknown option %s");
1961     return ; 
1962   }    
1963
1964   emcal =  dynamic_cast<TTask*>(task->GetListOfTasks()->FindObject("EMCAL")) ;
1965
1966   if (!emcal)
1967     return ; 
1968
1969   lofTasks = emcal->GetListOfTasks() ;
1970
1971   if (!lofTasks) 
1972     return ; 
1973
1974   TObject * obj = lofTasks->FindObject(name) ; 
1975   if (obj) 
1976
1977     lofTasks->Remove(obj) ;
1978 }
1979
1980 //____________________________________________________________________________ 
1981
1982 void AliEMCALGetter::RemoveObjects(TString opt, TString name) const 
1983 {
1984   // remove SDigits from the folder
1985   // path is fSDigitsFolder/fHeaderFileName/name
1986
1987   TFolder * emcal     = 0 ; 
1988   TFolder * emcalmain = 0 ; 
1989
1990   if (opt == "H") { // Hits
1991     emcal = dynamic_cast<TFolder*>(fHitsFolder->FindObject("EMCAL")) ;
1992     if (!emcal) 
1993       return ;
1994     name = "Hits" ; 
1995   }
1996   else if ( opt == "S") { // SDigits
1997     emcalmain = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
1998     if (!emcalmain) 
1999       return ;
2000     emcal = dynamic_cast<TFolder*>(emcalmain->FindObject(fHeaderFile)) ;
2001     if (!emcal) 
2002       return ;
2003   }
2004   else if (opt == "D") { // Digits
2005     emcal = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ;
2006     if (!emcal) 
2007       return ;
2008   }
2009   else if (opt == "RT") { // Tower RecPoints
2010     emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/TowerRecPoints")) ;
2011     if (!emcal) 
2012       return ;
2013   }
2014   else if (opt == "RP") { // Preshower RecPoints
2015     emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/PreShowerRecPoints")) ;
2016     if (!emcal) 
2017       return ;
2018   }
2019   else if (opt == "T") { // TrackSegments
2020     emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/TrackSegments")) ;
2021     if (!emcal) 
2022       return ;
2023   }
2024   else if (opt == "P") { // RecParticles
2025     emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/RecParticles")) ;
2026     if (!emcal) 
2027       return ;
2028   }
2029   else {
2030     Warning("RemoveObjects", "-> Unknown option %s", opt.Data());
2031     return ; 
2032   }
2033
2034   TObjArray * ar  = dynamic_cast<TObjArray*>(emcal->FindObject(name)) ; 
2035
2036   if (ar) { 
2037     emcal->Remove(ar) ;
2038     ar->Delete() ; 
2039     delete ar ; 
2040   }
2041
2042   if (opt == "S") 
2043     emcalmain->Remove(emcal) ; 
2044 }
2045
2046 //____________________________________________________________________________ 
2047
2048 void AliEMCALGetter::RemoveSDigits() const 
2049 {
2050   TFolder * emcal= dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
2051
2052   if (!emcal) 
2053     return ;
2054
2055   emcal->SetOwner() ; 
2056   emcal->Clear() ; 
2057 }
2058
2059 //____________________________________________________________________________ 
2060
2061 void AliEMCALGetter::CleanWhiteBoard(void){
2062
2063   TFolder * emcalmain = 0 ; 
2064   TFolder * emcal ;
2065   TObjArray * ar ;
2066   TList * lofTasks = 0 ; 
2067   TTask * task = 0 ; 
2068   TTask * emcalt = 0 ; 
2069
2070   // Hits  
2071
2072   emcal = dynamic_cast<TFolder*>(fHitsFolder->FindObject("EMCAL")) ;
2073
2074   if (emcal){  
2075     TObjArray * ar  = dynamic_cast<TObjArray*>(emcal->FindObject("Hits")) ; 
2076     if (ar) { 
2077       emcal->Remove(ar) ;
2078       ar->Delete() ; 
2079       delete ar ; 
2080     }
2081   }
2082
2083   // SDigits
2084
2085   emcalmain = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
2086
2087   if (emcalmain){ 
2088     emcal = dynamic_cast<TFolder*>(emcalmain->FindObject(fHeaderFile)) ;
2089     if (emcal) {
2090       ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fSDigitsTitle)) ; 
2091       if (ar) { 
2092         emcal->Remove(ar) ;
2093         ar->Delete() ; 
2094         delete ar ; 
2095       }
2096     }
2097     emcalmain->Remove(emcal) ; 
2098   }
2099
2100   // Digits
2101
2102   emcal = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ;
2103
2104   if (emcal){ 
2105     ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fDigitsTitle)) ; 
2106     if (ar) { 
2107       emcal->Remove(ar) ;
2108       ar->Delete() ; 
2109       delete ar ; 
2110     }
2111   }
2112
2113   // TowerRecPoints
2114
2115   emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/TowerRecPoints")) ;
2116
2117   if (emcal){ 
2118     ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fRecPointsTitle)) ; 
2119     if (ar) { 
2120       emcal->Remove(ar) ;
2121       ar->Delete() ; 
2122       delete ar ; 
2123     }
2124   }
2125
2126   // PreShowerRecPoints
2127
2128   emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/PreShowerRecPoints")) ;
2129
2130   if (emcal){ 
2131     ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fRecPointsTitle)) ; 
2132     if (ar) { 
2133       emcal->Remove(ar) ;
2134       ar->Delete() ; 
2135       delete ar ; 
2136     }
2137   }  
2138
2139   // TrackSegments
2140
2141   emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/TrackSegments")) ;
2142
2143   if (emcal) { 
2144     ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fTrackSegmentsTitle)) ; 
2145     if (ar) { 
2146       emcal->Remove(ar) ;
2147       ar->Delete() ; 
2148       delete ar ; 
2149     }
2150   }
2151
2152   // RecParticles
2153
2154   emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/RecParticles")) ;
2155
2156   if (emcal){ 
2157     ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fRecParticlesTitle)) ; 
2158     if (ar) { 
2159       emcal->Remove(ar) ;
2160       ar->Delete() ; 
2161       delete ar ; 
2162     }
2163   }
2164
2165   //---- Now Tasks ----------- 
2166
2167   TObject * obj ;
2168   TString sdname(fSDigitsTitle);
2169
2170   // Digitizer
2171
2172   task = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ;
2173
2174   if (task){ 
2175     emcalt =  dynamic_cast<TTask*>(task->GetListOfTasks()->FindObject("EMCAL")) ;
2176     if (emcalt){
2177       lofTasks = emcalt->GetListOfTasks() ;
2178       if (lofTasks){ 
2179         obj = lofTasks->FindObject(sdname.Data()) ; 
2180         if (obj) 
2181           lofTasks->Remove(obj) ;
2182       }
2183     }      
2184   }
2185
2186   sdname.Append(":") ;
2187
2188   // Clusterizer, TrackSegmentMaker, PID
2189
2190   task = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ;
2191
2192   if (task){ 
2193     emcalt =  dynamic_cast<TTask*>(task->GetListOfTasks()->FindObject("EMCAL")) ;
2194     if (emcalt){
2195       lofTasks = emcalt->GetListOfTasks() ;
2196       TIter next(lofTasks);
2197       while((obj=next())){ 
2198         TString oname(obj->GetName()) ;
2199         if (oname.BeginsWith(sdname)){ 
2200           lofTasks->Remove(obj) ;
2201         }
2202       }
2203     }  
2204   }
2205
2206   // SDigitizer
2207
2208   sdname.Append(fHeaderFile) ;
2209   task = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ;
2210
2211   if (task) {
2212     emcalt =  dynamic_cast<TTask*>(task->GetListOfTasks()->FindObject("EMCAL")) ;
2213     if (emcalt){
2214       lofTasks = emcalt->GetListOfTasks() ;
2215       if (lofTasks){ 
2216         obj = lofTasks->FindObject(sdname.Data()) ; 
2217         if (obj) 
2218           lofTasks->Remove(obj) ;
2219       }
2220     }
2221   }  
2222 }
2223
2224 //____________________________________________________________________________ 
2225
2226 void AliEMCALGetter::SetTitle(const char * branchTitle ) 
2227
2228 {
2229   fBranchTitle        = branchTitle ;
2230   fSDigitsTitle       = branchTitle ; 
2231   fDigitsTitle        = branchTitle ; 
2232   fRecPointsTitle     = branchTitle ; 
2233   fRecParticlesTitle  = branchTitle ; 
2234   fTrackSegmentsTitle = branchTitle ; 
2235
2236   if(fToSplit){
2237
2238     //First - extract full path if necessary
2239
2240     TString sFileName(fHeaderFile) ;
2241     Ssiz_t islash = sFileName.Last('/') ;
2242
2243     if(islash<sFileName.Length())
2244       sFileName.Remove(islash+1,sFileName.Length()) ;
2245     else
2246       sFileName="" ;
2247
2248     //Now construct file names
2249
2250     fSDigitsFileName       = sFileName ;
2251     fDigitsFileName        = sFileName ; 
2252     fRecPointsFileName     = sFileName ; 
2253     fRecParticlesFileName  = sFileName ; 
2254     fTrackSegmentsFileName = sFileName ; 
2255     fSDigitsFileName      += "EMCAL.SDigits." ;
2256     fDigitsFileName       += "EMCAL.Digits." ; 
2257     fRecPointsFileName    += "EMCAL.RecData." ; 
2258     fTrackSegmentsFileName+= "EMCAL.RecData." ; 
2259     fRecParticlesFileName += "EMCAL.RecData." ; 
2260
2261     if((strcmp(fBranchTitle.Data(),"Default")!=0)&&(strcmp(fBranchTitle.Data(),"")!=0)){
2262       fSDigitsFileName      += fBranchTitle ;
2263       fSDigitsFileName      += "." ;
2264       fDigitsFileName       += fBranchTitle ; 
2265       fDigitsFileName       += "." ; 
2266       fRecPointsFileName    += fBranchTitle ; 
2267       fRecPointsFileName    += "." ; 
2268       fRecParticlesFileName += fBranchTitle ; 
2269       fRecParticlesFileName += "." ; 
2270       fTrackSegmentsFileName+= fBranchTitle ; 
2271       fTrackSegmentsFileName+= "." ; 
2272     }
2273
2274     fSDigitsFileName      += "root" ;
2275     fDigitsFileName       += "root" ; 
2276     fRecPointsFileName    += "root" ; 
2277     fRecParticlesFileName += "root" ; 
2278     fTrackSegmentsFileName+= "root" ; 
2279   }
2280   else{
2281     fSDigitsFileName       = "" ; 
2282     fDigitsFileName        = "" ; 
2283     fRecPointsFileName     = "" ; 
2284     fRecParticlesFileName  = "" ; 
2285     fTrackSegmentsFileName = "" ; 
2286   }
2287
2288   TFolder * emcalFolder ; 
2289   emcalFolder = dynamic_cast<TFolder*>(fHitsFolder->FindObject("EMCAL")) ; 
2290
2291   if ( !emcalFolder ) 
2292     emcalFolder = fHitsFolder->AddFolder("EMCAL", "Hits from EMCAL") ; 
2293
2294   emcalFolder = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
2295
2296   if ( !emcalFolder ) 
2297     emcalFolder = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ; 
2298
2299   //Make folder for SDigits
2300
2301   TString subdir(fHeaderFile) ;
2302   subdir.ReplaceAll("/","_") ;
2303
2304   emcalFolder->AddFolder(subdir, fSDigitsFileName.Data());
2305   emcalFolder  = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ;
2306
2307   if ( !emcalFolder ) 
2308     emcalFolder = fDigitsFolder->AddFolder("EMCAL", "Digits from EMCAL") ;  
2309
2310   emcalFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL")) ; 
2311
2312   if ( !emcalFolder )
2313     emcalFolder = fRecoFolder->AddFolder("EMCAL", "Reconstructed data from EMCAL") ;  
2314 }
2315
2316 //____________________________________________________________________________ 
2317
2318 void AliEMCALGetter::CloseSplitFiles(void){
2319
2320   TFile * file ;
2321   file = static_cast<TFile*>(gROOT->GetFile(fSDigitsFileName.Data() ) ) ;
2322
2323   if(file)
2324     file->Close() ;
2325
2326   file = static_cast<TFile*>(gROOT->GetFile(fDigitsFileName.Data() ) ) ;
2327
2328   if(file)
2329     file->Close() ;
2330
2331   file = static_cast<TFile*>(gROOT->GetFile(fRecPointsFileName.Data() ) ) ;
2332
2333   if(file)
2334     file->Close() ;
2335
2336   file = static_cast<TFile*>(gROOT->GetFile(fTrackSegmentsFileName.Data() ) ) ;
2337
2338   if(file)
2339     file->Close() ;
2340
2341   file = static_cast<TFile*>(gROOT->GetFile(fRecParticlesFileName.Data() ) ) ;
2342
2343   if(file)
2344     file->Close() ;
2345 }
2346
2347
2348
2349
2350
2351