]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONDigitizerV3.cxx
Minimizing the number of delete for TClonesArray, as per OCT request
[u/mrichter/AliRoot.git] / MUON / AliMUONDigitizerV3.cxx
index f61e3294493869bb60a0ad2e27162361be10cf95..f2c93b63a1a0020fab64fdb3df15ff0fa77e4b86 100644 (file)
@@ -104,7 +104,8 @@ fGenerateNoisyDigits(generateNoisyDigits),
 fLogger(new AliMUONLogger(1000)),
 fTriggerStore(new AliMUONTriggerStoreV1),
 fDigitStore(0x0),
-fOutputDigitStore(0x0)
+fOutputDigitStore(0x0),
+fInputDigitStore(0x0)
 {
   /// Ctor.
 
@@ -125,7 +126,8 @@ AliMUONDigitizerV3::~AliMUONDigitizerV3()
   delete fTriggerStore;
   delete fDigitStore;
   delete fOutputDigitStore;
-   
+  delete fInputDigitStore;
+  
   AliInfo("Summary of messages");
   fLogger->Print();
   
@@ -327,6 +329,43 @@ AliMUONDigitizerV3::DecalibrateTrackerDigit(const AliMUONVCalibParam& pedestals,
   return adc;
 }
 
+//_____________________________________________________________________________
+void
+AliMUONDigitizerV3::CreateInputDigitStore()
+{
+  /// Create an input digit store, and check that all input files
+  /// actually contains the same type of AliMUONVDigitStore
+  
+  fInputDigitStore = 0x0;
+  
+  for ( Int_t iFile = 0; iFile < fManager->GetNinputs(); ++iFile )
+  {    
+    AliLoader* inputLoader = GetLoader(fManager->GetInputFolderName(iFile));
+    
+    inputLoader->LoadSDigits("READ");
+    
+    TTree* iTreeS = inputLoader->TreeS();
+    if (!iTreeS)
+    {
+      AliFatal(Form("Could not get access to input file #%d",iFile));
+    }
+    
+    AliMUONVDigitStore* inputStore = AliMUONVDigitStore::Create(*iTreeS);
+    
+    if (!fInputDigitStore)
+    {
+      fInputDigitStore = inputStore;
+    }
+    else
+    {
+      if ( inputStore->IsA() != fInputDigitStore->IsA() )
+      {
+        AliFatal("Got different types of AliMUONVDigitStore here. Please implement me.");
+      }
+    }
+  }
+}
+
 //_____________________________________________________________________________
 void
 AliMUONDigitizerV3::Exec(Option_t*)
@@ -380,17 +419,20 @@ AliMUONDigitizerV3::Exec(Option_t*)
     {
       AliFatal(Form("Could not get access to input file #%d",iFile));
     }
-    
-    AliMUONVDigitStore* inputStore = AliMUONVDigitStore::Create(*iTreeS);
-    inputStore->Connect(*iTreeS);
+
+    if (!fInputDigitStore)
+    {
+      CreateInputDigitStore();
+    }
+    fInputDigitStore->Connect(*iTreeS);
     
     iTreeS->GetEvent(0);
     
-    MergeWithSDigits(fDigitStore,*inputStore,fManager->GetMask(iFile));
+    MergeWithSDigits(fDigitStore,*fInputDigitStore,fManager->GetMask(iFile));
 
     inputLoader->UnloadSDigits();
     
-    delete inputStore;
+    fInputDigitStore->Clear();
   }
   
   // At this point, we do have digit arrays (one per chamber) which contains