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