]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/RESONANCES/AliRsnEventBuffer.cxx
a few more checks
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnEventBuffer.cxx
CommitLineData
06351446 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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//
17// Class AliRsnEventBuffer
18//
19// Implements a temporary buffer of many AliRsnEvent objects
20// which is useful for event mixing.
21//
22// author: Martin Vala (Martin.Vala@cern.ch)
23// revised by: A. Pulvirenti (alberto.pulvirenti@ct.infn.it)
24//
25
26#include "AliLog.h"
e0baff8c 27
28#include "AliRsnCut.h"
29#include "AliRsnCutSet.h"
06351446 30#include "AliRsnEventBuffer.h"
31
aec0ec32 32ClassImp(AliRsnEventBuffer)
06351446 33
34//_____________________________________________________________________________
aec0ec32 35AliRsnEventBuffer::AliRsnEventBuffer(Int_t buffSize, Bool_t deleteBufferWhenReset) :
36 fDeleteBufferWhenReset(deleteBufferWhenReset),
37 fEventsBufferSize(buffSize),
38 fEventsBufferIndex(-1)
06351446 39{
40//
41// Constructor.
42// Initializes to NULL all AliRsnEvent pointers.
43//
44
aec0ec32 45 Int_t i;
46 for (i = 0; i < fEventsBufferSize; i++) fEventsBuffer[i] = 0;
06351446 47}
48
49//_____________________________________________________________________________
50AliRsnEventBuffer::~AliRsnEventBuffer()
51{
52//
53// Destructor.
54// Actually does nothing.
55//
56
aec0ec32 57 //ClearBuffer();
06351446 58}
59
60//_____________________________________________________________________________
61void AliRsnEventBuffer::ClearBuffer()
62{
63//
64// Clears buffer, resetting all pointers.
65// If an event is on the HEAP, it is deleted.
66//
aec0ec32 67 Int_t i;
68 for (i = 0; i < fEventsBufferSize; i++)
69 {
70 AliDebug(1, Form("Clearing slot #%p in buffer", fEventsBuffer[i]));
71 if (fEventsBuffer[i]->IsOnHeap()) delete fEventsBuffer[i];
72 fEventsBuffer[i] = 0;
73 }
06351446 74}
75
76//_____________________________________________________________________________
77void AliRsnEventBuffer::ResetIndex()
78{
79//
80// Resets the index for accessing events in buffer
81//
aec0ec32 82 fEventsBufferIndex = -1;
83 if (fDeleteBufferWhenReset == kTRUE) ClearBuffer();
06351446 84}
85
86//_____________________________________________________________________________
aec0ec32 87void AliRsnEventBuffer::AddEvent(AliRsnEvent * event)
06351446 88{
89//
90// Insert a new event in the buffer.
91// Since the buffer has a fixed size, when the last index is reached,
92// the new event replaces the oldest one in the buffer
93//
94
aec0ec32 95 if (fEventsBufferIndex >= fEventsBufferSize - 1) ResetIndex();
96 fEventsBufferIndex++;
e0baff8c 97 if (fEventsBuffer[fEventsBufferIndex]) {
98 //AliInfo("Replacing event");
aec0ec32 99 *fEventsBuffer[fEventsBufferIndex] = *event;
e0baff8c 100 }
101 else {
102 //AliInfo("New event");
aec0ec32 103 fEventsBuffer[fEventsBufferIndex] = new AliRsnEvent(*event);
e0baff8c 104 }
e0baff8c 105}
106
107//_____________________________________________________________________________
108Int_t AliRsnEventBuffer::IndexOf(AliRsnEvent * event)
109{
110//
111// Return position of the event
112//
113
114 Int_t i;
115 for (i = 0; i < fEventsBufferSize; i++) {
116 if (event == fEventsBuffer[i]) return i;
117 }
118
119 return -1;
06351446 120}
121
122//_____________________________________________________________________________
123AliRsnEvent* AliRsnEventBuffer::GetCurrentEvent()
124{
125//
126// Returns the current event in the buffer
127//
aec0ec32 128 return GetEvent(fEventsBufferIndex);
06351446 129}
130
131//_____________________________________________________________________________
132AliRsnEvent * AliRsnEventBuffer::GetNextEvent()
133{
134//
135// Returns next event in the buffer w.r. to current
136//
aec0ec32 137 if (fEventsBufferIndex == fEventsBufferSize - 1) return GetEvent(0);
138 else return GetEvent(fEventsBufferIndex + 1);
06351446 139}
140
e0baff8c 141//_____________________________________________________________________________
142AliRsnEvent * AliRsnEventBuffer::GetNextGoodEvent
143(Int_t &start, AliRsnCutSet *cuts)
144{
145//
146// Scans the buffer starting from 'start' in order to
147// find another event which satisfies the cuts defined in 'cuts'.
148// If it finds such an event, returns it and upgrades the 'start' value
149// to its position, otherwise returns NULL.
150//
151
152 Int_t i = start;
153 AliRsnEvent *ref = GetCurrentEvent();
154 AliRsnEvent *ev = 0x0;
0ef90328 155 for(;;i--) {
e0baff8c 156 ev = GetEvent(i);
0ef90328 157 if (ev == ref) continue;
e0baff8c 158 if (!ev) break;
159 if (!cuts) {
160 start = i;
161 return ev;
162 }
163 else if (cuts->IsSelected(AliRsnCut::kMixEvent, ref, ev)) {
164 start = i;
165 return ev;
166 }
167 }
168
169 return 0x0;
170}
171
06351446 172//_____________________________________________________________________________
aec0ec32 173AliRsnEvent * AliRsnEventBuffer::GetEvent(Int_t index)
06351446 174{
175//
176// Returns an event in the buffer, provided its index
177//
aec0ec32 178 if (index < 0 || index >= fEventsBufferSize)
179 {
180 AliDebug(AliLog::kError,Form("Index out of range (index = %d , size = %d)", index, fEventsBufferSize));
181 return 0x0;
182 }
183 return (AliRsnEvent*)fEventsBuffer[index];
06351446 184}
185
186//_____________________________________________________________________________
187Int_t AliRsnEventBuffer::NEmptySlots()
188{
189//
190// Tells if the buffer is completely filled or has empty slots
191//
aec0ec32 192 Int_t i, counter = 0;
193 for (i = 0; i < fEventsBufferSize; i++)
194 {
195 if (!fEventsBuffer[i]) counter++;
196 }
197
198 return counter;
06351446 199}