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 void AliEveEventBuffer::CreateBufferThread() {
66 // cout << "hereherehere"<<endl;
67 TThread * fThread = new TThread(AliEveEventBuffer::BufferThread, (void*) this);
72 ///___________________________________________________________________________
73 void * AliEveEventBuffer::BufferThread(void * buffer) {
74 cout <<"BufferThread : " <<endl;
76 if (!reinterpret_cast<AliEveEventBuffer*>(buffer)->GetBusy()) {
77 reinterpret_cast<AliEveEventBuffer*>(buffer)->MonitorBuffer();
83 cout << "no buffer"<<endl;
88 ///_____________________________________________________________________________
89 void AliEveEventBuffer::MonitorBuffer() {
90 cout << "Monitorbuffer: " << endl;
91 if ( (CalculateDifference(fBIndex[kTop],fBIndex[kLast]) < fPreBuffer) ) {
93 cout << "Already called FetchEvent()" << endl;
101 //StopBufferMonitor();
108 ///_______________________________________________________________________________
109 TObject * AliEveEventBuffer::NextEvent() {
110 //See header file for documentation
111 cout << "In enxtevent"<<endl;
115 // cout << "Event Buffer busy"<<endl;
118 // else SetBusy(kTRUE);
119 TObject * nextEvent = GetNextUnSeen();
124 ///______________________________________________________________________________
125 TObject * AliEveEventBuffer::Back() {
126 cout << "go back"<<endl;
128 Int_t prevId = CalculatePrevious(fBIndex[kCurrent]);
129 if(prevId == fBIndex[kTop]) {
130 cout << "returning NULL" << endl;
133 fBIndex[kCurrent] = prevId;
135 cout <<"returning: "<< fBIndex[kCurrent] << " " << fEventBuffer->At(fBIndex[kCurrent]);
136 return fEventBuffer->At(fBIndex[kCurrent]);
142 ///______________________________________________________________________________
143 TObject * AliEveEventBuffer::Fwd() {
145 if (fBIndex[kCurrent] == fBIndex[kLast]) {
146 cout<< "returning NULL"<<endl;
150 fBIndex[kCurrent] = CalculateNext(fBIndex[kCurrent]);
151 TObject * event = fEventBuffer->At(fBIndex[kCurrent]);
157 ///________________________________________________________________________________
158 TObject * AliEveEventBuffer::GetNextUnSeen() {
159 //See header file for documentation
160 cout << "GetNextUnSeen"<<endl;
162 if(CalculateDifference(fBIndex[kTop], fBIndex[kLast])) {
163 fBIndex[kLast] = CalculateNext(fBIndex[kLast]);
164 fBIndex[kCurrent] = fBIndex[kLast];
166 return fEventBuffer->At(fBIndex[kCurrent]);
168 cout << "No new event available, only events in buffer available!"<<endl;
172 ///_________________________________________________________________________________
173 void AliEveEventBuffer::PrintIndeces() {
174 for(Int_t i = 0; i < kSize; i++) {
175 cout << i << ": " << fBIndex[i] << endl;
178 ///_________________________________________________________________________________
179 void AliEveEventBuffer::PrintBuffer() {
180 for(Int_t i = 0; i < 10; i++) {
181 AliESDEvent * event = dynamic_cast<AliESDEvent*>(fEventBuffer->At(i));
183 cout << i << ": " <<event << " " << event->GetEventNumberInFile() << endl;;
188 ///____________________________________________________________________________________
189 void AliEveEventBuffer::FetchEvent() {
190 cout << "FetchEvent " << endl;
191 TObject * event = GetEventFromSource();
192 ULong64_t eventId = GetEventIdFromSource();
195 fEventId[fBIndex[kTop]] = eventId;
199 cout << "FetchedEvent " << endl;
203 ///_________________________________________________________________________________
204 void AliEveEventBuffer::AddToBuffer(TObject * event) {
205 cout << "Add to buffer"<<endl;
208 fBIndex[kTop] = CalculateNext(fBIndex[kTop]);
209 //Delete the event already there (ok to delete as object, not aliesdevent, TList?)
210 //TObject * object = fEventBuffer->At(fBIndex[kTop]);
211 fEventBuffer->RemoveAt(fBIndex[kTop]);
212 //if (object) delete object;
213 fEventBuffer->AddAt(event, fBIndex[kTop]);
217 ///_____________________________________________________________________________________
218 Int_t AliEveEventBuffer::CalculateNext(Int_t current) {
219 //See header file for documentation
221 if(current == fBufferSize) current = 0;
226 ///_____________________________________________________________________________________
227 Int_t AliEveEventBuffer::CalculatePrevious(Int_t current) {
228 //See header file for documentation
229 cout << "CalculatePrev: " << current;
231 if(current == -1) current += fBufferSize;
232 cout << "... " << current << endl;
236 ///__________________________________________________________________________________
237 Int_t AliEveEventBuffer::CalculateDifference(Int_t top, Int_t low) {
238 //See header file for documentation
240 // cout << "top > low"<<endl;
242 } else if (top < low) {
243 // cout << "low < top"<<endl;
244 return (fBufferSize - low + top);
246 //cout << "calculated to 0"<<endl;
251 ///___________________________________________________________________________________
252 void AliEveEventBuffer::StartBufferMonitor() {
253 //cout << "NOT !!! starting buffer mon"<<endl;
254 cout << "starting buffer mon"<<endl;
255 CreateBufferThread();
256 SetBufferMonStarted(kTRUE);
259 ///___________________________________________________________________________________
260 void AliEveEventBuffer::StopBufferMonitor() {
261 cout << "Stopping buffer mon"<<endl;
262 SetBufferMonStarted(kFALSE);
267 // //_________________________________________________________________________________
268 // Int_t AliEveEventBuffer::NavigateEventBufferBack() {
269 // // see header file for class documentation
271 // // -- reached the end of the buffer
272 // if ( fNavigateBufferIdx == fBufferLowIdx )
275 // Int_t newIdx = fNavigateBufferIdx - 1;
276 // if ( newIdx == -1 )
277 // newIdx = BUFFERSIZE-1;
279 // fCurrentBufferIdx = fNavigateBufferIdx = newIdx;
284 // //_______________________________________________________________
285 // Int_t AliEveEventBuffer::NavigateEventBufferFwd() {
286 // // see header file for class documentation
288 // // -- reached the top of the buffer
289 // if ( fNavigateBufferIdx == fBufferTopIdx )
292 // Int_t newIdx = fNavigateBufferIdx + 1;
293 // if ( newIdx == BUFFERSIZE )
296 // fCurrentBufferIdx = fNavigateBufferIdx = newIdx;
301 // void AliEveEventBuffer::MonitorBuffer() {
302 // //See header file for documentation
303 // if( GetNAvailableEvents() < 10) {
304 // StopBufferChecker();
309 // void AliEveEventBuffer::StartLoop() {
310 // //See header file for documentation
311 // fTimer->Start(2000);
313 // void AliEveEventBuffer::StopLoop() {
314 // //See header file for documentation
318 // void AliEveEventBuffer::StartBufferChecker() {
319 // //See header file for documentation
320 // fBufferTimer->Start(2000);
322 // void AliEveEventBuffer::StopBufferChecker() {
323 // //See header file for documentation
324 // fBufferTimer->Stop();
327 // AliESDEvent * GetNextEvent() {
329 // tree->GetEntry(fEvent++);
331 // AliESDEvent * event = new AliESDEvent();
332 // event->ReadFromTree(fTree);
336 // cout << "error getting event" << endl;