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 Int_t[fBufferSize];
46 ///_______________________________________________________________________
47 AliEveEventBuffer::~AliEveEventBuffer() {
48 // see header file for class documentation
51 fEventBuffer->Clear();
62 void AliEveEventBuffer::CreateBufferThread() {
63 // cout << "hereherehere"<<endl;
64 TThread * fThread = new TThread(AliEveEventBuffer::BufferThread, (void*) this);
69 ///___________________________________________________________________________
70 void * AliEveEventBuffer::BufferThread(void * buffer) {
71 cout <<"BufferThread : " <<endl;
73 if (!reinterpret_cast<AliEveEventBuffer*>(buffer)->GetBusy()) {
74 reinterpret_cast<AliEveEventBuffer*>(buffer)->MonitorBuffer();
80 cout << "no buffer"<<endl;
85 ///_____________________________________________________________________________
86 void AliEveEventBuffer::MonitorBuffer() {
87 cout << "Monitorbuffer: " << endl;
88 if ( (CalculateDifference(fBIndex[kTop],fBIndex[kLast]) < fPreBuffer) ) {
90 cout << "Already called FetchEvent()" << endl;
98 //StopBufferMonitor();
105 ///_______________________________________________________________________________
106 TObject * AliEveEventBuffer::NextEvent() {
107 //See header file for documentation
108 cout << "In enxtevent"<<endl;
112 // cout << "Event Buffer busy"<<endl;
115 // else SetBusy(kTRUE);
116 TObject * nextEvent = GetNextUnSeen();
121 ///______________________________________________________________________________
122 TObject * AliEveEventBuffer::Back() {
123 cout << "go back"<<endl;
125 Int_t prevId = CalculatePrevious(fBIndex[kCurrent]);
126 if(prevId == fBIndex[kTop]) {
127 cout << "returning NULL" << endl;
130 fBIndex[kCurrent] = prevId;
132 cout <<"returning: "<< fBIndex[kCurrent] << " " << fEventBuffer->At(fBIndex[kCurrent]);
133 return fEventBuffer->At(fBIndex[kCurrent]);
137 ///______________________________________________________________________________
138 TObject * AliEveEventBuffer::Fwd() {
140 if (fBIndex[kCurrent] == fBIndex[kLast]) {
141 cout<< "returning NULL"<<endl;
145 fBIndex[kCurrent] = CalculateNext(fBIndex[kCurrent]);
146 TObject * event = fEventBuffer->At(fBIndex[kCurrent]);
152 ///________________________________________________________________________________
153 TObject * AliEveEventBuffer::GetNextUnSeen() {
154 //See header file for documentation
155 cout << "GetNextUnSeen"<<endl;
157 if(CalculateDifference(fBIndex[kTop], fBIndex[kLast])) {
158 fBIndex[kLast] = CalculateNext(fBIndex[kLast]);
159 fBIndex[kCurrent] = fBIndex[kLast];
161 return fEventBuffer->At(fBIndex[kCurrent]);
163 cout << "No new event available, only events in buffer available!"<<endl;
167 ///_________________________________________________________________________________
168 void AliEveEventBuffer::PrintIndeces() {
169 for(Int_t i = 0; i < kSize; i++) {
170 cout << i << ": " << fBIndex[i] << endl;
173 ///_________________________________________________________________________________
174 void AliEveEventBuffer::PrintBuffer() {
175 for(Int_t i = 0; i < 10; i++) {
176 AliESDEvent * event = dynamic_cast<AliESDEvent*>(fEventBuffer->At(i));
178 cout << i << ": " <<event << " " << event->GetEventNumberInFile() << endl;;
183 ///____________________________________________________________________________________
184 void AliEveEventBuffer::FetchEvent() {
185 cout << "FetchEvent " << endl;
186 TObject * event = GetEventFromSource();
187 if(event) AddToBuffer(event);
189 cout << "FetchedEvent " << endl;
193 ///_________________________________________________________________________________
194 void AliEveEventBuffer::AddToBuffer(TObject * event) {
195 cout << "Add to buffer"<<endl;
198 fBIndex[kTop] = CalculateNext(fBIndex[kTop]);
199 //Delete the event already there (ok to delete as object, not aliesdevent, TList?)
200 //TObject * object = fEventBuffer->At(fBIndex[kTop]);
201 fEventBuffer->RemoveAt(fBIndex[kTop]);
202 //if (object) delete object;
203 fEventBuffer->AddAt(event, fBIndex[kTop]);
208 ///_____________________________________________________________________________________
209 Int_t AliEveEventBuffer::CalculateNext(Int_t current) {
210 //See header file for documentation
212 if(current == fBufferSize) current = 0;
217 ///_____________________________________________________________________________________
218 Int_t AliEveEventBuffer::CalculatePrevious(Int_t current) {
219 //See header file for documentation
220 cout << "CalculatePrev: " << current;
222 if(current == -1) current += fBufferSize;
223 cout << "... " << current << endl;
227 ///__________________________________________________________________________________
228 Int_t AliEveEventBuffer::CalculateDifference(Int_t top, Int_t low) {
229 //See header file for documentation
231 // cout << "top > low"<<endl;
233 } else if (top < low) {
234 // cout << "low < top"<<endl;
235 return (fBufferSize - low + top);
237 //cout << "calculated to 0"<<endl;
242 ///___________________________________________________________________________________
243 void AliEveEventBuffer::StartBufferMonitor() {
244 //cout << "NOT !!! starting buffer mon"<<endl;
245 cout << "starting buffer mon"<<endl;
246 CreateBufferThread();
247 SetBufferMonStarted(kTRUE);
248 fTimer->Start(10000);
250 ///___________________________________________________________________________________
251 void AliEveEventBuffer::StopBufferMonitor() {
252 cout << "Stopping buffer mon"<<endl;
253 SetBufferMonStarted(kFALSE);
258 // //_________________________________________________________________________________
259 // Int_t AliEveEventBuffer::NavigateEventBufferBack() {
260 // // see header file for class documentation
262 // // -- reached the end of the buffer
263 // if ( fNavigateBufferIdx == fBufferLowIdx )
266 // Int_t newIdx = fNavigateBufferIdx - 1;
267 // if ( newIdx == -1 )
268 // newIdx = BUFFERSIZE-1;
270 // fCurrentBufferIdx = fNavigateBufferIdx = newIdx;
275 // //_______________________________________________________________
276 // Int_t AliEveEventBuffer::NavigateEventBufferFwd() {
277 // // see header file for class documentation
279 // // -- reached the top of the buffer
280 // if ( fNavigateBufferIdx == fBufferTopIdx )
283 // Int_t newIdx = fNavigateBufferIdx + 1;
284 // if ( newIdx == BUFFERSIZE )
287 // fCurrentBufferIdx = fNavigateBufferIdx = newIdx;
292 // void AliEveEventBuffer::MonitorBuffer() {
293 // //See header file for documentation
294 // if( GetNAvailableEvents() < 10) {
295 // StopBufferChecker();
300 // void AliEveEventBuffer::StartLoop() {
301 // //See header file for documentation
302 // fTimer->Start(2000);
304 // void AliEveEventBuffer::StopLoop() {
305 // //See header file for documentation
309 // void AliEveEventBuffer::StartBufferChecker() {
310 // //See header file for documentation
311 // fBufferTimer->Start(2000);
313 // void AliEveEventBuffer::StopBufferChecker() {
314 // //See header file for documentation
315 // fBufferTimer->Stop();
318 // AliESDEvent * GetNextEvent() {
320 // tree->GetEntry(fEvent++);
322 // AliESDEvent * event = new AliESDEvent();
323 // event->ReadFromTree(fTree);
327 // cout << "error getting event" << endl;