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>
33 #include <TEntryList.h>
36 ClassImp(AliMultiEventInputHandler)
38 AliMultiEventInputHandler::AliMultiEventInputHandler() :
39 AliInputEventHandler(),
50 // Default constructor
53 //______________________________________________________________________________
54 AliMultiEventInputHandler::AliMultiEventInputHandler(Int_t size, Int_t format) :
55 AliInputEventHandler(),
69 //______________________________________________________________________________
70 AliMultiEventInputHandler::AliMultiEventInputHandler(const char* name, const char* title, Int_t size, Int_t format):
71 AliInputEventHandler(name, title),
86 //______________________________________________________________________________
87 AliMultiEventInputHandler::~AliMultiEventInputHandler()
92 Bool_t AliMultiEventInputHandler::Init(TTree* tree, Option_t* /*opt*/)
94 // Initialisation necessary for each new tree
96 fEventBuffer = new AliVEvent*[fBufferSize];
98 for (Int_t i = 0; i < fBufferSize; i++)
100 fEventBuffer[i] = new AliAODEvent();
101 } else if (fFormat == 0) {
102 fEventBuffer[i] = new AliESDEvent();
104 AliWarning(Form("Unknown Format %5d", fFormat));
112 if (!fTree) return kFALSE;
113 for (Int_t i = 0; i < fBufferSize; i++)
114 fEventBuffer[i]->Clear();
121 Bool_t AliMultiEventInputHandler::Notify(const char */*path*/)
123 // Connect to new tree
125 TList* connectedList = (TList*) (fTree->GetUserInfo()->FindObject("AODObjectsConnectedToTree"));
126 if (connectedList && !fInit) {
127 fEventBuffer[0]->ReadFromTree(fTree, "reconnect");
129 if (fInit) fEventBuffer[0]->ReadFromTree(fTree, "");
138 Bool_t AliMultiEventInputHandler::BeginEvent(Long64_t /*entry*/)
140 // Actions before analysis of each event
142 // Reset the number of events buffered for this bin to 0
143 if (fCurrentBin != (fEventPool->BinNumber())) {
144 fCurrentBin = fEventPool->BinNumber();
150 Bool_t AliMultiEventInputHandler::FinishEvent()
153 // Connect the next event in the buffer to the tree
156 fIndex %= fBufferSize;
157 AliInfo(Form("Connecting buffer entry %5d", fIndex));
158 fEventBuffer[fIndex]->Clear();
160 if (fEventBuffer[fIndex]->GetList() && fCurrentEvt > (fBufferSize - 1))
161 fEventBuffer[fIndex]->GetList()->Delete();
163 fEventBuffer[fIndex]->ReadFromTree(fTree, "reconnect");
166 if (fNBuffered > fBufferSize) fNBuffered = fBufferSize;
168 Int_t nmax = fTree->GetEntries();
169 if (fTree->GetEntryList()) {
170 nmax = (fTree->GetEntryList()->GetN());
172 if (fTree->GetTree()) nmax = fTree->GetTree()->GetEntries();
175 if (fCurrentEvt == nmax)
177 for (Int_t i = 0; i < fBufferSize; i++) {
178 fEventBuffer[i]->Clear();
185 AliVEvent* AliMultiEventInputHandler::GetEvent(Int_t iev) const
187 // Get event number iev from buffer
188 if ((iev < 0) || (iev >= fBufferSize))
190 AliWarning(Form("Event number out of range: %10d", iev));
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]);