]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ANALYSIS/AliAnalysisTask.cxx
This method has to be called INSIDE the user redefined CreateOutputObjects
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisTask.cxx
index b35021ceeb7b56b441bcbd00d52c9d99986a0855..e901b9ddb7035ca3316dcd1269f96c626c665ffa 100644 (file)
 //    }
 // }
 // 
 //    }
 // }
 // 
-// The method CreateOutputObjects() has to be overloaded an will contain the
+// The method LocalInit() may be implemented to call locally (on the client)
+// all initialization methods of the class. It is not mandatory and was created
+// in order to minimize the complexity and readability of the analysis macro.
+// DO NOT create in this method the histigrams or task output objects that will
+// go in the task output containers. Use CreateOutputObjects for that.
+//
+// The method CreateOutputObjects() has to be implemented an will contain the
 // objects that should be created only once per session (e.g. output
 // histograms)
 //
 // objects that should be created only once per session (e.g. output
 // histograms)
 //
 //==============================================================================
 
 #include <Riostream.h>
 //==============================================================================
 
 #include <Riostream.h>
-#include <TDirectory.h>
+#include <TFile.h>
 #include <TClass.h>
 
 #include "AliAnalysisTask.h"
 #include "AliAnalysisDataSlot.h"
 #include "AliAnalysisDataContainer.h"
 #include <TClass.h>
 
 #include "AliAnalysisTask.h"
 #include "AliAnalysisDataSlot.h"
 #include "AliAnalysisDataContainer.h"
+#include "AliAnalysisManager.h"
 
 ClassImp(AliAnalysisTask)
 
 
 ClassImp(AliAnalysisTask)
 
@@ -113,6 +120,7 @@ AliAnalysisTask::AliAnalysisTask()
                  fOutputs(NULL)
 {
 // Default constructor.
                  fOutputs(NULL)
 {
 // Default constructor.
+   TObject::SetBit(kTaskEvtByEvt, kTRUE);
 }
 
 //______________________________________________________________________________
 }
 
 //______________________________________________________________________________
@@ -128,6 +136,7 @@ AliAnalysisTask::AliAnalysisTask(const char *name, const char *title)
                  fOutputs(NULL)                 
 {
 // Constructor.
                  fOutputs(NULL)                 
 {
 // Constructor.
+   TObject::SetBit(kTaskEvtByEvt, kTRUE);
    fInputs      = new TObjArray(2);
    fOutputs     = new TObjArray(2);
 }
    fInputs      = new TObjArray(2);
    fOutputs     = new TObjArray(2);
 }
@@ -377,6 +386,16 @@ void AliAnalysisTask::ConnectInputData(Option_t *)
 // Overload and connect your branches here.
 }
 
 // Overload and connect your branches here.
 }
 
+//______________________________________________________________________________
+void AliAnalysisTask::LocalInit()
+{
+// The method LocalInit() may be implemented to call locally (on the client)
+// all initialization methods of the class. It is not mandatory and was created
+// in order to minimize the complexity and readability of the analysis macro.
+// DO NOT create in this method the histigrams or task output objects that will
+// go in the task output containers. Use CreateOutputObjects for that.
+}
+
 //______________________________________________________________________________
 void AliAnalysisTask::CreateOutputObjects()
 {
 //______________________________________________________________________________
 void AliAnalysisTask::CreateOutputObjects()
 {
@@ -384,6 +403,36 @@ void AliAnalysisTask::CreateOutputObjects()
 // task initialization and/or create your output objects here.
 }
 
 // task initialization and/or create your output objects here.
 }
 
+//______________________________________________________________________________
+void AliAnalysisTask::OpenFile(Int_t iout, Option_t *option) const
+{
+// This method has to be called INSIDE the user redefined CreateOutputObjects
+// method, before creating each object corresponding to the output containers
+// that are to be written to a file. This need to be done in general for the big output
+// objects that may not fit memory during processing. 
+// - 'option' is the file opening option.
+//=========================================================================
+// NOTE !: The method call will be ignored in PROOF mode, in which case the 
+// results have to be streamed back to the client and written just before Terminate()
+//=========================================================================
+//
+// Example:
+// void MyAnaTask::CreateOutputObjects() {
+//    OpenFile(0);   // Will open the file for the object to be written at output #0
+//    fAOD = new TTree("AOD for D0toKPi");
+//    OpenFile(1);
+// now some histos that should go in the file of the second output container
+//    fHist1 = new TH1F("my quality check hist1",...);
+//    fHist2 = new TH2F("my quality check hist2",...);
+// }
+   
+   if (iout<0 || iout>=fNoutputs) return;
+   AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
+   if (!mgr || mgr->GetAnalysisType()==AliAnalysisManager::kProofAnalysis) return;
+   AliAnalysisDataContainer *cont = GetOutputSlot(iout)->GetContainer();
+   if (strlen(cont->GetFileName())) new TFile(cont->GetFileName(), option);
+}
+
 //______________________________________________________________________________
 Bool_t AliAnalysisTask::Notify()
 {
 //______________________________________________________________________________
 Bool_t AliAnalysisTask::Notify()
 {