]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALGetter.cxx
removed a Info()
[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     // Get Digits Tree header from file
1503
1504     TString treeName("TreeR") ;
1505     treeName += event ; 
1506     treeR = dynamic_cast<TTree*>(file->Get(treeName.Data()));
1507
1508     if(!treeR){ // TreeR not found in header file
1509       if (fDebug)
1510         Warning("ReadTreeD", "-> Cannot find TreeR in %s", fRecPointsFileName.Data());
1511       return 1;
1512     }
1513   }
1514   else
1515     treeR = gAlice->TreeR() ;
1516
1517   // RecPoints 
1518
1519   TObjArray * lob = static_cast<TObjArray*>(treeR->GetListOfBranches()) ;
1520   TIter next(lob) ; 
1521   TBranch * branch = 0 ; 
1522   TBranch * towerbranch = 0 ; 
1523   TBranch * preshowerbranch = 0 ; 
1524   TBranch * clusterizerbranch = 0 ; 
1525
1526   Bool_t emcalTowerRPfound = kFALSE, emcalPreShoRPfound = kFALSE, clusterizerfound = kFALSE ; 
1527
1528   while ( (branch = static_cast<TBranch*>(next())) && (!emcalTowerRPfound || !emcalPreShoRPfound || !clusterizerfound) ) {
1529     if(strcmp(branch->GetTitle(), fRecPointsTitle)==0 ) {
1530       if ( strcmp(branch->GetName(), "EMCALTowerRP")==0) {
1531         towerbranch = branch ; 
1532         emcalTowerRPfound = kTRUE ;
1533       }
1534       else if ( strcmp(branch->GetName(), "EMCALPreShoRP")==0) {
1535         preshowerbranch = branch ; 
1536         emcalPreShoRPfound = kTRUE ;
1537       }
1538       else if(strcmp(branch->GetName(), "AliEMCALClusterizer")==0){
1539         clusterizerbranch = branch ; 
1540         clusterizerfound = kTRUE ; 
1541       }
1542     }
1543   }
1544
1545   if ( !emcalTowerRPfound || !emcalPreShoRPfound || !clusterizerfound) {
1546     if (fDebug)
1547       Warning("ReadTreeR", "-> Cannot find RecPoints and/or Clusterizer with name %s", fRecPointsTitle.Data());
1548   } 
1549   else { 
1550     if(!TowerRecPoints(fRecPointsTitle) ) 
1551       PostRecPoints(fRecPointsTitle) ;
1552     towerbranch->SetAddress(TowerRecPointsRef(fRecPointsTitle)) ;
1553     towerbranch->GetEntry(0) ;
1554
1555     preshowerbranch->SetAddress(PreShowerRecPointsRef(fRecPointsTitle)) ; 
1556     preshowerbranch->GetEntry(0) ;  
1557
1558     if(!Clusterizer(fRecPointsTitle) )
1559       PostClusterizer(fRecPointsTitle) ;
1560
1561     clusterizerbranch->SetAddress(ClusterizerRef(fRecPointsTitle)) ;
1562     clusterizerbranch->GetEntry(0) ;
1563   }
1564
1565   if(gAlice->TreeR()!=treeR)
1566     treeR->Delete();
1567   return 0 ; 
1568 }
1569
1570 //____________________________________________________________________________ 
1571
1572 Int_t AliEMCALGetter::ReadTreeS(const Int_t event)
1573 {
1574   // Reads the SDigits treeS from all files  
1575   // Files, which should be opened are listed in emcalF
1576   // So, first get list of files
1577
1578   TFolder * emcalF = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject("EMCAL")) ;
1579
1580   if (!emcalF) 
1581     emcalF = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ; 
1582
1583   TCollection * folderslist = emcalF->GetListOfFolders() ; 
1584
1585   // Now iterate over the list of files and read TreeS into Whiteboard
1586
1587   TIter next(folderslist) ; 
1588   TFolder * folder = 0 ; 
1589   TFile * file; 
1590   TTree * treeS = 0;
1591
1592   while ( (folder = static_cast<TFolder*>(next())) ) {
1593     TString fileName("") ;
1594     if(fToSplit)
1595       fileName = folder->GetTitle() ;
1596     else
1597       fileName = folder->GetName() ; 
1598
1599     fileName.ReplaceAll("_","/") ; 
1600     file = static_cast<TFile*>(gROOT->GetFile(fileName)); 
1601
1602     if(!file) 
1603       file = TFile::Open(fileName) ;      
1604
1605     // Get SDigits Tree header from file
1606
1607     TString treeName("TreeS") ;
1608     treeName += event ; 
1609     treeS = dynamic_cast<TTree*>(file->Get(treeName.Data()));
1610
1611     if(!treeS){ // TreeS not found in header file
1612       if (fDebug)
1613         Warning("ReadTreeS", "-> Cannot find TreeS in %s", fileName.Data());
1614       return 1;
1615     }
1616
1617     //set address of the SDigits and SDigitizer
1618
1619     TBranch   * sdigitsBranch    = 0;
1620     TBranch   * sdigitizerBranch = 0;
1621     TBranch   * branch           = 0 ;  
1622     TObjArray * lob = static_cast<TObjArray*>(treeS->GetListOfBranches()) ;
1623     TIter next(lob) ; 
1624
1625     Bool_t emcalfound = kFALSE, sdigitizerfound = kFALSE ; 
1626
1627     while ( (branch = static_cast<TBranch*>(next())) && (!emcalfound || !sdigitizerfound) ) {
1628       if ( (strcmp(branch->GetName(), "EMCAL")==0) && (strcmp(branch->GetTitle(), fSDigitsTitle)==0) ) {
1629         emcalfound = kTRUE ;
1630         sdigitsBranch = branch ; 
1631       }
1632       else if ( (strcmp(branch->GetName(), "AliEMCALSDigitizer")==0) && 
1633                 (strcmp(branch->GetTitle(), fSDigitsTitle)==0) ) {
1634         sdigitizerfound = kTRUE ; 
1635         sdigitizerBranch = branch ;
1636       }
1637     }
1638     if ( !emcalfound || !sdigitizerfound ) {
1639       if (fDebug)
1640         Warning("ReadSDigits", "-> Digits and/or Digitizer branch with name %s not found", GetName());
1641       return 2; 
1642     }   
1643
1644     if ( !folder->FindObject(fSDigitsTitle) )  
1645       PostSDigits(fSDigitsTitle,folder->GetName()) ;
1646
1647     ((TClonesArray*) (*SDigitsRef(fSDigitsTitle,folder->GetName())))->Clear() ;
1648
1649     sdigitsBranch->SetAddress(SDigitsRef(fSDigitsTitle,folder->GetName())) ;
1650     sdigitsBranch->GetEntry(0) ;
1651
1652     TString sdname(fSDigitsTitle) ;
1653     sdname+=":" ;
1654     sdname+=folder->GetName() ;
1655
1656     if(!SDigitizer(sdname) ) 
1657       PostSDigitizer(fSDigitsTitle,folder->GetName()) ;
1658
1659     sdigitizerBranch->SetAddress(SDigitizerRef(sdname)) ;
1660     sdigitizerBranch->GetEntry(0) ; 
1661
1662     if(gAlice->TreeS()!=treeS)
1663       treeS->Delete();
1664   }    
1665    return 0 ;  
1666 }
1667
1668 //____________________________________________________________________________ 
1669
1670 void AliEMCALGetter::ReadTreeS(TTree * treeS, Int_t input)
1671 {  
1672   // Read the summable digits fron treeS()  
1673
1674   TString filename("mergefile") ;
1675   filename+= input ;
1676
1677   TFolder * emcalFolder = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ; 
1678   if ( !emcalFolder ) { 
1679     emcalFolder = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ; 
1680   } 
1681
1682   TFolder * folder=(TFolder*)emcalFolder->FindObject(filename) ;
1683
1684   //set address of the SDigits and SDigitizer
1685
1686   TBranch   * sdigitsBranch    = 0;
1687   TBranch   * sdigitizerBranch = 0;
1688   TBranch   * branch           = 0 ;  
1689   TObjArray * lob = (TObjArray*)treeS->GetListOfBranches() ;
1690   TIter next(lob) ; 
1691
1692   Bool_t emcalfound = kFALSE, sdigitizerfound = kFALSE ; 
1693
1694   while ( (branch = (TBranch*)next()) && (!emcalfound || !sdigitizerfound) ) {
1695     if ( strcmp(branch->GetName(), "EMCAL")==0) {
1696       emcalfound = kTRUE ;
1697       sdigitsBranch = branch ; 
1698     }
1699     else if ( strcmp(branch->GetName(), "AliEMCALSDigitizer")==0) {
1700       sdigitizerfound = kTRUE ; 
1701       sdigitizerBranch = branch ;
1702     }
1703   }
1704
1705   if ( !emcalfound || !sdigitizerfound ) {
1706     if (fDebug)
1707       Warning("ReadTreeS", "-> Digits and/or Digitizer branch not found");
1708     return ; 
1709   }   
1710
1711   if (!folder || !(folder->FindObject(sdigitsBranch->GetTitle()) ) )
1712     PostSDigits(sdigitsBranch->GetTitle(),filename) ;
1713
1714   sdigitsBranch->SetAddress(SDigitsRef(sdigitsBranch->GetTitle(),filename)) ;
1715   sdigitsBranch->GetEntry(0) ;
1716
1717   TString sdname(sdigitsBranch->GetTitle()) ;
1718   sdname+=":" ;
1719   sdname+=filename ;
1720
1721   if(!SDigitizer(sdigitsBranch->GetTitle()) )
1722     PostSDigitizer(sdigitsBranch->GetTitle(),filename) ;
1723
1724   sdigitizerBranch->SetAddress(SDigitizerRef(sdname)) ;
1725   sdigitizerBranch->GetEntry(0) ;
1726
1727   if(gAlice->TreeS()!=treeS)
1728     treeS->Delete();
1729 }    
1730
1731 //____________________________________________________________________________ 
1732
1733 void AliEMCALGetter::ReadPrimaries()
1734 {
1735
1736   // Reads specific branches of primaries
1737
1738   TClonesArray * ar = 0  ; 
1739
1740   if(! (ar = Primaries()) ) { 
1741     PostPrimaries() ;
1742     ar = Primaries() ; 
1743   }
1744
1745   ar->Delete() ; 
1746
1747   if (TreeK(fHeaderFile)) { // treeK found in header file
1748     if (fDebug) 
1749       Info("ReadPrimaries", "-> TreeK found in %s", fHeaderFile.Data());
1750     fNPrimaries = gAlice->GetNtrack() ; 
1751   } 
1752   else { // treeK not found in header file
1753     Error("ReadPrimaries", "-> TreeK not  found ");
1754     return ;
1755   }
1756
1757   Int_t index = 0 ; 
1758
1759   for (index = 0 ; index < fNPrimaries; index++) { 
1760     new ((*ar)[index]) TParticle(*(Primary(index)));
1761   }
1762 }
1763
1764 //____________________________________________________________________________ 
1765
1766 void AliEMCALGetter::Event(const Int_t event, const char* opt)
1767 {
1768   // Reads the content of all Tree's S, D and R
1769
1770   if (event >= gAlice->TreeE()->GetEntries() ) {
1771     Error("Event", "-> %d not found in TreeE!", event);
1772     return ; 
1773   }
1774
1775   Bool_t any = kFALSE ; 
1776
1777   if (strstr(opt,"A") ) // do not check the title of the branches
1778     any = kTRUE; 
1779
1780   gAlice->GetEvent(event) ; 
1781
1782   if( strstr(opt,"R") )
1783     ReadTreeR(event) ;
1784
1785   if( strstr(opt,"D") )
1786     ReadTreeD(event) ;
1787
1788   if(strstr(opt,"S") )
1789     ReadTreeS(event) ;
1790
1791   if(strstr(opt,"H") )
1792     ReadTreeH() ;
1793
1794   if( strstr(opt,"Q") )
1795     ReadTreeQA() ;
1796
1797   if( strstr(opt,"P") )
1798     ReadPrimaries() ;
1799 }
1800
1801 //____________________________________________________________________________ 
1802
1803 TObject * AliEMCALGetter::ReturnO(TString what, TString name, TString file) const 
1804 {
1805   // get the object named "what" from the folder
1806   // folders are named like //Folders
1807
1808   if ( file.IsNull() ) 
1809     file = fHeaderFile ; 
1810
1811   TFolder * folder = 0 ;
1812   TObject * emcalO  = 0 ; 
1813
1814   if ( what.CompareTo("Primaries") == 0 ) {
1815     folder = dynamic_cast<TFolder *>(fPrimariesFolder->FindObject("Primaries")) ; 
1816     if (folder) 
1817       emcalO  = dynamic_cast<TObject *>(folder->FindObject("Primaries")) ;  
1818     else 
1819       return 0 ; 
1820   }
1821   else if ( what.CompareTo("Hits") == 0 ) {
1822     folder = dynamic_cast<TFolder *>(fHitsFolder->FindObject("EMCAL")) ; 
1823     if (folder) 
1824       emcalO  = dynamic_cast<TObject *>(folder->FindObject("Hits")) ;  
1825   }
1826   else if ( what.CompareTo("SDigits") == 0 ) { 
1827     file.ReplaceAll("/","_") ; 
1828     TString path = "EMCAL/" + file  ; 
1829     folder = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject(path.Data())) ; 
1830     if (folder) { 
1831       if (name.IsNull())
1832         name = fSDigitsTitle ; 
1833       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
1834     }
1835   }
1836   else if ( what.CompareTo("Digits") == 0 ){
1837     folder = dynamic_cast<TFolder *>(fDigitsFolder->FindObject("EMCAL")) ; 
1838     if (folder) { 
1839       if (name.IsNull())
1840         name = fDigitsTitle ; 
1841       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
1842     } 
1843   }
1844   else if ( what.CompareTo("TowerRecPoints") == 0 ) {
1845     folder = dynamic_cast<TFolder *>(fRecoFolder->FindObject("EMCAL/TowerRecPoints")) ; 
1846     if (folder) { 
1847       if (name.IsNull())
1848         name = fRecPointsTitle ; 
1849       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
1850     } 
1851   }
1852   else if ( what.CompareTo("PreShowerRecPoints") == 0 ) {
1853     folder = dynamic_cast<TFolder *>(fRecoFolder->FindObject("EMCAL/PreShowerRecPoints")) ; 
1854     if (folder) { 
1855       if (name.IsNull())
1856         name = fRecPointsTitle ; 
1857       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
1858     }   
1859   }
1860
1861   if (!emcalO) {
1862     if(fDebug)
1863       Warning("ReturnO", "-> Object %s  not found in %s", what.Data(), folder->GetName());
1864     return 0 ;
1865   }
1866
1867   return emcalO ;
1868 }
1869
1870 //____________________________________________________________________________ 
1871
1872 const TTask * AliEMCALGetter::ReturnT(TString what, TString name) const 
1873 {
1874   // get the TTask named "what" from the folder
1875   // folders are named like //Folders/Tasks/what/EMCAL/name
1876
1877   TString search(what) ; 
1878   if ( what.CompareTo("Clusterizer") == 0 ) 
1879     search = "Reconstructioner" ; 
1880   else if ( what.CompareTo("TrackSegmentMaker") == 0 ) 
1881     search = "Reconstructioner" ; 
1882   else if ( what.CompareTo("PID") == 0 ) 
1883     search = "Reconstructioner" ; 
1884   else if ( what.CompareTo("QATasks") == 0 ) 
1885     search = "QA" ; 
1886   
1887   TTask * tasks = dynamic_cast<TTask*>(fTasksFolder->FindObject(search)) ; 
1888
1889   if (!tasks) {
1890     Error("AliReturnT", "-> Task %s not found!", what.Data());
1891     return 0 ; 
1892   }
1893
1894   TTask * emcalT = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
1895
1896   if (!emcalT) { 
1897     Error("ReturnT", "-> Task %s/EMCAL not found!", what.Data());
1898     return 0 ; 
1899   }
1900
1901   TList * list = emcalT->GetListOfTasks() ; 
1902
1903   if (what.CompareTo("SDigitizer") == 0) {  
1904     if ( name.IsNull() )
1905       name =  fSDigitsTitle ; 
1906   }
1907   else  if (what.CompareTo("Digitizer") == 0){ 
1908     if ( name.IsNull() )
1909       name =  fDigitsTitle ;
1910   }
1911   else  if (what.CompareTo("Clusterizer") == 0){ 
1912     if ( name.IsNull() )
1913       name =  fRecPointsTitle ;
1914     name.Append(":clu") ;
1915   }
1916
1917   TIter it(list) ;
1918   TTask * task = 0 ; 
1919
1920   while((task = static_cast<TTask *>(it.Next()) )){
1921     TString taskname(task->GetName()) ;
1922     if(taskname.BeginsWith(name)){
1923     return task ;}
1924   }
1925
1926   if(fDebug)
1927     Warning("ReturnT", "-> Task %s/%s not found!", search.Data(), name.Data());
1928   return 0 ;
1929 }
1930
1931 //____________________________________________________________________________ 
1932
1933 void AliEMCALGetter::RemoveTask(TString opt, TString name) const 
1934
1935 {
1936   // remove a task from the folder
1937   // path is fTasksFolder/SDigitizer/EMCAL/name
1938
1939   TTask * task  = 0 ; 
1940   TTask * emcal = 0 ; 
1941   TList * lofTasks = 0 ; 
1942
1943   if (opt == "S") { // SDigitizer
1944     task = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ;
1945     if (!task) 
1946       return ; 
1947   } 
1948   else if (opt == "D") { // Digitizer
1949     task = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ;
1950     if (!task) 
1951       return ; 
1952   }
1953   else if (opt == "C") { // Clusterizer
1954     task = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ;
1955     if (!task) 
1956       return ; 
1957   }
1958   else {
1959     Warning("RemoveTask", "-> Unknown option %s");
1960     return ; 
1961   }    
1962
1963   emcal =  dynamic_cast<TTask*>(task->GetListOfTasks()->FindObject("EMCAL")) ;
1964
1965   if (!emcal)
1966     return ; 
1967
1968   lofTasks = emcal->GetListOfTasks() ;
1969
1970   if (!lofTasks) 
1971     return ; 
1972
1973   TObject * obj = lofTasks->FindObject(name) ; 
1974   if (obj) 
1975
1976     lofTasks->Remove(obj) ;
1977 }
1978
1979 //____________________________________________________________________________ 
1980
1981 void AliEMCALGetter::RemoveObjects(TString opt, TString name) const 
1982 {
1983   // remove SDigits from the folder
1984   // path is fSDigitsFolder/fHeaderFileName/name
1985
1986   TFolder * emcal     = 0 ; 
1987   TFolder * emcalmain = 0 ; 
1988
1989   if (opt == "H") { // Hits
1990     emcal = dynamic_cast<TFolder*>(fHitsFolder->FindObject("EMCAL")) ;
1991     if (!emcal) 
1992       return ;
1993     name = "Hits" ; 
1994   }
1995   else if ( opt == "S") { // SDigits
1996     emcalmain = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
1997     if (!emcalmain) 
1998       return ;
1999     emcal = dynamic_cast<TFolder*>(emcalmain->FindObject(fHeaderFile)) ;
2000     if (!emcal) 
2001       return ;
2002   }
2003   else if (opt == "D") { // Digits
2004     emcal = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ;
2005     if (!emcal) 
2006       return ;
2007   }
2008   else if (opt == "RT") { // Tower RecPoints
2009     emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/TowerRecPoints")) ;
2010     if (!emcal) 
2011       return ;
2012   }
2013   else if (opt == "RP") { // Preshower RecPoints
2014     emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/PreShowerRecPoints")) ;
2015     if (!emcal) 
2016       return ;
2017   }
2018   else if (opt == "T") { // TrackSegments
2019     emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/TrackSegments")) ;
2020     if (!emcal) 
2021       return ;
2022   }
2023   else if (opt == "P") { // RecParticles
2024     emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/RecParticles")) ;
2025     if (!emcal) 
2026       return ;
2027   }
2028   else {
2029     Warning("RemoveObjects", "-> Unknown option %s", opt.Data());
2030     return ; 
2031   }
2032
2033   TObjArray * ar  = dynamic_cast<TObjArray*>(emcal->FindObject(name)) ; 
2034
2035   if (ar) { 
2036     emcal->Remove(ar) ;
2037     ar->Delete() ; 
2038     delete ar ; 
2039   }
2040
2041   if (opt == "S") 
2042     emcalmain->Remove(emcal) ; 
2043 }
2044
2045 //____________________________________________________________________________ 
2046
2047 void AliEMCALGetter::RemoveSDigits() const 
2048 {
2049   TFolder * emcal= dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
2050
2051   if (!emcal) 
2052     return ;
2053
2054   emcal->SetOwner() ; 
2055   emcal->Clear() ; 
2056 }
2057
2058 //____________________________________________________________________________ 
2059
2060 void AliEMCALGetter::CleanWhiteBoard(void){
2061
2062   TFolder * emcalmain = 0 ; 
2063   TFolder * emcal ;
2064   TObjArray * ar ;
2065   TList * lofTasks = 0 ; 
2066   TTask * task = 0 ; 
2067   TTask * emcalt = 0 ; 
2068
2069   // Hits  
2070
2071   emcal = dynamic_cast<TFolder*>(fHitsFolder->FindObject("EMCAL")) ;
2072
2073   if (emcal){  
2074     TObjArray * ar  = dynamic_cast<TObjArray*>(emcal->FindObject("Hits")) ; 
2075     if (ar) { 
2076       emcal->Remove(ar) ;
2077       ar->Delete() ; 
2078       delete ar ; 
2079     }
2080   }
2081
2082   // SDigits
2083
2084   emcalmain = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
2085
2086   if (emcalmain){ 
2087     emcal = dynamic_cast<TFolder*>(emcalmain->FindObject(fHeaderFile)) ;
2088     if (emcal) {
2089       ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fSDigitsTitle)) ; 
2090       if (ar) { 
2091         emcal->Remove(ar) ;
2092         ar->Delete() ; 
2093         delete ar ; 
2094       }
2095     }
2096     emcalmain->Remove(emcal) ; 
2097   }
2098
2099   // Digits
2100
2101   emcal = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ;
2102
2103   if (emcal){ 
2104     ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fDigitsTitle)) ; 
2105     if (ar) { 
2106       emcal->Remove(ar) ;
2107       ar->Delete() ; 
2108       delete ar ; 
2109     }
2110   }
2111
2112   // TowerRecPoints
2113
2114   emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/TowerRecPoints")) ;
2115
2116   if (emcal){ 
2117     ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fRecPointsTitle)) ; 
2118     if (ar) { 
2119       emcal->Remove(ar) ;
2120       ar->Delete() ; 
2121       delete ar ; 
2122     }
2123   }
2124
2125   // PreShowerRecPoints
2126
2127   emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/PreShowerRecPoints")) ;
2128
2129   if (emcal){ 
2130     ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fRecPointsTitle)) ; 
2131     if (ar) { 
2132       emcal->Remove(ar) ;
2133       ar->Delete() ; 
2134       delete ar ; 
2135     }
2136   }  
2137
2138   // TrackSegments
2139
2140   emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/TrackSegments")) ;
2141
2142   if (emcal) { 
2143     ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fTrackSegmentsTitle)) ; 
2144     if (ar) { 
2145       emcal->Remove(ar) ;
2146       ar->Delete() ; 
2147       delete ar ; 
2148     }
2149   }
2150
2151   // RecParticles
2152
2153   emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/RecParticles")) ;
2154
2155   if (emcal){ 
2156     ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fRecParticlesTitle)) ; 
2157     if (ar) { 
2158       emcal->Remove(ar) ;
2159       ar->Delete() ; 
2160       delete ar ; 
2161     }
2162   }
2163
2164   //---- Now Tasks ----------- 
2165
2166   TObject * obj ;
2167   TString sdname(fSDigitsTitle);
2168
2169   // Digitizer
2170
2171   task = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ;
2172
2173   if (task){ 
2174     emcalt =  dynamic_cast<TTask*>(task->GetListOfTasks()->FindObject("EMCAL")) ;
2175     if (emcalt){
2176       lofTasks = emcalt->GetListOfTasks() ;
2177       if (lofTasks){ 
2178         obj = lofTasks->FindObject(sdname.Data()) ; 
2179         if (obj) 
2180           lofTasks->Remove(obj) ;
2181       }
2182     }      
2183   }
2184
2185   sdname.Append(":") ;
2186
2187   // Clusterizer, TrackSegmentMaker, PID
2188
2189   task = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ;
2190
2191   if (task){ 
2192     emcalt =  dynamic_cast<TTask*>(task->GetListOfTasks()->FindObject("EMCAL")) ;
2193     if (emcalt){
2194       lofTasks = emcalt->GetListOfTasks() ;
2195       TIter next(lofTasks);
2196       while((obj=next())){ 
2197         TString oname(obj->GetName()) ;
2198         if (oname.BeginsWith(sdname)){ 
2199           lofTasks->Remove(obj) ;
2200         }
2201       }
2202     }  
2203   }
2204
2205   // SDigitizer
2206
2207   sdname.Append(fHeaderFile) ;
2208   task = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ;
2209
2210   if (task) {
2211     emcalt =  dynamic_cast<TTask*>(task->GetListOfTasks()->FindObject("EMCAL")) ;
2212     if (emcalt){
2213       lofTasks = emcalt->GetListOfTasks() ;
2214       if (lofTasks){ 
2215         obj = lofTasks->FindObject(sdname.Data()) ; 
2216         if (obj) 
2217           lofTasks->Remove(obj) ;
2218       }
2219     }
2220   }  
2221 }
2222
2223 //____________________________________________________________________________ 
2224
2225 void AliEMCALGetter::SetTitle(const char * branchTitle ) 
2226
2227 {
2228   fBranchTitle        = branchTitle ;
2229   fSDigitsTitle       = branchTitle ; 
2230   fDigitsTitle        = branchTitle ; 
2231   fRecPointsTitle     = branchTitle ; 
2232   fRecParticlesTitle  = branchTitle ; 
2233   fTrackSegmentsTitle = branchTitle ; 
2234
2235   if(fToSplit){
2236
2237     //First - extract full path if necessary
2238
2239     TString sFileName(fHeaderFile) ;
2240     Ssiz_t islash = sFileName.Last('/') ;
2241
2242     if(islash<sFileName.Length())
2243       sFileName.Remove(islash+1,sFileName.Length()) ;
2244     else
2245       sFileName="" ;
2246
2247     //Now construct file names
2248
2249     fSDigitsFileName       = sFileName ;
2250     fDigitsFileName        = sFileName ; 
2251     fRecPointsFileName     = sFileName ; 
2252     fRecParticlesFileName  = sFileName ; 
2253     fTrackSegmentsFileName = sFileName ; 
2254     fSDigitsFileName      += "EMCAL.SDigits." ;
2255     fDigitsFileName       += "EMCAL.Digits." ; 
2256     fRecPointsFileName    += "EMCAL.RecData." ; 
2257     fTrackSegmentsFileName+= "EMCAL.RecData." ; 
2258     fRecParticlesFileName += "EMCAL.RecData." ; 
2259
2260     if((strcmp(fBranchTitle.Data(),"Default")!=0)&&(strcmp(fBranchTitle.Data(),"")!=0)){
2261       fSDigitsFileName      += fBranchTitle ;
2262       fSDigitsFileName      += "." ;
2263       fDigitsFileName       += fBranchTitle ; 
2264       fDigitsFileName       += "." ; 
2265       fRecPointsFileName    += fBranchTitle ; 
2266       fRecPointsFileName    += "." ; 
2267       fRecParticlesFileName += fBranchTitle ; 
2268       fRecParticlesFileName += "." ; 
2269       fTrackSegmentsFileName+= fBranchTitle ; 
2270       fTrackSegmentsFileName+= "." ; 
2271     }
2272
2273     fSDigitsFileName      += "root" ;
2274     fDigitsFileName       += "root" ; 
2275     fRecPointsFileName    += "root" ; 
2276     fRecParticlesFileName += "root" ; 
2277     fTrackSegmentsFileName+= "root" ; 
2278   }
2279   else{
2280     fSDigitsFileName       = "" ; 
2281     fDigitsFileName        = "" ; 
2282     fRecPointsFileName     = "" ; 
2283     fRecParticlesFileName  = "" ; 
2284     fTrackSegmentsFileName = "" ; 
2285   }
2286
2287   TFolder * emcalFolder ; 
2288   emcalFolder = dynamic_cast<TFolder*>(fHitsFolder->FindObject("EMCAL")) ; 
2289
2290   if ( !emcalFolder ) 
2291     emcalFolder = fHitsFolder->AddFolder("EMCAL", "Hits from EMCAL") ; 
2292
2293   emcalFolder = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
2294
2295   if ( !emcalFolder ) 
2296     emcalFolder = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ; 
2297
2298   //Make folder for SDigits
2299
2300   TString subdir(fHeaderFile) ;
2301   subdir.ReplaceAll("/","_") ;
2302
2303   emcalFolder->AddFolder(subdir, fSDigitsFileName.Data());
2304   emcalFolder  = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ;
2305
2306   if ( !emcalFolder ) 
2307     emcalFolder = fDigitsFolder->AddFolder("EMCAL", "Digits from EMCAL") ;  
2308
2309   emcalFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL")) ; 
2310
2311   if ( !emcalFolder )
2312     emcalFolder = fRecoFolder->AddFolder("EMCAL", "Reconstructed data from EMCAL") ;  
2313 }
2314
2315 //____________________________________________________________________________ 
2316
2317 void AliEMCALGetter::CloseSplitFiles(void){
2318
2319   TFile * file ;
2320   file = static_cast<TFile*>(gROOT->GetFile(fSDigitsFileName.Data() ) ) ;
2321
2322   if(file)
2323     file->Close() ;
2324
2325   file = static_cast<TFile*>(gROOT->GetFile(fDigitsFileName.Data() ) ) ;
2326
2327   if(file)
2328     file->Close() ;
2329
2330   file = static_cast<TFile*>(gROOT->GetFile(fRecPointsFileName.Data() ) ) ;
2331
2332   if(file)
2333     file->Close() ;
2334
2335   file = static_cast<TFile*>(gROOT->GetFile(fTrackSegmentsFileName.Data() ) ) ;
2336
2337   if(file)
2338     file->Close() ;
2339
2340   file = static_cast<TFile*>(gROOT->GetFile(fRecParticlesFileName.Data() ) ) ;
2341
2342   if(file)
2343     file->Close() ;
2344 }
2345
2346
2347
2348
2349
2350