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