]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALGetter.cxx
Refreshes gAlice by getting it from the file each time a new getter is instantiated
[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
18 /* $Log:
19    29.05.2001 Yuri Kharlov:
20               Everywhere reading the treese TTree->GetEvent(i)
21               is replaced by reading the branches TBranch->GetEntry(0)
22 */
23
24 //_________________________________________________________________________
25 //  A singleton. This class should be used in the analysis stage to get 
26 //  reconstructed objects: Digits, RecPoints, TrackSegments and RecParticles,
27 //  instead of directly reading them from galice.root file. This container 
28 //  ensures, that one reads Digits, made of these particular digits, RecPoints, 
29 //  made of these particular RecPoints, TrackSegments and RecParticles. 
30 //  This becomes non trivial if there are several identical branches, produced with
31 //  different set of parameters. 
32 //
33 //  An example of how to use (see also class AliEMCALAnalyser):
34 //  AliEMCALGetter * gime = AliEMCALGetter::GetInstance("galice.root","test") ;
35 //  for(Int_t irecp = 0; irecp < gime->NRecParticles() ; irecp++)
36 //     AliEMCALRecParticle * part = gime->RecParticle(1) ;
37 //     ................
38 //  please->GetEvent(event) ;    // reads new event from galice.root
39 //                  
40 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
41 //*--         Completely redesigned by Dmitri Peressounko March 2001  
42 //
43 //*-- YS June 2001 : renamed the original AliEMCALIndexToObject and make
44 //*--         systematic usage of TFolders without changing the interface        
45 //////////////////////////////////////////////////////////////////////////////
46
47
48 // --- ROOT system ---
49
50 #include "TFile.h"
51 #include "TTree.h"
52 #include "TROOT.h"
53 #include "TObjString.h"
54 #include "TFolder.h"
55
56 // --- Standard library ---
57 #include <iostream.h>
58
59 // --- AliRoot header files ---
60
61 #include "AliRun.h"
62 #include "AliConfig.h"
63 #include "AliEMCALGetter.h"
64 #include "AliEMCALHit.h"
65 #include "AliEMCALv1.h"
66 #include "AliEMCALDigitizer.h"
67 #include "AliEMCALSDigitizer.h"
68 #include "AliEMCALClusterizer.h"
69 #include "AliEMCALClusterizerv1.h"
70 //#include "AliEMCALTrackSegmentMaker.h"
71 //#include "AliEMCALTrackSegmentMakerv1.h"
72 //#include "AliEMCALTrackSegment.h"
73 //#include "AliEMCALPID.h" 
74 //#include "AliEMCALPIDv1.h" 
75 #include "AliEMCALGeometry.h"
76
77 ClassImp(AliEMCALGetter)
78   
79   AliEMCALGetter * AliEMCALGetter::fgObjGetter = 0 ; 
80   TFile * AliEMCALGetter::fFile = 0 ; 
81
82 //____________________________________________________________________________ 
83 AliEMCALGetter::AliEMCALGetter(const char* headerFile, const char* branchTitle, const Option_t * rw)
84 {
85   //Initialize  all lists
86
87   fDebug = 0 ; 
88
89   fHeaderFile         = headerFile ; 
90   fBranchTitle        = branchTitle ;
91   fSDigitsTitle       = branchTitle ; 
92   fDigitsTitle        = branchTitle ; 
93   fRecPointsTitle     = branchTitle ; 
94   //fRecParticlesTitle  = branchTitle ; 
95   //fTrackSegmentsTitle = branchTitle ; 
96
97   fPrimaries = new TObjArray(1) ;
98
99   fModuleFolder  = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Configuration/Modules")); 
100   fHitsFolder    = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/RunMC/Event/Data/Hits")); 
101   fSDigitsFolder = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/RunMC/Event/Data/SDigits")); 
102   fDigitsFolder  = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Event/Data")); 
103   fRecoFolder    = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Event/RecData")); 
104   //fQAFolder      = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Conditions/QA")); 
105   fTasksFolder   = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Tasks")) ; 
106
107   fFailed = kFALSE ; 
108                    
109   if ( fHeaderFile != "aliroot"  ) { // to call the getter without a file
110
111     //open headers file
112     fFile = static_cast<TFile*>(gROOT->GetFile(fHeaderFile.Data() ) ) ;
113     if(!fFile){    //if file was not opened yet, read gAlice
114       if ( fHeaderFile.Contains("_") ) {
115         cerr << "AliPHOSGetter::AliPHOSGetter -> Invalid file name (_ not allowed) " << fHeaderFile.Data() << endl ;
116         abort() ; 
117       }
118       fFile =   TFile::Open(fHeaderFile.Data(),rw) ;   
119       
120       if (!fFile->IsOpen()) {
121         cerr << "ERROR : AliEMCALGetter::AliEMCALGetter -> Cannot open " << fHeaderFile.Data() << endl ; 
122         fFailed = kTRUE ;
123         return ;  
124       }
125     }
126     gAlice = static_cast<AliRun *>(fFile->Get("gAlice")) ;
127   }
128   
129
130   if (!gAlice) {
131     cerr << "ERROR : AliEMCALGetter::AliEMCALGetter -> Cannot find gAlice in " << fHeaderFile.Data() << endl ; 
132     fFailed = kTRUE ;
133     return ; 
134   }
135   if (!EMCAL()) {
136     if (fDebug)
137       cout << "INFO: AliEMCALGetter -> Posting EMCAL to Folders" << endl ; 
138     if (gAlice->GetDetector("EMCAL")) {
139       AliConfig * conf = AliConfig::Instance() ;
140       conf->Add(static_cast<AliDetector*>(gAlice->GetDetector("EMCAL"))) ; 
141       conf->Add(static_cast<AliModule*>(gAlice->GetDetector("EMCAL"))) ;
142     }
143     else 
144       cerr << "ERROR: AliEMCALGetter -> detector EMCAL not found" << endl ;
145   }
146   
147   fDebug=0;
148 }
149 //____________________________________________________________________________ 
150 AliEMCALGetter::~AliEMCALGetter()
151 {
152   if (fPrimaries) {
153     fPrimaries->Delete() ; 
154     delete fPrimaries ; 
155   }
156
157   TFolder * emcalF = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject("EMCAL")) ;
158   TCollection * folderslist = emcalF->GetListOfFolders() ; 
159   TIter next(folderslist) ; 
160   TFolder * folder = 0 ; 
161   while ( (folder = static_cast<TFolder*>(next())) ) 
162     emcalF->Remove(folder) ; 
163
164   fFile->Close() ;  
165   delete fFile ; 
166   fFile = 0 ;
167 }
168
169 //____________________________________________________________________________ 
170 void AliEMCALGetter::CreateWhiteBoard() const
171 {
172
173 }
174
175 //____________________________________________________________________________ 
176 AliEMCALGetter * AliEMCALGetter::GetInstance()
177 {
178   // Returns the pointer of the unique instance already defined
179   
180   AliEMCALGetter * rv = 0 ;
181   if ( fgObjGetter )
182     rv = fgObjGetter ;
183   else
184     cout << "AliEMCALGetter::GetInstance ERROR: not yet initialized" << endl ;
185   
186   fFile->cd() ; 
187   return rv ;
188 }
189
190 //____________________________________________________________________________ 
191 AliEMCALGetter * AliEMCALGetter::GetInstance(const char* headerFile,
192                                            const char* branchTitle, const Option_t * rw)
193 {
194   // Creates and returns the pointer of the unique instance
195   // Must be called only when the environment has changed 
196
197   if ( fgObjGetter )    
198     if((fgObjGetter->fBranchTitle.CompareTo(branchTitle) == 0) && 
199        (fgObjGetter->fHeaderFile.CompareTo(headerFile)==0)) {
200       fFile->cd() ; 
201       return fgObjGetter ;
202     }
203     else
204       fgObjGetter->~AliEMCALGetter() ;  // delete it already exists another version
205
206   fgObjGetter = new AliEMCALGetter(headerFile,branchTitle, rw) ; 
207
208   if (fgObjGetter->HasFailed() ) 
209     fgObjGetter = 0 ; 
210     
211   fFile->cd() ; 
212   return fgObjGetter ; 
213   
214 }
215
216 //____________________________________________________________________________ 
217 const AliEMCALv1 * AliEMCALGetter::EMCAL() 
218 {
219   // returns the EMCAL object 
220   AliEMCALv1 * emcal = dynamic_cast<AliEMCALv1*>(fModuleFolder->FindObject("EMCAL")) ;  
221   if (!emcal) 
222     if (fDebug)
223       cout << "WARNING: AliEMCALGetter::EMCAL -> EMCAL module not found in Folders" << endl ; 
224   return emcal ; 
225 }  
226
227 //____________________________________________________________________________ 
228 AliEMCALGeometry * AliEMCALGetter::EMCALGeometry() 
229 {
230   AliEMCALGeometry * rv = 0 ; 
231   if (EMCAL() )
232     rv =  EMCAL()->GetGeometry() ;
233   return rv ; 
234
235
236 //____________________________________________________________________________ 
237 Bool_t AliEMCALGetter::PostHits(void) const 
238 {  //------- Hits ----------------------
239
240   // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/Hits
241   
242   TFolder * emcalFolder = dynamic_cast<TFolder*>(fHitsFolder->FindObject("EMCAL")) ; 
243   if ( !emcalFolder ) {
244     if (fDebug) {
245       cout << "WARNING: AliEMCALGetter::Post H -> Folder //" << fHitsFolder << "/EMCAL/ not found!" << endl;
246       cout << "INFO:    AliEMCALGetter::Post H -> Adding Folder //" << fHitsFolder << "/EMCAL/"  << endl;
247     }
248     emcalFolder = fHitsFolder->AddFolder("EMCAL", "Hits from EMCAL") ; 
249   }    
250   TClonesArray *hits=  new TClonesArray("AliEMCALHit",1000) ;
251   hits->SetName("Hits") ;
252   emcalFolder->Add(hits) ; 
253   
254   return kTRUE;
255
256
257 //____________________________________________________________________________ 
258 TObject ** AliEMCALGetter::HitsRef(void) const 
259 {  //------- Hits ----------------------
260
261   
262   // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/Hits
263   if ( !fHitsFolder ) {
264     cerr << "ERROR: AliEMCALGetter::Post H -> Folder //" << fHitsFolder << " not found!" << endl;
265     return 0;
266   }    
267  
268   TFolder * emcalFolder = dynamic_cast<TFolder *>(fHitsFolder->FindObject("EMCAL")) ;
269   if ( !emcalFolder ) {
270     cerr << "ERROR: AliEMCALGetter::Post HRef -> Folder //" << fHitsFolder << "/EMCAL/ not found!" << endl;  
271     return 0;
272   }
273  
274   TObject * h = emcalFolder->FindObject("Hits") ;
275   if(!h) {
276     cerr << "ERROR: AliEMCALGetter::HRef -> " << emcalFolder->GetName() << "/Hits not found !" << endl ; 
277     return 0 ;
278   }
279   else
280     return emcalFolder->GetListOfFolders()->GetObjectRef(h) ;
281 }
282
283 //____________________________________________________________________________ 
284 Bool_t AliEMCALGetter::PostSDigits(const char * name, const char * headerFile) const 
285 {  //---------- SDigits -------------------------
286
287   
288   // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/SDigits/headerFile/sdigitsname
289   // because you can have sdigits from several hit files for mixing
290   
291   TFolder * emcalFolder = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ;
292   if ( !emcalFolder ) {
293     if (fDebug) {
294       cout << "WARNING: AliEMCALGetter::Post S -> Folder //" << fSDigitsFolder << "/EMCAL/ not found!" << endl;
295       cout << "INFO:    AliEMCALGetter::Post S -> Adding Folder //" << fHitsFolder << "/EMCAL/" << endl;
296     }
297     emcalFolder = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ; 
298   }    
299   TString subdir(headerFile) ;
300   subdir.ReplaceAll("/", "_") ; 
301   TFolder * emcalSubFolder = dynamic_cast<TFolder*>(emcalFolder->FindObject(subdir)) ; 
302   if ( !emcalSubFolder ) 
303     emcalSubFolder = emcalFolder->AddFolder(subdir, ""); 
304   
305   TObject * sd  = emcalSubFolder->FindObject(name); 
306   if ( sd ) {
307     if (fDebug)
308       cerr <<"INFO: AliEMCALGetter::Post S -> Folder " << subdir 
309            << " already exists!" << endl ;  
310   }else{
311     TClonesArray * sdigits = new TClonesArray("AliEMCALDigit",1) ;
312     sdigits->SetName(name) ;
313     emcalSubFolder->Add(sdigits) ;
314   }
315   
316   return kTRUE;
317
318 //____________________________________________________________________________ 
319 TObject ** AliEMCALGetter::SDigitsRef(const char * name, const char * file) const 
320 {  //------- SDigits ----------------------
321   
322   // the hierarchy is //Folders/RunMC/Event/Data/EMCAL/SDigits/filename/SDigits
323
324   if ( !fSDigitsFolder ) {
325     cerr << "ERROR: AliEMCALGetter::Post SRef -> Folder //" << fSDigitsFolder << " not found!" << endl;
326     return 0;
327   }    
328  
329   TFolder * emcalFolder = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject("EMCAL")) ;
330   if ( !emcalFolder ) {
331     cerr << "ERROR: AliEMCALGetter::Post SRef -> Folder //" << fSDigitsFolder << "/EMCAL/ not found!" << endl;
332     return 0;
333   }
334
335   TFolder * emcalSubFolder = 0 ;
336   if(file)
337     emcalSubFolder = dynamic_cast<TFolder *>(emcalFolder->FindObject(file)) ;
338   else
339     emcalSubFolder = dynamic_cast<TFolder *>(emcalFolder->FindObject(fHeaderFile)) ;
340   
341   if(!emcalSubFolder) {
342     cerr << "ERROR: AliEMCALGetter::Post SRef -> Folder //Folders/RunMC/Event/Data/EMCAL/" << file << "not found!" << endl;
343     return 0;
344   }
345
346   TObject * dis = emcalSubFolder->FindObject(name) ;
347   if(!dis)
348     return 0 ;
349   else
350     return emcalSubFolder->GetListOfFolders()->GetObjectRef(dis) ;
351
352 }
353
354 //____________________________________________________________________________ 
355 Bool_t AliEMCALGetter::PostSDigitizer(AliEMCALSDigitizer * sdigitizer) const 
356 {  //---------- SDigitizer -------------------------
357     
358   // the hierarchy is //Folders/Tasks/SDigitizer/EMCAL/sdigitsname
359
360
361   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ; 
362
363   if ( !sd ) {
364     cerr << "ERROR: AliEMCALGetter::Post Ser -> Task //" << fTasksFolder << "/SDigitizer not found!" << endl;
365     return kFALSE ;
366   }        
367   TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ; 
368   if ( !emcal )  {
369     if (fDebug) {
370       cout <<"WARNING: AliEMCALGetter::Post Ser ->//" << fTasksFolder << "/SDigitizer/EMCAL/ not found!" << endl;  
371       cout <<"INFO: AliEMCALGetter::Post Ser -> Adding //" << fTasksFolder << "/SDigitizer/EMCAL/" << endl;
372     }
373     emcal = new TTask("EMCAL", "") ; 
374     sd->Add(emcal) ; 
375   } 
376   AliEMCALSDigitizer * emcalsd  = dynamic_cast<AliEMCALSDigitizer *>(emcal->GetListOfTasks()->FindObject( sdigitizer->GetName() )); 
377   if (emcalsd) { 
378     if (fDebug)
379       cout << "INFO: AliEMCALGetter::Post Ser -> Task " << sdigitizer->GetName() << " already exists" << endl ; 
380     emcal->GetListOfTasks()->Remove(emcalsd) ;
381   }
382   emcal->Add(sdigitizer) ;      
383   return kTRUE; 
384   
385 }
386
387 //____________________________________________________________________________ 
388 TObject ** AliEMCALGetter::SDigitizerRef(const char * name) const 
389 {  
390
391   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ; 
392   if ( !sd ) {
393     cerr << "ERROR: AliEMCALGetter::Post SerRef -> Task //" << fTasksFolder << "/SDigitizer not found!" << endl;
394     abort();
395   }        
396
397   TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ; 
398   if ( !emcal )  {
399     cerr <<"ERROR: AliEMCALGetter::Post SerRef ->  //" << fTasksFolder << "/SDigitizer/EMCAL not found!" << endl;
400     abort();
401   }        
402
403   TTask * task = dynamic_cast<TTask*>(emcal->GetListOfTasks()->FindObject(name)) ; 
404
405   return emcal->GetListOfTasks()->GetObjectRef(task) ;
406
407 }
408
409 //____________________________________________________________________________ 
410 Bool_t AliEMCALGetter::PostSDigitizer(const char * name, const char * file) const 
411 {  //---------- SDigitizer -------------------------
412   
413  // the hierarchy is //Folders/Tasks/SDigitizer/EMCAL/sdigitsname
414
415
416   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ; 
417   if ( !sd ) {
418     cerr << "ERROR: AliEMCALGetter::Post Ser -> Task //" << fTasksFolder << "/SDigitizer not found!" << endl;
419     return kFALSE ;
420   }        
421
422   TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ; 
423   if ( !emcal )  {
424     if (fDebug) {
425       cout <<"WARNING: AliEMCALGetter::Post Ser ->  //" << fTasksFolder << "/SDigitizer/EMCAL/ not found!" << endl;
426       cout <<"INFO: AliEMCALGetter::Post Ser -> Adding  //" << fTasksFolder << "/SDigitizer/EMCAL" << endl;
427     }
428     emcal = new TTask("EMCAL", "") ; 
429     sd->Add(emcal) ; 
430   } 
431
432   TString sdname(name) ;
433   sdname.Append(":") ;
434   sdname.Append(file);
435   sdname.ReplaceAll("/","_") ; 
436   AliEMCALSDigitizer * emcalsd  = dynamic_cast<AliEMCALSDigitizer *>(emcal->GetListOfTasks()->FindObject( sdname )); 
437   if (!emcalsd) {
438     emcalsd = new AliEMCALSDigitizer() ;  
439     //Note, we can not call constructor with parameters: it will call Getter and screw up everething
440     emcalsd->SetName(sdname) ;
441     emcalsd->SetTitle(file) ;
442     emcal->Add(emcalsd) ;       
443   }
444   return kTRUE; 
445   
446 }
447
448 //____________________________________________________________________________ 
449 Bool_t AliEMCALGetter::PostDigits(const char * name) const 
450 {  //---------- Digits -------------------------
451
452   // the hierarchy is //Folders/Run/Event/Data/EMCAL/SDigits/name
453
454   TFolder * emcalFolder  = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ;
455
456   if ( !emcalFolder ) {
457     if (fDebug) {
458       cout << "WARNING: AliEMCALGetter::Post D -> Folder //" << fDigitsFolder << "/EMCAL/ not found!" << endl;
459       cout << "INFO:    AliEMCALGetter::Post D -> Adding Folder //" << fDigitsFolder << "/EMCAL/" << endl;
460     }
461     emcalFolder = fDigitsFolder->AddFolder("EMCAL", "Digits from EMCAL") ;  
462   }    
463  
464   TObject*  dig = emcalFolder->FindObject( name ) ;
465   if ( !dig ) {
466     TClonesArray * digits = new TClonesArray("AliEMCALDigit",1000) ;
467     digits->SetName(name) ;
468     emcalFolder->Add(digits) ;  
469   }
470   return kTRUE; 
471 }
472
473 //____________________________________________________________________________ 
474 TObject ** AliEMCALGetter::DigitsRef(const char * name) const 
475 { //------- Digits ----------------------
476   
477   // the hierarchy is //Folders/Run/Event/Data/EMCAL/Digits/name
478
479   if ( !fDigitsFolder ) {
480     cerr << "ERROR: AliEMCALGetter::Post DRef -> Folder //" << fDigitsFolder << " not found!" << endl;
481     return 0;
482   }    
483   
484   TFolder * emcalFolder  = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("EMCAL")) ; 
485   if ( !emcalFolder ) {
486     cerr << "ERROR: AliEMCALGetter::DRef -> Folder //" << fDigitsFolder << "/EMCAL/ not found!" << endl;
487     return 0;
488   }    
489
490   TObject * d = emcalFolder->FindObject(name) ;
491   if(!d)
492     return 0 ;
493   else
494     return emcalFolder->GetListOfFolders()->GetObjectRef(d) ;
495
496 }
497
498 //____________________________________________________________________________ 
499 Bool_t AliEMCALGetter::PostDigitizer(AliEMCALDigitizer * digitizer) const 
500 {  //---------- Digitizer -------------------------
501   
502   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ; 
503
504   if ( !sd ) {
505     cerr << "ERROR: AliEMCALGetter::Post Der -> Task //" << fTasksFolder << "/Digitizer not found!" << endl;
506     return kFALSE ;
507   }        
508   TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ; 
509   if ( !emcal )  {
510     if (fDebug) {
511       cout <<"WARNING: AliEMCALGetter::Post Der ->  //" << fTasksFolder << "/Digitizer/EMCAL not found!" << endl;
512       cout <<"INFO: AliEMCALGetter::Post Der -> Adding //" << fTasksFolder << "/Digitizer/EMCAL" << endl; 
513     }
514     emcal = new TTask("EMCAL", "") ; 
515     sd->Add(emcal) ; 
516   } 
517
518     AliEMCALDigitizer * emcald = dynamic_cast<AliEMCALDigitizer*>(emcal->GetListOfTasks()->FindObject(digitizer->GetName())) ; 
519     if (emcald) { 
520       emcald->Delete() ;
521       emcal->GetListOfTasks()->Remove(emcald) ;
522     }
523     emcal->Add(digitizer) ; 
524     return kTRUE; 
525 }  
526
527 //____________________________________________________________________________ 
528 Bool_t AliEMCALGetter::PostDigitizer(const char * name) const 
529 {  //---------- Digitizer -------------------------
530   
531  // the hierarchy is //Folders/Tasks/SDigitizer/EMCAL/sdigitsname
532
533   TTask * d  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ; 
534   if ( !d ) {
535     cerr << "ERROR: AliEMCALGetter::Post Der -> Task //" << fTasksFolder << "/Digitizer not found!" << endl;
536     return kFALSE ;
537   }        
538
539   TTask * emcal = dynamic_cast<TTask*>(d->GetListOfTasks()->FindObject("EMCAL")) ; 
540   if ( !emcal )  {
541     if (fDebug) {
542       cout <<"WARNING: AliEMCALGetter::Post Der -> //" << fTasksFolder << "/Digitizer/EMCAL not found!" << endl; 
543       cout <<"INFO: AliEMCALGetter::Post Der -> Adding //" << fTasksFolder << "/Digitizer/EMCAL" << endl;
544     }
545     emcal = new TTask("EMCAL", "") ; 
546     d->Add(emcal) ; 
547
548
549   AliEMCALDigitizer * emcald = dynamic_cast<AliEMCALDigitizer*>(emcal->GetListOfTasks()->FindObject(name)) ; 
550   if (!emcald) { 
551     emcald = new AliEMCALDigitizer() ;
552     emcald->SetName(fDigitsTitle) ;
553     emcald->SetTitle(fHeaderFile) ;
554     emcal->Add(emcald) ;
555   }
556   return kTRUE;  
557 }
558
559 //____________________________________________________________________________ 
560 TObject ** AliEMCALGetter::DigitizerRef(const char * name) const 
561 {  
562   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ; 
563   if ( !sd ) {
564     cerr << "ERROR: AliEMCALGetter::Post DerRef -> Task //" << fTasksFolder << "/Digitizer not found!" << endl;
565     abort();
566   }        
567
568   TTask * emcal = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("EMCAL")) ; 
569   if ( !emcal )  {
570     cerr <<"ERROR: AliEMCALGetter::Post DerRef ->  //" << fTasksFolder << "/Digitizer/EMCAL" << endl;
571     abort();
572   }        
573
574   TTask * task = dynamic_cast<TTask*>(emcal->GetListOfTasks()->FindObject(name)) ; 
575
576   return emcal->GetListOfTasks()->GetObjectRef(task) ;
577
578 }
579  
580 //____________________________________________________________________________ 
581 Bool_t AliEMCALGetter::PostRecPoints(const char * name) const 
582 { // -------------- RecPoints -------------------------------------------
583   
584   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/TowerRecPoints/name
585   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/PreShoRecPoints/name
586
587   TFolder * emcalFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL")) ; 
588   
589   if ( !emcalFolder ) {
590     if (fDebug) {
591       cout << "WARNING: AliEMCALGetter::Post RPo -> Folder //" << fRecoFolder << "/EMCAL/ not found!" << endl;
592       cout << "INFO:    AliEMCALGetter::Post Rpo -> Adding Folder //" << fRecoFolder << "/EMCAL/" << endl;
593     }
594     emcalFolder = fRecoFolder->AddFolder("EMCAL", "Reconstructed data from EMCAL") ;  
595   }    
596   
597   // Tower RecPoints 
598   TFolder * emcalRPoTowerFolder  = dynamic_cast<TFolder*>(emcalFolder->FindObject("TowerRecPoints")) ;
599   if ( !emcalRPoTowerFolder ) {
600     if (fDebug) {
601       cout << "WARNING: AliEMCALGetter::Post RPo -> Folder //" << fRecoFolder << "/EMCAL/TowerRecPoints/ not found!" << endl;
602       cout << "INFO:    AliEMCALGetter::Post Rpo -> Adding Folder //" << fRecoFolder << "/EMCAL/TowerRecPoints not found!" << endl;
603     }
604     emcalRPoTowerFolder = emcalFolder->AddFolder("TowerRecPoints", "Tower RecPoints from EMCAL") ;  
605   }    
606   
607   TObject * erp = emcalFolder->FindObject( name ) ;
608   if ( !erp )   {
609     TObjArray * towerrp = new TObjArray(100) ;
610     towerrp->SetName(name) ;
611     emcalRPoTowerFolder->Add(towerrp) ;  
612   }
613
614   // Pre Shower RecPoints 
615   TFolder * emcalRPoPreShoFolder  = dynamic_cast<TFolder*>(emcalFolder->FindObject("PreShoRecPoints")) ;
616   if ( !emcalRPoPreShoFolder ) {
617     if (fDebug) {
618       cout << "WARNING: AliEMCALGetter::Post RPo -> Folder //" << fRecoFolder << "/EMCAL/PreShoRecPoints/ not found!" << endl;
619       cout << "INFO:    AliEMCALGetter::Post Rpo -> Adding Folder //" << fRecoFolder << "/EMCAL/PreShoRecPoints/" << endl;
620     }
621     emcalRPoPreShoFolder = emcalFolder->AddFolder("PreShoRecPoints", "PreSho RecPoints from EMCAL") ;  
622   }    
623   
624   TObject * crp =  emcalRPoPreShoFolder->FindObject( name ) ;
625   if ( !crp )   {
626     TObjArray * preshorp = new TObjArray(100) ;
627     preshorp->SetName(name) ;
628     emcalRPoPreShoFolder->Add(preshorp) ;  
629   }
630   return kTRUE; 
631 }
632
633 //____________________________________________________________________________ 
634 TObject ** AliEMCALGetter::TowerRecPointsRef(const char * name) const 
635 { // -------------- RecPoints -------------------------------------------
636   
637   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/TowerRecPoints/name
638    
639   if ( !fRecoFolder ) {
640     cerr << "ERROR: AliEMCALGetter::TowerRecPointsRef -> Folder //" << fRecoFolder << " not found!" << endl;
641     abort() ; 
642   }    
643
644   TFolder * towerFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/TowerRecPoints")) ; 
645   if ( !towerFolder ) {
646     cerr << "ERROR: AliEMCALGetter::TowerRecPointsRef -> Folder //" << fRecoFolder << "/EMCAL/TowerRecPoints/ not found!" << endl;
647     abort() ;
648   }    
649
650
651   TObject * trp = towerFolder->FindObject(name ) ;
652   if ( !trp )   {
653     cerr << "ERROR: AliEMCALGetter::TowerRecPointsRef -> Object " << name << " not found!" << endl  ;
654     abort() ; 
655   }
656   return towerFolder->GetListOfFolders()->GetObjectRef(trp) ;
657
658
659
660 //____________________________________________________________________________ 
661 TObject ** AliEMCALGetter::PreShoRecPointsRef(const char * name) const 
662 { // -------------- RecPoints -------------------------------------------
663   
664   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/PreShoRecPoints/name
665    
666   if ( !fRecoFolder ) {
667     cerr << "ERROR: AliEMCALGetter::PreShoRecPointsRef -> Folder //" << fRecoFolder << " not found!" << endl;
668     abort() ; 
669   }    
670
671   TFolder * preshoFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/PreShoRecPoints")) ; 
672   if ( !preshoFolder ) {
673     cerr << "ERROR: AliEMCALGetter::PreShoRecPointsRef -> Folder //" << fRecoFolder << "/EMCAL/PreShoRecPoints/" << endl;
674     abort() ;
675   }    
676
677   TObject * prp = preshoFolder->FindObject(name ) ;
678   if ( !prp )   {
679     cerr << "ERROR: AliEMCALGetter::PreShoRecPointsRef -> Object " << name << " not found! " << endl ; 
680     abort() ;
681   }
682   return preshoFolder->GetListOfFolders()->GetObjectRef(prp) ;
683
684
685
686 //____________________________________________________________________________ 
687 Bool_t AliEMCALGetter::PostClusterizer(AliEMCALClusterizerv1 * clu) const 
688 { // ------------------ AliEMCALClusterizer ------------------------
689   
690   // the hierarchy is //Folders/Tasks/Reconstructioner/EMCAL/sdigitsname
691
692   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
693
694   if ( !tasks ) {
695     cerr << "ERROR: AliEMCALGetter::Post Rer -> Task //" << fTasksFolder << "/Reconstructioner not found!" << endl;
696     return kFALSE ;
697   }        
698         
699   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
700   if ( !emcal )  {
701     if (fDebug) {
702       cout <<"WARNING: AliEMCALGetter::Post Rer -> //" << fTasksFolder << "/ReconstructionerEMCAL not found!" << endl; 
703       cout <<"INFO: AliEMCALGetter::Post Rer -> Adding //" << fTasksFolder << "/Reconstructioner/EMCAL" << endl; 
704     }
705     emcal = new TTask("EMCAL", "") ; 
706     tasks->Add(emcal) ; 
707   } 
708
709   AliEMCALClusterizerv1 * emcalcl = dynamic_cast<AliEMCALClusterizerv1*>(emcal->GetListOfTasks()->FindObject(clu->GetName())) ; 
710   if (emcalcl) { 
711     if (fDebug)
712       cout << "INFO: AliEMCALGetter::Post Rer -> Task " << clu->GetName() << " already exists" << endl ; 
713     emcalcl->Delete() ; 
714     emcal->GetListOfTasks()->Remove(emcalcl) ;
715   }
716   emcal->Add(clu) ;      
717   return kTRUE; 
718
719
720 //____________________________________________________________________________ 
721 TObject ** AliEMCALGetter::ClusterizerRef(const char * name) const 
722 { // ------------------ AliEMCALClusterizer ------------------------
723   
724   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
725
726   if ( !tasks ) {
727     cerr << "ERROR: AliEMCALGetter::Post RerRef -> Task //" << fTasksFolder << "/Reconstructioner not found!" << endl;
728     abort() ;
729   }        
730         
731   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
732   if ( !emcal )  {
733     cerr <<"WARNING: AliEMCALGetter::Post RerRef -> //" << fTasksFolder << "/Reconstructioner/EMCAL" << endl; 
734     abort() ; 
735   }   
736
737   TList * l = emcal->GetListOfTasks() ; 
738   TIter it(l) ;
739   TTask * task ;
740   TTask * clu = 0 ;
741   TString cluname(name) ;
742   cluname+=":clu-" ;
743   while((task = static_cast<TTask *>(it.Next()) )){
744     TString taskname(task->GetName()) ;
745     if(taskname.BeginsWith(cluname)){
746       clu = task ;
747       break ;
748     }
749   }
750
751   if(clu) 
752     return l->GetObjectRef(clu) ;
753   else {
754     cerr << "ERROR: AliEMCALGetter::Post RerRef -> task " << task->GetName() << " not found! " << endl ; 
755     abort() ;
756   }
757 }
758
759 //____________________________________________________________________________ 
760 Bool_t AliEMCALGetter::PostClusterizer(const char * name) const 
761 { // ------------------ AliEMCALClusterizer ------------------------
762
763   // the hierarchy is //Folders/Tasks/Reconstructioner/EMCAL/sdigitsname
764   
765   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
766
767   if ( !tasks ) {
768     cerr << "ERROR: AliEMCALGetter::Post Rer -> Task//" << fTasksFolder << "/Reconstructioner not found!" << endl; 
769     return kFALSE ;
770   }        
771   
772   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
773   if ( !emcal )  {
774     if (fDebug) {
775       cout <<"WARNING: AliEMCALGetter::Post Rer -> //" << fTasksFolder << "/Reconstructioner/EMCAL not found!" << endl;
776       cout <<"INFO: AliEMCALGetter::Post Rer -> Adding //" << fTasksFolder << "/Reconstructioner/EMCAL" << endl;
777     }
778     emcal = new TTask("EMCAL", "") ; 
779     tasks->Add(emcal) ; 
780   } 
781
782   AliEMCALClusterizerv1 * emcalcl = new AliEMCALClusterizerv1() ;
783   TString clun(name) ;
784   clun+=":clu-v1" ;
785   emcalcl->SetName(clun) ;
786   emcal->Add(emcalcl) ;
787   return kTRUE; 
788   
789 }
790
791 //____________________________________________________________________________ 
792 /*Bool_t AliEMCALGetter::PostTrackSegments(const char * name) const 
793 { // ---------------TrackSegments -----------------------------------
794   
795   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/TrackSegments/name
796
797   TFolder * emcalFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL")) ; 
798   
799   if ( !emcalFolder ) {
800     if (fDebug) {
801       cout << "WARNING: AliEMCALGetter::Post TS -> Folder //" << fRecoFolder << "/EMCAL/ not found!" << endl;
802       cout << "INFO:    AliEMCALGetter::Post TS -> Adding Folder //" << fRecoFolder << "/EMCAL" << endl;
803     }
804     emcalFolder = fRecoFolder->AddFolder("EMCAL", "Reconstructed data from EMCAL") ;  
805   }    
806
807   TFolder * emcalTSFolder  = dynamic_cast<TFolder*>(emcalFolder->FindObject("TrackSegments")) ;
808   if ( !emcalTSFolder ) {
809     if (fDebug) {
810       cout << "WARNING: AliEMCALGetter::Post TS -> Folder//" << fRecoFolder << "/EMCAL/TrackSegments/ not found!" << endl; 
811       cout << "INFO:    AliEMCALGetter::Post TS -> Adding Folder //" << fRecoFolder << "/EMCAL/TrackSegments/" << endl; 
812     }
813     emcalTSFolder = emcalFolder->AddFolder("TrackSegments", "TrackSegments from EMCAL") ;  
814   }    
815   
816   TObject * tss =  emcalTSFolder->FindObject( name ) ;
817   if (!tss) {
818     TClonesArray * ts = new TClonesArray("AliEMCALTrackSegment",100) ;
819     ts->SetName(name) ;
820     emcalTSFolder->Add(ts) ;  
821   }
822   return kTRUE; 
823
824
825 //____________________________________________________________________________ 
826 TObject ** AliEMCALGetter::TrackSegmentsRef(const char * name) const 
827 { // ---------------TrackSegments -----------------------------------
828   
829   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/TrackSegments/name
830
831  if ( !fRecoFolder ) {
832     cerr << "ERROR: AliEMCALGetter::TrackSegmentsRef -> Folder //" << fRecoFolder << "not found!" << endl;
833     abort() ; 
834   }    
835
836   TFolder * emcalFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/TrackSegments")) ; 
837   if ( !emcalFolder ) {
838     cerr << "ERROR: AliEMCALGetter::TrackSegmentsRef -> Folder //" << fRecoFolder << "/EMCAL/TrackSegments/ not found!" << endl;
839     abort();
840   }    
841   
842   TObject * tss =  emcalFolder->FindObject(name) ;
843   if (!tss) {
844     cerr << "ERROR: AliEMCALGetter::TrackSegmentsRef -> object " << name << " not found! " << endl ;  
845     abort() ;  
846   }
847   return emcalFolder->GetListOfFolders()->GetObjectRef(tss) ;
848
849
850 //____________________________________________________________________________ 
851 Bool_t AliEMCALGetter::PostTrackSegmentMaker(AliEMCALTrackSegmentMaker * tsmaker) const 
852 { //------------Track Segment Maker ------------------------------
853   
854   // the hierarchy is //Folders/Tasks/Reconstructioner/EMCAL/sdigitsname
855
856   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
857
858   if ( !tasks ) {
859     cerr << "ERROR: AliEMCALGetter::Post Ter -> Task //" << fTasksFolder << "/Reconstructioner not found!" << endl;
860     return kFALSE ;
861   }        
862         
863   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
864   if ( !emcal )  {
865     if (fDebug) {
866       cout <<"WARNING: AliEMCALGetter::Post Rer -> //" << fTasksFolder << "/Reconstructioner/EMCAL not found!" << endl; 
867       cout <<"INFO: AliEMCALGetter::Post Rer -> Adding //" << fTasksFolder << "/Reconstructioner/EMCAL" << endl;
868     }
869     emcal = new TTask("EMCAL", "") ; 
870     tasks->Add(emcal) ; 
871   } 
872
873   AliEMCALTrackSegmentMaker * emcalts = 
874     dynamic_cast<AliEMCALTrackSegmentMaker*>(emcal->GetListOfTasks()->FindObject(tsmaker->GetName())) ; 
875   if (emcalts) { 
876     emcalts->Delete() ;
877     emcal->GetListOfTasks()->Remove(emcalts) ;
878   }
879   emcal->Add(tsmaker) ;      
880   return kTRUE; 
881   
882
883 //____________________________________________________________________________ 
884 Bool_t AliEMCALGetter::PostTrackSegmentMaker(const char * name) const 
885 { //------------Track Segment Maker ------------------------------
886   
887   // the hierarchy is //Folders/Tasks/Reconstructioner/EMCAL/sdigitsname
888   
889   
890   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
891   
892   if ( !tasks ) {
893     cerr << "ERROR: AliEMCALGetter::Post Ter -> Task //" << fTasksFolder << "/Reconstructioner not found!" << endl;
894     return kFALSE ;
895   }        
896   
897   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
898   if ( !emcal )  {
899     if (fDebug) {
900       cout <<"WARNING: AliEMCALGetter::Post Rer -> //" << fTasksFolder << "/Reconstructioner/EMCAL not found!" << endl; 
901       cout <<"INFO: AliEMCALGetter::Post Rer -> Adding //" << fTasksFolder << "/Reconstructioner/EMCAL" << endl;
902     }
903     emcal = new TTask("EMCAL", "") ; 
904     tasks->Add(emcal) ; 
905   } 
906
907   AliEMCALTrackSegmentMaker * emcalts = 
908     dynamic_cast<AliEMCALTrackSegmentMaker*>(emcal->GetListOfTasks()->FindObject(name)) ; 
909   if (!emcalts) { 
910     emcalts = new AliEMCALTrackSegmentMakerv1() ;
911     TString tsn(name);
912     tsn+=":tsm-v1" ;
913     emcalts->SetName(tsn) ;
914     emcal->Add(emcalts) ;      
915   }
916   return kTRUE; 
917   
918
919
920 //____________________________________________________________________________ 
921 TObject ** AliEMCALGetter::TSMakerRef(const char * name) const 
922 { //------------Track Segment Maker ------------------------------
923   
924   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
925
926   if ( !tasks ) {
927     cerr << "ERROR: AliEMCALGetter::TSLakerRef TerRef -> Task //" << fTasksFolder << "/Reconstructioner not found!" << endl;
928     abort() ;
929   }        
930         
931   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
932   if ( !emcal )  {
933     cerr <<"WARNING: AliEMCALGetter::TSMakerRef TerRef -> //" << fTasksFolder << "/Reconstructioner/EMCAL not found!" << endl; 
934     abort() ; 
935   }   
936
937   TList * l = emcal->GetListOfTasks() ; 
938   TIter it(l) ;
939   TTask * task ;
940   TTask * tsm = 0 ;
941   TString tsmname(name) ;
942   tsmname+=":tsm-" ;
943   while((task = static_cast<TTask *>(it.Next()) )){
944     TString taskname(task->GetName()) ;
945     if(taskname.BeginsWith(tsmname)){
946       tsm = task ;
947       break ;
948     }
949   }
950   
951   if(tsm) 
952     return l->GetObjectRef(tsm) ;
953   else {
954     cerr << "ERROR: AliEMCALGetter::TSLakerRef -> task " << task->GetName() << " not found! " << endl ; 
955     abort() ;
956   }
957
958
959 //____________________________________________________________________________ 
960 Bool_t AliEMCALGetter::PostRecParticles(const char * name) const 
961 {  // -------------------- RecParticles ------------------------
962   
963   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/TrackSegments/name
964
965   TFolder * emcalFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL")) ; 
966   
967   if ( !emcalFolder ) {
968     if (fDebug) {
969       cout << "WARNING: AliEMCALGetter::Post RPa -> Folder //" << fRecoFolder << "/EMCAL/ not found!" << endl;
970       cout << "INFO:    AliEMCALGetter::Post Rpa -> Adding Folder //" << fRecoFolder << "/EMCAL/" << endl;
971     }
972     emcalFolder = fRecoFolder->AddFolder("EMCAL", "Reconstructed data from EMCAL") ;  
973   }    
974
975  TFolder * emcalRPaFolder  = dynamic_cast<TFolder*>(emcalFolder->FindObject("RecParticles")) ;
976   if ( !emcalRPaFolder ) {
977     if (fDebug) {
978       cout << "WARNING: AliEMCALGetter::Post RPa -> Folder //" << fRecoFolder << "/EMCAL/RecParticles/ not found!" << endl;
979       cout << "INFO:    AliEMCALGetter::Post RPa -> Adding Folder //" << fRecoFolder << "/EMCAL/RecParticles/" << endl;
980     }
981     emcalRPaFolder = emcalFolder->AddFolder("RecParticles", "RecParticles from EMCAL") ;  
982   } 
983
984   TObject * rps = emcalRPaFolder->FindObject( name )  ;
985   if ( !rps ) {
986     TClonesArray * rp = new TClonesArray("AliEMCALRecParticle",100) ;
987     rp->SetName(name) ;    
988     emcalRPaFolder->Add(rp) ;  
989   }
990   return kTRUE; 
991
992
993 //____________________________________________________________________________ 
994 TObject ** AliEMCALGetter::RecParticlesRef(const char * name) const 
995 { // ---------------TrackSegments -----------------------------------
996   
997   // the hierarchy is //Folders/Run/Event/RecData/EMCAL/TrackSegments/name
998
999  if ( !fRecoFolder ) {
1000     cerr << "ERROR: AliEMCALGetter::RecParticlesRef -> Folder//" << fRecoFolder << " not found!" << endl; 
1001     abort() ; 
1002   }    
1003
1004   TFolder * emcalFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("EMCAL/RecParticles")) ; 
1005   if ( !emcalFolder ) {
1006     cerr << "ERROR: AliEMCALGetter::RecParticlesRef -> Folder //" << fRecoFolder << "/EMCAL/RecParticles/ not found!" << endl;
1007     abort() ;
1008   }    
1009
1010   TObject * tss =  emcalFolder->FindObject(name) ;
1011   if (!tss) {
1012     cerr << "ERROR: AliEMCALGetter::RecParticlesRef -> object " << name << " not found! " << endl ; 
1013     abort() ;  
1014   }
1015   return emcalFolder->GetListOfFolders()->GetObjectRef(tss) ;
1016 }
1017
1018 //____________________________________________________________________________ 
1019 Bool_t AliEMCALGetter::PostPID(AliEMCALPID * pid) const 
1020 {      // ------------AliEMCAL PID -----------------------------
1021
1022   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
1023
1024   if ( !tasks ) {
1025     cerr << "ERROR: AliEMCALGetter::Post Per -> Task //" << fTasksFolder << "/Reconstructioner not found!" << endl;
1026     return kFALSE ;
1027   }        
1028   
1029   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
1030   if ( !emcal )  {
1031     if (fDebug) {
1032       cout <<"WARNING: AliEMCALGetter::Post Per -> //" << fTasksFolder << "/Reconstructioner/EMCAL not found!" << endl; 
1033       cout <<"INFO: AliEMCALGetter::Post Per -> Adding //" << fTasksFolder << "/Reconstructioner/EMCAL" << endl;
1034     }
1035     emcal = new TTask("EMCAL", "") ; 
1036     tasks->Add(emcal) ; 
1037   } 
1038
1039   AliEMCALPID * emcalpid = dynamic_cast<AliEMCALPID*>(emcal->GetListOfTasks()->FindObject(pid->GetName())) ; 
1040   if (emcalpid) { 
1041     if (fDebug)
1042       cout << "INFO: AliEMCALGetter::Post Per -> Task " << pid->GetName()
1043            << " already exists" << endl ; 
1044     emcal->GetListOfTasks()->Remove(emcalpid) ;
1045   }
1046   
1047   emcal->Add(pid) ;      
1048   return kTRUE; 
1049
1050
1051 //____________________________________________________________________________ 
1052 Bool_t AliEMCALGetter::PostPID(const char * name) const 
1053 {     
1054   // the hierarchy is //Folders/Tasks/Reconstructioner/EMCAL/sdigitsname
1055   
1056   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
1057
1058   if ( !tasks ) {
1059     cerr << "ERROR: AliEMCALGetter::Post Per -> Task //" << fTasksFolder << "/Reconstructioner not found!" << endl;
1060     return kFALSE ;
1061   }        
1062   
1063   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
1064   if ( !emcal )  {
1065     if (fDebug) {
1066       cout <<"WARNING: AliEMCALGetter::Post Per -> //" << fTasksFolder << "/Reconstructioner/EMCAL not found!" << endl; 
1067       cout <<"INFO: AliEMCALGetter::Post Per -> Adding //" << fTasksFolder << "/Reconstructioner/EMCAL" << endl;
1068     }
1069     emcal = new TTask("EMCAL", "") ; 
1070     tasks->Add(emcal) ; 
1071   } 
1072
1073   TList * l = emcal->GetListOfTasks() ;   
1074   TIter it(l) ;
1075   TString pidname(name) ;
1076   pidname+=":pid" ; 
1077   TTask * task ;
1078   while((task = static_cast<TTask *>(it.Next()) )){
1079     TString taskname(task->GetName()) ;
1080     if(taskname.BeginsWith(pidname))
1081       return kTRUE ;
1082   }
1083  
1084   AliEMCALPIDv1 * emcalpid = new AliEMCALPIDv1() ;
1085   pidname+="-v1" ;
1086   emcalpid->SetName(pidname) ;
1087   emcal->Add(emcalpid) ;      
1088   
1089   return kTRUE; 
1090
1091
1092 //____________________________________________________________________________ 
1093 TObject ** AliEMCALGetter::PIDRef(const char * name) const 
1094 { //------------PID ------------------------------
1095
1096   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
1097
1098   if ( !tasks ) {
1099     cerr << "ERROR: AliEMCALGetter::PIDRef PerRef -> Task //" << fTasksFolder << "/Reconstructioner not found!" << endl;
1100     abort() ;
1101   }        
1102         
1103   TTask * emcal = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
1104   if ( !emcal )  {
1105     cerr <<"WARNING: AliEMCALGetter::PIDRef PerRef -> //" << fTasksFolder << "/ReconstructionerEMCAL not found!" << endl; 
1106     abort() ; 
1107   }   
1108   
1109   TList * l = emcal->GetListOfTasks() ; 
1110   TIter it(l) ;
1111   TTask * task ;
1112   TTask * pid = 0 ;
1113   TString pidname(name) ;
1114   pidname+=":pid-" ;
1115   while((task = static_cast<TTask *>(it.Next()) )){
1116     TString taskname(task->GetName()) ;
1117     if(taskname.BeginsWith(pidname)){
1118       pid = task ;
1119       break ;
1120     }
1121   }
1122   
1123   if(pid) 
1124     return l->GetObjectRef(pid) ;
1125   else {
1126     cerr << "ERROR: AliEMCALGetter::PIDRef -> task " << task->GetName() << " not found! " << endl ;  
1127     abort() ;
1128   }
1129
1130
1131 //____________________________________________________________________________ 
1132 Bool_t AliEMCALGetter::PostQA(void) const 
1133 { // ------------------ QA ---------------------------------
1134
1135   // the hierarchy is //Folders/Run/Conditions/QA/EMCAL/alarmsName
1136
1137   TFolder * emcalFolder = dynamic_cast<TFolder*>(fQAFolder->FindObject("EMCAL")) ; 
1138   if ( !emcalFolder ) {
1139     if (fDebug) {
1140       cout << "WARNING: AliEMCALGetter::Post Q -> Folder //" << fQAFolder << "/EMCAL/ not found!" << endl;
1141       cout << "INFO:    AliEMCALGetter::Post Q -> Adding Folder //" << fQAFolder << "/EMCAL/" << endl;
1142     }
1143     emcalFolder = fQAFolder->AddFolder("EMCAL", "QA from EMCAL") ; 
1144   }      
1145
1146   return kTRUE;
1147 }
1148
1149 //____________________________________________________________________________ 
1150 TObject ** AliEMCALGetter::AlarmsRef(void) const 
1151 {  //------- Alarms ----------------------
1152
1153   
1154   // the hierarchy is //Folders/Run/Conditions/QA/EMCAL
1155   if ( !fQAFolder ) {
1156     cerr << "ERROR: AliEMCALGetter::AlarmsRef QRef -> Folder //" << fQAFolder << " not found!" << endl;
1157     abort() ;
1158   }    
1159  
1160   TFolder * emcalFolder = dynamic_cast<TFolder *>(fQAFolder->FindObject("EMCAL")) ;
1161   if ( !emcalFolder ) {
1162     cerr << "ERROR: AliEMCALGetter::AlarmsRef QRef -> Folder //" << fQAFolder << "/EMCAL/ not found!" << endl;
1163     abort() ;
1164   }
1165    
1166   return fQAFolder->GetListOfFolders()->GetObjectRef(emcalFolder) ;
1167 }
1168 */
1169 //____________________________________________________________________________ 
1170 const TParticle * AliEMCALGetter::Primary(Int_t index) const
1171 {
1172   // Return primary particle numbered by <index>
1173   
1174   if(index < 0) 
1175     return 0 ;
1176   
1177   Int_t primaryIndex = index % 10000000 ; 
1178   Int_t primaryList = (Int_t ) ((index-primaryIndex)/10000000.)  ;
1179   
1180   if ( primaryList > 0  ) {
1181     if (fDebug) {
1182       cout << " Getter does not support currently Mixing of primary " << endl ;
1183       cout << "   can not return primary: " << index<< " (list "<< primaryList<< " primary # " << primaryIndex << " )"<<endl ;
1184     }
1185     return 0;
1186   }
1187   
1188   return gAlice->Particle(primaryIndex) ;
1189   
1190 }
1191
1192 //____________________________________________________________________________ 
1193 void AliEMCALGetter::ReadTreeD()
1194 {
1195   // Read the digit tree gAlice->TreeD()  
1196   if(gAlice->TreeD()== 0){
1197     cerr <<   "ERROR: AliEMCALGetter::ReadTreeD: can not read TreeD " << endl ;
1198   return ;
1199   }
1200   
1201   TObjArray * lob = static_cast<TObjArray*>(gAlice->TreeD()->GetListOfBranches()) ;
1202   TIter next(lob) ; 
1203   TBranch * branch = 0 ; 
1204   TBranch * digitsbranch = 0 ; 
1205   TBranch * digitizerbranch = 0 ; 
1206   Bool_t emcalfound = kFALSE, digitizerfound = kFALSE ; 
1207   
1208   while ( (branch = static_cast<TBranch*>(next())) && (!emcalfound || !digitizerfound) ) {
1209     if ( (strcmp(branch->GetName(), "EMCAL")==0) && (strcmp(branch->GetTitle(), fDigitsTitle)==0) ) {
1210       digitsbranch = branch ; 
1211       emcalfound = kTRUE ;
1212     }
1213     else if ( (strcmp(branch->GetName(), "AliEMCALDigitizer")==0) && (strcmp(branch->GetTitle(), fDigitsTitle)==0) ) {
1214       digitizerbranch = branch ; 
1215       digitizerfound = kTRUE ; 
1216     }
1217   }
1218
1219   if ( !emcalfound || !digitizerfound ) {
1220     if (fDebug)
1221       cout << "WARNING: AliEMCALGetter::ReadTreeD -> Cannot find Digits and/or Digitizer with name " 
1222            << fDigitsTitle << endl ;
1223     return ; 
1224   }   
1225  
1226   //read digits
1227   if(!Digits(fDigitsTitle) ) 
1228     PostDigits(fDigitsTitle);
1229   digitsbranch->SetAddress(DigitsRef(fDigitsTitle)) ;
1230   digitsbranch->GetEntry(0) ;
1231   
1232   
1233   // read  the Digitizer
1234   if(!Digitizer(fDigitsTitle))
1235     PostDigitizer(fDigitsTitle) ;
1236   digitizerbranch->SetAddress(DigitizerRef(fDigitsTitle)) ;
1237   digitizerbranch->GetEntry(0) ;
1238  
1239   
1240 }
1241
1242 //____________________________________________________________________________ 
1243 void AliEMCALGetter::ReadTreeH()
1244 {
1245   // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
1246
1247   if(gAlice->TreeH()== 0){
1248     cerr <<   "ERROR: AliEMCALGetter::ReadTreeH: -> Cannot read TreeH " << endl ;
1249     return ;
1250   }
1251   
1252   TBranch * hitsbranch = static_cast<TBranch*>(gAlice->TreeH()->GetBranch("EMCAL")) ;
1253   if ( !hitsbranch ) {
1254     if (fDebug)
1255       cout << "WARNING:  AliEMCALGetter::ReadTreeH -> Cannot find branch EMCAL" << endl ; 
1256     return ;
1257   }
1258   if(!Hits())
1259     PostHits() ;
1260  
1261   if (hitsbranch->GetEntries() > 1 ) {
1262     TClonesArray * tempo =  new TClonesArray("AliEMCALHit",1000) ;
1263     TClonesArray * hits = dynamic_cast<TClonesArray*>(*HitsRef()) ; 
1264     hitsbranch->SetAddress(&tempo) ;
1265     Int_t index = 0 ; 
1266     Int_t i = 0 ;
1267     for (i = 0 ; i < hitsbranch->GetEntries() ; i++) {
1268       hitsbranch->GetEntry(i) ;
1269       Int_t j = 0 ; 
1270       for ( j = 0 ; j < tempo->GetEntries() ; j++) { 
1271         const AliEMCALHit * hit = static_cast<const AliEMCALHit *>(tempo->At(j)) ; 
1272         new((*hits)[index]) AliEMCALHit( *hit ) ;
1273         index++ ; 
1274       }
1275     }
1276     delete tempo ; 
1277   }
1278   else {
1279   hitsbranch->SetAddress(HitsRef()) ;
1280   hitsbranch->GetEntry(0) ;
1281   }
1282 }
1283
1284 //____________________________________________________________________________ 
1285 void AliEMCALGetter::Track(Int_t itrack)
1286 {
1287   // Read the first entry of EMCAL branch in hit tree gAlice->TreeH()
1288
1289   if(gAlice->TreeH()== 0){
1290     cerr <<   "ERROR: AliEMCALGetter::ReadTreeH: -> Cannot read TreeH " << endl ;
1291     return ;
1292   }
1293   
1294   TBranch * hitsbranch = dynamic_cast<TBranch*>(gAlice->TreeH()->GetListOfBranches()->FindObject("EMCAL")) ;
1295   if ( !hitsbranch ) {
1296     if (fDebug)
1297       cout << "WARNING:  AliEMCALGetter::ReadTreeH -> Cannot find branch EMCAL" << endl ; 
1298     return ;
1299   }  
1300   if(!Hits())
1301     PostHits() ;
1302   hitsbranch->SetAddress(HitsRef()) ;
1303   hitsbranch->GetEntry(itrack) ;
1304
1305   
1306 }
1307 //____________________________________________________________________________ 
1308 // void AliEMCALGetter::ReadTreeQA()
1309 //{
1310   // Read the digit tree gAlice->TreeQA()
1311   // so far only EMCAL knows about this Tree  
1312
1313 //   if(EMCAL()->TreeQA()== 0){
1314 //     cerr <<   "ERROR: AliEMCALGetter::ReadTreeQA: can not read TreeQA " << endl ;
1315 //     return ;
1316 //   }
1317   
1318 //   TBranch * qabranch = EMCAL()->TreeQA()->GetBranch("EMCAL") ; 
1319 //   if (!qabranch) { 
1320 //     if (fDebug)
1321 //       cout << "WARNING: AliEMCALGetter::ReadTreeQA -> Cannot find QA Alarms for EMCAL" << endl ;
1322 //     return ; 
1323 //   }   
1324   
1325 //   if(!Alarms())
1326 //     PostQA() ; 
1327
1328 //   qabranch->SetAddress(AlarmsRef()) ;
1329
1330 //   qabranch->GetEntry(0) ;
1331  
1332 //   PostQA("EMCAL") ; 
1333 //   TFolder * alarmsF = Alarms() ; 
1334 //   alarmsF->Clear() ; 
1335 //   qabranch->SetAddress(&alarmsF) ;
1336 //   qabranch->GetEntry(0) ;
1337   
1338 //}
1339   
1340 //____________________________________________________________________________ 
1341 void AliEMCALGetter::ReadTreeR()
1342 {
1343       // Read the reconstrunction tree gAlice->TreeR()
1344
1345   if(gAlice->TreeR()== 0){
1346     cerr <<   "ERROR: AliEMCALGetter::ReadTreeR: can not read TreeR " << endl ;
1347     return ;
1348   }
1349   
1350   // RecPoints 
1351   TObjArray * lob = static_cast<TObjArray*>(gAlice->TreeR()->GetListOfBranches()) ;
1352   TIter next(lob) ; 
1353   TBranch * branch = 0 ; 
1354   TBranch * towerbranch = 0 ; 
1355   TBranch * preshobranch = 0 ; 
1356   TBranch * clusterizerbranch = 0 ; 
1357   Bool_t emcaltowerrpfound = kFALSE, emcalpreshorpfound = kFALSE, clusterizerfound = kFALSE ; 
1358   
1359   while ( (branch = static_cast<TBranch*>(next())) && (!emcaltowerrpfound || !emcalpreshorpfound || !clusterizerfound) ) 
1360     if(strcmp(branch->GetTitle(), fRecPointsTitle)==0) {
1361       if ( strcmp(branch->GetName(), "EMCALTowerRP")==0) {
1362         towerbranch = branch ; 
1363         emcaltowerrpfound = kTRUE ;
1364       }
1365       else if ( strcmp(branch->GetName(), "EMCALPreShoRP")==0) {
1366         preshobranch = branch ; 
1367         emcalpreshorpfound = kTRUE ;
1368       }
1369       else if(strcmp(branch->GetName(), "AliEMCALClusterizer")==0){
1370         clusterizerbranch = branch ; 
1371         clusterizerfound = kTRUE ; 
1372       }
1373     }
1374
1375   if ( !emcaltowerrpfound ) {
1376     if (fDebug)
1377       cout << "WARNING: AliEMCALGetter::ReadTreeR -> Cannot find TowerRecPoints with title " 
1378            << fRecPointsTitle << endl ;
1379     return ; 
1380   }   
1381   if ( !emcalpreshorpfound ) {
1382     if (fDebug)
1383       cout << "WARNING: AliEMCALGetter::ReadTreeR -> Cannot find PreShoRecPoints with title " 
1384            << fRecPointsTitle << endl ;
1385     return ; 
1386   }   
1387   if ( !clusterizerfound ) {
1388     if (fDebug)
1389       cout << "WARNING: AliEMCALGetter::ReadTreeR -> Can not find Clusterizer with title " 
1390            << fRecPointsTitle << endl ;
1391     return ; 
1392   }   
1393   
1394   // Read and Post the RecPoints
1395   if(!TowerRecPoints(fRecPointsTitle) )
1396     PostRecPoints(fRecPointsTitle) ;
1397   towerbranch->SetAddress(TowerRecPointsRef(fRecPointsTitle)) ;
1398   towerbranch->GetEntry(0) ;
1399
1400   preshobranch->SetAddress(PreShoRecPointsRef(fRecPointsTitle)) ;
1401   preshobranch->GetEntry(0) ;
1402   
1403   if(!Clusterizer(fRecPointsTitle) )
1404     PostClusterizer(fRecPointsTitle) ;
1405   clusterizerbranch->SetAddress(ClusterizerRef(fRecPointsTitle)) ;
1406   clusterizerbranch->GetEntry(0) ;
1407  
1408   
1409   //------------------- TrackSegments ---------------------
1410 //   next.Reset() ; 
1411 //   TBranch * tsbranch = 0 ; 
1412 //   TBranch * tsmakerbranch = 0 ; 
1413 //   Bool_t emcaltsfound = kFALSE, tsmakerfound = kFALSE ; 
1414     
1415 //   while ( (branch = static_cast<TBranch*>(next())) && (!emcaltsfound || !tsmakerfound) ) 
1416 //     if(strcmp(branch->GetTitle(), fTrackSegmentsTitle)==0)  {
1417 //       if ( strcmp(branch->GetName(), "EMCALTS")==0){
1418 //      tsbranch = branch ; 
1419 //      emcaltsfound = kTRUE ;
1420 //       }
1421 //       else if(strcmp(branch->GetName(), "AliEMCALTrackSegmentMaker")==0) {
1422 //      tsmakerbranch = branch ; 
1423 //      tsmakerfound  = kTRUE ; 
1424 //       }
1425 //     }
1426   
1427 //   if ( !emcaltsfound || !tsmakerfound ) {
1428 //     if (fDebug)
1429 //       cout << "WARNING: AliEMCALGetter::ReadTreeR -> Cannot find TrackSegments and/or TrackSegmentMaker with name "
1430 //         << fTrackSegmentsTitle << endl ;
1431 //     return ; 
1432 //   } 
1433   
1434 //   // Read and Post the TrackSegments
1435 //   if(!TrackSegments(fTrackSegmentsTitle))
1436 //     PostTrackSegments(fTrackSegmentsTitle) ;
1437 //   tsbranch->SetAddress(TrackSegmentsRef(fTrackSegmentsTitle)) ;
1438 //   tsbranch->GetEntry(0) ;
1439   
1440 //   // Read and Post the TrackSegment Maker
1441 //   if(!TrackSegmentMaker(fTrackSegmentsTitle))
1442 //     PostTrackSegmentMaker(fTrackSegmentsTitle) ;
1443 //   tsmakerbranch->SetAddress(TSMakerRef(fTrackSegmentsTitle)) ;
1444 //   tsmakerbranch->GetEntry(0) ;
1445   
1446   
1447 //   //------------ RecParticles ----------------------------
1448 //   next.Reset() ; 
1449 //   TBranch * rpabranch = 0 ; 
1450 //   TBranch * pidbranch = 0 ; 
1451 //   Bool_t emcalrpafound = kFALSE, pidfound = kFALSE ; 
1452   
1453 //   while ( (branch = static_cast<TBranch*>(next())) && (!emcalrpafound || !pidfound) ) 
1454 //     if(strcmp(branch->GetTitle(), fRecParticlesTitle)==0) {   
1455 //       if ( strcmp(branch->GetName(), "EMCALRP")==0) {   
1456 //      rpabranch = branch ; 
1457 //      emcalrpafound = kTRUE ;
1458 //       }
1459 //       else if (strcmp(branch->GetName(), "AliEMCALPID")==0) {
1460 //      pidbranch = branch ; 
1461 //      pidfound  = kTRUE ; 
1462 //       }
1463 //     }
1464   
1465 //   if ( !emcalrpafound || !pidfound ) {
1466 //     if (fDebug)
1467 //       cout << "WARNING: AliEMCALGetter::ReadTreeR -> Cannot find RecParticles and/or PID with name " 
1468 //         << fRecParticlesTitle << endl ;
1469 //     return ; 
1470 //   } 
1471   
1472 //   // Read and Post the RecParticles
1473 //   if(!RecParticles(fRecParticlesTitle))
1474 //     PostRecParticles(fRecParticlesTitle) ;
1475 //   rpabranch->SetAddress(RecParticlesRef(fRecParticlesTitle)) ;
1476 //   rpabranch->GetEntry(0) ;
1477   
1478 //   // Read and Post the PID
1479 //   if(!PID(fRecParticlesTitle))
1480 //     PostPID(fRecParticlesTitle) ;
1481 //   pidbranch->SetAddress(PIDRef(fRecParticlesTitle)) ;
1482 //   pidbranch->GetEntry(0) ;
1483   
1484   
1485 }
1486
1487 //____________________________________________________________________________ 
1488 void AliEMCALGetter::ReadTreeS(Int_t event)
1489 {
1490   // Read the summable digits tree gAlice->TreeS()  
1491   
1492   // loop over all opened files and read their SDigits to the White Board
1493   TFolder * emcalF = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject("EMCAL")) ;
1494   if (!emcalF) 
1495     emcalF = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ; 
1496   TCollection * folderslist = emcalF->GetListOfFolders() ; 
1497   
1498   //Add current file to list if it is not there yet
1499
1500   TString subdir(fHeaderFile) ;
1501   subdir.ReplaceAll("/","_") ; 
1502
1503   if ( (subdir != "aliroot") && ( !folderslist->Contains(subdir) ) ){
1504     emcalF->AddFolder(subdir, ""); 
1505   }
1506
1507   TIter next(folderslist) ; 
1508   TFolder * folder = 0 ; 
1509   TFile * file; 
1510   TTree * treeS = 0;
1511   while ( (folder = static_cast<TFolder*>(next())) ) {
1512    TString fileName(folder->GetName()) ; 
1513    fileName.ReplaceAll("_","/") ; 
1514    if(fHeaderFile.CompareTo(fileName) == 0 ) 
1515       treeS=gAlice->TreeS() ;
1516     else{
1517       file = static_cast<TFile*>(gROOT->GetFile(fileName)); 
1518       file->cd() ;
1519       
1520       // Get SDigits Tree header from file
1521       TString treeName("TreeS") ;
1522       treeName += event ; 
1523       treeS = dynamic_cast<TTree*>(gDirectory->Get(treeName.Data()));
1524     }
1525     if(treeS==0){
1526       cerr << "ERROR: AliEMCALGetter::ReadTreeS There is no SDigit Tree" << endl;
1527       return ;
1528     }
1529    
1530     //set address of the SDigits and SDigitizer
1531     TBranch   * sdigitsBranch    = 0;
1532     TBranch   * sdigitizerBranch = 0;
1533     TBranch   * branch           = 0 ;  
1534     TObjArray * lob = static_cast<TObjArray*>(treeS->GetListOfBranches()) ;
1535     TIter next(lob) ; 
1536     Bool_t emcalfound = kFALSE, sdigitizerfound = kFALSE ; 
1537     
1538     while ( (branch = static_cast<TBranch*>(next())) && (!emcalfound || !sdigitizerfound) ) {
1539       if ( (strcmp(branch->GetName(), "EMCAL")==0) && (strcmp(branch->GetTitle(), fSDigitsTitle)==0) ) {
1540         emcalfound = kTRUE ;
1541         sdigitsBranch = branch ; 
1542       }
1543       
1544       else if ( (strcmp(branch->GetName(), "AliEMCALSDigitizer")==0) && (strcmp(branch->GetTitle(), fSDigitsTitle)==0) ) {
1545         sdigitizerfound = kTRUE ; 
1546         sdigitizerBranch = branch ;
1547       }
1548     }
1549     if ( !emcalfound || !sdigitizerfound ) {
1550       if (fDebug)
1551         cout << "WARNING: AliEMCALGetter::ReadSDigits -> Digits and/or Digitizer branch with name " <<  fSDigitsTitle
1552              << " not found" << endl ;
1553       return ; 
1554     }   
1555     
1556     if ( !folder->FindObject(fSDigitsTitle) )  
1557       PostSDigits(fSDigitsTitle,folder->GetName()) ;
1558     sdigitsBranch->SetAddress(SDigitsRef(fSDigitsTitle,folder->GetName())) ;
1559     sdigitsBranch->GetEntry(0) ;
1560     
1561     TString sdname(fSDigitsTitle) ;
1562     sdname+=":" ;
1563     sdname+=folder->GetName() ;
1564     if(!SDigitizer(sdname) ) 
1565       PostSDigitizer(fSDigitsTitle,folder->GetName()) ;
1566     sdigitizerBranch->SetAddress(SDigitizerRef(sdname)) ;
1567     sdigitizerBranch->GetEntry(0) ;
1568     
1569   }    
1570   
1571   // After SDigits have been read from all files, return to the first one
1572   
1573   next.Reset();
1574   folder = static_cast<TFolder*>(next());
1575   if(folder){
1576     TString fileName(folder->GetName()) ; 
1577     fileName.ReplaceAll("_","/") ; 
1578     file   = static_cast<TFile*>(gROOT->GetFile(fileName)); 
1579     file   ->cd() ;
1580   }
1581   
1582 }
1583 //____________________________________________________________________________ 
1584 void AliEMCALGetter::ReadTreeS(TTree * treeS, Int_t input)
1585 {  // Read the summable digits fron treeS()  
1586
1587
1588   TString filename("mergefile") ;
1589   filename+= input ;
1590
1591   TFolder * emcalFolder = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("EMCAL")) ; 
1592   if ( !emcalFolder ) { 
1593    emcalFolder = fSDigitsFolder->AddFolder("EMCAL", "SDigits from EMCAL") ; 
1594   } 
1595   TFolder * folder=(TFolder*)emcalFolder->FindObject(filename) ;
1596   //set address of the SDigits and SDigitizer
1597   TBranch   * sdigitsBranch    = 0;
1598   TBranch   * sdigitizerBranch = 0;
1599   TBranch   * branch           = 0 ;  
1600   TObjArray * lob = (TObjArray*)treeS->GetListOfBranches() ;
1601   TIter next(lob) ; 
1602   Bool_t emcalfound = kFALSE, sdigitizerfound = kFALSE ; 
1603   
1604   while ( (branch = (TBranch*)next()) && (!emcalfound || !sdigitizerfound) ) {
1605     if ( strcmp(branch->GetName(), "EMCAL")==0) {
1606       emcalfound = kTRUE ;
1607       sdigitsBranch = branch ; 
1608     }
1609     
1610     else if ( strcmp(branch->GetName(), "AliEMCALSDigitizer")==0) {
1611       sdigitizerfound = kTRUE ; 
1612       sdigitizerBranch = branch ;
1613     }
1614   }
1615   if ( !emcalfound || !sdigitizerfound ) {
1616     if (fDebug)
1617       cout << "WARNING: AliEMCALGetter::ReadTreeS -> Digits and/or Digitizer branch not found" << endl ;
1618     return ; 
1619   }   
1620   
1621   if (!folder || !(folder->FindObject(sdigitsBranch->GetTitle()) ) )
1622     PostSDigits(sdigitsBranch->GetTitle(),filename) ;
1623
1624   sdigitsBranch->SetAddress(SDigitsRef(sdigitsBranch->GetTitle(),filename)) ;
1625   sdigitsBranch->GetEntry(0) ;
1626   
1627   TString sdname(sdigitsBranch->GetTitle()) ;
1628   sdname+=":" ;
1629   sdname+=filename ;
1630   if(!SDigitizer(sdigitsBranch->GetTitle()) )
1631     PostSDigitizer(sdigitsBranch->GetTitle(),filename) ;
1632
1633   sdigitizerBranch->SetAddress(SDigitizerRef(sdname)) ;
1634   sdigitizerBranch->GetEntry(0) ;
1635   
1636 }    
1637
1638
1639 //____________________________________________________________________________ 
1640 void AliEMCALGetter::ReadPrimaries()
1641 {
1642   // Reads specific branches of primaries
1643   
1644   fNPrimaries = gAlice->GetNtrack();
1645   
1646   //   //Check, is it necessary to open new files
1647   //   TArrayI* events = fDigitizer->GetCurrentEvents() ; 
1648   //   TClonesArray * filenames = fDigitizer->GetHeadersFiles() ;
1649 //   Int_t input ;
1650 //   for(input = 0; input < filenames->GetEntriesFast(); input++){
1651
1652 //     TObjString * filename = (TObjString *) filenames->At(input) ;
1653
1654 //     //Test, if this file already open
1655 //     TFile *file = (TFile*) gROOT->GetFile( filename->GetString() ) ;
1656 //     if(file == 0)
1657 //       file = new TFile( filename->GetString()) ;
1658 //     file->cd() ;
1659     
1660 //     // Get Kine Tree from file
1661 // //     char treeName[20];
1662 // //     sprintf(treeName,"TreeK%d",events->At(input));
1663 // //     TTree * treeK = (TTree*)gDirectory->Get(treeName);
1664 // //     if (treeK) 
1665 // //       treeK->SetBranchAddress("Particles", &fParticleBuffer);
1666 // //     else    
1667 // //       cout << "AliEMCALGetter: cannot find Kine Tree for event:" << events->At(input) << endl;
1668
1669 // //     // Create the particle stack
1670 // //     if(!fParticles) fParticles = new TClonesArray("TParticle",1000);
1671 // //     // Build the pointer list
1672 // //     if(fParticleMap) {     <----
1673 // //       fParticleMap->Clear();
1674 // //       fParticleMap->Expand(treeK->GetEntries());
1675 // //     } else
1676 // //       fParticleMap = new TObjArray(treeK->GetEntries());
1677     
1678 //     // From gAlice->Particle(i) 
1679
1680
1681 // //   if(!(*fParticleMap)[i]) {
1682 // //     Int_t nentries = fParticles->GetEntries();
1683     
1684 // //     // algorithmic way of getting entry index
1685 // //     // (primary particles are filled after secondaries)
1686 // //     Int_t entry;
1687 // //     if (i<fHeader.GetNprimary())
1688 // //       entry = i+fHeader.GetNsecondary();
1689 // //     else 
1690 // //       entry = i-fHeader.GetNprimary();
1691       
1692 // //     // only check the algorithmic way and give
1693 // //     // the fatal error if it is wrong
1694 // //     if (entry != fParticleFileMap[i]) {
1695 // //       Fatal("Particle",
1696 // //         "!!!! The algorithmic way is WRONG: !!!\n entry: %d map: %d",
1697 // //   entry, fParticleFileMap[i]); 
1698 // //     }  
1699       
1700 // //     fTreeK->GetEntry(fParticleFileMap[i]);
1701 // //     new ((*fParticles)[nentries]) TParticle(*fParticleBuffer);
1702 // //     fParticleMap->AddAt((*fParticles)[nentries],i);
1703 // //   }
1704 // //   return (TParticle *) (*fParticleMap)[i];
1705
1706    
1707     
1708 //   }
1709
1710
1711 //   //scan over opened files and read corresponding TreeK##
1712
1713   return ;
1714 }
1715 //____________________________________________________________________________ 
1716 void AliEMCALGetter::Event(const Int_t event, const char* opt)
1717 {
1718   // Reads the content of all Tree's S, D and R
1719   
1720   if (event >= gAlice->TreeE()->GetEntries() ) {
1721     cerr << "ERROR: AliEMCALGetter::Event -> " << event << " not found in TreeE!" << endl ; 
1722     return ; 
1723   }
1724   gAlice->GetEvent(event) ;
1725
1726   if(strstr(opt,"H") )
1727     ReadTreeH() ;
1728   
1729   if(strstr(opt,"S") )
1730     ReadTreeS(event) ;
1731
1732   if( strstr(opt,"D") )
1733     ReadTreeD() ;
1734
1735   if( strstr(opt,"R") )
1736     ReadTreeR() ;
1737
1738  // if( strstr(opt,"Q") )
1739   //  ReadTreeQA() ;
1740
1741  // if( strstr(opt,"P") || (strcmp(opt,"")==0) )
1742  //   ReadPrimaries() ;
1743
1744 }
1745
1746 //____________________________________________________________________________ 
1747 TObject * AliEMCALGetter::ReturnO(TString what, TString name, TString file) const 
1748 {
1749   // get the object named "what" from the folder
1750   // folders are named like //Folders
1751
1752   if ( file.IsNull() ) 
1753     file = fHeaderFile ; 
1754
1755   TFolder * folder = 0 ;
1756   TObject * emcalO  = 0 ; 
1757
1758   //  if ( name.IsNull() ) {
1759   if ( what.CompareTo("Hits") == 0 ) {
1760     folder = dynamic_cast<TFolder *>(fHitsFolder->FindObject("EMCAL")) ; 
1761     if (folder) 
1762       emcalO  = dynamic_cast<TObject *>(folder->FindObject("Hits")) ;  
1763   }
1764   else if ( what.CompareTo("SDigits") == 0 ) { 
1765     file.ReplaceAll("/","_") ; 
1766     TString path = "EMCAL/" + file  ; 
1767     folder = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject(path.Data())) ; 
1768     if (folder) { 
1769       if (name.IsNull())
1770         name = fSDigitsTitle ; 
1771       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
1772     }
1773   }
1774   else if ( what.CompareTo("Digits") == 0 ){
1775     folder = dynamic_cast<TFolder *>(fDigitsFolder->FindObject("EMCAL")) ; 
1776     if (folder) { 
1777       if (name.IsNull())
1778         name = fDigitsTitle ; 
1779       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
1780     } 
1781   }
1782   else if ( what.CompareTo("TowerRecPoints") == 0 ) {
1783     folder = dynamic_cast<TFolder *>(fRecoFolder->FindObject("EMCAL/TowerRecPoints")) ; 
1784     if (folder) { 
1785       if (name.IsNull())
1786         name = fRecPointsTitle ; 
1787       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
1788     } 
1789   }
1790   else if ( what.CompareTo("PreShoRecPoints") == 0 ) {
1791     folder = dynamic_cast<TFolder *>(fRecoFolder->FindObject("EMCAL/PreShoRecPoints")) ; 
1792     if (folder) { 
1793       if (name.IsNull())
1794         name = fRecPointsTitle ; 
1795       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
1796     }   
1797   }
1798   /*
1799   else if ( what.CompareTo("TrackSegments") == 0 ) {
1800     folder = dynamic_cast<TFolder *>(fRecoFolder->FindObject("EMCAL/TrackSegments")) ; 
1801     if (folder) { 
1802       if (name.IsNull())
1803         name = fTrackSegmentsTitle ; 
1804       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
1805     }   
1806   }
1807   else if ( what.CompareTo("RecParticles") == 0 ) {
1808     folder = dynamic_cast<TFolder *>(fRecoFolder->FindObject("EMCAL/RecParticles")) ; 
1809    if (folder) { 
1810       if (name.IsNull())
1811         name = fRecParticlesTitle ; 
1812       emcalO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
1813     }   
1814  }
1815   else if ( what.CompareTo("Alarms") == 0 ){ 
1816     if (name.IsNull() ) 
1817       emcalO = dynamic_cast<TObject *>(fQAFolder->FindObject("EMCAL")) ;  
1818     else {
1819       folder = dynamic_cast<TFolder *>(fQAFolder->FindObject("EMCAL")) ; 
1820       if (!folder) 
1821         emcalO = 0 ; 
1822       else 
1823         emcalO = dynamic_cast<TObject *>(folder->FindObject(name)) ;  
1824     }
1825   }
1826 */
1827   if (!emcalO) {
1828     if(fDebug)
1829       cerr << "WARNING : AliEMCALGetter::ReturnO -> Object " << what << " not found in " << folder->GetName() << endl ; 
1830     return 0 ;
1831   }
1832   return emcalO ;
1833 }
1834   
1835 //____________________________________________________________________________ 
1836 const TTask * AliEMCALGetter::ReturnT(TString what, TString name) const 
1837 {
1838   // get the TTask named "what" from the folder
1839   // folders are named like //Folders/Tasks/what/EMCAL/name
1840
1841   TString search(what) ; 
1842   if ( what.CompareTo("Clusterizer") == 0 ) 
1843     search = "Reconstructioner" ; 
1844   else if ( what.CompareTo("TrackSegmentMaker") == 0 ) 
1845     search = "Reconstructioner" ; 
1846   else if ( what.CompareTo("PID") == 0 ) 
1847     search = "Reconstructioner" ; 
1848   else if ( what.CompareTo("QATasks") == 0 ) 
1849     search = "QA" ; 
1850   
1851   TTask * tasks = dynamic_cast<TTask*>(fTasksFolder->FindObject(search)) ; 
1852
1853   if (!tasks) {
1854     cerr << "ERROR: AliEMCALGetter::ReturnT -> Task " << what << " not found!" << endl ;  
1855     return 0 ; 
1856   }
1857
1858   TTask * emcalT = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("EMCAL")) ; 
1859   if (!emcalT) { 
1860     cerr << "ERROR: AliEMCALGetter::ReturnT -> Task " << what << "/EMCAL not found!" << endl ;  
1861     return 0 ; 
1862   }
1863   
1864   TList * list = emcalT->GetListOfTasks() ; 
1865  
1866   if (what.CompareTo("SDigitizer") == 0) {  
1867     if ( name.IsNull() )
1868       name =  fSDigitsTitle ; 
1869   } else  if (what.CompareTo("Digitizer") == 0){ 
1870     if ( name.IsNull() )
1871       name =  fDigitsTitle ;
1872   } else  if (what.CompareTo("Clusterizer") == 0){ 
1873     if ( name.IsNull() )
1874       name =  fRecPointsTitle ;
1875     name.Append(":clu") ;
1876   }
1877  //  else  if (what.CompareTo("TrackSegmentMaker") == 0){ 
1878 //     if ( name.IsNull() )
1879 //       name =  fTrackSegmentsTitle ;
1880 //     name.Append(":tsm") ;
1881 //   }
1882 //   else  if (what.CompareTo("PID") == 0){ 
1883 //     if ( name.IsNull() )
1884 //       name =  fRecParticlesTitle ;
1885 //     name.Append(":pid") ;
1886 //   }
1887 //   else  if (what.CompareTo("QATasks") == 0){ 
1888 //     if ( name.IsNull() )
1889 //       return emcalT ;
1890 //   }
1891   
1892   TIter it(list) ;
1893   TTask * task = 0 ; 
1894   while((task = static_cast<TTask *>(it.Next()) )){
1895     TString taskname(task->GetName()) ;
1896     if(taskname.BeginsWith(name)){
1897     return task ;}
1898   }
1899   
1900   if(fDebug)
1901     cout << "WARNING: AliEMCALGetter::ReturnT -> Task " << search << "/" << name << " not found!" << endl ; 
1902   return 0 ;
1903 }