]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - EVE/EveHLT/AliEveHLTEventManager.cxx
Merge branch 'multipleThreads'
[u/mrichter/AliRoot.git] / EVE / EveHLT / AliEveHLTEventManager.cxx
... / ...
CommitLineData
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}
129///_______________________________________________________________________________________
130void AliEveHLTEventManager::ConnectEventBuffer() {
131 GetEventBuffer()->ConnectToSource();
132}
133
134
135///___________________________________________________________________________________________
136void AliEveHLTEventManager::StartBufferMonitor() {
137 AliEveEventBuffer * buffer = GetEventBuffer();
138 if(buffer) {
139 TThread * fThread = new TThread(AliEveEventBuffer::BufferThread, (void*) buffer);
140 fThread->Run();
141 } else {
142 cout << "Buffer does not exist " << endl;
143 }
144}
145//______________________________________________________________________________________________
146Int_t AliEveHLTEventManager::ProcessEvent(AliESDEvent * event) {
147
148 //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)
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
171 return 0;
172
173}
174
175
176
177//______________________________________________________________________________________________
178Int_t AliEveHLTEventManager::ProcessEvent(TList * blockList) {
179
180 //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)
181
182 if(!blockList) {
183 cout << "Block list is NULL pointer, return " << endl;
184 return -1;
185 }
186
187 cout << "reset ()"<<endl;
188 ResetDisplay();
189 cout << "done reset()"<<endl;
190 AliHLTHOMERBlockDesc * block = NULL;
191 TIter next(blockList);
192 while ((block = (AliHLTHOMERBlockDesc*)next())) {
193 cout <<"Process Block"<<endl;
194 ProcessBlock(block);
195 }
196
197 cout << "update() "<<endl;
198 UpdateDisplay();
199
200 return 0;
201
202}
203
204void AliEveHLTEventManager::ProcessBlock(AliHLTHOMERBlockDesc * block) {
205 //See header file for documentation
206
207#if 1//DEBUG
208 printf( "------------------- xxxxxxxxxxxxxxx ----------------------\n");
209 printf( "Detector : %s\n", block->GetDetector().Data() );
210 printf( "Datatype : %s\n", block->GetDataType().Data() );
211 if (block->IsTObject() )
212 printf( "Is TObject of class: %s\n", block->GetClassName().Data() );
213 printf( "------------------- xxxxxxxxxxxxxxx ----------------------\n");
214#endif
215
216
217 if(fShowBarrel) {
218
219 if ( ! block->GetDetector().CompareTo("PHOS") ) {
220 if(!fPhosElement) CreatePhosElement();
221 fPhosElement->ProcessBlock(block);
222 }
223
224 else if ( ! block->GetDetector().CompareTo("EMCA") ) {
225 if(!fEmcalElement) CreateEmcalElement();
226 fEmcalElement->ProcessBlock(block);
227 }
228
229 else if ( ! block->GetDetector().CompareTo("TPC") ) {
230 if(!fTPCElement) CreateTPCElement();
231 fTPCElement->ProcessBlock(block);
232 }
233
234 else if ( ! block->GetDetector().CompareTo("HLT") ) {
235 if(!fHLTElement) CreateHLTElement();
236 fHLTElement->ProcessBlock(block);
237 }
238
239 else if ( ! block->GetDetector().CompareTo("ITS") ) {
240 if(!fITSElement) CreateITSElement();
241 fITSElement->ProcessBlock(block);
242 }
243
244 else if ( ! block->GetDetector().CompareTo("ISDD") ) {
245 if(!fISDDElement) CreateISDDElement();
246 fISDDElement->ProcessBlock(block);
247 }
248
249 else if ( ! block->GetDetector().CompareTo("ISPD") ) {
250 if(!fISPDElement) CreateISPDElement();
251 fISPDElement->ProcessBlock(block);
252 }
253
254 else if ( ! block->GetDetector().CompareTo("ISSD") ) {
255 if(!fISSDElement) CreateISSDElement();
256 fISSDElement->ProcessBlock(block);
257 }
258
259 else if ( ! block->GetDetector().CompareTo("TRD") ) {
260 if(!fTRDElement) CreateTRDElement();
261 fTRDElement->ProcessBlock(block);
262 }
263
264 else if ( ! block->GetDetector().CompareTo("MUON") ) {
265 //Do Nothing
266 } else {
267 if(!fAnyElement) {
268 fAnyElement = new AliHLTEveAny();
269 fAnyElement->SetEventManager(this);
270 }
271 fAnyElement->ProcessBlock(block);
272 }
273
274 }
275
276
277 if(fShowMuon) {
278 if ( ! block->GetDetector().CompareTo("MUON") ) {
279 if(!fMuonElement) {
280 fMuonElement = new AliHLTEveMuon();
281 fMuonElement->SetEventManager(this);
282 gEve->AddElement(fMuonElement);
283 }
284 fMuonElement->ProcessBlock(block);
285 }
286 }
287
288}
289
290void AliEveHLTEventManager::ResetDisplay () {
291 //See header file for documentation
292
293 if(fPhosElement)
294 fPhosElement->ResetElements();
295
296 if(fEmcalElement)
297 fEmcalElement->ResetElements();
298
299 if(fTPCElement)
300 fTPCElement->ResetElements();
301
302 if(fHLTElement)
303 fHLTElement->ResetElements();
304
305 if(fITSElement)
306 fITSElement->ResetElements();
307
308 if(fISPDElement)
309 fISPDElement->ResetElements();
310
311 if(fISDDElement)
312 fISDDElement->ResetElements();
313
314 if(fISSDElement)
315 fISSDElement->ResetElements();
316
317 if (fTRDElement)
318 fTRDElement->ResetElements();
319
320 if(fAnyElement)
321 fAnyElement->ResetElements();
322
323 if(fMuonElement)
324 fMuonElement->ResetElements();
325
326}
327
328
329void AliEveHLTEventManager::PrintScreens() {
330// //See header file for documentation
331
332// fEveManager->GetDefaultGLViewer()->SavePicture(Form("%d_0x%lu_3D.gif", fRunNumber, GetEventID(fCurrentEventIdx)));
333// fRhoZViewer->GetGLViewer()->SavePicture(Form("%d_0x%lu_RhoZ.gif", fRunNumber, GetEventID(fCurrentEventIdx)));
334// fRPhiViewer->GetGLViewer()->SavePicture(Form("%d_0x%lu_RPhi.gif", fRunNumber, GetEventID(fCurrentEventIdx)));
335 return;
336}
337
338
339void AliEveHLTEventManager::StartLoop() {
340 //See header file for documentation
341 //fTimer->SetCommand("NextEvent()", "AliEveHLTEventManager", this);
342 SetEventLoopStarted(kTRUE);
343 fTimer->Start(10000);
344}
345
346void AliEveHLTEventManager::StopLoop() {
347 //See header file for documentation
348 fTimer->Stop();
349 SetEventLoopStarted(kFALSE);
350}
351
352
353// void AliEveHLTEventManager::NavigateBack() {
354
355// if (fHomerManager->NavigateEventBufferBack()) {
356// //return -1;
357// } else {
358
359// TList * blockList = fHomerManager->GetBlockList();
360// if(blockList) {
361// ProcessEvent(blockList);
362// } else {
363// cout << "BALLE Error blocklist NULL pointer even though it's navigateable"<<endl;
364// }
365// }
366
367// }
368
369// void AliEveHLTEventManager::NavigateFwd() {
370
371// if (fHomerManager->NavigateEventBufferFwd()) {
372// cout << "No event available" << endl;
373// return;
374// //return -1;
375// } else {
376// cout << "Getting block list" << endl;
377// TList * blockList = fHomerManager->GetBlockList();
378// if (blockList){
379// ProcessEvent(blockList);
380// } else {
381// cout << "blockList is NULL pointer"<<endl;
382// }
383// }
384
385// }
386
387void AliEveHLTEventManager::UpdateDisplay() {
388 //See header file for documentation
389 if(fPhosElement) fPhosElement->UpdateElements();
390 if(fEmcalElement) fEmcalElement->UpdateElements();
391 if(fTPCElement) fTPCElement->UpdateElements();
392 if(fHLTElement) fHLTElement->UpdateElements();
393 if(fITSElement) fITSElement->UpdateElements();
394 if(fISSDElement) fISSDElement->UpdateElements();
395 if(fISDDElement) fISDDElement->UpdateElements();
396 if(fISPDElement) fISPDElement->UpdateElements();
397 if(fTRDElement) fTRDElement->UpdateElements();
398 if(fAnyElement) fAnyElement->UpdateElements();
399 if(fMuonElement) fMuonElement->UpdateElements();
400
401
402 // -- Set EventID in Window Title
403 TString winTitle("Eve Main Window");
404 winTitle += Form("-- Run Number: %d", fRunNumber);
405 //winTitle += Form("-- Event ID : 0x%lu ", GetEventID(fCurrentEventIdx) );
406 GetEveManager()->GetBrowser()->SetWindowName(winTitle);
407
408 //==============================================================================
409 // -- Import global scene into projection scenes
410 //==============================================================================
411
412 Double_t x[3] = { 0, 0, 0 };
413
414 TEveElement* top = GetEveManager()->GetCurrentEvent();
415
416 if (fRPhiManager && top) {
417 fRPhiEventScene->DestroyElements();
418 if (fCenterProjectionsAtPrimaryVertex)
419 fRPhiManager->SetCenter(x[0], x[1], x[2]);
420 fRPhiManager->ImportElements(top, fRPhiEventScene);
421 }
422
423 if (fRhoZManager && top) {
424 fRhoZEventScene->DestroyElements();
425 if (fCenterProjectionsAtPrimaryVertex)
426 fRhoZManager->SetCenter(x[0], x[1], x[2]);
427 fRhoZManager->ImportElements(top, fRhoZEventScene);
428 }
429
430
431 //Redraw the display
432 GetEveManager()->Redraw3D(0,1); // (0, 1)
433 GetEveManager()->EnableRedraw();
434
435}
436
437void AliEveHLTEventManager::SaveEveryThing() {
438
439 GetEventBuffer()->WriteToFile();
440 //Save everything to file
441 //fEventBuffer->SaveBlockList();
442 //fEventBuffer->SaveAsyncBlockList();
443
444
445}
446
447
448
449void AliEveHLTEventManager::CreatePhosElement() {
450 fPhosElement = new AliHLTEvePhos();
451 fPhosElement->SetEventManager(this);
452 gEve->AddElement(fPhosElement);
453}
454
455void AliEveHLTEventManager::CreateEmcalElement() {
456 fEmcalElement = new AliHLTEveEmcal();
457 fEmcalElement->SetEventManager(this);
458 gEve->AddElement(fEmcalElement);
459}
460void AliEveHLTEventManager::CreateTPCElement() {
461 fTPCElement = new AliHLTEveTPC();
462 fTPCElement->SetEventManager(this);
463 gEve->AddElement(fTPCElement);
464}
465void AliEveHLTEventManager::CreateITSElement() {
466 fITSElement = new AliHLTEveITS();
467 fITSElement->SetEventManager(this);
468 gEve->AddElement(fITSElement);
469}
470void AliEveHLTEventManager::CreateISPDElement() {
471 fISPDElement = new AliHLTEveISPD();
472 fISPDElement->SetEventManager(this);
473 gEve->AddElement(fISPDElement);
474}
475void AliEveHLTEventManager::CreateISDDElement() {
476 fISDDElement = new AliHLTEveISDD();
477 fISDDElement->SetEventManager(this);
478 gEve->AddElement(fISSDElement);
479}
480void AliEveHLTEventManager::CreateISSDElement() {
481 fISSDElement = new AliHLTEveISSD();
482 fISSDElement->SetEventManager(this);
483 gEve->AddElement(fISSDElement);
484}
485void AliEveHLTEventManager::CreateTRDElement() {
486 fTRDElement = new AliHLTEveTRD();
487 fTRDElement->SetEventManager(this);
488 gEve->AddElement(fTRDElement);
489}
490void AliEveHLTEventManager::CreateHLTElement() {
491 fHLTElement = new AliHLTEveHLT();
492 fHLTElement->SetEventManager(this);
493 gEve->AddElement(fHLTElement);
494}
495
496