]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ANALYSIS/AliAnalysisSelector.cxx
added TOFheader writing in AOD
[u/mrichter/AliRoot.git] / ANALYSIS / AliAnalysisSelector.cxx
index 7568c1c4afc676edf321e31fc7aa6789daa81b6c..cfb07a40d87a3f28f4e7b81e55124fe6529e2157 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <Riostream.h>
 #include <TProcessID.h>
+#include <TROOT.h>
 
 #include "AliAnalysisManager.h"
 #include "AliAnalysisTask.h"
 
 ClassImp(AliAnalysisSelector)
 
+//______________________________________________________________________________
+AliAnalysisSelector::AliAnalysisSelector()
+                    :TSelector(), 
+                     fInitialized(kFALSE), 
+                     fAnalysis(NULL)
+{
+// Dummy ctor.
+   fAnalysis = AliAnalysisManager::GetAnalysisManager();
+   if (fAnalysis) fAnalysis->SetSelector(this);
+}   
+
 //______________________________________________________________________________
 AliAnalysisSelector::AliAnalysisSelector(AliAnalysisManager *mgr)
                     :TSelector(),
@@ -39,6 +51,7 @@ AliAnalysisSelector::AliAnalysisSelector(AliAnalysisManager *mgr)
 {
 // Constructor. Called by AliAnalysisManager which registers itself on the
 // selector running on the master.
+   mgr->SetSelector(this);
 }
 
 //______________________________________________________________________________
@@ -56,18 +69,27 @@ void AliAnalysisSelector::Init(TTree *tree)
 // Is Init called on workers in case of PROOF.
    if (!fAnalysis) {
       Error("Init", "Analysis manager NULL !");
+      Abort("Cannot initialize without analysis manager. Aborting.");
+      SetStatus(-1);
       return;
    }
-   if (fAnalysis->GetDebugLevel()>0) {
+   if (fAnalysis->GetDebugLevel()>1) {
       cout << "->AliAnalysisSelector->Init()" << endl;
    }   
    if (!tree) {
       Error("Init", "Input tree is NULL !");
+      Abort("Cannot initialize without tree. Aborting.");
+      SetStatus(-1);
       return;
    }
-   fAnalysis->Init(tree);
-   fInitialized = kTRUE;
-   if (fAnalysis->GetDebugLevel()>0) {
+   fInitialized = fAnalysis->Init(tree);
+   if (!fInitialized) {
+      Error("Init", "Some error occured during analysis manager initialization. Aborting.");
+      Abort("Error during AliAnalysisManager::Init()");
+      SetStatus(-1);
+      return;
+   }   
+   if (fAnalysis->GetDebugLevel()>1) {
       cout << "<-AliAnalysisSelector->Init()" << endl;
    }   
 }
@@ -77,8 +99,9 @@ void AliAnalysisSelector::Begin(TTree *)
 {
 // Assembly the input list.
    RestoreAnalysisManager();
-   if (fAnalysis && fAnalysis->GetDebugLevel()>0) {
+   if (fAnalysis && fAnalysis->GetDebugLevel()>1) {
       cout << "->AliAnalysisSelector->Begin: Analysis manager restored" << endl;
+      gROOT->SetMustClean(fAnalysis->MustClean());
    }
 }
 
@@ -88,11 +111,12 @@ void AliAnalysisSelector::SlaveBegin(TTree *tree)
 // Called on each worker. We "unpack" analysis manager here and call InitAnalysis.
    RestoreAnalysisManager();
    if (fAnalysis) {
-      if (fAnalysis->GetDebugLevel()>0) {
+      gROOT->SetMustClean(fAnalysis->MustClean());
+      if (fAnalysis->GetDebugLevel()>1) {
          cout << "->AliAnalysisSelector->SlaveBegin() after Restore" << endl;
       }   
       fAnalysis->SlaveBegin(tree);   
-      if (fAnalysis->GetDebugLevel()>0) {
+      if (fAnalysis->GetDebugLevel()>1) {
          cout << "<-AliAnalysisSelector->SlaveBegin()" << endl;
       }   
    }   
@@ -114,14 +138,30 @@ Bool_t AliAnalysisSelector::Notify()
 Bool_t AliAnalysisSelector::Process(Long64_t entry)
 {
 // Event loop.
-   if (fAnalysis->GetDebugLevel() > 0) {
+   static Int_t count = 0;
+   count++;
+   if (fAnalysis->GetDebugLevel() > 1) {
       cout << "->AliAnalysisSelector::Process()" << endl;
    }
-   Int_t nobjCount = TProcessID::GetObjectCount();
-   fAnalysis->GetEntry(entry);
-   fAnalysis->ExecAnalysis();
+   static Bool_t init=kTRUE;
+   static Int_t nobjCount = 0;
+   if(init) {
+     nobjCount = TProcessID::GetObjectCount();
+     init=kFALSE;
+   }
    TProcessID::SetObjectCount(nobjCount);
-   if (fAnalysis->GetDebugLevel() > 0) {
+   Int_t returnCode = fAnalysis->GetEntry(entry);
+   if (returnCode <= 0) {
+      cout << "Error retrieving event:" << entry << " Skipping ..." << endl;
+      fAnalysis->CountEvent(1,0,1,0);
+      // Try to skip file
+      Abort("Bad stream to file. Trying next image.", kAbortFile);
+      return kFALSE;
+   } else {
+      fAnalysis->ExecAnalysis();
+      fAnalysis->CountEvent(1,1,0,0);
+   }   
+   if (fAnalysis->GetDebugLevel() > 1) {
       cout << "<-AliAnalysisSelector::Process()" << endl;
    }   
    return kTRUE;
@@ -138,7 +178,7 @@ void AliAnalysisSelector::RestoreAnalysisManager()
          if (obj->IsA() == AliAnalysisManager::Class()) {
             fAnalysis = (AliAnalysisManager*)obj;
             fAnalysis->SetSelector(this);
-            if (fAnalysis->GetDebugLevel()>0) {
+            if (fAnalysis->GetDebugLevel()>1) {
                cout << "->AliAnalysisSelector->RestoreAnalysisManager: Analysis manager restored" << endl;
             }   
             break;
@@ -157,11 +197,14 @@ void AliAnalysisSelector::SlaveTerminate()
   // The SlaveTerminate() function is called after all entries or objects
   // have been processed. When running with PROOF SlaveTerminate() is called
   // on each slave server.
-   if (fAnalysis->GetDebugLevel() > 0) {
+   gROOT->SetMustClean(kTRUE);
+   if (fStatus == -1) return;  // TSelector won't abort...
+   if (fAnalysis->GetAnalysisType() == AliAnalysisManager::kMixingAnalysis) return;
+   if (fAnalysis->GetDebugLevel() > 1) {
       cout << "->AliAnalysisSelector::SlaveTerminate()" << endl;
    }   
    fAnalysis->PackOutput(fOutput);
-   if (fAnalysis->GetDebugLevel() > 0) {
+   if (fAnalysis->GetDebugLevel() > 1) {
       cout << "<-AliAnalysisSelector::SlaveTerminate()" << endl;
    }   
 }  
@@ -172,16 +215,20 @@ void AliAnalysisSelector::Terminate()
   // The Terminate() function is the last function to be called during
   // a query. It always runs on the client, it can be used to present
   // the results graphically or save the results to file.
+   gROOT->SetMustClean(kTRUE);
+   if (fStatus == -1) return;  // TSelector won't abort...
    if (!fAnalysis) {
       Error("Terminate","AliAnalysisSelector::Terminate: No analysis manager!!!");
       return;
    }   
-   if (fAnalysis->GetDebugLevel() > 0) {
+   // No Terminate() in case of event mixing
+   if (fAnalysis->GetAnalysisType() == AliAnalysisManager::kMixingAnalysis) return;
+   if (fAnalysis->GetDebugLevel() > 1) {
       cout << "->AliAnalysisSelector::Terminate()" << endl;
    }   
    fAnalysis->UnpackOutput(fOutput);
    fAnalysis->Terminate();   
-   if (fAnalysis->GetDebugLevel() > 0) {
+   if (fAnalysis->GetDebugLevel() > 1) {
       cout << "<-AliAnalysisSelector::Terminate()" << endl;
    }   
 }