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