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(),
58 fEventBuffer(new AliVEvent*[size])
60 // Default constructor
61 for (Int_t i = 0; i < size; i++)
63 fEventBuffer[i] = new AliAODEvent();
64 } else if (fFormat == 0) {
65 fEventBuffer[i] = new AliESDEvent();
67 AliWarning(Form("Unknown Format %5d", fFormat));
71 //______________________________________________________________________________
72 AliMultiEventInputHandler::AliMultiEventInputHandler(const char* name, const char* title, Int_t size, Int_t format):
73 AliInputEventHandler(name, title),
80 fEventBuffer(new AliVEvent*[size])
83 for (Int_t i = 0; i < size; i++)
85 fEventBuffer[i] = new AliAODEvent();
86 } else if (fFormat == 0) {
87 fEventBuffer[i] = new AliESDEvent();
89 AliWarning(Form("Unknown Format %5d", fFormat));
93 //______________________________________________________________________________
94 AliMultiEventInputHandler::~AliMultiEventInputHandler()
99 Bool_t AliMultiEventInputHandler::Init(TTree* tree, Option_t* /*opt*/)
101 // Initialisation necessary for each new tree
103 if (!fTree) return kFALSE;
104 for (Int_t i = 0; i < fBufferSize; i++)
105 fEventBuffer[i]->Clear();
112 Bool_t AliMultiEventInputHandler::Notify(const char */*path*/)
114 // Connect to new tree
115 fEventBuffer[0]->ReadFromTree(fTree, "");
119 Bool_t AliMultiEventInputHandler::BeginEvent(Long64_t /*entry*/)
121 // Actions before analysis of each event
123 // Reset the number of events buffered for this bin to 0
124 if (fCurrentBin != (fEventPool->BinNumber())) {
125 fCurrentBin = fEventPool->BinNumber();
131 Bool_t AliMultiEventInputHandler::FinishEvent()
134 // Connect the next event in the buffer to the tree
137 fIndex %= fBufferSize;
138 AliInfo(Form("Connecting buffer entry %5d", fIndex));
139 fEventBuffer[fIndex]->Clear();
140 fEventBuffer[fIndex]->ReadFromTree(fTree, "reconnect");
143 if (fNBuffered > fBufferSize) fNBuffered = fBufferSize;
148 AliVEvent* AliMultiEventInputHandler::GetEvent(Int_t iev) const
150 // Get event number iev from buffer
151 if ((iev < 0) || (iev >= fBufferSize))
153 AliWarning(Form("Event number out of range: %10d", iev));
157 iev = fIndex - (fBufferSize - 1 - iev);
158 if (iev < 0) iev += fBufferSize;
159 AliInfo(Form("Event index in buffer is %5d", iev));
160 return (fEventBuffer[iev]);