Line data Source code
1 : /**************************************************************************
2 : * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 : * *
4 : * Author: The ALICE Off-line Project. *
5 : * Contributors are mentioned in the code where appropriate. *
6 : * *
7 : * Permission to use, copy, modify and distribute this software and its *
8 : * documentation strictly for non-commercial purposes is hereby granted *
9 : * without fee, provided that the above copyright notice appears in all *
10 : * copies and that both the copyright notice and this permission notice *
11 : * appear in the supporting documentation. The authors make no claims *
12 : * about the suitability of this software for any purpose. It is *
13 : * provided "as is" without express or implied warranty. *
14 : **************************************************************************/
15 :
16 : /* $Id$ */
17 : // Author: Andrei Gheata, 20/12/2010
18 :
19 : //==============================================================================
20 : // AliAnalysisTaskStat - basic task that attaches a AliAnalysisTaskstatistics
21 : // object to the analysis manager. Use: AliAnalysisManager::AddStatisticsTask
22 : // to attach to a train.
23 : //==============================================================================
24 :
25 : #include "AliAnalysisTaskStat.h"
26 :
27 : #include <TList.h>
28 : #include "AliVEvent.h"
29 : #include "AliAnalysisManager.h"
30 : #include "AliAnalysisDataContainer.h"
31 : #include "AliAnalysisStatistics.h"
32 :
33 170 : ClassImp(AliAnalysisTaskStat)
34 :
35 : //______________________________________________________________________________
36 : AliAnalysisTaskStat::AliAnalysisTaskStat(const char *name)
37 0 : :AliAnalysisTaskSE(name),
38 0 : fStatistics(0),
39 0 : fOutputList(0)
40 0 : {
41 : // Named constructor.
42 0 : DefineOutput(1, TList::Class());
43 0 : fBranchNames = "ESD:AliESDHeader. AOD:header";
44 0 : fStatistics = new AliAnalysisStatistics("MgrStat");
45 0 : }
46 :
47 : //______________________________________________________________________________
48 : AliAnalysisTaskStat::~AliAnalysisTaskStat()
49 0 : {
50 : // Destructor.
51 0 : if (fOutputList) {
52 0 : if (!AliAnalysisManager::GetAnalysisManager()->IsProofMode()) delete fOutputList;
53 : } else {
54 0 : if (fStatistics) delete fStatistics;
55 : }
56 0 : }
57 :
58 : //______________________________________________________________________________
59 : AliAnalysisTaskStat *AliAnalysisTaskStat::AddToManager(UInt_t offlineMask)
60 : {
61 : // Add this task to the analysis manager. By default it selects MB events.
62 0 : AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
63 0 : if (!mgr) {
64 0 : ::Error("AliAnalysisTaskStat::AddToManager", "You need a manager first");
65 0 : return 0;
66 : }
67 0 : AliAnalysisDataContainer *cinput = mgr->GetCommonInputContainer();
68 0 : if (!cinput) {
69 0 : ::Error("AliAnalysisTaskStat::AddToManager", "Attach first the input handler");
70 0 : return 0;
71 : }
72 0 : AliAnalysisDataContainer *coutput = mgr->CreateContainer("MgrStat", TList::Class(), AliAnalysisManager::kOutputContainer,
73 0 : mgr->GetCommonFileName());
74 0 : AliAnalysisTaskStat *taskStatistics = new AliAnalysisTaskStat("MgrStat");
75 0 : mgr->AddTask(taskStatistics);
76 0 : AliAnalysisStatistics *stat = taskStatistics->GetStatistics();
77 0 : stat->SetOfflineMask(offlineMask);
78 0 : mgr->SetStatistics(stat);
79 0 : taskStatistics->SelectCollisionCandidates(offlineMask);
80 0 : mgr->ConnectInput(taskStatistics, 0, cinput);
81 0 : mgr->ConnectOutput(taskStatistics, 1, coutput);
82 : return taskStatistics;
83 0 : }
84 :
85 : //______________________________________________________________________________
86 : void AliAnalysisTaskStat::UserCreateOutputObjects()
87 : {
88 : // Create the output list.
89 0 : if (!fStatistics) {
90 0 : Fatal("UserCreateOutputObjects", "You are not allowed to create this task using the dummy constructor. Use the named one.");
91 0 : }
92 0 : fOutputList = new TList();
93 0 : fOutputList->SetOwner();
94 0 : if (fStatistics) fOutputList->Add(fStatistics);
95 0 : PostData(1, fOutputList);
96 0 : }
97 :
98 : //______________________________________________________________________________
99 : void AliAnalysisTaskStat::UserExec(Option_t *)
100 : {
101 : // Event loop.
102 0 : fStatistics->AddAccepted();
103 0 : }
104 :
105 : //______________________________________________________________________________
106 : void AliAnalysisTaskStat::Terminate(Option_t *)
107 : {
108 : // Get the statistics from its container and copy to manager.
109 0 : fOutputList = dynamic_cast<TList*>(GetOutputData(1));
110 0 : if (!fOutputList) {
111 0 : Error("Terminate", "Cannot get output list from container");
112 0 : return;
113 : }
114 0 : AliAnalysisStatistics *stat = dynamic_cast<AliAnalysisStatistics*>(fOutputList->At(0));
115 0 : if (!stat) {
116 0 : Error("Terminate", "Statistics object not found in list");
117 0 : return;
118 : }
119 0 : AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
120 0 : if (stat != fStatistics) {
121 : // Non-local mode
122 0 : fStatistics->AddInput(stat->GetNinput());
123 0 : fStatistics->AddProcessed(stat->GetNprocessed());
124 0 : fStatistics->AddFailed(stat->GetNfailed());
125 0 : fStatistics->AddAccepted(stat->GetNaccepted());
126 0 : mgr->SetStatistics(fStatistics);
127 0 : }
128 0 : fStatistics->Print();
129 0 : }
|