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"
31 #include <TObjArray.h>
34 #include <TEntryList.h>
37 ClassImp(AliMultiEventInputHandler)
39 AliMultiEventInputHandler::AliMultiEventInputHandler() :
40 AliInputEventHandler(),
52 // Default constructor
55 //______________________________________________________________________________
56 AliMultiEventInputHandler::AliMultiEventInputHandler(Int_t size, Int_t format) :
57 AliInputEventHandler(),
72 //______________________________________________________________________________
73 AliMultiEventInputHandler::AliMultiEventInputHandler(const char* name, const char* title, Int_t size, Int_t format):
74 AliInputEventHandler(name, title),
90 //______________________________________________________________________________
91 AliMultiEventInputHandler::~AliMultiEventInputHandler()
96 Bool_t AliMultiEventInputHandler::Init(TTree* tree, Option_t* /*opt*/)
98 // Initialisation necessary for each new tree
100 fEventBuffer = new AliVEvent*[fBufferSize];
102 for (Int_t i = 0; i < fBufferSize; i++)
104 fEventBuffer[i] = new AliAODEvent();
105 } else if (fFormat == 0) {
106 fEventBuffer[i] = new AliESDEvent();
108 AliWarning(Form("Unknown Format %5d", fFormat));
116 if (!fTree) return kFALSE;
117 for (Int_t i = 0; i < fBufferSize; i++)
118 fEventBuffer[i]->Clear();
125 Bool_t AliMultiEventInputHandler::Notify(const char */*path*/)
127 // Connect to new tree
129 TList* connectedList = (TList*) (fTree->GetUserInfo()->FindObject("AODObjectsConnectedToTree"));
130 if (connectedList && !fInit) {
131 fEventBuffer[0]->ReadFromTree(fTree, "reconnect");
133 if (fInit) fEventBuffer[0]->ReadFromTree(fTree, "");
142 Bool_t AliMultiEventInputHandler::BeginEvent(Long64_t /*entry*/)
144 // Actions before analysis of each event
146 // Reset the number of events buffered for this bin to 0
148 if (fCurrentBin != (fEventPool->BinNumber())) {
149 fCurrentBin = fEventPool->BinNumber();
156 fIsSelectedResult = 0;
157 if (fEventCuts && !IsUserCallSelectionMask())
159 fEventCuts->GetSelectionMask((AliESDEvent*)fEventBuffer[fIndex]);
165 Bool_t AliMultiEventInputHandler::FinishEvent()
168 // Connect the next event in the buffer to the tree
169 if (!fEventSkipped) fIndex++;
170 fIndex %= fBufferSize;
171 AliInfo(Form("Connecting buffer entry %5d", fIndex));
172 fEventBuffer[fIndex]->Clear();
174 if (fEventBuffer[fIndex]->GetList() && fCurrentEvt > (fBufferSize - 1))
175 fEventBuffer[fIndex]->GetList()->Delete();
177 fEventBuffer[fIndex]->ReadFromTree(fTree, "reconnect");
180 if (fNBuffered > fBufferSize) fNBuffered = fBufferSize;
182 Int_t nmax = fTree->GetEntries();
183 if (fTree->GetEntryList()) {
184 nmax = (fTree->GetEntryList()->GetN());
186 if (fTree->GetTree()) nmax = fTree->GetTree()->GetEntries();
189 if (fCurrentEvt == nmax)
191 for (Int_t i = 0; i < fBufferSize; i++) {
192 fEventBuffer[i]->Clear();
199 AliVEvent* AliMultiEventInputHandler::GetEvent(Int_t iev) const
201 // Get event number iev from buffer
202 if ((iev < 0) || (iev >= fBufferSize))
204 AliWarning(Form("Event number out of range: %10d", iev));
208 iev = fIndex - (fBufferSize - 1 - iev);
209 if (iev < 0) iev += fBufferSize;
210 AliInfo(Form("Event index in buffer is %5d", iev));
211 return (fEventBuffer[iev]);