]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/AliPHOSGetter.cxx
Added a collaborative work between Getter and Tasks (Digitizer and Clustrizer) so...
[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) {  // file not open yet
1354     //   file->Close() ; 
1355     file = TFile::Open(filename.Data(), "read") ; 
1356     delete fAlice ; 
1357     fAlice = static_cast<AliRun *>(file->Get("gAlice")) ; 
1358   }
1359
1360   TString treeName("TreeK") ; 
1361   treeName += EventNumber()  ; 
1362   TTree * tree = static_cast<TTree *>(file->Get(treeName.Data())) ;
1363   if (!tree && fDebug)  
1364     cout << "WARNING: AliPHOSGetter::TreeK -> " << treeName.Data() << " not found in " << filename.Data() << endl ; 
1365   
1366   return tree ;                       
1367 }
1368
1369 //____________________________________________________________________________ 
1370 TTree * AliPHOSGetter::TreeH(TString filename)  
1371 {
1372
1373   // returns TreeH from file filename
1374   // usefull in case of split file
1375
1376   if ( filename.IsNull() ) 
1377     filename = fHeaderFile ; 
1378
1379   TFile * file = 0 ; 
1380   file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
1381   if (!file) { // file not open yet
1382     file = TFile::Open(filename.Data(), "read") ; 
1383   }
1384   TString treeName("TreeH") ; 
1385   treeName += EventNumber()  ; 
1386   TTree * tree = static_cast<TTree *>(file->Get(treeName.Data())) ;
1387   if (!tree && fDebug)  
1388     cout << "WARNING: AliPHOSGetter::TreeH -> " << treeName.Data() << " not found in " << filename.Data() << endl ; 
1389   
1390   return tree ;                       
1391 }
1392
1393 //____________________________________________________________________________ 
1394 TTree * AliPHOSGetter::TreeS(TString filename)  
1395 {
1396
1397   // returns TreeS from file filename
1398   // usefull in case of split file
1399
1400   if ( filename.IsNull() ) 
1401     filename = fHeaderFile ; 
1402
1403   TFile * file = 0 ; 
1404   file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
1405   if (!file) { // file not open yet
1406     file = TFile::Open(filename.Data(), "read") ; 
1407   }
1408   TString treeName("TreeS") ; 
1409   treeName += EventNumber()  ; 
1410   TTree * tree = static_cast<TTree *>(file->Get(treeName.Data())) ;
1411   if (!tree && fDebug)  
1412     cout << "WARNING: AliPHOSGetter::TreeS -> " << treeName.Data() << " not found in " << filename.Data() << endl ; 
1413   
1414   return tree ;                       
1415 }
1416
1417 //____________________________________________________________________________ 
1418 TTree * AliPHOSGetter::TreeD(TString filename)  
1419 {
1420
1421   // returns TreeD from file filename
1422   // usefull in case of split file
1423
1424   if ( filename.IsNull() ) 
1425     filename = fHeaderFile ; 
1426
1427   TFile * file = 0 ; 
1428   file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
1429   if (!file) { // file not open yet
1430     file = TFile::Open(filename.Data(), "read") ; 
1431   }
1432   TString treeName("TreeD") ; 
1433   treeName += EventNumber()  ; 
1434   TTree * tree = static_cast<TTree *>(file->Get(treeName.Data())) ;
1435   if (!tree && fDebug)  
1436     cout << "WARNING: AliPHOSGetter::TreeD -> " << treeName.Data() << " not found in " << filename.Data() << endl ; 
1437   
1438   return tree ;                       
1439 }
1440
1441 //____________________________________________________________________________ 
1442 const TParticle * AliPHOSGetter::Primary(Int_t index) 
1443 {
1444   // Return primary particle numbered by <index>
1445
1446   if(index < 0) 
1447     return 0 ;
1448   TParticle *  p = 0 ;
1449   if (fAlice) 
1450     p = fAlice->Particle(index) ; 
1451   else 
1452     p = gAlice->Particle(index) ; 
1453   //   if (p->GetFirstMother() != -1 ) {
1454   //     cout << "AliPHOSGetter::Primary : Not a primary " << endl ; 
1455   //   }
1456   
1457   return p ; 
1458     
1459   
1460   
1461   //   Int_t primaryIndex = index % 10000000 ; 
1462 //   Int_t primaryList = (Int_t ) ((index-primaryIndex)/10000000.)  ;
1463   
1464 //   if ( primaryList > 0  ) {
1465 //     if (fDebug) {
1466 //       cout << " Getter does not support currently Mixing of primary " << endl ;
1467 //       cout << "   can not return primary: " << index<< " (list "<< primaryList<< " primary # " << primaryIndex << " )"<<endl ;
1468 //     }
1469 //     return 0;
1470 //   }
1471   
1472 //   return gAlice->Particle(primaryIndex) ;
1473   
1474 }
1475
1476 //____________________________________________________________________________ 
1477 const TParticle * AliPHOSGetter::Secondary(TParticle* p, Int_t index) const
1478 {
1479   // Return first (index=1) or second (index=2) secondary particle of primary particle p 
1480
1481   if(index <= 0) 
1482     return 0 ;
1483   if(index > 2)
1484     return 0 ;
1485
1486   if(p) {
1487   Int_t daughterIndex = p->GetDaughter(index-1) ; 
1488   return  gAlice->Particle(daughterIndex) ; 
1489   }
1490   else
1491     return 0 ;
1492 }
1493
1494 //____________________________________________________________________________ 
1495 Int_t AliPHOSGetter::ReadTreeD()
1496 {
1497   // Read the digit tree gAlice->TreeD()  
1498   
1499   TTree * treeD = gAlice->TreeD() ;
1500
1501   if(!treeD) { // TreeD not found in header file
1502     
1503     if (fDebug) 
1504       cout <<   "WARNING: AliPHOSGetter::ReadTreeD -> Cannot find TreeD in " << fHeaderFile << endl ;
1505     
1506     TString searchFileName("") ; 
1507     
1508     if (Digitizer())  // Digitizer found in header file
1509       searchFileName = Digitizer()->GetTitle() ; 
1510     
1511     else if (Clusterizer())  // Clusterizer found in header file
1512       searchFileName = Clusterizer()->GetDigitsFileName() ; 
1513     
1514     if (treeD = TreeD(searchFileName)) { //found TreeD in the file which contains the hits
1515       if (fDebug) 
1516         cout << "INFO: AliPHOSGetter::ReadTreeD -> TreeD found in " << searchFileName.Data() << endl ; 
1517       
1518     } else {
1519       cerr << "ERROR: AliPHOSGetter::ReadTreeD -> TreeD not found " << endl ; 
1520       return 1;
1521     }   
1522   }
1523   
1524   TObjArray * lob = static_cast<TObjArray*>(treeD->GetListOfBranches()) ;
1525   TIter next(lob) ; 
1526   TBranch * branch = 0 ; 
1527   TBranch * digitsbranch = 0 ; 
1528   TBranch * digitizerbranch = 0 ; 
1529   Bool_t phosfound = kFALSE, digitizerfound = kFALSE ; 
1530   
1531   while ( (branch = static_cast<TBranch*>(next())) && (!phosfound || !digitizerfound) ) {
1532     if ( (strcmp(branch->GetName(), "PHOS")==0) && (strcmp(branch->GetTitle(), fDigitsTitle)==0) ) {
1533       digitsbranch = branch ; 
1534       phosfound = kTRUE ;
1535     }
1536     else if ( (strcmp(branch->GetName(), "AliPHOSDigitizer")==0) && (strcmp(branch->GetTitle(), fDigitsTitle)==0) ) {
1537       digitizerbranch = branch ; 
1538       digitizerfound = kTRUE ; 
1539     }
1540   }
1541
1542   if ( !phosfound || !digitizerfound ) {
1543     if (fDebug)
1544       cout << "WARNING: AliPHOSGetter::ReadTreeD -> Cannot find Digits and/or Digitizer with name " 
1545            << fDigitsTitle << endl ;
1546     return 2; 
1547   }   
1548  
1549   //read digits
1550   if(!Digits(fDigitsTitle) ) 
1551     PostDigits(fDigitsTitle);
1552   digitsbranch->SetAddress(DigitsRef(fDigitsTitle)) ;
1553   digitsbranch->GetEntry(0) ;
1554   
1555   
1556   // read  the Digitizer
1557   RemoveTask("D", fDigitsTitle) ; // I do not understand why I need that 
1558   if(!Digitizer(fDigitsTitle))
1559     PostDigitizer(fDigitsTitle) ;
1560   digitizerbranch->SetAddress(DigitizerRef(fDigitsTitle)) ;
1561   digitizerbranch->GetEntry(0) ;
1562  
1563   return 0 ; 
1564 }
1565
1566 //____________________________________________________________________________ 
1567 Int_t AliPHOSGetter::ReadTreeH()
1568 {
1569   // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
1570   
1571   TTree * treeH = gAlice->TreeH() ;
1572
1573   if(!treeH) {// TreeH not found in header file
1574  
1575     if (fDebug) 
1576       cout <<   "WARNING: AliPHOSGetter::ReadTreeH -> Cannot find TreeH in " << fHeaderFile << endl ;
1577     
1578     TString searchFileName("") ; 
1579     
1580     if (SDigitizer())  // SDigitizer found in header file
1581         searchFileName = SDigitizer()->GetTitle() ;
1582  
1583     else if (Digitizer())  // Digitizer found in header file
1584       searchFileName = Digitizer()->GetHitsFileName() ; 
1585     
1586     else if (Clusterizer())  // Clusterizer found in header file
1587       searchFileName = Clusterizer()->GetHitsFileName() ; 
1588       
1589     if (treeH = TreeH(searchFileName)) { //found TreeH in the file which contains the hits
1590       if (fDebug) 
1591         cout << "INFO: AliPHOSGetter::ReadTreeH -> TreeH found in " << searchFileName.Data() << endl ; 
1592       
1593     } else {
1594       cerr << "ERROR: AliPHOSGetter::ReadTreeH -> TreeH not found " << endl ; 
1595       return 1;
1596     }  
1597   }
1598   
1599   TBranch * hitsbranch = static_cast<TBranch*>(treeH->GetBranch("PHOS")) ;
1600   if ( !hitsbranch ) {
1601     if (fDebug)
1602       cout << "WARNING:  AliPHOSGetter::ReadTreeH -> Cannot find branch PHOS" << endl ; 
1603     return 2;
1604   }
1605   if(!Hits())
1606     PostHits() ;
1607
1608   if (hitsbranch->GetEntries() > 1 ) {
1609     TClonesArray * tempo =  new TClonesArray("AliPHOSHit",1000) ;
1610     TClonesArray * hits = dynamic_cast<TClonesArray*>(*HitsRef()) ; 
1611     hitsbranch->SetAddress(&tempo) ;
1612     Int_t index = 0 ; 
1613     Int_t i = 0 ;
1614     for (i = 0 ; i < hitsbranch->GetEntries() ; i++) {
1615       hitsbranch->GetEntry(i) ;
1616       Int_t j = 0 ; 
1617       for ( j = 0 ; j < tempo->GetEntries() ; j++) { 
1618         const AliPHOSHit * hit = static_cast<const AliPHOSHit *>(tempo->At(j)) ; 
1619         new((*hits)[index]) AliPHOSHit( *hit ) ;
1620         index++ ; 
1621       }
1622     }
1623     delete tempo ; 
1624   }
1625   else {
1626     hitsbranch->SetAddress(HitsRef()) ;
1627     hitsbranch->GetEntry(0) ;
1628   }
1629   return 0 ; 
1630 }
1631
1632 //____________________________________________________________________________ 
1633 void AliPHOSGetter::Track(Int_t itrack)
1634 {
1635   // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
1636
1637   if(gAlice->TreeH()== 0){
1638     cerr <<   "ERROR: AliPHOSGetter::ReadTreeH: -> Cannot read TreeH " << endl ;
1639     return ;
1640   }
1641   
1642   TBranch * hitsbranch = dynamic_cast<TBranch*>(gAlice->TreeH()->GetListOfBranches()->FindObject("PHOS")) ;
1643   if ( !hitsbranch ) {
1644     if (fDebug)
1645       cout << "WARNING:  AliPHOSGetter::ReadTreeH -> Cannot find branch PHOS" << endl ; 
1646     return ;
1647   }  
1648   if(!Hits())
1649     PostHits() ;
1650
1651   hitsbranch->SetAddress(HitsRef()) ;
1652   hitsbranch->GetEntry(itrack) ;
1653
1654
1655 }
1656 //____________________________________________________________________________ 
1657 void AliPHOSGetter::ReadTreeQA()
1658 {
1659   // Read the digit tree gAlice->TreeQA()
1660   // so far only PHOS knows about this Tree  
1661
1662   if(PHOS()->TreeQA()== 0){
1663     cerr <<   "ERROR: AliPHOSGetter::ReadTreeQA: can not read TreeQA " << endl ;
1664     return ;
1665   }
1666   
1667   TBranch * qabranch = PHOS()->TreeQA()->GetBranch("PHOS") ; 
1668   if (!qabranch) { 
1669     if (fDebug)
1670       cout << "WARNING: AliPHOSGetter::ReadTreeQA -> Cannot find QA Alarms for PHOS" << endl ;
1671     return ; 
1672   }   
1673   
1674   if(!Alarms())
1675     PostQA() ; 
1676
1677   qabranch->SetAddress(AlarmsRef()) ;
1678
1679   qabranch->GetEntry(0) ;
1680  
1681 //   PostQA("PHOS") ; 
1682 //   TFolder * alarmsF = Alarms() ; 
1683 //   alarmsF->Clear() ; 
1684 //   qabranch->SetAddress(&alarmsF) ;
1685 //   qabranch->GetEntry(0) ;
1686   
1687 }
1688
1689 //____________________________________________________________________________ 
1690 Int_t AliPHOSGetter::ReadTreeR(Bool_t any)
1691 {
1692   // Read the reconstrunction tree gAlice->TreeR()
1693   // A particularity has been introduced here :
1694   //  if gime->Event(ievent,"R") is called branches with the current title are read, the current title
1695   //   being for example give in AliPHOSPID(fileName, title)
1696   //  if gime(Event(ievent, "RA") is called the title of the branches is not checked anymore, "A" stands for any
1697   // This is a feature needed by PID to be able to reconstruct several times particles (each time a ther title is given)
1698   // from a given set of TrackSegments (with a given name)
1699   // This is why any is NOT used to read the branch of RecParticles
1700   // any migh have become obsolete : to be checked
1701   // See AliPHOSPIDv1    
1702
1703   if(gAlice->TreeR()== 0){
1704     if (fDebug) 
1705       cout <<   "WARNING: AliPHOSGetter::ReadTreeR -> Cannot find TreeR" << endl ;
1706     return 1;
1707   }
1708   // RecPoints 
1709   TObjArray * lob = static_cast<TObjArray*>(gAlice->TreeR()->GetListOfBranches()) ;
1710   TIter next(lob) ; 
1711   TBranch * branch = 0 ; 
1712   TBranch * emcbranch = 0 ; 
1713   TBranch * cpvbranch = 0 ; 
1714   TBranch * clusterizerbranch = 0 ; 
1715   Bool_t phosemcrpfound = kFALSE, phoscpvrpfound = kFALSE, clusterizerfound = kFALSE ; 
1716
1717   
1718   while ( (branch = static_cast<TBranch*>(next())) && (!phosemcrpfound || !phoscpvrpfound || !clusterizerfound) ) 
1719
1720     if(strcmp(branch->GetTitle(), fRecPointsTitle)==0 || any) {
1721       if ( strcmp(branch->GetName(), "PHOSEmcRP")==0) {
1722         emcbranch = branch ; 
1723         phosemcrpfound = kTRUE ;
1724       }
1725       else if ( strcmp(branch->GetName(), "PHOSCpvRP")==0) {
1726         cpvbranch = branch ; 
1727         phoscpvrpfound = kTRUE ;
1728       }
1729       else if(strcmp(branch->GetName(), "AliPHOSClusterizer")==0){
1730         clusterizerbranch = branch ; 
1731         clusterizerfound = kTRUE ; 
1732       }
1733     }
1734
1735   if ( !phosemcrpfound || !phoscpvrpfound || !clusterizerfound) {
1736     if (fDebug)
1737       cout << "WARNING: AliPHOSGetter::ReadTreeR -> Cannot find RecPoints and/or Clusterizer with name " 
1738            << fRecPointsTitle << endl ;
1739  
1740   } else { 
1741     if(!EmcRecPoints(fRecPointsTitle) ) 
1742       PostRecPoints(fRecPointsTitle) ;
1743     
1744     emcbranch->SetAddress(EmcRecPointsRef(fRecPointsTitle)) ;
1745     emcbranch->GetEntry(0) ;
1746
1747     cpvbranch->SetAddress(CpvRecPointsRef(fRecPointsTitle)) ; 
1748     cpvbranch->GetEntry(0) ;  
1749     
1750     if(!Clusterizer(fRecPointsTitle) ) 
1751       PostClusterizer(fRecPointsTitle) ;
1752     
1753     clusterizerbranch->SetAddress(ClusterizerRef(fRecPointsTitle)) ;
1754     clusterizerbranch->GetEntry(0) ;
1755   }
1756   
1757   //------------------- TrackSegments ---------------------
1758   next.Reset() ; 
1759   TBranch * tsbranch = 0 ; 
1760   TBranch * tsmakerbranch = 0 ; 
1761   Bool_t phostsfound = kFALSE, tsmakerfound = kFALSE ; 
1762     
1763   while ( (branch = static_cast<TBranch*>(next())) && (!phostsfound || !tsmakerfound) ) 
1764     if(strcmp(branch->GetTitle(), fTrackSegmentsTitle)==0 || any)  {
1765       if ( strcmp(branch->GetName(), "PHOSTS")==0){
1766         tsbranch = branch ; 
1767         phostsfound = kTRUE ;
1768       }
1769       else if(strcmp(branch->GetName(), "AliPHOSTrackSegmentMaker")==0) {
1770         tsmakerbranch = branch ; 
1771         tsmakerfound  = kTRUE ; 
1772       }
1773     }
1774   
1775   if ( !phostsfound || !tsmakerfound ) {
1776     if (fDebug)
1777       cout << "WARNING: AliPHOSGetter::ReadTreeR -> Cannot find TrackSegments and/or TrackSegmentMaker with name "
1778            << fTrackSegmentsTitle << endl ;
1779   } else { 
1780     // Read and Post the TrackSegments
1781     if(!TrackSegments(fTrackSegmentsTitle))
1782       PostTrackSegments(fTrackSegmentsTitle) ;
1783     tsbranch->SetAddress(TrackSegmentsRef(fTrackSegmentsTitle)) ;
1784     tsbranch->GetEntry(0) ;
1785     // Read and Post the TrackSegment Maker
1786     if(!TrackSegmentMaker(fTrackSegmentsTitle))
1787       PostTrackSegmentMaker(fTrackSegmentsTitle) ;
1788     tsmakerbranch->SetAddress(TSMakerRef(fTrackSegmentsTitle)) ;
1789     tsmakerbranch->GetEntry(0) ;
1790  }
1791   
1792   
1793   //------------ RecParticles ----------------------------
1794   next.Reset() ; 
1795   TBranch * rpabranch = 0 ; 
1796   TBranch * pidbranch = 0 ; 
1797   Bool_t phosrpafound = kFALSE, pidfound = kFALSE ; 
1798   
1799   while ( (branch = static_cast<TBranch*>(next())) && (!phosrpafound || !pidfound) ) 
1800     if(strcmp(branch->GetTitle(), fRecParticlesTitle)==0) {   
1801       if ( strcmp(branch->GetName(), "PHOSRP")==0) {   
1802         rpabranch = branch ; 
1803         phosrpafound = kTRUE ;
1804       }
1805       else if (strcmp(branch->GetName(), "AliPHOSPID")==0) {
1806         pidbranch = branch ; 
1807         pidfound  = kTRUE ; 
1808       }
1809     }
1810   
1811   if ( !phosrpafound || !pidfound ) {
1812     if (fDebug)
1813       cout << "WARNING: AliPHOSGetter::ReadTreeR -> Cannot find RecParticles and/or PID with name " 
1814            << fRecParticlesTitle << endl ; 
1815   } else { 
1816     // Read and Post the RecParticles
1817     if(!RecParticles(fRecParticlesTitle)) 
1818       PostRecParticles(fRecParticlesTitle) ;
1819     rpabranch->SetAddress(RecParticlesRef(fRecParticlesTitle)) ;
1820     rpabranch->GetEntry(0) ;
1821     // Read and Post the PID
1822     if(!PID(fRecParticlesTitle))
1823       PostPID(fRecParticlesTitle) ;
1824     pidbranch->SetAddress(PIDRef(fRecParticlesTitle)) ;
1825     pidbranch->GetEntry(0) ;
1826   }
1827   return 0 ; 
1828 }
1829
1830 //____________________________________________________________________________ 
1831 Int_t AliPHOSGetter::ReadTreeS(Int_t event)
1832 {
1833   // Read the summable digits tree gAlice->TreeS()  
1834   
1835   // loop over all opened files and read their SDigits to the White Board
1836   TFolder * phosF = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject("PHOS")) ;
1837   if (!phosF) 
1838     phosF = fSDigitsFolder->AddFolder("PHOS", "SDigits from PHOS") ; 
1839   TCollection * folderslist = phosF->GetListOfFolders() ; 
1840   
1841   //Add current file to list if it is not there yet
1842   
1843   TString subdir(fHeaderFile) ;
1844   subdir.ReplaceAll("/","_") ; 
1845
1846   if ( (subdir != "aliroot") && ( !folderslist->Contains(subdir) ) ){
1847     phosF->AddFolder(subdir, ""); 
1848   }
1849     
1850   TIter next(folderslist) ; 
1851   TFolder * folder = 0 ; 
1852   TFile * file; 
1853   TTree * treeS = 0;
1854   while ( (folder = static_cast<TFolder*>(next())) ) {
1855     TString fileName(folder->GetName()) ; 
1856     fileName.ReplaceAll("_","/") ; 
1857     if(fHeaderFile.CompareTo(fileName) == 0 ) 
1858       treeS=gAlice->TreeS() ;
1859     else{
1860       file = static_cast<TFile*>(gROOT->GetFile(fileName)); 
1861       file->cd() ;
1862       
1863       // Get SDigits Tree header from file
1864       TString treeName("TreeS") ;
1865       treeName += event ; 
1866       treeS = dynamic_cast<TTree*>(gDirectory->Get(treeName.Data()));
1867     }
1868     if(!treeS){ // TreeS not found in header file
1869
1870       if (fDebug)
1871         cout << "WARNING: AliPHOSGetter::ReadTreeS -> Cannot find TreeS in " << fHeaderFile << endl;
1872     
1873       TString searchFileName("") ; 
1874
1875       if (SDigitizer())  // SDigitizer found in header file
1876         searchFileName = SDigitizer()->GetTitle() ;
1877  
1878       else if (Digitizer())  // Digitizer found in header file
1879         searchFileName = Digitizer()->GetSDigitsFileName() ; 
1880       
1881       else if (Clusterizer())  // Clusterizer found in header file
1882         searchFileName = Clusterizer()->GetSDigitsFileName() ; 
1883       
1884       if (treeS = TreeS(searchFileName)) { //found TreeS in the file which contains the hits
1885         if (fDebug) 
1886           cout << "INFO: AliPHOSGetter::ReadTreeS -> TreeS found in " << searchFileName.Data() << endl ; 
1887         
1888       } else {
1889       cerr << "ERROR: AliPHOSGetter::ReadTreeS -> TreeS not found " << endl ; 
1890       return 1;
1891       }
1892     }
1893     
1894     //set address of the SDigits and SDigitizer
1895     TBranch   * sdigitsBranch    = 0;
1896     TBranch   * sdigitizerBranch = 0;
1897     TBranch   * branch           = 0 ;  
1898     TObjArray * lob = static_cast<TObjArray*>(treeS->GetListOfBranches()) ;
1899     TIter next(lob) ; 
1900     Bool_t phosfound = kFALSE, sdigitizerfound = kFALSE ; 
1901     
1902     while ( (branch = static_cast<TBranch*>(next())) && (!phosfound || !sdigitizerfound) ) {
1903       if ( (strcmp(branch->GetName(), "PHOS")==0) && (strcmp(branch->GetTitle(), fSDigitsTitle)==0) ) {
1904         phosfound = kTRUE ;
1905         sdigitsBranch = branch ; 
1906       }
1907       
1908       else if ( (strcmp(branch->GetName(), "AliPHOSSDigitizer")==0) && (strcmp(branch->GetTitle(), fSDigitsTitle)==0) ) {
1909         sdigitizerfound = kTRUE ; 
1910         sdigitizerBranch = branch ;
1911       }
1912     }
1913     if ( !phosfound || !sdigitizerfound ) {
1914       if (fDebug)
1915         cout << "WARNING: AliPHOSDigitizer::ReadSDigits -> Digits and/or Digitizer branch with name " << GetName() 
1916              << " not found" << endl ;
1917       return 2; 
1918     }   
1919     
1920     if ( !folder->FindObject(fSDigitsTitle) )  
1921       PostSDigits(fSDigitsTitle,folder->GetName()) ;
1922
1923     sdigitsBranch->SetAddress(SDigitsRef(fSDigitsTitle,folder->GetName())) ;
1924     sdigitsBranch->GetEntry(0) ;
1925     
1926     TString sdname(fSDigitsTitle) ;
1927     sdname+=":" ;
1928     sdname+=folder->GetName() ;
1929     if(!SDigitizer(sdname) ) 
1930       PostSDigitizer(fSDigitsTitle,folder->GetName()) ;
1931     sdigitizerBranch->SetAddress(SDigitizerRef(sdname)) ;
1932     sdigitizerBranch->GetEntry(0) ; 
1933   }    
1934   
1935 // After SDigits have been read from all files, return to the first one
1936
1937   next.Reset();
1938   folder = static_cast<TFolder*>(next());
1939   if(folder){
1940     TString fileName(folder->GetName()) ; 
1941     fileName.ReplaceAll("_","/") ; 
1942     file   = static_cast<TFile*>(gROOT->GetFile(fileName)); 
1943     file   ->cd() ;
1944   }
1945   return 0 ; 
1946 }
1947 //____________________________________________________________________________ 
1948 void AliPHOSGetter::ReadTreeS(TTree * treeS, Int_t input)
1949 {  // Read the summable digits fron treeS()  
1950
1951
1952   TString filename("mergefile") ;
1953   filename+= input ;
1954
1955   TFolder * phosFolder = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("PHOS")) ; 
1956   if ( !phosFolder ) { 
1957    phosFolder = fSDigitsFolder->AddFolder("PHOS", "SDigits from PHOS") ; 
1958   } 
1959   TFolder * folder=(TFolder*)phosFolder->FindObject(filename) ;
1960   //set address of the SDigits and SDigitizer
1961   TBranch   * sdigitsBranch    = 0;
1962   TBranch   * sdigitizerBranch = 0;
1963   TBranch   * branch           = 0 ;  
1964   TObjArray * lob = (TObjArray*)treeS->GetListOfBranches() ;
1965   TIter next(lob) ; 
1966   Bool_t phosfound = kFALSE, sdigitizerfound = kFALSE ; 
1967   
1968   while ( (branch = (TBranch*)next()) && (!phosfound || !sdigitizerfound) ) {
1969     if ( strcmp(branch->GetName(), "PHOS")==0) {
1970       phosfound = kTRUE ;
1971       sdigitsBranch = branch ; 
1972     }
1973     
1974     else if ( strcmp(branch->GetName(), "AliPHOSSDigitizer")==0) {
1975       sdigitizerfound = kTRUE ; 
1976       sdigitizerBranch = branch ;
1977     }
1978   }
1979   if ( !phosfound || !sdigitizerfound ) {
1980     if (fDebug)
1981       cout << "WARNING: AliPHOSGetter::ReadTreeS -> Digits and/or Digitizer branch not found" << endl ;
1982     return ; 
1983   }   
1984   
1985   if (!folder || !(folder->FindObject(sdigitsBranch->GetTitle()) ) )
1986     PostSDigits(sdigitsBranch->GetTitle(),filename) ;
1987
1988   sdigitsBranch->SetAddress(SDigitsRef(sdigitsBranch->GetTitle(),filename)) ;
1989   sdigitsBranch->GetEntry(0) ;
1990   
1991   TString sdname(sdigitsBranch->GetTitle()) ;
1992   sdname+=":" ;
1993   sdname+=filename ;
1994   
1995   if(!SDigitizer(sdigitsBranch->GetTitle()) )
1996     PostSDigitizer(sdigitsBranch->GetTitle(),filename) ;
1997   sdigitizerBranch->SetAddress(SDigitizerRef(sdname)) ;
1998   sdigitizerBranch->GetEntry(0) ;
1999 }    
2000
2001
2002 //____________________________________________________________________________ 
2003 void AliPHOSGetter::ReadPrimaries()
2004 {
2005   // a lot simplified.... if 2 files are opened then we have a problem
2006
2007   TClonesArray * ar = 0  ; 
2008   if(! (ar = Primaries()) ) { 
2009     PostPrimaries() ;
2010     ar = Primaries() ; 
2011   }
2012   ar->Delete() ; 
2013   
2014   if (TreeK(fHeaderFile)) { // treeK found in header file
2015     if (fDebug) 
2016       cout << "INFO: AliPHOSGetter::ReadPrimaries -> TreeK found in " << fHeaderFile.Data() << endl ; 
2017     fNPrimaries = gAlice->GetNtrack() ; 
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 " << folder->GetName() << 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 }