bugfix: display reset before all block, not esd even block
[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
30e7579c 9#include "AliHLTEvePhos.h"
10#include "AliHLTEveEmcal.h"
11#include "AliHLTEveTPC.h"
12#include "AliHLTEveHLT.h"
13#include "AliHLTEveITS.h"
14#include "AliHLTEveISPD.h"
15#include "AliHLTEveISSD.h"
16#include "AliHLTEveISDD.h"
17#include "AliHLTEveTRD.h"
18#include "AliHLTEveMuon.h"
19#include "AliHLTEveAny.h"
20
21#include "AliEveHLTEventManager.h"
22#include "AliEveHOMERManager.h"
23#include "AliEveEventBuffer.h"
24
25#include "TList.h"
26#include "TTimer.h"
27
28#include "TThread.h"
29
30ClassImp(AliEveHLTEventManager);
31
32AliEveHLTEventManager::AliEveHLTEventManager() :
33 TEveElementList("Event Manager"),
34 fGeoManager(NULL),
35 fEveManager(NULL),
36 fRPhiManager(NULL),
37 fRhoZManager(NULL),
38 fRPhiEventScene(NULL),
39 fRhoZEventScene(NULL),
40 fRhoZViewer(NULL),
41 fRPhiViewer(NULL),
42 fTimer(NULL),
43 fPhosElement(NULL),
44 fEmcalElement(NULL),
45 fTPCElement(NULL),
46 fHLTElement(NULL),
47 fITSElement(NULL),
48 fISPDElement(NULL),
49 fISSDElement(NULL),
50 fISDDElement(NULL),
51 fTRDElement(NULL),
52 fMuonElement(NULL),
53 fAnyElement(NULL),
54 fEventLoopStarted(kFALSE),
55 fCenterProjectionsAtPrimaryVertex(kFALSE),
56 fShowBarrel(kTRUE),
57 fShowMuon(kFALSE),
cc87822c 58 fRunNumber(-1),
59 fEventId(-1)
30e7579c 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
8676f4b1 149 // -- Set EventID in Window Title
150 TString winTitle("Eve Main Window");
cc87822c 151 SetRunNumber(event->GetRunNumber());
152 SetEventId(GetEventBuffer()->GetEventId());
153 winTitle += Form("-- Run Number: %d", GetRunNumber());
154 winTitle += Form("-- Event ID : 0x%016lX ", GetEventId() );
8676f4b1 155 GetEveManager()->GetBrowser()->SetWindowName(winTitle);
156
157
30e7579c 158
159 cout << "reset()"<<endl;
160
30e7579c 161 cout << "process()"<<endl;
162 if(!fHLTElement) {
163 fHLTElement = new AliHLTEveHLT();
164 fHLTElement->SetEventManager(this);
165 gEve->AddElement(fHLTElement);
166 }
167 fHLTElement->ProcessEsdEvent(event);
168
169 if(!fPhosElement) CreatePhosElement();
170 fPhosElement->ProcessEvent(event);
171
172 if(!fEmcalElement) CreateEmcalElement();
173 fEmcalElement->ProcessEvent(event);
30e7579c 174
b088c0a1 175 gEve->Redraw3D(0, 1);
176 gEve->EnableRedraw();
177
30e7579c 178 return 0;
179
180}
181
182
183
184//______________________________________________________________________________________________
185Int_t AliEveHLTEventManager::ProcessEvent(TList * blockList) {
186
187 //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)
188
189 if(!blockList) {
190 cout << "Block list is NULL pointer, return " << endl;
191 return -1;
192 }
193
d5bb2040 194
195 ResetDisplay();
196
197
30e7579c 198 AliHLTHOMERBlockDesc * block = NULL;
199 TIter next(blockList);
200 while ((block = (AliHLTHOMERBlockDesc*)next())) {
201 cout <<"Process Block"<<endl;
202 ProcessBlock(block);
203 }
30e7579c 204
d5bb2040 205
206 cout << "update()"<<endl;
207 UpdateDisplay();
208
209
30e7579c 210 return 0;
211
212}
239fdf4e 213///___________________________________________________________________________________________
30e7579c 214
215void AliEveHLTEventManager::ProcessBlock(AliHLTHOMERBlockDesc * block) {
216 //See header file for documentation
217
218#if 1//DEBUG
219 printf( "------------------- xxxxxxxxxxxxxxx ----------------------\n");
220 printf( "Detector : %s\n", block->GetDetector().Data() );
221 printf( "Datatype : %s\n", block->GetDataType().Data() );
222 if (block->IsTObject() )
223 printf( "Is TObject of class: %s\n", block->GetClassName().Data() );
224 printf( "------------------- xxxxxxxxxxxxxxx ----------------------\n");
225#endif
226
227
228 if(fShowBarrel) {
229
230 if ( ! block->GetDetector().CompareTo("PHOS") ) {
231 if(!fPhosElement) CreatePhosElement();
232 fPhosElement->ProcessBlock(block);
233 }
234
235 else if ( ! block->GetDetector().CompareTo("EMCA") ) {
236 if(!fEmcalElement) CreateEmcalElement();
237 fEmcalElement->ProcessBlock(block);
238 }
239
240 else if ( ! block->GetDetector().CompareTo("TPC") ) {
241 if(!fTPCElement) CreateTPCElement();
242 fTPCElement->ProcessBlock(block);
243 }
244
245 else if ( ! block->GetDetector().CompareTo("HLT") ) {
246 if(!fHLTElement) CreateHLTElement();
d48add50 247
248 if(!block->GetDataType().CompareTo("ALIESDV0")) {
249 AliESDEvent * event = dynamic_cast<AliESDEvent *>(block->GetTObject());
250 if(event) {
251 ProcessEvent(event);
252 }
253 } else {
254 fHLTElement->ProcessBlock(block);
255 }
30e7579c 256 }
257
258 else if ( ! block->GetDetector().CompareTo("ITS") ) {
259 if(!fITSElement) CreateITSElement();
260 fITSElement->ProcessBlock(block);
261 }
262
263 else if ( ! block->GetDetector().CompareTo("ISDD") ) {
264 if(!fISDDElement) CreateISDDElement();
265 fISDDElement->ProcessBlock(block);
266 }
267
268 else if ( ! block->GetDetector().CompareTo("ISPD") ) {
269 if(!fISPDElement) CreateISPDElement();
270 fISPDElement->ProcessBlock(block);
271 }
272
273 else if ( ! block->GetDetector().CompareTo("ISSD") ) {
274 if(!fISSDElement) CreateISSDElement();
275 fISSDElement->ProcessBlock(block);
276 }
277
278 else if ( ! block->GetDetector().CompareTo("TRD") ) {
279 if(!fTRDElement) CreateTRDElement();
280 fTRDElement->ProcessBlock(block);
281 }
282
283 else if ( ! block->GetDetector().CompareTo("MUON") ) {
284 //Do Nothing
285 } else {
286 if(!fAnyElement) {
287 fAnyElement = new AliHLTEveAny();
288 fAnyElement->SetEventManager(this);
289 }
290 fAnyElement->ProcessBlock(block);
291 }
292
293 }
294
295
296 if(fShowMuon) {
297 if ( ! block->GetDetector().CompareTo("MUON") ) {
298 if(!fMuonElement) {
299 fMuonElement = new AliHLTEveMuon();
300 fMuonElement->SetEventManager(this);
301 gEve->AddElement(fMuonElement);
302 }
303 fMuonElement->ProcessBlock(block);
304 }
305 }
306
307}
308
309void AliEveHLTEventManager::ResetDisplay () {
310 //See header file for documentation
311
312 if(fPhosElement)
313 fPhosElement->ResetElements();
314
315 if(fEmcalElement)
316 fEmcalElement->ResetElements();
317
318 if(fTPCElement)
319 fTPCElement->ResetElements();
320
321 if(fHLTElement)
322 fHLTElement->ResetElements();
323
324 if(fITSElement)
325 fITSElement->ResetElements();
326
327 if(fISPDElement)
328 fISPDElement->ResetElements();
329
330 if(fISDDElement)
331 fISDDElement->ResetElements();
332
333 if(fISSDElement)
334 fISSDElement->ResetElements();
335
336 if (fTRDElement)
337 fTRDElement->ResetElements();
338
339 if(fAnyElement)
340 fAnyElement->ResetElements();
341
342 if(fMuonElement)
343 fMuonElement->ResetElements();
344
345}
346
347
348void AliEveHLTEventManager::PrintScreens() {
349// //See header file for documentation
350
cc87822c 351 fEveManager->GetDefaultGLViewer()->SavePicture(Form("%d_0x%016lX_3D.gif", fRunNumber, GetEventId()));
352 fRhoZViewer->GetGLViewer()->SavePicture(Form("%d_0x%016lX_RhoZ.gif", fRunNumber, GetEventId()));
353 fRPhiViewer->GetGLViewer()->SavePicture(Form("%d_0x%016lX_RPhi.gif", fRunNumber, GetEventId()));
30e7579c 354 return;
355}
356
357
358void AliEveHLTEventManager::StartLoop() {
359 //See header file for documentation
360 //fTimer->SetCommand("NextEvent()", "AliEveHLTEventManager", this);
d63d227e 361 NextEvent();
30e7579c 362 SetEventLoopStarted(kTRUE);
d63d227e 363 fTimer->Start(15000);
30e7579c 364}
365
366void AliEveHLTEventManager::StopLoop() {
367 //See header file for documentation
368 fTimer->Stop();
369 SetEventLoopStarted(kFALSE);
370}
371
372
373// void AliEveHLTEventManager::NavigateBack() {
374
375// if (fHomerManager->NavigateEventBufferBack()) {
376// //return -1;
377// } else {
378
379// TList * blockList = fHomerManager->GetBlockList();
380// if(blockList) {
381// ProcessEvent(blockList);
382// } else {
383// cout << "BALLE Error blocklist NULL pointer even though it's navigateable"<<endl;
384// }
385// }
386
387// }
388
389// void AliEveHLTEventManager::NavigateFwd() {
390
391// if (fHomerManager->NavigateEventBufferFwd()) {
392// cout << "No event available" << endl;
393// return;
394// //return -1;
395// } else {
396// cout << "Getting block list" << endl;
397// TList * blockList = fHomerManager->GetBlockList();
398// if (blockList){
399// ProcessEvent(blockList);
400// } else {
401// cout << "blockList is NULL pointer"<<endl;
402// }
403// }
404
405// }
406
407void AliEveHLTEventManager::UpdateDisplay() {
408 //See header file for documentation
409 if(fPhosElement) fPhosElement->UpdateElements();
410 if(fEmcalElement) fEmcalElement->UpdateElements();
411 if(fTPCElement) fTPCElement->UpdateElements();
412 if(fHLTElement) fHLTElement->UpdateElements();
413 if(fITSElement) fITSElement->UpdateElements();
414 if(fISSDElement) fISSDElement->UpdateElements();
415 if(fISDDElement) fISDDElement->UpdateElements();
416 if(fISPDElement) fISPDElement->UpdateElements();
417 if(fTRDElement) fTRDElement->UpdateElements();
418 if(fAnyElement) fAnyElement->UpdateElements();
419 if(fMuonElement) fMuonElement->UpdateElements();
420
421
30e7579c 422 //==============================================================================
423 // -- Import global scene into projection scenes
424 //==============================================================================
425
426 Double_t x[3] = { 0, 0, 0 };
427
428 TEveElement* top = GetEveManager()->GetCurrentEvent();
429
430 if (fRPhiManager && top) {
431 fRPhiEventScene->DestroyElements();
432 if (fCenterProjectionsAtPrimaryVertex)
433 fRPhiManager->SetCenter(x[0], x[1], x[2]);
434 fRPhiManager->ImportElements(top, fRPhiEventScene);
435 }
436
437 if (fRhoZManager && top) {
438 fRhoZEventScene->DestroyElements();
439 if (fCenterProjectionsAtPrimaryVertex)
440 fRhoZManager->SetCenter(x[0], x[1], x[2]);
441 fRhoZManager->ImportElements(top, fRhoZEventScene);
442 }
443
444
445 //Redraw the display
446 GetEveManager()->Redraw3D(0,1); // (0, 1)
447 GetEveManager()->EnableRedraw();
448
449}
450
451void AliEveHLTEventManager::SaveEveryThing() {
452
cc87822c 453 PrintScreens();
454
455 GetEventBuffer()->WriteToFile(GetRunNumber());
30e7579c 456 //Save everything to file
457 //fEventBuffer->SaveBlockList();
458 //fEventBuffer->SaveAsyncBlockList();
459
460
461}
462
463
464
465void AliEveHLTEventManager::CreatePhosElement() {
466 fPhosElement = new AliHLTEvePhos();
467 fPhosElement->SetEventManager(this);
468 gEve->AddElement(fPhosElement);
469}
470
471void AliEveHLTEventManager::CreateEmcalElement() {
472 fEmcalElement = new AliHLTEveEmcal();
473 fEmcalElement->SetEventManager(this);
474 gEve->AddElement(fEmcalElement);
475}
476void AliEveHLTEventManager::CreateTPCElement() {
477 fTPCElement = new AliHLTEveTPC();
478 fTPCElement->SetEventManager(this);
479 gEve->AddElement(fTPCElement);
480}
481void AliEveHLTEventManager::CreateITSElement() {
482 fITSElement = new AliHLTEveITS();
483 fITSElement->SetEventManager(this);
484 gEve->AddElement(fITSElement);
485}
486void AliEveHLTEventManager::CreateISPDElement() {
487 fISPDElement = new AliHLTEveISPD();
488 fISPDElement->SetEventManager(this);
489 gEve->AddElement(fISPDElement);
490}
491void AliEveHLTEventManager::CreateISDDElement() {
492 fISDDElement = new AliHLTEveISDD();
493 fISDDElement->SetEventManager(this);
494 gEve->AddElement(fISSDElement);
495}
496void AliEveHLTEventManager::CreateISSDElement() {
497 fISSDElement = new AliHLTEveISSD();
498 fISSDElement->SetEventManager(this);
499 gEve->AddElement(fISSDElement);
500}
501void AliEveHLTEventManager::CreateTRDElement() {
502 fTRDElement = new AliHLTEveTRD();
503 fTRDElement->SetEventManager(this);
504 gEve->AddElement(fTRDElement);
505}
506void AliEveHLTEventManager::CreateHLTElement() {
507 fHLTElement = new AliHLTEveHLT();
508 fHLTElement->SetEventManager(this);
509 gEve->AddElement(fHLTElement);
510}
511
512