]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSGetter.cxx
removed a warning and close/open files of TreeK
[u/mrichter/AliRoot.git] / PHOS / AliPHOSGetter.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 AliPHOSAnalyser):
34 //  AliPHOSGetter * gime = AliPHOSGetter::GetInstance("galice.root","test") ;
35 //  for(Int_t irecp = 0; irecp < gime->NRecParticles() ; irecp++)
36 //     AliPHOSRecParticle * part = gime->RecParticle(1) ;
37 //     ................
38 //  gime->Event(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 AliPHOSIndexToObject and make
44 //*--         systematic usage of TFolders without changing the interface        
45 //////////////////////////////////////////////////////////////////////////////
46
47
48 // --- ROOT system ---
49 #include "TFile.h"
50 #include "TTree.h"
51 #include "TROOT.h"
52 #include "TObjString.h"
53 #include "TFolder.h"
54 #include "TParticle.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 "AliPHOSGetter.h"
64 #include "AliPHOS.h"
65 #include "AliPHOSDigitizer.h"
66 #include "AliPHOSSDigitizer.h"
67 #include "AliPHOSClusterizerv1.h"
68 #include "AliPHOSTrackSegmentMakerv1.h"
69 #include "AliPHOSTrackSegment.h"
70 #include "AliPHOSPIDv1.h" 
71 #include "AliPHOSGeometry.h"
72
73 ClassImp(AliPHOSGetter)
74   
75   AliPHOSGetter * AliPHOSGetter::fgObjGetter = 0 ; 
76   TFile * AliPHOSGetter::fFile = 0 ; 
77
78 //____________________________________________________________________________ 
79 AliPHOSGetter::AliPHOSGetter(const char* headerFile, const char* branchTitle )
80 {
81   //Initialize  all lists
82
83   fDebug = 0 ; 
84
85   fAlice = 0 ; 
86   
87   fHeaderFile         = headerFile ; 
88   fBranchTitle        = branchTitle ;
89   fSDigitsTitle       = branchTitle ; 
90   fDigitsTitle        = branchTitle ; 
91   fRecPointsTitle     = branchTitle ; 
92   fRecParticlesTitle  = branchTitle ; 
93   fTrackSegmentsTitle = branchTitle ; 
94
95   fPrimaries = new TObjArray(1) ;
96
97   fModuleFolder    = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Configuration/Modules")); 
98   fPrimariesFolder = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/RunMC/Event/Data")); 
99   fHitsFolder      = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/RunMC/Event/Data/Hits")); 
100   fSDigitsFolder   = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/RunMC/Event/Data/SDigits")); 
101   fDigitsFolder    = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Event/Data")); 
102   fRecoFolder      = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Event/RecData")); 
103   fQAFolder        = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Conditions/QA")); 
104   fTasksFolder     = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Tasks")) ; 
105   
106   fFailed = kFALSE ;   
107
108   if ( fHeaderFile != "aliroot"  ) { // to call the getter without a file
109     //open headers file
110     fFile = static_cast<TFile*>(gROOT->GetFile(fHeaderFile.Data() ) ) ;
111     
112     if(!fFile) {    //if file was not opened yet, read gAlice
113       if ( fHeaderFile.Contains("_") ) {
114         cerr << "AliPHOSGetter::AliPHOSGetter -> Invalid file name (_ not allowed) " << fHeaderFile.Data() << endl ;
115         abort() ; 
116      }
117       fFile = TFile::Open(fHeaderFile.Data(),"update") ; 
118       if (!fFile->IsOpen()) {
119         cerr << "ERROR : AliPHOSGetter::AliPHOSGetter -> Cannot open " << fHeaderFile.Data() << endl ; 
120         fFailed = kTRUE ;
121         return ;  
122       }
123       gAlice = static_cast<AliRun *>(fFile->Get("gAlice")) ;
124     }       
125   }
126   
127   if (!gAlice) {
128     cerr << "ERROR : AliPHOSGetter::AliPHOSGetter -> Cannot find gAlice in " << fHeaderFile.Data() << endl ; 
129     fFailed = kTRUE ;
130     return ; 
131   }
132   if (!PHOS()) {
133     if (fDebug)
134       cout << "INFO: AliPHOSGetter:AliPHOSGetter -> Posting PHOS to Folders" << endl ; 
135     if (gAlice->GetDetector("PHOS")) {
136       AliConfig * conf = AliConfig::Instance() ; 
137       conf->Add(static_cast<AliDetector*>(gAlice->GetDetector("PHOS"))) ; 
138       conf->Add(static_cast<AliModule*>(gAlice->GetDetector("PHOS"))) ; 
139     }
140     else 
141       cerr << "ERROR: AliPHOSGetter:AliPHOSGetter -> detector PHOS not found" << endl ;  
142   }
143   
144   fDebug=0;
145 }
146 //____________________________________________________________________________ 
147 AliPHOSGetter::~AliPHOSGetter(){
148
149   if (fPrimaries) {
150     fPrimaries->Delete() ; 
151     delete fPrimaries ; 
152   }
153
154   TFolder * phosF = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject("PHOS")) ;
155   TCollection * folderslist = phosF->GetListOfFolders() ; 
156   TIter next(folderslist) ; 
157   TFolder * folder = 0 ; 
158   while ( (folder = static_cast<TFolder*>(next())) ) 
159     phosF->Remove(folder) ; 
160   
161   if (fFile) { 
162     fFile->Close() ;  
163     delete fFile ;
164     fFile = 0 ;
165   }
166   fgObjGetter = 0 ; 
167   
168 }
169
170 //____________________________________________________________________________ 
171 void AliPHOSGetter::CloseFile()
172 {
173   delete gAlice ;  
174   gAlice = 0 ; 
175   delete fAlice ; 
176   fAlice = 0 ; 
177 }
178
179 //____________________________________________________________________________ 
180 const TFolder * AliPHOSGetter::Folder(const TString what) const {
181
182   // returns the PHOS folder required by what
183   // what = hits, sdigits, digits
184
185   if ( what == "hits" ) 
186     return dynamic_cast<const TFolder *>(fHitsFolder->FindObject("PHOS")) ; 
187   else if ( what == "sdigits" ) 
188     return  dynamic_cast<const TFolder *>(fSDigitsFolder->FindObject("PHOS")) ; 
189   else if ( what == "digits" ) 
190     return  dynamic_cast<const TFolder *>(fDigitsFolder->FindObject("PHOS")) ; 
191   else {
192     cerr << "ERROR: AliPHOSGetter::GetFolder -> " << what.Data() << " illegal option (hits, sdigits, digits) " << endl ; 
193     return 0 ; 
194   }
195 }
196
197 //____________________________________________________________________________ 
198 AliPHOSGetter * AliPHOSGetter::GetInstance()
199 {
200   // Returns the pointer of the unique instance already defined
201   
202   if ( fgObjGetter ) {
203     if (fFile)   // not the case if fManager
204       fFile->cd() ; 
205     return fgObjGetter ;
206   }
207   else {
208     //cout << "WARNING: AliPHOSGetter::GetInstance ERROR: not yet initialized" << endl ;
209     return 0 ; 
210   }
211 }
212
213 //____________________________________________________________________________ 
214 AliPHOSGetter * AliPHOSGetter::GetInstance(const char* headerFile,
215                                            const char* branchTitle)
216 {
217   // Creates and returns the pointer of the unique instance
218   // Must be called only when the environment has changed 
219
220   if ( fgObjGetter && !fFile) // an instance exists and getter was called without a file (case of merging) 
221     return fgObjGetter ;
222
223   if ( fgObjGetter && fFile->IsOpen()) // an instance exists and the file is still open   
224     if((fgObjGetter->fBranchTitle.CompareTo(branchTitle) == 0) && 
225        (fgObjGetter->fHeaderFile.CompareTo(headerFile)==0)) {
226       fFile->cd() ; 
227       return fgObjGetter ;
228     }
229     else // another file than the existing one is required, scratch the getter
230       fgObjGetter->~AliPHOSGetter() ;  // delete it already exists another version
231   
232   fgObjGetter = new AliPHOSGetter(headerFile,branchTitle) ; 
233
234   if (fgObjGetter->HasFailed() ) 
235     fgObjGetter = 0 ; 
236   
237   // Posts a few item to the white board (folders)
238   // fgObjGetter->CreateWhiteBoard() ;
239   
240   if (fFile) 
241     fFile->cd() ; 
242   return fgObjGetter ; 
243   
244 }
245
246 //____________________________________________________________________________ 
247 void AliPHOSGetter::ListBranches(Int_t event) const  
248 {
249   
250   TBranch * branch = 0 ; 
251   if (gAlice->GetEvent(event) == -1)
252     return ; 
253
254   TTree * t =  gAlice->TreeH() ; 
255   if(t){
256     cout << "****** Hits    : " << endl ; 
257     TObjArray * lob = t->GetListOfBranches() ;
258     TIter next(lob) ; 
259     while ( (branch = static_cast<TBranch*>(next())) )
260       cout << "             " << branch->GetName() << endl ; 
261   }
262   
263   t = gAlice->TreeS() ;
264   if(t){
265     cout << "****** SDigits : " << endl ; 
266     TObjArray * lob = t->GetListOfBranches() ;
267     TIter next(lob) ; 
268     while ( (branch = static_cast<TBranch*>(next())) )
269       cout << "             " << branch->GetName() << endl ; 
270   }  
271   t = gAlice->TreeD() ;
272   if(t){
273     cout << "****** Digits  : " << endl ; 
274     TObjArray * lob = t->GetListOfBranches() ;
275     TIter next(lob) ; 
276     while ( (branch = static_cast<TBranch*>(next())) )
277       cout << "             " << branch->GetName() << " " << branch->GetTitle() << endl ; 
278   }
279
280   t = gAlice->TreeR() ;
281   if(t){
282     cout << "****** Recon   : " << endl ; 
283     TObjArray * lob = t->GetListOfBranches() ;
284     TIter next(lob) ; 
285     while ( (branch = static_cast<TBranch*>(next())) )
286       cout << "             " << branch->GetName() << " " << branch->GetTitle() << endl ; 
287   }
288 }
289
290 //____________________________________________________________________________ 
291 void AliPHOSGetter::NewBranch(TString name, Int_t event)  
292 {
293   fBranchTitle = fSDigitsTitle = fDigitsTitle = fRecPointsTitle = fTrackSegmentsTitle = fRecParticlesTitle =  name ; 
294   Event(event) ; 
295 }
296
297 //____________________________________________________________________________ 
298 Bool_t AliPHOSGetter::NewFile(TString name)  
299 {
300   fHeaderFile = name ; 
301   fFile->Close() ; 
302   fFailed = kFALSE; 
303
304   fFile = static_cast<TFile*>(gROOT->GetFile(fHeaderFile.Data() ) ) ;
305   if(!fFile) {    //if file was not opened yet, read gAlice
306     fFile = TFile::Open(fHeaderFile.Data(),"update") ;
307     if (!fFile->IsOpen()) {
308       cerr << "ERROR : AliPHOSGetter::NewFile -> Cannot open " << fHeaderFile.Data() << endl ; 
309       fFailed = kTRUE ;
310       return fFailed ;  
311     }
312     gAlice = static_cast<AliRun *>(fFile->Get("gAlice")) ;
313   } 
314   
315   if (!gAlice) {
316     cerr << "ERROR : AliPHOSGetter::AliPHOSGetter -> Cannot find gAlice in " << fHeaderFile.Data() << endl ; 
317     fFailed = kTRUE ;
318     return fFailed ; 
319   }
320   return fFailed ; 
321 }
322
323 //____________________________________________________________________________ 
324 const AliPHOS * AliPHOSGetter::PHOS() 
325 {
326   // returns the PHOS object 
327   AliPHOS * phos = dynamic_cast<AliPHOS*>(fModuleFolder->FindObject("PHOS")) ;  
328   if (!phos) 
329     if (fDebug)
330       cout << "WARNING: AliPHOSGetter::PHOS -> PHOS module not found in Folders" << endl ; 
331   return phos ; 
332 }  
333
334 //____________________________________________________________________________ 
335 const AliPHOSGeometry * AliPHOSGetter::PHOSGeometry() 
336 {
337   AliPHOSGeometry * rv = 0 ; 
338   if (PHOS() )
339     rv =  PHOS()->GetGeometry() ;
340   return rv ; 
341
342
343 //____________________________________________________________________________ 
344 Bool_t AliPHOSGetter::PostPrimaries(void) const 
345 {  //------- Primaries ----------------------
346
347   // the hierarchy is //Folders/RunMC/Event/Data/Primaries
348   
349   TFolder * primariesFolder = dynamic_cast<TFolder*>(fPrimariesFolder->FindObject("Primaries")) ; 
350   if ( !primariesFolder ) {
351     if (fDebug) {
352       cout << "WARNING: AliPHOSGetter::Post Primaries -> Folder //" << fPrimariesFolder->GetName() << "/Primaries/ not found!" << endl;
353       cout << "INFO:    AliPHOSGetter::Post Primaries -> Adding Folder //" << fPrimariesFolder->GetName() << "/Primaries/"  << endl;
354     }
355     primariesFolder = fPrimariesFolder->AddFolder("Primaries", "Primaries particles from TreeK") ; 
356   }    
357   TClonesArray *primaries=  new TClonesArray("TParticle",1000) ;
358   primaries->SetName("Primaries") ;
359   primariesFolder->Add(primaries) ; 
360   
361   return kTRUE;
362
363
364 //____________________________________________________________________________ 
365 TObject** AliPHOSGetter::PrimariesRef(void) const 
366 {  //------- Primaries ----------------------
367
368   
369   // the hierarchy is //Folders/RunMC/Event/Data/Primaries
370   if ( !fPrimariesFolder ) {
371     cerr << "ERROR: AliPHOSGetter::PrimariesRef -> Folder //" << fPrimariesFolder << " not found!" << endl;
372     abort() ;
373   }    
374  
375   TFolder * primariesFolder = dynamic_cast<TFolder *>(fPrimariesFolder->FindObject("Primaries")) ;
376   if ( !primariesFolder ) {
377     cerr << "ERROR: AliPHOSGetter::PrimariesRef -> Folder //" << fPrimariesFolder << "/Primaries/ not found!" << endl;  
378     abort() ;
379   }
380  
381   TObject * p = primariesFolder->FindObject("Primaries") ;
382   if(!p) {
383     cerr << "ERROR: AliPHOSGetter::PrimariesRef -> " << primariesFolder->GetName() << "/Primaries not found !" << endl ; 
384     abort() ;
385   }
386   else
387     return primariesFolder->GetListOfFolders()->GetObjectRef(p) ;
388 }
389
390 //____________________________________________________________________________ 
391 Bool_t AliPHOSGetter::PostHits(void) const 
392 {  //------- Hits ----------------------
393
394   // the hierarchy is //Folders/RunMC/Event/Data/PHOS/Hits
395   
396   TFolder * phosFolder = dynamic_cast<TFolder*>(fHitsFolder->FindObject("PHOS")) ; 
397   if ( !phosFolder ) {
398     if (fDebug) {
399       cout << "WARNING: AliPHOSGetter::Post H -> Folder //" << fHitsFolder << "/PHOS/ not found!" << endl;
400       cout << "INFO:    AliPHOSGetter::Post H -> Adding Folder //" << fHitsFolder << "/PHOS/"  << endl;
401     }
402     phosFolder = fHitsFolder->AddFolder("PHOS", "Hits from PHOS") ; 
403   }    
404   TClonesArray *hits=  new TClonesArray("AliPHOSHit",1000) ;
405   hits->SetName("Hits") ;
406   phosFolder->Add(hits) ; 
407   
408   return kTRUE;
409
410
411 //____________________________________________________________________________ 
412 TObject** AliPHOSGetter::HitsRef(void) const 
413 {  //------- Hits ----------------------
414
415   
416   // the hierarchy is //Folders/RunMC/Event/Data/PHOS/Hits
417   if ( !fHitsFolder ) {
418     cerr << "ERROR: AliPHOSGetter::HitsRef -> Folder //" << fHitsFolder << " not found!" << endl;
419     abort() ;
420   }    
421  
422   TFolder * phosFolder = dynamic_cast<TFolder *>(fHitsFolder->FindObject("PHOS")) ;
423   if ( !phosFolder ) {
424     cerr << "ERROR: AliPHOSGetter::HitsRef -> Folder //" << fHitsFolder << "/PHOS/ not found!" << endl;  
425     abort() ;
426   }
427  
428   TObject * h = phosFolder->FindObject("Hits") ;
429   if(!h) {
430     cerr << "ERROR: AliPHOSGetter::HitsRef -> " << phosFolder->GetName() << "/Hits not found !" << endl ; 
431     abort() ;
432   }
433   else
434     return phosFolder->GetListOfFolders()->GetObjectRef(h) ;
435 }
436
437 //____________________________________________________________________________ 
438 Bool_t AliPHOSGetter::PostSDigits(const char * name, const char * headerFile) const 
439 {  //---------- SDigits -------------------------
440
441   
442   // the hierarchy is //Folders/RunMC/Event/Data/PHOS/SDigits/headerFile/sdigitsname
443   // because you can have sdigits from several hit files for mixing
444   
445   TFolder * phosFolder = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("PHOS")) ;
446   if ( !phosFolder ) {
447     if (fDebug) {
448       cout << "WARNING: AliPHOSGetter::Post S -> Folder //" << fSDigitsFolder << "/PHOS/ not found!" << endl;
449       cout << "INFO:    AliPHOSGetter::Post S -> Adding Folder //" << fHitsFolder << "/PHOS/" << endl;
450     }
451     phosFolder = fSDigitsFolder->AddFolder("PHOS", "SDigits from PHOS") ; 
452   }    
453   TString subdir(headerFile) ;
454   subdir.ReplaceAll("/","_") ; 
455   TFolder * phosSubFolder = dynamic_cast<TFolder*>(phosFolder->FindObject(subdir)) ; 
456   if ( !phosSubFolder ) 
457     phosSubFolder = phosFolder->AddFolder(subdir, ""); 
458   
459   TObject * sd  = phosSubFolder->FindObject(name); 
460   if ( sd ) {
461     if (fDebug)
462       cerr <<"INFO: AliPHOSGetter::Post S -> Folder " << subdir 
463            << " already exists!" << endl ;  
464   }else{
465     TClonesArray * sdigits = new TClonesArray("AliPHOSDigit",1) ;
466     sdigits->SetName(name) ;
467     phosSubFolder->Add(sdigits) ;
468   }
469   
470   return kTRUE;
471
472 //____________________________________________________________________________ 
473 TObject** AliPHOSGetter::SDigitsRef(const char * name, const char * file) const 
474 {  //------- SDigits ----------------------
475   
476   // the hierarchy is //Folders/RunMC/Event/Data/PHOS/SDigits/filename/SDigits
477
478   if ( !fSDigitsFolder ) {
479     cerr << "ERROR: AliPHOSGetter::SDigitsRef -> Folder //" << fSDigitsFolder << " not found!" << endl;
480     abort() ;
481   }    
482  
483   TFolder * phosFolder = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject("PHOS")) ;
484   if ( !phosFolder ) {
485     cerr << "ERROR: AliPHOSGetter::SDigitsRef -> Folder //" << fSDigitsFolder << "/PHOS/ not found!" << endl;
486     abort() ;
487   }
488
489   TFolder * phosSubFolder = 0 ;
490   if(file)
491     phosSubFolder = dynamic_cast<TFolder *>(phosFolder->FindObject(file)) ;
492   else
493     phosSubFolder = dynamic_cast<TFolder *>(phosFolder->FindObject(fHeaderFile)) ;
494   
495   if(!phosSubFolder) {
496     cerr << "ERROR: AliPHOSGetter::DigitesSRef -> Folder //Folders/RunMC/Event/Data/PHOS/" << file << "not found!" << endl;
497     abort() ;
498   }
499
500   TObject * dis = phosSubFolder->FindObject(name) ;
501   if(!dis){
502     cerr << "ERROR: AliPHOSGetter::DigitesSRef -> object " << name << " not found! " << endl ; 
503     abort()  ;
504   }
505   else
506     return phosSubFolder->GetListOfFolders()->GetObjectRef(dis) ;
507
508 }
509
510 //____________________________________________________________________________ 
511 Bool_t AliPHOSGetter::PostSDigitizer(AliPHOSSDigitizer * sdigitizer) const 
512 {  //---------- SDigitizer -------------------------
513     
514   // the hierarchy is //Folders/Tasks/SDigitizer/PHOS/sdigitsname
515
516
517   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ; 
518
519   if ( !sd ) {
520     cerr << "ERROR: AliPHOSGetter::Post Ser -> Task //" << fTasksFolder << "/SDigitizer not found!" << endl;
521     return kFALSE ;
522   }        
523   TTask * phos = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("PHOS")) ; 
524   if ( !phos )  {
525     if (fDebug) {
526       cout <<"WARNING: AliPHOSGetter::Post Ser ->//" << fTasksFolder << "/SDigitizer/PHOS/ not found!" << endl;  
527       cout <<"INFO: AliPHOSGetter::Post Ser -> Adding //" << fTasksFolder << "/SDigitizer/PHOS/" << endl;
528     }
529     phos = new TTask("PHOS", "") ; 
530     sd->Add(phos) ; 
531   } 
532   AliPHOSSDigitizer * phossd  = dynamic_cast<AliPHOSSDigitizer *>(phos->GetListOfTasks()->FindObject( sdigitizer->GetName() )); 
533   if (phossd) { 
534     if (fDebug)
535       cout << "INFO: AliPHOSGetter::Post Ser -> Task " << sdigitizer->GetName() << " already exists" << endl ; 
536     phos->GetListOfTasks()->Remove(phossd) ;
537   }
538   phos->Add(sdigitizer) ;       
539   return kTRUE; 
540   
541 }
542
543 //____________________________________________________________________________ 
544 TObject** AliPHOSGetter::SDigitizerRef(const char * name) const 
545 {  
546
547   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ; 
548   if ( !sd ) {
549     cerr << "ERROR: AliPHOSGetter::Post SerRef -> Task //" << fTasksFolder << "/SDigitizer not found!" << endl;
550     abort();
551   }        
552
553   TTask * phos = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("PHOS")) ; 
554   if ( !phos )  {
555     cerr <<"ERROR: AliPHOSGetter::Post SerRef ->  //" << fTasksFolder << "/SDigitizer/PHOS not found!" << endl;
556     abort();
557   }        
558
559   TTask * task = dynamic_cast<TTask*>(phos->GetListOfTasks()->FindObject(name)) ; 
560
561   return phos->GetListOfTasks()->GetObjectRef(task) ;
562
563 }
564
565 //____________________________________________________________________________ 
566 Bool_t AliPHOSGetter::PostSDigitizer(const char * name, const char * file) const 
567 {  //---------- SDigitizer -------------------------
568   
569  // the hierarchy is //Folders/Tasks/SDigitizer/PHOS/sdigitsname
570
571   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ; 
572   if ( !sd ) {
573     cerr << "ERROR: AliPHOSGetter::Post Ser -> Task //" << fTasksFolder << "/SDigitizer not found!" << endl;
574     return kFALSE ;
575   }        
576
577   TTask * phos = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("PHOS")) ; 
578   if ( !phos )  {
579     if (fDebug) {
580       cout <<"WARNING: AliPHOSGetter::Post Ser ->  //" << fTasksFolder << "/SDigitizer/PHOS/ not found!" << endl;
581       cout <<"INFO: AliPHOSGetter::Post Ser -> Adding  //" << fTasksFolder << "/SDigitizer/PHOS" << endl;
582     }
583     phos = new TTask("PHOS", "") ; 
584     sd->Add(phos) ; 
585   } 
586
587   TString sdname(name) ;
588   sdname.Append(":") ;
589   sdname.Append(file);
590   sdname.ReplaceAll("/","_") ; 
591   AliPHOSSDigitizer * phossd  = dynamic_cast<AliPHOSSDigitizer *>(phos->GetListOfTasks()->FindObject( sdname )); 
592   if (!phossd) {
593     phossd = new AliPHOSSDigitizer() ;  
594     //Note, we can not call constructor with parameters: it will call Getter and scew up everething
595     phossd->SetName(sdname) ;
596     phossd->SetTitle(file) ;
597     phos->Add(phossd) ; 
598   }
599   return kTRUE; 
600   
601 }
602
603 //____________________________________________________________________________ 
604 Bool_t AliPHOSGetter::PostDigits(const char * name) const 
605 {  //---------- Digits -------------------------
606
607   // the hierarchy is //Folders/Run/Event/Data/PHOS/SDigits/name
608
609   TFolder * phosFolder  = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("PHOS")) ;
610
611   if ( !phosFolder ) {
612     if (fDebug) {
613       cout << "WARNING: AliPHOSGetter::Post D -> Folder //" << fDigitsFolder << "/PHOS/ not found!" << endl;
614       cout << "INFO:    AliPHOSGetter::Post D -> Adding Folder //" << fDigitsFolder << "/PHOS/" << endl;
615     }
616     phosFolder = fDigitsFolder->AddFolder("PHOS", "Digits from PHOS") ;  
617   }    
618  
619   TObject*  dig = phosFolder->FindObject( name ) ;
620   if ( !dig ) {
621     TClonesArray * digits = new TClonesArray("AliPHOSDigit",1000) ;
622     digits->SetName(name) ;
623     phosFolder->Add(digits) ;  
624   }
625   return kTRUE; 
626 }
627
628 //____________________________________________________________________________ 
629 TObject** AliPHOSGetter::DigitsRef(const char * name) const 
630 { //------- Digits ----------------------
631   
632   // the hierarchy is //Folders/Run/Event/Data/PHOS/Digits/name
633
634   if ( !fDigitsFolder ) {
635     cerr << "ERROR: AliPHOSGetter::DigitsRef -> Folder //" << fDigitsFolder << " not found!" << endl;
636     abort() ;
637   }    
638   
639   TFolder * phosFolder  = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("PHOS")) ; 
640   if ( !phosFolder ) {
641     cerr << "ERROR: AliPHOSGetter::DigitsRef -> Folder //" << fDigitsFolder << "/PHOS/ not found!" << endl;
642     abort() ;
643   }    
644
645   TObject * d = phosFolder->FindObject(name) ;
646   if(!d) {
647     cerr << "ERROR: AliPHOSGetter::DigitsRef -> object " << name << " not found! " << endl ; 
648     abort() ;
649   }
650   else
651     return phosFolder->GetListOfFolders()->GetObjectRef(d) ;
652
653 }
654
655 //____________________________________________________________________________ 
656 Bool_t AliPHOSGetter::PostDigitizer(AliPHOSDigitizer * digitizer) const 
657 {  //---------- Digitizer -------------------------
658   
659   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ; 
660
661   if ( !sd ) {
662     cerr << "ERROR: AliPHOSGetter::Post Der -> Task //" << fTasksFolder << "/Digitizer not found!" << endl;
663     return kFALSE ;
664   }        
665   TTask * phos = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("PHOS")) ; 
666   if ( !phos )  {
667     if (fDebug) {
668       cout <<"WARNING: AliPHOSGetter::Post Der ->  //" << fTasksFolder << "/Digitizer/PHOS not found!" << endl;
669       cout <<"INFO: AliPHOSGetter::Post Der -> Adding //" << fTasksFolder << "/Digitizer/PHOS" << endl; 
670     }
671     phos = new TTask("PHOS", "") ; 
672     sd->Add(phos) ; 
673   } 
674
675     AliPHOSDigitizer * phosd = dynamic_cast<AliPHOSDigitizer*>(phos->GetListOfTasks()->FindObject(digitizer->GetName())) ; 
676     if (phosd) { 
677       phosd->Delete() ;
678       phos->GetListOfTasks()->Remove(phosd) ;
679     }
680     phos->Add(digitizer) ; 
681     return kTRUE; 
682 }  
683
684 //____________________________________________________________________________ 
685 Bool_t AliPHOSGetter::PostDigitizer(const char * name) const 
686 {  //---------- Digitizer -------------------------
687   
688  // the hierarchy is //Folders/Tasks/SDigitizer/PHOS/sdigitsname
689
690   TTask * d  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ; 
691   if ( !d ) {
692     cerr << "ERROR: AliPHOSGetter::Post Der -> Task //" << fTasksFolder << "/Digitizer not found!" << endl;
693     return kFALSE ;
694   }        
695
696   TTask * phos = dynamic_cast<TTask*>(d->GetListOfTasks()->FindObject("PHOS")) ; 
697   if ( !phos )  {
698     if (fDebug) {
699       cout <<"WARNING: AliPHOSGetter::Post Der -> //" << fTasksFolder << "/Digitizer/PHOS not found!" << endl; 
700       cout <<"INFO: AliPHOSGetter::Post Der -> Adding //" << fTasksFolder << "/Digitizer/PHOS" << endl;
701     }
702     phos = new TTask("PHOS", "") ; 
703     d->Add(phos) ; 
704
705
706   AliPHOSDigitizer * phosd = dynamic_cast<AliPHOSDigitizer*>(phos->GetListOfTasks()->FindObject(name)) ; 
707   if (!phosd) { 
708     phosd = new AliPHOSDigitizer() ;
709     phosd->SetName(fDigitsTitle) ;
710     phosd->SetTitle(fHeaderFile) ;
711     phos->Add(phosd) ;
712   }
713   return kTRUE;  
714 }
715
716 //____________________________________________________________________________ 
717 TObject** AliPHOSGetter::DigitizerRef(const char * name) const 
718 {  
719   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ; 
720   if ( !sd ) {
721     cerr << "ERROR: AliPHOSGetter::Post DerRef -> Task //" << fTasksFolder << "/Digitizer not found!" << endl;
722     abort();
723   }        
724
725   TTask * phos = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("PHOS")) ; 
726   if ( !phos )  {
727     cerr <<"ERROR: AliPHOSGetter::Post DerRef ->  //" << fTasksFolder << "/Digitizer/PHOS" << endl;
728     abort();
729   }        
730
731   TTask * task = dynamic_cast<TTask*>(phos->GetListOfTasks()->FindObject(name)) ; 
732
733   return phos->GetListOfTasks()->GetObjectRef(task) ;
734
735 }
736  
737 //____________________________________________________________________________ 
738 Bool_t AliPHOSGetter::PostRecPoints(const char * name) const 
739 { // -------------- RecPoints -------------------------------------------
740   
741   // the hierarchy is //Folders/Run/Event/RecData/PHOS/EMCARecPoints/name
742   // the hierarchy is //Folders/Run/Event/RecData/PHOS/CPVRecPoints/name
743
744   TFolder * phosFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("PHOS")) ; 
745   
746   if ( !phosFolder ) {
747     if (fDebug) {
748       cout << "WARNING: AliPHOSGetter::Post RPo -> Folder //" << fRecoFolder->GetName() << "/PHOS/ not found!" << endl;
749       cout << "INFO:    AliPHOSGetter::Post Rpo -> Adding Folder //" << fRecoFolder->GetName() << "/PHOS/" << endl;
750     }
751     phosFolder = fRecoFolder->AddFolder("PHOS", "Reconstructed data from PHOS") ;  
752   }    
753   
754   // EMCA RecPoints 
755   TFolder * phosRPoEMCAFolder  = dynamic_cast<TFolder*>(phosFolder->FindObject("EMCARecPoints")) ;
756   if ( !phosRPoEMCAFolder ) {
757     if (fDebug) {
758       cout << "WARNING: AliPHOSGetter::Post RPo -> Folder //" << fRecoFolder->GetName() << "/PHOS/EMCARecPoints/ not found!" << endl;
759       cout << "INFO:    AliPHOSGetter::Post Rpo -> Adding Folder //" << fRecoFolder->GetName() << "/PHOS/EMCARecPoints" << endl;
760     }
761     phosRPoEMCAFolder = phosFolder->AddFolder("EMCARecPoints", "EMCA RecPoints from PHOS") ;  
762   }    
763   
764   TObject * erp = phosFolder->FindObject( name ) ;
765   if ( !erp )   {
766     TObjArray * emcrp = new TObjArray(100) ;
767     emcrp->SetName(name) ;
768     phosRPoEMCAFolder->Add(emcrp) ;  
769   }
770
771   // CPV RecPoints 
772   TFolder * phosRPoCPVFolder  = dynamic_cast<TFolder*>(phosFolder->FindObject("CPVRecPoints")) ;
773   if ( !phosRPoCPVFolder ) {
774     if (fDebug) {
775       cout << "WARNING: AliPHOSGetter::Post RPo -> Folder //" << fRecoFolder->GetName() << "/PHOS/CPVRecPoints/ not found!" << endl;
776       cout << "INFO:    AliPHOSGetter::Post Rpo -> Adding Folder //" << fRecoFolder->GetName() << "/PHOS/CPVRecPoints/" << endl;
777     }
778     phosRPoCPVFolder = phosFolder->AddFolder("CPVRecPoints", "CPV RecPoints from PHOS") ;  
779   }    
780   
781   TObject * crp =  phosRPoCPVFolder->FindObject( name ) ;
782   if ( !crp )   {
783     TObjArray * cpvrp = new TObjArray(100) ;
784     cpvrp->SetName(name) ;
785     phosRPoCPVFolder->Add(cpvrp) ;  
786   }
787   return kTRUE; 
788 }
789
790 //____________________________________________________________________________ 
791 TObject** AliPHOSGetter::EmcRecPointsRef(const char * name) const 
792 { // -------------- RecPoints -------------------------------------------
793   
794   // the hierarchy is //Folders/Run/Event/RecData/PHOS/EMCARecPoints/name
795    
796   if ( !fRecoFolder ) {
797     cerr << "ERROR: AliPHOSGetter::EmcRecPointsRef -> Folder //" << fRecoFolder->GetName() << " not found!" << endl;
798     abort() ; 
799   }    
800
801   TFolder * phosFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("PHOS/EMCARecPoints")) ; 
802   if ( !phosFolder ) {
803     cerr << "ERROR: AliPHOSGetter::EmcRecPointsRef -> Folder //" << fRecoFolder->GetName() << "/PHOS/EMCARecPoints/ not found!" << endl;
804     abort() ;
805   }    
806
807
808   TObject * erp = phosFolder->FindObject(name ) ;
809   if ( !erp )   {
810     cerr << "ERROR: AliPHOSGetter::EmcRecPointsRef -> object " << name << " not found! " << endl ; 
811     abort() ;
812   }
813   return phosFolder->GetListOfFolders()->GetObjectRef(erp) ;
814   
815
816
817 //____________________________________________________________________________ 
818 TObject** AliPHOSGetter::CpvRecPointsRef(const char * name) const 
819 { // -------------- RecPoints -------------------------------------------
820   
821   // the hierarchy is //Folders/Run/Event/RecData/PHOS/CPVRecPoints/name
822    
823   if ( !fRecoFolder ) {
824     cerr << "ERROR: AliPHOSGetter::CpvRecPointsRef -> Folder //" << fRecoFolder->GetName() << " not found!" << endl;
825     abort() ; 
826   }    
827
828   TFolder * phosFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("PHOS/CPVRecPoints")) ; 
829   if ( !phosFolder ) {
830     cerr << "ERROR: AliPHOSGetter::CpvRecPointsRef -> Folder //" << fRecoFolder->GetName() << "/PHOS/CPVRecPoints/" << endl;
831     abort() ;
832   }    
833
834   TObject * crp = phosFolder->FindObject(name ) ;
835   if ( !crp )   {
836     cerr << "ERROR: AliPHOSGetter::CpvRecPointsRef -> object " << name << " not found " << endl ; 
837     abort() ;
838   }
839   return phosFolder->GetListOfFolders()->GetObjectRef(crp) ;
840   
841
842
843 //____________________________________________________________________________ 
844 Bool_t AliPHOSGetter::PostClusterizer(AliPHOSClusterizer * clu) const 
845 { // ------------------ AliPHOSClusterizer ------------------------
846   
847   // the hierarchy is //Folders/Tasks/Reconstructioner/PHOS/sdigitsname
848
849   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
850
851   if ( !tasks ) {
852     cerr << "ERROR: AliPHOSGetter::Post Rer -> Task //" << fTasksFolder << "/Reconstructioner not found!" << endl;
853     return kFALSE ;
854   }        
855         
856   TTask * phos = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("PHOS")) ; 
857   if ( !phos )  {
858     if (fDebug) {
859       cout <<"WARNING: AliPHOSGetter::Post Rer -> //" << fTasksFolder << "/Reconstructioner/PHOS not found!" << endl; 
860       cout <<"INFO: AliPHOSGetter::Post Rer -> Adding //" << fTasksFolder << "/Reconstructioner/PHOS" << endl; 
861     }
862     phos = new TTask("PHOS", "") ; 
863     tasks->Add(phos) ; 
864   } 
865
866   AliPHOSClusterizer * phoscl = dynamic_cast<AliPHOSClusterizer*>(phos->GetListOfTasks()->FindObject(clu->GetName())) ; 
867   if (phoscl) { 
868     if (fDebug)
869       cout << "INFO: AliPHOSGetter::Post Rer -> Task " << clu->GetName() << " already exists" << endl ; 
870     phoscl->Delete() ; 
871     phos->GetListOfTasks()->Remove(phoscl) ;
872   }
873   phos->Add(clu) ;      
874   return kTRUE; 
875
876
877 //____________________________________________________________________________ 
878 TObject** AliPHOSGetter::ClusterizerRef(const char * name) const 
879 { // ------------------ AliPHOSClusterizer ------------------------
880   
881   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
882
883   if ( !tasks ) {
884     cerr << "ERROR: AliPHOSGetter::ClusterizerRef -> Task //" << fTasksFolder->GetName() << "/Reconstructioner not found!" << endl;
885     abort() ;
886   }        
887         
888   TTask * phos = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("PHOS")) ; 
889   if ( !phos )  {
890     cerr <<"WARNING: AliPHOSGetter::ClusterizerRef -> //" << fTasksFolder->GetName() << "/Reconstructioner/PHOS" << endl; 
891     abort() ; 
892   }   
893
894   TList * l = phos->GetListOfTasks() ; 
895   TIter it(l) ;
896   TTask * task ;
897   TTask * clu = 0 ;
898   TString cluname(name) ;
899   cluname+=":clu" ;
900   while((task = static_cast<TTask *>(it.Next()) )){
901     TString taskname(task->GetName()) ;
902     if(taskname.BeginsWith(cluname)){
903       clu = task ;
904       break ;
905     }
906   }
907
908   if(clu) 
909     return l->GetObjectRef(clu) ;
910   else{
911     cerr << "ERROR: AliPHOSGetter::ClusterizerRef -> Task //" << fTasksFolder->GetName() << "/Reconstructioner/clusterizer " <<  name << " not found!" << endl;
912     abort() ;
913   }
914 }
915
916 //____________________________________________________________________________ 
917 Bool_t AliPHOSGetter::PostClusterizer(const char * name) const 
918 { // ------------------ AliPHOSClusterizer ------------------------
919
920   // the hierarchy is //Folders/Tasks/Reconstructioner/PHOS/sdigitsname
921   
922   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
923
924   if ( !tasks ) {
925     cerr << "ERROR: AliPHOSGetter::Post Rer -> Task//" << fTasksFolder << "/Reconstructioner not found!" << endl; 
926     return kFALSE ;
927   }        
928   
929   TTask * phos = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("PHOS")) ; 
930   if ( !phos )  {
931     if (fDebug) {
932       cout <<"WARNING: AliPHOSGetter::Post Rer -> //" << fTasksFolder << "/Reconstructioner/PHOS not found!" << endl;
933       cout <<"INFO: AliPHOSGetter::Post Rer -> Adding //" << fTasksFolder << "/Reconstructioner/PHOS" << endl;
934     }
935     phos = new TTask("PHOS", "") ; 
936     tasks->Add(phos) ; 
937   } 
938
939   TList * l = phos->GetListOfTasks() ;   
940   TIter it(l) ;
941   TString clun(name) ;
942   clun+=":clu" ; 
943   TTask * task ;
944   while((task = static_cast<TTask *>(it.Next()) )){
945     TString taskname(task->GetName()) ;
946     if(taskname.BeginsWith(clun))
947       return kTRUE ;
948   }
949
950   AliPHOSClusterizerv1 * phoscl = new AliPHOSClusterizerv1() ;
951   phos->Add(phoscl) ;
952   return kTRUE; 
953   
954 }
955
956 //____________________________________________________________________________ 
957 Bool_t AliPHOSGetter::PostTrackSegments(const char * name) const 
958 { // ---------------TrackSegments -----------------------------------
959   
960   // the hierarchy is //Folders/Run/Event/RecData/PHOS/TrackSegments/name
961
962   TFolder * phosFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("PHOS")) ; 
963   
964   if ( !phosFolder ) {
965     if (fDebug) {
966       cout << "WARNING: AliPHOSGetter::Post TS -> Folder //" << fRecoFolder->GetName() << "/PHOS/ not found!" << endl;
967       cout << "INFO:    AliPHOSGetter::Post TS -> Adding Folder //" << fRecoFolder->GetName() << "/PHOS" << endl;
968     }
969     phosFolder = fRecoFolder->AddFolder("PHOS", "Reconstructed data from PHOS") ;  
970   }    
971
972   TFolder * phosTSFolder  = dynamic_cast<TFolder*>(phosFolder->FindObject("TrackSegments")) ;
973   if ( !phosTSFolder ) {
974     if (fDebug) {
975       cout << "WARNING: AliPHOSGetter::Post TS -> Folder //" << fRecoFolder->GetName() << "/PHOS/TrackSegments/ not found!" << endl; 
976       cout << "INFO:    AliPHOSGetter::Post TS -> Adding Folder //" << fRecoFolder->GetName() << "/PHOS/TrackSegments/" << endl; 
977     }
978     phosTSFolder = phosFolder->AddFolder("TrackSegments", "TrackSegments from PHOS") ;  
979   }    
980   
981   TObject * tss =  phosTSFolder->FindObject( name ) ;
982   if (!tss) {
983     TClonesArray * ts = new TClonesArray("AliPHOSTrackSegment",100) ;
984     ts->SetName(name) ;
985     phosTSFolder->Add(ts) ;  
986   }
987   return kTRUE; 
988
989
990 //____________________________________________________________________________ 
991 TObject** AliPHOSGetter::TrackSegmentsRef(const char * name) const 
992 { // ---------------TrackSegments -----------------------------------
993   
994   // the hierarchy is //Folders/Run/Event/RecData/PHOS/TrackSegments/name
995
996  if ( !fRecoFolder ) {
997     cerr << "ERROR: AliPHOSGetter::TrackSegmentsRef -> Folder //" << fRecoFolder->GetName() << "not found!" << endl;
998     abort() ; 
999   }    
1000
1001   TFolder * phosFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("PHOS/TrackSegments")) ; 
1002   if ( !phosFolder ) {
1003     cerr << "ERROR: AliPHOSGetter::TrackSegmentsRef -> Folder //" << fRecoFolder->GetName() << "/PHOS/TrackSegments/ not found!" << endl;
1004     abort() ;
1005   }    
1006   
1007   TObject * tss =  phosFolder->FindObject(name) ;
1008   if (!tss) {
1009     cerr << "ERROR: AliPHOSGetter::TrackSegmentsRef -> object " << name << " not found! " << endl ;  
1010     abort() ;  
1011   }
1012   return phosFolder->GetListOfFolders()->GetObjectRef(tss) ;
1013
1014
1015 //____________________________________________________________________________ 
1016 Bool_t AliPHOSGetter::PostTrackSegmentMaker(AliPHOSTrackSegmentMaker * tsmaker) const 
1017 { //------------Track Segment Maker ------------------------------
1018   
1019   // the hierarchy is //Folders/Tasks/Reconstructioner/PHOS/sdigitsname
1020
1021   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
1022
1023   if ( !tasks ) {
1024     cerr << "ERROR: AliPHOSGetter::Post Ter -> Task //" << fTasksFolder << "/Reconstructioner not found!" << endl;
1025     return kFALSE ;
1026   }        
1027         
1028   TTask * phos = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("PHOS")) ; 
1029   if ( !phos )  {
1030     if (fDebug) {
1031       cout <<"WARNING: AliPHOSGetter::Post Rer -> //" << fTasksFolder << "/Reconstructioner/PHOS not found!" << endl; 
1032       cout <<"INFO: AliPHOSGetter::Post Rer -> Adding //" << fTasksFolder << "/Reconstructioner/PHOS" << endl;
1033     }
1034     phos = new TTask("PHOS", "") ; 
1035     tasks->Add(phos) ; 
1036   } 
1037
1038   AliPHOSTrackSegmentMaker * phosts = 
1039     dynamic_cast<AliPHOSTrackSegmentMaker*>(phos->GetListOfTasks()->FindObject(tsmaker->GetName())) ; 
1040   if (phosts) { 
1041     phosts->Delete() ;
1042     phos->GetListOfTasks()->Remove(phosts) ;
1043   }
1044   phos->Add(tsmaker) ;      
1045   return kTRUE; 
1046   
1047
1048 //____________________________________________________________________________ 
1049 Bool_t AliPHOSGetter::PostTrackSegmentMaker(const char * name) const 
1050 { //------------Track Segment Maker ------------------------------
1051   
1052   // the hierarchy is //Folders/Tasks/Reconstructioner/PHOS/sdigitsname
1053   
1054   
1055   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
1056   
1057   if ( !tasks ) {
1058     cerr << "ERROR: AliPHOSGetter::Post Ter -> Task //" << fTasksFolder->GetName() << "/Reconstructioner not found!" << endl;
1059     return kFALSE ;
1060   }        
1061   
1062   TTask * phos = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("PHOS")) ; 
1063   if ( !phos )  {
1064     if (fDebug) {
1065       cout <<"WARNING: AliPHOSGetter::Post Ter -> //" << fTasksFolder->GetName() << "/Reconstructioner/PHOS not found!" << endl; 
1066       cout <<"INFO: AliPHOSGetter::Post Ter -> Adding //" << fTasksFolder->GetName() << "/Reconstructioner/PHOS" << endl;
1067     }
1068     phos = new TTask("PHOS", "") ; 
1069     tasks->Add(phos) ; 
1070   } 
1071
1072   TList * l = phos->GetListOfTasks() ;   
1073   TIter it(l) ;
1074   TString tsn(name);
1075   tsn+=":tsm" ; 
1076   TTask * task ;
1077   while((task = static_cast<TTask *>(it.Next()) )){
1078     TString taskname(task->GetName()) ;
1079     if(taskname.BeginsWith(tsn))
1080       return kTRUE ;
1081   }
1082   
1083   AliPHOSTrackSegmentMakerv1 * phosts = new AliPHOSTrackSegmentMakerv1() ;
1084   phosts->SetName(tsn) ;
1085
1086   phos->Add(phosts) ;      
1087   return kTRUE; 
1088   
1089
1090
1091 //____________________________________________________________________________ 
1092 TObject** AliPHOSGetter::TSMakerRef(const char * name) const 
1093 { //------------Track Segment Maker ------------------------------
1094   
1095   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
1096
1097   if ( !tasks ) {
1098     cerr << "ERROR: AliPHOSGetter::TSMakerRef -> Task //" << fTasksFolder->GetName() << "/Reconstructioner not found!" << endl;
1099     abort() ;
1100   }        
1101         
1102   TTask * phos = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("PHOS")) ; 
1103   if ( !phos )  {
1104     cerr <<"WARNING: AliPHOSGetter::TSMakerRef -> //" << fTasksFolder->GetName() << "/Reconstructioner/PHOS not found!" << endl; 
1105     abort()  ; 
1106   }   
1107
1108   TList * l = phos->GetListOfTasks() ; 
1109   TIter it(l) ;
1110   TTask * task ;
1111   TTask * tsm = 0 ;
1112   TString tsmname(name) ;
1113   tsmname+=":tsm" ;
1114   while((task = static_cast<TTask *>(it.Next()) )){
1115     TString taskname(task->GetName()) ;
1116     if(taskname.BeginsWith(tsmname)){
1117       tsm = task ;
1118       break ;
1119     }
1120   }
1121   
1122   if(tsm) 
1123     return l->GetObjectRef(tsm) ;
1124   else {
1125     cerr << "ERROR: AliPHOSGetter::TSMakerRef -> Task //" << fTasksFolder->GetName() << "/Reconstructioner/PHOS/TrackSegmentMarker/" << name << " not found!" << endl;
1126     abort() ;
1127   } 
1128
1129
1130 //____________________________________________________________________________ 
1131 Bool_t AliPHOSGetter::PostRecParticles(const char * name) const 
1132 {  // -------------------- RecParticles ------------------------
1133   
1134   // the hierarchy is //Folders/Run/Event/RecData/PHOS/RecParticles/name
1135
1136   TFolder * phosFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("PHOS")) ; 
1137   
1138   if ( !phosFolder ) {
1139     if (fDebug) {
1140       cout << "WARNING: AliPHOSGetter::Post RPa -> Folder //" << fRecoFolder->GetName() << "/PHOS/ not found!" << endl;
1141       cout << "INFO:    AliPHOSGetter::Post Rpa -> Adding Folder //" << fRecoFolder->GetName() << "/PHOS/" << endl;
1142     }
1143     phosFolder = fRecoFolder->AddFolder("PHOS", "Reconstructed data from PHOS") ;  
1144   }    
1145
1146  TFolder * phosRPaFolder  = dynamic_cast<TFolder*>(phosFolder->FindObject("RecParticles")) ;
1147   if ( !phosRPaFolder ) {
1148     if (fDebug) {
1149       cout << "WARNING: AliPHOSGetter::Post RPa -> Folder //" << fRecoFolder->GetName() << "/PHOS/RecParticles/ not found!" << endl;
1150       cout << "INFO:    AliPHOSGetter::Post RPa -> Adding Folder //" << fRecoFolder->GetName() << "/PHOS/RecParticles/" << endl;
1151     }
1152     phosRPaFolder = phosFolder->AddFolder("RecParticles", "RecParticles from PHOS") ;  
1153   } 
1154
1155   TObject * rps = phosRPaFolder->FindObject( name )  ;
1156   if ( !rps ) {
1157     TClonesArray * rp = new TClonesArray("AliPHOSRecParticle",100) ;
1158     rp->SetName(name) ;    
1159     phosRPaFolder->Add(rp) ;  
1160   }
1161   return kTRUE; 
1162
1163
1164 //____________________________________________________________________________ 
1165 TObject** AliPHOSGetter::RecParticlesRef(const char * name) const 
1166 { // ---------------TrackSegments -----------------------------------
1167   
1168   // the hierarchy is //Folders/Run/Event/RecData/PHOS/TrackSegments/name
1169
1170  if ( !fRecoFolder ) {
1171     cerr << "ERROR: AliPHOSGetter::RecParticlesRef -> Folder//" << fRecoFolder->GetName() << " not found!" << endl; 
1172     abort() ; 
1173   }    
1174
1175   TFolder * phosFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("PHOS/RecParticles")) ; 
1176   if ( !phosFolder ) {
1177     cerr << "ERROR: AliPHOSGetter::RecParticlesRef -> Folder //" << fRecoFolder->GetName() << "/PHOS/RecParticles/ not found!" << endl;
1178     abort() ;
1179   }    
1180
1181   TObject * tss =  phosFolder->FindObject(name  ) ;
1182   if (!tss) {
1183     cerr << "ERROR: AliPHOSGetter::RecParticlesRef -> object " << name << " not found! " << endl ; 
1184     abort() ;  
1185   }
1186   return phosFolder->GetListOfFolders()->GetObjectRef(tss) ;
1187 }
1188
1189 //____________________________________________________________________________ 
1190 Bool_t AliPHOSGetter::PostPID(AliPHOSPID * pid) const 
1191 {      // ------------AliPHOS PID -----------------------------
1192
1193   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
1194
1195   if ( !tasks ) {
1196     cerr << "ERROR: AliPHOSGetter::Post Per -> Task //" << fTasksFolder << "/Reconstructioner not found!" << endl;
1197     return kFALSE ;
1198   }        
1199   
1200   TTask * phos = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("PHOS")) ; 
1201   if ( !phos )  {
1202     if (fDebug) {
1203       cout <<"WARNING: AliPHOSGetter::Post Per -> //" << fTasksFolder << "/Reconstructioner/PHOS not found!" << endl; 
1204       cout <<"INFO: AliPHOSGetter::Post Per -> Adding //" << fTasksFolder << "/Reconstructioner/PHOS" << endl;
1205     }
1206     phos = new TTask("PHOS", "") ; 
1207     tasks->Add(phos) ; 
1208   } 
1209
1210   AliPHOSPID * phospid = dynamic_cast<AliPHOSPID*>(phos->GetListOfTasks()->FindObject(pid->GetName())) ; 
1211   if (phospid) { 
1212     if (fDebug)
1213       cout << "INFO: AliPHOSGetter::Post Per -> Task " << pid->GetName()
1214            << " already exists" << endl ; 
1215     phos->GetListOfTasks()->Remove(phospid) ;
1216   }
1217   
1218   phos->Add(pid) ;      
1219   return kTRUE; 
1220
1221
1222 //____________________________________________________________________________ 
1223 Bool_t AliPHOSGetter::PostPID(const char * name) const 
1224 {     
1225   // the hierarchy is //Folders/Tasks/Reconstructioner/PHOS/sdigitsname
1226   
1227   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
1228
1229   if ( !tasks ) {
1230     cerr << "ERROR: AliPHOSGetter::Post Per -> Task //" << fTasksFolder->GetName() << "/Reconstructioner not found!" << endl;
1231     return kFALSE ;
1232   }        
1233   
1234   TTask * phos = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("PHOS")) ; 
1235   if ( !phos )  {
1236     if (fDebug) {
1237       cout <<"WARNING: AliPHOSGetter::Post Per -> //" << fTasksFolder->GetName() << "/Reconstructioner/PHOS not found!" << endl; 
1238       cout <<"INFO: AliPHOSGetter::Post Per -> Adding //" << fTasksFolder->GetName() << "/Reconstructioner/PHOS" << endl;
1239     }
1240     phos = new TTask("PHOS", "") ; 
1241     tasks->Add(phos) ; 
1242   } 
1243
1244   TList * l = phos->GetListOfTasks() ;   
1245   TIter it(l) ;
1246   TString pidname(name) ;
1247   pidname+=":pid" ;
1248   TTask * task ;
1249   while((task = static_cast<TTask *>(it.Next()) )){
1250     TString taskname(task->GetName()) ;
1251     if(taskname.BeginsWith(pidname))
1252       return kTRUE ;
1253   }
1254  
1255   AliPHOSPIDv1 * phospid = new AliPHOSPIDv1() ;
1256   phospid->SetName(pidname) ; 
1257   phos->Add(phospid) ;      
1258   
1259   return kTRUE; 
1260
1261
1262 //____________________________________________________________________________ 
1263 TObject** AliPHOSGetter::PIDRef(const char * name) const 
1264 { //------------PID ------------------------------
1265
1266   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
1267
1268   if ( !tasks ) {
1269     cerr << "ERROR: AliPHOSGetter::PIDRef -> Task //" << fTasksFolder->GetName() << "/Reconstructioner not found!" << endl;
1270     abort() ;
1271   }        
1272         
1273   TTask * phos = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("PHOS")) ; 
1274   if ( !phos )  {
1275     cerr << "ERROR: AliPHOSGetter::PIDRef -> //" << fTasksFolder->GetName() << "/Reconstructioner/PHOS not found!" << endl; 
1276     abort()  ; 
1277   }   
1278   
1279   TList * l = phos->GetListOfTasks() ; 
1280   TIter it(l) ;
1281   TTask * task ;
1282   TTask * pid = 0 ;
1283   TString pidname(name) ;
1284   pidname+=":pid" ;
1285   while((task = static_cast<TTask *>(it.Next()) )){
1286     TString taskname(task->GetName()) ;
1287     if(taskname.BeginsWith(pidname)){
1288       pid = task ;
1289       break ;
1290     }
1291   }
1292   
1293   if(pid) 
1294     return l->GetObjectRef(pid) ;
1295   else {
1296     cerr << "ERROR: AliPHOSGetter::PIDRef -> Task //" << fTasksFolder->GetName() << "/Reconstructioner/PHOS/PID/" <<  name << " not found!" << endl;
1297     abort() ;
1298   }
1299   
1300
1301
1302 //____________________________________________________________________________ 
1303 Bool_t AliPHOSGetter::PostQA(void) const 
1304 { // ------------------ QA ---------------------------------
1305
1306   // the hierarchy is //Folders/Run/Conditions/QA/PHOS/alarmsName
1307
1308   TFolder * phosFolder = dynamic_cast<TFolder*>(fQAFolder->FindObject("PHOS")) ; 
1309   if ( !phosFolder ) {
1310     if (fDebug) {
1311       cout << "WARNING: AliPHOSGetter::Post Q -> Folder //" << fQAFolder << "/PHOS/ not found!" << endl;
1312       cout << "INFO:    AliPHOSGetter::Post Q -> Adding Folder //" << fQAFolder << "/PHOS/" << endl;
1313     }
1314     phosFolder = fQAFolder->AddFolder("PHOS", "QA from PHOS") ; 
1315   }      
1316
1317   return kTRUE;
1318 }
1319
1320 //____________________________________________________________________________ 
1321 TObject** AliPHOSGetter::AlarmsRef(void) const 
1322 {  //------- Alarms ----------------------
1323
1324   
1325   // the hierarchy is //Folders/Run/Conditions/QA/PHOS
1326   if ( !fQAFolder ) {
1327     cerr << "ERROR: AliPHOSGetter::AlarmsRef -> Folder //" << fQAFolder << " not found!" << endl;
1328     abort() ;
1329   }    
1330  
1331   TFolder * phosFolder = dynamic_cast<TFolder *>(fQAFolder->FindObject("PHOS")) ;
1332   if ( !phosFolder ) {
1333     cerr << "ERROR: AliPHOSGetter::AlarmsRef -> Folder //" << fQAFolder << "/PHOS/ not found!" << endl;
1334     abort() ;
1335   }
1336    
1337   return fQAFolder->GetListOfFolders()->GetObjectRef(phosFolder) ;
1338 }
1339
1340
1341 //____________________________________________________________________________ 
1342 TTree * AliPHOSGetter::TreeK(TString filename)  
1343 {
1344
1345   // returns TreeK from file filename
1346   // usefull in case of split file
1347
1348   if ( filename.IsNull() ) 
1349     filename = fHeaderFile ; 
1350
1351   TFile * file = 0 ; 
1352   file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
1353   if (file && (filename != fHeaderFile) ) {  // file already open 
1354     file->Close() ; 
1355     delete fAlice ; 
1356   }    
1357   file = TFile::Open(filename.Data(), "read") ; 
1358   fAlice = static_cast<AliRun *>(file->Get("gAlice")) ; 
1359   TString treeName("TreeK") ; 
1360   treeName += EventNumber()  ; 
1361   TTree * tree = static_cast<TTree *>(file->Get(treeName.Data())) ;
1362   if (!tree && fDebug)  
1363     cout << "WARNING: AliPHOSGetter::TreeK -> " << treeName.Data() << " not found in " << filename.Data() << endl ; 
1364   
1365   return tree ;                       
1366 }
1367
1368 //____________________________________________________________________________ 
1369 TTree * AliPHOSGetter::TreeH(TString filename)  
1370 {
1371
1372   // returns TreeH from file filename
1373   // usefull in case of split file
1374
1375   if ( filename.IsNull() ) 
1376     filename = fHeaderFile ; 
1377
1378   TFile * file = 0 ; 
1379   file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
1380   if (!file) { // file not open yet
1381     file = TFile::Open(filename.Data(), "read") ; 
1382   }
1383   TString treeName("TreeH") ; 
1384   treeName += EventNumber()  ; 
1385   TTree * tree = static_cast<TTree *>(file->Get(treeName.Data())) ;
1386   if (!tree && fDebug)  
1387     cout << "WARNING: AliPHOSGetter::TreeH -> " << treeName.Data() << " not found in " << filename.Data() << endl ; 
1388   
1389   return tree ;                       
1390 }
1391
1392 //____________________________________________________________________________ 
1393 TTree * AliPHOSGetter::TreeS(TString filename)  
1394 {
1395
1396   // returns TreeS from file filename
1397   // usefull in case of split file
1398
1399   if ( filename.IsNull() ) 
1400     filename = fHeaderFile ; 
1401
1402   TFile * file = 0 ; 
1403   file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
1404   if (!file) { // file not open yet
1405     file = TFile::Open(filename.Data(), "read") ; 
1406   }
1407   TString treeName("TreeS") ; 
1408   treeName += EventNumber()  ; 
1409   TTree * tree = static_cast<TTree *>(file->Get(treeName.Data())) ;
1410   if (!tree && fDebug)  
1411     cout << "WARNING: AliPHOSGetter::TreeS -> " << treeName.Data() << " not found in " << filename.Data() << endl ; 
1412   
1413   return tree ;                       
1414 }
1415
1416 //____________________________________________________________________________ 
1417 TTree * AliPHOSGetter::TreeD(TString filename)  
1418 {
1419
1420   // returns TreeD from file filename
1421   // usefull in case of split file
1422
1423   if ( filename.IsNull() ) 
1424     filename = fHeaderFile ; 
1425
1426   TFile * file = 0 ; 
1427   file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
1428   if (!file) { // file not open yet
1429     file = TFile::Open(filename.Data(), "read") ; 
1430   }
1431   TString treeName("TreeD") ; 
1432   treeName += EventNumber()  ; 
1433   TTree * tree = static_cast<TTree *>(file->Get(treeName.Data())) ;
1434   if (!tree && fDebug)  
1435     cout << "WARNING: AliPHOSGetter::TreeD -> " << treeName.Data() << " not found in " << filename.Data() << endl ; 
1436   
1437   return tree ;                       
1438 }
1439
1440 //____________________________________________________________________________ 
1441 const TParticle * AliPHOSGetter::Primary(Int_t index) 
1442 {
1443   // Return primary particle numbered by <index>
1444
1445   if(index < 0) 
1446     return 0 ;
1447   TParticle *  p = 0 ;
1448   if (fAlice) 
1449     p = fAlice->Particle(index) ; 
1450   else 
1451     p = gAlice->Particle(index) ; 
1452   //   if (p->GetFirstMother() != -1 ) {
1453   //     cout << "AliPHOSGetter::Primary : Not a primary " << endl ; 
1454   //   }
1455   
1456   return p ; 
1457     
1458   
1459   
1460   //   Int_t primaryIndex = index % 10000000 ; 
1461 //   Int_t primaryList = (Int_t ) ((index-primaryIndex)/10000000.)  ;
1462   
1463 //   if ( primaryList > 0  ) {
1464 //     if (fDebug) {
1465 //       cout << " Getter does not support currently Mixing of primary " << endl ;
1466 //       cout << "   can not return primary: " << index<< " (list "<< primaryList<< " primary # " << primaryIndex << " )"<<endl ;
1467 //     }
1468 //     return 0;
1469 //   }
1470   
1471 //   return gAlice->Particle(primaryIndex) ;
1472   
1473 }
1474
1475 //____________________________________________________________________________ 
1476 const TParticle * AliPHOSGetter::Secondary(TParticle* p, Int_t index) const
1477 {
1478   // Return first (index=1) or second (index=2) secondary particle of primary particle p 
1479
1480   if(index <= 0) 
1481     return 0 ;
1482   if(index > 2)
1483     return 0 ;
1484
1485   if(p) {
1486   Int_t daughterIndex = p->GetDaughter(index-1) ; 
1487   return  gAlice->Particle(daughterIndex) ; 
1488   }
1489   else
1490     return 0 ;
1491 }
1492
1493 //____________________________________________________________________________ 
1494 Int_t AliPHOSGetter::ReadTreeD()
1495 {
1496   // Read the digit tree gAlice->TreeD()  
1497   
1498   TTree * treeD = gAlice->TreeD() ;
1499
1500   if(!treeD) { // TreeD not found in header file
1501     
1502     if (fDebug) 
1503       cout <<   "WARNING: AliPHOSGetter::ReadTreeD -> Cannot find TreeD in " << fHeaderFile << endl ;
1504     
1505     TString searchFileName("") ; 
1506     
1507     if (Digitizer())  // Digitizer found in header file
1508       searchFileName = Digitizer()->GetTitle() ; 
1509     
1510     else if (Clusterizer())  // Clusterizer found in header file
1511       searchFileName = Clusterizer()->GetDigitsFileName() ; 
1512     
1513     if ( (treeD = TreeD(searchFileName)) ) { //found TreeD in the file which contains the hits
1514       if (fDebug) 
1515         cout << "INFO: AliPHOSGetter::ReadTreeD -> TreeD found in " << searchFileName.Data() << endl ; 
1516       
1517     } else {
1518       cerr << "ERROR: AliPHOSGetter::ReadTreeD -> TreeD not found " << endl ; 
1519       return 1;
1520     }   
1521   }
1522   
1523   TObjArray * lob = static_cast<TObjArray*>(treeD->GetListOfBranches()) ;
1524   TIter next(lob) ; 
1525   TBranch * branch = 0 ; 
1526   TBranch * digitsbranch = 0 ; 
1527   TBranch * digitizerbranch = 0 ; 
1528   Bool_t phosfound = kFALSE, digitizerfound = kFALSE ; 
1529   
1530   while ( (branch = static_cast<TBranch*>(next())) && (!phosfound || !digitizerfound) ) {
1531     if ( (strcmp(branch->GetName(), "PHOS")==0) && (strcmp(branch->GetTitle(), fDigitsTitle)==0) ) {
1532       digitsbranch = branch ; 
1533       phosfound = kTRUE ;
1534     }
1535     else if ( (strcmp(branch->GetName(), "AliPHOSDigitizer")==0) && (strcmp(branch->GetTitle(), fDigitsTitle)==0) ) {
1536       digitizerbranch = branch ; 
1537       digitizerfound = kTRUE ; 
1538     }
1539   }
1540
1541   if ( !phosfound || !digitizerfound ) {
1542     if (fDebug)
1543       cout << "WARNING: AliPHOSGetter::ReadTreeD -> Cannot find Digits and/or Digitizer with name " 
1544            << fDigitsTitle << endl ;
1545     return 2; 
1546   }   
1547  
1548   //read digits
1549   if(!Digits(fDigitsTitle) ) 
1550     PostDigits(fDigitsTitle);
1551   digitsbranch->SetAddress(DigitsRef(fDigitsTitle)) ;
1552   digitsbranch->GetEntry(0) ;
1553   
1554   
1555   // read  the Digitizer
1556   RemoveTask("D", fDigitsTitle) ; // I do not understand why I need that 
1557   if(!Digitizer(fDigitsTitle))
1558     PostDigitizer(fDigitsTitle) ;
1559   digitizerbranch->SetAddress(DigitizerRef(fDigitsTitle)) ;
1560   digitizerbranch->GetEntry(0) ;
1561  
1562   return 0 ; 
1563 }
1564
1565 //____________________________________________________________________________ 
1566 Int_t AliPHOSGetter::ReadTreeH()
1567 {
1568   // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
1569   
1570   TTree * treeH = gAlice->TreeH() ;
1571
1572   if(!treeH) {// TreeH not found in header file
1573  
1574     if (fDebug) 
1575       cout <<   "WARNING: AliPHOSGetter::ReadTreeH -> Cannot find TreeH in " << fHeaderFile << endl ;
1576     
1577     TString searchFileName("") ; 
1578     
1579     if (SDigitizer())  // SDigitizer found in header file
1580         searchFileName = SDigitizer()->GetTitle() ;
1581  
1582     else if (Digitizer())  // Digitizer found in header file
1583       searchFileName = Digitizer()->GetHitsFileName() ; 
1584     
1585     else if (Clusterizer())  // Clusterizer found in header file
1586       searchFileName = Clusterizer()->GetHitsFileName() ; 
1587       
1588     if ( (treeH = TreeH(searchFileName)) ) { //found TreeH in the file which contains the hits
1589       if (fDebug) 
1590         cout << "INFO: AliPHOSGetter::ReadTreeH -> TreeH found in " << searchFileName.Data() << endl ; 
1591       
1592     } else {
1593       cerr << "ERROR: AliPHOSGetter::ReadTreeH -> TreeH not found " << endl ; 
1594       return 1;
1595     }  
1596   }
1597   
1598   TBranch * hitsbranch = static_cast<TBranch*>(treeH->GetBranch("PHOS")) ;
1599   if ( !hitsbranch ) {
1600     if (fDebug)
1601       cout << "WARNING:  AliPHOSGetter::ReadTreeH -> Cannot find branch PHOS" << endl ; 
1602     return 2;
1603   }
1604   if(!Hits())
1605     PostHits() ;
1606
1607   if (hitsbranch->GetEntries() > 1 ) {
1608     TClonesArray * tempo =  new TClonesArray("AliPHOSHit",1000) ;
1609     TClonesArray * hits = dynamic_cast<TClonesArray*>(*HitsRef()) ; 
1610     hitsbranch->SetAddress(&tempo) ;
1611     Int_t index = 0 ; 
1612     Int_t i = 0 ;
1613     for (i = 0 ; i < hitsbranch->GetEntries() ; i++) {
1614       hitsbranch->GetEntry(i) ;
1615       Int_t j = 0 ; 
1616       for ( j = 0 ; j < tempo->GetEntries() ; j++) { 
1617         const AliPHOSHit * hit = static_cast<const AliPHOSHit *>(tempo->At(j)) ; 
1618         new((*hits)[index]) AliPHOSHit( *hit ) ;
1619         index++ ; 
1620       }
1621     }
1622     delete tempo ; 
1623   }
1624   else {
1625     hitsbranch->SetAddress(HitsRef()) ;
1626     hitsbranch->GetEntry(0) ;
1627   }
1628   return 0 ; 
1629 }
1630
1631 //____________________________________________________________________________ 
1632 void AliPHOSGetter::Track(Int_t itrack)
1633 {
1634   // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
1635
1636   if(gAlice->TreeH()== 0){
1637     cerr <<   "ERROR: AliPHOSGetter::ReadTreeH: -> Cannot read TreeH " << endl ;
1638     return ;
1639   }
1640   
1641   TBranch * hitsbranch = dynamic_cast<TBranch*>(gAlice->TreeH()->GetListOfBranches()->FindObject("PHOS")) ;
1642   if ( !hitsbranch ) {
1643     if (fDebug)
1644       cout << "WARNING:  AliPHOSGetter::ReadTreeH -> Cannot find branch PHOS" << endl ; 
1645     return ;
1646   }  
1647   if(!Hits())
1648     PostHits() ;
1649
1650   hitsbranch->SetAddress(HitsRef()) ;
1651   hitsbranch->GetEntry(itrack) ;
1652
1653
1654 }
1655 //____________________________________________________________________________ 
1656 void AliPHOSGetter::ReadTreeQA()
1657 {
1658   // Read the digit tree gAlice->TreeQA()
1659   // so far only PHOS knows about this Tree  
1660
1661   if(PHOS()->TreeQA()== 0){
1662     cerr <<   "ERROR: AliPHOSGetter::ReadTreeQA: can not read TreeQA " << endl ;
1663     return ;
1664   }
1665   
1666   TBranch * qabranch = PHOS()->TreeQA()->GetBranch("PHOS") ; 
1667   if (!qabranch) { 
1668     if (fDebug)
1669       cout << "WARNING: AliPHOSGetter::ReadTreeQA -> Cannot find QA Alarms for PHOS" << endl ;
1670     return ; 
1671   }   
1672   
1673   if(!Alarms())
1674     PostQA() ; 
1675
1676   qabranch->SetAddress(AlarmsRef()) ;
1677
1678   qabranch->GetEntry(0) ;
1679  
1680 //   PostQA("PHOS") ; 
1681 //   TFolder * alarmsF = Alarms() ; 
1682 //   alarmsF->Clear() ; 
1683 //   qabranch->SetAddress(&alarmsF) ;
1684 //   qabranch->GetEntry(0) ;
1685   
1686 }
1687
1688 //____________________________________________________________________________ 
1689 Int_t AliPHOSGetter::ReadTreeR(Bool_t any)
1690 {
1691   // Read the reconstrunction tree gAlice->TreeR()
1692   // A particularity has been introduced here :
1693   //  if gime->Event(ievent,"R") is called branches with the current title are read, the current title
1694   //   being for example give in AliPHOSPID(fileName, title)
1695   //  if gime(Event(ievent, "RA") is called the title of the branches is not checked anymore, "A" stands for any
1696   // This is a feature needed by PID to be able to reconstruct several times particles (each time a ther title is given)
1697   // from a given set of TrackSegments (with a given name)
1698   // This is why any is NOT used to read the branch of RecParticles
1699   // any migh have become obsolete : to be checked
1700   // See AliPHOSPIDv1    
1701
1702   if(gAlice->TreeR()== 0){
1703     if (fDebug) 
1704       cout <<   "WARNING: AliPHOSGetter::ReadTreeR -> Cannot find TreeR" << endl ;
1705     return 1;
1706   }
1707   // RecPoints 
1708   TObjArray * lob = static_cast<TObjArray*>(gAlice->TreeR()->GetListOfBranches()) ;
1709   TIter next(lob) ; 
1710   TBranch * branch = 0 ; 
1711   TBranch * emcbranch = 0 ; 
1712   TBranch * cpvbranch = 0 ; 
1713   TBranch * clusterizerbranch = 0 ; 
1714   Bool_t phosemcrpfound = kFALSE, phoscpvrpfound = kFALSE, clusterizerfound = kFALSE ; 
1715
1716   
1717   while ( (branch = static_cast<TBranch*>(next())) && (!phosemcrpfound || !phoscpvrpfound || !clusterizerfound) ) 
1718
1719     if(strcmp(branch->GetTitle(), fRecPointsTitle)==0 || any) {
1720       if ( strcmp(branch->GetName(), "PHOSEmcRP")==0) {
1721         emcbranch = branch ; 
1722         phosemcrpfound = kTRUE ;
1723       }
1724       else if ( strcmp(branch->GetName(), "PHOSCpvRP")==0) {
1725         cpvbranch = branch ; 
1726         phoscpvrpfound = kTRUE ;
1727       }
1728       else if(strcmp(branch->GetName(), "AliPHOSClusterizer")==0){
1729         clusterizerbranch = branch ; 
1730         clusterizerfound = kTRUE ; 
1731       }
1732     }
1733
1734   if ( !phosemcrpfound || !phoscpvrpfound || !clusterizerfound) {
1735     if (fDebug)
1736       cout << "WARNING: AliPHOSGetter::ReadTreeR -> Cannot find RecPoints and/or Clusterizer with name " 
1737            << fRecPointsTitle << endl ;
1738  
1739   } else { 
1740     if(!EmcRecPoints(fRecPointsTitle) ) 
1741       PostRecPoints(fRecPointsTitle) ;
1742     
1743     emcbranch->SetAddress(EmcRecPointsRef(fRecPointsTitle)) ;
1744     emcbranch->GetEntry(0) ;
1745
1746     cpvbranch->SetAddress(CpvRecPointsRef(fRecPointsTitle)) ; 
1747     cpvbranch->GetEntry(0) ;  
1748     
1749     if(!Clusterizer(fRecPointsTitle) ) 
1750       PostClusterizer(fRecPointsTitle) ;
1751     
1752     clusterizerbranch->SetAddress(ClusterizerRef(fRecPointsTitle)) ;
1753     clusterizerbranch->GetEntry(0) ;
1754   }
1755   
1756   //------------------- TrackSegments ---------------------
1757   next.Reset() ; 
1758   TBranch * tsbranch = 0 ; 
1759   TBranch * tsmakerbranch = 0 ; 
1760   Bool_t phostsfound = kFALSE, tsmakerfound = kFALSE ; 
1761     
1762   while ( (branch = static_cast<TBranch*>(next())) && (!phostsfound || !tsmakerfound) ) 
1763     if(strcmp(branch->GetTitle(), fTrackSegmentsTitle)==0 || any)  {
1764       if ( strcmp(branch->GetName(), "PHOSTS")==0){
1765         tsbranch = branch ; 
1766         phostsfound = kTRUE ;
1767       }
1768       else if(strcmp(branch->GetName(), "AliPHOSTrackSegmentMaker")==0) {
1769         tsmakerbranch = branch ; 
1770         tsmakerfound  = kTRUE ; 
1771       }
1772     }
1773   
1774   if ( !phostsfound || !tsmakerfound ) {
1775     if (fDebug)
1776       cout << "WARNING: AliPHOSGetter::ReadTreeR -> Cannot find TrackSegments and/or TrackSegmentMaker with name "
1777            << fTrackSegmentsTitle << endl ;
1778   } else { 
1779     // Read and Post the TrackSegments
1780     if(!TrackSegments(fTrackSegmentsTitle))
1781       PostTrackSegments(fTrackSegmentsTitle) ;
1782     tsbranch->SetAddress(TrackSegmentsRef(fTrackSegmentsTitle)) ;
1783     tsbranch->GetEntry(0) ;
1784     // Read and Post the TrackSegment Maker
1785     if(!TrackSegmentMaker(fTrackSegmentsTitle))
1786       PostTrackSegmentMaker(fTrackSegmentsTitle) ;
1787     tsmakerbranch->SetAddress(TSMakerRef(fTrackSegmentsTitle)) ;
1788     tsmakerbranch->GetEntry(0) ;
1789  }
1790   
1791   
1792   //------------ RecParticles ----------------------------
1793   next.Reset() ; 
1794   TBranch * rpabranch = 0 ; 
1795   TBranch * pidbranch = 0 ; 
1796   Bool_t phosrpafound = kFALSE, pidfound = kFALSE ; 
1797   
1798   while ( (branch = static_cast<TBranch*>(next())) && (!phosrpafound || !pidfound) ) 
1799     if(strcmp(branch->GetTitle(), fRecParticlesTitle)==0) {   
1800       if ( strcmp(branch->GetName(), "PHOSRP")==0) {   
1801         rpabranch = branch ; 
1802         phosrpafound = kTRUE ;
1803       }
1804       else if (strcmp(branch->GetName(), "AliPHOSPID")==0) {
1805         pidbranch = branch ; 
1806         pidfound  = kTRUE ; 
1807       }
1808     }
1809   
1810   if ( !phosrpafound || !pidfound ) {
1811     if (fDebug)
1812       cout << "WARNING: AliPHOSGetter::ReadTreeR -> Cannot find RecParticles and/or PID with name " 
1813            << fRecParticlesTitle << endl ; 
1814   } else { 
1815     // Read and Post the RecParticles
1816     if(!RecParticles(fRecParticlesTitle)) 
1817       PostRecParticles(fRecParticlesTitle) ;
1818     rpabranch->SetAddress(RecParticlesRef(fRecParticlesTitle)) ;
1819     rpabranch->GetEntry(0) ;
1820     // Read and Post the PID
1821     if(!PID(fRecParticlesTitle))
1822       PostPID(fRecParticlesTitle) ;
1823     pidbranch->SetAddress(PIDRef(fRecParticlesTitle)) ;
1824     pidbranch->GetEntry(0) ;
1825   }
1826   return 0 ; 
1827 }
1828
1829 //____________________________________________________________________________ 
1830 Int_t AliPHOSGetter::ReadTreeS(Int_t event)
1831 {
1832   // Read the summable digits tree gAlice->TreeS()  
1833   
1834   // loop over all opened files and read their SDigits to the White Board
1835   TFolder * phosF = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject("PHOS")) ;
1836   if (!phosF) 
1837     phosF = fSDigitsFolder->AddFolder("PHOS", "SDigits from PHOS") ; 
1838   TCollection * folderslist = phosF->GetListOfFolders() ; 
1839   
1840   //Add current file to list if it is not there yet
1841   
1842   TString subdir(fHeaderFile) ;
1843   subdir.ReplaceAll("/","_") ; 
1844
1845   if ( (subdir != "aliroot") && ( !folderslist->Contains(subdir) ) ){
1846     phosF->AddFolder(subdir, ""); 
1847   }
1848     
1849   TIter next(folderslist) ; 
1850   TFolder * folder = 0 ; 
1851   TFile * file; 
1852   TTree * treeS = 0;
1853   while ( (folder = static_cast<TFolder*>(next())) ) {
1854     TString fileName(folder->GetName()) ; 
1855     fileName.ReplaceAll("_","/") ; 
1856     if(fHeaderFile.CompareTo(fileName) == 0 ) 
1857       treeS=gAlice->TreeS() ;
1858     else{
1859       file = static_cast<TFile*>(gROOT->GetFile(fileName)); 
1860       file->cd() ;
1861       
1862       // Get SDigits Tree header from file
1863       TString treeName("TreeS") ;
1864       treeName += event ; 
1865       treeS = dynamic_cast<TTree*>(gDirectory->Get(treeName.Data()));
1866     }
1867     if(!treeS){ // TreeS not found in header file
1868
1869       if (fDebug)
1870         cout << "WARNING: AliPHOSGetter::ReadTreeS -> Cannot find TreeS in " << fHeaderFile << endl;
1871     
1872       TString searchFileName("") ; 
1873
1874       if (SDigitizer())  // SDigitizer found in header file
1875         searchFileName = SDigitizer()->GetTitle() ;
1876  
1877       else if (Digitizer())  // Digitizer found in header file
1878         searchFileName = Digitizer()->GetSDigitsFileName() ; 
1879       
1880       else if (Clusterizer())  // Clusterizer found in header file
1881         searchFileName = Clusterizer()->GetSDigitsFileName() ; 
1882       
1883       if ( (treeS = TreeS(searchFileName)) ) { //found TreeS in the file which contains the hits
1884         if (fDebug) 
1885           cout << "INFO: AliPHOSGetter::ReadTreeS -> TreeS found in " << searchFileName.Data() << endl ; 
1886         
1887       } else {
1888       cerr << "ERROR: AliPHOSGetter::ReadTreeS -> TreeS not found " << endl ; 
1889       return 1;
1890       }
1891     }
1892     
1893     //set address of the SDigits and SDigitizer
1894     TBranch   * sdigitsBranch    = 0;
1895     TBranch   * sdigitizerBranch = 0;
1896     TBranch   * branch           = 0 ;  
1897     TObjArray * lob = static_cast<TObjArray*>(treeS->GetListOfBranches()) ;
1898     TIter next(lob) ; 
1899     Bool_t phosfound = kFALSE, sdigitizerfound = kFALSE ; 
1900     
1901     while ( (branch = static_cast<TBranch*>(next())) && (!phosfound || !sdigitizerfound) ) {
1902       if ( (strcmp(branch->GetName(), "PHOS")==0) && (strcmp(branch->GetTitle(), fSDigitsTitle)==0) ) {
1903         phosfound = kTRUE ;
1904         sdigitsBranch = branch ; 
1905       }
1906       
1907       else if ( (strcmp(branch->GetName(), "AliPHOSSDigitizer")==0) && (strcmp(branch->GetTitle(), fSDigitsTitle)==0) ) {
1908         sdigitizerfound = kTRUE ; 
1909         sdigitizerBranch = branch ;
1910       }
1911     }
1912     if ( !phosfound || !sdigitizerfound ) {
1913       if (fDebug)
1914         cout << "WARNING: AliPHOSDigitizer::ReadSDigits -> Digits and/or Digitizer branch with name " << GetName() 
1915              << " not found" << endl ;
1916       return 2; 
1917     }   
1918     
1919     if ( !folder->FindObject(fSDigitsTitle) )  
1920       PostSDigits(fSDigitsTitle,folder->GetName()) ;
1921
1922     sdigitsBranch->SetAddress(SDigitsRef(fSDigitsTitle,folder->GetName())) ;
1923     sdigitsBranch->GetEntry(0) ;
1924     
1925     TString sdname(fSDigitsTitle) ;
1926     sdname+=":" ;
1927     sdname+=folder->GetName() ;
1928     if(!SDigitizer(sdname) ) 
1929       PostSDigitizer(fSDigitsTitle,folder->GetName()) ;
1930     sdigitizerBranch->SetAddress(SDigitizerRef(sdname)) ;
1931     sdigitizerBranch->GetEntry(0) ; 
1932   }    
1933   
1934 // After SDigits have been read from all files, return to the first one
1935
1936   next.Reset();
1937   folder = static_cast<TFolder*>(next());
1938   if(folder){
1939     TString fileName(folder->GetName()) ; 
1940     fileName.ReplaceAll("_","/") ; 
1941     file   = static_cast<TFile*>(gROOT->GetFile(fileName)); 
1942     file   ->cd() ;
1943   }
1944   return 0 ; 
1945 }
1946 //____________________________________________________________________________ 
1947 void AliPHOSGetter::ReadTreeS(TTree * treeS, Int_t input)
1948 {  // Read the summable digits fron treeS()  
1949
1950
1951   TString filename("mergefile") ;
1952   filename+= input ;
1953
1954   TFolder * phosFolder = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("PHOS")) ; 
1955   if ( !phosFolder ) { 
1956    phosFolder = fSDigitsFolder->AddFolder("PHOS", "SDigits from PHOS") ; 
1957   } 
1958   TFolder * folder=(TFolder*)phosFolder->FindObject(filename) ;
1959   //set address of the SDigits and SDigitizer
1960   TBranch   * sdigitsBranch    = 0;
1961   TBranch   * sdigitizerBranch = 0;
1962   TBranch   * branch           = 0 ;  
1963   TObjArray * lob = (TObjArray*)treeS->GetListOfBranches() ;
1964   TIter next(lob) ; 
1965   Bool_t phosfound = kFALSE, sdigitizerfound = kFALSE ; 
1966   
1967   while ( (branch = (TBranch*)next()) && (!phosfound || !sdigitizerfound) ) {
1968     if ( strcmp(branch->GetName(), "PHOS")==0) {
1969       phosfound = kTRUE ;
1970       sdigitsBranch = branch ; 
1971     }
1972     
1973     else if ( strcmp(branch->GetName(), "AliPHOSSDigitizer")==0) {
1974       sdigitizerfound = kTRUE ; 
1975       sdigitizerBranch = branch ;
1976     }
1977   }
1978   if ( !phosfound || !sdigitizerfound ) {
1979     if (fDebug)
1980       cout << "WARNING: AliPHOSGetter::ReadTreeS -> Digits and/or Digitizer branch not found" << endl ;
1981     return ; 
1982   }   
1983   
1984   if (!folder || !(folder->FindObject(sdigitsBranch->GetTitle()) ) )
1985     PostSDigits(sdigitsBranch->GetTitle(),filename) ;
1986
1987   sdigitsBranch->SetAddress(SDigitsRef(sdigitsBranch->GetTitle(),filename)) ;
1988   sdigitsBranch->GetEntry(0) ;
1989   
1990   TString sdname(sdigitsBranch->GetTitle()) ;
1991   sdname+=":" ;
1992   sdname+=filename ;
1993   
1994   if(!SDigitizer(sdigitsBranch->GetTitle()) )
1995     PostSDigitizer(sdigitsBranch->GetTitle(),filename) ;
1996   sdigitizerBranch->SetAddress(SDigitizerRef(sdname)) ;
1997   sdigitizerBranch->GetEntry(0) ;
1998 }    
1999
2000
2001 //____________________________________________________________________________ 
2002 void AliPHOSGetter::ReadPrimaries()
2003 {
2004   // a lot simplified.... if 2 files are opened then we have a problem
2005
2006   TClonesArray * ar = 0  ; 
2007   if(! (ar = Primaries()) ) { 
2008     PostPrimaries() ;
2009     ar = Primaries() ; 
2010   }
2011   ar->Delete() ; 
2012   
2013   if (TreeK(fHeaderFile)) { // treeK found in header file
2014     if (fDebug) 
2015       cout << "INFO: AliPHOSGetter::ReadPrimaries -> TreeK found in " << fHeaderFile.Data() << endl ; 
2016     fNPrimaries = gAlice->GetNtrack() ; 
2017     fAlice = 0 ; 
2018   
2019   } else { // treeK not found in header file
2020
2021     TString searchFileName("") ; 
2022
2023     if (SDigitizer())  // SDigitizer found in header file
2024       searchFileName = SDigitizer()->GetTitle() ;
2025
2026     else if (Digitizer())  // Digitizer found in header file
2027       searchFileName = Digitizer()->GetHitsFileName() ; 
2028
2029     else if (Clusterizer())  // Clusterizer found in header file
2030       searchFileName = Clusterizer()->GetHitsFileName() ; 
2031     
2032     if (TreeK(searchFileName)) { //found TreeK in the file which contains the hits
2033       if (fDebug) 
2034         cout << "INFO: AliPHOSGetter::ReadPrimaries -> TreeK found in " << searchFileName.Data() << endl ; 
2035       fAlice->GetEvent(EventNumber()) ; 
2036       fNPrimaries = fAlice->GetNtrack() ; 
2037       
2038     } else {
2039       cerr << "ERROR: AliPHOSGetter::ReadPrimaries -> TreeK not  found " << endl ; 
2040       return ;
2041     }
2042     
2043   }
2044   Int_t index = 0 ; 
2045   for (index = 0 ; index < fNPrimaries; index++) { 
2046     new ((*ar)[index]) TParticle(*(Primary(index)));
2047   }
2048 }
2049
2050 //____________________________________________________________________________ 
2051 void AliPHOSGetter::Event(const Int_t event, const char* opt)
2052 {
2053   // Reads the content of all Tree's S, D and R
2054
2055   if (event >= gAlice->TreeE()->GetEntries() ) {
2056     cerr << "ERROR: AliPHOSGetter::Event -> " << event << " not found in TreeE!" << endl ; 
2057     return ; 
2058   }
2059
2060   Bool_t any = kFALSE ; 
2061   if (strstr(opt,"A") ) // do not check the title of the branches
2062     any = kTRUE; 
2063
2064   gAlice->GetEvent(event) ; 
2065
2066   Int_t rvRH = 0 ;
2067   Int_t rvRS = 0 ;
2068   Int_t rvRD = 0 ;
2069   Int_t rvRR = 0 ;
2070
2071   if( strstr(opt,"R") )
2072     rvRR = ReadTreeR(any) ;
2073
2074   if( strstr(opt,"D") )
2075     rvRD = ReadTreeD() ;
2076
2077   if(strstr(opt,"S") )
2078     rvRS = ReadTreeS(event) ;
2079
2080   if(strstr(opt,"H") )
2081     rvRH = ReadTreeH() ;
2082    
2083   if( strstr(opt,"Q") )
2084     ReadTreeQA() ;
2085  
2086   if( strstr(opt,"P") || (strcmp(opt,"")==0) )
2087     ReadPrimaries() ;
2088   
2089 }
2090
2091 //____________________________________________________________________________ 
2092 TObject * AliPHOSGetter::ReturnO(TString what, TString name, TString file) const 
2093 {
2094   // get the object named "what" from the folder
2095   // folders are named like //Folders
2096
2097   if ( file.IsNull() ) 
2098     file = fHeaderFile ; 
2099
2100   TFolder * folder = 0 ;
2101   TObject * phosO  = 0 ; 
2102
2103   //  if ( name.IsNull() ) {
2104   if ( what.CompareTo("Primaries") == 0 ) {
2105     folder = dynamic_cast<TFolder *>(fPrimariesFolder->FindObject("Primaries")) ; 
2106     if (folder) 
2107       phosO  = dynamic_cast<TObject *>(folder->FindObject("Primaries")) ;  
2108     else 
2109       return 0 ; 
2110   }
2111   else if ( what.CompareTo("Hits") == 0 ) {
2112     folder = dynamic_cast<TFolder *>(fHitsFolder->FindObject("PHOS")) ; 
2113     if (folder) 
2114       phosO  = dynamic_cast<TObject *>(folder->FindObject("Hits")) ;  
2115   }
2116   else if ( what.CompareTo("SDigits") == 0 ) {
2117     file.ReplaceAll("/","_") ; 
2118     TString path = "PHOS/" + file  ;
2119     folder = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject(path.Data())) ; 
2120     if (folder) { 
2121       if (name.IsNull())
2122         name = fSDigitsTitle ; 
2123       phosO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
2124     }
2125   }
2126   else if ( what.CompareTo("Digits") == 0 ){
2127     folder = dynamic_cast<TFolder *>(fDigitsFolder->FindObject("PHOS")) ; 
2128     if (folder) { 
2129       if (name.IsNull())
2130         name = fDigitsTitle ; 
2131       phosO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
2132     } 
2133   }
2134   else if ( what.CompareTo("EmcRecPoints") == 0 ) {
2135     folder = dynamic_cast<TFolder *>(fRecoFolder->FindObject("PHOS/EMCARecPoints")) ; 
2136     if (folder) { 
2137       if (name.IsNull())
2138         name = fRecPointsTitle ; 
2139       phosO  = dynamic_cast<TObject *>(folder->FindObject(name)) ;
2140     } 
2141   }
2142   else if ( what.CompareTo("CpvRecPoints") == 0 ) {
2143     folder = dynamic_cast<TFolder *>(fRecoFolder->FindObject("PHOS/CPVRecPoints")) ; 
2144     if (folder) { 
2145       if (name.IsNull())
2146         name = fRecPointsTitle ; 
2147       phosO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
2148     }   
2149   }
2150   else if ( what.CompareTo("TrackSegments") == 0 ) {
2151     folder = dynamic_cast<TFolder *>(fRecoFolder->FindObject("PHOS/TrackSegments")) ; 
2152     if (folder) { 
2153       if (name.IsNull())
2154         name = fTrackSegmentsTitle ; 
2155       phosO  = dynamic_cast<TObject *>(folder->FindObject(name)) ; 
2156     }   
2157   }
2158   else if ( what.CompareTo("RecParticles") == 0 ) {
2159     folder = dynamic_cast<TFolder *>(fRecoFolder->FindObject("PHOS/RecParticles")) ; 
2160    if (folder) { 
2161       if (name.IsNull())
2162         name = fRecParticlesTitle ; 
2163       phosO  = dynamic_cast<TObject *>(folder->FindObject(name)) ;
2164     }   
2165  }
2166   else if ( what.CompareTo("Alarms") == 0 ){ 
2167     if (name.IsNull() ) 
2168       phosO = dynamic_cast<TObject *>(fQAFolder->FindObject("PHOS")) ;  
2169     else {
2170       folder = dynamic_cast<TFolder *>(fQAFolder->FindObject("PHOS")) ; 
2171       if (!folder) 
2172         phosO = 0 ; 
2173       else 
2174         phosO = dynamic_cast<TObject *>(folder->FindObject(name)) ;  
2175     }
2176   }
2177   if (!phosO) {
2178     if(fDebug)
2179       cerr << "WARNING : AliPHOSGetter::ReturnO -> Object " << what << " not found in PHOS" << endl ; 
2180     return 0 ;
2181   }
2182
2183   return phosO ;
2184 }
2185   
2186 //____________________________________________________________________________ 
2187 const TTask * AliPHOSGetter::ReturnT(TString what, TString name) const 
2188 {
2189   // get the TTask named "what" from the folder
2190   // folders are named like //Folders/Tasks/what/PHOS/name
2191
2192   TString search(what) ; 
2193   if ( what.CompareTo("Clusterizer") == 0 ) 
2194     search = "Reconstructioner" ; 
2195   else if ( what.CompareTo("TrackSegmentMaker") == 0 ) 
2196     search = "Reconstructioner" ; 
2197   else if ( what.CompareTo("PID") == 0 ) 
2198     search = "Reconstructioner" ; 
2199   else if ( what.CompareTo("QATasks") == 0 ) 
2200     search = "QA" ; 
2201
2202   TTask * tasks = dynamic_cast<TTask*>(fTasksFolder->FindObject(search)) ; 
2203
2204   if (!tasks) {
2205     cerr << "ERROR: AliPHOSGetter::ReturnT -> Task " << what << " not found!" << endl ;  
2206     return 0 ; 
2207   }
2208
2209   TTask * phosT = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("PHOS")) ; 
2210   if (!phosT) { 
2211     cerr << "ERROR: AliPHOSGetter::ReturnT -> Task " << what << "/PHOS not found!" << endl ;  
2212     return 0 ; 
2213   }
2214   
2215   TList * list = phosT->GetListOfTasks() ; 
2216  
2217   if (what.CompareTo("SDigitizer") == 0) {  
2218     if ( name.IsNull() )
2219       name =  fSDigitsTitle ; 
2220   } else  if (what.CompareTo("Digitizer") == 0){ 
2221     if ( name.IsNull() )
2222       name =  fDigitsTitle ;
2223   } else  if (what.CompareTo("Clusterizer") == 0){ 
2224     if ( name.IsNull() )
2225       name =  fRecPointsTitle ;
2226     name.Append(":clu") ;
2227   }
2228   else  if (what.CompareTo("TrackSegmentMaker") == 0){ 
2229     if ( name.IsNull() )
2230       name =  fTrackSegmentsTitle ;
2231     name.Append(":tsm") ;
2232   }
2233   else  if (what.CompareTo("PID") == 0){ 
2234     if ( name.IsNull() )
2235       name =  fRecParticlesTitle ;
2236     name.Append(":pid") ;
2237   }
2238   else  if (what.CompareTo("QATasks") == 0){ 
2239     if ( name.IsNull() )
2240       return phosT ;
2241   }
2242   
2243   TIter it(list) ;
2244   TTask * task = 0 ; 
2245   while((task = static_cast<TTask *>(it.Next()) )){
2246     TString taskname(task->GetName()) ;
2247     if(taskname.BeginsWith(name))
2248       return task ;
2249   }
2250   
2251   if(fDebug)
2252     cout << "WARNING: AliPHOSGetter::ReturnT -> Task " << search << "/PHOS/" << name << " not found!" << endl ; 
2253   return 0 ;
2254 }
2255
2256 //____________________________________________________________________________ 
2257 void AliPHOSGetter::RemoveTask(TString opt, TString name) const 
2258 {
2259   // remove a task from the folder
2260   // path is fTasksFolder/SDigitizer/PHOS/name
2261   
2262   TTask * task = 0 ; 
2263   TTask * phos = 0 ; 
2264   TList * lofTasks = 0 ; 
2265
2266   if (opt == "S") { // SDigitizer
2267     task = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ;
2268     if (!task) 
2269       return ; 
2270   }
2271   else if (opt == "D") { // Digitizer
2272     task = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ;
2273     if (!task) 
2274       return ; 
2275   }
2276   else if (opt == "C" || opt == "T" || opt == "P"  ) { // Clusterizer, TrackSegmentMaker, PID
2277     task = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ;
2278     if (!task) 
2279       return ; 
2280   }
2281   else {
2282     cerr << "WARNING: AliPHOSGetter::RemoveTask -> Unknown option " << opt.Data() << endl ; 
2283     return ; 
2284   }
2285   phos =  dynamic_cast<TTask*>(task->GetListOfTasks()->FindObject("PHOS")) ;
2286   if (!phos)
2287     return ; 
2288   lofTasks = phos->GetListOfTasks() ;
2289   if (!lofTasks) 
2290     return ; 
2291   TObject * obj = lofTasks->FindObject(name) ; 
2292   if (obj) 
2293     lofTasks->Remove(obj) ;
2294    
2295 }
2296
2297 //____________________________________________________________________________ 
2298 void AliPHOSGetter::RemoveObjects(TString opt, TString name) const 
2299 {
2300   // remove SDigits from the folder
2301   // path is fSDigitsFolder/fHeaderFileName/name
2302
2303   TFolder * phos     = 0 ; 
2304   TFolder * phosmain = 0 ; 
2305
2306   if (opt == "H") { // Hits
2307     phos = dynamic_cast<TFolder*>(fHitsFolder->FindObject("PHOS")) ;
2308     if (!phos) 
2309       return ;
2310     name = "Hits" ; 
2311   }
2312
2313   else if ( opt == "S") { // SDigits
2314     phosmain = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("PHOS")) ;
2315     if (!phosmain) 
2316       return ;
2317     phos = dynamic_cast<TFolder*>(phosmain->FindObject(fHeaderFile)) ;
2318     if (!phos) 
2319       return ;
2320   }
2321   
2322   else if (opt == "D") { // Digits
2323     phos = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("PHOS")) ;
2324     if (!phos) 
2325       return ;
2326   }
2327
2328   else if (opt == "RE") { // EMCARecPoints
2329     phos = dynamic_cast<TFolder*>(fRecoFolder->FindObject("PHOS/EMCARecPoints")) ;
2330     if (!phos) 
2331       return ;
2332   }
2333
2334   else if (opt == "RC") { // CPVRecPoints
2335     phos = dynamic_cast<TFolder*>(fRecoFolder->FindObject("PHOS/CPVRecPoints")) ;
2336     if (!phos) 
2337       return ;
2338   }  
2339
2340   else if (opt == "T") { // TrackSegments
2341     phos = dynamic_cast<TFolder*>(fRecoFolder->FindObject("PHOS/TrackSegments")) ;
2342     if (!phos) 
2343       return ;
2344   }
2345
2346   else if (opt == "P") { // RecParticles
2347     phos = dynamic_cast<TFolder*>(fRecoFolder->FindObject("PHOS/RecParticles")) ;
2348     if (!phos) 
2349       return ;
2350   }
2351   
2352   else {
2353     cerr << "WARNING: AliPHOSGetter::RemoveObjects -> Unknown option " << opt.Data() << endl ; 
2354     return ; 
2355   }
2356   
2357   TObjArray * ar  = dynamic_cast<TObjArray*>(phos->FindObject(name)) ; 
2358   if (ar) { 
2359     phos->Remove(ar) ;
2360     ar->Delete() ; 
2361     delete ar ; 
2362   }
2363
2364   if (opt == "S") 
2365     phosmain->Remove(phos) ; 
2366   
2367 }
2368
2369 //____________________________________________________________________________ 
2370 void AliPHOSGetter::RemoveSDigits() const 
2371 {
2372   TFolder * phos= dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("PHOS")) ;
2373   if (!phos) 
2374     return ;
2375   
2376   phos->SetOwner() ; 
2377   phos->Clear() ; 
2378 }