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