6 #include "AliEveEventBuffer.h"
9 //Not needed, only for debug
10 #include "AliESDEvent.h"
14 ClassImp(AliEveEventBuffer)
16 ///_______________________________________________________________________
17 AliEveEventBuffer::AliEveEventBuffer() :
26 fBufferMonStarted(kFALSE)
28 // see header file for class documentation
29 fEventBuffer = new TObjArray(fBufferSize, 0);
30 fEventBuffer->SetOwner(kFALSE);
32 for(int id = 0; id < kSize; id++) {
36 fTimer = new TTimer();
37 fTimer->Connect("Timeout()", "AliEveEventBuffer", this, "CreateBufferThread()");
39 fEventId = new ULong64_t[fBufferSize];
40 for(Int_t id = 0; id < fBufferSize; id++ ) {
49 ///_______________________________________________________________________
50 AliEveEventBuffer::~AliEveEventBuffer() {
51 // see header file for class documentation
54 fEventBuffer->Clear();
65 ///___________________________________________________________________________
66 void AliEveEventBuffer::CreateBufferThread() {
68 cout << "Buffer is busy, no thread created"<< endl;
71 if ( (CalculateDifference(fBIndex[kTop],fBIndex[kLast]) < fPreBuffer) ) {
72 cout << "CreateBufferThread()"<<endl;
73 TThread * fThread = new TThread(AliEveEventBuffer::BufferThread, (void*) this);
75 cout << "Started BufferThread"<<endl;
77 cout << "Buffer is full already"<<endl;
81 ///___________________________________________________________________________
82 void * AliEveEventBuffer::BufferThread(void * buffer) {
83 cout <<"BufferThread : " <<endl;
85 reinterpret_cast<AliEveEventBuffer*>(buffer)->MonitorBuffer();
87 cout << "no buffer"<<endl;
92 ///_____________________________________________________________________________
93 void AliEveEventBuffer::MonitorBuffer() {
94 cout << "Monitorbuffer: " << endl;
96 cout << "Already called FetchEvent()" << endl;
107 ///_______________________________________________________________________________
108 TObject * AliEveEventBuffer::NextEvent() {
109 //See header file for documentation
110 cout << "NextEvent()"<<endl;
114 // cout << "Event Buffer busy"<<endl;
117 // else SetBusy(kTRUE);
118 TObject * nextEvent = GetNextUnSeen();
123 ///______________________________________________________________________________
124 TObject * AliEveEventBuffer::Back() {
125 cout << "go back"<<endl;
127 Int_t prevId = CalculatePrevious(fBIndex[kCurrent]);
128 if(prevId == fBIndex[kTop]) {
129 cout << "returning NULL" << endl;
132 fBIndex[kCurrent] = prevId;
134 cout <<"returning: "<< fBIndex[kCurrent] << " " << fEventBuffer->At(fBIndex[kCurrent]);
135 return fEventBuffer->At(fBIndex[kCurrent]);
141 ///______________________________________________________________________________
142 TObject * AliEveEventBuffer::Fwd() {
144 if (fBIndex[kCurrent] == fBIndex[kLast]) {
145 cout<< "returning NULL"<<endl;
149 fBIndex[kCurrent] = CalculateNext(fBIndex[kCurrent]);
150 TObject * event = fEventBuffer->At(fBIndex[kCurrent]);
156 ///________________________________________________________________________________
157 TObject * AliEveEventBuffer::GetNextUnSeen() {
158 //See header file for documentation
159 cout << "GetNextUnSeen"<<endl;
161 if(CalculateDifference(fBIndex[kTop], fBIndex[kLast])) {
162 fBIndex[kLast] = CalculateNext(fBIndex[kLast]);
163 fBIndex[kCurrent] = fBIndex[kLast];
165 return fEventBuffer->At(fBIndex[kCurrent]);
167 cout << "No new event available, only events in buffer available!"<<endl;
171 ///_________________________________________________________________________________
172 void AliEveEventBuffer::PrintIndeces() {
173 for(Int_t i = 0; i < kSize; i++) {
174 cout << i << ": " << fBIndex[i] << endl;
177 ///_________________________________________________________________________________
178 void AliEveEventBuffer::PrintBuffer() {
179 for(Int_t i = 0; i < 10; i++) {
180 AliESDEvent * event = dynamic_cast<AliESDEvent*>(fEventBuffer->At(i));
182 cout << i << ": " <<event << " " << event->GetEventNumberInFile() << endl;;
187 ///____________________________________________________________________________________
188 void AliEveEventBuffer::FetchEvent() {
189 cout << "FetchEvent " << endl;
190 TObject * event = GetEventFromSource();
191 ULong64_t eventId = GetEventIdFromSource();
194 fEventId[fBIndex[kTop]] = eventId;
198 cout << "FetchedEvent " << endl;
202 ///_________________________________________________________________________________
203 void AliEveEventBuffer::AddToBuffer(TObject * event) {
204 cout << "Add to buffer"<<endl;
207 fBIndex[kTop] = CalculateNext(fBIndex[kTop]);
208 //Delete the event already there (ok to delete as object, not aliesdevent, TList?)
209 //TObject * object = fEventBuffer->At(fBIndex[kTop]);
210 fEventBuffer->RemoveAt(fBIndex[kTop]);
211 //if (object) delete object;
212 fEventBuffer->AddAt(event, fBIndex[kTop]);
216 ///_____________________________________________________________________________________
217 Int_t AliEveEventBuffer::CalculateNext(Int_t current) {
218 //See header file for documentation
220 if(current == fBufferSize) current = 0;
225 ///_____________________________________________________________________________________
226 Int_t AliEveEventBuffer::CalculatePrevious(Int_t current) {
227 //See header file for documentation
228 cout << "CalculatePrev: " << current;
230 if(current == -1) current += fBufferSize;
231 cout << "... " << current << endl;
235 ///__________________________________________________________________________________
236 Int_t AliEveEventBuffer::CalculateDifference(Int_t top, Int_t low) {
237 //See header file for documentation
239 // cout << "top > low"<<endl;
241 } else if (top < low) {
242 // cout << "low < top"<<endl;
243 return (fBufferSize - low + top);
245 //cout << "calculated to 0"<<endl;
250 ///___________________________________________________________________________________
251 void AliEveEventBuffer::StartBufferMonitor() {
252 //cout << "NOT !!! starting buffer mon"<<endl;
253 cout << "starting buffer mon"<<endl;
254 if(!GetBufferMonStarted()) {
255 CreateBufferThread();
256 SetBufferMonStarted(kTRUE);
259 cout << "Stopping buffer monitor"<<endl;
261 SetBufferMonStarted(kFALSE);
264 ///___________________________________________________________________________________
265 void AliEveEventBuffer::StopBufferMonitor() {
266 cout << "Stopping buffer mon"<<endl;
267 SetBufferMonStarted(kFALSE);
272 // //_________________________________________________________________________________
273 // Int_t AliEveEventBuffer::NavigateEventBufferBack() {
274 // // see header file for class documentation
276 // // -- reached the end of the buffer
277 // if ( fNavigateBufferIdx == fBufferLowIdx )
280 // Int_t newIdx = fNavigateBufferIdx - 1;
281 // if ( newIdx == -1 )
282 // newIdx = BUFFERSIZE-1;
284 // fCurrentBufferIdx = fNavigateBufferIdx = newIdx;
289 // //_______________________________________________________________
290 // Int_t AliEveEventBuffer::NavigateEventBufferFwd() {
291 // // see header file for class documentation
293 // // -- reached the top of the buffer
294 // if ( fNavigateBufferIdx == fBufferTopIdx )
297 // Int_t newIdx = fNavigateBufferIdx + 1;
298 // if ( newIdx == BUFFERSIZE )
301 // fCurrentBufferIdx = fNavigateBufferIdx = newIdx;
306 // void AliEveEventBuffer::MonitorBuffer() {
307 // //See header file for documentation
308 // if( GetNAvailableEvents() < 10) {
309 // StopBufferChecker();
314 // void AliEveEventBuffer::StartLoop() {
315 // //See header file for documentation
316 // fTimer->Start(2000);
318 // void AliEveEventBuffer::StopLoop() {
319 // //See header file for documentation
323 // void AliEveEventBuffer::StartBufferChecker() {
324 // //See header file for documentation
325 // fBufferTimer->Start(2000);
327 // void AliEveEventBuffer::StopBufferChecker() {
328 // //See header file for documentation
329 // fBufferTimer->Stop();
332 // AliESDEvent * GetNextEvent() {
334 // tree->GetEntry(fEvent++);
336 // AliESDEvent * event = new AliESDEvent();
337 // event->ReadFromTree(fTree);
341 // cout << "error getting event" << endl;