+ //set address of the SDigits and SDigitizer
+ TBranch * sdigitsBranch = 0;
+ TBranch * sdigitizerBranch = 0;
+ TBranch * branch = 0 ;
+ TObjArray * lob = (TObjArray*)treeS->GetListOfBranches() ;
+ TIter next(lob) ;
+ Bool_t phosfound = kFALSE, sdigitizerfound = kFALSE ;
+
+ while ( (branch = (TBranch*)next()) && (!phosfound || !sdigitizerfound) ) {
+ if ( (strcmp(branch->GetName(), "PHOS")==0) && (strcmp(branch->GetTitle(), GetName())==0) ) {
+ phosfound = kTRUE ;
+ sdigitsBranch = branch ;
+ }
+
+ else if ( (strcmp(branch->GetName(), "AliPHOSSDigitizer")==0) && (strcmp(branch->GetTitle(), GetName())==0) ) {
+ sdigitizerfound = kTRUE ;
+ sdigitizerBranch = branch ;
+ }
+ }
+ if ( !phosfound || !sdigitizerfound ) {
+ cerr << "WARNING: AliPHOSDigitizer::ReadSDigits -> Digits and/or Digitizer branch with name " << GetName()
+ << " not found" << endl ;
+ return kFALSE ;
+ }
+
+
+ if ( (sdigits = (TClonesArray*)folder->FindObject(GetName()) ) ) {
+ sdigitsBranch->SetAddress(&sdigits) ;
+ sdigits->Clear();
+
+ AliPHOSSDigitizer * sdigitizer = gime->SDigitizer() ;
+ sdigitizerBranch->SetAddress(&sdigitizer) ;
+
+ sdigitsBranch->GetEntry(0) ;
+ sdigitizerBranch->GetEntry(0) ;
+
+ fPedestal = sdigitizer->GetPedestalParameter() ;
+ fSlope = sdigitizer->GetCalibrationParameter() ;
+ }
+ }
+
+ // After SDigits have been read from all files, return to the first one
+
+ next.Reset();
+ folder = (TFolder*)next();
+ TFile * file = (TFile*)gROOT->GetFile(folder->GetName());
+ file->cd() ;
+
+ return kTRUE ;
+
+}
+
+//____________________________________________________________________________
+void AliPHOSDigitizer::Reset()
+{
+ // sets current event number to the first simulated event
+
+ if( strcmp(GetName(), "") == 0 )
+ Init() ;
+
+ // Int_t inputs ;
+// for(inputs = 0; inputs < fNinputs ;inputs++)
+// fIevent->AddAt(-1, inputs ) ;
+
+}
+
+//____________________________________________________________________________
+void AliPHOSDigitizer::WriteDigits(Int_t event)
+{
+
+ // Makes TreeD in the output file.
+ // Check if branch already exists:
+ // if yes, exit without writing: ROOT TTree does not support overwriting/updating of
+ // already existing branches.
+ // else creates branch with Digits, named "PHOS", title "...",
+ // and branch "AliPHOSDigitizer", with the same title to keep all the parameters
+ // and names of files, from which digits are made.
+
+ AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
+ TClonesArray * digits = gime->Digits() ;
+
+ if(gAlice->TreeD()==0)
+ gAlice->MakeTree("D") ;
+
+ // create new branches
+ // -- generate file name if necessary
+ char * file =0;
+ if(gSystem->Getenv("CONFIG_SPLIT_FILE")){ //generating file name
+ file = new char[strlen(gAlice->GetBaseFile())+20] ;
+ sprintf(file,"%s/PHOS.Digits.root",gAlice->GetBaseFile()) ;
+ }
+
+ TDirectory *cwd = gDirectory;
+ // -- create Digits branch
+ Int_t bufferSize = 32000 ;
+ TBranch * digitsBranch = gAlice->TreeD()->Branch("PHOS",&digits,bufferSize);
+ digitsBranch->SetTitle(GetName());
+ if (file) {
+ digitsBranch->SetFile(file);
+ TIter next( digitsBranch->GetListOfBranches());
+ TBranch * sbr ;
+ while ((sbr=(TBranch*)next())) {
+ sbr->SetFile(file);
+ }
+ cwd->cd();
+ }
+
+ // -- Create Digitizer branch
+ Int_t splitlevel = 0 ;
+ AliPHOSDigitizer * d = gime->Digitizer(GetName()) ;
+ TBranch * digitizerBranch = gAlice->TreeD()->Branch("AliPHOSDigitizer", "AliPHOSDigitizer", &d,bufferSize,splitlevel);
+ digitizerBranch->SetTitle(GetName());
+ if (file) {
+ digitizerBranch->SetFile(file);
+ TIter next( digitizerBranch->GetListOfBranches());
+ TBranch * sbr;
+ while ((sbr=(TBranch*)next())) {
+ sbr->SetFile(file);
+ }
+ cwd->cd();
+ }
+
+
+ digitsBranch->Fill() ;
+ digitizerBranch->Fill() ;
+
+ gAlice->TreeD()->Write(0,kOverwrite) ;
+
+}