]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/gui/src/AliHLTGUI.cxx
imported version 1.5
[u/mrichter/AliRoot.git] / HLT / TPCLib / gui / src / AliHLTGUI.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Authors: Jochen Thaeder <thaeder@kip.uni-heidelberg.de>                *
5  *          for The ALICE Off-line Project.                               *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /** @file   AliHLTGUI.cxx
17     @author Jochen Thaeder
18     @date   
19     @brief  Qt class for ALICE HLT online Display
20 */
21
22 #if __GNUC__>= 3
23 using namespace std;
24 #endif
25
26 #include <Rtypes.h>
27
28 #include "AliHLTGUI.h"
29 #include "AliHLTTPCDisplayMain.h"
30 #include "AliHLTLogging.h"
31 #include "AliHLTTPCDigitReaderRaw.h"
32
33 #include <TQtWidget.h>
34
35 #include <qlabel.h>
36 #include <qcheckbox.h>
37 #include <qspinbox.h>
38 #include <qbuttongroup.h>
39 #include <qgroupbox.h>
40 #include <qpushbutton.h>
41 #include <qlineedit.h>
42 #include <qlistview.h>
43 #include <qslider.h>
44 #include <qtabwidget.h>
45 #include <qtimer.h>
46
47 #include <sys/stat.h>
48 #include <fcntl.h>
49 #include <unistd.h>
50 #include <cstring>
51 #include <cerrno>
52 #include <iostream>
53 #include <vector>
54
55
56 // -- standard constructor
57 //____________________________________________________________________________________________________
58 AliHLTGUI::AliHLTGUI()
59   :
60   fDisplay(NULL),
61   fHostnames(),
62   fPorts(),
63   padrowWidget(NULL),
64   padWidget(NULL),
65   residualsWidget(NULL),
66   chargeWidget(NULL),
67   threeDWidget(NULL),
68   frontWidget(NULL),
69   hits_sWidget(NULL),
70   q_trackWidget(NULL),
71   q_sWidget(NULL),
72   padrow_padWidget(NULL),
73   fEventLoop(NULL) 
74 {
75 }
76
77 // -- not a valid copy constructor, defined according to effective C++ style
78 //____________________________________________________________________________________________________
79 AliHLTGUI::AliHLTGUI(const AliHLTGUI& srcGUI)
80   :
81   fDisplay(srcGUI.fDisplay),
82   fHostnames(srcGUI.fHostnames),
83   fPorts(srcGUI.fPorts),
84   padrowWidget(srcGUI.padrowWidget),
85   padWidget(srcGUI.padWidget),
86   residualsWidget(srcGUI.residualsWidget),
87   chargeWidget(srcGUI.chargeWidget),
88   threeDWidget(srcGUI.threeDWidget),
89   frontWidget(srcGUI.frontWidget),
90   hits_sWidget(srcGUI.hits_sWidget),
91   q_trackWidget(srcGUI.q_trackWidget),
92   q_sWidget(srcGUI.q_sWidget),
93   padrow_padWidget(srcGUI.padrow_padWidget),
94   fEventLoop(srcGUI.fEventLoop) 
95 {
96   HLTFatal("copy constructor not implemented");
97 }
98
99 // -- not a valid assignment op, but defined according to effective C++ style
100 //____________________________________________________________________________________________________
101 AliHLTGUI& AliHLTGUI::operator=(const AliHLTGUI&) {
102   HLTFatal("assignment operator not implemented");
103   return (*this);
104 }
105
106 // -- constructor
107 //____________________________________________________________________________________________________
108 AliHLTGUI::AliHLTGUI( Int_t argc, Char_t **argv )
109   :
110   fDisplay(NULL),
111   fHostnames(),
112   fPorts(),
113   padrowWidget(NULL),
114   padWidget(NULL),
115   residualsWidget(NULL),
116   chargeWidget(NULL),
117   threeDWidget(NULL),
118   frontWidget(NULL),
119   hits_sWidget(NULL),
120   q_trackWidget(NULL),
121   q_sWidget(NULL),
122   padrow_padWidget(NULL),
123   fEventLoop(NULL) 
124 {
125   cout << "Creating display" << endl;
126
127   // Set Widgets 
128   padrowWidget = tQtWidgetPadRow; 
129   residualsWidget = tQtWidgetResiduals;
130   threeDWidget = tQtWidget3D;
131   padWidget  = tQtWidgetPad; 
132   chargeWidget = tQtWidgetCharge;
133   frontWidget = tQtWidgetFront;
134   hits_sWidget = tQtWidgetHits_s;
135   q_trackWidget = tQtWidgetq_track;
136   q_sWidget = tQtWidgetQ_s;
137   padrow_padWidget = tQtWidgetPadRow_Pad;
138   
139   AliHLTTPCDisplayMain* display = new AliHLTTPCDisplayMain((void*) this, &AliHLTGUI::callback_setGUIPad);
140   if ( !display ) { 
141     HLTFatal( "ERROR no Display!" );
142     exit(-1);
143   }
144    
145   fDisplay = (void*)display;
146
147
148 #if STEP1
149
150   display->RegisterCanvas( charge, chargeWidget->GetCanvas() );
151   display->RegisterCanvas( padrow, padrowWidget->GetCanvas() );
152   display->RegisterCanvas( threeD, threeDWidget->GetCanvas() );
153   display->RegisterCanvas( pad, padWidget->GetCanvas() );
154   display->RegisterCanvas( residuals, residualWidget->GetCanvas() );
155   display->RegisterCanvas( front, frontWidget->GetCanvas() );
156   display->RegisterCanvas( hits_s, hits_sWidget->GetCanvas() );
157   display->RegisterCanvas( q_track, q_trackWidget->GetCanvas() );
158   display->RegisterCanvas( q_s, q_sWidget->GetCanvas() );
159   display->RegisterCanvas( padrow_pad, padrow_padWidget->GetCanvas() );
160
161 #else
162   // Set Canvas  // TODO : REDO with enum
163   display->SetCanvasCharge(chargeWidget->GetCanvas());
164   display->SetCanvasPadRow(padrowWidget->GetCanvas());
165   display->SetCanvas3D(threeDWidget->GetCanvas());
166   display->SetCanvasPad(padWidget->GetCanvas());
167   display->SetCanvasResiduals(residualsWidget->GetCanvas());
168   display->SetCanvasFront(frontWidget->GetCanvas());
169   display->SetCanvasHits_S(hits_sWidget->GetCanvas());  
170   display->SetCanvasQ_Track(q_trackWidget->GetCanvas());                
171   display->SetCanvasQ_S(q_sWidget->GetCanvas());
172 #if ALIHLTTPCDISPLAY_VERSION >= 2
173   display->SetCanvasPadRow_Pad(padrow_padWidget->GetCanvas());
174 #endif
175
176 #endif
177
178
179   // -- Timer for Event-Loop
180   // -----------------------
181   fEventLoop = new QTimer( this );
182   if ( !fEventLoop ) { 
183     HLTFatal( "ERROR no QTimer" );
184     exit(-1);
185   }
186
187   connect( fEventLoop, SIGNAL(timeout()),this, SLOT(nextEvent()) );
188
189   // -- read commandline arguments and set values in AliHLTTPCDiplayMain
190   // -------------------------------------------------------------------
191   Int_t ii = 0;
192   Char_t* cpErr;                     // error string
193   Int_t errocc = 0;                  // check if error occured
194   Bool_t connectToSource = kFALSE;   // check if connect to source on startup
195
196 #if 0
197   while ( ii < argc ) {      
198
199     // -- raw reader mode
200     if ( !strcmp( argv[ii], "-rawreadermode" ) ) {
201       if ( argc <= ii+1 ) {
202         HLTError( "Raw Reader Mode not specified" );
203         errocc = ENOTSUP;
204         break;
205       }
206         
207       //      Int_t readerMode = AliHLTTPCDigitReaderRaw::DecodeMode( argv[ii+1] );
208       //      Int_t readerMode = AliHLTTPCDigitReaderRaw::DecodeMode( 1 );
209       Int_t readerMode = 0;
210       if (readerMode < 0){
211         HLTError ("Cannot convert rawreadermode specifier '%s'", argv[ii+1]);
212         errocc = EINVAL;
213         break;
214       }
215       
216       //      display->SetRawReaderMode( readerMode );
217       
218       ii += 2;
219       continue;
220     }
221     
222     // -- zero suppression threshold
223     if ( !strcmp( argv[ii], "-adc-threshold" ) ) {
224       if ( argc <= ii+1 ) {
225         HLTError( "adc-threshold not specified" );
226         errocc = ENOTSUP;
227         break;
228       }
229       
230       Int_t sigThresh = strtoul( argv[ii+1], &cpErr ,0 );
231       if ( *cpErr ) {
232         HLTError("Cannot convert adc-threshold specifier '%s'.", argv[ii+1]);
233         errocc = EINVAL;
234         break;
235       }
236
237       //      display->SetZeroSuppressionThreshold(sigThresh);
238       
239       ii+=2;
240       continue;
241     }
242
243     // -- pad occupancy limit
244     if ( !strcmp( argv[ii], "-occupancy-limit" ) ) {
245       if ( argc <= ii+1 ) {
246         HLTError( "occupancy-limit not specified" );
247         errocc = ENOTSUP;
248         break;
249       }
250       
251       Float_t occuLimit = strtof( argv[ii+1], &cpErr );
252       if ( *cpErr ) {
253         HLTError("Cannot convert occupancy-limit  specifier '%s'.", argv[ii+1]);
254         errocc = EINVAL;
255         break;
256       }
257       
258       //      display->SetOccupancyLimit(occuLimit);
259       
260       ii+=2;
261       continue;
262     }
263     
264     // -- B field
265     if ( !strcmp( argv[ii], "-b-field" ) ) {
266       if ( argc <= ii+1 ) {
267         HLTError( "b-field not specified" );
268         errocc = ENOTSUP;
269         break;
270       }
271       
272       Float_t bfield = strtof( argv[ii+1], &cpErr );
273       if ( *cpErr ) {
274         HLTError("Cannot convert b-field specifier '%s'.", argv[ii+1]);
275         errocc = EINVAL;
276         break;
277       }
278       
279       //      display->SetBField( bfield )
280         
281         ii+=2;
282       continue;
283     }
284     
285     // -- N Time Bins
286     if ( !strcmp( argv[ii], "-n-time-bins" ) ) {
287       if ( argc <= ii+1 ) {
288         HLTError( "n-time-bins not specified" );
289         errocc = ENOTSUP;
290         break;
291       }
292
293       Int_t nTimeBins = strtoul( argv[ii+1], &cpErr ,0);
294       // check if already a number, if not check if "tpc" or "sim"
295       if ( *cpErr ) {
296         if ( !strcmp( argv[ii+1], "sim" ) ) 
297           nTimeBins = 442;        
298         else if  ( !strcmp( argv[ii+1], "tpc") ) 
299           nTimeBins = 1024;
300         else {
301           HLTError("Cannot convert n-time-bins specifier '%s'.", argv[ii+1]);
302           errocc = EINVAL;
303           break;
304         }
305       }
306       
307       //      display->SetNTimeBins( nTimeBins );
308       
309       ii+=2;
310       continue;
311     }
312
313     // -- TCP soucre
314     if ( !strcmp( argv[ii], "-tcp-source" ) ) {
315       if ( argc <= ii+1 ) {
316         HLTError( "-tcp-source not specified" );
317         errocc = ENOTSUP;
318         break;
319       }
320       
321       Int_t sourceCount = 1;
322
323       while ( 1 ){
324         // break if more argc is exceeded
325         if ( argc <= ii+sourceCount ) break;
326
327         // check is next is new option and source count != 1 ( because at least 1 host:port is needed)
328         if ( strstr( argv[ii + sourceCount], "-" ) ) {
329           if ( sourceCount == 1 ){
330             HLTError( "-tcp-source not specified" );
331             errocc = ENOTSUP;
332           }
333           break;
334         }
335
336         // break if argument is no host:port
337         if ( !strstr( argv[ii + sourceCount], ":" ) ) break;
338
339         Char_t *host = strtok( argv[ii + sourceCount], ":" );
340         Char_t *port = strtok( NULL, ":" );
341
342         if ( !port ) {    
343           HLTError("Cannot convert tcp-source specifier '%s'.", argv[ii+1]);
344           errocc = EINVAL;
345           break;
346         }
347
348         // push in vector
349         fHostnames.push_back( host );
350         fPorts.push_back( port );
351     
352         // write in List
353         QListViewItem * item1 = new QListViewItem( hostListView, host, port );
354         hostListView->insertItem(item1);
355
356         sourceCount++;
357       } // while ( 1 ) {
358
359       if  ( errocc != 0 ) break;
360       
361       ii += sourceCount;
362       continue;
363     }
364
365     // -- Connect
366     if ( !strcmp( argv[ii], "--connect" ) ) {
367       
368       connectToSource = kTRUE;
369
370       ii++;
371       continue;
372     }
373
374     // -- Help
375     if ( !strcmp( argv[ii], "--help" ) ) {
376       cout << "Usage: AliHLTGUI [OPTON VALUE] ..." << endl;
377       cout << " OPTIONs:\n --------" << endl;
378       cout << " -rawreadermode <mode>              Sets the mode for AliHLTDigitReaderRaw, can bei either digit or string." << endl;
379       cout << " -n-time-bins <mode>                Sets number of TimeBins for the TPC, can bei either a digit, 'sim' or 'tpc'." << endl;
380       cout << " -adc-threshold <mode>              Sets the ADC Threshold for the Zero-Suppression of raw data, should be ADC counts." << endl;
381       cout << " -occupancy-limit <mode>            Sets the Occupancy limits for pads, wherby <mode> is [0,1]." << endl;
382       cout << " -b-field <mode>                    Sets the B-field." << endl;
383       cout << " -tcp-source <host:port> ...        Sets Host and Ports to a TCP port of a TCPDumpSubscriber. Multiple Connections can be given." << endl;
384       cout << " -connect                           Connects already to given TCP-Sources." << endl;
385       cout << " --help                             Shows the Help Menu." << endl;
386       cout << " --version                          Prints version of AliHLTGUI" << endl;
387       
388       exit (0);
389     }
390     
391     // -- Version
392     if ( !strcmp( argv[ii], "--version" ) ) {
393       cout << "Version of AliHLTGUI: " << PACKAGE_VERSION << endl;
394       
395       exit (0);
396     }
397
398     // -- Unknown Option
399     HLTError( "Unknown Option", "Unknown option '%s'", argv[ii] );
400     errocc = EINVAL;
401     break;
402   } // end while ( ii < argc ) {      
403
404 #endif
405
406   // if error occured: Print usage and exit
407   if ( errocc != 0 ) {
408     cout << "Usage: AliHLTGUI [OPTON VALUE] ..." << endl;
409     cout << " OPTIONs:\n --------" << endl;
410     cout << " -rawreadermode <mode>              Sets the mode for AliHLTDigitReaderRaw, can bei either digit or string." << endl;
411     cout << " -n-time-bins <mode>                Sets number of TimeBins for the TPC, can bei either a digit, 'sim' or 'tpc'." << endl;
412     cout << " -adc-threshold <mode>              Sets the ADC Threshold for the Zero-Suppression of raw data, should be ADC counts." << endl;
413     cout << " -occupancy-limit <mode>            Sets the Occupancy limits for pads, wherby <mode> is [0,1]." << endl;
414     cout << " -b-field <mode>                    Sets the B-field." << endl;
415     cout << " -tcp-source <host:port> ...        Sets Host and Ports to a TCP port of a TCPDumpSubscriber. Multiple Connections can be given." << endl;
416     cout << " -connect                           Connects already to given TCP-Sources." << endl;
417     cout << " --help                             Shows the Help Menu." << endl;
418     cout << " --version                          Prints version of AliHLTGUI" << endl;
419     exit( errocc );
420   }
421
422
423   if ( connectToSource ) connectDisplay();
424
425 }
426
427 //____________________________________________________________________________________________________
428 AliHLTGUI::~AliHLTGUI() {     
429   // -- destructor
430
431   if (fEventLoop)
432     delete fEventLoop;
433   fEventLoop = NULL;
434
435   AliHLTTPCDisplayMain* display = (AliHLTTPCDisplayMain*) fDisplay;
436
437   if (display)
438     delete display;
439   fDisplay = NULL;
440 }
441
442 //____________________________________________________________________________________________________
443 void AliHLTGUI::connectDisplay() {  
444     // -- connect to Display class / TCPDumpSubscriber
445
446   AliHLTTPCDisplayMain* display = (AliHLTTPCDisplayMain*)fDisplay;
447   
448
449 #ifdef STEP2
450   enableDisplay( display->GetConnectionStatus() );
451 #else
452   // if connected => diconnect
453   if ( display->GetConnectionStatus() ) {
454     cout << "Disonnecting..."    << endl;
455     display->SetConnectionStatus(kFALSE);       
456     // -- CONNECT-TAB
457     connectPushButton->setText("Connect");
458     connectTextLabel->setText("DISCONNECTED");
459     connectTextLabel->setPaletteForegroundColor(red);   
460     HostListTextLabel->setEnabled(TRUE);
461     hostListView->setEnabled(TRUE);
462     removePushButton->setEnabled(TRUE);
463     addGroupBox->setEnabled(TRUE);
464     // -- DISPLAY-TAB
465     eventGroupBox->setEnabled(FALSE);
466     
467     
468 #if ALIHLTTPCDISPLAY_VERSION >= 2
469     display->Disconnect();
470 #else
471     HLTWarning("disconnect not available for AliHLTTPCDisplay version < 2");
472 #endif
473     
474     return;
475   }
476 #endif
477
478   cout << "Connecting..."    << endl;
479
480
481   // -- Set geometry file in AliHLTTPCDisplayMain
482   // --------------------------------------------
483   Char_t * geometryPath = getenv("ALIHLT_TOPDIR");
484   Char_t * geometryFile = "alice.geom";
485   
486   Char_t geoPath[256];
487
488   strcpy(geoPath,"");
489
490   if (geometryPath) {
491     strcat(geoPath,geometryPath);
492     strcat(geoPath,"/TPCLib/OnlineDisplay");
493   }
494   else strcat(geoPath,".");
495   
496   strcat(geoPath,"/");
497   strcat(geoPath,geometryFile);
498
499   // -- Set Hostnames in AliHLTTPCDisplayMain
500   // ----------------------------------------
501   Int_t cnt = fHostnames.size();
502   
503   if (cnt == 0){
504     HLTError( "Error establishing connection: No Hostnames specified" );
505     connectTextLabel->setText("ERROR");  
506     connectTextLabel->setPaletteForegroundColor(red);
507     return;
508   }
509
510   unsigned short* ports = new unsigned short[cnt];
511   const char** hostnames = new const char*[cnt];
512
513   for ( Int_t i = 0; i < cnt; i++ ) {
514     const char * temp = fHostnames[i].latin1();
515     hostnames[i] = temp;
516     ports[i] = (unsigned short) atoi(fPorts[i]);
517   }
518
519   Int_t connect = display->Connect( cnt, (const char**) hostnames, ports, geoPath);
520   
521   delete[] ports;
522   delete[] hostnames; 
523   
524   // check return value
525   if ( connect  == 0) {
526     connectTextLabel->setText("CONNECTED");
527     connectTextLabel->setPaletteForegroundColor(green);
528   }
529   else if (connect == -1){
530     connectTextLabel->setText("NO CHAIN");
531     connectTextLabel->setPaletteForegroundColor(red);
532     return;
533     }
534   else if (connect == -2){
535     connectTextLabel->setText("TIMEOUT");
536     connectTextLabel->setPaletteForegroundColor(red);
537     return;
538   }
539   else {
540     connectTextLabel->setText("GENERAL ERROR");
541     connectTextLabel->setPaletteForegroundColor(red);
542     return;
543   }
544 #ifdef STEP3
545
546   enableDataObjects();
547 #else
548   // if raw data present
549     if ( display->ExistsRawData() ) {
550       rawZeroGroupBox->setEnabled(TRUE);
551       rawSliceGroupBox->setEnabled(TRUE);
552       padrowGroupBox->setEnabled(TRUE);
553       frontDataButtonGroup->setEnabled(TRUE);
554       frontDisplayButtonGroup->setEnabled(TRUE);
555       padrowCheckBox->setEnabled(TRUE);
556       threeDRawButtonGroup->setEnabled(TRUE);
557     }
558     else {
559       rawZeroGroupBox->setEnabled(FALSE);
560       rawSliceGroupBox->setEnabled(FALSE);
561       padrowGroupBox->setEnabled(FALSE);
562       frontDataButtonGroup->setEnabled(FALSE);
563       frontDisplayButtonGroup->setEnabled(FALSE);
564       padrowCheckBox->setEnabled(FALSE);
565       threeDRawButtonGroup->setEnabled(FALSE);
566     }
567
568
569     // if cluster data present
570     if ( display->ExistsClusterData() ) {
571         clusterCheckBox->setEnabled(TRUE);
572         clusterPropButtonGroup->setEnabled(TRUE);
573     }
574     else {
575         clusterCheckBox->setEnabled(FALSE);
576         clusterPropButtonGroup->setEnabled(FALSE);
577     }
578
579     // if track data present
580     if ( display->ExistsTrackData() ) {
581         tracksCheckBox->setEnabled(TRUE);
582         trackPropGroupBox->setEnabled(TRUE);
583         selectTrackGroupBox->setEnabled(TRUE);
584         trackParamGroupBox->setEnabled(TRUE);
585     }
586     else {
587         tracksCheckBox->setEnabled(FALSE);
588         trackPropGroupBox->setEnabled(FALSE);
589         selectTrackGroupBox->setEnabled(FALSE);
590         trackParamGroupBox->setEnabled(FALSE);
591     }
592 #endif
593
594 #ifdef STEP2
595     enableDisplay( display->GetConnectionStatus() );
596 #else
597     // -- CONNECT-TAB
598     connectPushButton->setText("Disconnect");
599     connectTextLabel->setText("READ DATA");     
600     connectTextLabel->setPaletteForegroundColor(green);
601     HostListTextLabel->setEnabled(FALSE);
602     hostListView->setEnabled(FALSE);
603     removePushButton->setEnabled(FALSE);
604     addGroupBox->setEnabled(FALSE);
605         
606     // -- DISPLAY-TAB
607     eventGroupBox->setEnabled(TRUE);
608     nextEventPushButton->setEnabled(TRUE);
609     redisplayPushButton->setEnabled(TRUE);
610     saveGroupBox->setEnabled(TRUE);
611     sectorButtonGroup->setEnabled(TRUE);
612     threeDGroupBox->setEnabled(TRUE);
613 #endif
614
615        
616     display->ReadData(kFALSE);
617     display->DisplayEvent();
618
619     Char_t eventID[256] = "";
620 #if ALIHLTTPCDISPLAY_VERSION >= 2
621     sprintf(eventID,"%Lu",display->GetEventID());
622 #endif
623     sprintf(eventID,"%Lu",0);
624     eventIDTextLabel->setText(eventID);
625
626     displayTrackParam();
627 }
628
629 //____________________________________________________________________________________________________
630 void AliHLTGUI::nextEvent(){
631   // -- Display next event
632   AliHLTTPCDisplayMain* display = (AliHLTTPCDisplayMain*)fDisplay;
633   Int_t ret = 0;
634 #if ALIHLTTPCDISPLAY_VERSION >= 2
635   ret = display->ReadData();
636 #else
637   display->ReadData();
638 #endif
639   if (ret == -1){
640     connectTextLabel->setText("NO CHAIN");
641     setPaletteForegroundColor(red);
642     
643     // Stop of Event Loop
644     if (!fEventLoop->isActive()){
645       fEventLoop->stop();
646       eventLoopPushButton->setText("Start Loop");
647     }
648     
649     return;
650   }
651   else if (ret == -2) {
652     connectTextLabel->setText("TIME OUT");    
653     connectTextLabel->setPaletteForegroundColor(red);
654
655     // Stop of Event Loop
656     if (!fEventLoop->isActive()){
657       fEventLoop->stop();
658       eventLoopPushButton->setText("Start Loop");
659     }
660
661     return;
662   }
663   else if (ret == -3) {
664     connectTextLabel->setText("GENERAL ERROR");    
665     connectTextLabel->setPaletteForegroundColor(red);
666
667     // Stop of Event Loop
668     if (!fEventLoop->isActive()){
669       fEventLoop->stop();
670       eventLoopPushButton->setText("Start Loop");
671     }
672
673     return;
674   }
675   else {
676     connectTextLabel->setText("READ DATA");    
677     connectTextLabel->setPaletteForegroundColor(green); 
678   }
679     
680   display->DisplayEvent();
681
682   Char_t eventID[256] = "";
683 #if ALIHLTTPCDISPLAY_VERSION >= 2
684   sprintf(eventID,"%Lu",display->GetEventID());
685 #endif
686   sprintf(eventID,"%Lu",0);
687   eventIDTextLabel->setText(eventID);
688
689   displayTrackParam();
690 }
691
692 //____________________________________________________________________________________________________
693 void AliHLTGUI::eventLoop(){
694     // -- Start / Stop of Event Loop
695     if (!fEventLoop->isActive()){
696         fEventLoop->start(1000 * atoi( eventLoopSpinBox->text() ) );
697         eventLoopPushButton->setText("Stop Loop");
698     }
699     else {
700         fEventLoop->stop();
701         eventLoopPushButton->setText("Start Loop");
702     }    
703 }
704
705
706 //____________________________________________________________________________________________________
707 void AliHLTGUI::enableDisplay(Bool_t connected){
708   AliHLTTPCDisplayMain* display = (AliHLTTPCDisplayMain*) fDisplay;
709   
710   Bool_t inverseconnected  = ~connected; // TODO check!!
711   
712   // if already connected => disconnect
713   // else disconnect => connect
714   
715   HostListTextLabel->setEnabled( connected );
716   hostListView->setEnabled( connected );
717   removePushButton->setEnabled( connected );
718   addGroupBox->setEnabled( connected );
719   eventGroupBox->setEnabled( inverseconnected );
720
721   if ( connected ){
722     cout << "Disonnecting..."    << endl;
723     display->SetConnectionStatus( inverseconnected );   
724     // -- CONNECT-TAB
725     connectPushButton->setText("Connect");
726     connectTextLabel->setText("DISCONNECTED");
727     connectTextLabel->setPaletteForegroundColor(red);   
728     
729 #if ALIHLTTPCDISPLAY_VERSION >= 2
730     display->Disconnect();
731 #else
732     HLTWarning("disconnect not available for AliHLTTPCDisplay version < 2");
733 #endif
734
735     return;
736   }
737
738   else { // connected = false
739     // -- CONNECT-TAB
740     connectPushButton->setText("Disconnect");
741     connectTextLabel->setText("READ DATA");     
742     connectTextLabel->setPaletteForegroundColor(green);
743         
744     // -- DISPLAY-TAB
745     nextEventPushButton->setEnabled( inverseconnected );
746     redisplayPushButton->setEnabled( inverseconnected );
747     saveGroupBox->setEnabled( inverseconnected );
748     sectorButtonGroup->setEnabled( inverseconnected );
749     threeDGroupBox->setEnabled( inverseconnected );
750   }
751   
752 }
753
754 //____________________________________________________________________________________________________
755 void AliHLTGUI::enableDataObjects(){
756   AliHLTTPCDisplayMain* display = (AliHLTTPCDisplayMain*) fDisplay;
757
758   Bool_t existsRawData = display->ExistsRawData();
759   Bool_t existsClusterData = display->ExistsClusterData();
760   Bool_t existsTrackData = display->ExistsTrackData();
761
762   // -- RAW data
763   rawZeroGroupBox->setEnabled(existsRawData);
764   rawSliceGroupBox->setEnabled(existsRawData);
765   padrowGroupBox->setEnabled(existsRawData);
766   frontDataButtonGroup->setEnabled(existsRawData);
767   frontDisplayButtonGroup->setEnabled(existsRawData);
768   padrowCheckBox->setEnabled(existsRawData);
769   threeDRawButtonGroup->setEnabled(existsRawData);
770
771   // -- CLUSTER data
772   clusterCheckBox->setEnabled(existsClusterData);
773   clusterPropButtonGroup->setEnabled(existsClusterData);
774
775   // -- TRACK data
776   tracksCheckBox->setEnabled(existsTrackData);
777   trackPropGroupBox->setEnabled(existsTrackData);
778   selectTrackGroupBox->setEnabled(existsTrackData);
779   trackParamGroupBox->setEnabled(existsTrackData);
780 }
781
782 //____________________________________________________________________________________________________
783 void AliHLTGUI::updateEventLoop(){
784     if (fEventLoop->isActive())
785         fEventLoop->changeInterval(1000 * atoi( eventLoopSpinBox->text() ) );
786 }
787
788 //____________________________________________________________________________________________________
789 void AliHLTGUI::redisplay(Bool_t newRawSlice){
790     // -- ReDisplay current event
791     AliHLTTPCDisplayMain* display = (AliHLTTPCDisplayMain*)fDisplay;
792 #if ALIHLTTPCDISPLAY_VERSION >= 2
793     display->DisplayEvent(newRawSlice);
794 #else
795     display->DisplayEvent();
796 #endif
797
798     displayTrackParam();
799 }
800
801 //____________________________________________________________________________________________________
802 void  AliHLTGUI::saveHistograms(){
803     // -- save all Histograms
804     AliHLTTPCDisplayMain* display = (AliHLTTPCDisplayMain*)fDisplay;
805     display->SaveHistograms();
806 }
807
808 //____________________________________________________________________________________________________
809 void AliHLTGUI::addHost(){    
810     // -- add host to hostlist
811     // push in vector
812     fHostnames.push_back( hostnameLineEdit->text() );
813     fPorts.push_back( portSpinBox->text() );
814     
815     // write in List
816     QListViewItem * item1 = new QListViewItem(hostListView,  hostnameLineEdit->text(), portSpinBox->text() );
817     hostListView->insertItem(item1);
818 }
819
820 //____________________________________________________________________________________________________
821 void AliHLTGUI::removeHost(){    
822     // -- remove host from hostlist
823     if (hostListView->selectedItem()) {
824         for ( unsigned i = 0; i < fHostnames.size(); i++ ) {
825             if ( fHostnames[i] == hostListView->selectedItem()->text(0)  && fPorts[i] == hostListView->selectedItem()->text(1)){
826                 fHostnames.erase( fHostnames.begin()+i );
827                 fPorts.erase( fPorts.begin()+i );
828             }
829         }       
830         delete hostListView->selectedItem();   // #########
831         //      hostListView->removeItem(hostListView->selectedItem());
832     }
833 }
834
835 //----------------------------------------------------------------------------------------------------
836 //       SETTER - minor functions
837 //____________________________________________________________________________________________________
838 void AliHLTGUI::setSector(){  
839     // -- set sectors to display
840     AliHLTTPCDisplayMain* display = (AliHLTTPCDisplayMain*)fDisplay;   
841       
842     Int_t selectSectorID = sectorButtonGroup->selectedId();
843
844     // Set ALL Sectors
845     if (selectSectorID == 0) {
846         display->SetSlices();
847         display->SetTheta(90.);
848     }
849     // Set ONE Sector
850     else if (selectSectorID == 4) {
851         display->SetSlices( atoi( oneSpinBox->text() ) );
852         display->SetTheta(0.);
853     }
854     // Set RANGE of Sectors
855     else if (selectSectorID == 1) {
856         display->SetSlices( atoi( rangeMinSpinBox->text() ) ,atoi( rangeMaxSpinBox->text() ) );
857         display->SetTheta(90.);
858     }
859     // Set PAIR of Sectors
860     else if (selectSectorID == 3) { 
861         display->SetSlicesPair(atoi( pairSpinBox->text() ) );   
862         display->SetTheta(90.);
863     }
864     // Set PAIR RANGE of Sectors
865     else if (selectSectorID == 2) {
866         display->SetSlicesPair(atoi( pairRangeMinSpinBox->text() ) ,atoi( pairRangeMaxSpinBox->text() ) );
867         display->SetTheta(90.);
868     }
869     // redisplay 3D
870     redisplay();
871 }
872
873 //____________________________________________________________________________________________________
874 void AliHLTGUI::setCluster(){    
875     // -- set used/unuse/all cluster
876     AliHLTTPCDisplayMain* display = (AliHLTTPCDisplayMain*)fDisplay;   
877
878     //  ALL Cluster = 0  | USED Cluster = 1 | UNUSED Cluster = 2
879     display->SetSelectCluster( clusterPropButtonGroup->selectedId()  );
880           
881     // redisplay 3D
882     redisplay();
883 }
884 //____________________________________________________________________________________________________
885 void AliHLTGUI::setTrack(){    
886     // -- set track properties
887     AliHLTTPCDisplayMain* display = (AliHLTTPCDisplayMain*)fDisplay;  
888
889     display->SetCutHits(atoi (cutHitsSpinBox->text() ) );
890     display->SetCutPt( (Float_t) atof (cutPtLineEdit->text() ) );
891     display->SetCutPsi( (Float_t) atof (cutPsiLineEdit->text() ) );
892     display->SetCutLambda( (Float_t) atof (cutLambdaLineEdit->text() ) );       
893     display->SetCutS( (Float_t) atof (cutSLineEdit->text() ) );
894     display->SetIncidentPadrow( (Int_t) atoi (cutPadrowLineEdit->text() ) );
895     redisplay();
896 }
897
898 //____________________________________________________________________________________________________
899 void AliHLTGUI::setInvert(){    
900     // -- set invert 3D display
901     AliHLTTPCDisplayMain* display = (AliHLTTPCDisplayMain*)fDisplay;  
902
903     display->SetInvert();
904     redisplay();
905 }
906
907 //____________________________________________________________________________________________________
908 void AliHLTGUI::setKeepView(){    
909     // -- keep angle view 
910     AliHLTTPCDisplayMain* display = (AliHLTTPCDisplayMain*)fDisplay;   
911
912     if (keepViewCheckBox->isChecked() ) display->SetKeepView(kTRUE);
913     else display->SetKeepView(kFALSE);
914 }
915
916
917 void AliHLTGUI::setZeroSuppression(){    
918     // -- set Zero Suppresion
919     AliHLTTPCDisplayMain* display = (AliHLTTPCDisplayMain*)fDisplay;   
920
921 #if ALIHLTTPCDISPLAY_VERSION >= 2
922     if (rawZeroCheckBox->isChecked() ) display->SetZeroSuppression(kTRUE);
923     else display->SetZeroSuppression(kFALSE);
924 #else
925     HLTError("function not available for AliHLTTPCDisplay version < 2");
926 #endif
927
928     redisplay();
929 }
930
931
932 //____________________________________________________________________________________________________
933 void AliHLTGUI::setRawSlice(){    
934     // -- set  slice for padrow / pad / timebin
935     AliHLTTPCDisplayMain* display = (AliHLTTPCDisplayMain*)fDisplay;   
936
937     display->SetSlicePadRow( atoi (rawSectorSpinBox->text() ) );
938     
939     redisplay(kTRUE/*newRawSlice*/);
940 }
941
942 //____________________________________________________________________________________________________
943 void AliHLTGUI::setPadRow(){    
944     // -- set padrow
945     AliHLTTPCDisplayMain* display = (AliHLTTPCDisplayMain*)fDisplay;   
946
947     display->SetPadRow(atoi (padrowSpinBox->text() ) );
948
949     padSpinBox->setMaxValue(display->GetNPads());
950     padSlider->setMaxValue(display->GetNPads());
951
952     setPad(); 
953 }
954
955 //____________________________________________________________________________________________________
956 void AliHLTGUI::setPad(){    
957     // -- set pad, or pad histograms 
958     AliHLTTPCDisplayMain* display = (AliHLTTPCDisplayMain*)fDisplay;  
959  
960     display->SetPad(atoi (padSpinBox->text() ) );
961
962     redisplay();
963 }
964
965 //____________________________________________________________________________________________________
966 void AliHLTGUI::setTimeBin(){    
967     // -- set timebins
968     AliHLTTPCDisplayMain* display = (AliHLTTPCDisplayMain*)fDisplay;  
969
970     Int_t selectTimebinID = frontDisplayButtonGroup->selectedId();
971
972 #if ALIHLTTPCDISPLAY_VERSION >= 2
973     // Set ALL TimeBins
974     if ( selectTimebinID == 3)  display->SetTimeBinMinMax(0,display->GetNTimeBins()-1 );
975
976     // Set ONE TimeBin
977     else if ( selectTimebinID == 2) display->SetTimeBinMinMax( atoi( oneTimeBinSpinBox->text() ), atoi( oneTimeBinSpinBox->text() ) );
978
979     // Set RANGE of TimeBins
980     else if ( selectTimebinID == 1) {
981       Int_t  min = atoi( minTimeBinSpinBox->text() );
982       Int_t  max = atoi( maxTimeBinSpinBox->text() );
983
984       if ( max < min) {
985         max = min;
986         maxTimeBinSpinBox->setValue(max);
987       }
988
989       display->SetTimeBinMinMax( min , max );
990
991     }
992 #else
993     HLTError("function not available for AliHLTTPCDisplay version < 2");
994 #endif
995
996     redisplay();
997 }
998
999 //____________________________________________________________________________________________________
1000 void AliHLTGUI::selectTimeBinData(){    
1001     // -- select max,sum,average of Data
1002     AliHLTTPCDisplayMain* display = (AliHLTTPCDisplayMain*)fDisplay;  
1003
1004     Int_t selectFrontDataID = frontDataButtonGroup->selectedId();
1005
1006 #if ALIHLTTPCDISPLAY_VERSION >= 2
1007     // Set use sum in data
1008     if (selectFrontDataID == 0) display->SetFrontDataSwitch(0);
1009
1010     // Set use average in data
1011     else if (selectFrontDataID == 1) display->SetFrontDataSwitch(1);
1012
1013     // Set use maximum in data
1014     else if (selectFrontDataID == 2) display->SetFrontDataSwitch(2);
1015 #else
1016     HLTError("function not available for AliHLTTPCDisplay version < 2");
1017 #endif
1018
1019     redisplay();
1020 }
1021
1022 //____________________________________________________________________________________________________
1023 void AliHLTGUI::setSplitPadRow(){
1024     // -- set split PadRow Canvas
1025     AliHLTTPCDisplayMain* display = (AliHLTTPCDisplayMain*)fDisplay;  
1026
1027     if (padrowSplitCheckBox->isChecked() ) display->SetSplitPadRow(kTRUE);
1028     else display->SetSplitPadRow(kFALSE);
1029
1030     redisplay();
1031 }
1032 //____________________________________________________________________________________________________
1033 void AliHLTGUI::setSplitFront(){
1034     // -- set split Front Canvas
1035     AliHLTTPCDisplayMain* display = (AliHLTTPCDisplayMain*)fDisplay;  
1036
1037 #if ALIHLTTPCDISPLAY_VERSION >= 2
1038     if (frontSplitCheckBox->isChecked() ) display->SetSplitFront(kTRUE);
1039     else display->SetSplitFront(kFALSE);
1040 #else
1041     HLTError("function not available for AliHLTTPCDisplay version < 2");
1042 #endif
1043
1044     redisplay();
1045 }
1046
1047 /* ----- OLD DELETE
1048 //____________________________________________________________________________________________________
1049 void AliHLTGUI::setAllTimeBins(){
1050     // -- set show all Timebins in front view
1051     AliHLTTPCDisplayMain* display = (AliHLTTPCDisplayMain*)fDisplay;  
1052
1053     if (allTimebinCheckBox->isChecked() ) display->SetAllTimebins(kTRUE);
1054     else display->SetAllTimebins(kFALSE);
1055
1056     redisplay();
1057 }
1058 ----- */
1059
1060 //____________________________________________________________________________________________________
1061 void AliHLTGUI::setGUIPad(Int_t pad){    
1062     // -- set GUI pad value
1063     padSpinBox->setValue(pad);
1064 }
1065
1066 //____________________________________________________________________________________________________
1067 void AliHLTGUI::set3D(){    
1068     // -- set 3D Display
1069     AliHLTTPCDisplayMain* display = (AliHLTTPCDisplayMain*)fDisplay;  
1070    
1071     if  (padrowCheckBox->isChecked()) setPadRow();
1072     
1073     display->SetSwitches(tracksCheckBox->isChecked(), clusterCheckBox->isChecked(), padrowCheckBox->isChecked(), geometryCheckBox->isChecked() );
1074     redisplay();
1075 }
1076
1077 //____________________________________________________________________________________________________
1078 void AliHLTGUI::set3DRaw(){    
1079     // -- set 3D Display Raw Properties
1080     AliHLTTPCDisplayMain* display = (AliHLTTPCDisplayMain*)fDisplay;  
1081    
1082     Int_t selectRawID = threeDRawButtonGroup->selectedId();
1083
1084 #if ALIHLTTPCDISPLAY_VERSION >= 2
1085     // Set ALL PadRows
1086     if (selectRawID == 0) display->Set3DRawSwitch(0);
1087
1088     // Set ONE PadRow
1089     else if (selectRawID == 1) display->Set3DRawSwitch(1);
1090 #else
1091     HLTError("function not available for AliHLTTPCDisplay version < 2");
1092 #endif
1093
1094     // redisplay 3D
1095     redisplay();
1096 }
1097
1098 //____________________________________________________________________________________________________
1099 void AliHLTGUI::setSelectTrack(){    
1100     // --  turn on /off of single track
1101    AliHLTTPCDisplayMain* display = (AliHLTTPCDisplayMain*)fDisplay;  
1102
1103     display->SetSelectTrackSwitch( selectTrackCheckBox->isChecked() );
1104   
1105     if (! selectTrackCheckBox->isChecked() ) {
1106         display->SetSelectTrack(0);
1107         redisplay();
1108     }
1109     else selectTrackSector();
1110 }
1111
1112 //____________________________________________________________________________________________________
1113 void AliHLTGUI::selectTrackSector(){      
1114     // -- select slice for single track
1115     AliHLTTPCDisplayMain* display = (AliHLTTPCDisplayMain*)fDisplay;  
1116
1117     Int_t slice = atoi( selectTrackSectorSpinBox->text());
1118
1119     if (display->GetTracksPerSlice(slice) == 0)  selectTrackSpinBox->setMaxValue( 0 ); 
1120     else selectTrackSpinBox->setMaxValue( display->GetTracksPerSlice(slice)  - 1 );
1121
1122     selectTrackSpinBox->setValue(0);
1123
1124     display->SetSelectTrackSlice(slice); 
1125     
1126     selectTrack();
1127 }
1128
1129 //____________________________________________________________________________________________________
1130 void AliHLTGUI::selectTrack(){    
1131     // -- select single track in slice
1132     AliHLTTPCDisplayMain* display = (AliHLTTPCDisplayMain*)fDisplay;  
1133
1134     display->SetSelectTrack( atoi( selectTrackSpinBox->text() ) );
1135     redisplay();
1136 }
1137
1138
1139 //____________________________________________________________________________________________________
1140 void AliHLTGUI::displayTrackParam(){    
1141     // -- display Track Parameters
1142     AliHLTTPCDisplayMain* display = (AliHLTTPCDisplayMain*)fDisplay;  
1143    
1144     Char_t nHits[256] = "";
1145     Char_t charge[256] = "";
1146     Char_t kappa[256] = "";
1147     Char_t radius[256] = "";
1148     Char_t slice[256] = "";
1149     Char_t phi0[256] = "";
1150     Char_t psi[256] = "";
1151     Char_t lambda[256]= "";
1152     Char_t pt[256] = "";
1153     Char_t id[256] = "";
1154
1155     if ( display->GetSelectTrackSwitch() 
1156          && display->ExistsTrackData() 
1157          && display->GetDisplaySlice( atoi(selectTrackSectorSpinBox->text()) )  
1158          && display->GetTracksPerSlice( atoi(selectTrackSectorSpinBox->text()) ) > 0 ){ 
1159         sprintf(kappa,"%f",display->fTrackParam.kappa);
1160         sprintf(nHits,"%d",display->fTrackParam.nHits);
1161         sprintf(charge,"%d",display->fTrackParam.charge);
1162         sprintf(radius,"%f",display->fTrackParam.radius);
1163         sprintf(slice,"%d",display->fTrackParam.slice);
1164         sprintf(phi0,"%f",display->fTrackParam.phi0);
1165         sprintf(psi,"%f",display->fTrackParam.psi);
1166         sprintf(lambda,"%f",display->fTrackParam.lambda);
1167         sprintf(pt,"%f",display->fTrackParam.pt);
1168         sprintf(id,"%d",display->fTrackParam.id);
1169      } 
1170      else {
1171         sprintf(kappa,"%f",0.);
1172         sprintf(nHits,"%d",1);
1173         sprintf(charge,"%d",0);
1174         sprintf(radius,"%f",0.);
1175         sprintf(slice,"%d",0);
1176         sprintf(phi0,"%f",0.);
1177         sprintf(psi,"%f",0.);
1178         sprintf(lambda,"%f",0.);
1179         sprintf(pt,"%f",0.);
1180         sprintf(id,"%d",0);
1181      }
1182
1183      trackParamSliceTextLabel->setText(slice);
1184      trackParamIDTextLabel->setText(id);
1185      trackParamKappaTextLabel->setText(kappa);
1186      trackParamPtTextLabel->setText(pt);
1187      trackParamNHitsTextLabel->setText(nHits);
1188      trackParamChargeTextLabel->setText(charge);
1189      trackParamRadiusTextLabel->setText(radius);
1190      trackParamPhi0TextLabel->setText(phi0);
1191      trackParamPsiTextLabel->setText(psi);
1192      trackParamLambdaTextLabel->setText(lambda);
1193 }