]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALGetter.cxx
- Vertex using Vertex() method.
[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 "AliEMCALTrackSegmentMakerv1.h"
78 #include "AliEMCALTrackSegment.h"
79 #include "AliEMCALPIDv1.h" 
80 #include "AliEMCALGeometry.h"
81
82 ClassImp(AliEMCALGetter)
83
84   AliEMCALGetter * AliEMCALGetter::fgObjGetter = 0 ; 
85   TFile * AliEMCALGetter::fFile = 0 ; 
86
87 //____________________________________________________________________________ 
88
89 AliEMCALGetter::AliEMCALGetter(const char* headerFile, const char* branchTitle, const Bool_t toSplit)
90 {
91   // This is the ctor called by GetInstance and the only one that can be used 
92
93   if ( fHeaderFile.Contains("_") ) {
94     Fatal("AliEMCALGetter","Invalid file name (_ not allowed) %s",fHeaderFile.Data()) ;
95   }
96
97   //Initialize  all data
98
99   fFailed = kFALSE ;   
100   fDebug  = 0 ; 
101   fAlice  = 0 ; 
102
103   fToSplit    = toSplit ;
104   fHeaderFile = headerFile ; 
105
106   fPrimaries = new TObjArray(1) ;
107
108   fModuleFolder    = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Configuration/Modules")); 
109   fPrimariesFolder = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/RunMC/Event/Data")); 
110   fHitsFolder      = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/RunMC/Event/Data/Hits")); 
111   fSDigitsFolder   = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/RunMC/Event/Data/SDigits")); 
112   fDigitsFolder    = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Event/Data")); 
113   fRecoFolder      = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Event/RecData")); 
114   //fQAFolder      = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Conditions/QA")); 
115   fTasksFolder     = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Tasks")) ; 
116
117   //Set titles to branches and create EMCAL specific folders
118
119   SetTitle(branchTitle) ;
120
121   if ( fHeaderFile != "aliroot"  ) { // to call the getter without a file
122
123     //open headers file
124
125     fFile = static_cast<TFile*>(gROOT->GetFile(fHeaderFile.Data() ) ) ;
126
127     if(!fFile){    //if file was not opened yet, read gAlice
128       fFile = TFile::Open(fHeaderFile.Data(), "update") ;   
129       if (!fFile->IsOpen()) {
130         Error("AliEMCALGetter","Cannot open %s",fHeaderFile.Data()) ; 
131         fFailed = kTRUE ;
132         return ;  
133       }
134     }
135     gAlice = static_cast<AliRun *>(fFile->Get("gAlice")) ;
136   }
137
138   if (!gAlice) {
139     Error("AliEMCALGetter","Cannot find gAlice in %s",fHeaderFile.Data()) ; 
140     fFailed = kTRUE ;
141     return ; 
142   }
143   if (!EMCAL()) {
144     if (fDebug)
145       Info("AliEMCALGetter","Posting EMCAL to Folders") ; 
146
147     if (gAlice->GetDetector("EMCAL")) {
148       AliConfig * conf = AliConfig::Instance() ;
149       conf->Add(static_cast<AliDetector*>(gAlice->GetDetector("EMCAL"))) ; 
150       conf->Add(static_cast<AliModule*>(gAlice->GetDetector("EMCAL"))) ;
151     }
152     else 
153       Error("AliEMCALGetter"," Detector EMCAL not found");
154   }
155
156   fDebug=0;
157 }
158
159 //____________________________________________________________________________ 
160
161 AliEMCALGetter::~AliEMCALGetter()
162 {
163   if (fPrimaries) {
164     fPrimaries->Delete() ; 
165     delete fPrimaries ; 
166   }
167
168   TFolder * emcalF = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject("EMCAL")) ;
169   TCollection * folderslist = emcalF->GetListOfFolders() ; 
170   TIter next(folderslist) ; 
171   TFolder * folder = 0 ; 
172
173   while ( (folder = static_cast<TFolder*>(next())) ) 
174     emcalF->Remove(folder) ; 
175
176   if (fFile) { 
177     fFile->Close() ;  
178     delete fFile ; 
179     fFile = 0 ;
180   }
181
182   fgObjGetter = 0 ; 
183 }
184
185 //____________________________________________________________________________ 
186
187 void AliEMCALGetter::CloseFile()
188 {
189   delete gAlice ;  
190   gAlice = 0 ; 
191   delete fAlice ; 
192   fAlice = 0 ; 
193 }
194
195 //____________________________________________________________________________ 
196
197 const TFolder * AliEMCALGetter::Folder(const TString what) const {
198
199   // returns the EMCAL folder required by what
200   // what = hits, sdigits, digits
201
202   if ( what == "hits" ) 
203     return dynamic_cast<const TFolder *>(fHitsFolder->FindObject("EMCAL")) ; 
204   else if ( what == "sdigits" ) 
205     return  dynamic_cast<const TFolder *>(fSDigitsFolder->FindObject("EMCAL")) ; 
206   else if ( what == "digits" ) 
207     return  dynamic_cast<const TFolder *>(fDigitsFolder->FindObject("EMCAL")) ;
208   else {
209     Error("GetFolder","%s illegal option (hits, sdigits, digits) ", what.Data()) ; 
210     return 0 ; 
211   }
212 }
213
214 //____________________________________________________________________________ 
215
216 AliEMCALGetter * AliEMCALGetter::GetInstance()
217 {
218   // Returns the pointer of the unique instance already defined
219
220   if ( fgObjGetter ) {
221     return fgObjGetter ;
222   }
223   else {
224     return 0 ;
225   }
226 }
227
228 //____________________________________________________________________________ 
229
230 AliEMCALGetter * AliEMCALGetter::GetInstance(const char* headerFile,
231                                              const char* branchTitle,
232                                              const Bool_t toSplit)
233 {
234   // Creates and returns the pointer of the unique instance
235   // Must be called only when the environment has changed 
236
237   if(!fgObjGetter){
238     fgObjGetter = new AliEMCALGetter(headerFile,branchTitle,toSplit) ;
239     if(fgObjGetter->fFailed)
240       return 0;
241     else
242       return fgObjGetter ;
243   }
244
245   //First checks, if header file already opened
246
247   if(!fgObjGetter->fFile){
248      fgObjGetter = new AliEMCALGetter(headerFile,branchTitle,toSplit) ;
249     if(fgObjGetter->fFailed)
250       return 0;
251     else
252       return fgObjGetter ;
253   }
254
255   if(fgObjGetter->fHeaderFile.CompareTo(headerFile)==0){ //Opened the same header file   
256     if((fgObjGetter->fBranchTitle.CompareTo(branchTitle) == 0)&&   //Open the same branch title
257        (toSplit==fgObjGetter->fToSplit)){                          //Nothing should be cleaned
258     }
259     else{ //Clean all data and AliEMCAL...zers
260       if(fgObjGetter->fToSplit)
261         fgObjGetter->CloseSplitFiles() ;          
262       //fgObjGetter->CleanWhiteBoard() ;
263       fgObjGetter->fToSplit = toSplit ;
264       fgObjGetter->SetTitle(branchTitle) ;
265     }
266   }
267   else{  //Close already opened files, clean memory and open new header file
268     if(gAlice){ //should first delete gAlice, then close file
269       //Should be in dtor of EMCAL, but if one changes path ...
270       fgObjGetter->fModuleFolder->Remove(fgObjGetter->fModuleFolder->FindObject("EMCAL")) ; 
271       delete gAlice ;
272     }
273     if(fgObjGetter->fFile){
274       fgObjGetter->fFile->Close() ;
275       fgObjGetter->fFile=0;
276     }
277     if(fgObjGetter->fToSplit)
278       fgObjGetter->CloseSplitFiles() ;
279     fgObjGetter->CleanWhiteBoard() ;    
280     fgObjGetter = new AliEMCALGetter(headerFile,branchTitle,toSplit) ;
281   }
282
283   return fgObjGetter ; 
284
285 }
286
287 //____________________________________________________________________________ 
288
289 const Bool_t AliEMCALGetter::BranchExists(const TString recName) const
290 {
291   //Looks in the tree Tree"name" if branch with current name olready exists
292
293   TString filename("") ;
294   TString name, dataname, zername;
295   if(recName == "SDigits"){
296     filename=fSDigitsFileName ;
297     name = "TreeS0" ;
298     dataname = "EMCAL" ;
299     zername = "AliEMCALSDigitizer" ;
300   }
301   else if(recName == "Digits"){
302     filename=fDigitsFileName ;
303     name = "TreeD0" ;
304     dataname = "EMCAL" ;
305     zername = "AliEMCALDigitizer" ;
306   }
307   else if(recName =="RecPoints"){
308         filename=fRecPointsFileName ;
309         name = "TreeR0" ;
310         dataname = "EMCALEmcRP" ;
311         zername = "AliEMCALClusterizer" ;
312   }
313   else if(recName == "TrackSegments"){
314     filename=fTrackSegmentsFileName ;
315     name = "TreeR0" ;
316     dataname = "EMCALTS" ;
317     zername = "AliEMCALTrackSegmentMaker" ;
318   }      
319   else if(recName == "RecParticles"){
320     filename= fRecParticlesFileName ;
321     name = "TreeR0" ;
322     dataname = "EMCALRP" ;
323     zername = "AliEMCALPID" ;
324   }
325   else
326     return kFALSE ;
327
328   TFile * file ;
329   TTree * tree ;
330   if(fToSplit){
331     file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
332     if(!file)
333       file = TFile::Open(fSDigitsFileName.Data(),"update");
334   }
335   else
336     file = fFile ;
337
338   tree = (TTree *)file->Get(name.Data()) ;
339
340   if(!tree ) 
341     return kFALSE ;
342
343   TObjArray * lob = static_cast<TObjArray*>(tree->GetListOfBranches()) ;
344   TIter next(lob) ; 
345   TBranch * branch = 0 ;  
346   TString titleName(fBranchTitle);
347   titleName+=":";
348
349   while ((branch = (static_cast<TBranch*>(next())))) {
350     TString branchName(branch->GetName() ) ; 
351     TString branchTitle(branch->GetTitle() ) ;  
352     if ( branchName.BeginsWith(dataname) && branchTitle.BeginsWith(fBranchTitle) ){  
353       Warning("BranchExists", "branch %s with title %s already exits in %s", dataname.Data(), fBranchTitle.Data(), name.Data());
354       return kTRUE ;
355     }
356
357     if ( branchName.BeginsWith(zername) &&  branchTitle.BeginsWith(titleName) ){
358       Warning("BranchExists","Branch AliEMCAL... with title %s already exits in %s",branch->GetTitle(), name.Data());     
359       return kTRUE ; 
360     }
361   }
362
363     //We can't delete three if gAlice points to it... To be redisigned somehow???!!!
364
365   if(!fToSplit){
366     if(name.Contains("TreeS"))
367       if(tree!=gAlice->TreeS())
368         tree->Delete();
369     if(name.Contains("TreeD"))
370       if(tree!=gAlice->TreeD())
371         tree->Delete();
372     if(name.Contains("TreeR"))
373       if(tree!=gAlice->TreeR())
374         tree->Delete();    
375   }
376
377   return kFALSE ;
378 }
379
380 //____________________________________________________________________________ 
381
382 void AliEMCALGetter::ListBranches(Int_t event) const  
383 {
384   TBranch * branch = 0 ; 
385   if (gAlice->GetEvent(event) == -1)
386     return ; 
387
388   TTree * t =  gAlice->TreeH() ; 
389
390   if(t){
391     Info("ListBranches"," -> ****** Hits    : "); 
392     TObjArray * lob = t->GetListOfBranches() ;
393     TIter next(lob) ; 
394
395     while ( (branch = static_cast<TBranch*>(next())) )
396       Info("ListBranches","         %s", branch->GetName());
397
398   } else 
399     Warning("ListBranches"," -> TreeH not found for event %d",event);  
400
401   t = gAlice->TreeS() ;
402
403   if(t){
404     Info("ListBranches"," -> ****** SDigits : "); 
405     TObjArray * lob = t->GetListOfBranches() ;
406     TIter next(lob) ; 
407
408     while ( (branch = static_cast<TBranch*>(next())) )
409       Info("ListBranches","             %s %s",branch->GetName(),branch->GetTitle()); 
410   } else 
411     Warning("ListBranches"," -> TreeS not found for event %d",event);  
412
413   t = gAlice->TreeD() ;
414
415   if(t){
416     Info("ListBranches"," -> ****** Digits  : "); 
417     TObjArray * lob = t->GetListOfBranches() ;
418     TIter next(lob) ; 
419
420     while ( (branch = static_cast<TBranch*>(next())) )
421       Info("             %s %s", branch->GetName(), branch->GetTitle()); 
422   } else 
423     Warning("ListBranches"," -> TreeD not found for event %d", event);  
424
425   t = gAlice->TreeR() ;
426
427   if(t){
428     Info("ListBranches"," -> ****** Recon   : "); 
429     TObjArray * lob = t->GetListOfBranches() ;
430     TIter next(lob) ; 
431     while ( (branch = static_cast<TBranch*>(next())) )
432       Info("             %s %s", branch->GetName(), branch->GetTitle()); 
433   } else 
434     Warning("ListBranches"," -> TreeR not found for event %d",event);  
435 }
436
437 //____________________________________________________________________________ 
438
439 void AliEMCALGetter::NewBranch(TString name, Int_t event)  
440 {
441   fBranchTitle = fSDigitsTitle = fDigitsTitle = fRecPointsTitle = fTrackSegmentsTitle = fRecParticlesTitle =  name ; 
442   Event(event) ; 
443 }
444
445 //____________________________________________________________________________ 
446
447 Bool_t AliEMCALGetter::NewFile(TString name)  
448 {
449   fHeaderFile = name ; 
450   fFile->Close() ; 
451   fFailed = kFALSE; 
452
453   fFile = static_cast<TFile*>(gROOT->GetFile(fHeaderFile.Data() ) ) ;
454
455   if(!fFile) {    //if file was not opened yet, read gAlice
456     fFile = TFile::Open(fHeaderFile.Data(),"update") ;
457     if (!fFile->IsOpen()) {
458       Error("NewFile", " -> Cannot open %s", fHeaderFile.Data()); 
459       fFailed = kTRUE ;
460       return fFailed ;  
461     }
462     gAlice = static_cast<AliRun *>(fFile->Get("gAlice")) ;
463   } 
464
465   if (!gAlice) {
466     Error("NewFile"," -> Cannot find gAlice in %s", fHeaderFile.Data());
467     fFailed = kTRUE ;
468     return fFailed ; 
469   }
470   return fFailed ; 
471 }
472
473 //____________________________________________________________________________ 
474
475 const AliEMCAL * AliEMCALGetter::EMCAL() 
476 {
477   // returns the EMCAL object 
478
479   AliEMCAL * emcal = dynamic_cast<AliEMCAL*>(fModuleFolder->FindObject("EMCAL")) ;  
480
481   if (!emcal) 
482     if (fDebug)
483       Warning("EMCAL"," -> EMCAL module not found in Folders" );
484   return emcal ; 
485 }  
486
487 //____________________________________________________________________________ 
488
489 AliEMCALGeometry * AliEMCALGetter::EMCALGeometry() 
490 {
491   AliEMCALGeometry * rv = 0 ; 
492   if (EMCAL() )
493     rv =  EMCAL()->GetGeometry() ;
494   return rv ; 
495
496
497 //____________________________________________________________________________ 
498
499 const Bool_t AliEMCALGetter::PostPrimaries(void) const 
500 {  
501   //------- Primaries ----------------------
502   // the hierarchy is //Folders/RunMC/Event/Data/Primaries
503
504   TFolder * primariesFolder = dynamic_cast<TFolder*>(fPrimariesFolder->FindObject("Primaries")) ; 
505   if ( !primariesFolder ) {
506     if (fDebug) {
507       Warning("PostPrimaries", "-> Folder //%s/Primaries/ not found!", fPrimariesFolder->GetName());
508       Info("PostPrimaries", "-> Adding Folder //%s/Primaries/",fPrimariesFolder->GetName());
509     }
510     primariesFolder = fPrimariesFolder->AddFolder("Primaries", "Primaries particles from TreeK") ; 
511   }    
512
513   TClonesArray *primaries=  new TClonesArray("TParticle",1000) ;
514   primaries->SetName("Primaries") ;
515   primariesFolder->Add(primaries) ; 
516
517   return kTRUE;
518
519
520 //____________________________________________________________________________ 
521
522 TObject** AliEMCALGetter::PrimariesRef(void) const 
523 {  
524   //------- Primaries ----------------------
525   // the hierarchy is //Folders/RunMC/Event/Data/Primaries
526
527   if ( !fPrimariesFolder ) {
528     Fatal("PrimariesRef", "-> Folder //%s not found!",fPrimariesFolder);
529   }    
530
531   TFolder * primariesFolder = dynamic_cast<TFolder *>(fPrimariesFolder->FindObject("Primaries")) ;
532
533   if ( !primariesFolder ) {
534     Fatal("PrimariesRef", "-> Folder //%s/Primaries/ not found!",fPrimariesFolder);  
535   }
536
537   TObject * p = primariesFolder->FindObject("Primaries") ;
538
539   if(!p) {
540     Fatal("PrimariesRef", "-> %s/Primaries not found !",primariesFolder->GetName()); 
541   }
542
543   return primariesFolder->GetListOfFolders()->GetObjectRef(p) ;
544 }
545
546 //____________________________________________________________________________ 
547
548 const Bool_t AliEMCALGetter::PostHits(void) const 
549 {  
550   //------- Hits ----------------------
551   // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/Hits
552
553   TFolder * emcalFolder = dynamic_cast<TFolder*>(fHitsFolder->FindObject("EMCAL")) ; 
554
555   if ( !emcalFolder ) {
556     if (fDebug) {
557       Warning("PostHits", "-> Folder //%s/EMCAL/ not found!", fHitsFolder);
558       Info("PostHits", "-> Adding Folder //%s/EMCAL/",fHitsFolder);
559     }
560     emcalFolder = fHitsFolder->AddFolder("EMCAL", "Hits from EMCAL") ; 
561   }    
562
563   TClonesArray *hits=  new TClonesArray("AliEMCALHit",1000) ;
564   hits->SetName("Hits") ;
565   emcalFolder->Add(hits) ; 
566
567   return kTRUE;
568
569
570 //____________________________________________________________________________ 
571
572 TObject ** AliEMCALGetter::HitsRef(void) const 
573 {  
574   //------- Hits ----------------------
575   // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/Hits
576
577   if ( !fHitsFolder ) {
578     Error("HitsRef", "-> Folder //%s not found!",fHitsFolder);
579     return 0;
580   }    
581
582   TFolder * emcalFolder = dynamic_cast<TFolder *>(fHitsFolder->FindObject("EMCAL")) ;
583   if ( !emcalFolder ) {
584     Error("HitsRef", "-> Folder //%s/EMCAL/ not found!",fHitsFolder);
585     return 0;
586   }
587
588   TObject * h = emcalFolder->FindObject("Hits") ;
589
590   if(!h) {
591     Error("HitsRef", "-> %s/Hits not found !",emcalFolder->GetName());
592     return 0 ;
593   }
594   else
595     return emcalFolder->GetListOfFolders()->GetObjectRef(h) ;
596 }
597
598 //____________________________________________________________________________ 
599
600 const Bool_t AliEMCALGetter::PostSDigits(const char * name, const char * headerFile) const 
601 {  
602   //---------- SDigits -------------------------
603   // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/SDigits/headerFile/sdigitsname
604   // because you can have sdigits from several hit files for mixing
605
606   TFolder * emcalFolder = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
607
608   if ( !emcalFolder ) {
609     if (fDebug) {
610       Warning("PostSDigits", "-> Folder //%s/EMCAL/ not found!", fSDigitsFolder);
611       Info("PostSDigits", "-> Adding Folder //%s/EMCAL/",fHitsFolder);
612     }
613     emcalFolder = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ; 
614   }    
615
616   TString subdir(headerFile) ;
617   subdir.ReplaceAll("/", "_") ; 
618   TFolder * emcalSubFolder = dynamic_cast<TFolder*>(emcalFolder->FindObject(subdir)) ; 
619   if ( !emcalSubFolder ) 
620     emcalSubFolder = emcalFolder->AddFolder(subdir, ""); 
621
622   TObject * sd  = emcalSubFolder->FindObject(name); 
623
624   if ( !sd ) {
625     TClonesArray * sdigits = new TClonesArray("AliEMCALDigit",1) ;
626     sdigits->SetName(name) ;
627     emcalSubFolder->Add(sdigits) ;
628   }
629
630   return kTRUE;
631
632
633 //____________________________________________________________________________ 
634
635 TObject ** AliEMCALGetter::SDigitsRef(const char * name, const char * file) const 
636 {  
637   //------- SDigits ----------------------
638   // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/SDigits/filename/SDigits
639
640   if ( !fSDigitsFolder ) {
641     Fatal("SDigitsRef", "-> Folder //%s not found!", fSDigitsFolder);
642   }    
643
644   TFolder * emcalFolder = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject("EMCAL")) ;
645
646   if ( !emcalFolder ) {
647     Fatal("SDigitsRef", "-> Folder //%s/EMCAL/ not found!", fSDigitsFolder);
648   }
649
650   TFolder * emcalSubFolder = 0 ;
651
652   if(file)
653     emcalSubFolder = dynamic_cast<TFolder *>(emcalFolder->FindObject(file)) ;
654   else
655     emcalSubFolder = dynamic_cast<TFolder *>(emcalFolder->FindObject(fHeaderFile)) ;
656
657   if(!emcalSubFolder) {
658     Fatal("SDigitsRef", "-> Folder //Folders/RunMC/Event/Data/EMCAL/%s not found!", file);
659   }
660
661   TObject * dis = emcalSubFolder->FindObject(name) ;
662
663   if(!dis) {
664     Fatal("SDigitsRef", "-> object %s not found!", name);
665   }
666
667   return emcalSubFolder->GetListOfFolders()->GetObjectRef(dis) ;
668 }
669
670 //____________________________________________________________________________ 
671
672 const Bool_t AliEMCALGetter::PostSDigitizer(AliEMCALSDigitizer * sdigitizer) const 
673 {  
674   //---------- SDigitizer -------------------------
675   // the hierarchy is //Folders/Tasks/SDigitizer/EMCAL/sdigitsname
676
677   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ; 
678
679   if ( !sd ) {
680     Error("PostSDigitizer", "-> Task //%s/SDigitizer not found!",fTasksFolder);
681     return kFALSE ;
682   }        
683
684   TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ; 
685
686   if ( !emcal )  {
687     if (fDebug) {
688       Warning("PostSDigitizer", "->//%s/SDigitizer/EMCAL/ not found!",fTasksFolder);
689       Info("PostSDigitizer", "-> Adding //%s/SDigitizer/EMCAL/", fTasksFolder);
690     }
691     emcal = new TTask("EMCAL", "") ; 
692     sd->Add(emcal) ; 
693   } 
694
695   AliEMCALSDigitizer * emcalsd  = dynamic_cast<AliEMCALSDigitizer *>(emcal->GetListOfTasks()->FindObject( sdigitizer->GetName() )); 
696
697   if (emcalsd) { 
698     if (fDebug)
699       Info("PostSDigitizer", "-> Task %s already exists",sdigitizer->GetName());
700     emcal->GetListOfTasks()->Remove(emcalsd) ;
701   }
702
703   emcal->Add(sdigitizer) ;      
704
705   return kTRUE; 
706 }
707
708 //____________________________________________________________________________ 
709
710 TObject ** AliEMCALGetter::SDigitizerRef(const char * name) const 
711 {  
712   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ; 
713
714   if ( !sd ) {
715     Fatal("SDigitizerRef", "-> Task //%s/SDigitizer not found!", fTasksFolder);
716   }        
717
718   TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ; 
719
720   if ( !emcal )  {
721     Fatal("SDigitizerRef", "->  //%s/SDigitizer/EMCAL not found!", fTasksFolder);
722   }        
723
724   TTask * task = dynamic_cast<TTask*>(emcal->GetListOfTasks()->FindObject(name)) ; 
725
726   return emcal->GetListOfTasks()->GetObjectRef(task) ;
727 }
728
729 //____________________________________________________________________________ 
730
731 const Bool_t AliEMCALGetter::PostSDigitizer(const char * name, const char * file) const 
732 {  
733   //---------- SDigitizer -------------------------
734   // the hierarchy is //Folders/Tasks/SDigitizer/EMCAL/sdigitsname
735
736   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ; 
737
738   if ( !sd ) {
739     Error("PostSDigitizer", "-> Task //%s/SDigitizer not found!", fTasksFolder);
740     return kFALSE ;
741   }        
742
743   TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ; 
744
745   if ( !emcal )  {
746     if (fDebug) {
747       Warning("PostSDigitizer", "->  //%s/SDigitizer/EMCAL/ not found!", fTasksFolder);
748
749       Info("PostSDigitizer", "-> Adding  //%s/SDigitizer/EMCAL", fTasksFolder);
750
751     }
752     emcal = new TTask("EMCAL", "") ; 
753     sd->Add(emcal) ; 
754   } 
755
756   TString sdname(name) ;
757   sdname.Append(":") ;
758   sdname.Append(file);
759   sdname.ReplaceAll("/","_") ; 
760   AliEMCALSDigitizer * emcalsd  = dynamic_cast<AliEMCALSDigitizer *>(emcal->GetListOfTasks()->FindObject( sdname )); 
761
762   if (!emcalsd) {
763     emcalsd = new AliEMCALSDigitizer() ;  
764
765     //Note, we can not call constructor with parameters: it will call Getter and screw up everething
766
767     emcalsd->SetName(sdname) ;
768     emcalsd->SetTitle(file) ;
769     emcal->Add(emcalsd) ;       
770   }
771
772   return kTRUE; 
773 }
774
775 //____________________________________________________________________________ 
776
777 const Bool_t AliEMCALGetter::PostDigits(const char * name) const 
778 {  
779   //---------- Digits -------------------------
780   // the hierarchy is //Folders/Run/Event/Data/EMCAL/SDigits/name
781
782   TFolder * emcalFolder  = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ;
783
784   if ( !emcalFolder ) {
785     if (fDebug) {
786       Warning("PostDigits", "-> Folder //%s/EMCAL/ not found!", fDigitsFolder);
787       Info("PostDigits", "-> Adding Folder //%s/EMCAL/", fDigitsFolder);
788     }
789     emcalFolder = fDigitsFolder->AddFolder("EMCAL", "Digits from EMCAL") ;  
790   }    
791
792   TObject*  dig = emcalFolder->FindObject( name ) ;
793
794   if ( !dig ) {
795     TClonesArray * digits = new TClonesArray("AliEMCALDigit",1000) ;
796     digits->SetName(name) ;
797     emcalFolder->Add(digits) ;  
798   }
799
800   return kTRUE; 
801 }
802
803 //____________________________________________________________________________ 
804
805 TObject ** AliEMCALGetter::DigitsRef(const char * name) const 
806
807   //------- Digits ----------------------
808   // the hierarchy is //Folders/Run/Event/Data/EMCAL/Digits/name
809
810   if ( !fDigitsFolder ) {
811     Fatal("DigitsRef", "-> Folder //%s not found!", fDigitsFolder);
812   }    
813
814   TFolder * emcalFolder  = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ; 
815
816   if ( !emcalFolder ) {
817     Fatal("DigitsRef", "-> Folder //%s/EMCAL/ not found!", fDigitsFolder);
818   }    
819
820   TObject * d = emcalFolder->FindObject(name) ;
821
822   if(!d) {
823     Fatal("DigitsRef", "-> object %s not found!", name);
824   }   
825
826   return emcalFolder->GetListOfFolders()->GetObjectRef(d) ;
827 }
828
829 //____________________________________________________________________________ 
830
831 const Bool_t AliEMCALGetter::PostDigitizer(AliEMCALDigitizer * digitizer) const
832 {  
833   //---------- Digitizer -------------------------
834
835   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ; 
836
837   if ( !sd ) {
838     Error("PostDigitizer", "-> Task //%s/Digitizer not found!", fTasksFolder);
839     return kFALSE ;
840   }        
841
842   TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ; 
843
844   if ( !emcal )  {
845     if (fDebug) {
846       Warning("PostDigitizer", "->  //%s/Digitizer/EMCAL not found!", fTasksFolder);
847       Info("PostDigitizer", "-> Adding //%s/Digitizer/EMCAL", fTasksFolder);
848     }
849     emcal = new TTask("EMCAL", "") ; 
850     sd->Add(emcal) ; 
851   } 
852
853     AliEMCALDigitizer * emcald = dynamic_cast<AliEMCALDigitizer*>(emcal->GetListOfTasks()->FindObject(digitizer->GetName())) ; 
854
855     if (emcald) { 
856       emcald->Delete() ;
857       emcal->GetListOfTasks()->Remove(emcald) ;
858     }
859
860     emcal->Add(digitizer) ; 
861
862     return kTRUE; 
863 }  
864
865 //____________________________________________________________________________ 
866
867 const Bool_t AliEMCALGetter::PostDigitizer(const char * name) const 
868 {  
869   //---------- Digitizer -------------------------
870   // the hierarchy is //Folders/Tasks/SDigitizer/EMCAL/sdigitsname
871
872   TTask * d  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ; 
873
874   if ( !d ) {
875
876     Error("PostDigitizer", "-> Task //%s/Digitizer not found!", fTasksFolder);
877     return kFALSE ;
878   }        
879
880   TTask * emcal = dynamic_cast<TTask*>(d->GetListOfTasks()->FindObject("EMCAL")) ; 
881
882   if ( !emcal )  {
883     if (fDebug) {
884       Warning("PostDigitizer", "-> //%s/Digitizer/EMCAL not found!", fTasksFolder);
885
886       Info("PostDigitizer", "-> Adding //%s/Digitizer/EMCAL", fTasksFolder);
887     }
888     emcal = new TTask("EMCAL", "") ; 
889     d->Add(emcal) ; 
890
891
892   AliEMCALDigitizer * emcald = dynamic_cast<AliEMCALDigitizer*>(emcal->GetListOfTasks()->FindObject(name)) ; 
893
894   if (!emcald) { 
895     emcald = new AliEMCALDigitizer() ;
896     emcald->SetName(fDigitsTitle) ;
897     emcald->SetTitle(fHeaderFile) ;
898     emcal->Add(emcald) ;
899   }
900
901   return kTRUE;  
902 }
903
904 //____________________________________________________________________________ 
905
906 TObject ** AliEMCALGetter::DigitizerRef(const char * name) const 
907 {  
908
909   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ; 
910
911   if ( !sd ) {
912     Fatal("DigitizerRef", "-> Task //%s/Digitizer not found!", fTasksFolder->GetName());
913   }        
914
915   TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ; 
916
917   if ( !emcal )  {
918     Fatal("DigitizerRef", "->  //%s/Digitizer/EMCAL", fTasksFolder->GetName());
919   }        
920
921   TTask * task = dynamic_cast<TTask*>(emcal->GetListOfTasks()->FindObject(name)) ; 
922
923   return emcal->GetListOfTasks()->GetObjectRef(task) ;
924 }
925
926 //____________________________________________________________________________ 
927
928 const Bool_t AliEMCALGetter::PostRecPoints(const char * name) const 
929
930   // -------------- RecPoints -------------------------------------------
931   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/TowerRecPoints/name
932   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/PreShowerRecPoints/name
933
934   TFolder * emcalFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL")) ; 
935
936   if ( !emcalFolder ) {
937     if (fDebug) {
938       Warning("PostRecPoints", "-> Folder //%s/EMCAL/ not found!", fRecoFolder);
939       Info("PostRecPoints", "-> Adding Folder //%s/EMCAL/", fRecoFolder);
940     }
941     emcalFolder = fRecoFolder->AddFolder("EMCAL", "Reconstructed data from EMCAL") ;  
942   }    
943
944   // Pre Shower RecPoints 
945
946   TFolder * emcalRPoPREFolder  = dynamic_cast<TFolder*>(emcalFolder->FindObject("PRERecPoints")) ;
947
948   if ( !emcalRPoPREFolder ) {
949     if (fDebug) {
950       Warning("PostRecPoints", "-> Folder //%s/EMCAL/PRERecPoints/ not found!", fRecoFolder);
951       Info("PostRecPoints", "-> Adding Folder //%s/EMCAL/PRERecPoints/", fRecoFolder);
952     }
953     emcalRPoPREFolder = emcalFolder->AddFolder("PRERecPoints", "PRE RecPoints from EMCAL") ;  
954   }    
955
956   TObject * rpPRE =  emcalRPoPREFolder->FindObject( name ) ;
957
958   if ( !rpPRE )   {
959     TObjArray * aPRErp = new TObjArray(100) ;
960     aPRErp->SetName(name) ;
961     emcalRPoPREFolder->Add(aPRErp) ;  
962   }
963
964  // EC RecPoints 
965
966   TFolder * emcalRPoECFolder  = dynamic_cast<TFolder*>(emcalFolder->FindObject("ECRecPoints")) ;
967
968   if ( !emcalRPoECFolder ) {
969     if (fDebug) {
970
971       Warning("PostRecPoints", "-> Folder //%s/EMCAL/ECRecPoints/ not found!", fRecoFolder);
972       Info("PostRecPoints", "-> Adding Folder //%s/EMCAL/ECRecPoints not found!", fRecoFolder);
973     }
974     emcalRPoECFolder = emcalFolder->AddFolder("ECRecPoints", "EC RecPoints from EMCAL") ;  
975   }    
976
977   TObject * rpEC = emcalFolder->FindObject( name ) ;
978
979   if ( !rpEC )   {
980     TObjArray * aECrp = new TObjArray(100) ;
981     aECrp->SetName(name) ;
982     emcalRPoECFolder->Add(aECrp) ;  
983   }
984
985  // HC RecPoints 
986
987   TFolder * emcalRPoHCFolder  = dynamic_cast<TFolder*>(emcalFolder->FindObject("HCRecPoints")) ;
988
989   if ( !emcalRPoHCFolder ) {
990     if (fDebug) {
991
992       Warning("PostRecPoints", "-> Folder //%s/EMCAL/HCRecPoints/ not found!", fRecoFolder);
993       Info("PostRecPoints", "-> Adding Folder //%s/EMCAL/HCRecPoints not found!", fRecoFolder);
994     }
995     emcalRPoHCFolder = emcalFolder->AddFolder("HCRecPoints", "HC RecPoints from EMCAL") ;  
996   }    
997
998   TObject * rpHC = emcalFolder->FindObject( name ) ;
999
1000   if ( !rpHC )   {
1001     TObjArray * aHCrp = new TObjArray(100) ;
1002     aHCrp->SetName(name) ;
1003     emcalRPoHCFolder->Add(aHCrp) ;  
1004   }
1005
1006   return kTRUE; 
1007 }
1008
1009 //____________________________________________________________________________ 
1010
1011 TObject ** AliEMCALGetter::ECRecPointsRef(const char * name) const 
1012
1013   // -------------- RecPoints -------------------------------------------
1014   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/ECRecPoints/name
1015
1016   if ( !fRecoFolder ) {
1017     Fatal("ECRecPointsRef", "-> Folder //%s not found!", fRecoFolder);
1018   }    
1019
1020   TFolder * towerFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/ECRecPoints")) ; 
1021
1022   if ( !towerFolder ) {
1023     Fatal("ECRecPointsRef", "-> Folder //%s/EMCAL/ECRecPoints/ not found!", fRecoFolder);
1024   }    
1025
1026   TObject * trp = towerFolder->FindObject(name ) ;
1027
1028   if ( !trp )   {
1029     Fatal("ECRecPointsRef", "-> Object %s not found!", name);
1030   }
1031
1032   return towerFolder->GetListOfFolders()->GetObjectRef(trp) ;
1033
1034
1035 //____________________________________________________________________________ 
1036
1037 TObject ** AliEMCALGetter::HCRecPointsRef(const char * name) const 
1038
1039   // -------------- RecPoints -------------------------------------------
1040   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/HCRecPoints/name
1041
1042   if ( !fRecoFolder ) {
1043     Fatal("HCRecPointsRef", "-> Folder //%s not found!", fRecoFolder);
1044   }    
1045
1046   TFolder * towerFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/HCRecPoints")) ; 
1047
1048   if ( !towerFolder ) {
1049     Fatal("HCRecPointsRef", "-> Folder //%s/EMCAL/HCRecPoints/ not found!", fRecoFolder);
1050   }    
1051
1052   TObject * trp = towerFolder->FindObject(name ) ;
1053
1054   if ( !trp )   {
1055     Fatal("HCRecPointsRef", "-> Object %s not found!", name);
1056   }
1057
1058   return towerFolder->GetListOfFolders()->GetObjectRef(trp) ;
1059
1060
1061 //____________________________________________________________________________ 
1062
1063 TObject ** AliEMCALGetter::PRERecPointsRef(const char * name) const 
1064
1065   // -------------- RecPoints -------------------------------------------
1066   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/PRERecPoints/name
1067
1068   if ( !fRecoFolder ) {
1069     Fatal("PRERecPointsRef", "-> Folder //%s not found!", fRecoFolder);
1070   }    
1071
1072   TFolder * folderPRE  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/PRERecPoints")) ; 
1073
1074   if ( !folderPRE ) {
1075     Fatal("PRERecPointsRef", "-> Folder //%s/EMCAL/PRERecPoints/", fRecoFolder);
1076   }    
1077
1078
1079
1080   TObject * prp = folderPRE->FindObject(name ) ;
1081
1082   if ( !prp )   {
1083     Fatal("PRERecPointsRef", "-> Object %s not found!", name);
1084   }
1085
1086   return folderPRE->GetListOfFolders()->GetObjectRef(prp) ;
1087
1088
1089 //____________________________________________________________________________ 
1090
1091 const Bool_t AliEMCALGetter::PostClusterizer(AliEMCALClusterizer * clu) const 
1092
1093   // ------------------ AliEMCALClusterizer ------------------------
1094   // the hierarchy is //Folders/Tasks/Reconstructioner/EMCAL/sdigitsname
1095
1096   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
1097
1098   if ( !tasks ) {
1099     Error("PostClusterizer", "-> Task //%s/Reconstructioner not found!", fTasksFolder);
1100     return kFALSE ;
1101   }        
1102
1103   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
1104
1105   if ( !emcal )  {
1106     if (fDebug) {
1107       Warning("PostClusterizer", "-> //%s/ReconstructionerEMCAL not found!", fTasksFolder);
1108       Info("PostClusterizer", "-> Adding //%s/Reconstructioner/EMCAL", fTasksFolder);
1109     }
1110     emcal = new TTask("EMCAL", "") ; 
1111     tasks->Add(emcal) ; 
1112   } 
1113
1114   AliEMCALClusterizerv1 * emcalcl = dynamic_cast<AliEMCALClusterizerv1*>(emcal->GetListOfTasks()->FindObject(clu->GetName())) ; 
1115
1116   if (emcalcl) { 
1117     if (fDebug)
1118       Info("PostClusterizer", "-> Task %s already exists", clu->GetName());
1119     emcalcl->Delete() ; 
1120     emcal->GetListOfTasks()->Remove(emcalcl) ;
1121   }
1122   emcal->Add(clu) ;      
1123
1124   return kTRUE; 
1125
1126
1127 //____________________________________________________________________________ 
1128
1129 TObject ** AliEMCALGetter::ClusterizerRef(const char * name) const 
1130
1131   // ------------------ AliEMCALClusterizer ------------------------
1132
1133   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
1134
1135   if ( !tasks ) {
1136     Fatal("ClusterizerRef", "-> Task //%s/Reconstructioner not found!", fTasksFolder->GetName());
1137   }        
1138
1139   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
1140
1141   if ( !emcal )  {
1142     Fatal("ClusterizerRef", "-> //%s/Reconstructioner/EMCAL", fTasksFolder->GetName());
1143   }   
1144
1145   TList * l = emcal->GetListOfTasks() ; 
1146   TIter it(l) ;
1147   TTask * task ;
1148   TTask * clu = 0 ;
1149   TString cluname(name) ;
1150   cluname+=":clu-" ;
1151
1152   while((task = static_cast<TTask *>(it.Next()) )){
1153     TString taskname(task->GetName()) ;
1154     if(taskname.BeginsWith(cluname)){
1155       clu = task ;
1156       break ;
1157     }
1158   }
1159
1160   if(!clu) {
1161     Fatal("ClusterizerRef", "-> task %s not found!", task->GetName());
1162   }
1163
1164   return l->GetObjectRef(clu) ;
1165 }
1166
1167 //____________________________________________________________________________ 
1168
1169 const Bool_t AliEMCALGetter::PostClusterizer(const char * name) const 
1170
1171   // ------------------ AliEMCALClusterizer ------------------------
1172   // the hierarchy is //Folders/Tasks/Reconstructioner/EMCAL/sdigitsname
1173   
1174
1175   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
1176
1177   if ( !tasks ) {
1178     Error("PostClusterizer", "-> Task //%s/Reconstructioner not found!", fTasksFolder->GetName());
1179     return kFALSE ;
1180   }        
1181
1182   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
1183
1184   if ( !emcal )  {
1185     if (fDebug) {
1186       Warning("PostClusterizer", "-> //%s/Reconstructioner/EMCAL not found!", fTasksFolder);
1187       Info("PostClusterizer", "-> Adding //%s/Reconstructioner/EMCAL", fTasksFolder);
1188     }
1189     emcal = new TTask("EMCAL", "") ; 
1190     tasks->Add(emcal) ; 
1191   } 
1192
1193   TList * l = emcal->GetListOfTasks() ;   
1194   TIter it(l) ;
1195   TString clun(name) ;
1196   clun+=":clu" ; 
1197   TTask * task ;
1198
1199   while((task = static_cast<TTask *>(it.Next()) )){
1200     TString taskname(task->GetName()) ;
1201
1202     if(taskname.BeginsWith(clun))
1203       return kTRUE ;
1204   }
1205
1206   AliEMCALClusterizerv1 * emcalcl = new AliEMCALClusterizerv1() ;
1207
1208   clun+="-v1" ; 
1209   emcalcl->SetName(clun) ;
1210   emcalcl->SetTitle(fHeaderFile) ; 
1211   emcal->Add(emcalcl) ;
1212
1213   return kTRUE; 
1214 }
1215
1216 //____________________________________________________________________________ 
1217 const Bool_t AliEMCALGetter::PostTrackSegments(const char * name) const 
1218 { // ---------------TrackSegments -----------------------------------
1219   
1220   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/TrackSegments/name
1221
1222   TFolder * emcalFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL")) ; 
1223   
1224   if ( !emcalFolder ) {
1225     if (fDebug) {
1226       Warning("PostTrackSegments", "-> Folder //%s/EMCAL/ not found", fRecoFolder->GetName()) ;
1227       Info("PostTrackSegments", "-> Adding Folder //%s/EMCAL", fRecoFolder->GetName()) ;
1228     }
1229     emcalFolder = fRecoFolder->AddFolder("EMCAL", "Reconstructed data from EMCAL") ;  
1230   }    
1231
1232   TFolder * emcalTSFolder  = dynamic_cast<TFolder*>(emcalFolder->FindObject("TrackSegments")) ;
1233   if ( !emcalTSFolder ) {
1234     if (fDebug) {
1235       Warning("PostTrackSegments", "-> Folder //%s/EMCAL/TrackSegments/ not found!", fRecoFolder->GetName() ) ; 
1236       Info("PostTrackSegments", "-> Adding Folder //%s/EMCAL/TrackSegments/", fRecoFolder->GetName()) ; 
1237     }
1238     emcalTSFolder = emcalFolder->AddFolder("TrackSegments", "TrackSegments from EMCAL") ;  
1239   }    
1240   
1241   TObject * tss =  emcalTSFolder->FindObject( name ) ;
1242   if (!tss) {
1243     TClonesArray * ts = new TClonesArray("AliEMCALTrackSegment",100) ;
1244     ts->SetName(name) ;
1245     emcalTSFolder->Add(ts) ;  
1246   }
1247   return kTRUE; 
1248
1249
1250 //____________________________________________________________________________ 
1251 TObject** AliEMCALGetter::TrackSegmentsRef(const char * name) const 
1252 { // ---------------TrackSegments -----------------------------------
1253   
1254   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/TrackSegments/name
1255
1256  if ( !fRecoFolder ) {
1257     Fatal("TrackSegmentsRef", "Folder //%s not found !", fRecoFolder->GetName() ) ;
1258   }    
1259
1260   TFolder * emcalFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/TrackSegments")) ; 
1261   if ( !emcalFolder ) {
1262     Fatal("TrackSegmentsRef", "Folder //%s/EMCAL/TrackSegments/ not found !", fRecoFolder->GetName() ) ;
1263   }    
1264   
1265   TObject * tss =  emcalFolder->FindObject(name) ;
1266   if (!tss) {
1267     Fatal("TrackSegmentsRef", "object %s not found !", name) ;  
1268   }
1269   return emcalFolder->GetListOfFolders()->GetObjectRef(tss) ;
1270
1271
1272 //____________________________________________________________________________ 
1273 const Bool_t AliEMCALGetter::PostTrackSegmentMaker(AliEMCALTrackSegmentMaker * tsmaker) const 
1274 { //------------Track Segment Maker ------------------------------
1275   
1276   // the hierarchy is //Folders/Tasks/Reconstructioner/EMCAL/sdigitsname
1277
1278   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
1279
1280   if ( !tasks ) {
1281     Error("PostTrackSegmentMaker", "Task //%s/Reconstructioner not found !", fTasksFolder) ;
1282     return kFALSE ;
1283   }        
1284         
1285   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
1286   if ( !emcal )  {
1287     if (fDebug) {
1288       Warning("PostTrackSegmentMaker", "//%s/Reconstructioner/EMCAL not found!", fTasksFolder) ; 
1289       Info("PostTrackSegmentMaker", "Adding //%s/Reconstructioner/EMCAL", fTasksFolder) ;
1290     }
1291     emcal = new TTask("EMCAL", "") ; 
1292     tasks->Add(emcal) ; 
1293   } 
1294
1295   AliEMCALTrackSegmentMaker * emcalts = 
1296     dynamic_cast<AliEMCALTrackSegmentMaker*>(emcal->GetListOfTasks()->FindObject(tsmaker->GetName())) ; 
1297   if (emcalts) { 
1298     emcalts->Delete() ;
1299     emcal->GetListOfTasks()->Remove(emcalts) ;
1300   }
1301   emcal->Add(tsmaker) ;      
1302   return kTRUE; 
1303   
1304
1305 //____________________________________________________________________________ 
1306 const Bool_t AliEMCALGetter::PostTrackSegmentMaker(const char * name) const 
1307 { //------------Track Segment Maker ------------------------------
1308   
1309   // the hierarchy is //Folders/Tasks/Reconstructioner/EMCAL/sdigitsname
1310   
1311   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
1312   
1313   if ( !tasks ) {
1314     Error("PostTrackSegmentMaker", "Task //%s/Reconstructioner not found !", fTasksFolder->GetName() ) ;
1315     return kFALSE ;
1316   }        
1317   
1318   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
1319   if ( !emcal )  {
1320     if (fDebug) {
1321       Warning("PostTrackSegmentMaker", "//%s/Reconstructioner/EMCAL not found!", fTasksFolder->GetName() ) ; 
1322       Info("PostTrackSegmentMaker", "Adding //%s/Reconstructioner/EMCAL", fTasksFolder->GetName()) ;
1323     }
1324     emcal = new TTask("EMCAL", "") ; 
1325     tasks->Add(emcal) ; 
1326   } 
1327
1328   TList * l = emcal->GetListOfTasks() ;   
1329   TIter it(l) ;
1330   TString tsn(name);
1331   tsn+=":tsm" ; 
1332   TTask * task ;
1333   while((task = static_cast<TTask *>(it.Next()) )){
1334     TString taskname(task->GetName()) ;
1335     if(taskname.BeginsWith(tsn))
1336       return kTRUE ;
1337   }
1338   
1339   AliEMCALTrackSegmentMakerv1 * emcalts = new AliEMCALTrackSegmentMakerv1() ;
1340   tsn+="-v1" ;
1341   emcalts->SetName(tsn) ;
1342   emcalts->SetTitle(fHeaderFile) ;
1343   emcal->Add(emcalts) ;      
1344   return kTRUE; 
1345   
1346
1347
1348 //____________________________________________________________________________ 
1349 TObject** AliEMCALGetter::TSMakerRef(const char * name) const 
1350 { //------------Track Segment Maker ------------------------------
1351   
1352   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
1353
1354   if ( !tasks ) {
1355     Fatal("TSMakerRef", "Task //%s/Reconstructioner not found !", fTasksFolder->GetName() ) ;
1356   }        
1357         
1358   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
1359   if ( !emcal )  {
1360     Fatal("TSMakerRef", "//%s/Reconstructioner/EMCAL not found !", fTasksFolder->GetName() ) ; 
1361   }   
1362
1363   TList * l = emcal->GetListOfTasks() ; 
1364   TIter it(l) ;
1365   TTask * task ;
1366   TTask * tsm = 0 ;
1367   TString tsmname(name) ;
1368   tsmname+=":tsm" ;
1369   while((task = static_cast<TTask *>(it.Next()) )){
1370     TString taskname(task->GetName()) ;
1371     if(taskname.BeginsWith(tsmname)){
1372       tsm = task ;
1373       break ;
1374     }
1375   }
1376   
1377   if(!tsm) {
1378    Fatal("TSMakerRef", "Task //%s/Reconstructioner/EMCAL/TrackSegmentMarker/%s not found !", fTasksFolder->GetName(),  name) ;
1379   }
1380  
1381   return l->GetObjectRef(tsm) ;
1382
1383
1384
1385 //____________________________________________________________________________ 
1386 const Bool_t AliEMCALGetter::PostRecParticles(const char * name) const 
1387 {  // -------------------- RecParticles ------------------------
1388   
1389   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/RecParticles/name
1390
1391   TFolder * emcalFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL")) ; 
1392   
1393   if ( !emcalFolder ) {
1394     if (fDebug) {
1395       Warning("PostRecParticles", "-> Folder //%s/EMCAL/ not found!", fRecoFolder->GetName()) ;
1396       Info("PostRecParticles", "-> Adding Folder //%s/EMCAL/", fRecoFolder->GetName()) ;
1397     }
1398     emcalFolder = fRecoFolder->AddFolder("EMCAL", "Reconstructed data from EMCAL") ;  
1399   }    
1400
1401  TFolder * emcalRPaFolder  = dynamic_cast<TFolder*>(emcalFolder->FindObject("RecParticles")) ;
1402   if ( !emcalRPaFolder ) {
1403     if (fDebug) {
1404       Warning("PostRecParticles", "-> Folder //%s/EMCAL/RecParticles/ not found!", fRecoFolder->GetName()) ;
1405       Info("PostRecParticles", "-> Adding Folder //%s/EMCAL/RecParticles/", fRecoFolder->GetName()) ;
1406     }
1407     emcalRPaFolder = emcalFolder->AddFolder("RecParticles", "RecParticles from EMCAL") ;  
1408   } 
1409
1410   TObject * rps = emcalRPaFolder->FindObject( name )  ;
1411   if ( !rps ) {
1412     TClonesArray * rp = new TClonesArray("AliEMCALRecParticle",100) ;
1413     rp->SetName(name) ;    
1414     emcalRPaFolder->Add(rp) ;  
1415   }
1416   return kTRUE; 
1417
1418
1419 //____________________________________________________________________________ 
1420 TObject** AliEMCALGetter::RecParticlesRef(const char * name) const 
1421 { // ---------------RecParticles -----------------------------------
1422   
1423   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/TrackSegments/name
1424
1425  if ( !fRecoFolder ) {
1426     Fatal("RecParticlesRef", "Folder//%s not found !", fRecoFolder->GetName() ) ; 
1427   }    
1428
1429   TFolder * emcalFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/RecParticles")) ; 
1430   if ( !emcalFolder ) {
1431     Fatal("RecParticlesRef", "Folder //%s/EMCAL/RecParticles/ not found !", fRecoFolder->GetName() ) ;
1432   }    
1433
1434   TObject * tss =  emcalFolder->FindObject(name  ) ;
1435   if (!tss) {
1436     Fatal("RecParticlesRef", "object %s not found !", name) ; 
1437   }
1438   return emcalFolder->GetListOfFolders()->GetObjectRef(tss) ;
1439 }
1440
1441 //____________________________________________________________________________ 
1442 const Bool_t AliEMCALGetter::PostPID(AliEMCALPID * pid) const 
1443 {      // ------------AliEMCAL PID -----------------------------
1444
1445   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
1446
1447   if ( !tasks ) {
1448     Error("PostPID", "Task //%s/Reconstructioner not found !", fTasksFolder) ;
1449     return kFALSE ;
1450   }        
1451   
1452   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
1453   if ( !emcal )  {
1454     if (fDebug) {
1455       Warning("PostPID", "//%s/Reconstructioner/EMCAL not found!", fTasksFolder) ; 
1456       Info("PostPID", "Adding //%s/Reconstructioner/EMCAL", fTasksFolder) ;
1457     }
1458     emcal = new TTask("EMCAL", "") ; 
1459     tasks->Add(emcal) ; 
1460   } 
1461
1462   AliEMCALPID * emcalpid = dynamic_cast<AliEMCALPID*>(emcal->GetListOfTasks()->FindObject(pid->GetName())) ; 
1463   if (emcalpid) { 
1464     if (fDebug)
1465       Info("PostPID", "-> Task %s qlready exists", pid->GetName()) ; 
1466     emcal->GetListOfTasks()->Remove(emcalpid) ;
1467   }
1468   
1469   emcal->Add(pid) ;      
1470   return kTRUE; 
1471
1472
1473 //____________________________________________________________________________ 
1474 const Bool_t AliEMCALGetter::PostPID(const char * name) const 
1475 {     
1476   // the hierarchy is //Folders/Tasks/Reconstructioner/EMCAL/sdigitsname
1477   
1478   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
1479
1480   if ( !tasks ) {
1481     Error("PostPID", "Task //%s/Reconstructioner not found !", fTasksFolder->GetName() ) ;
1482     return kFALSE ;
1483   }        
1484   
1485   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
1486   if ( !emcal )  {
1487     if (fDebug) {
1488       Warning("PostPID", "//%s/Reconstructioner/EMCAL not found!", fTasksFolder->GetName()) ; 
1489       Info("PostPID", "Adding //%s/Reconstructioner/EMCAL", fTasksFolder->GetName()) ;
1490     }
1491     emcal = new TTask("EMCAL", "") ; 
1492     tasks->Add(emcal) ; 
1493   } 
1494
1495   TList * l = emcal->GetListOfTasks() ;   
1496   TIter it(l) ;
1497   TString pidname(name) ;
1498   pidname+=":pid" ;
1499   TTask * task ;
1500   while((task = static_cast<TTask *>(it.Next()) )){
1501     TString taskname(task->GetName()) ;
1502     if(taskname.BeginsWith(pidname))
1503       return kTRUE ;
1504   }
1505  
1506   AliEMCALPIDv1 * emcalpid = new AliEMCALPIDv1() ;
1507   pidname+="-v1" ;
1508   emcalpid->SetName(pidname) ; 
1509   emcalpid->SetTitle(fHeaderFile) ;
1510   emcal->Add(emcalpid) ;      
1511   
1512   return kTRUE; 
1513
1514
1515 //____________________________________________________________________________ 
1516 TObject** AliEMCALGetter::PIDRef(const char * name) const 
1517 { //------------PID ------------------------------
1518
1519   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
1520
1521   if ( !tasks ) {
1522     Fatal("PIDRef", "Task //%s/Reconstructioner not found !", fTasksFolder->GetName() ) ;
1523   }        
1524         
1525   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
1526   if ( !emcal )  {
1527     Fatal("PIDRef", "//%s/Reconstructioner/EMCAL not found !", fTasksFolder->GetName() ) ; 
1528   }   
1529   
1530   TList * l = emcal->GetListOfTasks() ; 
1531   TIter it(l) ;
1532   TTask * task ;
1533   TTask * pid = 0 ;
1534   TString pidname(name) ;
1535   pidname+=":pid" ;
1536   while((task = static_cast<TTask *>(it.Next()) )){
1537     TString taskname(task->GetName()) ;
1538     if(taskname.BeginsWith(pidname)){
1539       pid = task ;
1540       break ;
1541     }
1542   }
1543   
1544   if(!pid) {
1545     Fatal("PIDRef", "Task //%s/Reconstructioner/EMCAL/PID/%s not found !", fTasksFolder->GetName(), name) ;
1546   }
1547   
1548     return l->GetObjectRef(pid) ;
1549
1550
1551 //____________________________________________________________________________ 
1552 TTree * AliEMCALGetter::TreeK(TString filename)  
1553 {
1554   // returns TreeK from file filename
1555   // usefull in case of split file
1556
1557   if ( filename.IsNull() ) 
1558     filename = fHeaderFile ; 
1559
1560   TFile * file = 0 ; 
1561
1562   file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
1563
1564   if (!file || !file->IsOpen())  // file not yet open 
1565     file = TFile::Open(filename.Data(), "read") ; 
1566   
1567   if(filename != fHeaderFile ){
1568     fAlice = dynamic_cast<AliRun *>(file->Get("gAlice")) ;
1569   }
1570
1571   TString treeName("TreeK") ; 
1572   treeName += EventNumber()  ; 
1573   TTree * tree = static_cast<TTree *>(file->Get(treeName.Data())) ;
1574
1575   if (!tree && fDebug)  
1576     Warning("TreeK", "-> %s not found in %s", treeName.Data(),filename.Data());
1577
1578   return tree ;                       
1579 }
1580
1581 //____________________________________________________________________________ 
1582
1583 TTree * AliEMCALGetter::TreeH(TString filename)  
1584 {
1585   // returns TreeH from file filename
1586   // usefull in case of split file
1587
1588   if ( filename.IsNull() ) 
1589     filename = fHeaderFile ; 
1590
1591   TFile * file = 0 ; 
1592   file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
1593
1594   if (!file) { // file not open yet
1595     file = TFile::Open(filename.Data(), "read") ; 
1596   }
1597
1598   TString treeName("TreeH") ; 
1599   treeName += EventNumber()  ; 
1600   TTree * tree = static_cast<TTree *>(file->Get(treeName.Data())) ;
1601
1602   if (!tree && fDebug)  
1603     Warning("TreeH", "-> %s not found in %s", treeName.Data(), filename.Data());
1604   return tree ;                       
1605 }
1606
1607 //____________________________________________________________________________ 
1608
1609 TTree * AliEMCALGetter::TreeS(TString filename)  
1610 {
1611   // returns TreeS from file filename
1612   // usefull in case of split file
1613
1614   if ( filename.IsNull() ) 
1615     filename = fHeaderFile ; 
1616
1617   TFile * file = 0 ; 
1618   file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
1619
1620   if (!file) { // file not open yet
1621     file = TFile::Open(filename.Data(), "read") ; 
1622   }
1623
1624   TString treeName("TreeS") ; 
1625   treeName += EventNumber()  ; 
1626   TTree * tree = static_cast<TTree *>(file->Get(treeName.Data())) ;
1627
1628   if (!tree && fDebug)  
1629     Warning("TreeS", "-> %s not found in %s", treeName.Data(), filename.Data());
1630   return tree ;                       
1631 }
1632
1633 //____________________________________________________________________________ 
1634
1635 TTree * AliEMCALGetter::TreeD(TString filename)  
1636 {
1637   // returns TreeD from file filename
1638   // usefull in case of split file
1639
1640   if ( filename.IsNull() ) 
1641     filename = fHeaderFile ; 
1642
1643   TFile * file = 0 ; 
1644   file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
1645
1646   if (!file) { // file not open yet
1647     file = TFile::Open(filename.Data(), "read") ; 
1648   }
1649
1650   TString treeName("TreeD") ; 
1651   treeName += EventNumber()  ; 
1652   TTree * tree = static_cast<TTree *>(file->Get(treeName.Data())) ;
1653
1654   if (!tree && fDebug)  
1655     Warning("TreeD", "-> %s not found in %s", treeName.Data(), filename.Data());
1656   return tree ;                       
1657 }
1658
1659 //____________________________________________________________________________ 
1660
1661 const TParticle * AliEMCALGetter::Primary(Int_t index) const
1662 {
1663   // Return primary particle numbered by <index>
1664
1665   if(index < 0) 
1666     return 0 ;
1667
1668   TParticle *  p = 0 ;
1669     if (fAlice) 
1670       p = fAlice->Particle(index) ; 
1671     else
1672       p = gAlice->Particle(index) ; 
1673  
1674   return p ; 
1675 }
1676
1677 //____________________________________________________________________________ 
1678
1679 const TParticle * AliEMCALGetter::Secondary(TParticle* p, Int_t index) const
1680 {
1681   // Return first (index=1) or second (index=2) secondary particle of primary particle p 
1682
1683   if(index <= 0) 
1684     return 0 ;
1685   if(index > 2)
1686     return 0 ;
1687
1688   if(p) {
1689     Int_t daughterIndex = p->GetDaughter(index-1) ; 
1690     return  gAlice->Particle(daughterIndex) ; 
1691   }
1692   else
1693     return 0 ;
1694 }
1695
1696 //____________________________________________________________________________ 
1697
1698 Int_t AliEMCALGetter::ReadTreeD(const Int_t event)
1699 {
1700   // Read the digit tree gAlice->TreeD()  
1701
1702   TTree * treeD ;
1703   if(fToSplit){
1704     TFile * file = static_cast<TFile*>(gROOT->GetFile(fDigitsFileName)); 
1705     if(!file) 
1706       file = TFile::Open(fDigitsFileName) ;      
1707
1708     // Get Digits Tree header from file
1709
1710     TString treeName("TreeD") ;
1711     treeName += event ; 
1712     treeD = dynamic_cast<TTree*>(file->Get(treeName.Data()));
1713
1714     if(!treeD){ // TreeD not found in header file
1715       if (fDebug)
1716         Warning("ReadTreeD", "-> Cannot find TreeD in %s", fDigitsFileName.Data());
1717       return 1;
1718     }
1719   }
1720   else
1721     treeD = gAlice->TreeD() ;
1722
1723   TObjArray * lob = static_cast<TObjArray*>(treeD->GetListOfBranches()) ;
1724   TIter next(lob) ; 
1725   TBranch * branch = 0 ; 
1726   TBranch * digitsbranch = 0 ; 
1727   TBranch * digitizerbranch = 0 ; 
1728
1729   Bool_t emcalfound = kFALSE, digitizerfound = kFALSE ; 
1730
1731   while ( (branch = static_cast<TBranch*>(next())) && (!emcalfound || !digitizerfound) ) {
1732     if ( (strcmp(branch->GetName(), "EMCAL")==0) && (strcmp(branch->GetTitle(), fDigitsTitle)==0) ) {
1733       digitsbranch = branch ; 
1734       emcalfound = kTRUE ;
1735     }
1736     else if ( (strcmp(branch->GetName(), "AliEMCALDigitizer")==0) && (strcmp(branch->GetTitle(), fDigitsTitle)==0) ) {
1737       digitizerbranch = branch ; 
1738       digitizerfound = kTRUE ; 
1739     }
1740   }
1741
1742   if ( !emcalfound || !digitizerfound ) {
1743     if (fDebug)
1744       Warning("ReadTreeD", "-> Cannot find Digits and/or Digitizer with name %s", fDigitsTitle.Data());
1745     return 2; 
1746   }   
1747
1748   //read digits
1749
1750   if(!Digits(fDigitsTitle) ) 
1751     PostDigits(fDigitsTitle);
1752   digitsbranch->SetAddress(DigitsRef(fDigitsTitle)) ;
1753   digitsbranch->GetEntry(0) ;
1754
1755   // read  the Digitizer
1756
1757   RemoveTask("D", fDigitsTitle) ; // I do not understand why I need that 
1758   if(!Digitizer(fDigitsTitle))
1759     PostDigitizer(fDigitsTitle) ;
1760   digitizerbranch->SetAddress(DigitizerRef(fDigitsTitle)) ;
1761   digitizerbranch->GetEntry(0) ;
1762
1763   lob->Delete();
1764
1765   if(gAlice->TreeD()!=treeD)
1766     treeD->Delete();
1767
1768   return 0 ; 
1769 }
1770
1771 //____________________________________________________________________________ 
1772
1773 Int_t AliEMCALGetter::ReadTreeH()
1774 {
1775   // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
1776
1777   TTree * treeH = gAlice->TreeH() ;
1778
1779   if(!treeH) {// TreeH not found in header file
1780     if (fDebug) 
1781       Warning("ReadTreeH", "-> Cannot find TreeH in %s", fHeaderFile.Data());
1782
1783     TString searchFileName("EMCAL.HITS") ; 
1784     if((strcmp(fBranchTitle.Data(),"Default")!=0)&&(strcmp(fBranchTitle.Data(),"")!=0)){
1785       searchFileName+="." ;
1786       searchFileName += fBranchTitle ;
1787     }
1788
1789     searchFileName+=".root" ;
1790
1791     if ( (treeH = TreeH(searchFileName)) ) { //found TreeH in the file which contains the hits
1792       if (fDebug) 
1793         Info("ReadTreeH", "-> TreeH found in %s", searchFileName.Data());
1794     } else {
1795       Error("ReadTreeH", "-> TreeH not found "); 
1796       return 1;
1797     }  
1798   }
1799
1800   TBranch * hitsbranch = static_cast<TBranch*>(gAlice->TreeH()->GetBranch("EMCAL")) ;
1801
1802   if ( !hitsbranch ) {
1803     if (fDebug)
1804       Warning("ReadTreeH", "-> Cannot find branch EMCAL"); 
1805     return 2;
1806   }
1807
1808   if(!Hits())
1809     PostHits() ;
1810
1811   if (hitsbranch->GetEntries() > 1 ) {
1812     (dynamic_cast<TClonesArray*> (*HitsRef()))->Clear() ;
1813     TClonesArray * tempo =  new TClonesArray("AliEMCALHit",1000) ;
1814     TClonesArray * hits = dynamic_cast<TClonesArray*>(*HitsRef()) ; 
1815     hitsbranch->SetAddress(&tempo) ;
1816
1817     Int_t index = 0 ; 
1818     Int_t i = 0 ;
1819
1820     for (i = 0 ; i < hitsbranch->GetEntries() ; i++) {
1821       hitsbranch->GetEntry(i) ;
1822       Int_t j = 0 ; 
1823       for ( j = 0 ; j < tempo->GetEntries() ; j++) { 
1824         const AliEMCALHit * hit = static_cast<const AliEMCALHit *>(tempo->At(j)) ; 
1825         new((*hits)[index]) AliEMCALHit( *hit ) ;
1826         index++ ; 
1827       }
1828     }
1829     delete tempo ; 
1830   }
1831   else {
1832     (dynamic_cast<TClonesArray*> (*HitsRef()))->Clear() ;
1833     hitsbranch->SetAddress(HitsRef()) ;
1834     hitsbranch->GetEntry(0) ;
1835   }
1836   return 0 ; 
1837 }
1838
1839 //____________________________________________________________________________ 
1840
1841 void AliEMCALGetter::Track(const Int_t itrack)
1842 {
1843   // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
1844   if(gAlice->TreeH()== 0){
1845     Error("ReadTreeH", "-> Cannot read TreeH ");
1846     return ;
1847   }
1848
1849   TBranch * hitsbranch = dynamic_cast<TBranch*>(gAlice->TreeH()->GetListOfBranches()->FindObject("EMCAL")) ;
1850
1851   if ( !hitsbranch ) {
1852     if (fDebug)
1853       Warning("ReadTreeH", "-> Cannot find branch EMCAL"); 
1854     return ;
1855   }  
1856
1857   if(!Hits())
1858     PostHits() ;
1859
1860   (dynamic_cast<TClonesArray*> (*HitsRef()))->Clear() ;
1861   hitsbranch->SetAddress(HitsRef()) ;
1862   hitsbranch->GetEntry(itrack) ;
1863 }
1864
1865 //____________________________________________________________________________ 
1866
1867 void AliEMCALGetter::ReadTreeQA()
1868 {
1869   if (fDebug)
1870     Warning("ReadTreeQA", "-> %s not implemented", ClassName());
1871 }
1872
1873   
1874
1875 //____________________________________________________________________________ 
1876
1877 Int_t AliEMCALGetter::ReadTreeR(const Int_t event)
1878
1879 {
1880   // Read the reconstrunction tree gAlice->TreeR()
1881   // A particularity has been introduced here :
1882   //  if gime->Event(ievent,"R") is called branches with the current title are read, the current title
1883   //   being for example give in AliEMCALPID(fileName, title)
1884   //  if gime(Event(ievent, "RA") is called the title of the branches is not checked anymore, "A" stands for any
1885   // This is a feature needed by PID to be able to reconstruct several times particles (each time a ther title is given)
1886   // from a given set of TrackSegments (with a given name)
1887   // This is why any is NOT used to read the branch of RecParticles
1888   // any migh have become obsolete : to be checked
1889   // See AliEMCALPIDv1    
1890
1891   //first - clean if necessary
1892   if(ECALRecPoints(fRecPointsTitle)){
1893     ECALRecPoints(fRecPointsTitle)->Delete() ;
1894     PRERecPoints(fRecPointsTitle)->Delete() ;
1895     HCALRecPoints(fRecPointsTitle)->Delete() ;
1896  }
1897   //clear TrackSegments
1898   if(TrackSegments(fTrackSegmentsTitle))
1899     TrackSegments(fTrackSegmentsTitle)->Clear() ;
1900         
1901   TTree * treeR ;
1902
1903   if(fToSplit){
1904     TFile * file = static_cast<TFile*>(gROOT->GetFile(fRecPointsFileName)); 
1905     if(!file) 
1906       file = TFile::Open(fRecPointsFileName) ;      
1907     // Get Digits Tree header from file
1908
1909     TString treeName("TreeR") ;
1910     treeName += event ; 
1911     treeR = dynamic_cast<TTree*>(file->Get(treeName.Data()));
1912
1913     if(!treeR){ // TreeR not found in header file
1914       if (fDebug)
1915         Warning("ReadTreeR", "-> Cannot find TreeR in %s", fRecPointsFileName.Data());
1916       return 1;
1917     }
1918   }
1919   else
1920     treeR = gAlice->TreeR() ;
1921
1922   // RecPoints 
1923
1924   TObjArray * lob = static_cast<TObjArray*>(treeR->GetListOfBranches()) ;
1925   TIter next(lob) ; 
1926   TBranch * branch = 0 ; 
1927   TBranch * branchPRE = 0 ; 
1928   TBranch * branchEC  = 0 ; 
1929   TBranch * branchHC  = 0 ; 
1930   TBranch * clusterizerbranch = 0 ; 
1931
1932   Bool_t emcalPRERPfound = kFALSE, emcalECRPfound = kFALSE, emcalHCRPfound = kFALSE, clusterizerfound = kFALSE ; 
1933
1934   while ( (branch = static_cast<TBranch*>(next())) && (!emcalPRERPfound || !emcalECRPfound || !emcalHCRPfound || !clusterizerfound) ) {
1935     if(strcmp(branch->GetTitle(), fRecPointsTitle)==0 ) {
1936       if ( strcmp(branch->GetName(), "EMCALPRERP")==0) {
1937         branchPRE = branch ; 
1938         emcalPRERPfound = kTRUE ;
1939       }
1940       else if ( strcmp(branch->GetName(), "EMCALECRP")==0) {
1941         branchEC = branch ; 
1942         emcalECRPfound = kTRUE ;
1943       }
1944       else if ( strcmp(branch->GetName(), "EMCALHCRP")==0) {
1945         branchHC = branch ; 
1946         emcalHCRPfound = kTRUE ;
1947       }
1948        else if(strcmp(branch->GetName(), "AliEMCALClusterizer")==0){
1949         clusterizerbranch = branch ; 
1950         clusterizerfound = kTRUE ; 
1951       }
1952     }
1953   }
1954
1955   if ( !emcalPRERPfound || !emcalECRPfound || !emcalHCRPfound || !clusterizerfound) {
1956     if (fDebug)
1957       Warning("ReadTreeR", "-> Cannot find RecPoints and/or Clusterizer with name %s", fRecPointsTitle.Data());
1958   } 
1959   else { 
1960     if(!ECALRecPoints(fRecPointsTitle) ) 
1961       PostRecPoints(fRecPointsTitle) ;
1962     branchEC->SetAddress(ECRecPointsRef(fRecPointsTitle)) ;
1963     branchEC->GetEntry(0) ;
1964
1965     branchPRE->SetAddress(PRERecPointsRef(fRecPointsTitle)) ; 
1966     branchPRE->GetEntry(0) ;  
1967
1968     branchHC->SetAddress(HCRecPointsRef(fRecPointsTitle)) ; 
1969     branchHC->GetEntry(0) ;  
1970
1971     if(!Clusterizer(fRecPointsTitle) )
1972       PostClusterizer(fRecPointsTitle) ;
1973
1974     clusterizerbranch->SetAddress(ClusterizerRef(fRecPointsTitle)) ;
1975     clusterizerbranch->GetEntry(0) ;
1976   }
1977
1978   //------------------- TrackSegments ---------------------
1979   next.Reset() ; 
1980   TBranch * tsbranch = 0 ; 
1981   TBranch * tsmakerbranch = 0 ; 
1982   Bool_t emcaltsfound = kFALSE, tsmakerfound = kFALSE ; 
1983   while ( (branch = static_cast<TBranch*>(next())) && (!emcaltsfound || !tsmakerfound) ) {
1984     if(strcmp(branch->GetTitle(), fTrackSegmentsTitle)==0 )  {
1985       if ( strcmp(branch->GetName(), "EMCALTS")==0){
1986         tsbranch = branch ; 
1987         emcaltsfound = kTRUE ;
1988       }
1989       else if(strcmp(branch->GetName(), "AliEMCALTrackSegmentMaker")==0) {
1990         tsmakerbranch = branch ; 
1991         tsmakerfound  = kTRUE ; 
1992       }
1993     }
1994   }
1995
1996   if ( !emcaltsfound || !tsmakerfound ) {
1997     if (fDebug)
1998       Warning("ReadTreeR", "-> Cannot find TrackSegments and/or TrackSegmentMaker with name %s", fTrackSegmentsTitle.Data() ) ;
1999   } else { 
2000     // Read and Post the TrackSegments
2001     if(!TrackSegments(fTrackSegmentsTitle))
2002       PostTrackSegments(fTrackSegmentsTitle) ;
2003     tsbranch->SetAddress(TrackSegmentsRef(fTrackSegmentsTitle)) ;
2004     tsbranch->GetEntry(0) ;
2005
2006     // Read and Post the TrackSegment Maker
2007     if(!TrackSegmentMaker(fTrackSegmentsTitle))
2008       PostTrackSegmentMaker(fTrackSegmentsTitle) ;
2009     tsmakerbranch->SetAddress(TSMakerRef(fTrackSegmentsTitle)) ;
2010     tsmakerbranch->GetEntry(0) ;
2011  }
2012  //------------ RecParticles ----------------------------
2013   next.Reset() ; 
2014   TBranch * rpabranch = 0 ; 
2015   TBranch * pidbranch = 0 ; 
2016   Bool_t emcalrpafound = kFALSE, pidfound = kFALSE ; 
2017   
2018   while ( (branch = static_cast<TBranch*>(next())) && (!emcalrpafound || !pidfound) ) 
2019     if(strcmp(branch->GetTitle(), fRecParticlesTitle)==0) {   
2020       if ( strcmp(branch->GetName(), "EMCALRP")==0) {   
2021         rpabranch = branch ; 
2022         emcalrpafound = kTRUE ;
2023       }
2024       else if (strcmp(branch->GetName(), "AliEMCALPID")==0) {
2025         pidbranch = branch ; 
2026         pidfound  = kTRUE ; 
2027       }
2028     }
2029   
2030   if ( !emcalrpafound || !pidfound ) {
2031     if (fDebug)
2032       Warning("ReadTreeR", "-> Cannot find RecParticles and/or PID with name %s", fRecParticlesTitle.Data() ) ; 
2033   } else { 
2034     // Read and Post the RecParticles
2035     if(!RecParticles(fRecParticlesTitle)) 
2036       PostRecParticles(fRecParticlesTitle) ;
2037     rpabranch->SetAddress(RecParticlesRef(fRecParticlesTitle)) ;
2038     rpabranch->GetEntry(0) ;
2039     // Read and Post the PID
2040     if(!PID(fRecParticlesTitle))
2041       PostPID(fRecParticlesTitle) ;
2042     pidbranch->SetAddress(PIDRef(fRecParticlesTitle)) ;
2043     pidbranch->GetEntry(0) ;
2044   }
2045
2046   if(gAlice->TreeR()!=treeR)
2047     treeR->Delete();
2048   return 0 ; 
2049 }
2050
2051 //____________________________________________________________________________ 
2052
2053 Int_t AliEMCALGetter::ReadTreeS(const Int_t event)
2054 {
2055   // Reads the SDigits treeS from all files  
2056   // Files, which should be opened are listed in emcalF
2057   // So, first get list of files
2058
2059   TFolder * emcalF = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject("EMCAL")) ;
2060
2061   if (!emcalF) 
2062     emcalF = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ; 
2063
2064   TCollection * folderslist = emcalF->GetListOfFolders() ; 
2065
2066   // Now iterate over the list of files and read TreeS into Whiteboard
2067
2068   TIter next(folderslist) ; 
2069   TFolder * folder = 0 ; 
2070   TFile * file; 
2071   TTree * treeS = 0;
2072
2073   while ( (folder = static_cast<TFolder*>(next())) ) {
2074     TString fileName("") ;
2075     if(fToSplit)
2076       fileName = folder->GetTitle() ;
2077     else
2078       fileName = folder->GetName() ; 
2079
2080     fileName.ReplaceAll("_","/") ; 
2081     file = static_cast<TFile*>(gROOT->GetFile(fileName)); 
2082
2083     if(!file) 
2084       file = TFile::Open(fileName) ;      
2085
2086     // Get SDigits Tree header from file
2087
2088     TString treeName("TreeS") ;
2089     treeName += event ; 
2090     treeS = dynamic_cast<TTree*>(file->Get(treeName.Data()));
2091
2092     if(!treeS){ // TreeS not found in header file
2093       if (fDebug)
2094         Warning("ReadTreeS", "-> Cannot find TreeS in %s", fileName.Data());
2095       return 1;
2096     }
2097
2098     //set address of the SDigits and SDigitizer
2099
2100     TBranch   * sdigitsBranch    = 0;
2101     TBranch   * sdigitizerBranch = 0;
2102     TBranch   * branch           = 0 ;  
2103     TObjArray * lob = static_cast<TObjArray*>(treeS->GetListOfBranches()) ;
2104     TIter next(lob) ; 
2105
2106     Bool_t emcalfound = kFALSE, sdigitizerfound = kFALSE ; 
2107
2108     while ( (branch = static_cast<TBranch*>(next())) && (!emcalfound || !sdigitizerfound) ) {
2109       if ( (strcmp(branch->GetName(), "EMCAL")==0) && (strcmp(branch->GetTitle(), fSDigitsTitle)==0) ) {
2110         emcalfound = kTRUE ;
2111         sdigitsBranch = branch ; 
2112       }
2113       else if ( (strcmp(branch->GetName(), "AliEMCALSDigitizer")==0) && 
2114                 (strcmp(branch->GetTitle(), fSDigitsTitle)==0) ) {
2115         sdigitizerfound = kTRUE ; 
2116         sdigitizerBranch = branch ;
2117       }
2118     }
2119     if ( !emcalfound || !sdigitizerfound ) {
2120       if (fDebug)
2121         Warning("ReadSDigits", "-> Digits and/or Digitizer branch with name %s not found", GetName());
2122       return 2; 
2123     }   
2124
2125     if ( !folder->FindObject(fSDigitsTitle) )  
2126       PostSDigits(fSDigitsTitle,folder->GetName()) ;
2127
2128     ((TClonesArray*) (*SDigitsRef(fSDigitsTitle,folder->GetName())))->Clear() ;
2129
2130     sdigitsBranch->SetAddress(SDigitsRef(fSDigitsTitle,folder->GetName())) ;
2131     sdigitsBranch->GetEntry(0) ;
2132
2133     TString sdname(fSDigitsTitle) ;
2134     sdname+=":" ;
2135     sdname+=folder->GetName() ;
2136
2137     if(!SDigitizer(sdname) ) 
2138       PostSDigitizer(fSDigitsTitle,folder->GetName()) ;
2139
2140     sdigitizerBranch->SetAddress(SDigitizerRef(sdname)) ;
2141     sdigitizerBranch->GetEntry(0) ; 
2142
2143     if(gAlice->TreeS()!=treeS)
2144       treeS->Delete();
2145   }    
2146    return 0 ;  
2147 }
2148
2149 //____________________________________________________________________________ 
2150
2151 void AliEMCALGetter::ReadTreeS(TTree * treeS, Int_t input)
2152 {  
2153   // Read the summable digits fron treeS()  
2154
2155   TString filename("mergefile") ;
2156   filename+= input ;
2157
2158   TFolder * emcalFolder = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ; 
2159   if ( !emcalFolder ) { 
2160     emcalFolder = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ; 
2161   } 
2162
2163   TFolder * folder=(TFolder*)emcalFolder->FindObject(filename) ;
2164
2165   //set address of the SDigits and SDigitizer
2166
2167   TBranch   * sdigitsBranch    = 0;
2168   TBranch   * sdigitizerBranch = 0;
2169   TBranch   * branch           = 0 ;  
2170   TObjArray * lob = (TObjArray*)treeS->GetListOfBranches() ;
2171   TIter next(lob) ; 
2172
2173   Bool_t emcalfound = kFALSE, sdigitizerfound = kFALSE ; 
2174
2175   while ( (branch = (TBranch*)next()) && (!emcalfound || !sdigitizerfound) ) {
2176     if ( strcmp(branch->GetName(), "EMCAL")==0) {
2177       emcalfound = kTRUE ;
2178       sdigitsBranch = branch ; 
2179     }
2180     else if ( strcmp(branch->GetName(), "AliEMCALSDigitizer")==0) {
2181       sdigitizerfound = kTRUE ; 
2182       sdigitizerBranch = branch ;
2183     }
2184   }
2185
2186   if ( !emcalfound || !sdigitizerfound ) {
2187     if (fDebug)
2188       Warning("ReadTreeS", "-> Digits and/or Digitizer branch not found");
2189     return ; 
2190   }   
2191
2192   if (!folder || !(folder->FindObject(sdigitsBranch->GetTitle()) ) )
2193     PostSDigits(sdigitsBranch->GetTitle(),filename) ;
2194
2195   sdigitsBranch->SetAddress(SDigitsRef(sdigitsBranch->GetTitle(),filename)) ;
2196   sdigitsBranch->GetEntry(0) ;
2197
2198   TString sdname(sdigitsBranch->GetTitle()) ;
2199   sdname+=":" ;
2200   sdname+=filename ;
2201
2202   if(!SDigitizer(sdigitsBranch->GetTitle()) )
2203     PostSDigitizer(sdigitsBranch->GetTitle(),filename) ;
2204
2205   sdigitizerBranch->SetAddress(SDigitizerRef(sdname)) ;
2206   sdigitizerBranch->GetEntry(0) ;
2207
2208   if(gAlice->TreeS()!=treeS)
2209     treeS->Delete();
2210 }    
2211
2212 //____________________________________________________________________________ 
2213
2214 void AliEMCALGetter::ReadPrimaries()
2215 {
2216
2217   // Reads specific branches of primaries
2218
2219   TClonesArray * ar = 0  ; 
2220
2221   if(! (ar = Primaries()) ) { 
2222     PostPrimaries() ;
2223     ar = Primaries() ; 
2224   }
2225
2226   ar->Delete() ; 
2227
2228   if (TreeK(fHeaderFile)) { // treeK found in header file
2229     if (fDebug) 
2230       Info("ReadPrimaries", "-> TreeK found in %s", fHeaderFile.Data());
2231     fNPrimaries = gAlice->GetNtrack() ; 
2232     fAlice = 0 ; 
2233   } 
2234   else { // treeK not found in header file
2235     Error("ReadPrimaries", "-> TreeK not  found ");
2236     return ;
2237   }
2238
2239   Int_t index = 0 ; 
2240
2241   for (index = 0 ; index < fNPrimaries; index++) { 
2242     new ((*ar)[index]) TParticle(*(Primary(index)));
2243   }
2244 }
2245
2246 //____________________________________________________________________________ 
2247
2248 void AliEMCALGetter::Event(const Int_t event, const char* opt)
2249 {
2250   // Reads the content of all Tree's S, D and R
2251
2252   if (event >= gAlice->TreeE()->GetEntries() ) {
2253     Error("Event", "-> %d not found in TreeE!", event);
2254     return ; 
2255   }
2256
2257   Bool_t any = kFALSE ; 
2258
2259   if (strstr(opt,"A") ) // do not check the title of the branches
2260     any = kTRUE; 
2261
2262   gAlice->GetEvent(event) ; 
2263
2264   if( strstr(opt,"R") )
2265     ReadTreeR(event) ;
2266
2267   if( strstr(opt,"D") )
2268     ReadTreeD(event) ;
2269
2270   if(strstr(opt,"S") )
2271     ReadTreeS(event) ;
2272
2273   if(strstr(opt,"H") )
2274     ReadTreeH() ;
2275
2276   if( strstr(opt,"Q") )
2277     ReadTreeQA() ;
2278
2279   if( strstr(opt,"P") )
2280     ReadPrimaries() ;
2281 }
2282
2283 //____________________________________________________________________________ 
2284
2285 TObject * AliEMCALGetter::ReturnO(TString what, TString name, TString file) const 
2286 {
2287   // get the object named "what" from the folder
2288   // folders are named like //Folders
2289
2290   if ( file.IsNull() ) 
2291     file = fHeaderFile ; 
2292
2293   TFolder * folder = 0 ;
2294   TObject * emcalO  = 0 ; 
2295
2296   if ( what.CompareTo("Primaries") == 0 ) {
2297     folder = dynamic_cast<TFolder *>(fPrimariesFolder->FindObject("Primaries")) ; 
2298     if (folder) 
2299       emcalO  = dynamic_cast<TObject *>(folder->FindObject("Primaries")) ;  
2300     else 
2301       return 0 ; 
2302   }
2303   else if ( what.CompareTo("Hits") == 0 ) {
2304     folder = dynamic_cast<TFolder *>(fHitsFolder->FindObject("EMCAL")) ; 
2305     if (folder) 
2306       emcalO  = dynamic_cast<TObject *>(folder->FindObject("Hits")) ;  
2307   }
2308   else if ( what.CompareTo("SDigits") == 0 ) { 
2309     file.ReplaceAll("/","_") ; 
2310     TString path = "EMCAL/" + file  ; 
2311     folder = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject(path.Data())) ; 
2312     if (folder) { 
2313       if (name.IsNull())
2314         name = fSDigitsTitle ; 
2315       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
2316     }
2317   }
2318   else if ( what.CompareTo("Digits") == 0 ){
2319     folder = dynamic_cast<TFolder *>(fDigitsFolder->FindObject("EMCAL")) ; 
2320     if (folder) { 
2321       if (name.IsNull())
2322         name = fDigitsTitle ; 
2323       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
2324     } 
2325   }
2326   else if ( what.CompareTo("PRERecPoints") == 0 ) {
2327     folder = dynamic_cast<TFolder *>(fRecoFolder->FindObject("EMCAL/PRERecPoints")) ; 
2328     if (folder) { 
2329       if (name.IsNull())
2330         name = fRecPointsTitle ; 
2331       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
2332     }   
2333   }
2334   else if ( what.CompareTo("ECALRecPoints") == 0 ) {
2335     folder = dynamic_cast<TFolder *>(fRecoFolder->FindObject("EMCAL/ECRecPoints")) ; 
2336     if (folder) { 
2337       if (name.IsNull())
2338         name = fRecPointsTitle ; 
2339       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
2340     } 
2341   }
2342   else if ( what.CompareTo("HCALRecPoints") == 0 ) {
2343     folder = dynamic_cast<TFolder *>(fRecoFolder->FindObject("EMCAL/HCRecPoints")) ; 
2344     if (folder) { 
2345       if (name.IsNull())
2346         name = fRecPointsTitle ; 
2347       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
2348     } 
2349   }
2350   else if ( what.CompareTo("TrackSegments") == 0 ) {
2351     folder = dynamic_cast<TFolder *>(fRecoFolder->FindObject("EMCAL/TrackSegments")) ; 
2352     if (folder) { 
2353       if (name.IsNull())
2354         name = fTrackSegmentsTitle ; 
2355       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
2356     }   
2357   }
2358   else if ( what.CompareTo("RecParticles") == 0 ) {
2359     folder = dynamic_cast<TFolder *>(fRecoFolder->FindObject("EMCAL/RecParticles")) ; 
2360     if (folder) { 
2361       if (name.IsNull())
2362         name = fRecParticlesTitle ; 
2363       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ;
2364     }   
2365   }
2366  if (!emcalO) {
2367     if(fDebug)
2368       Warning("ReturnO", "-> Object %s  not found in %s", what.Data(), folder->GetName());
2369     return 0 ;
2370   }
2371
2372   return emcalO ;
2373 }
2374
2375 //____________________________________________________________________________ 
2376
2377 const TTask * AliEMCALGetter::ReturnT(TString what, TString name) const 
2378 {
2379   // get the TTask named "what" from the folder
2380   // folders are named like //Folders/Tasks/what/EMCAL/name
2381
2382   TString search(what) ; 
2383   if ( what.CompareTo("Clusterizer") == 0 ) 
2384     search = "Reconstructioner" ; 
2385   else if ( what.CompareTo("TrackSegmentMaker") == 0 ) 
2386     search = "Reconstructioner" ; 
2387   else if ( what.CompareTo("PID") == 0 ) 
2388     search = "Reconstructioner" ; 
2389   else if ( what.CompareTo("QATasks") == 0 ) 
2390     search = "QA" ; 
2391   
2392   TTask * tasks = dynamic_cast<TTask*>(fTasksFolder->FindObject(search)) ; 
2393
2394   if (!tasks) {
2395     Error("AliReturnT", "-> Task %s not found!", what.Data());
2396     return 0 ; 
2397   }
2398
2399   TTask * emcalT = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
2400
2401   if (!emcalT) { 
2402     Error("ReturnT", "-> Task %s/EMCAL not found!", what.Data());
2403     return 0 ; 
2404   }
2405
2406   TList * list = emcalT->GetListOfTasks() ; 
2407
2408   if (what.CompareTo("SDigitizer") == 0) {  
2409     if ( name.IsNull() )
2410       name =  fSDigitsTitle ; 
2411   }
2412   else  if (what.CompareTo("Digitizer") == 0){ 
2413     if ( name.IsNull() )
2414       name =  fDigitsTitle ;
2415   }
2416   else  if (what.CompareTo("Clusterizer") == 0){ 
2417     if ( name.IsNull() )
2418       name =  fRecPointsTitle ;
2419     name.Append(":clu") ;
2420   }
2421   else  if (what.CompareTo("TrackSegmentMaker") == 0){ 
2422     if ( name.IsNull() )
2423       name =  fTrackSegmentsTitle ;
2424     name.Append(":tsm") ;
2425   }
2426   else  if (what.CompareTo("PID") == 0){ 
2427     if ( name.IsNull() )
2428       name =  fRecParticlesTitle ;
2429     name.Append(":pid") ;
2430   }
2431   TIter it(list) ;
2432   TTask * task = 0 ; 
2433
2434   while((task = static_cast<TTask *>(it.Next()) )){
2435     TString taskname(task->GetName()) ;
2436     if(taskname.BeginsWith(name)){
2437       return task ;}
2438   }
2439   
2440   if(fDebug)
2441     Warning("ReturnT", "-> Task %s/%s not found!", search.Data(), name.Data());
2442   return 0 ;
2443 }
2444
2445 //____________________________________________________________________________ 
2446
2447 void AliEMCALGetter::RemoveTask(TString opt, TString name) const 
2448
2449 {
2450   // remove a task from the folder
2451   // path is fTasksFolder/SDigitizer/EMCAL/name
2452
2453   TTask * task  = 0 ; 
2454   TTask * emcal = 0 ; 
2455   TList * lofTasks = 0 ; 
2456
2457   if (opt == "S") { // SDigitizer
2458     task = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ;
2459     if (!task) 
2460       return ; 
2461   } 
2462   else if (opt == "D") { // Digitizer
2463     task = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ;
2464     if (!task) 
2465       return ; 
2466   }
2467   else if (opt == "C" || opt == "T" ) { // Clusterizer, TrackSegmentMaker
2468     task = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ;
2469     if (!task) 
2470       return ; 
2471   }
2472   else {
2473     Warning("RemoveTask", "-> Unknown option %s");
2474     return ; 
2475   }    
2476
2477   emcal =  dynamic_cast<TTask*>(task->GetListOfTasks()->FindObject("EMCAL")) ;
2478
2479   if (!emcal)
2480     return ; 
2481
2482   lofTasks = emcal->GetListOfTasks() ;
2483
2484   if (!lofTasks) 
2485     return ; 
2486
2487   TObject * obj = lofTasks->FindObject(name) ; 
2488   if (obj) 
2489
2490     lofTasks->Remove(obj) ;
2491 }
2492
2493 //____________________________________________________________________________ 
2494
2495 void AliEMCALGetter::RemoveObjects(TString opt, TString name) const 
2496 {
2497   // remove SDigits from the folder
2498   // path is fSDigitsFolder/fHeaderFileName/name
2499
2500   TFolder * emcal     = 0 ; 
2501   TFolder * emcalmain = 0 ; 
2502
2503   if (opt == "H") { // Hits
2504     emcal = dynamic_cast<TFolder*>(fHitsFolder->FindObject("EMCAL")) ;
2505     if (!emcal) 
2506       return ;
2507     name = "Hits" ; 
2508   }
2509   else if ( opt == "S") { // SDigits
2510     emcalmain = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
2511     if (!emcalmain) 
2512       return ;
2513     emcal = dynamic_cast<TFolder*>(emcalmain->FindObject(fHeaderFile)) ;
2514     if (!emcal) 
2515       return ;
2516   }
2517   else if (opt == "D") { // Digits
2518     emcal = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ;
2519     if (!emcal) 
2520       return ;
2521   }
2522   else if (opt == "RT") { // Tower RecPoints
2523     emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/TowerRecPoints")) ;
2524     if (!emcal) 
2525       return ;
2526   }
2527   else if (opt == "RP") { // Preshower RecPoints
2528     emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/PreShowerRecPoints")) ;
2529     if (!emcal) 
2530       return ;
2531   }
2532   else if (opt == "T") { // TrackSegments
2533     emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/TrackSegments")) ;
2534     if (!emcal) 
2535       return ;
2536   }
2537   else if (opt == "P") { // RecParticles
2538     emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/RecParticles")) ;
2539     if (!emcal) 
2540       return ;
2541   }
2542   else {
2543     Warning("RemoveObjects", "-> Unknown option %s", opt.Data());
2544     return ; 
2545   }
2546
2547   TObjArray * ar  = dynamic_cast<TObjArray*>(emcal->FindObject(name)) ; 
2548
2549   if (ar) { 
2550     emcal->Remove(ar) ;
2551     ar->Delete() ; 
2552     delete ar ; 
2553   }
2554
2555   if (opt == "S") 
2556     emcalmain->Remove(emcal) ; 
2557 }
2558
2559 //____________________________________________________________________________ 
2560
2561 void AliEMCALGetter::RemoveSDigits() const 
2562 {
2563   TFolder * emcal= dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
2564
2565   if (!emcal) 
2566     return ;
2567
2568   emcal->SetOwner() ; 
2569   emcal->Clear() ; 
2570 }
2571
2572 //____________________________________________________________________________ 
2573
2574 void AliEMCALGetter::CleanWhiteBoard(void){
2575
2576   TFolder * emcalmain = 0 ; 
2577   TFolder * emcal ;
2578   TObjArray * ar ;
2579   TList * lofTasks = 0 ; 
2580   TTask * task = 0 ; 
2581   TTask * emcalt = 0 ; 
2582
2583   // Hits  
2584
2585   emcal = dynamic_cast<TFolder*>(fHitsFolder->FindObject("EMCAL")) ;
2586
2587   if (emcal){  
2588     TObjArray * ar  = dynamic_cast<TObjArray*>(emcal->FindObject("Hits")) ; 
2589     if (ar) { 
2590       emcal->Remove(ar) ;
2591       ar->Delete() ; 
2592       delete ar ; 
2593     }
2594   }
2595
2596   // SDigits
2597
2598   emcalmain = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
2599
2600   if (emcalmain){ 
2601     emcal = dynamic_cast<TFolder*>(emcalmain->FindObject(fHeaderFile)) ;
2602     if (emcal) {
2603       ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fSDigitsTitle)) ; 
2604       if (ar) { 
2605         emcal->Remove(ar) ;
2606         ar->Delete() ; 
2607         delete ar ; 
2608       }
2609     }
2610     emcalmain->Remove(emcal) ; 
2611   }
2612
2613   // Digits
2614
2615   emcal = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ;
2616
2617   if (emcal){ 
2618     ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fDigitsTitle)) ; 
2619     if (ar) { 
2620       emcal->Remove(ar) ;
2621       ar->Delete() ; 
2622       delete ar ; 
2623     }
2624   }
2625
2626   // TowerRecPoints
2627
2628   emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/TowerRecPoints")) ;
2629
2630   if (emcal){ 
2631     ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fRecPointsTitle)) ; 
2632     if (ar) { 
2633       emcal->Remove(ar) ;
2634       ar->Delete() ; 
2635       delete ar ; 
2636     }
2637   }
2638
2639   // PreShowerRecPoints
2640
2641   emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/PreShowerRecPoints")) ;
2642
2643   if (emcal){ 
2644     ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fRecPointsTitle)) ; 
2645     if (ar) { 
2646       emcal->Remove(ar) ;
2647       ar->Delete() ; 
2648       delete ar ; 
2649     }
2650   }  
2651
2652   // TrackSegments
2653
2654   emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/TrackSegments")) ;
2655
2656   if (emcal) { 
2657     ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fTrackSegmentsTitle)) ; 
2658     if (ar) { 
2659       emcal->Remove(ar) ;
2660       ar->Delete() ; 
2661       delete ar ; 
2662     }
2663   }
2664
2665   // RecParticles
2666
2667   emcal = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/RecParticles")) ;
2668
2669   if (emcal){ 
2670     ar  = dynamic_cast<TObjArray*>(emcal->FindObject(fRecParticlesTitle)) ; 
2671     if (ar) { 
2672       emcal->Remove(ar) ;
2673       ar->Delete() ; 
2674       delete ar ; 
2675     }
2676   }
2677
2678   //---- Now Tasks ----------- 
2679
2680   TObject * obj ;
2681   TString sdname(fSDigitsTitle);
2682
2683   // Digitizer
2684
2685   task = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ;
2686
2687   if (task){ 
2688     emcalt =  dynamic_cast<TTask*>(task->GetListOfTasks()->FindObject("EMCAL")) ;
2689     if (emcalt){
2690       lofTasks = emcalt->GetListOfTasks() ;
2691       if (lofTasks){ 
2692         obj = lofTasks->FindObject(sdname.Data()) ; 
2693         if (obj) 
2694           lofTasks->Remove(obj) ;
2695       }
2696     }      
2697   }
2698
2699   sdname.Append(":") ;
2700
2701   // Clusterizer, TrackSegmentMaker, PID
2702
2703   task = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ;
2704
2705   if (task){ 
2706     emcalt =  dynamic_cast<TTask*>(task->GetListOfTasks()->FindObject("EMCAL")) ;
2707     if (emcalt){
2708       lofTasks = emcalt->GetListOfTasks() ;
2709       TIter next(lofTasks);
2710       while((obj=next())){ 
2711         TString oname(obj->GetName()) ;
2712         if (oname.BeginsWith(sdname)){ 
2713           lofTasks->Remove(obj) ;
2714         }
2715       }
2716     }  
2717   }
2718
2719   // SDigitizer
2720
2721   sdname.Append(fHeaderFile) ;
2722   task = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ;
2723
2724   if (task) {
2725     emcalt =  dynamic_cast<TTask*>(task->GetListOfTasks()->FindObject("EMCAL")) ;
2726     if (emcalt){
2727       lofTasks = emcalt->GetListOfTasks() ;
2728       if (lofTasks){ 
2729         obj = lofTasks->FindObject(sdname.Data()) ; 
2730         if (obj) 
2731           lofTasks->Remove(obj) ;
2732       }
2733     }
2734   }  
2735 }
2736
2737 //____________________________________________________________________________ 
2738
2739 void AliEMCALGetter::SetTitle(const char * branchTitle ) 
2740
2741 {
2742   fBranchTitle        = branchTitle ;
2743   fSDigitsTitle       = branchTitle ; 
2744   fDigitsTitle        = branchTitle ; 
2745   fRecPointsTitle     = branchTitle ; 
2746   fRecParticlesTitle  = branchTitle ; 
2747   fTrackSegmentsTitle = branchTitle ; 
2748
2749   if(fToSplit){
2750
2751     //First - extract full path if necessary
2752
2753     TString sFileName(fHeaderFile) ;
2754     Ssiz_t islash = sFileName.Last('/') ;
2755
2756     if(islash<sFileName.Length())
2757       sFileName.Remove(islash+1,sFileName.Length()) ;
2758     else
2759       sFileName="" ;
2760
2761     //Now construct file names
2762
2763     fSDigitsFileName       = sFileName ;
2764     fDigitsFileName        = sFileName ; 
2765     fRecPointsFileName     = sFileName ; 
2766     fRecParticlesFileName  = sFileName ; 
2767     fTrackSegmentsFileName = sFileName ; 
2768     fSDigitsFileName      += "EMCAL.SDigits." ;
2769     fDigitsFileName       += "EMCAL.Digits." ; 
2770     fRecPointsFileName    += "EMCAL.RecData." ; 
2771     fTrackSegmentsFileName+= "EMCAL.RecData." ; 
2772     fRecParticlesFileName += "EMCAL.RecData." ; 
2773
2774     if((strcmp(fBranchTitle.Data(),"Default")!=0)&&(strcmp(fBranchTitle.Data(),"")!=0)){
2775       fSDigitsFileName      += fBranchTitle ;
2776       fSDigitsFileName      += "." ;
2777       fDigitsFileName       += fBranchTitle ; 
2778       fDigitsFileName       += "." ; 
2779       fRecPointsFileName    += fBranchTitle ; 
2780       fRecPointsFileName    += "." ; 
2781       fRecParticlesFileName += fBranchTitle ; 
2782       fRecParticlesFileName += "." ; 
2783       fTrackSegmentsFileName+= fBranchTitle ; 
2784       fTrackSegmentsFileName+= "." ; 
2785     }
2786
2787     fSDigitsFileName      += "root" ;
2788     fDigitsFileName       += "root" ; 
2789     fRecPointsFileName    += "root" ; 
2790     fRecParticlesFileName += "root" ; 
2791     fTrackSegmentsFileName+= "root" ; 
2792   }
2793   else{
2794     fSDigitsFileName       = "" ; 
2795     fDigitsFileName        = "" ; 
2796     fRecPointsFileName     = "" ; 
2797     fRecParticlesFileName  = "" ; 
2798     fTrackSegmentsFileName = "" ; 
2799   }
2800
2801   TFolder * emcalFolder ; 
2802   emcalFolder = dynamic_cast<TFolder*>(fHitsFolder->FindObject("EMCAL")) ; 
2803
2804   if ( !emcalFolder ) 
2805     emcalFolder = fHitsFolder->AddFolder("EMCAL", "Hits from EMCAL") ; 
2806
2807   emcalFolder = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
2808
2809   if ( !emcalFolder ) 
2810     emcalFolder = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ; 
2811
2812   //Make folder for SDigits
2813
2814   TString subdir(fHeaderFile) ;
2815   subdir.ReplaceAll("/","_") ;
2816
2817   emcalFolder->AddFolder(subdir, fSDigitsFileName.Data());
2818   emcalFolder  = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ;
2819
2820   if ( !emcalFolder ) 
2821     emcalFolder = fDigitsFolder->AddFolder("EMCAL", "Digits from EMCAL") ;  
2822
2823   emcalFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL")) ; 
2824
2825   if ( !emcalFolder )
2826     emcalFolder = fRecoFolder->AddFolder("EMCAL", "Reconstructed data from EMCAL") ;  
2827 }
2828
2829 //____________________________________________________________________________ 
2830
2831 void AliEMCALGetter::CloseSplitFiles(void){
2832
2833   TFile * file ;
2834   file = static_cast<TFile*>(gROOT->GetFile(fSDigitsFileName.Data() ) ) ;
2835
2836   if(file)
2837     file->Close() ;
2838
2839   file = static_cast<TFile*>(gROOT->GetFile(fDigitsFileName.Data() ) ) ;
2840
2841   if(file)
2842     file->Close() ;
2843
2844   file = static_cast<TFile*>(gROOT->GetFile(fRecPointsFileName.Data() ) ) ;
2845
2846   if(file)
2847     file->Close() ;
2848
2849   file = static_cast<TFile*>(gROOT->GetFile(fTrackSegmentsFileName.Data() ) ) ;
2850
2851   if(file)
2852     file->Close() ;
2853
2854   file = static_cast<TFile*>(gROOT->GetFile(fRecParticlesFileName.Data() ) ) ;
2855
2856   if(file)
2857     file->Close() ;
2858 }
2859
2860
2861
2862
2863
2864