Fixes from Coverity(15969,15968,15967,15964,15963,15962,15961,10283)
[u/mrichter/AliRoot.git] / ANALYSIS / EventMixing / AliAnalysisTaskMixInfo.cxx
CommitLineData
b425275c 1//
2// Class AliAnalysisTaskMixInfo
3//
4// AliAnalysisTaskMixInfo is task
5// for mixing info
6//
7// authors:
8// Martin Vala (martin.vala@cern.ch)
9//
10
11#include <TList.h>
12
13#include "AliAnalysisManager.h"
14
15#include "AliMixInputEventHandler.h"
16#include "AliAnalysisTaskMixInfo.h"
17#include "AliMixInfo.h"
18#include "AliMixEventPool.h"
19
20ClassImp(AliAnalysisTaskMixInfo)
21
22//________________________________________________________________________
23AliAnalysisTaskMixInfo::AliAnalysisTaskMixInfo(const char *name)
24 : AliAnalysisTaskSE(name),
25 fOutputList(0),
26 fMixInfo(0),
27 fCurrentEntryTmp(-1),
28 fLogType(AliLog::kInfo),
29 fLogClassesString()
30{
31 //
32 // Constructor
33 //
34 DefineOutput(1, TList::Class());
35}
36
37//________________________________________________________________________
38AliAnalysisTaskMixInfo::~AliAnalysisTaskMixInfo()
39{
40 //
41 // Destructor
42 //
43 if (fOutputList && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) delete fOutputList;
44}
45
46//________________________________________________________________________
47void AliAnalysisTaskMixInfo::UserCreateOutputObjects()
48{
49 // Create histograms
50 // Called once
51
52 SetDebugForAllClasses();
53 fOutputList = new TList();
54 fOutputList->SetOwner(kTRUE);
55 if (!fMixInfo) InitMixInfo();
56
57 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
58 AliMultiInputEventHandler *inEvHMain = dynamic_cast<AliMultiInputEventHandler *>(mgr->GetInputEventHandler());
59 if (inEvHMain) {
60 AliMixInputEventHandler *mixEH = dynamic_cast<AliMixInputEventHandler *>(inEvHMain->GetFirstMultiInputHandler());
61 if (mixEH) {
62 AliMixEventPool *evPool = mixEH->GetEventPool();
63 if (evPool) {
64 evPool->SetBufferSize(mixEH->BufferSize());
65 evPool->SetMixNumber(mixEH->MixNumber());
66 fMixInfo->SetEventPool(evPool);
67 }
68 }
69 }
70
71 if (fMixInfo) fOutputList->Add(fMixInfo);
72
73 // Post output data.
74 PostData(1, fOutputList);
75}
76
77//________________________________________________________________________
78void AliAnalysisTaskMixInfo::UserExec(Option_t *)
79{
80 // Main loop
81 // Called for each event
82// if (fCurrentEntry != fCurrentEntryTmp) {
83// fCurrentEntryTmp = fCurrentEntry;
84 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
85 AliMultiInputEventHandler *inEvHMain = dynamic_cast<AliMultiInputEventHandler *>(mgr->GetInputEventHandler());
86 if (inEvHMain) {
87 AliMixInputEventHandler *mixEH = dynamic_cast<AliMixInputEventHandler *>(inEvHMain->GetFirstMultiInputHandler());
88 if (fMixInfo && mixEH) {
89 if (mixEH->BufferSize() > 1) {
90 if (mixEH->NumberMixedTimes() >= mixEH->BufferSize())
91 fMixInfo->FillHistogram(AliMixInfo::kMainEvents, mixEH->CurrentBinIndex());
92 } else {
93 fMixInfo->FillHistogram(AliMixInfo::kMainEvents, mixEH->CurrentBinIndex());
94 }
781b6757 95
b425275c 96 if (mixEH->CurrentEntryMix() >= 0)
97 AliDebug(AliLog::kDebug + 1, Form("Main %lld %d [%lld,%lld] %d", mixEH->CurrentEntry(), mixEH->NumberMixed(), mixEH->CurrentEntryMain(), mixEH->CurrentEntryMix(), mixEH->NumberMixed()));
781b6757 98 }
b425275c 99 }
100 // Post output data.
101 PostData(1, fOutputList);
102}
103
104//________________________________________________________________________
105void AliAnalysisTaskMixInfo::UserExecMix(Option_t *)
106{
107 // UserExecMix
108 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
109 AliMultiInputEventHandler *inEvHMain = dynamic_cast<AliMultiInputEventHandler *>(mgr->GetInputEventHandler());
110 if (inEvHMain) {
111 AliMixInputEventHandler *mixEH = dynamic_cast<AliMixInputEventHandler *>(inEvHMain->GetFirstMultiInputHandler());
781b6757 112 if (!mixEH) return;
b425275c 113 if (fMixInfo) fMixInfo->FillHistogram(AliMixInfo::kMixedEvents, mixEH->CurrentBinIndex());
781b6757 114 if (mixEH->CurrentEntryMix() < 0) {
b425275c 115 AliError("Mix entry is -1 and it should not happen !!!!!");
116 return ;
117 }
781b6757 118 AliDebug(AliLog::kDebug, Form("Mixing %lld %d [%lld,%lld] %d", mixEH->CurrentEntry(), mixEH->NumberMixed(), mixEH->CurrentEntryMain(), mixEH->CurrentEntryMix(), mixEH->CurrentBinIndex()));
b425275c 119 }
120 // Post output data.
121 PostData(1, fOutputList);
122}
123
124//________________________________________________________________________
125void AliAnalysisTaskMixInfo::FinishTaskOutput()
126{
127 // FinishTaskOutput
128 if (fMixInfo) fMixInfo->Print();
129}
130
131
132//________________________________________________________________________
133void AliAnalysisTaskMixInfo::Terminate(Option_t *)
134{
135 // Draw result to the screen
136 // Called once at the end of the query
137 fOutputList = dynamic_cast<TList *>(GetOutputData(1));
138 if (!fOutputList) {
139 AliError("fOutputList not available");
140 return;
141 }
142 fOutputList->Print();
143 fMixInfo = (AliMixInfo *) fOutputList->FindObject("mixInfo");
144 if (fMixInfo) {
145 fMixInfo->Draw("HIST");
146 AliMixEventPool *evPool = (AliMixEventPool *) fMixInfo->GetEventPool("mixEventPool");
147 if (evPool) evPool->Print();
148 }
149}
150
151//_____________________________________________________________________________
152void AliAnalysisTaskMixInfo::SetLogType(AliLog::EType_t type, TString allClasses)
153{
154 //
155 // Set Log level for this and other classes (list of their names)
156 //
157 AliDebug(AliLog::kDebug + 10, "<-");
158 fLogType = type;
159 fLogClassesString = allClasses;
160 SetDebugForAllClasses();
161 AliDebug(AliLog::kDebug + 10, "->");
162}
163
164//_____________________________________________________________________________
165void AliAnalysisTaskMixInfo::SetDebugForAllClasses()
166{
167 //
168 // Set debug level for all classes for which it is required
169 //
170 AliDebug(AliLog::kDebug + 10, "<-");
171 TObjArray *array = fLogClassesString.Tokenize(":");
172 TObjString *str;
173 TString strr;
174 for (Int_t i = 0; i < array->GetEntriesFast(); i++) {
175 str = (TObjString *) array->At(i);
176 strr = str->GetString();
177 AliLog::SetClassDebugLevel(strr.Data(), fLogType);
178 AliDebug(AliLog::kDebug + 5, Form("Setting Debug level %d to %s ...", (Int_t)fLogType - AliLog::kDebug, strr.Data()));
179 }
180 AliDebug(AliLog::kDebug + 10, "->");
181}
182
183
184void AliAnalysisTaskMixInfo::InitMixInfo()
185{
186 //
187 // Init mixing info
188 //
189 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
190 AliMultiInputEventHandler *inEvHMain = dynamic_cast<AliMultiInputEventHandler *>(mgr->GetInputEventHandler());
191 if (inEvHMain) {
192 // AliMixEventInputHandler *mixEH = dynamic_cast<AliMixEventInputHandler *>(inEvHMain->MixingHandler());
193 AliMixInputEventHandler *mixEH = dynamic_cast<AliMixInputEventHandler *>(inEvHMain->GetFirstMultiInputHandler());
194 if (mixEH) {
195 fMixInfo = new AliMixInfo("mixInfo", "Mix title");
196// if(fMixInfo) fMixInfo->SetOutputList(fOutputList);
197 AliMixEventPool *evPool = mixEH->GetEventPool();
198 if (!evPool) {
199 // TList *list = new TList;
200 if (fMixInfo) fMixInfo->CreateHistogram(AliMixInfo::kMainEvents, 1, 1, 2);
201 if (fMixInfo) fMixInfo->CreateHistogram(AliMixInfo::kMixedEvents, 1, 1, 2);
202 } else {
203 if (evPool->NeedInit()) evPool->Init();
204 Int_t num = evPool->GetListOfEntryLists()->GetEntriesFast();
205 if (fMixInfo) fMixInfo->CreateHistogram(AliMixInfo::kMainEvents, num, 1, num + 1);
206 if (fMixInfo) fMixInfo->CreateHistogram(AliMixInfo::kMixedEvents, num, 1, num + 1);
207 }
208 } else {
209 AliError("No mixEH");
210 }
211 } else {
212 AliError("No inEvHMain");
213 }
214}