1 /**************************************************************************
2 * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //-------------------------------------------------------------------------
19 // Event handler for multiple VEvent input.
20 // This class handles multiple inputs for event mixing.
21 // Author: Andreas Morsch, CERN
22 //-------------------------------------------------------------------------
24 #include "AliMultiEventInputHandler.h"
25 #include "AliVEvent.h"
26 #include "AliAODEvent.h"
27 #include "AliESDEvent.h"
28 #include "AliVEventPool.h"
30 #include <TObjArray.h>
34 ClassImp(AliMultiEventInputHandler)
36 AliMultiEventInputHandler::AliMultiEventInputHandler() :
37 AliInputEventHandler(),
46 // Default constructor
49 //______________________________________________________________________________
50 AliMultiEventInputHandler::AliMultiEventInputHandler(Int_t size, Int_t format) :
51 AliInputEventHandler(),
63 //______________________________________________________________________________
64 AliMultiEventInputHandler::AliMultiEventInputHandler(const char* name, const char* title, Int_t size, Int_t format):
65 AliInputEventHandler(name, title),
78 //______________________________________________________________________________
79 AliMultiEventInputHandler::~AliMultiEventInputHandler()
84 Bool_t AliMultiEventInputHandler::Init(TTree* tree, Option_t* /*opt*/)
86 // Initialisation necessary for each new tree
88 fEventBuffer = new AliVEvent*[fBufferSize];
90 for (Int_t i = 0; i < fBufferSize; i++)
92 fEventBuffer[i] = new AliAODEvent();
93 } else if (fFormat == 0) {
94 fEventBuffer[i] = new AliESDEvent();
96 AliWarning(Form("Unknown Format %5d", fFormat));
102 if (!fTree) return kFALSE;
103 for (Int_t i = 0; i < fBufferSize; i++)
104 fEventBuffer[i]->Clear();
111 Bool_t AliMultiEventInputHandler::Notify(const char */*path*/)
113 // Connect to new tree
116 static Bool_t first = kTRUE;
120 fEventBuffer[0]->ReadFromTree(fTree, "");
123 fEventBuffer[0]->ReadFromTree(fTree, "reconnect");
130 Bool_t AliMultiEventInputHandler::BeginEvent(Long64_t /*entry*/)
132 // Actions before analysis of each event
134 // Reset the number of events buffered for this bin to 0
135 if (fCurrentBin != (fEventPool->BinNumber())) {
136 fCurrentBin = fEventPool->BinNumber();
142 Bool_t AliMultiEventInputHandler::FinishEvent()
145 // Connect the next event in the buffer to the tree
148 fIndex %= fBufferSize;
149 AliInfo(Form("Connecting buffer entry %5d", fIndex));
150 fEventBuffer[fIndex]->Clear();
151 fEventBuffer[fIndex]->ReadFromTree(fTree, "reconnect");
154 if (fNBuffered > fBufferSize) fNBuffered = fBufferSize;
159 AliVEvent* AliMultiEventInputHandler::GetEvent(Int_t iev) const
161 // Get event number iev from buffer
162 if ((iev < 0) || (iev >= fBufferSize))
164 AliWarning(Form("Event number out of range: %10d", iev));
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]);