]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveHLT/AliEveHLTEventManager.cxx
c658106b0a9619f3ae680611a10e00744ced56e6
[u/mrichter/AliRoot.git] / EVE / EveHLT / AliEveHLTEventManager.cxx
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 "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
30 ClassImp(AliEveHLTEventManager);
31
32 AliEveHLTEventManager::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), 
58   fRunNumber(-1),
59   fEventId(-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  
72 AliEveHLTEventManager::~AliEveHLTEventManager() {
73   
74   //DestroyElements();
75   //DestroyDetectorElements();  
76   
77 }
78
79
80 void 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
130 ///_______________________________________________________________________________________
131 void AliEveHLTEventManager::ConnectEventBuffer() {
132   GetEventBuffer()->ConnectToSource();
133 }
134
135
136 ///___________________________________________________________________________________________
137 void AliEveHLTEventManager::StartBufferMonitor() { 
138   AliEveEventBuffer * buffer = GetEventBuffer();
139   buffer->StartBufferMonitor();
140 }
141
142 //______________________________________________________________________________________________
143 Int_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)
146
147   gEve->DisableRedraw();
148
149   // -- Set EventID in Window Title  
150   TString winTitle("Eve Main Window");
151   SetRunNumber(event->GetRunNumber());
152   SetEventId(GetEventBuffer()->GetEventId());
153   winTitle += Form("-- Run Number: %d", GetRunNumber()); 
154   winTitle += Form("-- Event ID : 0x%016lX ", GetEventId() );
155   GetEveManager()->GetBrowser()->SetWindowName(winTitle);
156
157
158   
159   cout << "reset()"<<endl;
160   
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);
174
175   gEve->Redraw3D(0, 1);
176   gEve->EnableRedraw();
177
178   return 0;
179
180 }
181
182
183
184 //______________________________________________________________________________________________
185 Int_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  
194
195   AliHLTHOMERBlockDesc * block = NULL;
196   TIter next(blockList);
197   while ((block = (AliHLTHOMERBlockDesc*)next())) {
198     cout <<"Process Block"<<endl;
199     ProcessBlock(block);
200   } 
201   
202
203   return 0;
204
205 }
206 ///___________________________________________________________________________________________
207
208 void 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       
241       if(!block->GetDataType().CompareTo("ALIESDV0")) {
242         AliESDEvent * event = dynamic_cast<AliESDEvent *>(block->GetTObject());
243         if(event) {
244           ProcessEvent(event);
245         }
246       } else {
247         fHLTElement->ProcessBlock(block);
248       }
249     }
250
251     else if ( ! block->GetDetector().CompareTo("ITS") ) {
252       if(!fITSElement) CreateITSElement();
253       fITSElement->ProcessBlock(block);
254     }
255     
256     else if ( ! block->GetDetector().CompareTo("ISDD") ) {
257       if(!fISDDElement) CreateISDDElement();
258       fISDDElement->ProcessBlock(block);
259     }
260     
261     else if ( ! block->GetDetector().CompareTo("ISPD") ) {
262       if(!fISPDElement) CreateISPDElement();
263       fISPDElement->ProcessBlock(block);
264     }
265     
266     else if ( ! block->GetDetector().CompareTo("ISSD") ) {
267       if(!fISSDElement) CreateISSDElement();
268       fISSDElement->ProcessBlock(block);
269     }
270     
271     else if ( ! block->GetDetector().CompareTo("TRD") ) {
272       if(!fTRDElement) CreateTRDElement();
273       fTRDElement->ProcessBlock(block);
274     }
275     
276     else if ( ! block->GetDetector().CompareTo("MUON") ) {
277       //Do Nothing
278     } else {
279       if(!fAnyElement) {
280         fAnyElement = new AliHLTEveAny();
281         fAnyElement->SetEventManager(this);
282       } 
283       fAnyElement->ProcessBlock(block);
284     }
285      
286   }
287
288    
289   if(fShowMuon) {
290     if ( ! block->GetDetector().CompareTo("MUON") ) {
291       if(!fMuonElement) {
292         fMuonElement = new AliHLTEveMuon();
293         fMuonElement->SetEventManager(this);
294         gEve->AddElement(fMuonElement);
295       }
296       fMuonElement->ProcessBlock(block);
297     }
298   }
299
300 }
301
302 void AliEveHLTEventManager::ResetDisplay () {
303   //See header file for documentation
304
305  if(fPhosElement)
306    fPhosElement->ResetElements();
307  
308  if(fEmcalElement)
309    fEmcalElement->ResetElements();
310  
311  if(fTPCElement)
312    fTPCElement->ResetElements();
313  
314  if(fHLTElement)
315    fHLTElement->ResetElements();
316  
317  if(fITSElement)
318    fITSElement->ResetElements();
319  
320  if(fISPDElement)
321    fISPDElement->ResetElements();
322  
323  if(fISDDElement)
324    fISDDElement->ResetElements();
325  
326  if(fISSDElement)
327    fISSDElement->ResetElements();
328
329  if (fTRDElement)
330    fTRDElement->ResetElements();
331
332  if(fAnyElement)
333    fAnyElement->ResetElements();
334
335  if(fMuonElement)
336    fMuonElement->ResetElements();
337
338 }
339
340
341 void AliEveHLTEventManager::PrintScreens() {
342 //   //See header file for documentation
343
344   Float_t scale = 4.f;
345   //Int_t width = 4000;
346   //Int_t height = 2000;
347
348   fEveManager->GetDefaultGLViewer()->SavePictureScale(Form("run_%d_0x%016lX_3D.gif", fRunNumber, GetEventId()), scale);
349   fRhoZViewer->GetGLViewer()->SavePictureScale(Form("run_%d_0x%016lX_RhoZ.gif", fRunNumber, GetEventId()), scale);
350   fRPhiViewer->GetGLViewer()->SavePictureScale(Form("run_%d_0x%016lX_RPhi.gif", fRunNumber, GetEventId()), scale);
351   return;
352 }
353
354
355 void AliEveHLTEventManager::StartLoop() {
356   //See header file for documentation
357   //fTimer->SetCommand("NextEvent()", "AliEveHLTEventManager", this);
358   NextEvent();
359   SetEventLoopStarted(kTRUE);
360   fTimer->Start(45000);
361 }
362
363 void AliEveHLTEventManager::StopLoop() {
364   //See header file for documentation
365   fTimer->Stop();
366   SetEventLoopStarted(kFALSE);
367 }
368
369
370 // void AliEveHLTEventManager::NavigateBack() {
371   
372 //   if (fHomerManager->NavigateEventBufferBack()) {
373 //     //return -1;
374 //   } else {
375     
376 //     TList * blockList = fHomerManager->GetBlockList();
377 //     if(blockList) {      
378 //       ProcessEvent(blockList);
379 //     } else {
380 //       cout << "BALLE Error blocklist NULL pointer even though it's navigateable"<<endl;
381 //     }
382 //   }   
383
384 // }
385
386 // void AliEveHLTEventManager::NavigateFwd() {
387
388 //   if (fHomerManager->NavigateEventBufferFwd()) {
389 //     cout << "No event available" << endl;
390 //     return;
391 //     //return -1;
392 //   } else {
393 //     cout << "Getting block list" << endl;
394 //     TList * blockList = fHomerManager->GetBlockList();
395 //     if (blockList){
396 //       ProcessEvent(blockList);
397 //     } else {
398 //       cout << "blockList is NULL pointer"<<endl;
399 //     }
400 //   }
401
402 // }
403
404 void  AliEveHLTEventManager::UpdateDisplay() {
405   //See header file for documentation
406   if(fPhosElement) fPhosElement->UpdateElements();
407   if(fEmcalElement) fEmcalElement->UpdateElements();
408   if(fTPCElement) fTPCElement->UpdateElements();
409   if(fHLTElement) fHLTElement->UpdateElements();
410   if(fITSElement) fITSElement->UpdateElements();
411   if(fISSDElement) fISSDElement->UpdateElements();
412   if(fISDDElement) fISDDElement->UpdateElements();
413   if(fISPDElement) fISPDElement->UpdateElements();
414   if(fTRDElement) fTRDElement->UpdateElements();
415   if(fAnyElement) fAnyElement->UpdateElements();
416   if(fMuonElement) fMuonElement->UpdateElements();
417
418
419   //==============================================================================
420   // -- Import global scene into projection scenes
421   //==============================================================================
422
423   Double_t x[3] = { 0, 0, 0 };
424   
425   TEveElement* top = GetEveManager()->GetCurrentEvent();
426   
427   if (fRPhiManager && top) {
428     fRPhiEventScene->DestroyElements();
429     if (fCenterProjectionsAtPrimaryVertex)
430       fRPhiManager->SetCenter(x[0], x[1], x[2]);
431     fRPhiManager->ImportElements(top, fRPhiEventScene);
432   }
433   
434   if (fRhoZManager && top) {
435     fRhoZEventScene->DestroyElements();
436     if (fCenterProjectionsAtPrimaryVertex)
437       fRhoZManager->SetCenter(x[0], x[1], x[2]);
438     fRhoZManager->ImportElements(top, fRhoZEventScene);
439   }
440
441
442   //Redraw the display
443   GetEveManager()->Redraw3D(0,1); // (0, 1)
444   GetEveManager()->EnableRedraw(); 
445
446 }
447
448 void AliEveHLTEventManager::SaveEveryThing() {
449
450   PrintScreens();
451
452   GetEventBuffer()->WriteToFile(GetRunNumber());
453   //Save everything to file
454   //fEventBuffer->SaveBlockList();
455   //fEventBuffer->SaveAsyncBlockList();
456
457
458 }
459
460
461
462 void AliEveHLTEventManager::CreatePhosElement() {
463   fPhosElement = new AliHLTEvePhos();
464   fPhosElement->SetEventManager(this);
465   gEve->AddElement(fPhosElement);
466 }
467
468 void AliEveHLTEventManager::CreateEmcalElement() {
469   fEmcalElement = new AliHLTEveEmcal();
470   fEmcalElement->SetEventManager(this);
471   gEve->AddElement(fEmcalElement);
472 }
473 void AliEveHLTEventManager::CreateTPCElement() {
474   fTPCElement = new AliHLTEveTPC();
475   fTPCElement->SetEventManager(this);
476   gEve->AddElement(fTPCElement);
477 }
478 void AliEveHLTEventManager::CreateITSElement() {
479   fITSElement = new AliHLTEveITS();
480   fITSElement->SetEventManager(this);
481   gEve->AddElement(fITSElement);
482 }
483 void AliEveHLTEventManager::CreateISPDElement() {
484   fISPDElement = new AliHLTEveISPD();
485   fISPDElement->SetEventManager(this);
486   gEve->AddElement(fISPDElement);
487 }
488 void AliEveHLTEventManager::CreateISDDElement() {
489   fISDDElement = new AliHLTEveISDD();
490   fISDDElement->SetEventManager(this);
491   gEve->AddElement(fISSDElement);
492 }
493 void AliEveHLTEventManager::CreateISSDElement() {
494   fISSDElement = new AliHLTEveISSD();
495   fISSDElement->SetEventManager(this);
496   gEve->AddElement(fISSDElement);
497 }
498 void AliEveHLTEventManager::CreateTRDElement() {
499   fTRDElement = new AliHLTEveTRD();
500   fTRDElement->SetEventManager(this);
501   gEve->AddElement(fTRDElement);
502 }
503 void AliEveHLTEventManager::CreateHLTElement() {
504   fHLTElement = new AliHLTEveHLT();
505   fHLTElement->SetEventManager(this);
506   gEve->AddElement(fHLTElement);
507 }
508
509