-Fixed bug in offline buffer that deleted event object.
[u/mrichter/AliRoot.git] / EVE / EveHLT / AliEveHLTEventManager.cxx
CommitLineData
30e7579c 1#include "TEveManager.h"
2#include "TEveScene.h"
3#include "TEveProjectionManager.h"
4#include "TEveBrowser.h"
5#include "TGLViewer.h"
6#include "TEveViewer.h"
7#include "TEveEventManager.h"
8
9//#include "AliHLTTriggerDecision.h"
10#include "AliHLTEvePhos.h"
11#include "AliHLTEveEmcal.h"
12#include "AliHLTEveTPC.h"
13#include "AliHLTEveHLT.h"
14#include "AliHLTEveITS.h"
15#include "AliHLTEveISPD.h"
16#include "AliHLTEveISSD.h"
17#include "AliHLTEveISDD.h"
18#include "AliHLTEveTRD.h"
19#include "AliHLTEveMuon.h"
20#include "AliHLTEveAny.h"
21
22#include "AliEveHLTEventManager.h"
23#include "AliEveHOMERManager.h"
24#include "AliEveEventBuffer.h"
25
26#include "TList.h"
27#include "TTimer.h"
28
29#include "TThread.h"
30
31ClassImp(AliEveHLTEventManager);
32
33AliEveHLTEventManager::AliEveHLTEventManager() :
34 TEveElementList("Event Manager"),
35 fGeoManager(NULL),
36 fEveManager(NULL),
37 fRPhiManager(NULL),
38 fRhoZManager(NULL),
39 fRPhiEventScene(NULL),
40 fRhoZEventScene(NULL),
41 fRhoZViewer(NULL),
42 fRPhiViewer(NULL),
43 fTimer(NULL),
44 fPhosElement(NULL),
45 fEmcalElement(NULL),
46 fTPCElement(NULL),
47 fHLTElement(NULL),
48 fITSElement(NULL),
49 fISPDElement(NULL),
50 fISSDElement(NULL),
51 fISDDElement(NULL),
52 fTRDElement(NULL),
53 fMuonElement(NULL),
54 fAnyElement(NULL),
55 fEventLoopStarted(kFALSE),
56 fCenterProjectionsAtPrimaryVertex(kFALSE),
57 fShowBarrel(kTRUE),
58 fShowMuon(kFALSE),
59 fRunNumber(-1)
60{
61 // see header file for class documentation
62 // or
63 // refer to README to build package
64 // or
65 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
66
67 fTimer = new TTimer();
68 fTimer->Connect("Timeout()", "AliEveHLTEventManager", this, "NextEvent()" );
69
70}
71
72AliEveHLTEventManager::~AliEveHLTEventManager() {
73
74 //DestroyElements();
75 //DestroyDetectorElements();
76
77}
78
79
80void AliEveHLTEventManager::DestroyDetectorElements(){
81 //See header file for documentation
82
83 if (fPhosElement)
84 delete fPhosElement;
85 fPhosElement = NULL;
86
87 if(fEmcalElement)
88 delete fEmcalElement;
89 fEmcalElement = NULL;
90
91 if(fTPCElement)
92 delete fTPCElement;
93 fTPCElement = NULL;
94
95 if(fHLTElement)
96 delete fHLTElement;
97 fHLTElement = NULL;
98
99 if(fITSElement)
100 delete fITSElement;
101 fITSElement = NULL;
102
103 if(fISSDElement)
104 delete fISSDElement;
105 fISSDElement = NULL;
106
107 if(fISDDElement)
108 delete fISDDElement;
109 fISDDElement = NULL;
110
111 if(fISPDElement)
112 delete fISPDElement;
113 fISPDElement = NULL;
114
115 if(fTRDElement)
116 delete fTRDElement;
117 fTRDElement = NULL;
118
119 if(fMuonElement)
120 delete fMuonElement;
121 fMuonElement = NULL;
122
123 if(fAnyElement)
124 delete fAnyElement;
125 fAnyElement = NULL;
126
127
128}
239fdf4e 129
30e7579c 130///_______________________________________________________________________________________
131void AliEveHLTEventManager::ConnectEventBuffer() {
132 GetEventBuffer()->ConnectToSource();
133}
134
135
136///___________________________________________________________________________________________
137void AliEveHLTEventManager::StartBufferMonitor() {
138 AliEveEventBuffer * buffer = GetEventBuffer();
239fdf4e 139 buffer->StartBufferMonitor();
30e7579c 140}
239fdf4e 141
30e7579c 142//______________________________________________________________________________________________
143Int_t AliEveHLTEventManager::ProcessEvent(AliESDEvent * event) {
144
145 //We have a new event, reset display items (need to check if there really is anything interesting in event before resetting. ie not just histos)
b088c0a1 146
147 gEve->DisableRedraw();
148
30e7579c 149
150 cout << "reset()"<<endl;
151
152 ResetDisplay();
153
154 cout << "process()"<<endl;
155 if(!fHLTElement) {
156 fHLTElement = new AliHLTEveHLT();
157 fHLTElement->SetEventManager(this);
158 gEve->AddElement(fHLTElement);
159 }
160 fHLTElement->ProcessEsdEvent(event);
161
162 if(!fPhosElement) CreatePhosElement();
163 fPhosElement->ProcessEvent(event);
164
165 if(!fEmcalElement) CreateEmcalElement();
166 fEmcalElement->ProcessEvent(event);
167
168 cout << "update()"<<endl;
169 UpdateDisplay();
170
b088c0a1 171 gEve->Redraw3D(0, 1);
172 gEve->EnableRedraw();
173
30e7579c 174 return 0;
175
176}
177
178
179
180//______________________________________________________________________________________________
181Int_t AliEveHLTEventManager::ProcessEvent(TList * blockList) {
182
183 //We have a new event, reset display items (need to check if there really is anything interesting in event before resetting. ie not just histos)
184
185 if(!blockList) {
186 cout << "Block list is NULL pointer, return " << endl;
187 return -1;
188 }
189
190 cout << "reset ()"<<endl;
191 ResetDisplay();
192 cout << "done reset()"<<endl;
193 AliHLTHOMERBlockDesc * block = NULL;
194 TIter next(blockList);
195 while ((block = (AliHLTHOMERBlockDesc*)next())) {
196 cout <<"Process Block"<<endl;
197 ProcessBlock(block);
198 }
199
200 cout << "update() "<<endl;
201 UpdateDisplay();
202
203 return 0;
204
205}
239fdf4e 206///___________________________________________________________________________________________
30e7579c 207
208void AliEveHLTEventManager::ProcessBlock(AliHLTHOMERBlockDesc * block) {
209 //See header file for documentation
210
211#if 1//DEBUG
212 printf( "------------------- xxxxxxxxxxxxxxx ----------------------\n");
213 printf( "Detector : %s\n", block->GetDetector().Data() );
214 printf( "Datatype : %s\n", block->GetDataType().Data() );
215 if (block->IsTObject() )
216 printf( "Is TObject of class: %s\n", block->GetClassName().Data() );
217 printf( "------------------- xxxxxxxxxxxxxxx ----------------------\n");
218#endif
219
220
221 if(fShowBarrel) {
222
223 if ( ! block->GetDetector().CompareTo("PHOS") ) {
224 if(!fPhosElement) CreatePhosElement();
225 fPhosElement->ProcessBlock(block);
226 }
227
228 else if ( ! block->GetDetector().CompareTo("EMCA") ) {
229 if(!fEmcalElement) CreateEmcalElement();
230 fEmcalElement->ProcessBlock(block);
231 }
232
233 else if ( ! block->GetDetector().CompareTo("TPC") ) {
234 if(!fTPCElement) CreateTPCElement();
235 fTPCElement->ProcessBlock(block);
236 }
237
238 else if ( ! block->GetDetector().CompareTo("HLT") ) {
239 if(!fHLTElement) CreateHLTElement();
240 fHLTElement->ProcessBlock(block);
241 }
242
243 else if ( ! block->GetDetector().CompareTo("ITS") ) {
244 if(!fITSElement) CreateITSElement();
245 fITSElement->ProcessBlock(block);
246 }
247
248 else if ( ! block->GetDetector().CompareTo("ISDD") ) {
249 if(!fISDDElement) CreateISDDElement();
250 fISDDElement->ProcessBlock(block);
251 }
252
253 else if ( ! block->GetDetector().CompareTo("ISPD") ) {
254 if(!fISPDElement) CreateISPDElement();
255 fISPDElement->ProcessBlock(block);
256 }
257
258 else if ( ! block->GetDetector().CompareTo("ISSD") ) {
259 if(!fISSDElement) CreateISSDElement();
260 fISSDElement->ProcessBlock(block);
261 }
262
263 else if ( ! block->GetDetector().CompareTo("TRD") ) {
264 if(!fTRDElement) CreateTRDElement();
265 fTRDElement->ProcessBlock(block);
266 }
267
268 else if ( ! block->GetDetector().CompareTo("MUON") ) {
269 //Do Nothing
270 } else {
271 if(!fAnyElement) {
272 fAnyElement = new AliHLTEveAny();
273 fAnyElement->SetEventManager(this);
274 }
275 fAnyElement->ProcessBlock(block);
276 }
277
278 }
279
280
281 if(fShowMuon) {
282 if ( ! block->GetDetector().CompareTo("MUON") ) {
283 if(!fMuonElement) {
284 fMuonElement = new AliHLTEveMuon();
285 fMuonElement->SetEventManager(this);
286 gEve->AddElement(fMuonElement);
287 }
288 fMuonElement->ProcessBlock(block);
289 }
290 }
291
292}
293
294void AliEveHLTEventManager::ResetDisplay () {
295 //See header file for documentation
296
297 if(fPhosElement)
298 fPhosElement->ResetElements();
299
300 if(fEmcalElement)
301 fEmcalElement->ResetElements();
302
303 if(fTPCElement)
304 fTPCElement->ResetElements();
305
306 if(fHLTElement)
307 fHLTElement->ResetElements();
308
309 if(fITSElement)
310 fITSElement->ResetElements();
311
312 if(fISPDElement)
313 fISPDElement->ResetElements();
314
315 if(fISDDElement)
316 fISDDElement->ResetElements();
317
318 if(fISSDElement)
319 fISSDElement->ResetElements();
320
321 if (fTRDElement)
322 fTRDElement->ResetElements();
323
324 if(fAnyElement)
325 fAnyElement->ResetElements();
326
327 if(fMuonElement)
328 fMuonElement->ResetElements();
329
330}
331
332
333void AliEveHLTEventManager::PrintScreens() {
334// //See header file for documentation
335
336// fEveManager->GetDefaultGLViewer()->SavePicture(Form("%d_0x%lu_3D.gif", fRunNumber, GetEventID(fCurrentEventIdx)));
337// fRhoZViewer->GetGLViewer()->SavePicture(Form("%d_0x%lu_RhoZ.gif", fRunNumber, GetEventID(fCurrentEventIdx)));
338// fRPhiViewer->GetGLViewer()->SavePicture(Form("%d_0x%lu_RPhi.gif", fRunNumber, GetEventID(fCurrentEventIdx)));
339 return;
340}
341
342
343void AliEveHLTEventManager::StartLoop() {
344 //See header file for documentation
345 //fTimer->SetCommand("NextEvent()", "AliEveHLTEventManager", this);
346 SetEventLoopStarted(kTRUE);
347 fTimer->Start(10000);
348}
349
350void AliEveHLTEventManager::StopLoop() {
351 //See header file for documentation
352 fTimer->Stop();
353 SetEventLoopStarted(kFALSE);
354}
355
356
357// void AliEveHLTEventManager::NavigateBack() {
358
359// if (fHomerManager->NavigateEventBufferBack()) {
360// //return -1;
361// } else {
362
363// TList * blockList = fHomerManager->GetBlockList();
364// if(blockList) {
365// ProcessEvent(blockList);
366// } else {
367// cout << "BALLE Error blocklist NULL pointer even though it's navigateable"<<endl;
368// }
369// }
370
371// }
372
373// void AliEveHLTEventManager::NavigateFwd() {
374
375// if (fHomerManager->NavigateEventBufferFwd()) {
376// cout << "No event available" << endl;
377// return;
378// //return -1;
379// } else {
380// cout << "Getting block list" << endl;
381// TList * blockList = fHomerManager->GetBlockList();
382// if (blockList){
383// ProcessEvent(blockList);
384// } else {
385// cout << "blockList is NULL pointer"<<endl;
386// }
387// }
388
389// }
390
391void AliEveHLTEventManager::UpdateDisplay() {
392 //See header file for documentation
393 if(fPhosElement) fPhosElement->UpdateElements();
394 if(fEmcalElement) fEmcalElement->UpdateElements();
395 if(fTPCElement) fTPCElement->UpdateElements();
396 if(fHLTElement) fHLTElement->UpdateElements();
397 if(fITSElement) fITSElement->UpdateElements();
398 if(fISSDElement) fISSDElement->UpdateElements();
399 if(fISDDElement) fISDDElement->UpdateElements();
400 if(fISPDElement) fISPDElement->UpdateElements();
401 if(fTRDElement) fTRDElement->UpdateElements();
402 if(fAnyElement) fAnyElement->UpdateElements();
403 if(fMuonElement) fMuonElement->UpdateElements();
404
405
406 // -- Set EventID in Window Title
407 TString winTitle("Eve Main Window");
408 winTitle += Form("-- Run Number: %d", fRunNumber);
409 //winTitle += Form("-- Event ID : 0x%lu ", GetEventID(fCurrentEventIdx) );
410 GetEveManager()->GetBrowser()->SetWindowName(winTitle);
411
412 //==============================================================================
413 // -- Import global scene into projection scenes
414 //==============================================================================
415
416 Double_t x[3] = { 0, 0, 0 };
417
418 TEveElement* top = GetEveManager()->GetCurrentEvent();
419
420 if (fRPhiManager && top) {
421 fRPhiEventScene->DestroyElements();
422 if (fCenterProjectionsAtPrimaryVertex)
423 fRPhiManager->SetCenter(x[0], x[1], x[2]);
424 fRPhiManager->ImportElements(top, fRPhiEventScene);
425 }
426
427 if (fRhoZManager && top) {
428 fRhoZEventScene->DestroyElements();
429 if (fCenterProjectionsAtPrimaryVertex)
430 fRhoZManager->SetCenter(x[0], x[1], x[2]);
431 fRhoZManager->ImportElements(top, fRhoZEventScene);
432 }
433
434
435 //Redraw the display
436 GetEveManager()->Redraw3D(0,1); // (0, 1)
437 GetEveManager()->EnableRedraw();
438
439}
440
441void AliEveHLTEventManager::SaveEveryThing() {
442
443 GetEventBuffer()->WriteToFile();
444 //Save everything to file
445 //fEventBuffer->SaveBlockList();
446 //fEventBuffer->SaveAsyncBlockList();
447
448
449}
450
451
452
453void AliEveHLTEventManager::CreatePhosElement() {
454 fPhosElement = new AliHLTEvePhos();
455 fPhosElement->SetEventManager(this);
456 gEve->AddElement(fPhosElement);
457}
458
459void AliEveHLTEventManager::CreateEmcalElement() {
460 fEmcalElement = new AliHLTEveEmcal();
461 fEmcalElement->SetEventManager(this);
462 gEve->AddElement(fEmcalElement);
463}
464void AliEveHLTEventManager::CreateTPCElement() {
465 fTPCElement = new AliHLTEveTPC();
466 fTPCElement->SetEventManager(this);
467 gEve->AddElement(fTPCElement);
468}
469void AliEveHLTEventManager::CreateITSElement() {
470 fITSElement = new AliHLTEveITS();
471 fITSElement->SetEventManager(this);
472 gEve->AddElement(fITSElement);
473}
474void AliEveHLTEventManager::CreateISPDElement() {
475 fISPDElement = new AliHLTEveISPD();
476 fISPDElement->SetEventManager(this);
477 gEve->AddElement(fISPDElement);
478}
479void AliEveHLTEventManager::CreateISDDElement() {
480 fISDDElement = new AliHLTEveISDD();
481 fISDDElement->SetEventManager(this);
482 gEve->AddElement(fISSDElement);
483}
484void AliEveHLTEventManager::CreateISSDElement() {
485 fISSDElement = new AliHLTEveISSD();
486 fISSDElement->SetEventManager(this);
487 gEve->AddElement(fISSDElement);
488}
489void AliEveHLTEventManager::CreateTRDElement() {
490 fTRDElement = new AliHLTEveTRD();
491 fTRDElement->SetEventManager(this);
492 gEve->AddElement(fTRDElement);
493}
494void AliEveHLTEventManager::CreateHLTElement() {
495 fHLTElement = new AliHLTEveHLT();
496 fHLTElement->SetEventManager(this);
497 gEve->AddElement(fHLTElement);
498}
499
500