]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ANALYSIS/AliAnalysisTask.cxx
AliEveTrackCounter, AliEveTrackCounterEditor
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTask.cxx
index 2ea368db23ade12bed603478af38bd1048e711d2..c4a123a709c3c561cce5e1ccb251af6947f04122 100644 (file)
 #include <TFile.h>
 #include <TClass.h>
 #include <TTree.h>
+#include <TROOT.h>
 
 #include "AliAnalysisTask.h"
 #include "AliAnalysisDataSlot.h"
@@ -401,6 +402,16 @@ void AliAnalysisTask::EnableBranch(Int_t islot, const char *bname) const
    }
    AliAnalysisDataSlot::EnableBranch(bname, tree);
 }
+
+//______________________________________________________________________________
+void AliAnalysisTask::FinishTaskOutput()
+{
+// Optional method that is called in SlaveTerminate phase. 
+// Used for calling aditional methods just after the last event was processed ON
+// THE WORKING NODE. The call is made also in local case.
+// Do NOT delete output objects here since they will have to be sent for 
+// merging in PROOF mode - use class destructor for cleanup.
+}
       
 //______________________________________________________________________________
 void AliAnalysisTask::ConnectInputData(Option_t *)
@@ -453,12 +464,25 @@ TFile *AliAnalysisTask::OpenFile(Int_t iout, Option_t *option) const
       return NULL;
    }   
    // We allow file opening also on the slaves (AG)
-//   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
-//   if (!mgr || mgr->GetAnalysisType()==AliAnalysisManager::kProofAnalysis) return;
+   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
    AliAnalysisDataContainer *cont = GetOutputSlot(iout)->GetContainer();
    TFile *f = NULL;
-   if (strlen(cont->GetFileName())) f = new TFile(cont->GetFileName(), option);
-   if (f && !f->IsZombie()) return f;
+   if (!strlen(cont->GetFileName())) {
+      Error("OpenFile", "No file name specified for container %s", cont->GetName());
+      return f;
+   }   
+   if (mgr->GetAnalysisType()==AliAnalysisManager::kProofAnalysis && cont->IsSpecialOutput())
+      f = mgr->OpenProofFile(cont->GetFileName(),option);
+   else {
+      // Check first if the file is already opened
+      f = (TFile*)gROOT->GetListOfFiles()->FindObject(cont->GetFileName());
+      if (!f) f = new TFile(cont->GetFileName(), option);
+   }   
+   if (f && !f->IsZombie()) {
+      cont->SetFile(f);
+      return f;
+   }
+   cont->SetFile(NULL);
    return NULL;
 }
 
@@ -469,6 +493,13 @@ Bool_t AliAnalysisTask::Notify()
    return kTRUE;
 }
 
+//______________________________________________________________________________
+Bool_t AliAnalysisTask::NotifyBinChange()
+{
+// Overload this IF you need to treat bin change in event mixing.
+   return kTRUE;
+}
+
 //______________________________________________________________________________
 void AliAnalysisTask::Terminate(Option_t *)
 {