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