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