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