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