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;
70 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() ";
98 cout << "done " << endl;
102 ///_______________________________________________________________________________
103 TObject * AliEveEventBuffer::NextEvent() {
104 //See header file for documentation
105 cout << "NextEvent()"<<endl;
106 TObject * nextEvent = GetNextUnSeen();
110 ///______________________________________________________________________________
111 TObject * AliEveEventBuffer::Back() {
112 cout << "go back"<<endl;
114 Int_t prevId = CalculatePrevious(fBIndex[kCurrent]);
115 if(prevId == fBIndex[kTop]) {
116 cout << "returning NULL" << endl;
119 fBIndex[kCurrent] = prevId;
121 cout <<"returning: "<< fBIndex[kCurrent] << " " << fEventBuffer->At(fBIndex[kCurrent]);
122 return fEventBuffer->At(fBIndex[kCurrent]);
128 ///______________________________________________________________________________
129 TObject * AliEveEventBuffer::Fwd() {
131 if (fBIndex[kCurrent] == fBIndex[kLast]) {
132 cout<< "returning NULL"<<endl;
136 fBIndex[kCurrent] = CalculateNext(fBIndex[kCurrent]);
137 TObject * event = fEventBuffer->At(fBIndex[kCurrent]);
143 ///________________________________________________________________________________
144 TObject * AliEveEventBuffer::GetNextUnSeen() {
145 //See header file for documentation
146 cout << "GetNextUnSeen"<<endl;
148 if(CalculateDifference(fBIndex[kTop], fBIndex[kLast])) {
149 fBIndex[kLast] = CalculateNext(fBIndex[kLast]);
150 fBIndex[kCurrent] = fBIndex[kLast];
152 return fEventBuffer->At(fBIndex[kCurrent]);
154 cout << "No new event available, only events in buffer available!"<<endl;
158 ///_________________________________________________________________________________
159 void AliEveEventBuffer::PrintIndeces() {
160 for(Int_t i = 0; i < kSize; i++) {
161 cout << i << ": " << fBIndex[i] << endl;
164 ///_________________________________________________________________________________
165 void AliEveEventBuffer::PrintBuffer() {
166 for(Int_t i = 0; i < 10; i++) {
167 AliESDEvent * event = dynamic_cast<AliESDEvent*>(fEventBuffer->At(i));
169 cout << i << ": " <<event << " " << event->GetEventNumberInFile() << endl;;
174 ///____________________________________________________________________________________
175 void AliEveEventBuffer::FetchEvent() {
176 cout << "FetchEvent " << endl;
177 TObject * event = GetEventFromSource();
178 ULong64_t eventId = GetEventIdFromSource();
181 fEventId[fBIndex[kTop]] = eventId;
185 cout << "FetchedEvent " << endl;
189 ///_________________________________________________________________________________
190 void AliEveEventBuffer::AddToBuffer(TObject * event) {
191 cout << "Add to buffer"<<endl;
194 fBIndex[kTop] = CalculateNext(fBIndex[kTop]);
195 //Delete the event already there (ok to delete as object, not aliesdevent, TList?)
196 //TObject * object = fEventBuffer->At(fBIndex[kTop]);
197 fEventBuffer->RemoveAt(fBIndex[kTop]);
198 //if (object) delete object;
199 fEventBuffer->AddAt(event, fBIndex[kTop]);
203 ///_____________________________________________________________________________________
204 Int_t AliEveEventBuffer::CalculateNext(Int_t current) {
205 //See header file for documentation
207 if(current == fBufferSize) current = 0;
212 ///_____________________________________________________________________________________
213 Int_t AliEveEventBuffer::CalculatePrevious(Int_t current) {
214 //See header file for documentation
215 cout << "CalculatePrev: " << current;
217 if(current == -1) current += fBufferSize;
218 cout << "... " << current << endl;
222 ///__________________________________________________________________________________
223 Int_t AliEveEventBuffer::CalculateDifference(Int_t top, Int_t low) {
224 //See header file for documentation
226 // cout << "top > low"<<endl;
228 } else if (top < low) {
229 // cout << "low < top"<<endl;
230 return (fBufferSize - low + top);
232 //cout << "calculated to 0"<<endl;
237 ///___________________________________________________________________________________
238 void AliEveEventBuffer::StartBufferMonitor() {
239 //cout << "NOT !!! starting buffer mon"<<endl;
240 cout << "starting buffer mon"<<endl;
241 if(!GetBufferMonStarted()) {
242 CreateBufferThread();
243 SetBufferMonStarted(kTRUE);
246 cout << "Stopping buffer monitor"<<endl;
248 SetBufferMonStarted(kFALSE);
251 ///___________________________________________________________________________________
252 void AliEveEventBuffer::StopBufferMonitor() {
253 cout << "Stopping buffer mon"<<endl;
254 SetBufferMonStarted(kFALSE);
259 // //_________________________________________________________________________________
260 // Int_t AliEveEventBuffer::NavigateEventBufferBack() {
261 // // see header file for class documentation
263 // // -- reached the end of the buffer
264 // if ( fNavigateBufferIdx == fBufferLowIdx )
267 // Int_t newIdx = fNavigateBufferIdx - 1;
268 // if ( newIdx == -1 )
269 // newIdx = BUFFERSIZE-1;
271 // fCurrentBufferIdx = fNavigateBufferIdx = newIdx;
276 // //_______________________________________________________________
277 // Int_t AliEveEventBuffer::NavigateEventBufferFwd() {
278 // // see header file for class documentation
280 // // -- reached the top of the buffer
281 // if ( fNavigateBufferIdx == fBufferTopIdx )
284 // Int_t newIdx = fNavigateBufferIdx + 1;
285 // if ( newIdx == BUFFERSIZE )
288 // fCurrentBufferIdx = fNavigateBufferIdx = newIdx;
293 // void AliEveEventBuffer::MonitorBuffer() {
294 // //See header file for documentation
295 // if( GetNAvailableEvents() < 10) {
296 // StopBufferChecker();
301 // void AliEveEventBuffer::StartLoop() {
302 // //See header file for documentation
303 // fTimer->Start(2000);
305 // void AliEveEventBuffer::StopLoop() {
306 // //See header file for documentation
310 // void AliEveEventBuffer::StartBufferChecker() {
311 // //See header file for documentation
312 // fBufferTimer->Start(2000);
314 // void AliEveEventBuffer::StopBufferChecker() {
315 // //See header file for documentation
316 // fBufferTimer->Stop();
319 // AliESDEvent * GetNextEvent() {
321 // tree->GetEntry(fEvent++);
323 // AliESDEvent * event = new AliESDEvent();
324 // event->ReadFromTree(fTree);
328 // cout << "error getting event" << endl;