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