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