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