]>
Commit | Line | Data |
---|---|---|
1 | /************************************************************************** | |
2 | * Copyright(c) 1998-2007, 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 | ||
18 | //------------------------------------------------------------------------- | |
19 | // Event handler for multiple VEvent input. | |
20 | // This class handles multiple inputs for event mixing. | |
21 | // Author: Andreas Morsch, CERN | |
22 | //------------------------------------------------------------------------- | |
23 | ||
24 | #include "AliMultiEventInputHandler.h" | |
25 | #include "AliVEvent.h" | |
26 | #include "AliAODEvent.h" | |
27 | #include "AliESDEvent.h" | |
28 | #include "AliVEventPool.h" | |
29 | #include "AliVCuts.h" | |
30 | #include "AliLog.h" | |
31 | #include <TObjArray.h> | |
32 | #include <TTree.h> | |
33 | #include <TList.h> | |
34 | #include <TEntryList.h> | |
35 | ||
36 | ||
37 | ClassImp(AliMultiEventInputHandler) | |
38 | ||
39 | AliMultiEventInputHandler::AliMultiEventInputHandler() : | |
40 | AliInputEventHandler(), | |
41 | fBufferSize(0), | |
42 | fFormat(1), | |
43 | fNBuffered(0), | |
44 | fIndex(0), | |
45 | fCurrentBin(0), | |
46 | fCurrentEvt(0), | |
47 | fInit(0), | |
48 | fEventPool(0), | |
49 | fEventBuffer(0), | |
50 | fEventSkipped(0) | |
51 | { | |
52 | // Default constructor | |
53 | } | |
54 | ||
55 | //______________________________________________________________________________ | |
56 | AliMultiEventInputHandler::AliMultiEventInputHandler(Int_t size, Int_t format) : | |
57 | AliInputEventHandler(), | |
58 | fBufferSize(size), | |
59 | fFormat(format), | |
60 | fNBuffered(0), | |
61 | fIndex(0), | |
62 | fCurrentBin(0), | |
63 | fCurrentEvt(0), | |
64 | fInit(0), | |
65 | fEventPool(0), | |
66 | fEventBuffer(0), | |
67 | fEventSkipped(0) | |
68 | { | |
69 | // constructor | |
70 | } | |
71 | ||
72 | //______________________________________________________________________________ | |
73 | AliMultiEventInputHandler::AliMultiEventInputHandler(const char* name, const char* title, Int_t size, Int_t format): | |
74 | AliInputEventHandler(name, title), | |
75 | fBufferSize(size), | |
76 | fFormat(format), | |
77 | fNBuffered(0), | |
78 | fIndex(0), | |
79 | fCurrentBin(0), | |
80 | fCurrentEvt(0), | |
81 | fInit(0), | |
82 | fEventPool(0), | |
83 | fEventBuffer(0), | |
84 | fEventSkipped(0) | |
85 | { | |
86 | // Constructor | |
87 | ||
88 | } | |
89 | ||
90 | //______________________________________________________________________________ | |
91 | AliMultiEventInputHandler::~AliMultiEventInputHandler() | |
92 | { | |
93 | // Destructor | |
94 | } | |
95 | ||
96 | Bool_t AliMultiEventInputHandler::Init(TTree* tree, Option_t* /*opt*/) | |
97 | { | |
98 | // Initialisation necessary for each new tree | |
99 | if (!fEventBuffer) { | |
100 | fEventBuffer = new AliVEvent*[fBufferSize]; | |
101 | ||
102 | for (Int_t i = 0; i < fBufferSize; i++) | |
103 | if (fFormat == 1) { | |
104 | fEventBuffer[i] = new AliAODEvent(); | |
105 | } else if (fFormat == 0) { | |
106 | fEventBuffer[i] = new AliESDEvent(); | |
107 | } else{ | |
108 | AliWarning(Form("Unknown Format %5d", fFormat)); | |
109 | } | |
110 | } | |
111 | ||
112 | ||
113 | fTree = tree; | |
114 | fInit = 1; | |
115 | ||
116 | if (!fTree) return kFALSE; | |
117 | for (Int_t i = 0; i < fBufferSize; i++) | |
118 | fEventBuffer[i]->Clear(); | |
119 | fIndex = 0; | |
120 | fNBuffered = 1; | |
121 | return kTRUE; | |
122 | } | |
123 | ||
124 | ||
125 | Bool_t AliMultiEventInputHandler::Notify(const char */*path*/) | |
126 | { | |
127 | // Connect to new tree | |
128 | ||
129 | TList* connectedList = (TList*) (fTree->GetUserInfo()->FindObject("AODObjectsConnectedToTree")); | |
130 | if (connectedList && !fInit) { | |
131 | fEventBuffer[0]->ReadFromTree(fTree, "reconnect"); | |
132 | } else { | |
133 | if (fInit) fEventBuffer[0]->ReadFromTree(fTree, ""); | |
134 | } | |
135 | ||
136 | fCurrentEvt = 0; | |
137 | fInit = 0; | |
138 | ||
139 | return (kTRUE); | |
140 | } | |
141 | ||
142 | Bool_t AliMultiEventInputHandler::BeginEvent(Long64_t /*entry*/) | |
143 | { | |
144 | // Actions before analysis of each event | |
145 | // | |
146 | // Reset the number of events buffered for this bin to 0 | |
147 | ||
148 | if (fCurrentBin != (fEventPool->BinNumber())) { | |
149 | fCurrentBin = fEventPool->BinNumber(); | |
150 | fNBuffered = 0; | |
151 | } | |
152 | // | |
153 | // Event selection | |
154 | // | |
155 | if (fFormat == 0) { | |
156 | fIsSelectedResult = 0; | |
157 | if (fEventCuts && !IsUserCallSelectionMask()) | |
158 | fIsSelectedResult = | |
159 | fEventCuts->GetSelectionMask((AliESDEvent*)fEventBuffer[fIndex]); | |
160 | } | |
161 | ||
162 | return kTRUE; | |
163 | } | |
164 | ||
165 | Bool_t AliMultiEventInputHandler::FinishEvent() | |
166 | { | |
167 | // | |
168 | // Connect the next event in the buffer to the tree | |
169 | if (!fEventSkipped) fIndex++; | |
170 | fIndex %= fBufferSize; | |
171 | AliInfo(Form("Connecting buffer entry %5d", fIndex)); | |
172 | fEventBuffer[fIndex]->Clear(); | |
173 | fCurrentEvt++; | |
174 | if (fEventBuffer[fIndex]->GetList() && fCurrentEvt > (fBufferSize - 1)) | |
175 | fEventBuffer[fIndex]->GetList()->Delete(); | |
176 | ||
177 | fEventBuffer[fIndex]->ReadFromTree(fTree, "reconnect"); | |
178 | ||
179 | fNBuffered++; | |
180 | if (fNBuffered > fBufferSize) fNBuffered = fBufferSize; | |
181 | ||
182 | Int_t nmax = fTree->GetEntries(); | |
183 | if (fTree->GetEntryList()) { | |
184 | nmax = (fTree->GetEntryList()->GetN()); | |
185 | } else { | |
186 | if (fTree->GetTree()) nmax = fTree->GetTree()->GetEntries(); | |
187 | } | |
188 | ||
189 | if (fCurrentEvt == nmax) | |
190 | { | |
191 | for (Int_t i = 0; i < fBufferSize; i++) { | |
192 | fEventBuffer[i]->Clear(); | |
193 | } | |
194 | } | |
195 | ||
196 | return (kTRUE); | |
197 | } | |
198 | ||
199 | AliVEvent* AliMultiEventInputHandler::GetEvent(Int_t iev) const | |
200 | { | |
201 | // Get event number iev from buffer | |
202 | if ((iev < 0) || (iev >= fBufferSize)) | |
203 | { | |
204 | AliWarning(Form("Event number out of range: %10d", iev)); | |
205 | return 0; | |
206 | } | |
207 | ||
208 | iev = fIndex - (fBufferSize - 1 - iev); | |
209 | if (iev < 0) iev += fBufferSize; | |
210 | AliInfo(Form("Event index in buffer is %5d", iev)); | |
211 | return (fEventBuffer[iev]); | |
212 | } | |
213 |