new method mgr->AddStatisticsTask() that adds a special framework task to any train...
authoragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 20 Dec 2010 14:53:22 +0000 (14:53 +0000)
committeragheata <agheata@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 20 Dec 2010 14:53:22 +0000 (14:53 +0000)
ANALYSIS/ANALYSISaliceLinkDef.h
ANALYSIS/AliAnalysisManager.cxx
ANALYSIS/AliAnalysisManager.h
ANALYSIS/AliAnalysisSelector.cxx
ANALYSIS/AliAnalysisStatistics.h
ANALYSIS/AliAnalysisTaskStat.cxx [new file with mode: 0644]
ANALYSIS/AliAnalysisTaskStat.h [new file with mode: 0644]
ANALYSIS/CMakelibANALYSISalice.pkg
ANALYSIS/libANALYSISalice.pkg

index 7e93e83..e179bb7 100644 (file)
@@ -35,6 +35,7 @@
 #pragma link C++ class AliCollisionNormalizationTask+;
 #pragma link C++ class AliAnalysisTaskAODCentralityMaker+;
 #pragma link C++ class AliCentralitySelectionTask+;
+#pragma link C++ class AliAnalysisTaskStat+;
 
 #ifdef WITHXML
 #pragma link C++ class AliTagAnalysis+;
index 4456be9..7088ace 100644 (file)
 //
 //==============================================================================
 
-#include <Riostream.h>
+#include "AliAnalysisManager.h"
 
+#include <Riostream.h>
 #include <TError.h>
 #include <TClass.h>
 #include <TFile.h>
-//#include <TKey.h>
 #include <TMath.h>
 #include <TH1.h>
 #include <TMethodCall.h>
@@ -48,7 +48,8 @@
 #include "AliVEventHandler.h"
 #include "AliVEventPool.h"
 #include "AliSysInfo.h"
-#include "AliAnalysisManager.h"
+#include "AliAnalysisStatistics.h"
+#include "AliAnalysisTaskStat.h"
 
 ClassImp(AliAnalysisManager)
 
@@ -87,7 +88,8 @@ AliAnalysisManager::AliAnalysisManager(const char *name, const char *title)
                     fRunFromPath(0),
                     fNcalls(0),
                     fStatisticsMsg(),
-                    fRequestedBranches()
+                    fRequestedBranches(),
+                    fStatistics(0)
 {
 // Default constructor.
    fgAnalysisManager = this;
@@ -135,7 +137,8 @@ AliAnalysisManager::AliAnalysisManager(const AliAnalysisManager& other)
                     fRunFromPath(0),
                     fNcalls(other.fNcalls),
                     fStatisticsMsg(other.fStatisticsMsg),
-                    fRequestedBranches(other.fRequestedBranches)
+                    fRequestedBranches(other.fRequestedBranches),
+                    fStatistics(other.fStatistics)
 {
 // Copy constructor.
    fTasks      = new TObjArray(*other.fTasks);
@@ -187,6 +190,7 @@ AliAnalysisManager& AliAnalysisManager::operator=(const AliAnalysisManager& othe
       fNcalls     = other. fNcalls;
       fStatisticsMsg = other.fStatisticsMsg;
       fRequestedBranches = other.fRequestedBranches;
+      fStatistics = other.fStatistics;
    }
    return *this;
 }
@@ -217,8 +221,8 @@ Int_t AliAnalysisManager::GetEntry(Long64_t entry, Int_t getall)
 // Read one entry of the tree or a whole branch.
    fCurrentEntry = entry;
    if (!fAutoBranchHandling)
-     return entry;
-   return fTree ? fTree->GetTree()->GetEntry(entry, getall) : 0;
+     return 123456789;
+   return fTree ? fTree->GetTree()->GetEntry(entry, getall) : -1;
 }
 
 //______________________________________________________________________________
@@ -2248,10 +2252,36 @@ void AliAnalysisManager::DoLoadBranch(const char *name)
     fTable.Add(br);
   }
   if (br->GetReadEntry()==GetCurrentEntry()) return;
-  br->GetEntry(GetCurrentEntry());
+  Int_t ret = br->GetEntry(GetCurrentEntry());
+  if (ret<0) {
+    Error("DoLoadBranch", "Could not load entry %lld from branch %s",GetCurrentEntry(), name);
+  }
 }
 
 //______________________________________________________________________________
+void AliAnalysisManager::AddStatisticsTask()
+{
+// Add the statistics task to the manager.
+  if (fStatistics) {
+     Info("AddStatisticsTask", "Already added");
+     return;
+  }   
+  AliAnalysisTaskStat *taskStatistics = AliAnalysisTaskStat::AddToManager();
+  if (taskStatistics) fStatistics = taskStatistics->GetStatistics();
+}  
+
+//______________________________________________________________________________
+void AliAnalysisManager::CountEvent(Int_t ninput, Int_t nprocessed, Int_t nfailed, Int_t naccepted)
+{
+// Bookkeep current event;
+   if (!fStatistics) return;
+   fStatistics->AddInput(ninput);
+   fStatistics->AddProcessed(nprocessed);
+   fStatistics->AddFailed(nfailed);
+   fStatistics->AddAccepted(naccepted);
+}   
+
+//______________________________________________________________________________
 void AliAnalysisManager::AddStatisticsMsg(const char *line)
 {
 // Add a line in the statistics message. If available, the statistics message is written
index 652251c..bd968d9 100644 (file)
@@ -30,6 +30,7 @@ class AliAnalysisTask;
 class AliVEventHandler;
 class AliVEventPool;
 class AliAnalysisGrid;
+class AliAnalysisStatistics;
 
 
 class AliAnalysisManager : public TNamed {
@@ -158,7 +159,9 @@ enum EAliAnalysisFlags {
    
    // Analysis initialization and execution, status
    void                 AddBranches(const char *branches);
+   void                 AddStatisticsTask();
    void                 CheckBranches(Bool_t load=kFALSE);
+   void                 CountEvent(Int_t ninput, Int_t nprocessed, Int_t nfailed, Int_t naccepted);
    Bool_t               InitAnalysis();
    Bool_t               IsInitialized() const {return fInitOK;}
    Bool_t               IsExternalLoop() const {return TObject::TestBit(kExternalLoop);}
@@ -172,6 +175,7 @@ enum EAliAnalysisFlags {
    static void          ProgressBar(const char *opname, Long64_t current, Long64_t size, TStopwatch * const watch=0, Bool_t last=kFALSE, Bool_t refresh=kFALSE);
    void                 AddStatisticsMsg(const char *line);
    const char          *GetStatisticsMsg() const {return fStatisticsMsg.Data();}
+   const AliAnalysisStatistics *GetStatistics() const {return fStatistics;}
    void                 WriteStatisticsMsg(Int_t nevents);
    Int_t                GetNcalls() const {return fNcalls;}
    Bool_t               ValidateOutputFiles() const;
@@ -212,8 +216,9 @@ private:
    Int_t                   fNcalls;              // Total number of calls (events) of ExecAnalysis
    TString                 fStatisticsMsg;       // Statistics user message
    TString                 fRequestedBranches;   // Requested branch names
+   AliAnalysisStatistics  *fStatistics;          // Statistics info about input events
    static TString          fgCommonFileName;     //! Common output file name (not streamed)
    static AliAnalysisManager *fgAnalysisManager; //! static pointer to object instance
-   ClassDef(AliAnalysisManager,11)  // Analysis manager class
+   ClassDef(AliAnalysisManager,12)  // Analysis manager class
 };   
 #endif
index 8bc69c5..d9e6deb 100644 (file)
@@ -141,10 +141,13 @@ Bool_t AliAnalysisSelector::Process(Long64_t entry)
    }
    Int_t nobjCount = TProcessID::GetObjectCount();
    Int_t returnCode = fAnalysis->GetEntry(entry);
-   if (returnCode <= 0)
-      cout << "Error retrieving event. Skipping this event." << endl;
-   else
-     fAnalysis->ExecAnalysis();
+   if (returnCode <= 0) {
+      cout << "Error retrieving event:" << entry << " Skipping ..." << endl;
+      fAnalysis->CountEvent(1,0,1,0);
+   } else {
+      fAnalysis->ExecAnalysis();
+      fAnalysis->CountEvent(1,1,0,0);
+   }   
    TProcessID::SetObjectCount(nobjCount);
    if (fAnalysis->GetDebugLevel() > 1) {
       cout << "<-AliAnalysisSelector::Process()" << endl;
index 6148dec..8531977 100644 (file)
@@ -44,7 +44,7 @@ public:
   Long64_t                    GetNaccepted()  const         {return fNaccepted;}
 
   virtual Long64_t            Merge(TCollection* list);
-  virtual void                Print(const Option_t *option) const;
+  virtual void                Print(const Option_t *option="") const;
 
   ClassDef(AliAnalysisStatistics,1)  // Class holding the processed events statistics
 };
diff --git a/ANALYSIS/AliAnalysisTaskStat.cxx b/ANALYSIS/AliAnalysisTaskStat.cxx
new file mode 100644 (file)
index 0000000..720cf0e
--- /dev/null
@@ -0,0 +1,123 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/* $Id$ */
+// Author: Andrei Gheata, 20/12/2010
+
+//==============================================================================
+// AliAnalysisTaskStat - basic task that attaches a AliAnalysisTaskstatistics 
+// object to the analysis manager. Use: AliAnalysisManager::AddStatisticsTask
+// to attach to a train.
+//==============================================================================
+
+#include "AliAnalysisTaskStat.h"
+
+#include <TList.h>
+#include "AliVEvent.h"
+#include "AliAnalysisManager.h"
+#include "AliAnalysisDataContainer.h"
+#include "AliAnalysisStatistics.h"
+
+ClassImp(AliAnalysisTaskStat)
+
+//______________________________________________________________________________
+AliAnalysisTaskStat::AliAnalysisTaskStat(const char *name)
+                    :AliAnalysisTaskSE(name),
+                     fStatistics(0),
+                     fOutputList(0)
+{
+// Named constructor.
+  DefineOutput(1, TList::Class());
+  fBranchNames = "ESD:AliESDHeader. AOD:header";
+  fStatistics = new AliAnalysisStatistics("MgrStat");
+}
+
+//______________________________________________________________________________
+AliAnalysisTaskStat::~AliAnalysisTaskStat()
+{
+// Destructor.
+  if (fOutputList) {
+    if (!AliAnalysisManager::GetAnalysisManager()->IsProofMode()) delete fOutputList;
+  } else {
+    if (fStatistics) delete fStatistics;
+  }
+} 
+    
+//______________________________________________________________________________
+AliAnalysisTaskStat *AliAnalysisTaskStat::AddToManager()
+{
+// Add this task to the analysis manager. By default it selects MB events.
+  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
+  if (!mgr) {
+    ::Error("AliAnalysisTaskStat::AddToManager", "You need a manager first");
+    return 0;
+  }
+  AliAnalysisDataContainer *cinput = mgr->GetCommonInputContainer();
+  if (!cinput) {
+    ::Error("AliAnalysisTaskStat::AddToManager", "Attach first the input handler");
+    return 0;
+  }  
+  AliAnalysisDataContainer *coutput = mgr->CreateContainer("MgrStat", TList::Class(), AliAnalysisManager::kOutputContainer,
+                mgr->GetCommonFileName());
+  AliAnalysisTaskStat *taskStatistics = new AliAnalysisTaskStat("MgrStat");
+  mgr->AddTask(taskStatistics);
+  taskStatistics->SelectCollisionCandidates(AliVEvent::kMB);
+  mgr->ConnectInput(taskStatistics, 0, cinput);
+  mgr->ConnectOutput(taskStatistics, 1, coutput);
+  return taskStatistics;
+}
+
+//______________________________________________________________________________
+void  AliAnalysisTaskStat::UserCreateOutputObjects()
+{
+// Create the output list.
+  if (!fStatistics) {
+    Fatal("UserCreateOutputObjects", "You are not allowed to create this task using the dummy constructor. Use the named one.");
+  }
+  fOutputList = new TList();
+  fOutputList->SetOwner();
+  if (fStatistics) fOutputList->Add(fStatistics);
+  PostData(1, fOutputList);
+}   
+
+//______________________________________________________________________________
+void  AliAnalysisTaskStat::UserExec(Option_t *)
+{
+// Event loop.
+  fStatistics->AddAccepted();
+}
+
+//______________________________________________________________________________
+void  AliAnalysisTaskStat::Terminate(Option_t *)
+{
+// Get the statistics from its container and copy to manager.
+  fOutputList = dynamic_cast<TList*>(GetOutputData(1));
+  if (!fOutputList) {
+    Error("Terminate", "Cannot get output list from container");
+    return;
+  }
+  AliAnalysisStatistics *stat = dynamic_cast<AliAnalysisStatistics*>(fOutputList->At(0));
+  if (!stat) {
+    Error("Terminate", "Statistics object not found in list");
+    return;
+  }
+  if (fStatistics) {
+    fStatistics->AddInput(stat->GetNinput());
+    fStatistics->AddProcessed(stat->GetNprocessed());
+    fStatistics->AddFailed(stat->GetNfailed());
+    fStatistics->AddAccepted(stat->GetNaccepted());
+    fStatistics->Print();
+  }
+}  
diff --git a/ANALYSIS/AliAnalysisTaskStat.h b/ANALYSIS/AliAnalysisTaskStat.h
new file mode 100644 (file)
index 0000000..9ba1b63
--- /dev/null
@@ -0,0 +1,49 @@
+#ifndef ALIANALYSISTASKSTAT_H
+#define ALIANALYSISTASKSTAT_H
+/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+// Author: Andrei Gheata, 20/12/2010
+
+//==============================================================================
+//   AliAnalysisTaskStat - Analysis task that ataches an AliAnalysisStatistics
+//      to the analysis manager
+//==============================================================================
+
+#ifndef ALIANALYSISTASKSE_H
+#include "AliAnalysisTaskSE.h"
+#endif
+
+class AliAnalysisStatistics;
+
+class AliAnalysisTaskStat : public AliAnalysisTaskSE
+{
+
+protected:
+  AliAnalysisStatistics      *fStatistics; // Statistics object
+  TList                      *fOutputList; // Output list
+
+private:
+  AliAnalysisTaskStat(const AliAnalysisTaskStat& other);
+  AliAnalysisTaskStat& operator= (const AliAnalysisTaskStat& other);
+
+public:
+  AliAnalysisTaskStat() : AliAnalysisTaskSE(), fStatistics(0), fOutputList(0) {}
+  AliAnalysisTaskStat(const char *name);
+  virtual ~AliAnalysisTaskStat();
+
+  // Static method to add to the analysis manager
+  static AliAnalysisTaskStat *AddToManager();
+
+  // Implementation of interface methods
+  virtual void UserCreateOutputObjects();
+  virtual void UserExec(Option_t *option);
+  virtual void Terminate(Option_t *option);
+  
+  // Getters
+  AliAnalysisStatistics *GetStatistics() const {return fStatistics;}
+
+  ClassDef(AliAnalysisTaskStat, 1); // Statistics task
+};
+#endif
index 4c5dad1..a59cfef 100644 (file)
@@ -25,7 +25,7 @@
 # SHLIBS - Shared Libraries and objects for linking (Executables only)           #
 #--------------------------------------------------------------------------------#
 
-set ( SRCS     AliAnalysisTaskSE.cxx AliAnalysisTaskME.cxx AliAnalysisTaskESDfilter.cxx AliAnalysisTaskKineFilter.cxx AliAnalysisTaskMCParticleFilter.cxx AliKineTrackCuts.cxx AliESDtrackCuts.cxx  AliESDpidCuts.cxx AliESDv0Cuts.cxx AliEventPoolOTF.cxx AliEventPoolLoop.cxx AliEventPoolSparse.cxx AliAnalysisTaskTagCreator.cxx AliMultiEventInputHandler.cxx AliTriggerAnalysis.cxx AliPhysicsSelection.cxx AliBackgroundSelection.cxx AliPhysicsSelectionTask.cxx AliAnalysisFilter.cxx AliAnalysisCuts.cxx AliCollisionNormalization.cxx AliCollisionNormalizationTask.cxx AliAnalysisTaskAODCentralityMaker.cxx)
+set ( SRCS     AliAnalysisTaskSE.cxx AliAnalysisTaskME.cxx AliAnalysisTaskESDfilter.cxx AliAnalysisTaskKineFilter.cxx AliAnalysisTaskMCParticleFilter.cxx AliKineTrackCuts.cxx AliESDtrackCuts.cxx  AliESDpidCuts.cxx AliESDv0Cuts.cxx AliEventPoolOTF.cxx AliEventPoolLoop.cxx AliEventPoolSparse.cxx AliAnalysisTaskTagCreator.cxx AliMultiEventInputHandler.cxx AliTriggerAnalysis.cxx AliPhysicsSelection.cxx AliBackgroundSelection.cxx AliPhysicsSelectionTask.cxx AliAnalysisFilter.cxx AliAnalysisCuts.cxx AliCollisionNormalization.cxx AliCollisionNormalizationTask.cxx AliCentralitySelectionTask.cxx AliAnalysisTaskAODCentralityMaker.cxx AliAnalysisTaskStat.cxx)
 
 if( ROOTHASALIEN STREQUAL "yes")
        
index be2dfed..0a11cec 100644 (file)
@@ -5,13 +5,14 @@ SRCS =        AliAnalysisTaskSE.cxx AliAnalysisTaskME.cxx \
        AliKineTrackCuts.cxx AliESDtrackCuts.cxx  AliESDpidCuts.cxx AliESDv0Cuts.cxx \
        AliEventPoolOTF.cxx AliEventPoolLoop.cxx AliEventPoolSparse.cxx \
        AliAnalysisTaskTagCreator.cxx \
-        AliMultiEventInputHandler.cxx \
+   AliMultiEventInputHandler.cxx \
        AliTriggerAnalysis.cxx \
-        AliPhysicsSelection.cxx AliBackgroundSelection.cxx \
-        AliPhysicsSelectionTask.cxx \
-        AliAnalysisFilter.cxx AliAnalysisCuts.cxx \
+   AliPhysicsSelection.cxx AliBackgroundSelection.cxx \
+   AliPhysicsSelectionTask.cxx \
+   AliAnalysisFilter.cxx AliAnalysisCuts.cxx \
        AliCollisionNormalization.cxx AliCollisionNormalizationTask.cxx \
-       AliAnalysisTaskAODCentralityMaker.cxx AliCentralitySelectionTask.cxx
+       AliAnalysisTaskAODCentralityMaker.cxx AliCentralitySelectionTask.cxx \
+   AliAnalysisTaskStat.cxx
 
 
 ifeq (yes,$(CHECKALIEN))