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