forked from alisw/AliPhysics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAliMixEventInputHandler.cxx
More file actions
249 lines (223 loc) · 8.24 KB
/
Copy pathAliMixEventInputHandler.cxx
File metadata and controls
249 lines (223 loc) · 8.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
//
// Class AliMixEventInputHandler
//
// Mixing input handler prepare N events before UserExec
// TODO example
// author:
// Martin Vala (martin.vala@cern.ch)
//
#include <TFile.h>
#include <TChain.h>
#include <TEntryList.h>
#include "AliLog.h"
#include "AliMixEventPool.h"
#include "AliMixEventInputHandler.h"
#include "AliAnalysisManager.h"
#include "AliMixInputHandlerInfo.h"
#include <TChainElement.h>
ClassImp(AliMixEventInputHandler)
//_____________________________________________________________________________
AliMixEventInputHandler::AliMixEventInputHandler(const Int_t size) :
AliInputEventHandler(),
fBufferSize(size),
fInputHandlers(),
fMixTrees(),
fTreeMap(size),
fMixIntupHandlerInfoTmp(0),
fEntryCounter(0),
fEventPool(0),
fMixEventNumber(0) {
//
// Default constructor.
//
AliDebug(AliLog::kDebug + 10, "<-");
AliDebug(AliLog::kDebug + 10, "->");
}
//_____________________________________________________________________________
AliInputEventHandler *AliMixEventInputHandler::InputEventHandler(const Int_t index) {
//
// Returns input handler
//
AliDebug(AliLog::kDebug, Form("<-"));
if ((index >= 0) && (index < fBufferSize)) {
AliDebug(AliLog::kDebug, Form("->"));
return (AliInputEventHandler *) fInputHandlers.At(index);
}
AliDebug(AliLog::kDebug, Form("->"));
return 0;
}
//_____________________________________________________________________________
void AliMixEventInputHandler::SetInputHandlerForMixing(const AliInputEventHandler *const inHandler) {
//
// Create N (fBufferSize) copies of input handler
//
AliDebug(AliLog::kDebug, Form("<-"));
AliDebug(AliLog::kDebug, Form("Creating %d input event handlers ...", fBufferSize));
for (Int_t i = 0; i < fBufferSize; i++) {
AliDebug(AliLog::kDebug + 5, Form("Adding %d ...", i));
fInputHandlers.Add((AliInputEventHandler *) inHandler->Clone());
}
AliDebug(AliLog::kDebug, Form("->"));
}
//_____________________________________________________________________________
Bool_t AliMixEventInputHandler::Init(Option_t *opt) {
//
// Init() is called for all mix input handlers.
//
AliDebug(AliLog::kDebug, Form("<- \"%s\"", opt));
AliInputEventHandler *eh = 0;
TObjArrayIter next(&fInputHandlers);
while ((eh = (AliInputEventHandler *) next())) {
eh->Init(opt);
}
AliDebug(AliLog::kDebug, Form("->"));
return kTRUE;
}
//_____________________________________________________________________________
Bool_t AliMixEventInputHandler::Init(TTree *tree, Option_t *) {
//
// Init(const char*path) is called for all mix input handlers.
// Create event pool if needed
//
AliDebug(AliLog::kDebug, Form("<- %p", tree));
if (!tree) {
AliDebug(AliLog::kDebug, Form("->"));
return kFALSE;
}
AliDebug(AliLog::kDebug, Form("%s", tree->GetCurrentFile()->GetName()));
// clears array of input handlers
fMixTrees.SetOwner(kTRUE);
fMixTrees.Clear();
// create AliMixInputHandlerInfo
if (!fMixIntupHandlerInfoTmp) fMixIntupHandlerInfoTmp = new AliMixInputHandlerInfo(tree->GetName());
// adds current file
fMixIntupHandlerInfoTmp->AddTreeToChain(tree);
Int_t lastIndex = fMixIntupHandlerInfoTmp->GetChain()->GetListOfFiles()->GetEntries();
TChainElement *che = (TChainElement *)fMixIntupHandlerInfoTmp->GetChain()->GetListOfFiles()->At(lastIndex - 1);
AliMixInputHandlerInfo *mixIHI = 0;
for (Int_t i = 0; i < fInputHandlers.GetEntries(); i++) {
AliDebug(AliLog::kDebug, Form("fInputHandlers[%d]", i));
mixIHI = new AliMixInputHandlerInfo(fMixIntupHandlerInfoTmp->GetName(), fMixIntupHandlerInfoTmp->GetTitle());
mixIHI->PrepareEntry(che, -1, InputEventHandler(i));
AliDebug(AliLog::kDebug, Form("chain[%d]->GetEntries() = %lld", i, mixIHI->GetChain()->GetEntries()));
fMixTrees.Add(mixIHI);
}
AliDebug(AliLog::kDebug, Form("fEntryCounter=%lld", fEntryCounter));
if (fEventPool->NeedInit())
fEventPool->Init();
AliDebug(AliLog::kDebug, Form("->"));
return kTRUE;
}
//_____________________________________________________________________________
Bool_t AliMixEventInputHandler::Notify() {
//
// Notify() is called for all mix input handlers
//
AliDebug(AliLog::kDebug, Form("<-"));
AliInputEventHandler *eh = 0;
TObjArrayIter next(&fInputHandlers);
while ((eh = (AliInputEventHandler *) next())) {
eh->Notify();
}
AliDebug(AliLog::kDebug, Form("->"));
return kTRUE;
}
//_____________________________________________________________________________
Bool_t AliMixEventInputHandler::Notify(const char *path) {
//
// Notify(const char*path) is called for all mix input handlers
//
AliDebug(AliLog::kDebug, Form("<- %s", path));
AliInputEventHandler *eh = 0;
TObjArrayIter next(&fInputHandlers);
while ((eh = (AliInputEventHandler *) next())) {
eh->Notify(path);
}
AliDebug(AliLog::kDebug, Form("->"));
return kTRUE;
}
//_____________________________________________________________________________
Bool_t AliMixEventInputHandler::BeginEvent(Long64_t entry) {
//
// BeginEvent(Long64_t entry) is called for all mix input handlers
//
AliDebug(AliLog::kDebug, Form("-> %lld", entry));
AliInputEventHandler *eh = 0;
TObjArrayIter next(&fInputHandlers);
while ((eh = (AliInputEventHandler *) next())) {
eh->BeginEvent(entry);
}
AliDebug(AliLog::kDebug, Form("->"));
return kTRUE;
}
//_____________________________________________________________________________
Bool_t AliMixEventInputHandler::GetEntry() {
//
// Sets correct events to every mix events
//
AliDebug(AliLog::kDebug, Form("<-"));
AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
AliInputEventHandler *inEvHMain = dynamic_cast<AliInputEventHandler *>(mgr->GetInputEventHandler());
Long64_t zeroChainEntries = fMixIntupHandlerInfoTmp->GetChain()->GetEntries() - inEvHMain->GetTree()->GetEntries();
// if fEntryCounter is 0 just add entry
if (!fEntryCounter) {
if (inEvHMain) {
fEventPool->AddEntry(inEvHMain->GetTree()->GetReadEntry() + zeroChainEntries, inEvHMain->GetEvent());
}
return kTRUE;
}
AliDebug(AliLog::kDebug, Form("++++++++++++++ BEGIN SETUP EVENT %lld +++++++++++++++++++", fEntryCounter));
fMixEventNumber = 0;
TEntryList *el = fEventPool->FindEntryList(inEvHMain->GetEvent());
Long64_t elNum = 0;
if (el)
elNum = el->GetN();
else
AliDebug(AliLog::kDebug, "el is null");
AliInputEventHandler *eh = 0;
AliMixInputHandlerInfo *mihi = 0;
TObjArrayIter next(&fInputHandlers);
Int_t counter = 0;
Long64_t entryMix = 0;
while ((eh = (AliInputEventHandler *) next())) {
if (fEventPool->GetListOfEventCuts()->GetEntries() > 0) {
entryMix = -1;
if (el && el->GetN() >= fBufferSize) {
Long64_t entryInEntryList = elNum - 1 - counter;
if (entryInEntryList < 0) break;
entryMix = el->GetEntry(entryInEntryList);
}
} else {
entryMix = fEntryCounter - 1 - counter ;
}
AliDebug(AliLog::kDebug, Form("Handler[%d] entryMix %lld ", counter, entryMix));
if (entryMix < 0) break;
mihi = (AliMixInputHandlerInfo *) fMixTrees.At(counter);
TChainElement *te = fMixIntupHandlerInfoTmp->GetEntryInTree(entryMix);
mihi->PrepareEntry(te, entryMix, InputEventHandler(counter));
fMixEventNumber++;
counter++;
}
if (inEvHMain) {
fEventPool->AddEntry(inEvHMain->GetTree()->GetReadEntry() + zeroChainEntries, inEvHMain->GetEvent());
}
AliDebug(AliLog::kDebug, Form("fEntryCounter=%lld fMixEventNumber=%d", fEntryCounter, fMixEventNumber));
AliDebug(AliLog::kDebug, Form("++++++++++++++ END SETUP EVENT %lld +++++++++++++++++++", fEntryCounter));
AliDebug(AliLog::kDebug, Form("->"));
return kTRUE;
}
//_____________________________________________________________________________
Bool_t AliMixEventInputHandler::FinishEvent() {
//
// FinishEvent() is called for all mix input handlers
//
AliDebug(AliLog::kDebug, Form("<-"));
AliInputEventHandler *eh = 0;
TObjArrayIter next(&fInputHandlers);
while ((eh = (AliInputEventHandler *) next())) {
eh->FinishEvent();
}
fEntryCounter++;
AliDebug(AliLog::kDebug, Form("->"));
return kTRUE;
}