]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ANALYSIS/AliMultiEventInputHandler.cxx
Update from Alberica. Addition of VZERO equalized signals and ZNC.
[u/mrichter/AliRoot.git] / ANALYSIS / AliMultiEventInputHandler.cxx
CommitLineData
fab17817 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"
3c329509 29#include "AliVCuts.h"
fab17817 30#include "AliLog.h"
31#include <TObjArray.h>
32#include <TTree.h>
28a79204 33#include <TList.h>
34#include <TEntryList.h>
fab17817 35
36
37ClassImp(AliMultiEventInputHandler)
38
39AliMultiEventInputHandler::AliMultiEventInputHandler() :
40 AliInputEventHandler(),
41 fBufferSize(0),
42 fFormat(1),
43 fNBuffered(0),
44 fIndex(0),
45 fCurrentBin(0),
28a79204 46 fCurrentEvt(0),
47 fInit(0),
fab17817 48 fEventPool(0),
3c329509 49 fEventBuffer(0),
50 fEventSkipped(0)
fab17817 51{
52 // Default constructor
53}
54
55//______________________________________________________________________________
56AliMultiEventInputHandler::AliMultiEventInputHandler(Int_t size, Int_t format) :
57 AliInputEventHandler(),
58 fBufferSize(size),
59 fFormat(format),
60 fNBuffered(0),
61 fIndex(0),
62 fCurrentBin(0),
28a79204 63 fCurrentEvt(0),
64 fInit(0),
fab17817 65 fEventPool(0),
3c329509 66 fEventBuffer(0),
67 fEventSkipped(0)
fab17817 68{
67b28e0a 69 // constructor
fab17817 70}
71
72//______________________________________________________________________________
73AliMultiEventInputHandler::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),
28a79204 80 fCurrentEvt(0),
81 fInit(0),
fab17817 82 fEventPool(0),
3c329509 83 fEventBuffer(0),
84 fEventSkipped(0)
fab17817 85{
86 // Constructor
67b28e0a 87
fab17817 88}
89
90//______________________________________________________________________________
91AliMultiEventInputHandler::~AliMultiEventInputHandler()
92{
93// Destructor
94}
95
96Bool_t AliMultiEventInputHandler::Init(TTree* tree, Option_t* /*opt*/)
97{
98 // Initialisation necessary for each new tree
67b28e0a 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
fab17817 113 fTree = tree;
28a79204 114 fInit = 1;
115
fab17817 116 if (!fTree) return kFALSE;
47482059 117 for (Int_t i = 0; i < fBufferSize; i++)
118 fEventBuffer[i]->Clear();
fab17817 119 fIndex = 0;
120 fNBuffered = 1;
121 return kTRUE;
122}
123
47482059 124
125Bool_t AliMultiEventInputHandler::Notify(const char */*path*/)
126{
67b28e0a 127 // Connect to new tree
2da1d158 128
28a79204 129 TList* connectedList = (TList*) (fTree->GetUserInfo()->FindObject("AODObjectsConnectedToTree"));
130 if (connectedList && !fInit) {
67b28e0a 131 fEventBuffer[0]->ReadFromTree(fTree, "reconnect");
28a79204 132 } else {
133 if (fInit) fEventBuffer[0]->ReadFromTree(fTree, "");
588195ca 134 }
135
28a79204 136 fCurrentEvt = 0;
137 fInit = 0;
67b28e0a 138
47482059 139 return (kTRUE);
140}
141
fab17817 142Bool_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
2da1d158 147
fab17817 148 if (fCurrentBin != (fEventPool->BinNumber())) {
149 fCurrentBin = fEventPool->BinNumber();
150 fNBuffered = 0;
151 }
3c329509 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
fab17817 162 return kTRUE;
163}
164
165Bool_t AliMultiEventInputHandler::FinishEvent()
166{
167 //
168 // Connect the next event in the buffer to the tree
3c329509 169 if (!fEventSkipped) fIndex++;
fab17817 170 fIndex %= fBufferSize;
171 AliInfo(Form("Connecting buffer entry %5d", fIndex));
47482059 172 fEventBuffer[fIndex]->Clear();
28a79204 173 fCurrentEvt++;
174 if (fEventBuffer[fIndex]->GetList() && fCurrentEvt > (fBufferSize - 1))
175 fEventBuffer[fIndex]->GetList()->Delete();
176
fab17817 177 fEventBuffer[fIndex]->ReadFromTree(fTree, "reconnect");
178
179 fNBuffered++;
180 if (fNBuffered > fBufferSize) fNBuffered = fBufferSize;
2da1d158 181
28a79204 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
fab17817 196 return (kTRUE);
197}
198
fab17817 199AliVEvent* 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