]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliAODHandler.cxx
- Reset the MC header in FinishEvent
[u/mrichter/AliRoot.git] / STEER / AliAODHandler.cxx
index 16955922af49d823d31f89b0cb757f691e2af426..20d87fbd89c7b7c4769a2fc7c81bf3b16b74f7b7 100644 (file)
@@ -52,16 +52,19 @@ AliAODHandler::AliAODHandler() :
     AliVEventHandler(),
     fIsStandard(kTRUE),
     fFillAOD(kTRUE),
+    fFillAODRun(kTRUE),
     fNeedsHeaderReplication(kFALSE),
     fNeedsTracksBranchReplication(kFALSE),
     fNeedsVerticesBranchReplication(kFALSE),
     fNeedsV0sBranchReplication(kFALSE),
+    fNeedsCascadesBranchReplication(kFALSE),
     fNeedsTrackletsBranchReplication(kFALSE),
     fNeedsPMDClustersBranchReplication(kFALSE),
     fNeedsJetsBranchReplication(kFALSE),
     fNeedsFMDClustersBranchReplication(kFALSE),
     fNeedsCaloClustersBranchReplication(kFALSE),
     fNeedsMCParticlesBranchReplication(kFALSE),
+    fNeedsDimuonsBranchReplication(kFALSE),
     fAODIsReplicated(kFALSE),
     fAODEvent(NULL),
     fMCEventH(NULL),
@@ -79,16 +82,19 @@ AliAODHandler::AliAODHandler(const char* name, const char* title):
     AliVEventHandler(name, title),
     fIsStandard(kTRUE),
     fFillAOD(kTRUE),
+    fFillAODRun(kTRUE),
     fNeedsHeaderReplication(kFALSE),
     fNeedsTracksBranchReplication(kFALSE),
     fNeedsVerticesBranchReplication(kFALSE),
     fNeedsV0sBranchReplication(kFALSE),
+    fNeedsCascadesBranchReplication(kFALSE),
     fNeedsTrackletsBranchReplication(kFALSE),
     fNeedsPMDClustersBranchReplication(kFALSE),
     fNeedsJetsBranchReplication(kFALSE),
     fNeedsFMDClustersBranchReplication(kFALSE),
     fNeedsCaloClustersBranchReplication(kFALSE),
     fNeedsMCParticlesBranchReplication(kFALSE),
+    fNeedsDimuonsBranchReplication(kFALSE),
     fAODIsReplicated(kFALSE),
     fAODEvent(NULL),
     fMCEventH(NULL),
@@ -123,7 +129,9 @@ Bool_t AliAODHandler::Init(Option_t* opt)
   // Initialize IO
   //
   // Create the AODevent object
-  if(!fAODEvent){
+    
+  Bool_t createStdAOD = fIsStandard || fFillAOD;
+  if(!fAODEvent && createStdAOD){
     fAODEvent = new AliAODEvent();
     if (fIsStandard) fAODEvent->CreateStdContent();
   }
@@ -131,19 +139,21 @@ Bool_t AliAODHandler::Init(Option_t* opt)
   // File opening according to execution mode
   TString option(opt);
   option.ToLower();
-  TDirectory *owd = gDirectory;
-  if (option.Contains("proof")) {
-    // proof
-    // Merging via files. Need to access analysis manager via interpreter.
-    gROOT->ProcessLine(Form("AliAnalysisDataContainer *c_common_out = AliAnalysisManager::GetAnalysisManager()->GetCommonOutputContainer();"));
-    gROOT->ProcessLine(Form("AliAnalysisManager::GetAnalysisManager()->OpenProofFile(c_common_out, \"RECREATE\");"));
-    fFileA = gFile;
-  } else {
-    // local and grid
-    fFileA = new TFile(fFileName.Data(), "RECREATE");
-  }
-  CreateTree(1);
-  owd->cd();
+  if (createStdAOD) {
+    TDirectory *owd = gDirectory;
+    if (option.Contains("proof")) {
+      // proof
+      // Merging via files. Need to access analysis manager via interpreter.
+      gROOT->ProcessLine(Form("AliAnalysisDataContainer *c_common_out = AliAnalysisManager::GetAnalysisManager()->GetCommonOutputContainer();"));
+      gROOT->ProcessLine(Form("AliAnalysisManager::GetAnalysisManager()->OpenProofFile(c_common_out, \"RECREATE\");"));
+      fFileA = gFile;
+    } else {
+      // local and grid
+      fFileA = new TFile(fFileName.Data(), "RECREATE");
+    }
+    CreateTree(1);
+    owd->cd();
+  }  
   if (fExtensions) {
      TIter next(fExtensions);
      AliAODExtension *ext;
@@ -180,15 +190,13 @@ void AliAODHandler::StoreMCParticles(){
   // has to passed to the AOD Handler by this task 
   // (doing this in the steering macro would not work on PROOF)
 
+  if (!fAODEvent) return;
   TClonesArray *mcarray = (TClonesArray*)fAODEvent->FindListObject(AliAODMCParticle::StdBranchName()); 
   if(!mcarray)return;
-  mcarray->Delete();
 
   AliAODMCHeader *mcHeader = (AliAODMCHeader*)fAODEvent->FindListObject(AliAODMCHeader::StdBranchName()); 
   if(!mcHeader)return;
 
-  mcHeader->Reset();
-
   // Get the MC Infos.. Handler needs to be set before 
   // while adding the branch
   // This needs to be done, not to depend on the AnalysisManager
@@ -384,25 +392,33 @@ void AliAODHandler::StoreMCParticles(){
 Bool_t AliAODHandler::FinishEvent()
 {
   // Fill data structures
-  if(fFillAOD){
-    fAODEvent->MakeEntriesReferencable();
-    // StoreMCParticles();
-    FillTree();
-    if (fExtensions) {
-      TIter next(fExtensions);
-      AliAODExtension *ext;
-      while ((ext=(AliAODExtension*)next())) ext->FinishEvent();
-    }
-    if (fFilters) {   
-      TIter nextf(fFilters);
-      AliAODExtension *ext;
-      while ((ext=(AliAODExtension*)nextf())) {
-//        ext->SetEvent(fAODEvent);
-        ext->FinishEvent();
-      }  
-    }       
+  if(fFillAOD && fFillAODRun && fAODEvent){
+      fAODEvent->MakeEntriesReferencable();
+      fTreeA->BranchRef();
+      FillTree();
   }
+
+  if (fFillAOD) {      
+      if (fExtensions) {
+         TIter next(fExtensions);
+         AliAODExtension *ext;
+         while ((ext=(AliAODExtension*)next())) ext->FinishEvent();
+      }
+      if (fFilters) {   
+         TIter nextf(fFilters);
+         AliAODExtension *ext;
+         while ((ext=(AliAODExtension*)nextf())) {
+             ext->FinishEvent();
+         }  
+      }       
+  }  
   if (fIsStandard) fAODEvent->ResetStd();
+  TClonesArray *mcarray = (TClonesArray*)fAODEvent->FindListObject(AliAODMCParticle::StdBranchName()); 
+  if(mcarray) mcarray->Delete();
+
+  AliAODMCHeader *mcHeader = (AliAODMCHeader*)fAODEvent->FindListObject(AliAODMCHeader::StdBranchName()); 
+  if(!mcHeader) mcHeader->Reset();
+
   // Reset AOD replication flag
   fAODIsReplicated = kFALSE;
   return kTRUE;
@@ -426,6 +442,7 @@ Bool_t AliAODHandler::TerminateIO()
 {
   // Terminate IO
   if (fFileA) {
+    fFileA->Write();
     fFileA->Close();
     delete fFileA;
     fFileA = 0;
@@ -457,15 +474,16 @@ void AliAODHandler::CreateTree(Int_t flag)
 //______________________________________________________________________________
 void AliAODHandler::FillTree()
 {
     // Fill the AOD Tree
-  fTreeA->Fill();
+    fTreeA->Fill();
 }
 
 //______________________________________________________________________________
 void AliAODHandler::AddAODtoTreeUserInfo()
 {
   // Add aod event to tree user info
-  fTreeA->GetUserInfo()->Add(fAODEvent);
+  if (fTreeA) fTreeA->GetUserInfo()->Add(fAODEvent);
   // Now the tree owns our fAODEvent...
   fAODEvent = 0;
 }
@@ -498,7 +516,6 @@ void AliAODHandler::AddBranch(const char* cname, void* addobj, const char* filen
       
       fTreeA->Bronch(obj->GetName(), cname, fAODEvent->GetList()->GetObjectRef(obj),
                     kBufsize, kSplitlevel - 1);
-      //    fTreeA->Branch(obj->GetName(), cname, addobj);
     }
     owd->cd();
 }
@@ -671,10 +688,8 @@ void AliAODExtension::AddBranch(const char* cname, void* addobj)
     if (!fTreeE->FindBranch(obj->GetName())) {
       // Do the same as if we book via 
       // TTree::Branch(TCollection*)
-      
       fTreeE->Bronch(obj->GetName(), cname, fAODEvent->GetList()->GetObjectRef(obj),
                     kBufsize, kSplitlevel - 1);
-      //    fTreeA->Branch(obj->GetName(), cname, addobj);
     }
     owd->cd();
 }
@@ -715,6 +730,7 @@ Bool_t AliAODExtension::Init(Option_t *option)
   }  
   fTreeE = new TTree("aodTree", "AliAOD tree");
   fTreeE->Branch(fAODEvent->GetList());
+  fTreeE->BranchRef();
   owd->cd();
   return kTRUE;
 }