]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVE/EveHLT/AliEveHOMERManager.cxx
Warning
[u/mrichter/AliRoot.git] / EVE / EveHLT / AliEveHOMERManager.cxx
1 //-*- Mode: C++ -*-
2
3 // $Id$
4 // Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007              *
5 // Author: Jochen Thaeder <thaeder@kip.uni-heidelberg.de>                *
6 // Author: 2010 Svein Lindal <slindal@fys.uio.no>                        *
7 //         for The ALICE HLT Project.                                    *
8
9
10
11 /** @file   AliEveHOMERManager.cxx
12     @author Jochen Thaeder,  Svein Lindal <slindal@fys.uio.no>
13     @date
14     @brief  Manager for HOMER online
15 */
16
17 #if __GNUC__>= 3
18    using namespace std;
19 #endif
20
21 #include "unistd.h"
22 #include "TEveManager.h"
23 #include "TTimer.h"
24 #include "TEveScene.h"
25 #include "TEveProjectionManager.h"
26 #include "TEveBrowser.h"
27 #include "TGLViewer.h"
28 #include "TEveViewer.h"
29
30 #include "AliEveHOMERManager.h"
31 #include "AliHLTHOMERBlockDesc.h"
32 #include "AliHLTHOMERManager.h"
33 #include "AliHLTTriggerDecision.h"
34 #include "AliHLTEvePhos.h"
35 #include "AliHLTEveEmcal.h"
36 #include "AliHLTEveTPC.h"
37 #include "AliHLTEveHLT.h"
38 #include "AliHLTEveITS.h"
39 #include "AliHLTEveISPD.h"
40 #include "AliHLTEveISSD.h"
41 #include "AliHLTEveISDD.h"
42 #include "AliHLTEveTRD.h"
43 #include "AliHLTEveMuon.h"
44 #include "AliHLTEveAny.h"
45 #include "AliEveHOMERSourceList.h"
46
47 //#include "TTimer.h"
48
49 ClassImp(AliEveHOMERManager)
50   
51 /*
52  * ---------------------------------------------------------------------------------
53  *                            Constructor / Destructor
54  * ---------------------------------------------------------------------------------
55  */
56   
57 //##################################################################################
58 AliEveHOMERManager::AliEveHOMERManager() :
59 TEveElementList("Homer Manager"),
60   AliHLTHOMERManager(), 
61   fSrcList(NULL),
62   fRetryCount(1000),
63   fRetrySleeptime(15),
64   fGeoManager(NULL),
65   fEveManager(NULL),
66   fRPhiManager(NULL),
67   fRhoZManager(NULL),
68   fRPhiEventScene(NULL),
69   fRhoZEventScene(NULL),
70   fRhoZViewer(NULL),
71   fRPhiViewer(NULL),
72   fTimer(NULL),
73 //  fSourceListTimer(NULL),
74   fPhosElement(NULL), 
75   fEmcalElement(NULL), 
76   fTPCElement(NULL),
77   fHLTElement(NULL),
78   fITSElement(NULL),
79   fISPDElement(NULL),
80   fISSDElement(NULL),
81   fISDDElement(NULL),
82   fTRDElement(NULL),
83   fMuonElement(NULL),
84   fAnyElement(NULL),
85   fEventLoopStarted(kFALSE),
86   fCenterProjectionsAtPrimaryVertex(kFALSE),
87   fShowBarrel(kTRUE),
88   fShowMuon(kFALSE) 
89 {
90   // see header file for class documentation
91   // or
92   // refer to README to build package
93   // or
94   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
95    
96   fTimer = new TTimer();
97   fTimer->Connect("Timeout()", "AliEveHOMERManager", this, "NextHOMEREvent()" );
98
99   //fSourceListTimer = new TTimer();
100
101   fPhosElement = new AliHLTEvePhos();
102   fPhosElement->SetEventManager(this);
103    
104   fEmcalElement = new AliHLTEveEmcal();
105   fEmcalElement->SetEventManager(this);
106    
107   fTPCElement = new AliHLTEveTPC();
108   fTPCElement->SetEventManager(this);
109    
110   fHLTElement = new AliHLTEveHLT();
111   fHLTElement->SetEventManager(this);
112    
113   fITSElement = new AliHLTEveITS();
114   fITSElement->SetEventManager(this);
115   
116   fISPDElement = new AliHLTEveISPD();
117   fISPDElement->SetEventManager(this);
118
119   fISDDElement = new AliHLTEveISDD();
120   fISDDElement->SetEventManager(this);
121
122   fISSDElement = new AliHLTEveISSD();
123   fISSDElement->SetEventManager(this);
124
125   fTRDElement = new AliHLTEveTRD();
126   fTRDElement->SetEventManager(this);
127
128 }
129
130 //##################################################################################
131 AliEveHOMERManager::~AliEveHOMERManager() {
132  // see header file for class documentation 
133
134   DestroyElements();
135   DestroyDetectorElements();
136
137 }
138
139
140
141 void AliEveHOMERManager::DestroyDetectorElements(){
142   //See header file for documentation
143   if (fSrcList)
144     delete fSrcList;
145   fSrcList = NULL;
146
147   if (fPhosElement)
148     delete fPhosElement;
149   fPhosElement = NULL;
150
151   if(fEmcalElement)
152     delete fEmcalElement;
153   fEmcalElement = NULL;
154
155   if(fTPCElement)
156     delete fTPCElement;
157   fTPCElement = NULL;
158
159   if(fHLTElement)
160     delete fHLTElement;
161   fHLTElement = NULL;
162
163   if(fITSElement)
164     delete fITSElement;
165   fITSElement = NULL;
166
167   if(fISSDElement)
168     delete fISSDElement;
169   fISSDElement = NULL;
170
171   if(fISDDElement)
172     delete fISDDElement;
173   fISDDElement = NULL;
174
175   if(fISPDElement)
176     delete fISPDElement;
177   fISPDElement = NULL;
178
179   if(fTRDElement)
180     delete fTRDElement;
181   fTRDElement = NULL;
182
183   if(fMuonElement)
184     delete fMuonElement;
185   fMuonElement = NULL;
186  
187   if(fAnyElement)
188     delete fAnyElement;
189   fAnyElement = NULL;
190   
191
192 }
193
194
195
196 /*
197  * ---------------------------------------------------------------------------------
198  *                                 Source Handling
199  * ---------------------------------------------------------------------------------
200  */
201
202 //##################################################################################
203 Int_t AliEveHOMERManager::CreateEveSourcesList() {
204   // see header file for class documentation
205
206   DestroyElements();
207
208   Int_t iResult = CreateSourcesList();
209
210   //  fStateHasChanged = kTRUE;
211   
212   HLTDebug(Form("iResult XXX %d", iResult));
213   if ( iResult )
214     return iResult;
215
216
217   HLTDebug(Form("iResult %d", iResult));
218   if (fSrcList) {
219     HLTInfo("delete source list");
220     DestroyElements();
221     //delete fSrcList;
222     fSrcList = NULL;
223     //fSrcList->Clear();
224     HLTInfo("cleared source list");
225   }
226
227
228   // -- Create new AliEVE sources list 
229   if(!fSrcList){
230     HLTInfo("no source list");
231     fSrcList = new AliEveHOMERSourceList("HLT Sources");
232     fSrcList->SetManager(this);
233     
234     AddElement(fSrcList);
235   }
236   
237   //HLTInfo(Form("createbytype", iResult));
238   fSrcList->CreateByDet();
239   
240   HLTDebug(Form("Done createing source list %d", iResult));    
241   
242   
243   
244   return iResult;
245 }
246
247 //##################################################################################
248 Int_t AliEveHOMERManager::CreateEveSourcesListLoop() {
249   // see header file for class documentation
250
251   Int_t iResult = 0;
252
253   for ( Int_t retry = 0; retry < fRetryCount ; retry++ ) {
254
255     iResult = CreateEveSourcesList();
256
257     if (!iResult) {
258       HLTInfo("Source list successfully created.");
259       break;
260     }
261     else if (iResult == 1) {
262       HLTWarning( Form("Couldn't find active services, sleeping %d s before making attempt %d out of %d", fRetrySleeptime, retry, fRetryCount) ) ;
263     }   
264     else if (iResult == 2) {
265       HLTWarning( Form("Services List empty, sleeping %d s before making new attempt.", fRetrySleeptime) ) ;
266     }
267     else {
268       HLTError( Form("Other problem ... \n") ); 
269       return iResult;
270     } 
271
272     //fSourceListTimer->Start(fRetrySleeptime, kFALSE);
273     sleep(fRetrySleeptime);
274
275   }
276
277   if ( iResult ) {
278     HLTWarning( Form("Couldn't find active services.") );
279     return iResult;
280   } 
281   
282   return iResult;
283 }
284
285 //##################################################################################
286 Int_t AliEveHOMERManager::ConnectEVEtoHOMER( TString detector ) {
287   // see header file for class documentation
288
289   HLTInfo("");
290   fStateHasChanged = fSrcList->GetSelectedSources();
291   HLTInfo(Form("has state changed % d", fStateHasChanged));
292   return ConnectHOMER(detector);
293 }
294
295
296 //##################################################################################
297 Int_t AliEveHOMERManager::ReConnectHOMER( TString /*detector*/ ){
298   // see header file for class documentation
299   
300   Int_t iResult = 0;
301
302   DisconnectHOMER();
303   iResult = CreateEveSourcesListLoop();
304   HLTInfo("Created new source list, reconnect to HOMER");
305   iResult = ConnectEVEtoHOMER();
306   if ( iResult ) {
307     HLTError(Form("Error reconnecting."));
308   }
309
310   return iResult;
311 }
312
313
314 //_____________________________________________________________________________________
315 Int_t AliEveHOMERManager::NextHOMEREvent() {
316   //See header file for documentation  
317   Int_t iResult = 0;
318
319   
320  
321   if ( NextEvent() ) {
322     
323     HLTInfo("Failed getting next event, trying to reconnect");
324     iResult = ReConnectHOMER();
325     return NextHOMEREvent();
326   }
327  
328   return ProcessEvent();
329  
330 }
331
332
333 //______________________________________________________________________________________________
334 Int_t AliEveHOMERManager::ProcessEvent() {
335
336   //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)
337   ResetDisplay();
338  
339
340   AliHLTHOMERBlockDesc * block = NULL;
341
342
343   //Process the SYNCED block list
344   if ( GetBlockList() == NULL) {
345     printf ("onlineDisplay:   No regular BlockList ... \n");
346     cout << endl;
347     //return -1;
348    
349   } else {
350     
351     if (GetBlockList()->IsEmpty() ) {
352       printf ("onlineDisplay:   No Sync Blocks in list ... \n");
353       cout<<endl;
354       //return;
355     }  
356    
357     
358     TIter next(GetBlockList());
359     while ((block = (AliHLTHOMERBlockDesc*)next())) {
360       ProcessBlock(block);
361      
362     } 
363   }
364
365
366   //Read out histograms and elements from detectors outside physics 1 partition
367   TIter anext(GetAsyncBlockList());
368
369   while ( (block = (AliHLTHOMERBlockDesc*)anext()) ) {
370     ProcessBlock(block);
371   }
372   
373   UpdateDisplay();
374
375   return 0;
376
377 }
378
379 void  AliEveHOMERManager::UpdateDisplay() {
380   //See header file for documentation
381   fPhosElement->UpdateElements();
382   fEmcalElement->UpdateElements();
383   fTPCElement->UpdateElements();
384   fHLTElement->UpdateElements();
385   fITSElement->UpdateElements();
386   fISSDElement->UpdateElements();
387   fISDDElement->UpdateElements();
388   fISPDElement->UpdateElements();
389   fTRDElement->UpdateElements();
390   if(fAnyElement) fAnyElement->UpdateElements();
391   if(fMuonElement) fMuonElement->UpdateElements();
392
393
394   // -- Set EventID in Window Title  
395   TString winTitle("Eve Main Window -- Event ID : ");
396   winTitle += Form("0x%llu ", GetEventID() );
397   GetEveManager()->GetBrowser()->SetWindowName(winTitle);
398
399   //==============================================================================
400   // -- Import global scene into projection scenes
401   //==============================================================================
402
403   // XXX Primary vertex ... to be retrieved from the ESD
404   Double_t x[3] = { 0, 0, 0 };
405   
406   TEveElement* top = GetEveManager()->GetCurrentEvent();
407   
408   if (fRPhiManager && top) {
409     fRPhiEventScene->DestroyElements();
410     if (fCenterProjectionsAtPrimaryVertex)
411       fRPhiManager->SetCenter(x[0], x[1], x[2]);
412     fRPhiManager->ImportElements(top, fRPhiEventScene);
413   }
414   
415   if (fRhoZManager && top) {
416     fRhoZEventScene->DestroyElements();
417     if (fCenterProjectionsAtPrimaryVertex)
418       fRhoZManager->SetCenter(x[0], x[1], x[2]);
419     fRhoZManager->ImportElements(top, fRhoZEventScene);
420   }
421
422
423   //Redraw the display
424   GetEveManager()->Redraw3D(0,1); // (0, 1)
425   GetEveManager()->EnableRedraw(); 
426
427 }
428
429 void AliEveHOMERManager::ProcessBlock(AliHLTHOMERBlockDesc * block) {
430   //See header file for documentation
431   
432 #if 0//DEBUG
433   printf( "------------------- xxxxxxxxxxxxxxx ----------------------\n");
434   printf( "Detector           : %s\n", block->GetDetector().Data() );
435   printf( "Datatype           : %s\n", block->GetDataType().Data() );
436   if (block->IsTObject() )
437     printf( "Is TObject of class: %s\n", block->GetClassName().Data() );
438   printf( "------------------- xxxxxxxxxxxxxxx ----------------------\n");
439 #endif
440
441
442   if(fShowBarrel) {
443
444     if ( ! block->GetDetector().CompareTo("PHOS") ) 
445       fPhosElement->ProcessBlock(block);
446     
447     else if ( ! block->GetDetector().CompareTo("EMCA") ) 
448       fEmcalElement->ProcessBlock(block);
449   
450     else if ( ! block->GetDetector().CompareTo("TPC") ) 
451       fTPCElement->ProcessBlock(block);
452   
453     else if ( ! block->GetDetector().CompareTo("HLT") ) 
454       fHLTElement->ProcessBlock(block);
455   
456     else if ( ! block->GetDetector().CompareTo("ITS") ) 
457       fITSElement->ProcessBlock(block);
458   
459     else if ( ! block->GetDetector().CompareTo("ISDD") ) 
460       fISDDElement->ProcessBlock(block);
461   
462     else if ( ! block->GetDetector().CompareTo("ISPD") ) 
463       fISPDElement->ProcessBlock(block);
464   
465     else if ( ! block->GetDetector().CompareTo("ISSD") ) 
466       fISSDElement->ProcessBlock(block);
467
468     else if ( ! block->GetDetector().CompareTo("TRD") ) 
469       fTRDElement->ProcessBlock(block);
470    
471     else if ( ! block->GetDetector().CompareTo("MUON") ) {
472       //Do Nothing
473        
474
475     } else {
476       if(!fAnyElement) {
477         fAnyElement = new AliHLTEveAny();
478         fAnyElement->SetEventManager(this);
479       } 
480       fAnyElement->ProcessBlock(block);
481     }
482      
483   }
484
485    
486   if(fShowMuon) {
487     if ( ! block->GetDetector().CompareTo("MUON") ) {
488       if(!fMuonElement) {
489         fMuonElement = new AliHLTEveMuon();
490         fMuonElement->SetEventManager(this);
491       }
492       fMuonElement->ProcessBlock(block);
493     }
494   }
495
496 }
497
498 void AliEveHOMERManager::ResetDisplay () {
499   //See header file for documentation
500
501  if(fPhosElement)
502    fPhosElement->ResetElements();
503  
504  if(fEmcalElement)
505    fEmcalElement->ResetElements();
506  
507  if(fTPCElement)
508    fTPCElement->ResetElements();
509  
510  if(fHLTElement)
511    fHLTElement->ResetElements();
512  
513  if(fITSElement)
514    fITSElement->ResetElements();
515  
516  if(fISPDElement)
517    fISPDElement->ResetElements();
518  
519  if(fISDDElement)
520    fISDDElement->ResetElements();
521  
522  if(fISSDElement)
523    fISSDElement->ResetElements();
524
525  if (fTRDElement)
526    fTRDElement->ResetElements();
527
528  if(fAnyElement)
529    fAnyElement->ResetElements();
530
531  if(fMuonElement)
532    fMuonElement->ResetElements();
533
534 }
535
536
537 void AliEveHOMERManager::PrintScreens() {
538   //See header file for documentation
539
540   fEveManager->GetDefaultGLViewer()->SavePicture(Form("0x%llu_3D.gif", GetEventID()));
541   fRhoZViewer->GetGLViewer()->SavePicture(Form("0x%llu_RhoZ.gif", GetEventID()));
542   fRPhiViewer->GetGLViewer()->SavePicture(Form("0x%llu_RPhi.gif", GetEventID()));
543
544 }
545
546 void AliEveHOMERManager::StartLoop() {
547   //See header file for documentation
548   //fTimer->SetCommand("NextEvent()", "AliEveHOMERManager", this);
549   SetEventLoopStarted(kTRUE);
550   fTimer->Start(10000);
551 }
552
553 void AliEveHOMERManager::StopLoop() {
554   //See header file for documentation
555   fTimer->Stop();
556   SetEventLoopStarted(kFALSE);
557 }
558
559 // void AliEveHOMERManager::TimeOut(Int_t sec) {
560   
561 //   TTimer t(sec*1000, kFALSE);
562
563 //   cout << "Start timer for " << sec << " seconds" << endl;
564
565 //   while (!t.CheckTimer(gSystem->Now()))
566 //     gSystem->Sleep(100);  // 100 ms sleep
567
568 //   cout << "Timed out." << endl;
569
570 // }