]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliAODHandler.cxx
- Set of changes needed for merging aod files in CAF. Some fixes also for event mixing.
[u/mrichter/AliRoot.git] / STEER / AliAODHandler.cxx
index d37a2f3d3ce4af851bfdc242701089a3db929386..04f152250bd49a994ae8ea7e1c0f6f9064d4258b 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <TTree.h>
 #include <TFile.h>
+#include <TString.h>
 
 #include "AliAODHandler.h"
 #include "AliAODEvent.h"
@@ -32,10 +33,11 @@ ClassImp(AliAODHandler)
 //______________________________________________________________________________
 AliAODHandler::AliAODHandler() :
     AliVEventHandler(),
+    fIsStandard(kTRUE),
     fAODEvent(NULL),
     fTreeA(NULL),
     fFileA(NULL),
-    fName("")
+    fFileName("")
 {
   // default constructor
 }
@@ -43,50 +45,71 @@ AliAODHandler::AliAODHandler() :
 //______________________________________________________________________________
 AliAODHandler::AliAODHandler(const char* name, const char* title):
     AliVEventHandler(name, title),
+    fIsStandard(kTRUE),
     fAODEvent(NULL),
     fTreeA(NULL),
     fFileA(NULL),
-    fName("")
+    fFileName("")
 {
 }
 
 //______________________________________________________________________________
 AliAODHandler::~AliAODHandler() 
 {
-// destructor
+  delete fAODEvent;
+  if(fFileA){
+    // is already handled in TerminateIO
+    fFileA->Close();
+    delete fFileA;
+  }
+  delete fTreeA;
+ // destructor
 }
 
-
-Bool_t AliAODHandler::InitIO(Option_t* opt)
+//______________________________________________________________________________
+Bool_t AliAODHandler::Init(Option_t* opt)
 {
-    // Initialize IO
-    //
-    // Create the AODevent object
+  // Initialize IO
+  //
+  // Create the AODevent object
+  if(!fAODEvent){
     fAODEvent = new AliAODEvent();
-    fAODEvent->CreateStdContent();
-    //
-    // File opening according to execution mode
-
-    if (!(strcmp(opt, "proof"))) {
-       // proof
-       CreateTree(0);
-    } else {
-       // local and grid
-       fFileA = new TFile(fName, "RECREATE");
-       CreateTree(1);
-    }
-    return kTRUE;
+    if (fIsStandard) fAODEvent->CreateStdContent();
+  }
+  //
+  // File opening according to execution mode
+  TString option(opt);
+  option.ToLower();
+  if (option.Contains("proof")) {
+    // proof
+    if (option.Contains("special")) {
+       // File for tree already opened on slave -> merging via files
+       fFileA = gFile;
+       CreateTree(1);
+    } else {   
+       // Merging in memory
+       CreateTree(0);
+    }   
+  } else {
+    // local and grid
+    TDirectory *owd = gDirectory;
+    fFileA = new TFile(fFileName.Data(), "RECREATE");
+    CreateTree(1);
+    owd->cd();
+  }
+  return kTRUE;
 }
 
 Bool_t AliAODHandler::FinishEvent()
 {
     // Fill data structures
+    fAODEvent->MakeEntriesReferencable();
     FillTree();
-    fAODEvent->ClearStd();
-    
+    if (fIsStandard) fAODEvent->ResetStd();
     return kTRUE;
 }
 
+//______________________________________________________________________________
 Bool_t AliAODHandler::Terminate()
 {
     // Terminate 
@@ -94,6 +117,7 @@ Bool_t AliAODHandler::Terminate()
     return kTRUE;
 }
 
+//______________________________________________________________________________
 Bool_t AliAODHandler::TerminateIO()
 {
     // Terminate IO
@@ -104,7 +128,7 @@ Bool_t AliAODHandler::TerminateIO()
     return kTRUE;
 }
 
-
+//______________________________________________________________________________
 void AliAODHandler::CreateTree(Int_t flag)
 {
     // Creates the AOD Tree
@@ -113,15 +137,45 @@ void AliAODHandler::CreateTree(Int_t flag)
     if (flag == 0) fTreeA->SetDirectory(0);
 }
 
+//______________________________________________________________________________
 void AliAODHandler::FillTree()
 {
     // Fill the AOD Tree
     fTreeA->Fill();
 }
 
-
+//______________________________________________________________________________
 void AliAODHandler::AddAODtoTreeUserInfo()
 {
     // Add aod event to tree user info
     fTreeA->GetUserInfo()->Add(fAODEvent);
 }
+
+//______________________________________________________________________________
+void AliAODHandler::AddBranch(const char* cname, void* addobj)
+{
+    // Add a new branch to the aod 
+    TDirectory *owd = gDirectory;
+    if (fFileA) {
+       fFileA->cd();
+    }
+    char** apointer = (char**) addobj;
+    TObject* obj = (TObject*) *apointer;
+    fTreeA->Branch(obj->GetName(), cname, addobj);
+    fAODEvent->AddObject(obj);
+    owd->cd();
+}
+
+//______________________________________________________________________________
+void AliAODHandler::SetOutputFileName(const char* fname)
+{
+// Set file name.
+   fFileName = fname;
+}
+
+//______________________________________________________________________________
+const char *AliAODHandler::GetOutputFileName()
+{
+// Get file name.
+   return fFileName.Data();
+}