]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Improved the mechanism to divert SDigits into a separate file.
authorschutz <schutz@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 30 May 2002 15:09:52 +0000 (15:09 +0000)
committerschutz <schutz@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 30 May 2002 15:09:52 +0000 (15:09 +0000)
PHOS/AliPHOSSDigitizer.cxx
PHOS/AliPHOSSDigitizer.h

index 5cd484e927f58955cd3600625acdde887de92706..0fe839c786a99ed2b9226bb600337f57418d0d12 100644 (file)
@@ -13,6 +13,7 @@
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
+
 /* $Id$ */
 
 //_________________________________________________________________________
@@ -83,6 +84,7 @@ ClassImp(AliPHOSSDigitizer)
   fB             = 10000000.;
   fPrimThreshold = 0.01 ;
   fSDigitsInRun  = 0 ; 
+  fSplitFile     = 0 ; 
 }
 
 //____________________________________________________________________________ 
@@ -93,9 +95,17 @@ AliPHOSSDigitizer::AliPHOSSDigitizer(const char * headerFile, const char * sDigi
   fB             = 10000000.;
   fPrimThreshold = 0.01 ;
   fSDigitsInRun  = 0 ;
+  fSplitFile     = 0 ; 
   Init();
 }
 
+//____________________________________________________________________________ 
+AliPHOSSDigitizer::~AliPHOSSDigitizer()
+{
+  if (fSplitFile) 
+    if ( fSplitFile->IsOpen() ) 
+      fSplitFile->Close() ; 
+}
 
 //____________________________________________________________________________ 
 void AliPHOSSDigitizer::Init()
@@ -153,10 +163,12 @@ void AliPHOSSDigitizer::Exec(Option_t *option)
     Bool_t phosfound = kFALSE, sdigitizerfound = kFALSE ; 
     
     while ( (branch = (static_cast<TBranch*>(next()))) && (!phosfound || !sdigitizerfound) ) {
-      if ( (strcmp(branch->GetName(), "PHOS")==0) && (strcmp(branch->GetTitle(), GetName())==0) ) 
+      TString thisName( GetName() ) ; 
+      TString branchName( branch->GetTitle() ) ; 
+      branchName.Append(":") ; 
+      if ( (strcmp(branch->GetName(), "PHOS")==0) && thisName.BeginsWith(branchName) )  
        phosfound = kTRUE ;
-      
-      else if ( (strcmp(branch->GetName(), "AliPHOSSDigitizer")==0) && (strcmp(branch->GetTitle(), GetName())==0) ) 
+      else if ( (strcmp(branch->GetName(), "AliPHOSSDigitizer")==0) &&  thisName.BeginsWith(branchName) )
        sdigitizerfound = kTRUE ; 
     }
     
@@ -181,6 +193,7 @@ void AliPHOSSDigitizer::Exec(Option_t *option)
     
     
     //Now make SDigits from hits, for PHOS it is the same, so just copy    
+
     Int_t Nprim =  (Int_t)  (gAlice->TreeH())->GetEntries(); 
     // Attention Nprim is the number of primaries tracked by Geant and this number could be different to the number of Primaries in TreeK;
     Int_t iprim;
@@ -201,6 +214,7 @@ void AliPHOSSDigitizer::Exec(Option_t *option)
        nSdigits++ ;    
        
       }
+
     } // loop over iprim
     
     sdigits->Sort() ;
@@ -208,6 +222,7 @@ void AliPHOSSDigitizer::Exec(Option_t *option)
     nSdigits = sdigits->GetEntriesFast() ;
     fSDigitsInRun += nSdigits ;  
     sdigits->Expand(nSdigits) ;
+
     Int_t i ;
     for (i = 0 ; i < nSdigits ; i++) { 
       AliPHOSDigit * digit = dynamic_cast<AliPHOSDigit *>(sdigits->At(i)) ; 
@@ -215,8 +230,8 @@ void AliPHOSSDigitizer::Exec(Option_t *option)
     }
 
     if(gAlice->TreeS() == 0)
-       gAlice->MakeTree("S") ;
-        
+      gAlice->MakeTree("S",fSplitFile);
+    
     //First list of sdigits
     Int_t bufferSize = 32000 ;    
     TBranch * sdigitsBranch = gAlice->TreeS()->Branch("PHOS",&sdigits,bufferSize);
@@ -228,15 +243,21 @@ void AliPHOSSDigitizer::Exec(Option_t *option)
     TBranch * sdigitizerBranch = gAlice->TreeS()->Branch("AliPHOSSDigitizer","AliPHOSSDigitizer",
                                               &sd,bufferSize,splitlevel); 
     sdigitizerBranch->SetTitle(sdname);
+  
     sdigitsBranch->Fill() ; 
-
+    sdigitizerBranch->Fill() ;
     gAlice->TreeS()->AutoSave() ;
     
     if(strstr(option,"deb"))
       PrintSDigits(option) ;
-    
+  
   }
+
+  if (fSplitFile) 
+    if ( fSplitFile->IsOpen() ) 
+      fSplitFile->Close() ; 
   
+
   if(strstr(option,"tim")){
     gBenchmark->Stop("PHOSSDigitizer");
     cout << "AliPHOSSDigitizer:" << endl ;
@@ -277,38 +298,50 @@ void AliPHOSSDigitizer::SetSDigitsBranch(const char * title )
 }
 
 //__________________________________________________________________
-void AliPHOSSDigitizer::SetSplitFile(const TString splitFileName) const
+void AliPHOSSDigitizer::SetSplitFile(const TString splitFileName) 
 {
   // Diverts the SDigits in a file separate from the hits file
   
   TDirectory * cwd = gDirectory ;
-  TFile * splitFile = gAlice->InitTreeFile("S",splitFileName.Data());
-  splitFile->cd() ; 
-  gAlice->Write();
+  
+  if ( !(gAlice->GetTreeSFileName() == splitFileName) ) {
+    if (gAlice->GetTreeSFile() ) 
+      gAlice->GetTreeSFile()->Close() ; 
+  }
+  
+  fSplitFile = gAlice->InitTreeFile("S",splitFileName.Data());
+  fSplitFile->cd() ; 
+  if ( !fSplitFile->Get("gAlice") ) 
+    gAlice->Write();
   
   TTree *treeE  = gAlice->TreeE();
   if (!treeE) {
-    cerr<<"No TreeE found "<<endl;
+    cerr << "ERROR: AliPHOSSDigitizer::SetSPlitFile -> No TreeE found "<<endl;
     abort() ;
   }      
   
   // copy TreeE
-  AliHeader *header = new AliHeader();
-  treeE->SetBranchAddress("Header", &header);
-  treeE->SetBranchStatus("*",1);
-  TTree *treeENew =  treeE->CloneTree();
-  treeENew->Write();
-  
+  if ( !fSplitFile->Get("TreeE") ) {
+    AliHeader *header = new AliHeader();
+    treeE->SetBranchAddress("Header", &header);
+    treeE->SetBranchStatus("*",1);
+    TTree *treeENew =  treeE->CloneTree();
+    treeENew->Write();
+  }
+
   // copy AliceGeom
-  TGeometry *AliceGeom = static_cast<TGeometry*>(cwd->Get("AliceGeom"));
-  if (!AliceGeom) {
-    cerr<<"AliceGeom was not found in the input file "<<endl;
-    abort() ;
+  if ( !fSplitFile->Get("AliceGeom") ) {
+    TGeometry *AliceGeom = static_cast<TGeometry*>(cwd->Get("AliceGeom"));
+    if (!AliceGeom) {
+      cerr << "ERROR: AliPHOSSDigitizer::SetSPlitFile -> AliceGeom was not found in the input file "<<endl;
+      abort() ;
+    }
+    AliceGeom->Write();
   }
-  AliceGeom->Write();
+
   cwd->cd() ; 
-  gAlice->MakeTree("S",splitFile);
-  cout << "INFO: AliPHOSSDigitizer::SetSPlitMode -> SDigits will be stored in " << splitFileName.Data() << endl ; 
+  gAlice->MakeTree("S",fSplitFile);
+  cout << "INFO: AliPHOSSDigitizer::SetSPlitFile -> SDigits will be stored in " << splitFileName.Data() << endl ; 
 }
 
 //__________________________________________________________________
index 5dd854ff63972f00bf3fce8194faa6a3949d1fa2..2742004b8b77b3e356f159a012d07d9e81be89ad 100644 (file)
@@ -16,6 +16,8 @@
 // --- ROOT system ---
 #include "TTask.h"
 #include "TString.h"
+class TFile ; 
+
 // --- Standard library ---
 
 // --- AliRoot header files ---
@@ -25,7 +27,7 @@ class AliPHOSSDigitizer: public TTask {
 public:
   AliPHOSSDigitizer() ;          // ctor
   AliPHOSSDigitizer(const char* HeaderFile,const char *SdigitsTitle = "Default") ; 
-  virtual ~AliPHOSSDigitizer(){} // dtor
+  virtual ~AliPHOSSDigitizer() ; // dtor
 
   Float_t  Calibrate(Int_t amp)const {return (amp - fA)/fB ; }
   Int_t    Digitize(Float_t Energy)const { return (Int_t ) ( fA + Energy*fB); }
@@ -34,7 +36,7 @@ public:
   const Int_t    GetSDigitsInRun() const {return fSDigitsInRun ;}  
   virtual void Print(Option_t* option) const ;
   void SetSDigitsBranch(const char * title ) ;
-  void SetSplitFile(const TString splitFileName = "PHOS.SDigits.root") const ;
+  void SetSplitFile(const TString splitFileName = "PHOS.SDigits.root") ;
   void UseHitsFrom(const char * filename) ;      
   Bool_t operator == (const AliPHOSSDigitizer & sd) const ;
 
@@ -48,6 +50,7 @@ private:
   Float_t fB ;              // Slope Digitizition parameters
   Float_t fPrimThreshold ;  // To store primari if Elos > threshold
   Int_t fSDigitsInRun ;     //! Total number of sdigits in one run
+  TFile * fSplitFile ;      //! file in which SDigits will eventually be stored
 
   ClassDef(AliPHOSSDigitizer,1)  // description