6 #include "AliEveEventBuffer.h"
9 //Not needed, only for debug
10 #include "AliESDEvent.h"
14 ClassImp(AliEveEventBuffer)
16 ///_______________________________________________________________________
17 AliEveEventBuffer::AliEveEventBuffer() :
27 fBufferMonStarted(kFALSE)
29 // see header file for class documentation
30 fEventBuffer = new TObjArray(10, 0);
31 fEventBuffer->SetOwner(kTRUE);
33 for(int id = 0; id < kSize; id++) {
37 fTimer = new TTimer();
38 fTimer->Connect("Timeout()", "AliEveEventBuffer", this, "MonitorBuffer()");
40 fEventId = new Int_t[fBufferSize];
47 ///_______________________________________________________________________
48 AliEveEventBuffer::~AliEveEventBuffer() {
49 // see header file for class documentation
52 fEventBuffer->Clear();
63 ///___________________________________________________________________________
64 void * AliEveEventBuffer::BufferThread(void * buffer) {
66 if (!reinterpret_cast<AliEveEventBuffer*>(buffer)->GetBufferMonStarted()) {
67 reinterpret_cast<AliEveEventBuffer*>(buffer)->StartBufferMonitor();
73 ///_____________________________________________________________________________
74 void AliEveEventBuffer::MonitorBuffer() {
75 cout << "Monitorbuffer: " << endl;
77 cout << "Already called FetchEvent()" << endl;
80 cout << "fbusy = false"<<endl;
82 if ( (CalculateDifference(fBIndex[kTop],fBIndex[kLast]) < fPreBuffer) ) {
87 //StopBufferMonitor();
93 ///_______________________________________________________________________________
94 TObject * AliEveEventBuffer::NextEvent() {
95 //See header file for documentation
97 cout << "Event Buffer busy"<<endl;
101 cout << "In enxtevent"<<endl;
102 TObject * nextEvent = GetNextUnSeen();
107 ///______________________________________________________________________________
108 TObject * AliEveEventBuffer::Back() {
109 cout << "go back"<<endl;
111 Int_t prevId = CalculatePrevious(fBIndex[kCurrent]);
112 if(prevId == fBIndex[kTop]) {
113 cout << "returning NULL" << endl;
116 fBIndex[kCurrent] = prevId;
118 cout <<"returning: "<< fBIndex[kCurrent] << " " << fEventBuffer->At(fBIndex[kCurrent]);
119 return fEventBuffer->At(fBIndex[kCurrent]);
123 ///______________________________________________________________________________
124 TObject * AliEveEventBuffer::Fwd() {
126 if (fBIndex[kCurrent] == fBIndex[kLast]) {
127 cout<< "returning NULL"<<endl;
131 fBIndex[kCurrent] = CalculateNext(fBIndex[kCurrent]);
132 TObject * event = fEventBuffer->At(fBIndex[kCurrent]);
138 ///________________________________________________________________________________
139 TObject * AliEveEventBuffer::GetNextUnSeen() {
140 //See header file for documentation
141 cout << "GetNextUnSeend"<<endl;
143 if(CalculateDifference(fBIndex[kTop], fBIndex[kLast])) {
144 fBIndex[kLast] = CalculateNext(fBIndex[kLast]);
145 fBIndex[kCurrent] = fBIndex[kLast];
147 return fEventBuffer->At(fBIndex[kCurrent]);
149 cout << "No new event available, only events in buffer available!"<<endl;
153 ///_________________________________________________________________________________
154 void AliEveEventBuffer::PrintIndeces() {
155 for(Int_t i = 0; i < kSize; i++) {
156 cout << i << ": " << fBIndex[i] << endl;
159 ///_________________________________________________________________________________
160 void AliEveEventBuffer::PrintBuffer() {
161 for(Int_t i = 0; i < 10; i++) {
162 AliESDEvent * event = dynamic_cast<AliESDEvent*>(fEventBuffer->At(i));
164 cout << i << ": " <<event << " " << event->GetEventNumberInFile() << endl;;
169 ///____________________________________________________________________________________
170 void AliEveEventBuffer::FetchEvent() {
171 cout << "FetchEvent " << endl;
172 TObject * event = GetEventFromSource();
173 if(event) AddToBuffer(event);
175 cout << "FetchedEvent " << endl;
179 ///_________________________________________________________________________________
180 void AliEveEventBuffer::AddToBuffer(TObject * event) {
181 cout << "Add to buffer"<<endl;
184 fBIndex[kTop] = CalculateNext(fBIndex[kTop]);
185 //Delete the event already there (ok to delete as object, not aliesdevent, TList?)
186 TObject * object = fEventBuffer->At(fBIndex[kTop]);
187 if (object) delete object;
188 fEventBuffer->AddAt(event, fBIndex[kTop]);
193 ///_____________________________________________________________________________________
194 Int_t AliEveEventBuffer::CalculateNext(Int_t current) {
195 //See header file for documentation
197 if(current == fBufferSize) current = 0;
202 ///_____________________________________________________________________________________
203 Int_t AliEveEventBuffer::CalculatePrevious(Int_t current) {
204 //See header file for documentation
205 cout << "CalculatePrev: " << current;
207 if(current == -1) current += fBufferSize;
208 cout << "... " << current << endl;
212 ///__________________________________________________________________________________
213 Int_t AliEveEventBuffer::CalculateDifference(Int_t top, Int_t low) {
214 //See header file for documentation
216 // cout << "top > low"<<endl;
218 } else if (top < low) {
219 // cout << "low < top"<<endl;
220 return (fBufferSize - low + top);
222 //cout << "calculated to 0"<<endl;
227 ///___________________________________________________________________________________
228 void AliEveEventBuffer::StartBufferMonitor() {
229 //cout << "NOT !!! starting buffer mon"<<endl;
230 cout << "starting buffer mon"<<endl;
233 ///___________________________________________________________________________________
234 void AliEveEventBuffer::StopBufferMonitor() {
235 cout << "Stopping buffer mon"<<endl;
240 // //_________________________________________________________________________________
241 // Int_t AliEveEventBuffer::NavigateEventBufferBack() {
242 // // see header file for class documentation
244 // // -- reached the end of the buffer
245 // if ( fNavigateBufferIdx == fBufferLowIdx )
248 // Int_t newIdx = fNavigateBufferIdx - 1;
249 // if ( newIdx == -1 )
250 // newIdx = BUFFERSIZE-1;
252 // fCurrentBufferIdx = fNavigateBufferIdx = newIdx;
257 // //_______________________________________________________________
258 // Int_t AliEveEventBuffer::NavigateEventBufferFwd() {
259 // // see header file for class documentation
261 // // -- reached the top of the buffer
262 // if ( fNavigateBufferIdx == fBufferTopIdx )
265 // Int_t newIdx = fNavigateBufferIdx + 1;
266 // if ( newIdx == BUFFERSIZE )
269 // fCurrentBufferIdx = fNavigateBufferIdx = newIdx;
274 // void AliEveEventBuffer::MonitorBuffer() {
275 // //See header file for documentation
276 // if( GetNAvailableEvents() < 10) {
277 // StopBufferChecker();
282 // void AliEveEventBuffer::StartLoop() {
283 // //See header file for documentation
284 // fTimer->Start(2000);
286 // void AliEveEventBuffer::StopLoop() {
287 // //See header file for documentation
291 // void AliEveEventBuffer::StartBufferChecker() {
292 // //See header file for documentation
293 // fBufferTimer->Start(2000);
295 // void AliEveEventBuffer::StopBufferChecker() {
296 // //See header file for documentation
297 // fBufferTimer->Stop();
300 // AliESDEvent * GetNextEvent() {
302 // tree->GetEntry(fEvent++);
304 // AliESDEvent * event = new AliESDEvent();
305 // event->ReadFromTree(fTree);
309 // cout << "error getting event" << endl;