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