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