2 // Class AliMixEventInputHandler
4 // Mixing input handler prepare N events before UserExec
7 // Martin Vala (martin.vala@cern.ch)
12 #include <TEntryList.h>
14 #include "AliMixEventPool.h"
15 #include "AliMixEventInputHandler.h"
16 #include "AliAnalysisManager.h"
18 #include "AliMixInputHandlerInfo.h"
19 #include <TChainElement.h>
21 ClassImp(AliMixEventInputHandler)
23 //_____________________________________________________________________________
24 AliMixEventInputHandler::AliMixEventInputHandler(const Int_t size) :
25 AliInputEventHandler(),
30 fMixIntupHandlerInfoTmp(0),
35 // Default constructor.
37 AliDebug(AliLog::kDebug + 10, "<-");
38 AliDebug(AliLog::kDebug + 10, "->");
41 //_____________________________________________________________________________
42 AliInputEventHandler *AliMixEventInputHandler::InputEventHandler(const Int_t index) {
44 // Returns input handler
46 AliDebug(AliLog::kDebug, Form("<-"));
47 if ((index >= 0) && (index < fBufferSize)) {
48 AliDebug(AliLog::kDebug, Form("->"));
49 return (AliInputEventHandler *) fInputHandlers.At(index);
51 AliDebug(AliLog::kDebug, Form("->"));
54 //_____________________________________________________________________________
55 void AliMixEventInputHandler::SetInputHandlerForMixing(const AliInputEventHandler *const inHandler) {
57 // Create N (fBufferSize) copies of input handler
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());
65 AliDebug(AliLog::kDebug, Form("->"));
67 //_____________________________________________________________________________
68 Bool_t AliMixEventInputHandler::Init(Option_t *opt) {
70 // Init() is called for all mix input handlers.
72 AliDebug(AliLog::kDebug, Form("<- \"%s\"", opt));
73 AliInputEventHandler *eh = 0;
74 TObjArrayIter next(&fInputHandlers);
75 while ((eh = (AliInputEventHandler *) next())) {
78 AliDebug(AliLog::kDebug, Form("->"));
81 //_____________________________________________________________________________
82 Bool_t AliMixEventInputHandler::Init(TTree *tree, Option_t *) {
84 // Init(const char*path) is called for all mix input handlers.
85 // Create event pool if needed
87 AliDebug(AliLog::kDebug, Form("<- %p", tree));
89 AliDebug(AliLog::kDebug, Form("->"));
92 AliDebug(AliLog::kDebug, Form("%s", tree->GetCurrentFile()->GetName()));
94 // clears array of input handlers
95 fMixTrees.SetOwner(kTRUE);
98 // create AliMixInputHandlerInfo
99 if (!fMixIntupHandlerInfoTmp) fMixIntupHandlerInfoTmp = new AliMixInputHandlerInfo(tree->GetName());
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++) {
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);
114 AliDebug(AliLog::kDebug, Form("fEntryCounter=%lld", fEntryCounter));
116 if (fEventPool->NeedInit())
119 AliDebug(AliLog::kDebug, Form("->"));
122 //_____________________________________________________________________________
123 Bool_t AliMixEventInputHandler::Notify() {
125 // Notify() is called for all mix input handlers
127 AliDebug(AliLog::kDebug, Form("<-"));
128 AliInputEventHandler *eh = 0;
129 TObjArrayIter next(&fInputHandlers);
130 while ((eh = (AliInputEventHandler *) next())) {
133 AliDebug(AliLog::kDebug, Form("->"));
137 //_____________________________________________________________________________
138 Bool_t AliMixEventInputHandler::Notify(const char *path) {
140 // Notify(const char*path) is called for all mix input handlers
142 AliDebug(AliLog::kDebug, Form("<- %s", path));
143 AliInputEventHandler *eh = 0;
144 TObjArrayIter next(&fInputHandlers);
145 while ((eh = (AliInputEventHandler *) next())) {
148 AliDebug(AliLog::kDebug, Form("->"));
151 //_____________________________________________________________________________
152 Bool_t AliMixEventInputHandler::BeginEvent(Long64_t entry) {
154 // BeginEvent(Long64_t entry) is called for all mix input handlers
157 AliDebug(AliLog::kDebug, Form("-> %lld", entry));
158 AliInputEventHandler *eh = 0;
159 TObjArrayIter next(&fInputHandlers);
160 while ((eh = (AliInputEventHandler *) next())) {
161 eh->BeginEvent(entry);
163 AliDebug(AliLog::kDebug, Form("->"));
168 //_____________________________________________________________________________
169 Bool_t AliMixEventInputHandler::GetEntry() {
171 // Sets correct events to every mix events
173 AliDebug(AliLog::kDebug, Form("<-"));
175 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
176 AliInputEventHandler *inEvHMain = dynamic_cast<AliInputEventHandler *>(mgr->GetInputEventHandler());
178 Long64_t zeroChainEntries = fMixIntupHandlerInfoTmp->GetChain()->GetEntries() - inEvHMain->GetTree()->GetEntries();
180 // if fEntryCounter is 0 just add entry
181 if (!fEntryCounter) {
184 fEventPool->AddEntry(inEvHMain->GetTree()->GetReadEntry() + zeroChainEntries, inEvHMain->GetEvent());
189 AliDebug(AliLog::kDebug, Form("++++++++++++++ BEGIN SETUP EVENT %lld +++++++++++++++++++", fEntryCounter));
192 TEntryList *el = fEventPool->FindEntryList(inEvHMain->GetEvent());
197 AliDebug(AliLog::kDebug, "el is null");
199 AliInputEventHandler *eh = 0;
200 AliMixInputHandlerInfo *mihi = 0;
201 TObjArrayIter next(&fInputHandlers);
203 Long64_t entryMix = 0;
204 while ((eh = (AliInputEventHandler *) next())) {
205 if (fEventPool->GetListOfEventCuts()->GetEntries() > 0) {
207 if (el && el->GetN() >= fBufferSize) {
208 Long64_t entryInEntryList = elNum - 1 - counter;
209 if (entryInEntryList < 0) break;
210 entryMix = el->GetEntry(entryInEntryList);
213 entryMix = fEntryCounter - 1 - counter ;
216 AliDebug(AliLog::kDebug, Form("Handler[%d] entryMix %lld ", counter, entryMix));
217 if (entryMix < 0) break;
219 mihi = (AliMixInputHandlerInfo *) fMixTrees.At(counter);
220 TChainElement *te = fMixIntupHandlerInfoTmp->GetEntryInTree(entryMix);
221 mihi->PrepareEntry(te, entryMix, InputEventHandler(counter));
227 fEventPool->AddEntry(inEvHMain->GetTree()->GetReadEntry() + zeroChainEntries, inEvHMain->GetEvent());
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("->"));
235 //_____________________________________________________________________________
236 Bool_t AliMixEventInputHandler::FinishEvent() {
238 // FinishEvent() is called for all mix input handlers
240 AliDebug(AliLog::kDebug, Form("<-"));
241 AliInputEventHandler *eh = 0;
242 TObjArrayIter next(&fInputHandlers);
243 while ((eh = (AliInputEventHandler *) next())) {
247 AliDebug(AliLog::kDebug, Form("->"));