Use TList::Delete, change some output
[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"
220b9d66 19#include "AliHLTEveMultCorr.h"
30e7579c 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),
220b9d66 54 fMultCorrElement(NULL),
30e7579c 55 fAnyElement(NULL),
56 fEventLoopStarted(kFALSE),
57 fCenterProjectionsAtPrimaryVertex(kFALSE),
58 fShowBarrel(kTRUE),
59 fShowMuon(kFALSE),
359ecc79 60 fRunNumber(666),
cc87822c 61 fEventId(-1)
30e7579c 62{
63 // see header file for class documentation
64 // or
65 // refer to README to build package
66 // or
67 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
68
69 fTimer = new TTimer();
70 fTimer->Connect("Timeout()", "AliEveHLTEventManager", this, "NextEvent()" );
71
72}
73
74AliEveHLTEventManager::~AliEveHLTEventManager() {
75
76 //DestroyElements();
77 //DestroyDetectorElements();
78
79}
80
81
82void AliEveHLTEventManager::DestroyDetectorElements(){
83 //See header file for documentation
84
85 if (fPhosElement)
86 delete fPhosElement;
87 fPhosElement = NULL;
88
89 if(fEmcalElement)
90 delete fEmcalElement;
91 fEmcalElement = NULL;
92
93 if(fTPCElement)
94 delete fTPCElement;
95 fTPCElement = NULL;
96
97 if(fHLTElement)
98 delete fHLTElement;
99 fHLTElement = NULL;
100
101 if(fITSElement)
102 delete fITSElement;
103 fITSElement = NULL;
104
105 if(fISSDElement)
106 delete fISSDElement;
107 fISSDElement = NULL;
108
109 if(fISDDElement)
110 delete fISDDElement;
111 fISDDElement = NULL;
112
113 if(fISPDElement)
114 delete fISPDElement;
115 fISPDElement = NULL;
116
117 if(fTRDElement)
118 delete fTRDElement;
119 fTRDElement = NULL;
120
121 if(fMuonElement)
122 delete fMuonElement;
123 fMuonElement = NULL;
220b9d66 124
125 if(fMultCorrElement)
126 delete fMultCorrElement;
127 fMultCorrElement = NULL;
30e7579c 128
129 if(fAnyElement)
130 delete fAnyElement;
131 fAnyElement = NULL;
132
133
134}
239fdf4e 135
30e7579c 136///_______________________________________________________________________________________
137void AliEveHLTEventManager::ConnectEventBuffer() {
138 GetEventBuffer()->ConnectToSource();
139}
140
141
142///___________________________________________________________________________________________
143void AliEveHLTEventManager::StartBufferMonitor() {
144 AliEveEventBuffer * buffer = GetEventBuffer();
239fdf4e 145 buffer->StartBufferMonitor();
30e7579c 146}
239fdf4e 147
30e7579c 148//______________________________________________________________________________________________
149Int_t AliEveHLTEventManager::ProcessEvent(AliESDEvent * event) {
150
151 //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 152
153 gEve->DisableRedraw();
154
359ecc79 155 event->GetStdContent();
8676f4b1 156 // -- Set EventID in Window Title
157 TString winTitle("Eve Main Window");
cc87822c 158 SetRunNumber(event->GetRunNumber());
159 SetEventId(GetEventBuffer()->GetEventId());
160 winTitle += Form("-- Run Number: %d", GetRunNumber());
161 winTitle += Form("-- Event ID : 0x%016lX ", GetEventId() );
8676f4b1 162 GetEveManager()->GetBrowser()->SetWindowName(winTitle);
163
30e7579c 164 if(!fHLTElement) {
165 fHLTElement = new AliHLTEveHLT();
166 fHLTElement->SetEventManager(this);
167 gEve->AddElement(fHLTElement);
168 }
169 fHLTElement->ProcessEsdEvent(event);
170
171 if(!fPhosElement) CreatePhosElement();
172 fPhosElement->ProcessEvent(event);
173
174 if(!fEmcalElement) CreateEmcalElement();
175 fEmcalElement->ProcessEvent(event);
30e7579c 176
b088c0a1 177 gEve->Redraw3D(0, 1);
178 gEve->EnableRedraw();
179
30e7579c 180 return 0;
181
182}
183
184
185
186//______________________________________________________________________________________________
187Int_t AliEveHLTEventManager::ProcessEvent(TList * blockList) {
188
189 //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)
190
191 if(!blockList) {
192 cout << "Block list is NULL pointer, return " << endl;
193 return -1;
194 }
195
d5bb2040 196
30e7579c 197 AliHLTHOMERBlockDesc * block = NULL;
198 TIter next(blockList);
199 while ((block = (AliHLTHOMERBlockDesc*)next())) {
200 cout <<"Process Block"<<endl;
201 ProcessBlock(block);
202 }
30e7579c 203
d5bb2040 204
30e7579c 205 return 0;
206
207}
239fdf4e 208///___________________________________________________________________________________________
30e7579c 209
210void AliEveHLTEventManager::ProcessBlock(AliHLTHOMERBlockDesc * block) {
211 //See header file for documentation
212
213#if 1//DEBUG
214 printf( "------------------- xxxxxxxxxxxxxxx ----------------------\n");
215 printf( "Detector : %s\n", block->GetDetector().Data() );
216 printf( "Datatype : %s\n", block->GetDataType().Data() );
217 if (block->IsTObject() )
218 printf( "Is TObject of class: %s\n", block->GetClassName().Data() );
219 printf( "------------------- xxxxxxxxxxxxxxx ----------------------\n");
220#endif
221
222
223 if(fShowBarrel) {
224
225 if ( ! block->GetDetector().CompareTo("PHOS") ) {
226 if(!fPhosElement) CreatePhosElement();
227 fPhosElement->ProcessBlock(block);
228 }
229
230 else if ( ! block->GetDetector().CompareTo("EMCA") ) {
231 if(!fEmcalElement) CreateEmcalElement();
232 fEmcalElement->ProcessBlock(block);
233 }
234
235 else if ( ! block->GetDetector().CompareTo("TPC") ) {
236 if(!fTPCElement) CreateTPCElement();
237 fTPCElement->ProcessBlock(block);
238 }
239
240 else if ( ! block->GetDetector().CompareTo("HLT") ) {
241 if(!fHLTElement) CreateHLTElement();
d48add50 242
243 if(!block->GetDataType().CompareTo("ALIESDV0")) {
244 AliESDEvent * event = dynamic_cast<AliESDEvent *>(block->GetTObject());
245 if(event) {
246 ProcessEvent(event);
247 }
220b9d66 248
249 } else if(!(block->GetDataType().CompareTo("ROOTTOBJ"))) {
250
251 if(!fMultCorrElement) CreateMultCorrElement();
252 fMultCorrElement->ProcessBlock(block);
253
d48add50 254 } else {
255 fHLTElement->ProcessBlock(block);
256 }
30e7579c 257 }
258
259 else if ( ! block->GetDetector().CompareTo("ITS") ) {
260 if(!fITSElement) CreateITSElement();
261 fITSElement->ProcessBlock(block);
262 }
263
264 else if ( ! block->GetDetector().CompareTo("ISDD") ) {
265 if(!fISDDElement) CreateISDDElement();
266 fISDDElement->ProcessBlock(block);
267 }
268
269 else if ( ! block->GetDetector().CompareTo("ISPD") ) {
270 if(!fISPDElement) CreateISPDElement();
271 fISPDElement->ProcessBlock(block);
272 }
273
274 else if ( ! block->GetDetector().CompareTo("ISSD") ) {
275 if(!fISSDElement) CreateISSDElement();
276 fISSDElement->ProcessBlock(block);
277 }
278
279 else if ( ! block->GetDetector().CompareTo("TRD") ) {
280 if(!fTRDElement) CreateTRDElement();
281 fTRDElement->ProcessBlock(block);
282 }
283
284 else if ( ! block->GetDetector().CompareTo("MUON") ) {
285 //Do Nothing
286 } else {
287 if(!fAnyElement) {
288 fAnyElement = new AliHLTEveAny();
289 fAnyElement->SetEventManager(this);
290 }
291 fAnyElement->ProcessBlock(block);
292 }
293
294 }
295
296
297 if(fShowMuon) {
298 if ( ! block->GetDetector().CompareTo("MUON") ) {
299 if(!fMuonElement) {
300 fMuonElement = new AliHLTEveMuon();
301 fMuonElement->SetEventManager(this);
302 gEve->AddElement(fMuonElement);
303 }
304 fMuonElement->ProcessBlock(block);
305 }
306 }
307
308}
309
310void AliEveHLTEventManager::ResetDisplay () {
311 //See header file for documentation
312
313 if(fPhosElement)
314 fPhosElement->ResetElements();
315
316 if(fEmcalElement)
317 fEmcalElement->ResetElements();
318
319 if(fTPCElement)
320 fTPCElement->ResetElements();
321
322 if(fHLTElement)
323 fHLTElement->ResetElements();
324
325 if(fITSElement)
326 fITSElement->ResetElements();
327
328 if(fISPDElement)
329 fISPDElement->ResetElements();
330
331 if(fISDDElement)
332 fISDDElement->ResetElements();
333
334 if(fISSDElement)
335 fISSDElement->ResetElements();
336
337 if (fTRDElement)
338 fTRDElement->ResetElements();
339
340 if(fAnyElement)
341 fAnyElement->ResetElements();
342
343 if(fMuonElement)
344 fMuonElement->ResetElements();
345
346}
347
348
349void AliEveHLTEventManager::PrintScreens() {
350// //See header file for documentation
351
cf331698 352 Float_t scale = 4.f;
353 //Int_t width = 4000;
354 //Int_t height = 2000;
355
356 fEveManager->GetDefaultGLViewer()->SavePictureScale(Form("run_%d_0x%016lX_3D.gif", fRunNumber, GetEventId()), scale);
357 fRhoZViewer->GetGLViewer()->SavePictureScale(Form("run_%d_0x%016lX_RhoZ.gif", fRunNumber, GetEventId()), scale);
358 fRPhiViewer->GetGLViewer()->SavePictureScale(Form("run_%d_0x%016lX_RPhi.gif", fRunNumber, GetEventId()), scale);
30e7579c 359 return;
360}
361
362
363void AliEveHLTEventManager::StartLoop() {
364 //See header file for documentation
365 //fTimer->SetCommand("NextEvent()", "AliEveHLTEventManager", this);
d63d227e 366 NextEvent();
30e7579c 367 SetEventLoopStarted(kTRUE);
ce63b00c 368 fTimer->Start(45000);
30e7579c 369}
370
371void AliEveHLTEventManager::StopLoop() {
372 //See header file for documentation
373 fTimer->Stop();
374 SetEventLoopStarted(kFALSE);
375}
376
377
378// void AliEveHLTEventManager::NavigateBack() {
379
380// if (fHomerManager->NavigateEventBufferBack()) {
381// //return -1;
382// } else {
383
384// TList * blockList = fHomerManager->GetBlockList();
385// if(blockList) {
386// ProcessEvent(blockList);
387// } else {
388// cout << "BALLE Error blocklist NULL pointer even though it's navigateable"<<endl;
389// }
390// }
391
392// }
393
394// void AliEveHLTEventManager::NavigateFwd() {
395
396// if (fHomerManager->NavigateEventBufferFwd()) {
397// cout << "No event available" << endl;
398// return;
399// //return -1;
400// } else {
401// cout << "Getting block list" << endl;
402// TList * blockList = fHomerManager->GetBlockList();
403// if (blockList){
404// ProcessEvent(blockList);
405// } else {
406// cout << "blockList is NULL pointer"<<endl;
407// }
408// }
409
410// }
411
412void AliEveHLTEventManager::UpdateDisplay() {
413 //See header file for documentation
fc482d0c 414 cout << "AliHLTEventManager::UpdateDisplay(); " <<endl;
30e7579c 415 if(fPhosElement) fPhosElement->UpdateElements();
416 if(fEmcalElement) fEmcalElement->UpdateElements();
417 if(fTPCElement) fTPCElement->UpdateElements();
418 if(fHLTElement) fHLTElement->UpdateElements();
419 if(fITSElement) fITSElement->UpdateElements();
420 if(fISSDElement) fISSDElement->UpdateElements();
421 if(fISDDElement) fISDDElement->UpdateElements();
422 if(fISPDElement) fISPDElement->UpdateElements();
423 if(fTRDElement) fTRDElement->UpdateElements();
424 if(fAnyElement) fAnyElement->UpdateElements();
425 if(fMuonElement) fMuonElement->UpdateElements();
426
427
30e7579c 428 //==============================================================================
429 // -- Import global scene into projection scenes
430 //==============================================================================
431
432 Double_t x[3] = { 0, 0, 0 };
433
434 TEveElement* top = GetEveManager()->GetCurrentEvent();
435
436 if (fRPhiManager && top) {
437 fRPhiEventScene->DestroyElements();
438 if (fCenterProjectionsAtPrimaryVertex)
439 fRPhiManager->SetCenter(x[0], x[1], x[2]);
440 fRPhiManager->ImportElements(top, fRPhiEventScene);
441 }
442
443 if (fRhoZManager && top) {
444 fRhoZEventScene->DestroyElements();
445 if (fCenterProjectionsAtPrimaryVertex)
446 fRhoZManager->SetCenter(x[0], x[1], x[2]);
447 fRhoZManager->ImportElements(top, fRhoZEventScene);
448 }
449
450
451 //Redraw the display
452 GetEveManager()->Redraw3D(0,1); // (0, 1)
453 GetEveManager()->EnableRedraw();
454
455}
456
457void AliEveHLTEventManager::SaveEveryThing() {
458
fc482d0c 459 //Print the screens
cc87822c 460 PrintScreens();
fc482d0c 461 //Save block lists to file
cc87822c 462 GetEventBuffer()->WriteToFile(GetRunNumber());
30e7579c 463}
464
465
466
467void AliEveHLTEventManager::CreatePhosElement() {
468 fPhosElement = new AliHLTEvePhos();
469 fPhosElement->SetEventManager(this);
470 gEve->AddElement(fPhosElement);
471}
472
220b9d66 473void AliEveHLTEventManager::CreateMultCorrElement() {
474 fMultCorrElement = new AliHLTEveMultCorr("MultCorr");
475 fMultCorrElement->SetEventManager(this);
476 gEve->AddElement(fMultCorrElement);
477}
478
30e7579c 479void AliEveHLTEventManager::CreateEmcalElement() {
480 fEmcalElement = new AliHLTEveEmcal();
481 fEmcalElement->SetEventManager(this);
482 gEve->AddElement(fEmcalElement);
483}
484void AliEveHLTEventManager::CreateTPCElement() {
485 fTPCElement = new AliHLTEveTPC();
486 fTPCElement->SetEventManager(this);
487 gEve->AddElement(fTPCElement);
488}
489void AliEveHLTEventManager::CreateITSElement() {
490 fITSElement = new AliHLTEveITS();
491 fITSElement->SetEventManager(this);
492 gEve->AddElement(fITSElement);
493}
494void AliEveHLTEventManager::CreateISPDElement() {
495 fISPDElement = new AliHLTEveISPD();
496 fISPDElement->SetEventManager(this);
497 gEve->AddElement(fISPDElement);
498}
499void AliEveHLTEventManager::CreateISDDElement() {
500 fISDDElement = new AliHLTEveISDD();
501 fISDDElement->SetEventManager(this);
502 gEve->AddElement(fISSDElement);
503}
504void AliEveHLTEventManager::CreateISSDElement() {
505 fISSDElement = new AliHLTEveISSD();
506 fISSDElement->SetEventManager(this);
507 gEve->AddElement(fISSDElement);
508}
509void AliEveHLTEventManager::CreateTRDElement() {
510 fTRDElement = new AliHLTEveTRD();
511 fTRDElement->SetEventManager(this);
512 gEve->AddElement(fTRDElement);
513}
514void AliEveHLTEventManager::CreateHLTElement() {
515 fHLTElement = new AliHLTEveHLT();
516 fHLTElement->SetEventManager(this);
517 gEve->AddElement(fHLTElement);
518}
519
520