]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PHOS/AliPHOSGetter.cxx
Coding convention obeyed
[u/mrichter/AliRoot.git] / PHOS / AliPHOSGetter.cxx
index 20dd81bba116dd4cbb472b741a68ea2f762e5dfe..d52cb66c5a2ed0bc22373e599444d463f90d949f 100644 (file)
               Everywhere reading the treese TTree->GetEvent(i)
               is replaced by reading the branches TBranch->GetEntry(0)
 */
+/* $Log:
+   08.2002 Dmitri Peressounko:
+
+*/
 
 //_________________________________________________________________________
 //  A singleton. This class should be used in the analysis stage to get 
@@ -35,7 +39,7 @@
 //  for(Int_t irecp = 0; irecp < gime->NRecParticles() ; irecp++)
 //     AliPHOSRecParticle * part = gime->RecParticle(1) ;
 //     ................
-//  please->GetEvent(event) ;    // reads new event from galice.root
+//  gime->Event(event) ;    // reads new event from galice.root
 //                  
 //*-- Author: Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
 //*--         Completely redesigned by Dmitri Peressounko March 2001  
@@ -44,9 +48,7 @@
 //*--         systematic usage of TFolders without changing the interface        
 //////////////////////////////////////////////////////////////////////////////
 
-
 // --- ROOT system ---
-
 #include "TFile.h"
 #include "TTree.h"
 #include "TROOT.h"
 #include "TParticle.h"
 
 // --- Standard library ---
-#include <iostream.h>
 
 // --- AliRoot header files ---
-
 #include "AliRun.h"
 #include "AliConfig.h"
 #include "AliPHOSGetter.h"
 #include "AliPHOSTrackSegment.h"
 #include "AliPHOSPIDv1.h" 
 #include "AliPHOSGeometry.h"
-
+#include "AliPHOSRaw2Digits.h"
+//#include "AliPHOSCalibrationDB.h"
+#include "AliPHOSBeamTestEvent.h"
 ClassImp(AliPHOSGetter)
   
   AliPHOSGetter * AliPHOSGetter::fgObjGetter = 0 ; 
-  TFile * AliPHOSGetter::fFile = 0 ; 
+  TFile * AliPHOSGetter::fgFile = 0 ; 
 
 //____________________________________________________________________________ 
-AliPHOSGetter::AliPHOSGetter(const char* headerFile, const char* branchTitle )
+AliPHOSGetter::AliPHOSGetter(const char* headerFile, const char* branchTitle, const Bool_t toSplit )
 {
-  //Initialize  all lists
+  // This is the ctor called by GetInstance and the only one that can be used 
 
-  fDebug = 0 ; 
-  
-  fHeaderFile         = headerFile ; 
-  fBranchTitle        = branchTitle ;
-  fSDigitsTitle       = branchTitle ; 
-  fDigitsTitle        = branchTitle ; 
-  fRecPointsTitle     = branchTitle ; 
-  fRecParticlesTitle  = branchTitle ; 
-  fTrackSegmentsTitle = branchTitle ; 
+  if( fHeaderFile.Contains("_") ) {
+    Fatal("AliPHOSGetter", "Invalid file name (_ not allowed) %s", fHeaderFile.Data() ) ;
+  }
+
+  //Initialize  all data
+
+  fFailed = kFALSE ;   
+  fDebug  = 0 ; 
+  fAlice  = 0 ; 
+  fBTE    = 0 ;
+
+  fToSplit    = toSplit ;
+  fHeaderFile = headerFile ; 
 
   fPrimaries = new TObjArray(1) ;
 
@@ -102,50 +108,48 @@ AliPHOSGetter::AliPHOSGetter(const char* headerFile, const char* branchTitle )
   fQAFolder        = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Run/Conditions/QA")); 
   fTasksFolder     = dynamic_cast<TFolder*>(gROOT->FindObjectAny("Folders/Tasks")) ; 
 
-  fFailed = kFALSE ; 
+  //Set titles to branches and create PHOS specific folders
+  SetTitle(branchTitle) ;
 
   if ( fHeaderFile != "aliroot"  ) { // to call the getter without a file
-
     //open headers file
-    fFile = static_cast<TFile*>(gROOT->GetFile(fHeaderFile.Data() ) ) ;
-    if(!fFile) {    //if file was not opened yet, read gAlice
-      if ( fHeaderFile.Contains("_") ) {
-       cerr << "AliPHOSGetter::AliPHOSGetter -> Invalid file name (_ not allowed) " << fHeaderFile.Data() << endl ;
-       abort() ; 
-      }
-      fFile = TFile::Open(fHeaderFile.Data(),"update") ;
-      
-      if (!fFile->IsOpen()) {
-       cerr << "ERROR : AliPHOSGetter::AliPHOSGetter -> Cannot open " << fHeaderFile.Data() << endl ; 
+    fgFile = static_cast<TFile*>(gROOT->GetFile(fHeaderFile.Data() ) ) ;
+
+    if(!fgFile) {    //if file was not opened yet, read gAlice
+      fgFile = TFile::Open(fHeaderFile.Data(),"update") ;
+      if (!fgFile->IsOpen()) {
+       Error("AliPHOSGetter", "Cannot open %s", fHeaderFile.Data() ) ; 
        fFailed = kTRUE ;
         return ;  
       }
-      gAlice = static_cast<AliRun *>(fFile->Get("gAlice")) ;
-    } 
+    }
+    gAlice = dynamic_cast<AliRun *>(fgFile->Get("gAlice")) ;
   }
-
+  
   if (!gAlice) {
-    cerr << "ERROR : AliPHOSGetter::AliPHOSGetter -> Cannot find gAlice in " << fHeaderFile.Data() << endl ; 
+    Error("AliPHOSGetter", "Cannot find gAlice in %s", fHeaderFile.Data() ) ; 
     fFailed = kTRUE ;
     return ; 
   }
   if (!PHOS()) {
     if (fDebug)
-      cout << "INFO: AliPHOSGetter -> Posting PHOS to Folders" << endl ; 
+      Info("AliPHOSGetter", "-> Posting PHOS to Folders") ; 
     if (gAlice->GetDetector("PHOS")) {
       AliConfig * conf = AliConfig::Instance() ; 
       conf->Add(static_cast<AliDetector*>(gAlice->GetDetector("PHOS"))) ; 
       conf->Add(static_cast<AliModule*>(gAlice->GetDetector("PHOS"))) ; 
     }
     else 
-      cerr << "ERROR: AliPHOSGetter -> detector PHOS not found" << endl ;  
+      Error("AliPHOSGetter", "detector PHOS not found") ;    
   }
-  
+
   fDebug=0;
 }
-//____________________________________________________________________________ 
-AliPHOSGetter::~AliPHOSGetter(){
 
+//____________________________________________________________________________ 
+AliPHOSGetter::~AliPHOSGetter()
+{
+  // dtor
   if (fPrimaries) {
     fPrimaries->Delete() ; 
     delete fPrimaries ; 
@@ -157,106 +161,270 @@ AliPHOSGetter::~AliPHOSGetter(){
   TFolder * folder = 0 ; 
   while ( (folder = static_cast<TFolder*>(next())) ) 
     phosF->Remove(folder) ; 
-
-  if (fFile) { 
-    fFile->Close() ;  
-    delete fFile ;
-    fFile = 0 ;
+  
+  if (fgFile) { 
+    fgFile->Close() ;  
+    delete fgFile ;
+    fgFile = 0 ;
   }
-    
+  fgObjGetter = 0 ; 
+  
+}
+
+//____________________________________________________________________________ 
+void AliPHOSGetter::CloseFile()
+{
+  // delete gAlice
+
+  if(gAlice)
+    delete gAlice ;  
+  gAlice = 0 ; 
+  if(fAlice)
+    delete fAlice ; 
+  fAlice = 0 ; 
 }
 
+//____________________________________________________________________________ 
+const TFolder * AliPHOSGetter::Folder(const TString what) const {
+
+  // returns the PHOS folder required by what
+  // what = hits, sdigits, digits
+
+  if ( what == "hits" ) 
+    return dynamic_cast<const TFolder *>(fHitsFolder->FindObject("PHOS")) ; 
+  else if ( what == "sdigits" ) 
+    return  dynamic_cast<const TFolder *>(fSDigitsFolder->FindObject("PHOS")) ; 
+  else if ( what == "digits" ) 
+    return  dynamic_cast<const TFolder *>(fDigitsFolder->FindObject("PHOS")) ; 
+  else {
+    Error("GetFolder", " %s illegal option (hits, sdigits, digits)", what.Data() ) ; 
+    return 0 ; 
+  }
+}
 
 //____________________________________________________________________________ 
 AliPHOSGetter * AliPHOSGetter::GetInstance()
 {
   // Returns the pointer of the unique instance already defined
   
-  AliPHOSGetter * rv = 0 ;
-  if ( fgObjGetter )
-    rv = fgObjGetter ;
-  else
-    cout << "AliPHOSGetter::GetInstance ERROR: not yet initialized" << endl ;
-
-  return rv ;
+  if ( fgObjGetter ) {
+    return fgObjGetter ;
+  }
+  else {
+    //Warning("GetInstance", "not yet initialized") ;
+    return 0 ; 
+  }
 }
 
 //____________________________________________________________________________ 
 AliPHOSGetter * AliPHOSGetter::GetInstance(const char* headerFile,
-                                          const char* branchTitle)
+                                          const char* branchTitle,
+                                           const Bool_t toSplit)
 {
   // Creates and returns the pointer of the unique instance
-  // Must be called only when the environment has changed 
+  // Must be called only when the environment has changed
 
-  if ( fgObjGetter )    
-    if((fgObjGetter->fBranchTitle.CompareTo(branchTitle) == 0) && 
-       (fgObjGetter->fHeaderFile.CompareTo(headerFile)==0)) {
-      fFile->cd() ; 
+  if(!fgObjGetter){
+    fgObjGetter = new AliPHOSGetter(headerFile,branchTitle,toSplit) ;
+    if(fgObjGetter->fFailed)
+      return 0;
+    else
       return fgObjGetter ;
+  }
+
+  //First checks, if header file already opened
+  if(!fgObjGetter->fgFile){
+     fgObjGetter = new AliPHOSGetter(headerFile,branchTitle,toSplit) ;
+    if(fgObjGetter->fFailed)
+      return 0;
+    else
+      return fgObjGetter ;
+  }
+
+  if(fgObjGetter->fHeaderFile.CompareTo(headerFile)==0){ //Opened the same header file
+    if((fgObjGetter->fBranchTitle.CompareTo(branchTitle) == 0)&&   //Open the same branch title
+       (toSplit==fgObjGetter->fToSplit)){                          //Nothing should be cleaned
     }
-    else 
-      fgObjGetter->~AliPHOSGetter() ;  // delete it already exists another version
-  fgObjGetter = new AliPHOSGetter(headerFile,branchTitle) ; 
+    else{ //Clean all data and AliPHOS...zers
+      if(fgObjGetter->fToSplit)
+       fgObjGetter->CloseSplitFiles() ;
+      fgObjGetter->CleanWhiteBoard() ;
+      fgObjGetter->fToSplit = toSplit ;
+      fgObjGetter->SetTitle(branchTitle) ;
+    }
+  }
+  else{  //Close already opened files, clean memory and open new header file
+    if(gAlice){ //should first delete gAlice, then close file
+      //Should be in dtor of PHOS, but if one changes path ...
+      fgObjGetter->fModuleFolder->Remove(fgObjGetter->fModuleFolder->FindObject("PHOS")) ; 
+      delete gAlice ;      
+    }
+    if(fgObjGetter->fgFile){
+      fgObjGetter->fgFile->Close() ;
+      fgObjGetter->fgFile=0;
+    }
+    if(fgObjGetter->fToSplit)
+      fgObjGetter->CloseSplitFiles() ;
+    fgObjGetter->CleanWhiteBoard() ;    
+    fgObjGetter = new AliPHOSGetter(headerFile,branchTitle,toSplit) ;
 
-  if (fgObjGetter->HasFailed() ) 
-    fgObjGetter = 0 ; 
-  
+  }
+  return fgObjGetter ; 
   
-  // Posts a few item to the white board (folders)
-  // fgObjGetter->CreateWhiteBoard() ;
+}
+
+//____________________________________________________________________________ 
+const Bool_t AliPHOSGetter::BranchExists(const TString recName) const
+{
+  //Looks in the tree Tree"name" if branch with current name olready exists
+
+  TString filename("") ;
+  TString name, dataname, zername ;
+  if(recName == "SDigits"){
+    filename=fSDigitsFileName ;
+    name = "TreeS0" ;
+    dataname = "PHOS" ;
+    zername = "AliPHOSSDigitizer" ;
+  }
+  else
+    if(recName == "Digits"){
+      filename=fDigitsFileName ;
+      name = "TreeD0" ;
+      dataname = "PHOS" ;
+      zername = "AliPHOSDigitizer" ;
+    }
+    else
+      if(recName == "RecPoints"){
+       filename=fRecPointsFileName ;
+       name = "TreeR0" ;
+       dataname = "PHOSEmcRP" ;
+       zername = "AliPHOSClusterizer" ;
+      }
+      else
+       if(recName == "TrackSegments"){
+         filename=fTrackSegmentsFileName ;
+         name = "TreeR0" ;
+         dataname = "PHOSTS" ;
+         zername = "AliPHOSTrackSegmentMaker" ;
+       }        
+       else
+         if(recName == "RecParticles"){
+           filename= fRecParticlesFileName ;
+           name = "TreeR0" ;
+           dataname = "PHOSRP" ;
+           zername = "AliPHOSPID" ;
+         }
+         else
+           return kFALSE ;
+
+  TFile * file ;
+  TTree * tree ;
+  if(fToSplit){
+    file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
+    if(!file)
+      file = TFile::Open(fSDigitsFileName.Data(),"update");
+  }
+  else
+    file = fgFile ;
+
+  tree = (TTree *)file->Get(name.Data()) ;
   
-  return fgObjGetter ; 
+  if(!tree ) 
+    return kFALSE ;
+
+  TObjArray * lob = static_cast<TObjArray*>(tree->GetListOfBranches()) ;
+  TIter next(lob) ; 
+  TBranch * branch = 0 ;  
+  TString titleName(fBranchTitle);
+  titleName+=":";
+  while ((branch = (static_cast<TBranch*>(next())))) {
+    TString branchName(branch->GetName() ) ; 
+    TString branchTitle(branch->GetTitle() ) ;  
+    if ( branchName.BeginsWith(dataname) && branchTitle.BeginsWith(fBranchTitle) ){  
+      Warning("BranchExists", "branch %s with title %s already exists in %s", dataname.Data(), fBranchTitle.Data(), name.Data() ) ;
+      return kTRUE ;
+    }
+    if ( branchName.BeginsWith(zername) &&  branchTitle.BeginsWith(titleName) ){
+      Warning("BranchExists", "branch AliPHOS... with title %s already exists in %s", branch->GetTitle(), name.Data() ) ;     
+      return kTRUE ; 
+    }
+  }
+  //We can't delete three if gAlice points to it... To be redisigned somehow???!!!
+  if(!fToSplit){
+    if(name.Contains("TreeS"))
+      if(tree!=gAlice->TreeS())
+       tree->Delete();
+    if(name.Contains("TreeD"))
+      if(tree!=gAlice->TreeD())
+       tree->Delete();
+    if(name.Contains("TreeR"))
+      if(tree!=gAlice->TreeR())
+       tree->Delete();    
+  }
+  return kFALSE ;
   
 }
 
 //____________________________________________________________________________ 
 void AliPHOSGetter::ListBranches(Int_t event) const  
 {
+  // Iterates over branches in each TreeH, TreeS, TreeD and TreeR and
+  // prints lists of branches to stdout
+  // (I don't know why this method is needed. Yu.Kharlov)
   
   TBranch * branch = 0 ; 
   if (gAlice->GetEvent(event) == -1)
     return ; 
-
+  
   TTree * t =  gAlice->TreeH() ; 
   if(t){
-    cout << "****** Hits    : " << endl ; 
+    Info("ListBranches", "-> ****** Hits    : ") ; 
     TObjArray * lob = t->GetListOfBranches() ;
     TIter next(lob) ; 
     while ( (branch = static_cast<TBranch*>(next())) )
-      cout << "             " << branch->GetName() << endl ; 
-  }
+      Info("ListBranches", "             %s", branch->GetName()) ; 
+  } else
+    Warning("ListBranches", "TreeH not found for event %d", event ) ;  
   
   t = gAlice->TreeS() ;
   if(t){
-    cout << "****** SDigits : " << endl ; 
+    Info("ListBranches", "-> ****** SDigits : ") ; 
     TObjArray * lob = t->GetListOfBranches() ;
     TIter next(lob) ; 
     while ( (branch = static_cast<TBranch*>(next())) )
-      cout << "             " << branch->GetName() << endl ; 
-  }  
+      Info("ListBranches", "             %s %s", branch->GetName(), branch->GetTitle()) ; 
+  } else 
+    Warning("ListBranches", "TreeS not found for event %d", event)  ;  
+  
+  
   t = gAlice->TreeD() ;
   if(t){
-    cout << "****** Digits  : " << endl ; 
+    Info("ListBranches", "-> ****** Digits  : ") ; 
     TObjArray * lob = t->GetListOfBranches() ;
     TIter next(lob) ; 
     while ( (branch = static_cast<TBranch*>(next())) )
-      cout << "             " << branch->GetName() << " " << branch->GetTitle() << endl ; 
-  }
+      Info("ListBranches", "             %s %s", branch->GetName(), branch->GetTitle()) ; 
+  } else 
+    Warning("ListBranches", "TreeD not found for event %d", event) ;  
+  
 
   t = gAlice->TreeR() ;
   if(t){
-    cout << "****** Recon   : " << endl ; 
+    Info("ListBranches", "-> ****** Recon   : ") ; 
     TObjArray * lob = t->GetListOfBranches() ;
     TIter next(lob) ; 
     while ( (branch = static_cast<TBranch*>(next())) )
-      cout << "             " << branch->GetName() << " " << branch->GetTitle() << endl ; 
-  }
+     Info("ListBranches", "             %s %s", branch->GetName(), branch->GetTitle()) ; 
+  } else 
+    Warning("ListBranches", "TreeR not found for event %d", event) ;  
+  
 }
 
 //____________________________________________________________________________ 
 void AliPHOSGetter::NewBranch(TString name, Int_t event)  
 {
+  // Set titles for (S)Digits, RecPoints, TSegments and RecParticles branches
+
   fBranchTitle = fSDigitsTitle = fDigitsTitle = fRecPointsTitle = fTrackSegmentsTitle = fRecParticlesTitle =  name ; 
   Event(event) ; 
 }
@@ -264,23 +432,24 @@ void AliPHOSGetter::NewBranch(TString name, Int_t event)
 //____________________________________________________________________________ 
 Bool_t AliPHOSGetter::NewFile(TString name)  
 {
+  // Open a new file
   fHeaderFile = name ; 
-  fFile->Close() ; 
+  fgFile->Close() ; 
   fFailed = kFALSE; 
 
-  fFile = static_cast<TFile*>(gROOT->GetFile(fHeaderFile.Data() ) ) ;
-  if(!fFile) {    //if file was not opened yet, read gAlice
-    fFile = TFile::Open(fHeaderFile.Data(),"update") ;
-    if (!fFile->IsOpen()) {
-      cerr << "ERROR : AliPHOSGetter::NewFile -> Cannot open " << fHeaderFile.Data() << endl ; 
+  fgFile = static_cast<TFile*>(gROOT->GetFile(fHeaderFile.Data() ) ) ;
+  if(!fgFile) {    //if file was not opened yet, read gAlice
+    fgFile = TFile::Open(fHeaderFile.Data(),"update") ;
+    if (!fgFile->IsOpen()) {
+      Error("NewFile", "Cannot open %s", fHeaderFile.Data() ) ; 
       fFailed = kTRUE ;
       return fFailed ;  
     }
-    gAlice = static_cast<AliRun *>(fFile->Get("gAlice")) ;
+    gAlice = static_cast<AliRun *>(fgFile->Get("gAlice")) ;
   } 
   
   if (!gAlice) {
-    cerr << "ERROR : AliPHOSGetter::AliPHOSGetter -> Cannot find gAlice in " << fHeaderFile.Data() << endl ; 
+    Error("AliPHOSGetter", "Cannot find gAlice in %s", fHeaderFile.Data() ) ; 
     fFailed = kTRUE ;
     return fFailed ; 
   }
@@ -294,13 +463,15 @@ const AliPHOS * AliPHOSGetter::PHOS()
   AliPHOS * phos = dynamic_cast<AliPHOS*>(fModuleFolder->FindObject("PHOS")) ;  
   if (!phos) 
     if (fDebug)
-      cout << "WARNING: AliPHOSGetter::PHOS -> PHOS module not found in Folders" << endl ; 
+      Warning("PHOS", "-> PHOS module not found in Folders") ; 
   return phos ; 
 }  
 
 //____________________________________________________________________________ 
 const AliPHOSGeometry * AliPHOSGetter::PHOSGeometry() 
 {
+  // Returns PHOS geometry
+
   AliPHOSGeometry * rv = 0 ; 
   if (PHOS() )
     rv =  PHOS()->GetGeometry() ;
@@ -308,7 +479,7 @@ const AliPHOSGeometry * AliPHOSGetter::PHOSGeometry()
 } 
 
 //____________________________________________________________________________ 
-Bool_t AliPHOSGetter::PostPrimaries(void) const 
+const Bool_t AliPHOSGetter::PostPrimaries(void) const 
 {  //------- Primaries ----------------------
 
   // the hierarchy is //Folders/RunMC/Event/Data/Primaries
@@ -316,8 +487,8 @@ Bool_t AliPHOSGetter::PostPrimaries(void) const
   TFolder * primariesFolder = dynamic_cast<TFolder*>(fPrimariesFolder->FindObject("Primaries")) ; 
   if ( !primariesFolder ) {
     if (fDebug) {
-      cout << "WARNING: AliPHOSGetter::Post Primaries -> Folder //" << fPrimariesFolder << "/Primaries/ not found!" << endl;
-      cout << "INFO:    AliPHOSGetter::Post Primaries -> Adding Folder //" << fPrimariesFolder << "/Primaries/"  << endl;
+      Warning("PostPrimaries", "-> Folder //%s/Primaries/ not found!", fPrimariesFolder->GetName()) ;
+      Info("PostPrimaries", "-> Adding Folder //%s/Primaries", fPrimariesFolder->GetName()) ;
     }
     primariesFolder = fPrimariesFolder->AddFolder("Primaries", "Primaries particles from TreeK") ; 
   }    
@@ -335,27 +506,24 @@ TObject** AliPHOSGetter::PrimariesRef(void) const
   
   // the hierarchy is //Folders/RunMC/Event/Data/Primaries
   if ( !fPrimariesFolder ) {
-    cerr << "ERROR: AliPHOSGetter::PrimariesRef -> Folder //" << fPrimariesFolder << " not found!" << endl;
-    abort() ;
+    Fatal("PrimariesRef", "Folder //%s not found", fPrimariesFolder) ;
   }    
  
   TFolder * primariesFolder = dynamic_cast<TFolder *>(fPrimariesFolder->FindObject("Primaries")) ;
   if ( !primariesFolder ) {
-    cerr << "ERROR: AliPHOSGetter::PrimariesRef -> Folder //" << fPrimariesFolder << "/Primaries/ not found!" << endl;  
-    abort() ;
+    Fatal("PrimariesRef", "Folder //%s/Primaries/ not found", fPrimariesFolder) ;  
   }
  
   TObject * p = primariesFolder->FindObject("Primaries") ;
   if(!p) {
-    cerr << "ERROR: AliPHOSGetter::PrimariesRef -> " << primariesFolder->GetName() << "/Primaries not found !" << endl ; 
-    abort() ;
+    Fatal("PrimariesRef","%s /Primaries not found !", primariesFolder->GetName() ) ; 
   }
-  else
-    return primariesFolder->GetListOfFolders()->GetObjectRef(p) ;
+
+  return primariesFolder->GetListOfFolders()->GetObjectRef(p) ;
 }
 
 //____________________________________________________________________________ 
-Bool_t AliPHOSGetter::PostHits(void) const 
+const Bool_t AliPHOSGetter::PostHits(void) const 
 {  //------- Hits ----------------------
 
   // the hierarchy is //Folders/RunMC/Event/Data/PHOS/Hits
@@ -363,8 +531,8 @@ Bool_t AliPHOSGetter::PostHits(void) const
   TFolder * phosFolder = dynamic_cast<TFolder*>(fHitsFolder->FindObject("PHOS")) ; 
   if ( !phosFolder ) {
     if (fDebug) {
-      cout << "WARNING: AliPHOSGetter::Post H -> Folder //" << fHitsFolder << "/PHOS/ not found!" << endl;
-      cout << "INFO:    AliPHOSGetter::Post H -> Adding Folder //" << fHitsFolder << "/PHOS/"  << endl;
+      Warning("PostHits", "-> Folder //%s/PHOS/ not found!", fHitsFolder) ;
+      Info("PostHits", "-> Adding Folder //%s/PHOS/", fHitsFolder) ;
     }
     phosFolder = fHitsFolder->AddFolder("PHOS", "Hits from PHOS") ; 
   }    
@@ -382,27 +550,24 @@ TObject** AliPHOSGetter::HitsRef(void) const
   
   // the hierarchy is //Folders/RunMC/Event/Data/PHOS/Hits
   if ( !fHitsFolder ) {
-    cerr << "ERROR: AliPHOSGetter::HitsRef -> Folder //" << fHitsFolder << " not found!" << endl;
-    abort() ;
+    Fatal("HitsRef", "Folder //%s not found !", fHitsFolder) ;
   }    
  
   TFolder * phosFolder = dynamic_cast<TFolder *>(fHitsFolder->FindObject("PHOS")) ;
   if ( !phosFolder ) {
-    cerr << "ERROR: AliPHOSGetter::HitsRef -> Folder //" << fHitsFolder << "/PHOS/ not found!" << endl;  
-    abort() ;
+    Fatal("HitsRef", "Folder //%s/PHOS/ not found !", fHitsFolder) ;  
   }
  
   TObject * h = phosFolder->FindObject("Hits") ;
   if(!h) {
-    cerr << "ERROR: AliPHOSGetter::HitsRef -> " << phosFolder->GetName() << "/Hits not found !" << endl ; 
-    abort() ;
+    Fatal("HitsRef", "%s/Hits not fount !", phosFolder->GetName() ) ; 
   }
-  else
-    return phosFolder->GetListOfFolders()->GetObjectRef(h) ;
+
+  return phosFolder->GetListOfFolders()->GetObjectRef(h) ;
 }
 
 //____________________________________________________________________________ 
-Bool_t AliPHOSGetter::PostSDigits(const char * name, const char * headerFile) const 
+const Bool_t AliPHOSGetter::PostSDigits(const char * name, const char * headerFile) const 
 {  //---------- SDigits -------------------------
 
   
@@ -412,23 +577,32 @@ Bool_t AliPHOSGetter::PostSDigits(const char * name, const char * headerFile) co
   TFolder * phosFolder = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("PHOS")) ;
   if ( !phosFolder ) {
     if (fDebug) {
-      cout << "WARNING: AliPHOSGetter::Post S -> Folder //" << fSDigitsFolder << "/PHOS/ not found!" << endl;
-      cout << "INFO:    AliPHOSGetter::Post S -> Adding Folder //" << fHitsFolder << "/PHOS/" << endl;
+      Warning("PostSDigits", "-> Folder //%s/PHOS/ not found!", fSDigitsFolder) ;
+      Info("PostSDigits", "-> Adding Folder //%s/PHOS/", fHitsFolder) ;
     }
     phosFolder = fSDigitsFolder->AddFolder("PHOS", "SDigits from PHOS") ; 
   }    
+
+  
   TString subdir(headerFile) ;
-  subdir.ReplaceAll("/","_") ; 
+  if(fToSplit){
+    subdir.Remove(subdir.Last('/')+1,subdir.Length()) ;
+    subdir.ReplaceAll("/","_") ; 
+    subdir+="PHOS.SDigits." ;
+    if(name && (strcmp(name,"Default")!=0)){
+      subdir+=name ;
+      subdir+="." ;
+    }
+    subdir+="root" ;
+  }
+    
   TFolder * phosSubFolder = dynamic_cast<TFolder*>(phosFolder->FindObject(subdir)) ; 
   if ( !phosSubFolder ) 
     phosSubFolder = phosFolder->AddFolder(subdir, ""); 
   
+
   TObject * sd  = phosSubFolder->FindObject(name); 
-  if ( sd ) {
-    if (fDebug)
-      cerr <<"INFO: AliPHOSGetter::Post S -> Folder " << subdir 
-          << " already exists!" << endl ;  
-  }else{
+  if ( !sd ) {
     TClonesArray * sdigits = new TClonesArray("AliPHOSDigit",1) ;
     sdigits->SetName(name) ;
     phosSubFolder->Add(sdigits) ;
@@ -437,61 +611,55 @@ Bool_t AliPHOSGetter::PostSDigits(const char * name, const char * headerFile) co
   return kTRUE;
 } 
 //____________________________________________________________________________ 
-TObject** AliPHOSGetter::SDigitsRef(const char * name, const char * file) const 
+TObject** AliPHOSGetter::SDigitsRef(const char * name, const char * foldername) const 
 {  //------- SDigits ----------------------
   
   // the hierarchy is //Folders/RunMC/Event/Data/PHOS/SDigits/filename/SDigits
 
   if ( !fSDigitsFolder ) {
-    cerr << "ERROR: AliPHOSGetter::SDigitsRef -> Folder //" << fSDigitsFolder << " not found!" << endl;
-    abort() ;
+    Fatal("SDigitsRef", "Folder //%s not found !", fSDigitsFolder) ;
   }    
  
-  TFolder * phosFolder = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject("PHOS")) ;
+  TFolder * phosFolder = static_cast<TFolder *>(fSDigitsFolder->FindObject("PHOS")) ;
   if ( !phosFolder ) {
-    cerr << "ERROR: AliPHOSGetter::SDigitsRef -> Folder //" << fSDigitsFolder << "/PHOS/ not found!" << endl;
-    abort() ;
+    Fatal("SDigitsRef", "Folder //%s/PHOS not found !", fSDigitsFolder) ;
   }
 
   TFolder * phosSubFolder = 0 ;
-  if(file)
-    phosSubFolder = dynamic_cast<TFolder *>(phosFolder->FindObject(file)) ;
-  else
-    phosSubFolder = dynamic_cast<TFolder *>(phosFolder->FindObject(fHeaderFile)) ;
+
+  phosSubFolder = dynamic_cast<TFolder *>(phosFolder->FindObject(foldername)) ;
   
   if(!phosSubFolder) {
-    cerr << "ERROR: AliPHOSGetter::DigitesSRef -> Folder //Folders/RunMC/Event/Data/PHOS/" << file << "not found!" << endl;
-    abort() ;
+    Fatal("SDigitsRef", "Folder //Folders/RunMC/Event/Data/PHOS/%s not found !", foldername) ;
   }
 
   TObject * dis = phosSubFolder->FindObject(name) ;
   if(!dis){
-    cerr << "ERROR: AliPHOSGetter::DigitesSRef -> object " << name << " not found! " << endl ; 
-    abort()  ;
+    Fatal("SDigitsRef", "object %s not found !", name) ; 
   }
-  else
-    return phosSubFolder->GetListOfFolders()->GetObjectRef(dis) ;
+
+  return phosSubFolder->GetListOfFolders()->GetObjectRef(dis) ;
 
 }
 
 //____________________________________________________________________________ 
-Bool_t AliPHOSGetter::PostSDigitizer(AliPHOSSDigitizer * sdigitizer) const 
-{  //---------- SDigitizer -------------------------
-    
+const Bool_t AliPHOSGetter::PostSDigitizer(AliPHOSSDigitizer * sdigitizer) const 
+{  
+  //---------- SDigitizer -------------------------
   // the hierarchy is //Folders/Tasks/SDigitizer/PHOS/sdigitsname
 
 
   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ; 
 
   if ( !sd ) {
-    cerr << "ERROR: AliPHOSGetter::Post Ser -> Task //" << fTasksFolder << "/SDigitizer not found!" << endl;
+    Error("PostDigitizer", "Task //%s/SDigitizer not found !", fTasksFolder) ;
     return kFALSE ;
   }        
   TTask * phos = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("PHOS")) ; 
   if ( !phos )  {
     if (fDebug) {
-      cout <<"WARNING: AliPHOSGetter::Post Ser ->//" << fTasksFolder << "/SDigitizer/PHOS/ not found!" << endl;  
-      cout <<"INFO: AliPHOSGetter::Post Ser -> Adding //" << fTasksFolder << "/SDigitizer/PHOS/" << endl;
+      Warning("PostSDigitizer", "->//%s/SDigitizer/PHOS/ not found!", fTasksFolder) ;  
+      Info("PostSDigitizer", "-> Adding //%s/SDigitizer/PHOS/", fTasksFolder) ;
     }
     phos = new TTask("PHOS", "") ; 
     sd->Add(phos) ; 
@@ -499,7 +667,7 @@ Bool_t AliPHOSGetter::PostSDigitizer(AliPHOSSDigitizer * sdigitizer) const
   AliPHOSSDigitizer * phossd  = dynamic_cast<AliPHOSSDigitizer *>(phos->GetListOfTasks()->FindObject( sdigitizer->GetName() )); 
   if (phossd) { 
     if (fDebug)
-      cout << "INFO: AliPHOSGetter::Post Ser -> Task " << sdigitizer->GetName() << " already exists" << endl ; 
+      Info("PostSDigitizer", "-> Task %s already exists", sdigitizer->GetName()) ; 
     phos->GetListOfTasks()->Remove(phossd) ;
   }
   phos->Add(sdigitizer) ;      
@@ -510,17 +678,16 @@ Bool_t AliPHOSGetter::PostSDigitizer(AliPHOSSDigitizer * sdigitizer) const
 //____________________________________________________________________________ 
 TObject** AliPHOSGetter::SDigitizerRef(const char * name) const 
 {  
+  //---------- return task SDigitizer -------------------------
 
   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ; 
   if ( !sd ) {
-    cerr << "ERROR: AliPHOSGetter::Post SerRef -> Task //" << fTasksFolder << "/SDigitizer not found!" << endl;
-    abort();
+    Fatal("SDigitizerRef", "Task //%s/SDigitizer not found !", fTasksFolder) ;
   }        
 
   TTask * phos = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("PHOS")) ; 
   if ( !phos )  {
-    cerr <<"ERROR: AliPHOSGetter::Post SerRef ->  //" << fTasksFolder << "/SDigitizer/PHOS not found!" << endl;
-    abort();
+    Fatal("SDigitizerRef", "//%s/SDigitizer/PHOS not found !", fTasksFolder) ;
   }        
 
   TTask * task = dynamic_cast<TTask*>(phos->GetListOfTasks()->FindObject(name)) ; 
@@ -530,23 +697,22 @@ TObject** AliPHOSGetter::SDigitizerRef(const char * name) const
 }
 
 //____________________________________________________________________________ 
-Bool_t AliPHOSGetter::PostSDigitizer(const char * name, const char * file) const 
-{  //---------- SDigitizer -------------------------
-  
- // the hierarchy is //Folders/Tasks/SDigitizer/PHOS/sdigitsname
-
+const Bool_t AliPHOSGetter::PostSDigitizer(const char * name, const char * file) const 
+{  
+  //---------- SDigitizer -------------------------
+  // the hierarchy is //Folders/Tasks/SDigitizer/PHOS/sdigitsname
 
   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ; 
   if ( !sd ) {
-    cerr << "ERROR: AliPHOSGetter::Post Ser -> Task //" << fTasksFolder << "/SDigitizer not found!" << endl;
+    Error("PostSDigitizer", "Task //%s/SDigitizer not found !", fTasksFolder) ;
     return kFALSE ;
   }        
 
   TTask * phos = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("PHOS")) ; 
   if ( !phos )  {
     if (fDebug) {
-      cout <<"WARNING: AliPHOSGetter::Post Ser ->  //" << fTasksFolder << "/SDigitizer/PHOS/ not found!" << endl;
-      cout <<"INFO: AliPHOSGetter::Post Ser -> Adding  //" << fTasksFolder << "/SDigitizer/PHOS" << endl;
+      Error("PostSDigitizer", "->  //%s/SDigitizer/PHOS/ not found!", fTasksFolder) ;
+      Info("PostSDigitizer", "-> Adding  //%s/SDigitizer/PHOS", fTasksFolder) ;
     }
     phos = new TTask("PHOS", "") ; 
     sd->Add(phos) ; 
@@ -559,7 +725,7 @@ Bool_t AliPHOSGetter::PostSDigitizer(const char * name, const char * file) const
   AliPHOSSDigitizer * phossd  = dynamic_cast<AliPHOSSDigitizer *>(phos->GetListOfTasks()->FindObject( sdname )); 
   if (!phossd) {
     phossd = new AliPHOSSDigitizer() ;  
-    //Note, we can not call constructor with parameters: it will call Getter and scrud up everething
+    //Note, we can not call constructor with parameters: it will call Getter and scew up everething
     phossd->SetName(sdname) ;
     phossd->SetTitle(file) ;
     phos->Add(phossd) ;        
@@ -569,7 +735,7 @@ Bool_t AliPHOSGetter::PostSDigitizer(const char * name, const char * file) const
 }
 
 //____________________________________________________________________________ 
-Bool_t AliPHOSGetter::PostDigits(const char * name) const 
+const Bool_t AliPHOSGetter::PostDigits(const char * name) const 
 {  //---------- Digits -------------------------
 
   // the hierarchy is //Folders/Run/Event/Data/PHOS/SDigits/name
@@ -578,8 +744,8 @@ Bool_t AliPHOSGetter::PostDigits(const char * name) const
 
   if ( !phosFolder ) {
     if (fDebug) {
-      cout << "WARNING: AliPHOSGetter::Post D -> Folder //" << fDigitsFolder << "/PHOS/ not found!" << endl;
-      cout << "INFO:    AliPHOSGetter::Post D -> Adding Folder //" << fDigitsFolder << "/PHOS/" << endl;
+      Warning("PostDigitizer", "-> Folder //%s/PHOS/ not found!", fDigitsFolder) ;
+      Info("PostDigitizer", "-> Adding Folder //%s/PHOS/", fDigitsFolder) ;
     }
     phosFolder = fDigitsFolder->AddFolder("PHOS", "Digits from PHOS") ;  
   }    
@@ -595,46 +761,44 @@ Bool_t AliPHOSGetter::PostDigits(const char * name) const
 
 //____________________________________________________________________________ 
 TObject** AliPHOSGetter::DigitsRef(const char * name) const 
-{ //------- Digits ----------------------
-  
-  // the hierarchy is //Folders/Run/Event/Data/PHOS/Digits/name
+{
+  //------- Digits ----------------------
+    // the hierarchy is //Folders/Run/Event/Data/PHOS/Digits/name
 
   if ( !fDigitsFolder ) {
-    cerr << "ERROR: AliPHOSGetter::DigitsRef -> Folder //" << fDigitsFolder << " not found!" << endl;
-    abort() ;
+    Fatal("DigitsRef", "Folder //%s not found !", fDigitsFolder) ;
   }    
   
   TFolder * phosFolder  = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("PHOS")) ; 
   if ( !phosFolder ) {
-    cerr << "ERROR: AliPHOSGetter::DigitsRef -> Folder //" << fDigitsFolder << "/PHOS/ not found!" << endl;
-    abort() ;
+    Fatal("DigitsRef", "Folder //%s/PHOS/ not found !", fDigitsFolder) ;
   }    
 
   TObject * d = phosFolder->FindObject(name) ;
   if(!d) {
-    cerr << "ERROR: AliPHOSGetter::DigitsRef -> object " << name << " not found! " << endl ; 
-    abort() ;
+    Fatal("DigitsRef", "object %s not found !", name) ; 
   }
-  else
-    return phosFolder->GetListOfFolders()->GetObjectRef(d) ;
+
+  return phosFolder->GetListOfFolders()->GetObjectRef(d) ;
 
 }
 
 //____________________________________________________________________________ 
-Bool_t AliPHOSGetter::PostDigitizer(AliPHOSDigitizer * digitizer) const 
-{  //---------- Digitizer -------------------------
+const Bool_t AliPHOSGetter::PostDigitizer(AliPHOSDigitizer * digitizer) const 
+{
+  //---------- Digitizer -------------------------
   
   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ; 
 
   if ( !sd ) {
-    cerr << "ERROR: AliPHOSGetter::Post Der -> Task //" << fTasksFolder << "/Digitizer not found!" << endl;
+    Error("PostDigitizer", "Task //%s/Digitizer not found !", fTasksFolder) ;
     return kFALSE ;
   }        
   TTask * phos = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("PHOS")) ; 
   if ( !phos )  {
     if (fDebug) {
-      cout <<"WARNING: AliPHOSGetter::Post Der ->  //" << fTasksFolder << "/Digitizer/PHOS not found!" << endl;
-      cout <<"INFO: AliPHOSGetter::Post Der -> Adding //" << fTasksFolder << "/Digitizer/PHOS" << endl
+      Error("PostDigitizer", "//%s/Digitizer/PHOS not found!", fTasksFolder) ;
+      Info("PostDigitizer", "Adding //%s/Digitizer/PHOS", fTasksFolder) 
     }
     phos = new TTask("PHOS", "") ; 
     sd->Add(phos) ; 
@@ -650,33 +814,41 @@ Bool_t AliPHOSGetter::PostDigitizer(AliPHOSDigitizer * digitizer) const
 }  
 
 //____________________________________________________________________________ 
-Bool_t AliPHOSGetter::PostDigitizer(const char * name) const 
-{  //---------- Digitizer -------------------------
-  
- // the hierarchy is //Folders/Tasks/SDigitizer/PHOS/sdigitsname
+const Bool_t AliPHOSGetter::PostDigitizer(const char * name) const 
+{
+  //---------- Digitizer -------------------------
 // the hierarchy is //Folders/Tasks/SDigitizer/PHOS/sdigitsname
 
   TTask * d  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ; 
   if ( !d ) {
-    cerr << "ERROR: AliPHOSGetter::Post Der -> Task //" << fTasksFolder << "/Digitizer not found!" << endl;
+    Error("PostDigitizer", "Task //%s/Digitizer not found !", fTasksFolder) ;
     return kFALSE ;
   }        
 
   TTask * phos = dynamic_cast<TTask*>(d->GetListOfTasks()->FindObject("PHOS")) ; 
   if ( !phos )  {
     if (fDebug) {
-      cout <<"WARNING: AliPHOSGetter::Post Der -> //" << fTasksFolder << "/Digitizer/PHOS not found!" << endl
-      cout <<"INFO: AliPHOSGetter::Post Der -> Adding //" << fTasksFolder << "/Digitizer/PHOS" << endl;
+      Warning("PostDigitizer", "//%s/Digitizer/PHOS not found!", fTasksFolder) 
+      Info("PostDigitizer", "Adding //%s/Digitizer/PHOS", fTasksFolder) ;
     }
     phos = new TTask("PHOS", "") ; 
     d->Add(phos) ; 
 } 
 
-  AliPHOSDigitizer * phosd = dynamic_cast<AliPHOSDigitizer*>(phos->GetListOfTasks()->FindObject(name)) ; 
+  TTask * phosd = dynamic_cast<TTask*>(phos->GetListOfTasks()->FindObject(fDigitsTitle)) ; 
   if (!phosd) { 
-    phosd = new AliPHOSDigitizer() ;
-    phosd->SetName(fDigitsTitle) ;
-    phosd->SetTitle(fHeaderFile) ;
-    phos->Add(phosd) ;
+    if(strcmp(name, "Digitizer")==0){
+      phosd = new AliPHOSDigitizer() ;
+      phosd->SetName(fDigitsTitle) ;
+      phosd->SetTitle(fHeaderFile) ;
+      phos->Add(phosd) ;
+    } 
+    else{
+      phosd = new AliPHOSRaw2Digits() ;
+      phosd->SetName(fDigitsTitle) ;
+      phosd->SetTitle(fHeaderFile) ;
+      phos->Add(phosd) ;
+    }      
   }
   return kTRUE;  
 }
@@ -684,16 +856,15 @@ Bool_t AliPHOSGetter::PostDigitizer(const char * name) const
 //____________________________________________________________________________ 
 TObject** AliPHOSGetter::DigitizerRef(const char * name) const 
 {  
+  // -------------- Return Digitizer task ------------------------------------
   TTask * sd  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ; 
   if ( !sd ) {
-    cerr << "ERROR: AliPHOSGetter::Post DerRef -> Task //" << fTasksFolder << "/Digitizer not found!" << endl;
-    abort();
+    Fatal("DigitizerRef", "Task //%s/Digitizer not found !", fTasksFolder) ;
   }        
 
   TTask * phos = dynamic_cast<TTask*>(sd->GetListOfTasks()->FindObject("PHOS")) ; 
   if ( !phos )  {
-    cerr <<"ERROR: AliPHOSGetter::Post DerRef ->  //" << fTasksFolder << "/Digitizer/PHOS" << endl;
-    abort();
+    Fatal("DigitizerRef", "//%s/Digitizer/PHOS", fTasksFolder) ;
   }        
 
   TTask * task = dynamic_cast<TTask*>(phos->GetListOfTasks()->FindObject(name)) ; 
@@ -703,7 +874,7 @@ TObject** AliPHOSGetter::DigitizerRef(const char * name) const
 }
  
 //____________________________________________________________________________ 
-Bool_t AliPHOSGetter::PostRecPoints(const char * name) const 
+const Bool_t AliPHOSGetter::PostRecPoints(const char * name) const 
 { // -------------- RecPoints -------------------------------------------
   
   // the hierarchy is //Folders/Run/Event/RecData/PHOS/EMCARecPoints/name
@@ -713,8 +884,8 @@ Bool_t AliPHOSGetter::PostRecPoints(const char * name) const
   
   if ( !phosFolder ) {
     if (fDebug) {
-      cout << "WARNING: AliPHOSGetter::Post RPo -> Folder //" << fRecoFolder->GetName() << "/PHOS/ not found!" << endl;
-      cout << "INFO:    AliPHOSGetter::Post Rpo -> Adding Folder //" << fRecoFolder->GetName() << "/PHOS/" << endl;
+      Warning("PostRecPoints", "-> Folder //%s/PHOS/ not found!", fRecoFolder->GetName()) ;
+      Info("PostRecPoints", "-> Adding Folder //%s/PHOS/", fRecoFolder->GetName()) ;
     }
     phosFolder = fRecoFolder->AddFolder("PHOS", "Reconstructed data from PHOS") ;  
   }    
@@ -723,8 +894,8 @@ Bool_t AliPHOSGetter::PostRecPoints(const char * name) const
   TFolder * phosRPoEMCAFolder  = dynamic_cast<TFolder*>(phosFolder->FindObject("EMCARecPoints")) ;
   if ( !phosRPoEMCAFolder ) {
     if (fDebug) {
-      cout << "WARNING: AliPHOSGetter::Post RPo -> Folder //" << fRecoFolder->GetName() << "/PHOS/EMCARecPoints/ not found!" << endl;
-      cout << "INFO:    AliPHOSGetter::Post Rpo -> Adding Folder //" << fRecoFolder->GetName() << "/PHOS/EMCARecPoints" << endl;
+      Warning("PostRecPoints", "-> Folder //%s/PHOS/EMCARecPoints/ not found!", fRecoFolder->GetName()) ;
+      Info("PostRecPoints", "-> Adding Folder //%s/PHOS/EMCARecPoints", fRecoFolder->GetName()) ;
     }
     phosRPoEMCAFolder = phosFolder->AddFolder("EMCARecPoints", "EMCA RecPoints from PHOS") ;  
   }    
@@ -740,8 +911,8 @@ Bool_t AliPHOSGetter::PostRecPoints(const char * name) const
   TFolder * phosRPoCPVFolder  = dynamic_cast<TFolder*>(phosFolder->FindObject("CPVRecPoints")) ;
   if ( !phosRPoCPVFolder ) {
     if (fDebug) {
-      cout << "WARNING: AliPHOSGetter::Post RPo -> Folder //" << fRecoFolder->GetName() << "/PHOS/CPVRecPoints/ not found!" << endl;
-      cout << "INFO:    AliPHOSGetter::Post Rpo -> Adding Folder //" << fRecoFolder->GetName() << "/PHOS/CPVRecPoints/" << endl;
+      Warning("PostRecPoints", "-> Folder //%s/PHOS/CPVRecPoints/ not found!", fRecoFolder->GetName()) ;
+      Info("PostRecPoints", "-> Adding Folder //%s/PHOS/CPVRecPoints/", fRecoFolder->GetName()) ;
     }
     phosRPoCPVFolder = phosFolder->AddFolder("CPVRecPoints", "CPV RecPoints from PHOS") ;  
   }    
@@ -762,21 +933,18 @@ TObject** AliPHOSGetter::EmcRecPointsRef(const char * name) const
   // the hierarchy is //Folders/Run/Event/RecData/PHOS/EMCARecPoints/name
    
   if ( !fRecoFolder ) {
-    cerr << "ERROR: AliPHOSGetter::EmcRecPointsRef -> Folder //" << fRecoFolder->GetName() << " not found!" << endl;
-    abort() ; 
+    Fatal("EmcRecPointsRef", "Folder //%s not found !", fRecoFolder->GetName() ) ;
   }    
 
   TFolder * phosFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("PHOS/EMCARecPoints")) ; 
   if ( !phosFolder ) {
-    cerr << "ERROR: AliPHOSGetter::EmcRecPointsRef -> Folder //" << fRecoFolder->GetName() << "/PHOS/EMCARecPoints/ not found!" << endl;
-    abort() ;
+     Fatal("EmcRecPointsRef", "Folder //%s/PHOS/EMCARecPoints/ not found !", fRecoFolder->GetName() ) ;
   }    
 
 
   TObject * erp = phosFolder->FindObject(name ) ;
   if ( !erp )   {
-    cerr << "ERROR: AliPHOSGetter::EmcRecPointsRef -> object " << name << " not found! " << endl ; 
-    abort() ;
+    Fatal("EmcRecPointsRef", "object %s not found !", name) ; 
   }
   return phosFolder->GetListOfFolders()->GetObjectRef(erp) ;
   
@@ -789,27 +957,24 @@ TObject** AliPHOSGetter::CpvRecPointsRef(const char * name) const
   // the hierarchy is //Folders/Run/Event/RecData/PHOS/CPVRecPoints/name
    
   if ( !fRecoFolder ) {
-    cerr << "ERROR: AliPHOSGetter::CpvRecPointsRef -> Folder //" << fRecoFolder->GetName() << " not found!" << endl;
-    abort() ; 
+    Fatal("CpvRecPointsRef", "Folder //%s not found !", fRecoFolder->GetName() ) ;
   }    
 
   TFolder * phosFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("PHOS/CPVRecPoints")) ; 
   if ( !phosFolder ) {
-    cerr << "ERROR: AliPHOSGetter::CpvRecPointsRef -> Folder //" << fRecoFolder->GetName() << "/PHOS/CPVRecPoints/" << endl;
-    abort() ;
+    Fatal("CpvRecPointsRef", "Folder //%s/PHOS/CPVRecPoints/ not found !", fRecoFolder->GetName() ) ;
   }    
 
   TObject * crp = phosFolder->FindObject(name ) ;
   if ( !crp )   {
-    cerr << "ERROR: AliPHOSGetter::CpvRecPointsRef -> object " << name << " not found " << endl ; 
-    abort() ;
+    Fatal("CpvRecPointsRef", "object %s nott found", name ) ; 
   }
   return phosFolder->GetListOfFolders()->GetObjectRef(crp) ;
   
 } 
 
 //____________________________________________________________________________ 
-Bool_t AliPHOSGetter::PostClusterizer(AliPHOSClusterizer * clu) const 
+const Bool_t AliPHOSGetter::PostClusterizer(AliPHOSClusterizer * clu) const 
 { // ------------------ AliPHOSClusterizer ------------------------
   
   // the hierarchy is //Folders/Tasks/Reconstructioner/PHOS/sdigitsname
@@ -817,15 +982,15 @@ Bool_t AliPHOSGetter::PostClusterizer(AliPHOSClusterizer * clu) const
   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
 
   if ( !tasks ) {
-    cerr << "ERROR: AliPHOSGetter::Post Rer -> Task //" << fTasksFolder << "/Reconstructioner not found!" << endl;
+    Error("PostClusterizer", "Task //%s/Reconstructioner not found !", fTasksFolder) ;
     return kFALSE ;
   }        
         
   TTask * phos = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("PHOS")) ; 
   if ( !phos )  {
     if (fDebug) {
-      cout <<"WARNING: AliPHOSGetter::Post Rer -> //" << fTasksFolder << "/ReconstructionerPHOS not found!" << endl
-      cout <<"INFO: AliPHOSGetter::Post Rer -> Adding //" << fTasksFolder << "/Reconstructioner/PHOS" << endl
+      Warning("PostClusterizer", "//%s/Reconstructioner/PHOS not found!", fTasksFolder) 
+      Info("PostClusterizer", "Adding //%s/Reconstructioner/PHOS", fTasksFolder) 
     }
     phos = new TTask("PHOS", "") ; 
     tasks->Add(phos) ; 
@@ -834,7 +999,7 @@ Bool_t AliPHOSGetter::PostClusterizer(AliPHOSClusterizer * clu) const
   AliPHOSClusterizer * phoscl = dynamic_cast<AliPHOSClusterizer*>(phos->GetListOfTasks()->FindObject(clu->GetName())) ; 
   if (phoscl) { 
     if (fDebug)
-      cout << "INFO: AliPHOSGetter::Post Rer -> Task " << clu->GetName() << " already exists" << endl ; 
+      Info("PostClusterizer", "Task %s already exists", clu->GetName()) ; 
     phoscl->Delete() ; 
     phos->GetListOfTasks()->Remove(phoscl) ;
   }
@@ -844,19 +1009,18 @@ Bool_t AliPHOSGetter::PostClusterizer(AliPHOSClusterizer * clu) const
 
 //____________________________________________________________________________ 
 TObject** AliPHOSGetter::ClusterizerRef(const char * name) const 
-{ // ------------------ AliPHOSClusterizer ------------------------
+{
+  // ------------------ AliPHOSClusterizer ------------------------
   
   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
 
   if ( !tasks ) {
-    cerr << "ERROR: AliPHOSGetter::ClusterizerRef -> Task //" << fTasksFolder->GetName() << "/Reconstructioner not found!" << endl;
-    abort() ;
+    Fatal("ClusterizerRef", "Task //%s/Reconstructioner not found !", fTasksFolder->GetName() ) ;
   }        
         
   TTask * phos = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("PHOS")) ; 
   if ( !phos )  {
-    cerr <<"WARNING: AliPHOSGetter::ClusterizerRef -> //" << fTasksFolder->GetName() << "/Reconstructioner/PHOS" << endl; 
-    abort() ; 
+    Fatal("ClusterizerRef", " //%s/Reconstructioner/PHOS not founf !", fTasksFolder->GetName() ) ; 
   }   
 
   TList * l = phos->GetListOfTasks() ; 
@@ -873,16 +1037,16 @@ TObject** AliPHOSGetter::ClusterizerRef(const char * name) const
     }
   }
 
-  if(clu) 
-    return l->GetObjectRef(clu) ;
-  else{
-    cerr << "ERROR: AliPHOSGetter::ClusterizerRef -> Task //" << fTasksFolder->GetName() << "/Reconstructioner/clusterizer " <<  name << " not found!" << endl;
-    abort() ;
+  if(!clu) {
+    Fatal("ClusterizerRef", "Task //%s/Reconstructioner/clusterizer/%s not found", fTasksFolder->GetName(), name) ;
   }
+
+  return l->GetObjectRef(clu) ;
+
 }
 
 //____________________________________________________________________________ 
-Bool_t AliPHOSGetter::PostClusterizer(const char * name) const 
+const Bool_t AliPHOSGetter::PostClusterizer(const char * name) const 
 { // ------------------ AliPHOSClusterizer ------------------------
 
   // the hierarchy is //Folders/Tasks/Reconstructioner/PHOS/sdigitsname
@@ -890,15 +1054,15 @@ Bool_t AliPHOSGetter::PostClusterizer(const char * name) const
   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
 
   if ( !tasks ) {
-    cerr << "ERROR: AliPHOSGetter::Post Rer -> Task//" << fTasksFolder << "/Reconstructioner not found!" << endl
+    Error("PostClusterizer", "Task//%s/Reconstructioner not found !", fTasksFolder) 
     return kFALSE ;
   }        
   
   TTask * phos = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("PHOS")) ; 
   if ( !phos )  {
     if (fDebug) {
-      cout <<"WARNING: AliPHOSGetter::Post Rer -> //" << fTasksFolder << "/Reconstructioner/PHOS not found!" << endl;
-      cout <<"INFO: AliPHOSGetter::Post Rer -> Adding //" << fTasksFolder << "/Reconstructioner/PHOS" << endl;
+      Warning("PostClusterizer", "//%s/Reconstructioner/PHOS not found!", fTasksFolder) ;
+      Info("PostClusterizer", "Adding //%s/Reconstructioner/PHOS", fTasksFolder) ;
     }
     phos = new TTask("PHOS", "") ; 
     tasks->Add(phos) ; 
@@ -916,14 +1080,16 @@ Bool_t AliPHOSGetter::PostClusterizer(const char * name) const
   }
 
   AliPHOSClusterizerv1 * phoscl = new AliPHOSClusterizerv1() ;
+  clun+="-v1" ; 
   phoscl->SetName(clun) ;
+  phoscl->SetTitle(fHeaderFile) ;
   phos->Add(phoscl) ;
   return kTRUE; 
   
 }
 
 //____________________________________________________________________________ 
-Bool_t AliPHOSGetter::PostTrackSegments(const char * name) const 
+const Bool_t AliPHOSGetter::PostTrackSegments(const char * name) const 
 { // ---------------TrackSegments -----------------------------------
   
   // the hierarchy is //Folders/Run/Event/RecData/PHOS/TrackSegments/name
@@ -932,8 +1098,8 @@ Bool_t AliPHOSGetter::PostTrackSegments(const char * name) const
   
   if ( !phosFolder ) {
     if (fDebug) {
-      cout << "WARNING: AliPHOSGetter::Post TS -> Folder //" << fRecoFolder << "/PHOS/ not found!" << endl;
-      cout << "INFO:    AliPHOSGetter::Post TS -> Adding Folder //" << fRecoFolder->GetName() << "/PHOS" << endl;
+      Warning("PostTrackSegments", "-> Folder //%s/PHOS/ not found", fRecoFolder->GetName()) ;
+      Info("PostTrackSegments", "-> Adding Folder //%s/PHOS", fRecoFolder->GetName()) ;
     }
     phosFolder = fRecoFolder->AddFolder("PHOS", "Reconstructed data from PHOS") ;  
   }    
@@ -941,8 +1107,8 @@ Bool_t AliPHOSGetter::PostTrackSegments(const char * name) const
   TFolder * phosTSFolder  = dynamic_cast<TFolder*>(phosFolder->FindObject("TrackSegments")) ;
   if ( !phosTSFolder ) {
     if (fDebug) {
-      cout << "WARNING: AliPHOSGetter::Post TS -> Folder//" << fRecoFolder->GetName() << "/PHOS/TrackSegments/ not found!" << endl
-      cout << "INFO:    AliPHOSGetter::Post TS -> Adding Folder //" << fRecoFolder->GetName() << "/PHOS/TrackSegments/" << endl
+      Warning("PostTrackSegments", "-> Folder //%s/PHOS/TrackSegments/ not found!", fRecoFolder->GetName() ) 
+      Info("PostTrackSegments", "-> Adding Folder //%s/PHOS/TrackSegments/", fRecoFolder->GetName()) 
     }
     phosTSFolder = phosFolder->AddFolder("TrackSegments", "TrackSegments from PHOS") ;  
   }    
@@ -963,26 +1129,23 @@ TObject** AliPHOSGetter::TrackSegmentsRef(const char * name) const
   // the hierarchy is //Folders/Run/Event/RecData/PHOS/TrackSegments/name
 
  if ( !fRecoFolder ) {
-    cerr << "ERROR: AliPHOSGetter::TrackSegmentsRef -> Folder //" << fRecoFolder->GetName() << "not found!" << endl;
-    abort() ; 
+    Fatal("TrackSegmentsRef", "Folder //%s not found !", fRecoFolder->GetName() ) ;
   }    
 
   TFolder * phosFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("PHOS/TrackSegments")) ; 
   if ( !phosFolder ) {
-    cerr << "ERROR: AliPHOSGetter::TrackSegmentsRef -> Folder //" << fRecoFolder->GetName() << "/PHOS/TrackSegments/ not found!" << endl;
-    abort() ;
+    Fatal("TrackSegmentsRef", "Folder //%s/PHOS/TrackSegments/ not found !", fRecoFolder->GetName() ) ;
   }    
   
   TObject * tss =  phosFolder->FindObject(name) ;
   if (!tss) {
-    cerr << "ERROR: AliPHOSGetter::TrackSegmentsRef -> object " << name << " not found! " << endl ;  
-    abort() ;  
+    Fatal("TrackSegmentsRef", "object %s not found !", name) ;  
   }
   return phosFolder->GetListOfFolders()->GetObjectRef(tss) ;
 } 
 
 //____________________________________________________________________________ 
-Bool_t AliPHOSGetter::PostTrackSegmentMaker(AliPHOSTrackSegmentMaker * tsmaker) const 
+const Bool_t AliPHOSGetter::PostTrackSegmentMaker(AliPHOSTrackSegmentMaker * tsmaker) const 
 { //------------Track Segment Maker ------------------------------
   
   // the hierarchy is //Folders/Tasks/Reconstructioner/PHOS/sdigitsname
@@ -990,15 +1153,15 @@ Bool_t AliPHOSGetter::PostTrackSegmentMaker(AliPHOSTrackSegmentMaker * tsmaker)
   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
 
   if ( !tasks ) {
-    cerr << "ERROR: AliPHOSGetter::Post Ter -> Task //" << fTasksFolder << "/Reconstructioner not found!" << endl;
+    Error("PostTrackSegmentMaker", "Task //%s/Reconstructioner not found !", fTasksFolder) ;
     return kFALSE ;
   }        
         
   TTask * phos = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("PHOS")) ; 
   if ( !phos )  {
     if (fDebug) {
-      cout <<"WARNING: AliPHOSGetter::Post Rer -> //" << fTasksFolder << "/Reconstructioner/PHOS not found!" << endl
-      cout <<"INFO: AliPHOSGetter::Post Rer -> Adding //" << fTasksFolder << "/Reconstructioner/PHOS" << endl;
+      Warning("PostTrackSegmentMaker", "//%s/Reconstructioner/PHOS not found!", fTasksFolder) 
+      Info("PostTrackSegmentMaker", "Adding //%s/Reconstructioner/PHOS", fTasksFolder) ;
     }
     phos = new TTask("PHOS", "") ; 
     tasks->Add(phos) ; 
@@ -1015,24 +1178,23 @@ Bool_t AliPHOSGetter::PostTrackSegmentMaker(AliPHOSTrackSegmentMaker * tsmaker)
   
 } 
 //____________________________________________________________________________ 
-Bool_t AliPHOSGetter::PostTrackSegmentMaker(const char * name) const 
-{ //------------Track Segment Maker ------------------------------
-  
+const Bool_t AliPHOSGetter::PostTrackSegmentMaker(const char * name) const 
+{ 
+  //------------Track Segment Maker ------------------------------
   // the hierarchy is //Folders/Tasks/Reconstructioner/PHOS/sdigitsname
   
-  
   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
   
   if ( !tasks ) {
-    cerr << "ERROR: AliPHOSGetter::Post Ter -> Task //" << fTasksFolder << "/Reconstructioner not found!" << endl;
+    Error("PostTrackSegmentMaker", "Task //%s/Reconstructioner not found !", fTasksFolder->GetName() ) ;
     return kFALSE ;
   }        
   
   TTask * phos = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("PHOS")) ; 
   if ( !phos )  {
     if (fDebug) {
-      cout <<"WARNING: AliPHOSGetter::Post Rer -> //" << fTasksFolder << "/Reconstructioner/PHOS not found!" << endl
-      cout <<"INFO: AliPHOSGetter::Post Rer -> Adding //" << fTasksFolder << "/Reconstructioner/PHOS" << endl;
+      Warning("PostTrackSegmentMaker", "//%s/Reconstructioner/PHOS not found!", fTasksFolder->GetName() ) 
+      Info("PostTrackSegmentMaker", "Adding //%s/Reconstructioner/PHOS", fTasksFolder->GetName()) ;
     }
     phos = new TTask("PHOS", "") ; 
     tasks->Add(phos) ; 
@@ -1050,8 +1212,9 @@ Bool_t AliPHOSGetter::PostTrackSegmentMaker(const char * name) const
   }
   
   AliPHOSTrackSegmentMakerv1 * phosts = new AliPHOSTrackSegmentMakerv1() ;
+  tsn+="-v1" ;
   phosts->SetName(tsn) ;
-
+  phosts->SetTitle(fHeaderFile) ;
   phos->Add(phosts) ;      
   return kTRUE; 
   
@@ -1059,19 +1222,18 @@ Bool_t AliPHOSGetter::PostTrackSegmentMaker(const char * name) const
 
 //____________________________________________________________________________ 
 TObject** AliPHOSGetter::TSMakerRef(const char * name) const 
-{ //------------Track Segment Maker ------------------------------
+{
+  //------------Track Segment Maker ------------------------------
   
   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
 
   if ( !tasks ) {
-    cerr << "ERROR: AliPHOSGetter::TSMakerRef -> Task //" << fTasksFolder << "/Reconstructioner not found!" << endl;
-    abort() ;
+    Fatal("TSMakerRef", "Task //%s/Reconstructioner not found !", fTasksFolder->GetName() ) ;
   }        
         
   TTask * phos = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("PHOS")) ; 
   if ( !phos )  {
-    cerr <<"WARNING: AliPHOSGetter::TSMakerRef -> //" << fTasksFolder << "/Reconstructioner/PHOS not found!" << endl; 
-    abort()  ; 
+    Fatal("TSMakerRef", "//%s/Reconstructioner/PHOS not found !", fTasksFolder->GetName() ) ; 
   }   
 
   TList * l = phos->GetListOfTasks() ; 
@@ -1088,26 +1250,26 @@ TObject** AliPHOSGetter::TSMakerRef(const char * name) const
     }
   }
   
-  if(tsm) 
-    return l->GetObjectRef(tsm) ;
-  else {
-    cerr << "ERROR: AliPHOSGetter::TSMakerRef -> Task //" << fTasksFolder << "/Reconstructioner/TrackSegmentMarker name not found!" << endl;
-    abort() ;
-  } 
+  if(!tsm) {
+   Fatal("TSMakerRef", "Task //%s/Reconstructioner/PHOS/TrackSegmentMarker/%s not found !", fTasksFolder->GetName(),  name) ;
+  }
+  return l->GetObjectRef(tsm) ;
+
 } 
 
 //____________________________________________________________________________ 
-Bool_t AliPHOSGetter::PostRecParticles(const char * name) const 
+const Bool_t AliPHOSGetter::PostRecParticles(const char * name) const 
 {  // -------------------- RecParticles ------------------------
   
-  // the hierarchy is //Folders/Run/Event/RecData/PHOS/TrackSegments/name
+  // the hierarchy is //Folders/Run/Event/RecData/PHOS/RecParticles/name
 
   TFolder * phosFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("PHOS")) ; 
   
   if ( !phosFolder ) {
     if (fDebug) {
-      cout << "WARNING: AliPHOSGetter::Post RPa -> Folder //" << fRecoFolder->GetName() << "/PHOS/ not found!" << endl;
-      cout << "INFO:    AliPHOSGetter::Post Rpa -> Adding Folder //" << fRecoFolder->GetName() << "/PHOS/" << endl;
+      Warning("PostRecParticles", "-> Folder //%s/PHOS/ not found!", fRecoFolder->GetName()) ;
+      Info("PostRecParticles", "-> Adding Folder //%s/PHOS/", fRecoFolder->GetName()) ;
     }
     phosFolder = fRecoFolder->AddFolder("PHOS", "Reconstructed data from PHOS") ;  
   }    
@@ -1115,8 +1277,8 @@ Bool_t AliPHOSGetter::PostRecParticles(const char * name) const
  TFolder * phosRPaFolder  = dynamic_cast<TFolder*>(phosFolder->FindObject("RecParticles")) ;
   if ( !phosRPaFolder ) {
     if (fDebug) {
-      cout << "WARNING: AliPHOSGetter::Post RPa -> Folder //" << fRecoFolder->GetName() << "/PHOS/RecParticles/ not found!" << endl;
-      cout << "INFO:    AliPHOSGetter::Post RPa -> Adding Folder //" << fRecoFolder->GetName() << "/PHOS/RecParticles/" << endl;
+      Warning("PostRecParticles", "-> Folder //%s/PHOS/RecParticles/ not found!", fRecoFolder->GetName()) ;
+      Info("PostRecParticles", "-> Adding Folder //%s/PHOS/RecParticles/", fRecoFolder->GetName()) ;
     }
     phosRPaFolder = phosFolder->AddFolder("RecParticles", "RecParticles from PHOS") ;  
   } 
@@ -1132,45 +1294,60 @@ Bool_t AliPHOSGetter::PostRecParticles(const char * name) const
 
 //____________________________________________________________________________ 
 TObject** AliPHOSGetter::RecParticlesRef(const char * name) const 
-{ // ---------------TrackSegments -----------------------------------
+{ // ---------------RecParticles -----------------------------------
   
   // the hierarchy is //Folders/Run/Event/RecData/PHOS/TrackSegments/name
 
  if ( !fRecoFolder ) {
-    cerr << "ERROR: AliPHOSGetter::RecParticlesRef -> Folder//" << fRecoFolder->GetName() << " not found!" << endl; 
-    abort() ; 
+    Fatal("RecParticlesRef", "Folder//%s not found !", fRecoFolder->GetName() ) ; 
   }    
 
   TFolder * phosFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("PHOS/RecParticles")) ; 
   if ( !phosFolder ) {
-    cerr << "ERROR: AliPHOSGetter::RecParticlesRef -> Folder //" << fRecoFolder->GetName() << "/PHOS/RecParticles/ not found!" << endl;
-    abort() ;
+    Fatal("RecParticlesRef", "Folder //%s/PHOS/RecParticles/ not found !", fRecoFolder->GetName() ) ;
   }    
 
   TObject * tss =  phosFolder->FindObject(name  ) ;
   if (!tss) {
-    cerr << "ERROR: AliPHOSGetter::RecParticlesRef -> object " << name << " not found! " << endl ; 
-    abort() ;  
+    Fatal("RecParticlesRef", "object %s not found !", name) ; 
   }
   return phosFolder->GetListOfFolders()->GetObjectRef(tss) ;
 }
-
 //____________________________________________________________________________ 
-Bool_t AliPHOSGetter::PostPID(AliPHOSPID * pid) const 
-{      // ------------AliPHOS PID -----------------------------
+const UShort_t AliPHOSGetter::EventPattern(void)
+{
+  // Return the pattern (trigger bit register) of the beam-test event
+  if(fBTE)
+    return fBTE->GetPattern() ;
+  else
+    return 0 ;
+}
+//____________________________________________________________________________ 
+const Float_t AliPHOSGetter::BeamEnergy(void)
+{
+  // Return the beam energy of the beam-test event
+  if(fBTE)
+    return fBTE->GetBeamEnergy() ;
+  else
+    return 0 ;
+}
+//____________________________________________________________________________ 
+const Bool_t AliPHOSGetter::PostPID(AliPHOSPID * pid) const 
+{ 
+  // ------------AliPHOS PID -----------------------------
 
   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
 
   if ( !tasks ) {
-    cerr << "ERROR: AliPHOSGetter::Post Per -> Task //" << fTasksFolder << "/Reconstructioner not found!" << endl;
+    Error("PostPID", "Task //%s/Reconstructioner not found !", fTasksFolder) ;
     return kFALSE ;
   }        
   
   TTask * phos = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("PHOS")) ; 
   if ( !phos )  {
     if (fDebug) {
-      cout <<"WARNING: AliPHOSGetter::Post Per -> //" << fTasksFolder << "/Reconstructioner/PHOS not found!" << endl
-      cout <<"INFO: AliPHOSGetter::Post Per -> Adding //" << fTasksFolder << "/Reconstructioner/PHOS" << endl;
+      Warning("PostPID", "//%s/Reconstructioner/PHOS not found!", fTasksFolder) 
+      Info("PostPID", "Adding //%s/Reconstructioner/PHOS", fTasksFolder) ;
     }
     phos = new TTask("PHOS", "") ; 
     tasks->Add(phos) ; 
@@ -1179,8 +1356,7 @@ Bool_t AliPHOSGetter::PostPID(AliPHOSPID * pid) const
   AliPHOSPID * phospid = dynamic_cast<AliPHOSPID*>(phos->GetListOfTasks()->FindObject(pid->GetName())) ; 
   if (phospid) { 
     if (fDebug)
-      cout << "INFO: AliPHOSGetter::Post Per -> Task " << pid->GetName()
-          << " already exists" << endl ; 
+      Info("PostPID", "-> Task %s qlready exists", pid->GetName()) ; 
     phos->GetListOfTasks()->Remove(phospid) ;
   }
   
@@ -1189,22 +1365,22 @@ Bool_t AliPHOSGetter::PostPID(AliPHOSPID * pid) const
 } 
 
 //____________________________________________________________________________ 
-Bool_t AliPHOSGetter::PostPID(const char * name) const 
+const Bool_t AliPHOSGetter::PostPID(const char * name) const 
 {     
   // the hierarchy is //Folders/Tasks/Reconstructioner/PHOS/sdigitsname
   
   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
 
   if ( !tasks ) {
-    cerr << "ERROR: AliPHOSGetter::Post Per -> Task //" << fTasksFolder << "/Reconstructioner not found!" << endl;
+    Error("PostPID", "Task //%s/Reconstructioner not found !", fTasksFolder->GetName() ) ;
     return kFALSE ;
   }        
   
   TTask * phos = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("PHOS")) ; 
   if ( !phos )  {
     if (fDebug) {
-      cout <<"WARNING: AliPHOSGetter::Post Per -> //" << fTasksFolder << "/Reconstructioner/PHOS not found!" << endl
-      cout <<"INFO: AliPHOSGetter::Post Per -> Adding //" << fTasksFolder << "/Reconstructioner/PHOS" << endl;
+      Warning("PostPID", "//%s/Reconstructioner/PHOS not found!", fTasksFolder->GetName()) 
+      Info("PostPID", "Adding //%s/Reconstructioner/PHOS", fTasksFolder->GetName()) ;
     }
     phos = new TTask("PHOS", "") ; 
     tasks->Add(phos) ; 
@@ -1213,7 +1389,7 @@ Bool_t AliPHOSGetter::PostPID(const char * name) const
   TList * l = phos->GetListOfTasks() ;   
   TIter it(l) ;
   TString pidname(name) ;
-  pidname+=":pidv1" ; 
+  pidname+=":pid" ;
   TTask * task ;
   while((task = static_cast<TTask *>(it.Next()) )){
     TString taskname(task->GetName()) ;
@@ -1222,7 +1398,9 @@ Bool_t AliPHOSGetter::PostPID(const char * name) const
   }
  
   AliPHOSPIDv1 * phospid = new AliPHOSPIDv1() ;
+  pidname+="-v1" ;
   phospid->SetName(pidname) ; 
+  phospid->SetTitle(fHeaderFile) ;
   phos->Add(phospid) ;      
   
   return kTRUE; 
@@ -1230,19 +1408,18 @@ Bool_t AliPHOSGetter::PostPID(const char * name) const
 
 //____________________________________________________________________________ 
 TObject** AliPHOSGetter::PIDRef(const char * name) const 
-{ //------------PID ------------------------------
+{
+  //------------PID ------------------------------
 
   TTask * tasks  = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ; 
 
   if ( !tasks ) {
-    cerr << "ERROR: AliPHOSGetter::PIDRef -> Task //" << fTasksFolder << "/Reconstructioner not found!" << endl;
-    abort() ;
+    Fatal("PIDRef", "Task //%s/Reconstructioner not found !", fTasksFolder->GetName() ) ;
   }        
         
   TTask * phos = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("PHOS")) ; 
   if ( !phos )  {
-    cerr << "ERROR: AliPHOSGetter::PIDRef -> //" << fTasksFolder << "/Reconstructioner/PHOS not found!" << endl; 
-    abort()  ; 
+    Fatal("PIDRef", "//%s/Reconstructioner/PHOS not found !", fTasksFolder->GetName() ) ; 
   }   
   
   TList * l = phos->GetListOfTasks() ; 
@@ -1259,17 +1436,15 @@ TObject** AliPHOSGetter::PIDRef(const char * name) const
     }
   }
   
-  if(pid) 
-    return l->GetObjectRef(pid) ;
-  else {
-    cerr << "ERROR: AliPHOSGetter::PIDRef -> Task //" << fTasksFolder << "/Reconstructioner/PID name not found!" << endl;
-    abort() ;
+  if(!pid) {
+    Fatal("PIDRef", "Task //%s/Reconstructioner/PHOS/PID/%s not found !", fTasksFolder->GetName(), name) ;
   }
   
+    return l->GetObjectRef(pid) ;
 } 
 
 //____________________________________________________________________________ 
-Bool_t AliPHOSGetter::PostQA(void) const 
+const Bool_t AliPHOSGetter::PostQA(void) const 
 { // ------------------ QA ---------------------------------
 
   // the hierarchy is //Folders/Run/Conditions/QA/PHOS/alarmsName
@@ -1277,8 +1452,8 @@ Bool_t AliPHOSGetter::PostQA(void) const
   TFolder * phosFolder = dynamic_cast<TFolder*>(fQAFolder->FindObject("PHOS")) ; 
   if ( !phosFolder ) {
     if (fDebug) {
-      cout << "WARNING: AliPHOSGetter::Post Q -> Folder //" << fQAFolder << "/PHOS/ not found!" << endl;
-      cout << "INFO:    AliPHOSGetter::Post Q -> Adding Folder //" << fQAFolder << "/PHOS/" << endl;
+      Warning("PostQA", "-> Folder //%s/PHOS/ not found!", fQAFolder) ;
+      Info("PostQA", "-> Adding Folder //%s/PHOS", fQAFolder) ;
     }
     phosFolder = fQAFolder->AddFolder("PHOS", "QA from PHOS") ; 
   }      
@@ -1293,46 +1468,135 @@ TObject** AliPHOSGetter::AlarmsRef(void) const
   
   // the hierarchy is //Folders/Run/Conditions/QA/PHOS
   if ( !fQAFolder ) {
-    cerr << "ERROR: AliPHOSGetter::AlarmsRef -> Folder //" << fQAFolder << " not found!" << endl;
-    abort() ;
+    Fatal("AlarmsRef", "Folder //%s not found !", fQAFolder) ;
   }    
  
   TFolder * phosFolder = dynamic_cast<TFolder *>(fQAFolder->FindObject("PHOS")) ;
   if ( !phosFolder ) {
-    cerr << "ERROR: AliPHOSGetter::AlarmsRef -> Folder //" << fQAFolder << "/PHOS/ not found!" << endl;
-    abort() ;
+    Fatal("AlarmsRef", "Folder //%s/PHOS/ not found !", fQAFolder) ;
   }
    
   return fQAFolder->GetListOfFolders()->GetObjectRef(phosFolder) ;
 }
 
+
 //____________________________________________________________________________ 
-const TParticle * AliPHOSGetter::Primary(Int_t index) const
+TTree * AliPHOSGetter::TreeK(TString filename)  
 {
-  // Return primary particle numbered by <index>
 
-  if(index < 0) 
-    return 0 ;
-  TParticle *  p = gAlice->Particle(index) ; 
-//   if (p->GetFirstMother() != -1 ) {
-//     cout << "AliPHOSGetter::Primary : Not a primary " << endl ; 
+  // returns TreeK from file filename
+  // usefull in case of split file
+
+  if ( filename.IsNull() ) 
+    filename = fHeaderFile ; 
+
+  TFile * file = 0 ; 
+  file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
+//   if (file && (filename != fHeaderFile) ) {  // file already open 
+//     file->Close() ; 
+//     //delete fAlice ; 
 //   }
-  return p ; 
+  if(!file || !file->IsOpen())    
+    file = TFile::Open(filename.Data(), "read") ;
+  if(filename != fHeaderFile ){
+    fAlice = dynamic_cast<AliRun *>(file->Get("gAlice")) ;
+  } 
+  TString treeName("TreeK") ; 
+  treeName += EventNumber()  ; 
+  TTree * tree = dynamic_cast<TTree *>(file->Get(treeName.Data())) ;
+  if (!tree && fDebug)  
+    Warning("TreeK", "-> %s not found in %s", treeName.Data(), filename.Data()) ; 
   
+  return tree ;                      
+}
+
+//____________________________________________________________________________ 
+TTree * AliPHOSGetter::TreeH(TString filename)  
+{
+
+  // returns TreeH from file filename
+  // usefull in case of split file
+
+  if ( filename.IsNull() ) 
+    filename = fHeaderFile ; 
+
+  TFile * file = 0 ; 
+  file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
+  if (!file) { // file not open yet
+    file = TFile::Open(filename.Data(), "read") ; 
+  }
+  TString treeName("TreeH") ; 
+  treeName += EventNumber()  ; 
+  TTree * tree = static_cast<TTree *>(file->Get(treeName.Data())) ;
+  if (!tree && fDebug)  
+    Warning("TreeH", "-> %s not found in %s", treeName.Data(), filename.Data()) ; 
   
-//   Int_t primaryIndex = index % 10000000 ; 
-//   Int_t primaryList = (Int_t ) ((index-primaryIndex)/10000000.)  ;
+  return tree ;                      
+}
+
+//____________________________________________________________________________ 
+TTree * AliPHOSGetter::TreeS(TString filename)  
+{
+
+  // returns TreeS from file filename
+  // usefull in case of split file
+
+  if ( filename.IsNull() ) 
+    filename = fHeaderFile ; 
+
+  TFile * file = 0 ; 
+  file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
+  if (!file) { // file not open yet
+    file = TFile::Open(filename.Data(), "read") ; 
+  }
+  TString treeName("TreeS") ; 
+  treeName += EventNumber()  ; 
+  TTree * tree = static_cast<TTree *>(file->Get(treeName.Data())) ;
+  if (!tree && fDebug)  
+    Warning("TreeS", "-> %s not found in %s", treeName.Data(), filename.Data() ); 
   
-//   if ( primaryList > 0  ) {
-//     if (fDebug) {
-//       cout << " Getter does not support currently Mixing of primary " << endl ;
-//       cout << "   can not return primary: " << index<< " (list "<< primaryList<< " primary # " << primaryIndex << " )"<<endl ;
-//     }
-//     return 0;
-//   }
+  return tree ;                      
+}
+
+//____________________________________________________________________________ 
+TTree * AliPHOSGetter::TreeD(TString filename)  
+{
+
+  // returns TreeD from file filename
+  // usefull in case of split file
+
+  if ( filename.IsNull() ) 
+    filename = fHeaderFile ; 
+
+  TFile * file = 0 ; 
+  file = static_cast<TFile*>(gROOT->GetFile(filename.Data() ) ) ;
+  if (!file) { // file not open yet
+    file = TFile::Open(filename.Data(), "read") ; 
+  }
+  TString treeName("TreeD") ; 
+  treeName += EventNumber()  ; 
+  TTree * tree = static_cast<TTree *>(file->Get(treeName.Data())) ;
+  if (!tree && fDebug)  
+    Warning("TreeD", "-> %s not found in %s", treeName.Data(), filename.Data()) ; 
   
-//   return gAlice->Particle(primaryIndex) ;
+  return tree ;                      
+}
+
+//____________________________________________________________________________ 
+const TParticle * AliPHOSGetter::Primary(Int_t index) const 
+{
+  // Return primary particle numbered by <index>
+
+  if(index < 0) 
+    return 0 ;
+  TParticle *  p = 0 ;
+  if (fAlice) 
+    p = fAlice->Particle(index) ; 
+  else 
+    p = gAlice->Particle(index) ; 
   
+  return p ; 
+    
 }
 
 //____________________________________________________________________________ 
@@ -1354,15 +1618,29 @@ const TParticle * AliPHOSGetter::Secondary(TParticle* p, Int_t index) const
 }
 
 //____________________________________________________________________________ 
-Int_t AliPHOSGetter::ReadTreeD()
+Int_t AliPHOSGetter::ReadTreeD(const Int_t event)
 {
   // Read the digit tree gAlice->TreeD()  
-  if(gAlice->TreeD()== 0){
-    cerr <<   "WARNING: AliPHOSGetter::ReadTreeD: can not read TreeD " << endl ;
-  return 1;
+  
+  TTree * treeD ;
+  if(fToSplit){
+    TFile * file = static_cast<TFile*>(gROOT->GetFile(fDigitsFileName)); 
+    if(!file) 
+      file = TFile::Open(fDigitsFileName) ;      
+    // Get Digits Tree header from file
+    TString treeName("TreeD") ;
+    treeName += event ; 
+    treeD = dynamic_cast<TTree*>(file->Get(treeName.Data()));
+    if(!treeD){ // TreeD not found in header file
+      if (fDebug)
+       Warning("ReadTreeD", "-> Cannot find TreeD in %s", fDigitsFileName.Data()) ;
+      return 1;
+    }
   }
+  else
+    treeD = gAlice->TreeD() ;
   
-  TObjArray * lob = static_cast<TObjArray*>(gAlice->TreeD()->GetListOfBranches()) ;
+  TObjArray * lob = static_cast<TObjArray*>(treeD->GetListOfBranches()) ;
   TIter next(lob) ; 
   TBranch * branch = 0 ; 
   TBranch * digitsbranch = 0 ; 
@@ -1374,55 +1652,119 @@ Int_t AliPHOSGetter::ReadTreeD()
       digitsbranch = branch ; 
       phosfound = kTRUE ;
     }
-    else if ( (strcmp(branch->GetName(), "AliPHOSDigitizer")==0) && (strcmp(branch->GetTitle(), fDigitsTitle)==0) ) {
+    else if ( ((strcmp(branch->GetName(), "AliPHOSDigitizer")==0)||
+              (strcmp(branch->GetName(), "AliPHOSRaw2Digits")==0)) &&
+             (strcmp(branch->GetTitle(), fDigitsTitle)==0) ) {
       digitizerbranch = branch ; 
       digitizerfound = kTRUE ; 
     }
   }
-
+  
   if ( !phosfound || !digitizerfound ) {
     if (fDebug)
-      cout << "WARNING: AliPHOSGetter::ReadTreeD -> Cannot find Digits and/or Digitizer with name " 
-          << fDigitsTitle << endl ;
+      Warning("ReadTreeD", "-> Cannot find Digits and/or Digitizer with name %s", fDigitsTitle.Data()) ;
     return 2; 
   }   
+  
   //read digits
   if(!Digits(fDigitsTitle) ) 
     PostDigits(fDigitsTitle);
+  else
+    Digits(fDigitsTitle)->Clear() ;
   digitsbranch->SetAddress(DigitsRef(fDigitsTitle)) ;
   digitsbranch->GetEntry(0) ;
   
-  
   // read  the Digitizer
-  if(!Digitizer(fDigitsTitle))
-    PostDigitizer(fDigitsTitle) ;
+  if(Digitizer()){
+    if(strcmp(Digitizer()->IsA()->GetName(),digitizerbranch->GetName())!=0){
+      RemoveTask("D", fDigitsTitle) ;
+      if(strcmp(digitizerbranch->GetName(), "AliPHOSDigitizer")==0)
+       PostDigitizer("Digitizer") ;
+      else
+       PostDigitizer("Raw2Digits") ;
+    }
+  }
+  else{
+    if(strcmp(digitizerbranch->GetName(), "AliPHOSDigitizer")==0)
+      PostDigitizer("Digitizer") ;
+    else
+      PostDigitizer("Raw2Digits") ;
+  }
+    
+
   digitizerbranch->SetAddress(DigitizerRef(fDigitsTitle)) ;
   digitizerbranch->GetEntry(0) ;
+  
+
+//   if((!fcdb)&&(strcmp(digitizerbranch->GetName(), "AliPHOSRaw2Digits")==0))
+//     ReadCalibrationDB("Primordial","beamtest.root") ;
+
+
+  if(gAlice->TreeD()!=treeD)
+    treeD->Delete();
+
   return 0 ; 
 }
+//____________________________________________________________________________ 
+//void AliPHOSGetter::ReadCalibrationDB(const char * database,const char * filename){
+//
+//  if(fcdb && (strcmp(database,fcdb->GetTitle())==0))
+//    return ;
+//
+//  TFile * file = gROOT->GetFile(filename) ;
+//  if(!file)
+//    file = TFile::Open(filename);
+//  if(!file){
+//    Error ("ReadCalibrationDB", "Cannot open file %s", filename) ;
+//    return ;
+//  }
+//  if(fcdb)
+//    fcdb->Delete() ;
+//  fcdb = dynamic_cast<AliPHOSCalibrationDB *>(file->Get("AliPHOSCalibrationDB")) ;
+//  if(!fcdb)
+//    Error ("ReadCalibrationDB", "No database %s in file %s", database, filename) ;
+//}
 
 //____________________________________________________________________________ 
 Int_t AliPHOSGetter::ReadTreeH()
 {
   // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
+  
+  TTree * treeH = gAlice->TreeH() ;
 
-  if(gAlice->TreeH()== 0){
-    cerr <<   "WARNING: AliPHOSGetter::ReadTreeH: -> Cannot read TreeH " << endl ;
-    return 1;
+  if(!treeH) {// TreeH not found in header file
+    if (fDebug) 
+      Warning("ReadTreeH", "-> Cannot find TreeH in %s", fHeaderFile.Data() ) ;
+    
+    TString searchFileName("PHOS.Hits") ; 
+    if((strcmp(fBranchTitle.Data(),"Default")!=0)&&(strcmp(fBranchTitle.Data(),"")!=0)){
+      searchFileName+="." ;
+      searchFileName += fBranchTitle ;
+    }
+    searchFileName+=".root" ;
+    
+    if ( (treeH = TreeH(searchFileName)) ) { //found TreeH in the file which contains the hits
+      if (fDebug) 
+       Info("ReadTreeH", "-> TreeH found in %s", searchFileName.Data()) ; 
+      
+    } else {
+      Error("ReadTreeH", "TreeH not found") ; 
+      return 1;
+    }  
   }
   
-  TBranch * hitsbranch = static_cast<TBranch*>(gAlice->TreeH()->GetBranch("PHOS")) ;
+  TBranch * hitsbranch = static_cast<TBranch*>(treeH->GetBranch("PHOS")) ;
   if ( !hitsbranch ) {
     if (fDebug)
-      cout << "WARNING:  AliPHOSGetter::ReadTreeH -> Cannot find branch PHOS" << endl ; 
+      Warning("ReadTreeH", "-> Cannot find branch PHOS") ; 
     return 2;
   }
   if(!Hits())
     PostHits() ;
 
   if (hitsbranch->GetEntries() > 1 ) {
+    (dynamic_cast<TClonesArray*> (*HitsRef()))->Clear() ;
     TClonesArray * tempo =  new TClonesArray("AliPHOSHit",1000) ;
     TClonesArray * hits = dynamic_cast<TClonesArray*>(*HitsRef()) ; 
     hitsbranch->SetAddress(&tempo) ;
@@ -1440,6 +1782,7 @@ Int_t AliPHOSGetter::ReadTreeH()
     delete tempo ; 
   }
   else {
+    (dynamic_cast<TClonesArray*> (*HitsRef()))->Clear() ;
     hitsbranch->SetAddress(HitsRef()) ;
     hitsbranch->GetEntry(0) ;
   }
@@ -1447,29 +1790,30 @@ Int_t AliPHOSGetter::ReadTreeH()
 }
 
 //____________________________________________________________________________ 
-void AliPHOSGetter::Track(Int_t itrack)
+void AliPHOSGetter::Track(const Int_t itrack) 
 {
   // Read the first entry of PHOS branch in hit tree gAlice->TreeH()
 
   if(gAlice->TreeH()== 0){
-    cerr <<   "ERROR: AliPHOSGetter::ReadTreeH: -> Cannot read TreeH " << endl ;
+    Error("Track", "Cannot read TreeH") ;
     return ;
   }
   
   TBranch * hitsbranch = dynamic_cast<TBranch*>(gAlice->TreeH()->GetListOfBranches()->FindObject("PHOS")) ;
   if ( !hitsbranch ) {
     if (fDebug)
-      cout << "WARNING:  AliPHOSGetter::ReadTreeH -> Cannot find branch PHOS" << endl ; 
+      Warning("Track", "Cannot find branch PHOS") ; 
     return ;
   }  
   if(!Hits())
     PostHits() ;
 
+  (dynamic_cast<TClonesArray*> (*HitsRef()))->Clear() ;
   hitsbranch->SetAddress(HitsRef()) ;
   hitsbranch->GetEntry(itrack) ;
 
-
 }
+
 //____________________________________________________________________________ 
 void AliPHOSGetter::ReadTreeQA()
 {
@@ -1477,14 +1821,14 @@ void AliPHOSGetter::ReadTreeQA()
   // so far only PHOS knows about this Tree  
 
   if(PHOS()->TreeQA()== 0){
-    cerr <<   "ERROR: AliPHOSGetter::ReadTreeQA: can not read TreeQA " << endl ;
+    Error("ReadTreeQA", "Cannot read TreeQA") ;
     return ;
   }
   
   TBranch * qabranch = PHOS()->TreeQA()->GetBranch("PHOS") ; 
   if (!qabranch) { 
     if (fDebug)
-      cout << "WARNING: AliPHOSGetter::ReadTreeQA -> Cannot find QA Alarms for PHOS" << endl ;
+      Warning("ReadTreeQA", "Cannot find QA Alarms for PHOS");
     return ; 
   }   
   
@@ -1504,7 +1848,7 @@ void AliPHOSGetter::ReadTreeQA()
 }
 
 //____________________________________________________________________________ 
-Int_t AliPHOSGetter::ReadTreeR(Bool_t any)
+Int_t AliPHOSGetter::ReadTreeR(const Int_t event)
 {
   // Read the reconstrunction tree gAlice->TreeR()
   // A particularity has been introduced here :
@@ -1517,12 +1861,37 @@ Int_t AliPHOSGetter::ReadTreeR(Bool_t any)
   // any migh have become obsolete : to be checked
   // See AliPHOSPIDv1    
 
-  if(gAlice->TreeR()== 0){
-    cerr <<   "WARNING: AliPHOSGetter::ReadTreeR: can not read TreeR " << endl ;
-    return 1;
+  //first - clean if necessary
+  if(EmcRecPoints(fRecPointsTitle)){
+    EmcRecPoints(fRecPointsTitle)->Delete() ;
+    CpvRecPoints(fRecPointsTitle)->Delete() ;
+  }
+  //clear TrackSegments
+  if(TrackSegments(fTrackSegmentsTitle))
+    TrackSegments(fTrackSegmentsTitle)->Clear() ;
+  if(RecParticles(fRecParticlesTitle))
+    RecParticles(fRecParticlesTitle)->Clear() ;
+       
+  TTree * treeR ;
+  if(fToSplit){
+    TFile * file = static_cast<TFile*>(gROOT->GetFile(fRecPointsFileName)); 
+    if(!file) 
+      file = TFile::Open(fRecPointsFileName) ;      
+    // Get Digits Tree header from file
+    TString treeName("TreeR") ;
+    treeName += event ; 
+    treeR = dynamic_cast<TTree*>(file->Get(treeName.Data()));
+    if(!treeR){ // TreeR not found in header file
+      if (fDebug)
+       Warning("ReadTreeD", "-> Cannot find TreeR in %s", fRecPointsFileName.Data()) ;
+      return 1;
+    }
   }
+  else
+    treeR = gAlice->TreeR() ;
+  
   // RecPoints 
-  TObjArray * lob = static_cast<TObjArray*>(gAlice->TreeR()->GetListOfBranches()) ;
+  TObjArray * lob = static_cast<TObjArray*>(treeR->GetListOfBranches()) ;
   TIter next(lob) ; 
   TBranch * branch = 0 ; 
   TBranch * emcbranch = 0 ; 
@@ -1531,9 +1900,8 @@ Int_t AliPHOSGetter::ReadTreeR(Bool_t any)
   Bool_t phosemcrpfound = kFALSE, phoscpvrpfound = kFALSE, clusterizerfound = kFALSE ; 
 
   
-  while ( (branch = static_cast<TBranch*>(next())) && (!phosemcrpfound || !phoscpvrpfound || !clusterizerfound) ) 
-
-    if(strcmp(branch->GetTitle(), fRecPointsTitle)==0 || any) {
+  while ( (branch = static_cast<TBranch*>(next())) && (!phosemcrpfound || !phoscpvrpfound || !clusterizerfound) ) {
+    if(strcmp(branch->GetTitle(), fRecPointsTitle)==0 ) {
       if ( strcmp(branch->GetName(), "PHOSEmcRP")==0) {
        emcbranch = branch ; 
        phosemcrpfound = kTRUE ;
@@ -1547,35 +1915,24 @@ Int_t AliPHOSGetter::ReadTreeR(Bool_t any)
        clusterizerfound = kTRUE ; 
       }
     }
+  }
 
-  if ( !phosemcrpfound ) {
+  if ( !phosemcrpfound || !phoscpvrpfound || !clusterizerfound) {
     if (fDebug)
-      cout << "WARNING: AliPHOSGetter::ReadTreeR -> Cannot find EmcRecPoints with title " 
-          << fRecPointsTitle << endl ;
+      Warning("ReadTreeR", "-> Cannot find RecPoints and/or Clusterizer with name %s", fRecPointsTitle.Data() ) ;
  
   } else { 
     if(!EmcRecPoints(fRecPointsTitle) ) 
       PostRecPoints(fRecPointsTitle) ;
     emcbranch->SetAddress(EmcRecPointsRef(fRecPointsTitle)) ;
     emcbranch->GetEntry(0) ;
-  }
-  
-  if ( !phoscpvrpfound ) {
-    if (fDebug)
-      cout << "WARNING: AliPHOSGetter::ReadTreeR -> Cannot find CpvRecPoints with title " 
-          << fRecPointsTitle << endl ; 
-  } else { 
+
     cpvbranch->SetAddress(CpvRecPointsRef(fRecPointsTitle)) ; 
-    cpvbranch->GetEntry(0) ;
-  }   
-  
-  if ( !clusterizerfound ) {
-    if (fDebug)
-      cout << "WARNING: AliPHOSGetter::ReadTreeR -> Can not find Clusterizer with title " 
-          << fRecPointsTitle << endl ; 
-  }  else { 
+    cpvbranch->GetEntry(0) ;  
+    
     if(!Clusterizer(fRecPointsTitle) )
       PostClusterizer(fRecPointsTitle) ;
+    
     clusterizerbranch->SetAddress(ClusterizerRef(fRecPointsTitle)) ;
     clusterizerbranch->GetEntry(0) ;
   }
@@ -1585,9 +1942,8 @@ Int_t AliPHOSGetter::ReadTreeR(Bool_t any)
   TBranch * tsbranch = 0 ; 
   TBranch * tsmakerbranch = 0 ; 
   Bool_t phostsfound = kFALSE, tsmakerfound = kFALSE ; 
-    
-  while ( (branch = static_cast<TBranch*>(next())) && (!phostsfound || !tsmakerfound) ) 
-    if(strcmp(branch->GetTitle(), fTrackSegmentsTitle)==0 || any)  {
+  while ( (branch = static_cast<TBranch*>(next())) && (!phostsfound || !tsmakerfound) ) {
+    if(strcmp(branch->GetTitle(), fTrackSegmentsTitle)==0 )  {
       if ( strcmp(branch->GetName(), "PHOSTS")==0){
        tsbranch = branch ; 
        phostsfound = kTRUE ;
@@ -1597,17 +1953,18 @@ Int_t AliPHOSGetter::ReadTreeR(Bool_t any)
        tsmakerfound  = kTRUE ; 
       }
     }
-  
+  }
+
   if ( !phostsfound || !tsmakerfound ) {
     if (fDebug)
-      cout << "WARNING: AliPHOSGetter::ReadTreeR -> Cannot find TrackSegments and/or TrackSegmentMaker with name "
-          << fTrackSegmentsTitle << endl ;
+      Warning("ReadTreeR", "-> Cannot find TrackSegments and/or TrackSegmentMaker with name %s", fTrackSegmentsTitle.Data() ) ;
   } else { 
     // Read and Post the TrackSegments
     if(!TrackSegments(fTrackSegmentsTitle))
       PostTrackSegments(fTrackSegmentsTitle) ;
     tsbranch->SetAddress(TrackSegmentsRef(fTrackSegmentsTitle)) ;
     tsbranch->GetEntry(0) ;
+
     // Read and Post the TrackSegment Maker
     if(!TrackSegmentMaker(fTrackSegmentsTitle))
       PostTrackSegmentMaker(fTrackSegmentsTitle) ;
@@ -1636,8 +1993,7 @@ Int_t AliPHOSGetter::ReadTreeR(Bool_t any)
   
   if ( !phosrpafound || !pidfound ) {
     if (fDebug)
-      cout << "WARNING: AliPHOSGetter::ReadTreeR -> Cannot find RecParticles and/or PID with name " 
-          << fRecParticlesTitle << endl ; 
+      Warning("ReadTreeR", "-> Cannot find RecParticles and/or PID with name %s", fRecParticlesTitle.Data() ) ; 
   } else { 
     // Read and Post the RecParticles
     if(!RecParticles(fRecParticlesTitle)) 
@@ -1650,49 +2006,43 @@ Int_t AliPHOSGetter::ReadTreeR(Bool_t any)
     pidbranch->SetAddress(PIDRef(fRecParticlesTitle)) ;
     pidbranch->GetEntry(0) ;
   }
+
+  if(gAlice->TreeR()!=treeR)
+    treeR->Delete();
   return 0 ; 
 }
 
 //____________________________________________________________________________ 
-Int_t AliPHOSGetter::ReadTreeS(Int_t event)
+Int_t AliPHOSGetter::ReadTreeS(const Int_t event)
 {
-  // Read the summable digits tree gAlice->TreeS()  
-  
-  // loop over all opened files and read their SDigits to the White Board
+  // Reads the SDigits treeS from all files  
+  // Files, which should be opened are listed in phosF
+  // So, first get list of files
   TFolder * phosF = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject("PHOS")) ;
   if (!phosF) 
     phosF = fSDigitsFolder->AddFolder("PHOS", "SDigits from PHOS") ; 
   TCollection * folderslist = phosF->GetListOfFolders() ; 
   
-  //Add current file to list if it is not there yet
-  
-  TString subdir(fHeaderFile) ;
-  subdir.ReplaceAll("/","_") ; 
-
-  if ( (subdir != "aliroot") && ( !folderslist->Contains(subdir) ) ){
-    phosF->AddFolder(subdir, ""); 
-  }
-    
+  // Now iterate over the list of files and read TreeS into Whiteboard
   TIter next(folderslist) ; 
   TFolder * folder = 0 ; 
   TFile * file; 
   TTree * treeS = 0;
   while ( (folder = static_cast<TFolder*>(next())) ) {
-    TString fileName(folder->GetName()) ; 
+    TString fileName("") ;
+    fileName = folder->GetName() ; 
     fileName.ReplaceAll("_","/") ; 
-    if(fHeaderFile.CompareTo(fileName) == 0 ) 
-      treeS=gAlice->TreeS() ;
-    else{
-      file = static_cast<TFile*>(gROOT->GetFile(fileName)); 
-      file->cd() ;
-      
-      // Get SDigits Tree header from file
-      TString treeName("TreeS") ;
-      treeName += event ; 
-      treeS = dynamic_cast<TTree*>(gDirectory->Get(treeName.Data()));
-    }
-    if(treeS==0){
-      cerr << "WARNING: AliPHOSGetter::ReadTreeS There is no SDigit Tree" << endl;
+    file = static_cast<TFile*>(gROOT->GetFile(fileName)); 
+    if(!file) 
+      file = TFile::Open(fileName) ;      
+    // Get SDigits Tree header from file
+    TString treeName("TreeS") ;
+    treeName += event ; 
+    treeS = dynamic_cast<TTree*>(file->Get(treeName.Data()));
+
+    if(!treeS){ // TreeS not found in header file
+      if (fDebug)
+       Warning("ReadTreeS", "-> Cannot find TreeS in %s", fileName.Data()) ;
       return 1;
     }
     
@@ -1703,28 +2053,32 @@ Int_t AliPHOSGetter::ReadTreeS(Int_t event)
     TObjArray * lob = static_cast<TObjArray*>(treeS->GetListOfBranches()) ;
     TIter next(lob) ; 
     Bool_t phosfound = kFALSE, sdigitizerfound = kFALSE ; 
-    
+
     while ( (branch = static_cast<TBranch*>(next())) && (!phosfound || !sdigitizerfound) ) {
       if ( (strcmp(branch->GetName(), "PHOS")==0) && (strcmp(branch->GetTitle(), fSDigitsTitle)==0) ) {
        phosfound = kTRUE ;
        sdigitsBranch = branch ; 
       }
       
-      else if ( (strcmp(branch->GetName(), "AliPHOSSDigitizer")==0) && (strcmp(branch->GetTitle(), fSDigitsTitle)==0) ) {
+      else if ( (strcmp(branch->GetName(), "AliPHOSSDigitizer")==0) && 
+               (strcmp(branch->GetTitle(), fSDigitsTitle)==0) ) {
        sdigitizerfound = kTRUE ; 
        sdigitizerBranch = branch ;
       }
     }
     if ( !phosfound || !sdigitizerfound ) {
       if (fDebug)
-       cout << "WARNING: AliPHOSDigitizer::ReadSDigits -> Digits and/or Digitizer branch with name " << GetName() 
-            << " not found" << endl ;
+       Warning("ReadSDigits", "-> Digits and/or Digitizer branch with name %s not found", GetName()) ;
       return 2; 
     }   
     
-    if ( !folder->FindObject(fSDigitsTitle) )  
-      PostSDigits(fSDigitsTitle,folder->GetName()) ;
+    if ( !folder->FindObject(fSDigitsTitle) ){  
+      TClonesArray * sdigits = new TClonesArray("AliPHOSDigit",1) ;
+      sdigits->SetName(fSDigitsTitle) ;
+      folder->Add(sdigits) ;
+    }
 
+    ((TClonesArray*) (*SDigitsRef(fSDigitsTitle,folder->GetName())))->Clear() ;
     sdigitsBranch->SetAddress(SDigitsRef(fSDigitsTitle,folder->GetName())) ;
     sdigitsBranch->GetEntry(0) ;
     
@@ -1733,28 +2087,18 @@ Int_t AliPHOSGetter::ReadTreeS(Int_t event)
     sdname+=folder->GetName() ;
     if(!SDigitizer(sdname) ) 
       PostSDigitizer(fSDigitsTitle,folder->GetName()) ;
-
     sdigitizerBranch->SetAddress(SDigitizerRef(sdname)) ;
-    sdigitizerBranch->GetEntry(0) ;
-    
+    sdigitizerBranch->GetEntry(0) ; 
+    if(gAlice->TreeS()!=treeS)
+      treeS->Delete();
   }    
-  
-  // After SDigits have been read from all files, return to the first one
-  
-  next.Reset();
-  folder = static_cast<TFolder*>(next());
-  if(folder){
-    TString fileName(folder->GetName()) ; 
-    fileName.ReplaceAll("_","/") ; 
-    file   = static_cast<TFile*>(gROOT->GetFile(fileName)); 
-    file   ->cd() ;
-  }
   return 0 ; 
 }
+
 //____________________________________________________________________________ 
 void AliPHOSGetter::ReadTreeS(TTree * treeS, Int_t input)
-{  // Read the summable digits fron treeS()  
-
+{
+  // Read the summable digits fron treeS()  
 
   TString filename("mergefile") ;
   filename+= input ;
@@ -1785,25 +2129,26 @@ void AliPHOSGetter::ReadTreeS(TTree * treeS, Int_t input)
   }
   if ( !phosfound || !sdigitizerfound ) {
     if (fDebug)
-      cout << "WARNING: AliPHOSGetter::ReadTreeS -> Digits and/or Digitizer branch not found" << endl ;
+      Warning("ReadTreeS", "-> Digits and/or Digitizer branch not found") ;
     return ; 
   }   
   
   if (!folder || !(folder->FindObject(sdigitsBranch->GetTitle()) ) )
     PostSDigits(sdigitsBranch->GetTitle(),filename) ;
 
-  sdigitsBranch->SetAddress(SDigitsRef(sdigitsBranch->GetTitle(),filename)) ;
+  sdigitsBranch->SetAddress(SDigitsRef(sdigitsBranch->GetTitle(),folder->GetName())) ;
   sdigitsBranch->GetEntry(0) ;
   
   TString sdname(sdigitsBranch->GetTitle()) ;
   sdname+=":" ;
   sdname+=filename ;
+  
   if(!SDigitizer(sdigitsBranch->GetTitle()) )
     PostSDigitizer(sdigitsBranch->GetTitle(),filename) ;
-
   sdigitizerBranch->SetAddress(SDigitizerRef(sdname)) ;
   sdigitizerBranch->GetEntry(0) ;
-  
+  if(gAlice->TreeS()!=treeS)
+    treeS->Delete();
 }    
 
 
@@ -1819,52 +2164,72 @@ void AliPHOSGetter::ReadPrimaries()
   }
   ar->Delete() ; 
   
-  fNPrimaries = gAlice->GetNtrack() ; 
+  if (TreeK(fHeaderFile)) { // treeK found in header file
+    if (fDebug) 
+      Info("ReadPrimaries", "-> TreeK found in %s", fHeaderFile.Data() ); 
+    fNPrimaries = gAlice->GetNtrack() ; 
+    fAlice = 0 ; 
+  
+  } else { // treeK not found in header file
+    Error("ReadPrimaries", "TreeK not found") ; 
+    return ;  
+  }
+
   Int_t index = 0 ; 
   for (index = 0 ; index < fNPrimaries; index++) { 
     new ((*ar)[index]) TParticle(*(Primary(index)));
   }
 }
+
 //____________________________________________________________________________ 
-void AliPHOSGetter::Event(const Int_t event, const char* opt)
+void AliPHOSGetter::Event(const Int_t event, const char* opt)  
 {
   // Reads the content of all Tree's S, D and R
+
   if (event >= gAlice->TreeE()->GetEntries() ) {
-    cerr << "ERROR: AliPHOSGetter::Event -> " << event << " not found in TreeE!" << endl ; 
+    Error("Event", "%d not found in TreeE !", event) ; 
     return ; 
   }
 
+  TBranch * btb = gAlice->TreeE()->GetBranch("AliPHOSBeamTestEvent") ;
+  if(btb){
+    if(!fBTE)
+      fBTE = new AliPHOSBeamTestEvent() ;
+    btb->SetAddress(&fBTE) ;
+    btb->GetEntry(event) ;
+  }
+  else{
+    if(fBTE){
+      delete fBTE ;
+      fBTE = 0 ;
+    }
+  }
+
   Bool_t any = kFALSE ; 
   if (strstr(opt,"A") ) // do not check the title of the branches
     any = kTRUE; 
 
   gAlice->GetEvent(event) ; 
 
-  Int_t rvRH = 0 ;
-  Int_t rvRS = 0 ;
-  Int_t rvRD = 0 ;
-  Int_t rvRR = 0 ;
-
-  if(strstr(opt,"H") )
-    rvRH = ReadTreeH() ;
-  
-  if(strstr(opt,"S") )
-    rvRS = ReadTreeS(event) ;
+  if( strstr(opt,"R") )
+    ReadTreeR(event) ;
 
   if( strstr(opt,"D") )
-    rvRD = ReadTreeD() ;
+    ReadTreeD(event) ;
 
-  if( strstr(opt,"R") )
-    rvRR = ReadTreeR(any) ;
+  if(strstr(opt,"S") )
+    ReadTreeS(event) ;
 
+  if(strstr(opt,"H") )
+    ReadTreeH() ;
+   
   if( strstr(opt,"Q") )
     ReadTreeQA() ;
 
   if( strstr(opt,"P") || (strcmp(opt,"")==0) )
-    if ( gAlice->Stack() ) 
-      ReadPrimaries() ;
+    ReadPrimaries() ;
 
 }
 
 //____________________________________________________________________________ 
@@ -1875,15 +2240,18 @@ TObject * AliPHOSGetter::ReturnO(TString what, TString name, TString file) const
 
   if ( file.IsNull() ) 
     file = fHeaderFile ; 
+  if( name.IsNull() )
+    name = fBranchTitle ;
 
   TFolder * folder = 0 ;
   TObject * phosO  = 0 ; 
 
-  //  if ( name.IsNull() ) {
   if ( what.CompareTo("Primaries") == 0 ) {
     folder = dynamic_cast<TFolder *>(fPrimariesFolder->FindObject("Primaries")) ; 
     if (folder) 
       phosO  = dynamic_cast<TObject *>(folder->FindObject("Primaries")) ;  
+    else 
+      return 0 ; 
   }
   else if ( what.CompareTo("Hits") == 0 ) {
     folder = dynamic_cast<TFolder *>(fHitsFolder->FindObject("PHOS")) ; 
@@ -1891,7 +2259,16 @@ TObject * AliPHOSGetter::ReturnO(TString what, TString name, TString file) const
       phosO  = dynamic_cast<TObject *>(folder->FindObject("Hits")) ;  
   }
   else if ( what.CompareTo("SDigits") == 0 ) {
-    file.ReplaceAll("/","_") ; 
+    if(fToSplit){
+      file.Remove(file.Last('/')+1,file.Length()-file.Last('/')-1) ;
+      file.ReplaceAll("/","_") ; 
+      file+="PHOS.SDigits." ;
+      if(name && (strcmp(name,"Default")!=0)){
+       file+=name ;
+       file+="." ;
+      }
+      file+="root" ;
+    }
     TString path = "PHOS/" + file  ;
     folder = dynamic_cast<TFolder *>(fSDigitsFolder->FindObject(path.Data())) ; 
     if (folder) { 
@@ -1941,19 +2318,11 @@ TObject * AliPHOSGetter::ReturnO(TString what, TString name, TString file) const
     }   
  }
   else if ( what.CompareTo("Alarms") == 0 ){ 
-    if (name.IsNull() ) 
-      phosO = dynamic_cast<TObject *>(fQAFolder->FindObject("PHOS")) ;  
-    else {
-      folder = dynamic_cast<TFolder *>(fQAFolder->FindObject("PHOS")) ; 
-      if (!folder) 
-       phosO = 0 ; 
-      else 
-       phosO = dynamic_cast<TObject *>(folder->FindObject(name)) ;  
-    }
+      phosO = dynamic_cast<TFolder *>(fQAFolder->FindObject("PHOS")) ;        
   }
   if (!phosO) {
     if(fDebug)
-      cerr << "ERROR : AliPHOSGetter::ReturnO -> Object " << what << " not found in " << fQAFolder->GetName() << endl ; 
+      Warning("ReturnO", "Object %s not found in PHOS", what.Data() ) ; 
     return 0 ;
   }
 
@@ -1979,13 +2348,13 @@ const TTask * AliPHOSGetter::ReturnT(TString what, TString name) const
   TTask * tasks = dynamic_cast<TTask*>(fTasksFolder->FindObject(search)) ; 
 
   if (!tasks) {
-    cerr << "ERROR: AliPHOSGetter::ReturnT -> Task " << what << " not found!" << endl ;  
+    Error("ReturnT", "Task %s not found !", what.Data() ) ;  
     return 0 ; 
   }
 
   TTask * phosT = dynamic_cast<TTask*>(tasks->GetListOfTasks()->FindObject("PHOS")) ; 
   if (!phosT) { 
-    cerr << "ERROR: AliPHOSGetter::ReturnT -> Task " << what << "/PHOS not found!" << endl ;  
+     Error("ReturnT", "Task %s/PHOS not found !", what.Data() ) ;  
     return 0 ; 
   }
   
@@ -2000,12 +2369,12 @@ const TTask * AliPHOSGetter::ReturnT(TString what, TString name) const
   } else  if (what.CompareTo("Clusterizer") == 0){ 
     if ( name.IsNull() )
       name =  fRecPointsTitle ;
-    name.Append(":clusterizer") ;
+    name.Append(":clu") ;
   }
   else  if (what.CompareTo("TrackSegmentMaker") == 0){ 
     if ( name.IsNull() )
       name =  fTrackSegmentsTitle ;
-    name.Append(":tracksegmentmaker") ;
+    name.Append(":tsm") ;
   }
   else  if (what.CompareTo("PID") == 0){ 
     if ( name.IsNull() )
@@ -2026,6 +2395,386 @@ const TTask * AliPHOSGetter::ReturnT(TString what, TString name) const
   }
   
   if(fDebug)
-    cout << "WARNING: AliPHOSGetter::ReturnT -> Task " << search << "/" << name << " not found!" << endl ; 
+    Warning("ReturnT", "-> Task %s/PHOS/%s not found", search.Data(), name.Data() ) ; 
   return 0 ;
 }
+
+//____________________________________________________________________________ 
+void AliPHOSGetter::RemoveTask(TString opt, TString name) const 
+{
+  // remove a task from the folder
+  // path is fTasksFolder/SDigitizer/PHOS/name
+  
+  TTask * task = 0 ; 
+  TTask * phos = 0 ; 
+  TList * lofTasks = 0 ; 
+
+  if (opt == "S") { // SDigitizer
+    task = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ;
+    if (!task) 
+      return ; 
+  }
+  else if (opt == "D") { // Digitizer
+    task = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ;
+    if (!task) 
+      return ; 
+  }
+  else if (opt == "C" || opt == "T" || opt == "P"  ) { // Clusterizer, TrackSegmentMaker, PID
+    task = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ;
+    if (!task) 
+      return ; 
+  }
+  else {
+    Warning("RemoveTask", "Unknown option %s", opt.Data() ); 
+    return ; 
+  }
+  phos =  dynamic_cast<TTask*>(task->GetListOfTasks()->FindObject("PHOS")) ;
+  if (!phos)
+    return ; 
+  lofTasks = phos->GetListOfTasks() ;
+  if (!lofTasks) 
+    return ; 
+  TObject * obj = lofTasks->FindObject(name) ; 
+  if (obj) 
+    lofTasks->Remove(obj) ;
+   
+}
+
+//____________________________________________________________________________ 
+void AliPHOSGetter::RemoveObjects(TString opt, TString name) const 
+{
+  // remove SDigits from the folder
+  // path is fSDigitsFolder/fHeaderFileName/name
+
+  TFolder * phos     = 0 ; 
+  TFolder * phosmain = 0 ; 
+
+  if (opt == "H") { // Hits
+    phos = dynamic_cast<TFolder*>(fHitsFolder->FindObject("PHOS")) ;
+    if (!phos) 
+      return ;
+    name = "Hits" ; 
+  }
+
+  else if ( opt == "S") { // SDigits
+    phosmain = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("PHOS")) ;
+    if (!phosmain) 
+      return ;
+    phos = dynamic_cast<TFolder*>(phosmain->FindObject(fHeaderFile)) ;
+    if (!phos) 
+      return ;
+  }
+  
+  else if (opt == "D") { // Digits
+    phos = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("PHOS")) ;
+    if (!phos) 
+      return ;
+  }
+
+  else if (opt == "RE") { // EMCARecPoints
+    phos = dynamic_cast<TFolder*>(fRecoFolder->FindObject("PHOS/EMCARecPoints")) ;
+    if (!phos) 
+      return ;
+  }
+
+  else if (opt == "RC") { // CPVRecPoints
+    phos = dynamic_cast<TFolder*>(fRecoFolder->FindObject("PHOS/CPVRecPoints")) ;
+    if (!phos) 
+      return ;
+  }  
+
+  else if (opt == "T") { // TrackSegments
+    phos = dynamic_cast<TFolder*>(fRecoFolder->FindObject("PHOS/TrackSegments")) ;
+    if (!phos) 
+      return ;
+  }
+
+  else if (opt == "P") { // RecParticles
+    phos = dynamic_cast<TFolder*>(fRecoFolder->FindObject("PHOS/RecParticles")) ;
+    if (!phos) 
+      return ;
+  }
+  
+  else {
+    Warning("RemoveObjects", "Unknown option %s", opt.Data() ) ; 
+    return ; 
+  }
+  
+  TObjArray * ar  = dynamic_cast<TObjArray*>(phos->FindObject(name)) ; 
+  if (ar) { 
+    phos->Remove(ar) ;
+    ar->Delete() ; 
+    delete ar ; 
+  }
+
+  if (opt == "S") 
+    phosmain->Remove(phos) ; 
+  
+}
+
+//____________________________________________________________________________ 
+void AliPHOSGetter::RemoveSDigits() const 
+{
+  // Clean SDigit array
+
+  TFolder * phos= dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("PHOS")) ;
+  if (!phos) 
+    return ;
+  
+  phos->SetOwner() ; 
+  phos->Clear() ; 
+}
+
+//____________________________________________________________________________ 
+void AliPHOSGetter::CleanWhiteBoard(void)
+{
+  // Delete all PHOS objects from folders
+
+  TFolder * phosmain = 0 ; 
+  TFolder * phos ;
+  TObjArray * ar ;
+  TList * lofTasks = 0 ; 
+  TTask * task = 0 ; 
+  TTask * phost = 0 ; 
+  
+  // Hits  
+  phos = dynamic_cast<TFolder*>(fHitsFolder->FindObject("PHOS")) ;
+  if (phos){  
+    TObjArray * ar  = dynamic_cast<TObjArray*>(phos->FindObject("Hits")) ; 
+    if (ar) { 
+      phos->Remove(ar) ;
+      ar->Delete() ; 
+      delete ar ; 
+    }
+  }
+  
+  // SDigits
+  phosmain = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("PHOS")) ;
+  if (phosmain){ 
+    phos = dynamic_cast<TFolder*>(phosmain->FindObject(fHeaderFile)) ;
+    if (phos) {
+      ar  = dynamic_cast<TObjArray*>(phos->FindObject(fSDigitsTitle)) ; 
+      if (ar) { 
+       phos->Remove(ar) ;
+       ar->Delete() ; 
+       delete ar ; 
+      }
+    }
+    phosmain->Remove(phos) ; 
+  }
+
+  
+  // Digits
+  phos = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("PHOS")) ;
+  if (phos){ 
+    ar  = dynamic_cast<TObjArray*>(phos->FindObject(fDigitsTitle)) ; 
+    if (ar) { 
+      phos->Remove(ar) ;
+      ar->Delete() ; 
+      delete ar ; 
+    }
+  }
+
+
+  // EMCARecPoints
+  phos = dynamic_cast<TFolder*>(fRecoFolder->FindObject("PHOS/EMCARecPoints")) ;
+  if (phos){ 
+    ar  = dynamic_cast<TObjArray*>(phos->FindObject(fRecPointsTitle)) ; 
+    if (ar) { 
+      phos->Remove(ar) ;
+      ar->Delete() ; 
+      delete ar ; 
+    }
+  }
+
+  
+  // CPVRecPoints
+  phos = dynamic_cast<TFolder*>(fRecoFolder->FindObject("PHOS/CPVRecPoints")) ;
+  if (phos){ 
+    ar  = dynamic_cast<TObjArray*>(phos->FindObject(fRecPointsTitle)) ; 
+    if (ar) { 
+      phos->Remove(ar) ;
+      ar->Delete() ; 
+      delete ar ; 
+    }
+  }  
+
+  
+  // TrackSegments
+  phos = dynamic_cast<TFolder*>(fRecoFolder->FindObject("PHOS/TrackSegments")) ;
+  if (phos) { 
+    ar  = dynamic_cast<TObjArray*>(phos->FindObject(fTrackSegmentsTitle)) ; 
+    if (ar) { 
+      phos->Remove(ar) ;
+      ar->Delete() ; 
+      delete ar ; 
+    }
+  }
+  
+
+
+  // RecParticles
+  phos = dynamic_cast<TFolder*>(fRecoFolder->FindObject("PHOS/RecParticles")) ;
+  if (phos){ 
+    ar  = dynamic_cast<TObjArray*>(phos->FindObject(fRecParticlesTitle)) ; 
+    if (ar) { 
+      phos->Remove(ar) ;
+      ar->Delete() ; 
+      delete ar ; 
+    }
+  }
+
+
+  //---- Now Tasks ----------- 
+
+  TObject * obj ;
+  TString sdname(fSDigitsTitle);
+  
+  // Digitizer
+  task = dynamic_cast<TTask*>(fTasksFolder->FindObject("Digitizer")) ;
+  if (task){ 
+    phost =  dynamic_cast<TTask*>(task->GetListOfTasks()->FindObject("PHOS")) ;
+    if (phost){
+      lofTasks = phost->GetListOfTasks() ;
+      if (lofTasks){ 
+       obj = lofTasks->FindObject(sdname.Data()) ; 
+       if (obj) 
+         lofTasks->Remove(obj) ;
+      }
+    }      
+  }
+  
+
+  sdname.Append(":") ;
+  // Clusterizer, TrackSegmentMaker, PID
+  task = dynamic_cast<TTask*>(fTasksFolder->FindObject("Reconstructioner")) ;
+  if (task){ 
+    phost =  dynamic_cast<TTask*>(task->GetListOfTasks()->FindObject("PHOS")) ;
+    if (phost){
+      lofTasks = phost->GetListOfTasks() ;
+      TIter next(lofTasks);
+      while((obj=next())){ 
+       TString oname(obj->GetName()) ;
+       if (oname.BeginsWith(sdname)){ 
+         lofTasks->Remove(obj) ;
+       }
+      }
+    }  
+  }
+
+
+  // SDigitizer
+  sdname.Append(fHeaderFile) ;
+  task = dynamic_cast<TTask*>(fTasksFolder->FindObject("SDigitizer")) ;
+  if (task) {
+    phost =  dynamic_cast<TTask*>(task->GetListOfTasks()->FindObject("PHOS")) ;
+    if (phost){
+      lofTasks = phost->GetListOfTasks() ;
+      if (lofTasks){ 
+       obj = lofTasks->FindObject(sdname.Data()) ; 
+       if (obj) 
+         lofTasks->Remove(obj) ;
+      }
+    }
+  }  
+
+}
+//____________________________________________________________________________ 
+void AliPHOSGetter::SetTitle(const char * branchTitle ) 
+{
+  // Set branch titles and add folders with PHOS data
+
+  fBranchTitle        = branchTitle ;
+  fSDigitsTitle       = branchTitle ; 
+  fDigitsTitle        = branchTitle ; 
+  fRecPointsTitle     = branchTitle ; 
+  fRecParticlesTitle  = branchTitle ; 
+  fTrackSegmentsTitle = branchTitle ; 
+  if(fToSplit){
+    //First - extract full path if necessary
+    TString sFileName(fHeaderFile) ;
+    Ssiz_t islash = sFileName.Last('/') ;
+    if(islash<sFileName.Length())
+      sFileName.Remove(islash+1,sFileName.Length()) ;
+    else
+      sFileName="" ;
+    //Now construct file names
+    fSDigitsFileName       = sFileName ;
+    fDigitsFileName        = sFileName ; 
+    fRecPointsFileName     = sFileName ; 
+    fRecParticlesFileName  = sFileName ; 
+    fTrackSegmentsFileName = sFileName ; 
+    fSDigitsFileName      += "PHOS.SDigits." ;
+    fDigitsFileName       += "PHOS.Digits." ; 
+    fRecPointsFileName    += "PHOS.RecData." ; 
+    fTrackSegmentsFileName+= "PHOS.RecData." ; 
+    fRecParticlesFileName += "PHOS.RecData." ; 
+    if((strcmp(fBranchTitle.Data(),"Default")!=0)&&(strcmp(fBranchTitle.Data(),"")!=0)){
+      fSDigitsFileName      += fBranchTitle ;
+      fSDigitsFileName      += "." ;
+      fDigitsFileName       += fBranchTitle ; 
+      fDigitsFileName       += "." ; 
+      fRecPointsFileName    += fBranchTitle ; 
+      fRecPointsFileName    += "." ; 
+      fRecParticlesFileName += fBranchTitle ; 
+      fRecParticlesFileName += "." ; 
+      fTrackSegmentsFileName+= fBranchTitle ; 
+      fTrackSegmentsFileName+= "." ; 
+    }
+    fSDigitsFileName      += "root" ;
+    fDigitsFileName       += "root" ; 
+    fRecPointsFileName    += "root" ; 
+    fRecParticlesFileName += "root" ; 
+    fTrackSegmentsFileName+= "root" ; 
+  }else{
+    fSDigitsFileName       = fHeaderFile ;
+
+    fDigitsFileName        = "" ; 
+    fRecPointsFileName     = "" ; 
+    fRecParticlesFileName  = "" ; 
+    fTrackSegmentsFileName = "" ; 
+  }
+  TFolder * phosFolder ; 
+  phosFolder = dynamic_cast<TFolder*>(fHitsFolder->FindObject("PHOS")) ; 
+  if ( !phosFolder ) 
+    phosFolder = fHitsFolder->AddFolder("PHOS", "Hits from PHOS") ; 
+
+  phosFolder = dynamic_cast<TFolder*>(fSDigitsFolder->FindObject("PHOS")) ;
+  if ( !phosFolder ) 
+    phosFolder = fSDigitsFolder->AddFolder("PHOS", "SDigits from PHOS") ; 
+
+  //Make folder for SDigits
+  fSDigitsFileName.ReplaceAll("/","_") ;
+  phosFolder->AddFolder(fSDigitsFileName.Data(),"");
+
+  phosFolder  = dynamic_cast<TFolder*>(fDigitsFolder->FindObject("PHOS")) ;
+  if ( !phosFolder ) 
+    phosFolder = fDigitsFolder->AddFolder("PHOS", "Digits from PHOS") ;  
+
+  phosFolder  = dynamic_cast<TFolder*>(fRecoFolder->FindObject("PHOS")) ; 
+  if ( !phosFolder )
+    phosFolder = fRecoFolder->AddFolder("PHOS", "Reconstructed data from PHOS") ;  
+  
+}
+//____________________________________________________________________________ 
+void AliPHOSGetter::CloseSplitFiles(void)
+{
+  // Close files opened in a split mode
+  TFile * file ;
+  file = static_cast<TFile*>(gROOT->GetFile(fSDigitsFileName.Data() ) ) ;
+  if(file)
+    file->Close() ;
+  file = static_cast<TFile*>(gROOT->GetFile(fDigitsFileName.Data() ) ) ;
+  if(file)
+    file->Close() ;
+  file = static_cast<TFile*>(gROOT->GetFile(fRecPointsFileName.Data() ) ) ;
+  if(file)
+    file->Close() ;
+  file = static_cast<TFile*>(gROOT->GetFile(fTrackSegmentsFileName.Data() ) ) ;
+  if(file)
+    file->Close() ;
+  file = static_cast<TFile*>(gROOT->GetFile(fRecParticlesFileName.Data() ) ) ;
+  if(file)
+    file->Close() ;
+
+}