Merge branch 'displayDevel'
[u/mrichter/AliRoot.git] / EVE / EveHLT / AliEveHOMERManager.cxx
CommitLineData
a82a31af 1//-*- Mode: C++ -*-
2
d810d0de 3// $Id$
33791895 4// Main authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007 *
fd31e9de 5// Author: Jochen Thaeder <thaeder@kip.uni-heidelberg.de> *
33791895 6// Author: 2010 Svein Lindal <slindal@fys.uio.no> *
fd31e9de 7// for The ALICE HLT Project. *
059c30e4 8
a82a31af 9
7279ee15 10
d810d0de 11/** @file AliEveHOMERManager.cxx
33791895 12 @author Jochen Thaeder, Svein Lindal <slindal@fys.uio.no>
51346b82 13 @date
cfa641b1 14 @brief Manager for HOMER online
059c30e4 15*/
16
17#if __GNUC__>= 3
18 using namespace std;
19#endif
20
9e78371d 21#include "unistd.h"
33791895 22#include "TEveManager.h"
23#include "TTimer.h"
24#include "TEveScene.h"
25#include "TEveProjectionManager.h"
26#include "TEveBrowser.h"
bf1911d5 27#include "TGLViewer.h"
28#include "TEveViewer.h"
33791895 29
d810d0de 30#include "AliEveHOMERManager.h"
cfa641b1 31#include "AliHLTHOMERBlockDesc.h"
cfa641b1 32#include "AliHLTHOMERManager.h"
33#include "AliHLTTriggerDecision.h"
33791895 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"
a15e6d7d 48
d810d0de 49ClassImp(AliEveHOMERManager)
a82a31af 50
059c30e4 51/*
52 * ---------------------------------------------------------------------------------
51346b82 53 * Constructor / Destructor
54 * ---------------------------------------------------------------------------------
059c30e4 55 */
a82a31af 56
059c30e4 57//##################################################################################
a82a31af 58AliEveHOMERManager::AliEveHOMERManager() :
33791895 59TEveElementList("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),
bf1911d5 70 fRhoZViewer(NULL),
71 fRPhiViewer(NULL),
33791895 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)
cfa641b1 89{
33791895 90 // see header file for class documentation
a82a31af 91 // or
92 // refer to README to build package
93 // or
94 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
33791895 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
059c30e4 128}
129
059c30e4 130//##################################################################################
d810d0de 131AliEveHOMERManager::~AliEveHOMERManager() {
a82a31af 132 // see header file for class documentation
059c30e4 133
33791895 134 DestroyElements();
135 DestroyDetectorElements();
136
137}
138
139
140
141void AliEveHOMERManager::DestroyDetectorElements(){
142 //See header file for documentation
a82a31af 143 if (fSrcList)
46eadbb4 144 delete fSrcList;
145 fSrcList = NULL;
33791895 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
059c30e4 192}
193
33791895 194
195
059c30e4 196/*
197 * ---------------------------------------------------------------------------------
7279ee15 198 * Source Handling
51346b82 199 * ---------------------------------------------------------------------------------
059c30e4 200 */
201
202//##################################################################################
a82a31af 203Int_t AliEveHOMERManager::CreateEveSourcesList() {
204 // see header file for class documentation
059c30e4 205
059c30e4 206 DestroyElements();
059c30e4 207
a82a31af 208 Int_t iResult = CreateSourcesList();
33791895 209
210 // fStateHasChanged = kTRUE;
46eadbb4 211
dd407e8c 212 HLTDebug(Form("iResult XXX %d", iResult));
a82a31af 213 if ( iResult )
059c30e4 214 return iResult;
51346b82 215
33791895 216
dd407e8c 217 HLTDebug(Form("iResult %d", iResult));
33791895 218 if (fSrcList) {
a5af8000 219 HLTInfo("delete source list");
33791895 220 DestroyElements();
221 //delete fSrcList;
222 fSrcList = NULL;
223 //fSrcList->Clear();
a5af8000 224 HLTInfo("cleared source list");
33791895 225 }
226
51346b82 227
a82a31af 228 // -- Create new AliEVE sources list
33791895 229 if(!fSrcList){
a5af8000 230 HLTInfo("no source list");
33791895 231 fSrcList = new AliEveHOMERSourceList("HLT Sources");
232 fSrcList->SetManager(this);
a82a31af 233
33791895 234 AddElement(fSrcList);
235 }
dd407e8c 236
237 //HLTInfo(Form("createbytype", iResult));
33791895 238 fSrcList->CreateByDet();
dd407e8c 239
240 HLTDebug(Form("Done createing source list %d", iResult));
241
242
33791895 243
059c30e4 244 return iResult;
245}
246
059c30e4 247//##################################################################################
9e78371d 248Int_t AliEveHOMERManager::CreateEveSourcesListLoop() {
a82a31af 249 // see header file for class documentation
059c30e4 250
251 Int_t iResult = 0;
9e78371d 252
253 for ( Int_t retry = 0; retry < fRetryCount ; retry++ ) {
33791895 254
9e78371d 255 iResult = CreateEveSourcesList();
33791895 256
257 if (!iResult) {
258 HLTInfo("Source list successfully created.");
9e78371d 259 break;
33791895 260 }
9e78371d 261 else if (iResult == 1) {
cfa641b1 262 HLTWarning( Form("Couldn't find active services, sleeping %d s before making attempt %d out of %d", fRetrySleeptime, retry, fRetryCount) ) ;
9e78371d 263 }
264 else if (iResult == 2) {
33791895 265 HLTWarning( Form("Services List empty, sleeping %d s before making new attempt.", fRetrySleeptime) ) ;
9e78371d 266 }
267 else {
268 HLTError( Form("Other problem ... \n") );
269 return iResult;
270 }
33791895 271
272 //fSourceListTimer->Start(fRetrySleeptime, kFALSE);
9e78371d 273 sleep(fRetrySleeptime);
33791895 274
9e78371d 275 }
276
277 if ( iResult ) {
703482d8 278 HLTWarning( Form("Couldn't find active services.") );
9e78371d 279 return iResult;
280 }
a82a31af 281
9e78371d 282 return iResult;
283}
059c30e4 284
9e78371d 285//##################################################################################
703482d8 286Int_t AliEveHOMERManager::ConnectEVEtoHOMER( TString detector ) {
9e78371d 287 // see header file for class documentation
059c30e4 288
33791895 289 HLTInfo("");
9e78371d 290 fStateHasChanged = fSrcList->GetSelectedSources();
33791895 291 HLTInfo(Form("has state changed % d", fStateHasChanged));
703482d8 292 return ConnectHOMER(detector);
059c30e4 293}
cfa641b1 294
33791895 295
296//##################################################################################
8b21b920 297Int_t AliEveHOMERManager::ReConnectHOMER( TString /*detector*/ ){
33791895 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//_____________________________________________________________________________________
315Int_t AliEveHOMERManager::NextHOMEREvent() {
316 //See header file for documentation
317 Int_t iResult = 0;
318
319
33791895 320
321 if ( NextEvent() ) {
322
323 HLTInfo("Failed getting next event, trying to reconnect");
324 iResult = ReConnectHOMER();
325 return NextHOMEREvent();
326 }
33791895 327
3da168a7 328 return ProcessEvent();
329
330}
331
332
333//______________________________________________________________________________________________
334Int_t AliEveHOMERManager::ProcessEvent() {
335
33791895 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();
3da168a7 338
339
340 AliHLTHOMERBlockDesc * block = NULL;
341
342
33791895 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());
33791895 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()) ) {
33791895 370 ProcessBlock(block);
33791895 371 }
372
373 UpdateDisplay();
374
375 return 0;
376
377}
378
379void 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
33791895 395 TString winTitle("Eve Main Window -- Event ID : ");
4ca062cf 396 winTitle += Form("0x%lu ", GetEventID() );
33791895 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
429void AliEveHOMERManager::ProcessBlock(AliHLTHOMERBlockDesc * block) {
430 //See header file for documentation
431
bf1911d5 432#if 0//DEBUG
33791895 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
498void 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
bf1911d5 537void AliEveHOMERManager::PrintScreens() {
538 //See header file for documentation
539
4ca062cf 540 fEveManager->GetDefaultGLViewer()->SavePicture(Form("0x%lu_3D.gif", GetEventID()));
541 fRhoZViewer->GetGLViewer()->SavePicture(Form("0x%lu_RhoZ.gif", GetEventID()));
542 fRPhiViewer->GetGLViewer()->SavePicture(Form("0x%lu_RPhi.gif", GetEventID()));
bf1911d5 543
544}
545
33791895 546void AliEveHOMERManager::StartLoop() {
547 //See header file for documentation
548 //fTimer->SetCommand("NextEvent()", "AliEveHOMERManager", this);
549 SetEventLoopStarted(kTRUE);
4ea94afd 550 fTimer->Start(10000);
33791895 551}
552
553void 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// }