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