]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ANALYSIS/AliMultiEventInputHandler.cxx
correcting compilation warning
[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>
32
33
34ClassImp(AliMultiEventInputHandler)
35
36AliMultiEventInputHandler::AliMultiEventInputHandler() :
37 AliInputEventHandler(),
38 fBufferSize(0),
39 fFormat(1),
40 fNBuffered(0),
41 fIndex(0),
42 fCurrentBin(0),
fab17817 43 fEventPool(0),
44 fEventBuffer(0)
45{
46 // Default constructor
47}
48
49//______________________________________________________________________________
50AliMultiEventInputHandler::AliMultiEventInputHandler(Int_t size, Int_t format) :
51 AliInputEventHandler(),
52 fBufferSize(size),
53 fFormat(format),
54 fNBuffered(0),
55 fIndex(0),
56 fCurrentBin(0),
fab17817 57 fEventPool(0),
58 fEventBuffer(new AliVEvent*[size])
59{
60 // Default constructor
61 for (Int_t i = 0; i < size; i++)
62 if (fFormat == 1) {
63 fEventBuffer[i] = new AliAODEvent();
64 } else if (fFormat == 0) {
65 fEventBuffer[i] = new AliESDEvent();
66 } else{
67 AliWarning(Form("Unknown Format %5d", fFormat));
68 }
69}
70
71//______________________________________________________________________________
72AliMultiEventInputHandler::AliMultiEventInputHandler(const char* name, const char* title, Int_t size, Int_t format):
73 AliInputEventHandler(name, title),
74 fBufferSize(size),
75 fFormat(format),
76 fNBuffered(0),
77 fIndex(0),
78 fCurrentBin(0),
fab17817 79 fEventPool(0),
80 fEventBuffer(new AliVEvent*[size])
81{
82 // Constructor
83 for (Int_t i = 0; i < size; i++)
84 if (fFormat == 1) {
85 fEventBuffer[i] = new AliAODEvent();
86 } else if (fFormat == 0) {
87 fEventBuffer[i] = new AliESDEvent();
88 } else{
89 AliWarning(Form("Unknown Format %5d", fFormat));
90 }
91}
92
93//______________________________________________________________________________
94AliMultiEventInputHandler::~AliMultiEventInputHandler()
95{
96// Destructor
97}
98
99Bool_t AliMultiEventInputHandler::Init(TTree* tree, Option_t* /*opt*/)
100{
101 // Initialisation necessary for each new tree
102 fTree = tree;
103 if (!fTree) return kFALSE;
47482059 104 for (Int_t i = 0; i < fBufferSize; i++)
105 fEventBuffer[i]->Clear();
fab17817 106 fIndex = 0;
107 fNBuffered = 1;
108 return kTRUE;
109}
110
47482059 111
112Bool_t AliMultiEventInputHandler::Notify(const char */*path*/)
113{
588195ca 114 static Bool_t first = kTRUE;
115
47482059 116 // Connect to new tree
588195ca 117 if (first) {
118 fEventBuffer[0]->ReadFromTree(fTree, "");
119 first = kFALSE;
120 } else {
121 fEventBuffer[0]->ReadFromTree(fTree, "reconnect");
122 }
123
47482059 124 return (kTRUE);
125}
126
fab17817 127Bool_t AliMultiEventInputHandler::BeginEvent(Long64_t /*entry*/)
128{
129 // Actions before analysis of each event
130 //
131 // Reset the number of events buffered for this bin to 0
132 if (fCurrentBin != (fEventPool->BinNumber())) {
133 fCurrentBin = fEventPool->BinNumber();
134 fNBuffered = 0;
135 }
136 return kTRUE;
137}
138
139Bool_t AliMultiEventInputHandler::FinishEvent()
140{
141 //
142 // Connect the next event in the buffer to the tree
143 fIndex++;
144
145 fIndex %= fBufferSize;
146 AliInfo(Form("Connecting buffer entry %5d", fIndex));
47482059 147 fEventBuffer[fIndex]->Clear();
fab17817 148 fEventBuffer[fIndex]->ReadFromTree(fTree, "reconnect");
149
150 fNBuffered++;
151 if (fNBuffered > fBufferSize) fNBuffered = fBufferSize;
152
153 return (kTRUE);
154}
155
fab17817 156AliVEvent* AliMultiEventInputHandler::GetEvent(Int_t iev) const
157{
158 // Get event number iev from buffer
159 if ((iev < 0) || (iev >= fBufferSize))
160 {
161 AliWarning(Form("Event number out of range: %10d", iev));
162 return 0;
163 }
164
165 iev = fIndex - (fBufferSize - 1 - iev);
166 if (iev < 0) iev += fBufferSize;
167 AliInfo(Form("Event index in buffer is %5d", iev));
168 return (fEventBuffer[iev]);
169}
170