]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliAODHandler.cxx
Obsolete TrackReferences related code removed.
[u/mrichter/AliRoot.git] / STEER / AliAODHandler.cxx
index 46f9c95c5d05740bba7c1bb42d3f28edbfac57a7..4716e6bb242b60639e1167361f8769d8a999c95e 100644 (file)
@@ -32,6 +32,7 @@ ClassImp(AliAODHandler)
 //______________________________________________________________________________
 AliAODHandler::AliAODHandler() :
     AliVEventHandler(),
+    fIsStandard(kTRUE),
     fAODEvent(NULL),
     fTreeA(NULL),
     fFileA(NULL),
@@ -43,6 +44,7 @@ AliAODHandler::AliAODHandler() :
 //______________________________________________________________________________
 AliAODHandler::AliAODHandler(const char* name, const char* title):
     AliVEventHandler(name, title),
+    fIsStandard(kTRUE),
     fAODEvent(NULL),
     fTreeA(NULL),
     fFileA(NULL),
@@ -53,39 +55,49 @@ AliAODHandler::AliAODHandler(const char* name, const char* title):
 //______________________________________________________________________________
 AliAODHandler::~AliAODHandler() 
 {
-// destructor
+  delete fAODEvent;
+  if(fFileA){
+    // is already handled in TerminateIO
+    fFileA->Close();
+    delete fFileA;
+  }
+  delete fTreeA;
+  delete fName;
+ // 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
-    } else {
-       // local and grid
-       fFileA = new TFile(fName, "RECREATE");
-    }
-    //
-    // Create the output tree
-    CreateTree();
-    
-    return kTRUE;
+    if (fIsStandard) fAODEvent->CreateStdContent();
+  }
+  //
+  // File opening according to execution mode
+  
+  if (!(strcmp(opt, "proof"))) {
+    // proof
+    CreateTree(0);
+  } else {
+    // local and grid
+    TDirectory *owd = gDirectory;
+    fFileA = new TFile(fName, "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;
 }
 
@@ -99,16 +111,21 @@ Bool_t AliAODHandler::Terminate()
 Bool_t AliAODHandler::TerminateIO()
 {
     // Terminate IO
-
+    if (fFileA) {
+       fFileA->ls();
+       fFileA->Close();
+       delete fFileA;
+    }
     return kTRUE;
 }
 
 
-void AliAODHandler::CreateTree()
+void AliAODHandler::CreateTree(Int_t flag)
 {
     // Creates the AOD Tree
     fTreeA = new TTree("aodTree", "AliAOD tree");
     fTreeA->Branch(fAODEvent->GetList());
+    if (flag == 0) fTreeA->SetDirectory(0);
 }
 
 void AliAODHandler::FillTree()
@@ -123,3 +140,15 @@ void AliAODHandler::AddAODtoTreeUserInfo()
     // Add aod event to tree user info
     fTreeA->GetUserInfo()->Add(fAODEvent);
 }
+
+void AliAODHandler::AddBranch(const char* cname, TObject* addobj)
+{
+    // Add a new branch to the aod 
+    TDirectory *owd = gDirectory;
+    if (fFileA) {
+       fFileA->cd();
+    }
+    fTreeA->Branch(addobj->GetName(), cname, &addobj);
+    fAODEvent->AddObject(addobj);
+    owd->cd();
+}