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