]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/OnlineDisplay/AliHLTTPCDisplayMain.cxx
TPC OnlineDisplay: TView has been made pure virtual ;-( fix in order to use TView3D...
[u/mrichter/AliRoot.git] / HLT / TPCLib / OnlineDisplay / AliHLTTPCDisplayMain.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   AliHLTTPCDisplayMain.cxx
17     @author Jochen Thaeder
18     @date   
19     @brief  Interface class for ALICE HLT online Display
20 */
21
22
23 #define DEBUG 0
24
25 #if defined(HAVE_HOMERREADER) 
26 #include "HOMERReader.h"
27 #endif // defined(HAVE_HOMERREADER) 
28 //-----------
29 #include "AliHLTTPCDisplayMain.h"
30 #include "AliHLTTPCDisplayCharge.h"
31 #include "AliHLTTPCDisplayPadRow.h"
32 #include "AliHLTTPCDisplayPad.h"
33 #include "AliHLTTPCDisplay3D.h"
34 #include "AliHLTTPCDisplayResiduals.h"
35 #include "AliHLTTPCDisplayFront.h"
36 //-----------
37 #include "AliHLTStdIncludes.h"
38 #include "AliHLTTPCDefinitions.h"
39 #include "AliHLTDataTypes.h"
40 #include "AliHLTTPCSpacePointData.h"
41 #include "AliHLTTPCClusterDataFormat.h"
42 #include "AliHLTTPCTrackletDataFormat.h"
43 #include "AliHLTTPCDigitReader.h"
44 #include "AliHLTTPCDigitReaderRaw.h"
45 #include "AliHLTTPCPad.h"
46 #include "AliHLT_C_Component_WrapperInterface.h"
47 #include "AliHLTTPCLogging.h"
48
49 #include "AliHLTTPCTransform.h"
50 #include "AliHLTTPCTrack.h"
51 #include "AliHLTTPCTrackArray.h"
52 #include "AliHLTTPCMemHandler.h"
53 #include "AliHLTTPCDigitReaderPacked.h"
54
55 #ifdef use_aliroot
56 #include <TClonesArray.h>
57 #include <AliRun.h>
58 #include <AliSimDigits.h>
59 #include <AliTPCParam.h>
60 #endif
61
62 #if __GNUC__ >= 3
63 using namespace std;
64 #endif
65
66 // -- input datatypes , reverse
67 const Char_t* spptID   = "SRETSULC";   // CLUSTERS
68 const Char_t* trksegID = "SGESKART";   // TRAKSEGS
69 const Char_t* trkID    = "  SKCART";   // TRACKS
70 const Char_t* padrowID = "KPWR_LDD";   // DDL_RWPK
71
72 ClassImp(AliHLTTPCDisplayMain)
73
74 //____________________________________________________________________________________________________
75 AliHLTTPCDisplayMain::AliHLTTPCDisplayMain(void* pt2GUI, void (*pt2Function)(void*, Int_t)) {
76   //constructor
77
78   AliHLTLogging::SetGlobalLogLevel(kHLTLogError);
79
80   fCanvasArray = new TCanvas* [nCanvasTypes];
81   fWorkerArray = new void* [nWorkerTypes]; 
82
83   // set N of TimeBins
84   fgNTimeBins = 1024;   //  446 or 1024
85
86   fRawReaderMode = 0;
87   fZeroSuppressionThreshold = 10;
88   fOccupancyLimit = 1.0;
89   fBField = 0.4;
90   fNTimeBins = 1024;
91
92   //callback handler
93   fPt2Gui = pt2GUI;
94   fPadCallback = pt2Function;
95         
96   fReader = NULL;
97   
98   fConnect = kFALSE;
99   fEventID = 0;
100
101   fDisplayCharge = NULL; 
102   fDisplayPadRow = NULL;
103   fDisplayPad = NULL;
104   fDisplay3D = NULL;
105   fDisplayResiduals = NULL;
106   fDisplayFront = NULL;
107
108   fCanvasCharge = NULL;
109   fCanvasPadRow = NULL;
110   fCanvasPad = NULL;
111   fCanvas3D = NULL;
112   fCanvasResiduals = NULL;
113   fCanvasFront = NULL;
114   fCanvasHits_S = NULL;
115   fCanvasQ_Track = NULL;
116   fCanvasQ_S = NULL;
117   fCanvasPadRow_Pad = NULL;
118
119
120   fExistsRawData = kFALSE;
121   fExistsClusterData = kFALSE;
122   fExistsTrackData = kFALSE;
123
124   memset(fClusters,0,36*6*sizeof(AliHLTTPCSpacePointData*));
125   memset(fNcl, 0, 36*6*sizeof(UInt_t)); 
126
127   fTracks = NULL;
128
129   fZeroSuppression = kTRUE;
130   fNPads = AliHLTTPCTransform::GetNPads(0);
131   fPad = -1;
132   fPadRow = 0;
133   fSlicePadRow = 0; 
134   fSplitPadRow = kFALSE;
135   
136   fFrontDataSwitch = 2;
137   fTimeBinMin = 0;
138   fTimeBinMax = GetNTimeBins() -1;
139   fSplitFront = kFALSE;
140     
141   fSelectTrack = -1;
142   fSelectTrackSlice = 0;
143   fSelectTrackSwitch = kFALSE;
144   
145   fSelectCluster = 0;
146
147   fMinSlice = 0;
148   fMaxSlice = 35;
149   fSlicePair = kFALSE;
150
151   SetSliceArray();
152   
153   fTheta = 90.;
154   fPhi = 0.;
155
156   fBackColor = 1;
157   fLineColor = 0;
158   fKeepView = kTRUE;
159
160   fSwitch3DCluster = kFALSE;
161   fSwitch3DTracks = kFALSE;
162   fSwitch3DPadRow = kFALSE;
163   fSwitch3DGeometry = kTRUE;
164   fSwitch3DRaw = 0;
165
166   fCutHits = 0;
167   fCutPt = 0.;
168   fCutPsi = 0.;
169   fCutLambda = 0.;
170   fCut_S = 0.;
171   fCutPadrow = 159;
172   
173
174   fTrackParam.kappa = 0.;
175   fTrackParam.nHits = 0;
176   fTrackParam.charge = 0;
177   fTrackParam.radius = 0.;
178   fTrackParam.slice = 0;
179   fTrackParam.phi0 = 0.;
180   fTrackParam.psi = 0.;
181   fTrackParam.lambda = 0.;
182   fTrackParam.pt = 0.;
183   fTrackParam.id = 0;
184   fTrackParam.bfield = 0.;
185   fTrackParam.s = 0.;
186 }
187
188 //____________________________________________________________________________________________________
189 AliHLTTPCDisplayMain::~AliHLTTPCDisplayMain() {
190   //destructor
191   if ( fTracks )  delete fTracks;
192   fTracks = NULL;
193   
194   if ( fCanvasArray ) delete fTracks;
195   fTracks = NULL;
196
197   if ( fWorkerArray ) delete fWorkerArray;
198   fWorkerArray = NULL;
199
200 #if defined(HAVE_HOMERREADER) 
201   HOMERReader* reader= (HOMERReader*) fReader;
202
203     if (reader)
204       delete reader;
205     fReader = NULL;
206 #endif // defined(HAVE_HOMERREADER) 
207
208     if (fDisplayResiduals)
209       delete fDisplayResiduals;
210     fDisplayResiduals = NULL;
211
212     if (fDisplay3D)
213       delete fDisplay3D;
214     fDisplay3D = NULL;
215
216     if (fDisplayPad)
217       delete fDisplayPad;
218     fDisplayPad = NULL;
219
220     if (fDisplayPadRow)
221       delete fDisplayPadRow;
222     fDisplayPadRow = NULL;
223
224     if (fDisplayFront)
225       delete fDisplayFront;
226     fDisplayFront = NULL;
227
228     if (fDisplayCharge)
229       delete fDisplayCharge;
230     fDisplayCharge = NULL;
231 }
232
233 //____________________________________________________________________________________________________
234 Int_t AliHLTTPCDisplayMain::Connect( unsigned int cnt, const char** hostnames, unsigned short* ports, Char_t *gfile){
235
236     Char_t* defaultGeometry=NULL;
237 #if defined(DEFAULT_GEOMETRY)
238     defaultGeometry=DEFAULT_GEOMETRY;
239 #endif
240     if (gfile!=NULL) {
241       HLTDebug("probing geometry file %s", gfile);
242       ifstream test(gfile);
243       if (test.fail()) {
244         HLTWarning("unable to find geometry file %s, using default file", gfile);
245         gfile=defaultGeometry;
246       }
247       test.close();
248     } else {
249       HLTDebug("using default geometry file %s", gfile, defaultGeometry);
250       gfile=defaultGeometry;
251     }
252     if (gfile==NULL) {
253       HLTError("geometry file missing");
254       return -EINVAL;
255     }
256 #if defined(HAVE_HOMERREADER) 
257   
258   Int_t ret;
259   
260   while(1) {
261
262     // -- CONNECT to TCPDumpSubscriber via HOMER
263     // ---------------------------------------------
264     HOMERReader* reader = new HOMERReader( cnt, (const char**) hostnames, ports );
265     ret=reader->GetConnectionStatus();
266     
267     if ( ret ) {        
268       Int_t ndx = reader->GetErrorConnectionNdx();
269       if ( ndx < (Int_t) cnt) HLTError("Error establishing connection to TCP source %s:%hu: %s (%d)\n", hostnames[ndx], ports[ndx], strerror(ret), ret );
270       else HLTError("Error establishing connection to unknown source with index %d: %s (%d)\n",ndx, strerror(ret), ret );
271       
272       delete reader;
273       reader = NULL;
274       return -1;
275     }
276
277     // -- ERROR HANDLING for HOMER (error codes and empty blocks)
278     // --------------------------------------------------------------
279     Int_t  ret1 = reader->ReadNextEvent(3000000); // timeout in microseconds (3s)
280
281     if ( ret1 ) {         
282       Int_t ndx = reader->GetErrorConnectionNdx();
283       
284       if ( ret1 == 111 || ret1 == 32 ) {
285         HLTError( "Error, No Connection to source %d: %s (%d)\n", ndx, strerror(ret1), ret1 );
286
287         delete reader;
288         reader = NULL;
289         
290         return -1; 
291       }
292       else if (ret1 == 110){
293         HLTError( "Timout occured, reading event from source %d: %s (%d)\n", ndx, strerror(ret1), ret1 );
294
295         delete reader;
296         reader = NULL;
297         
298         return -2;
299       }
300       else if ( ret1 == 56 || ret1 == 6 ) {
301         HLTError( "Error reading event from source %d: %s (%d) -- RETRY\n", ndx, strerror(ret1), ret1 );
302
303         delete reader;
304         reader = NULL;
305         
306         continue; 
307       }
308       else {
309         HLTError( "General Error reading event from source %d: %s (%d)\n", ndx, strerror(ret1), ret1 );
310
311         delete reader;
312         reader = NULL;
313         
314         return -3;
315       }
316     }
317
318     unsigned long blockCnt = reader->GetBlockCnt();  
319
320     HLTDebug( "Event 0x%016LX (%Lu) with %lu blocks\n", (ULong64_t)reader->GetEventID(), (ULong64_t)reader->GetEventID(), blockCnt );
321
322     if (blockCnt == 0){
323       delete reader;
324       reader = NULL;
325       continue;
326     }
327     
328     // SWITCH on the Display parts according what DATATAYPES are present
329     // ---------------------------------------------------------------------
330     for ( unsigned long i = 0; i < blockCnt; i++ ) {
331       char tmp1[9];
332       memset( tmp1, 0, 9 );
333       void *tmp11 = tmp1;
334       ULong64_t* tmp12 = (ULong64_t*)tmp11;
335       *tmp12 = reader->GetBlockDataType( i );
336
337       if (!strcmp(tmp1,padrowID)) fExistsRawData = kTRUE;
338       else if (!strcmp(tmp1,spptID)) fExistsClusterData = kTRUE;
339       else if (!strcmp(tmp1,trksegID)) fExistsTrackData = kTRUE;          
340       else if (!strcmp(tmp1,trkID)) fExistsTrackData = kTRUE;             
341     }
342   
343     // -- Set reader and eventID
344     // -------------------------------
345     fEventID = (ULong64_t)reader->GetEventID();
346     fReader = (void*) reader;
347     fConnect = kTRUE; 
348
349     break; // leave while(1), if connected to source
350   }
351
352   
353   // -- Initialize TPC Display Classes  -- IMPORTANT... don't change the order of them
354   //    Check if necessary data types are present
355   // ------------------------------------------------------------------------------------
356   fDisplay3D = new AliHLTTPCDisplay3D(this, gfile);
357
358   if (ExistsRawData()){
359     fDisplayPadRow = new AliHLTTPCDisplayPadRow(this);
360     fDisplayPad = new AliHLTTPCDisplayPad(this);
361     fDisplayFront = new AliHLTTPCDisplayFront(this);
362   }
363   
364   if (ExistsClusterData()){
365     fDisplayCharge = new AliHLTTPCDisplayCharge(this);
366   }
367   
368   if (ExistsTrackData() && ExistsClusterData() ){
369     fDisplayResiduals = new AliHLTTPCDisplayResiduals(this);
370   }
371
372  
373
374 #else
375     HLTFatal("HOMER reader not available");
376 #endif // defined(HAVE_HOMERREADER)  
377
378     return 0;
379 }
380
381 //____________________________________________________________________________________________________
382 Int_t AliHLTTPCDisplayMain::Disconnect(){
383 #if defined(HAVE_HOMERREADER) 
384     // READ CLUSTER and TRACK data
385     HOMERReader* reader = (HOMERReader*)fReader;
386
387     if (reader)
388       delete reader;
389     fReader = NULL;
390
391 #else
392     HLTFatal("HOMER raeder not available");
393 #endif // defined(HAVE_HOMERREADER) 
394
395     return 0;
396 }
397
398
399 //____________________________________________________________________________________________________
400 Int_t AliHLTTPCDisplayMain::ReadData(Bool_t nextSwitch){
401 // READ CLUSTER and TRACK data
402
403 #if defined(HAVE_HOMERREADER) 
404   HOMERReader* reader = (HOMERReader*)fReader;
405
406   // -- reset TracksPerSlice Array
407   for(Int_t ii=0;ii<36;ii++) fTracksPerSlice[ii] = 0;
408
409   Int_t ret;
410   ULong_t blk;
411
412   // -- READ next event data and ERROR HANDLING for HOMER (error codes and empty blocks)
413   // ---------------------------------------------------------------------------------------
414   if (nextSwitch) {
415     
416     while(1){
417       ret = reader->ReadNextEvent();
418       
419       if ( ret == 111 || ret == 32 || ret == 6 ) {
420         Int_t ndx = reader->GetErrorConnectionNdx();
421         HLTError( "Error, No Connection to source %d: %s (%d)\n", ndx, strerror(ret), ret );
422         return -1; 
423       }
424       else if ( ret == 110 ) {
425         Int_t ndx = reader->GetErrorConnectionNdx();
426         HLTError( "Timout occured, reading event from source %d: %s (%d)\n", ndx, strerror(ret), ret );
427         return -2; 
428       }
429       else if ( ret == 56) {
430         Int_t ndx = reader->GetErrorConnectionNdx();
431         HLTError( "Error reading event from source %d: %s (%d) -- RETRY\n", ndx, strerror(ret), ret );
432         continue; 
433       }
434       else if ( ret ) {
435         Int_t ndx = reader->GetErrorConnectionNdx();
436         HLTError( "General Error reading event from source %d: %s (%d)\n", ndx, strerror(ret), ret );
437         return -3;
438       }
439       else {
440         break;
441       }
442     }
443   } // end if (nextSwitch)
444
445   // -- Get blockCnt and eventID
446   // -------------------------------
447   ULong_t blockCnt = reader->GetBlockCnt();
448   fEventID = (ULong64_t)reader->GetEventID();
449
450   HLTError( "Event 0x%016LX (%Lu) with %lu blocks\n", (ULong64_t)reader->GetEventID(), (ULong64_t)reader->GetEventID(), blockCnt );
451
452   // Loop for Debug only
453   for ( ULong_t i = 0; i < blockCnt; i++ ) {
454     Char_t tmp1[9], tmp2[5];
455     memset( tmp1, 0, 9 );
456     memset( tmp2, 0, 5 );
457     void *tmp11 = tmp1;
458     ULong64_t* tmp12 = (ULong64_t*)tmp11;
459     *tmp12 = reader->GetBlockDataType( i );
460     void *tmp21 = tmp2;
461     ULong_t* tmp22 = (ULong_t*)tmp21;
462     *tmp22 = reader->GetBlockDataOrigin( i );
463
464     HLTError( "Block %lu length: %lu - type: %s - origin: %s\n",i, reader->GetBlockDataLength( i ), tmp1, tmp2 );
465   } // end for ( ULong_t i = 0; i < blockCnt; i++ ) {
466
467
468   // -- READ RAW DATA
469   //---------------------
470   ReadRawData();
471   
472   // -- READ CLUSTER DATA
473   //-------------------------
474   ReadClusterData();
475
476   // -- READ TRACKS
477   //-------------------
478   ReadTrackData();
479
480 #else
481   HLTFatal("HOMER raeder not available");
482 #endif // defined(HAVE_HOMERREADER) 
483
484   return 0;
485 }
486
487 //____________________________________________________________________________________________________
488 void AliHLTTPCDisplayMain::DisplayEvent(Bool_t newRawSlice){
489 #if defined(HAVE_HOMERREADER) 
490     HOMERReader* reader = (HOMERReader*)fReader;
491
492     //--------------------------------------------------------------------------------------------
493     // READ RAW DATA for PADROW/PAD HISTOGRAM
494     //--------------------------------------------------------------------------------------------
495     if ( ExistsRawData() ){     
496         fDisplayPadRow->Reset();
497         fDisplayPad->Reset();
498         fDisplayFront->Reset();
499
500         if (newRawSlice)  ReadRawData();
501
502
503         fDisplayPad->Fill();
504         fDisplayPadRow->Fill();
505         fDisplayFront->Fill();
506
507
508         fDisplayPad->Draw();
509         fDisplayPadRow->Draw();
510         fDisplayFront->Draw();
511     }
512
513     //--------------------------------------------------------------------------------------------
514     // DRAW RESIDUALS
515     //--------------------------------------------------------------------------------------------
516     if ( ExistsClusterData() && ExistsTrackData() ){
517         fDisplayResiduals->Reset();
518         fDisplayResiduals->Fill();
519         fDisplayResiduals->Draw();
520     }
521
522     //--------------------------------------------------------------------------------------------
523     // DRAW CHARGE 
524     //--------------------------------------------------------------------------------------------
525     if ( ExistsClusterData() ){
526         fDisplayCharge->Reset();
527         fDisplayCharge->Fill();
528         fDisplayCharge->Draw();
529     }
530
531     //--------------------------------------------------------------------------------------------
532     // DRAW 3D
533     //--------------------------------------------------------------------------------------------
534
535     // TAKE CARE !!! EXISTSxxxData() HANDLING of 3D will be done IN this class !!!
536     fDisplay3D->Draw(); 
537
538     cout << "afterdraw" << endl;
539 #else
540     HLTFatal("HOMER raeder not available");
541 #endif // defined(HAVE_HOMERREADER) 
542
543 }
544
545 //____________________________________________________________________________________________________
546 void AliHLTTPCDisplayMain::SaveHistograms(){    
547   // Save histograms as eps
548   fDisplayCharge->Save();
549   fDisplayPadRow->Save();
550   fDisplayPad->Save();
551   fDisplay3D->Save();
552   fDisplayResiduals->Save();
553   fDisplayFront->Save();
554   fDisplayCharge->Save();
555 }
556
557 //----------------------------------------------------------------------------------------------------
558 //                 READ DATA
559 //____________________________________________________________________________________________________
560 //____________________________________________________________________________________________________
561 void AliHLTTPCDisplayMain::ReadRawData(){
562   // -- READ raw data of one sector into 3D arrays fRawData and fRawDataZeroSuppressed
563
564   // -- reset arrays
565   memset(fRawData, 0, 159*140*1024*sizeof(UInt_t));
566   memset(fRawDataZeroSuppressed, 0, 159*140*1024*sizeof(UInt_t));
567
568 #if defined(HAVE_HOMERREADER) 
569   HOMERReader* reader = (HOMERReader*)fReader;
570   
571   // -- read raw data blocks
572   // ---------------------------
573   ULong_t blk;
574   Char_t* rawID = "KPWR_LDD";    
575   blk = reader->FindBlockNdx( rawID, " CPT",0xFFFFFFFF );
576   
577   while ( blk != ~(ULong_t)0 ) {
578     HLTDebug( "Found raw data block %lu\n", blk );
579
580 #if HOMER_VERSION >= 2
581     // -- Check for corrupt data
582     AliHLTUInt64_t corruptFlag = reader->GetBlockStatusFlags( blk );
583     if (corruptFlag & 0x00000001) {
584       HLTError( "Data block %lu is corrupt\n",blk );
585       blk = reader->FindBlockNdx( rawID, " CPT", 0xFFFFFFFF, blk+1 );
586       continue;
587     }
588 #endif
589
590     void* rawDataBlock = (void*) reader->GetBlockData( blk );
591     unsigned long rawDataLen = reader->GetBlockDataLength( blk );
592     
593     ULong_t spec = reader->GetBlockDataSpec( blk );
594     Int_t patch = AliHLTTPCDefinitions::GetMinPatchNr( spec );
595     Int_t slice = AliHLTTPCDefinitions::GetMinSliceNr( spec );
596     
597     HLTDebug( "Raw data found for slice %u - patch %u\n", slice, patch );
598
599     // -- Wrong slice for raw data 
600     if ( GetSlicePadRow() != slice) {
601       blk = reader->FindBlockNdx( rawID, " CPT", 0xFFFFFFFF, blk+1 );
602       continue;
603     } 
604     
605 #if defined(HAVE_TPC_MAPPING)
606
607     // -- Read data out of block
608     AliHLTTPCDigitReaderRaw digitReader( GetRawReaderMode() );
609     
610     // Initialize RAW DATA
611     Int_t firstRow = AliHLTTPCTransform::GetFirstRow(patch);
612     Int_t lastRow = AliHLTTPCTransform::GetLastRow(patch);
613     
614     // Outer sector, patches 2, 3, 4, 5 -  start counting in patch 2 with row 0
615     Int_t rowOffset = 0;
616     if ( patch >= 2 ) rowOffset = AliHLTTPCTransform::GetFirstRow( 2 );
617     
618     // Initialize block for reading packed data
619     digitReader.InitBlock(rawDataBlock,rawDataLen,firstRow,lastRow,patch,slice);
620     
621     Bool_t readValue = digitReader.Next();
622
623     if (!readValue){    
624       HLTError ( "No value in data block %lu \n", blk);
625       blk = reader->FindBlockNdx( rawID, " CPT", 0xFFFFFFFF, blk+1 );
626       continue;
627     }
628
629     // -- Fill Zero Suppressed Array
630     // ---------------------------------
631
632     Int_t newRow = 0;    
633     UShort_t time=0,newTime=0;
634     UInt_t pad=0,newPad=0;
635     Int_t signal=0;
636
637     Int_t gatingGridOffset=50;
638     Int_t signalThreshold = GetZeroSuppressionThreshold();
639     AliHLTTPCPad baseline(gatingGridOffset, GetNTimeBins() );
640
641     // just to make later conversion to a list of objects easier
642     AliHLTTPCPad* pCurrentPad=NULL;
643     if ( signalThreshold >= 0) {
644       pCurrentPad=&baseline;
645       baseline.SetThreshold(signalThreshold);
646     }
647
648     while ( readValue ) { // Reads through all digits in block
649      
650       while(1){ //Loop over time bins of current pad
651         // read all the values for one pad at once to calculate the base line
652         if (pCurrentPad) {
653           
654           if (!pCurrentPad->IsStarted()) {
655             
656             //      HLTDebug("reading data for pad %d, padrow %d", digitReader.GetPad(), digitReader.GetRow()+rowOffset);
657             
658             pCurrentPad->SetID(digitReader.GetRow()+rowOffset,digitReader.GetPad());
659             
660             if ( (pCurrentPad->StartEvent()) >= 0) {
661               // loop over data of one pad and read it into AliHLTTPCPad class
662               do {
663                 if ( (digitReader.GetRow()+rowOffset) != pCurrentPad->GetRowNumber() ) break;
664                 if ( digitReader.GetPad() != pCurrentPad->GetPadNumber() ) break;
665                 pCurrentPad->SetRawData( digitReader.GetTime(), digitReader.GetSignal() );
666                 
667                 //      HLTDebug("set raw data to pad: bin %d charge %d", digitReader.GetTime(), digitReader.GetSignal());
668                 
669               } while ( (readValue = digitReader.Next()) != 0 );
670             }
671
672             // calculate baseline of pad
673             pCurrentPad->CalculateBaseLine( GetNTimeBins() / 2);
674             
675             if ( pCurrentPad->Next(kTRUE/*do zero suppression*/) == 0 ) {
676               //              HLTDebug("no data available after zero suppression");
677               
678               pCurrentPad->StopEvent();
679               pCurrentPad->ResetHistory();
680               break;
681             }
682
683             Int_t time = pCurrentPad->GetCurrentPosition();
684             if ( time > pCurrentPad->GetSize() ) {
685               HLTError("invalid time bin for pad");
686               break;
687             }     
688           } // end - if (!pCurrentPad->IsStarted()) {
689         } // end - if (pCurrentPad) {
690         
691         if (pCurrentPad) {
692           Float_t occupancy=pCurrentPad->GetOccupancy();
693           if ( occupancy < GetOccupancyLimit() ) {
694             signal = pCurrentPad->GetCorrectedData();
695           } 
696           else {
697             signal = 0;
698             HLTInfo("ignoring pad %d with occupancy level %f %%", pCurrentPad->GetPadNumber(), occupancy);
699           }
700           //      signal = pCurrentPad->GetCorrectedData();
701         } else {
702           signal = digitReader.GetSignal();
703         }
704
705         fRawDataZeroSuppressed[ pCurrentPad->GetRowNumber() ][ pCurrentPad->GetPadNumber() ][ pCurrentPad->GetCurrentPosition() ] = (UInt_t)signal;
706
707         
708         HLTDebug("get next charge value: position %d charge %d", time, signal);
709         
710         if( time >= AliHLTTPCTransform::GetNTimeBins() ){
711           HLTWarning("Timebin (%d) out of range (%d)", time, AliHLTTPCTransform::GetNTimeBins());
712           break;
713         }
714           
715         if (pCurrentPad) {
716         
717           if( (pCurrentPad->Next(kTRUE/*do zero suppression*/)) == 0 ) {
718             pCurrentPad->StopEvent();
719             pCurrentPad->ResetHistory();
720
721             if(readValue) {
722               newPad = digitReader.GetPad();
723               newTime = digitReader.GetTime();
724               newRow = digitReader.GetRow() + rowOffset;
725             }
726             break;
727           }
728           
729           newPad=pCurrentPad->GetPadNumber();
730           newTime=pCurrentPad->GetCurrentPosition();
731           newRow=pCurrentPad->GetRowNumber();
732         } 
733         else {
734           
735           readValue = digitReader.Next();
736           
737           //Check where to stop:
738           if(!readValue) break; //No more value
739           
740           newPad = digitReader.GetPad();
741           newTime = digitReader.GetTime();
742           newRow = digitReader.GetRow() + rowOffset;
743         }
744         
745         if(newPad != pad) break; //new pad
746         if(newTime != time+1) break; //end of sequence
747         
748         time = newTime;
749         
750       } // end - while(1){ // Loop over time bins of current pad
751
752       if ( !readValue ) break;
753
754     } // end  while ( readValue ) {
755
756     // -- END ZERO SUPPRESSION
757
758     // Rewind block for reading packed data
759     digitReader.InitBlock(rawDataBlock,rawDataLen,firstRow,lastRow,patch,slice);
760
761     // -- Fill Raw Array
762     // ---------------------
763     readValue = digitReader.Next();
764     
765     // LOOP over raw data and fill arrays
766     while ( readValue ){ 
767             
768       Int_t row = digitReader.GetRow() + rowOffset;
769       Int_t pad = (Int_t) digitReader.GetPad();
770       Int_t time = (Int_t) digitReader.GetTime();
771       UInt_t signal = (UInt_t) digitReader.GetSignal();
772
773       fRawData[row][pad][time] = signal;
774             
775       // -- read next value
776       readValue = digitReader.Next();
777       
778       // -- No more value
779       if(!readValue) break; 
780
781     } // end  while ( readValue ){ 
782
783 #else //! defined(HAVE_TPC_MAPPING)
784     HLTFatal("DigitReaderRaw not available - check your build");
785 #endif //defined(HAVE_TPC_MAPPING)
786           
787     blk = reader->FindBlockNdx( rawID, " CPT", 0xFFFFFFFF, blk+1 );
788     
789   } // end while ( blk != ~(ULong_t)0 ) {
790   
791 #else
792   HLTFatal("HOMER raeder not available");
793 #endif // defined(HAVE_HOMERREADER) 
794   
795 }
796
797 //____________________________________________________________________________________________________
798 void AliHLTTPCDisplayMain::ReadClusterData(){
799  // -- READ cluster data 
800 #if defined(HAVE_HOMERREADER) 
801   HOMERReader* reader = (HOMERReader*)fReader;
802
803   ULong_t blk;
804   blk = reader->FindBlockNdx( (char*)spptID, " CPT",0xFFFFFFFF );
805    
806   while ( blk != ~(ULong_t)0 ) {            
807     HLTDebug( "Found clusters block %lu\n", blk );
808     
809     const AliHLTTPCClusterData* clusterData = (const AliHLTTPCClusterData*)reader->GetBlockData( blk );
810     if ( !clusterData ) {
811       HLTError( "No track data for block %lu\n", blk );
812       blk = reader->FindBlockNdx( (char*)spptID, " CPT", 0xFFFFFFFF, blk+1 );
813       continue;
814     }
815         
816     ULong_t spec = reader->GetBlockDataSpec( blk );
817     Int_t patch = AliHLTTPCDefinitions::GetMinPatchNr( spec );
818     Int_t slice = AliHLTTPCDefinitions::GetMinSliceNr( spec );
819
820     HLTDebug( "%lu Clusters found for slice %u - patch %u\n", clusterData->fSpacePointCnt, slice, patch );
821
822     void* tmp30 = (void*)clusterData;
823     Byte_t* tmp31 = (Byte_t*)tmp30;
824     ULong_t offset;
825     offset = sizeof(clusterData->fSpacePointCnt);
826     if ( offset <= reader->GetBlockTypeAlignment( blk, 1 ) ) offset = reader->GetBlockTypeAlignment( blk, 1 );
827     tmp31 += offset;
828     tmp30 = tmp31;
829     AliHLTTPCSpacePointData* tmp32 = (AliHLTTPCSpacePointData*)tmp30;
830         
831     SetupCluster( slice, patch, clusterData->fSpacePointCnt, tmp32 );
832     
833     blk = reader->FindBlockNdx( (char*)spptID, " CPT", 0xFFFFFFFF, blk+1 );
834   }
835   
836 #else
837   HLTFatal("HOMER raeder not available");
838 #endif // defined(HAVE_HOMERREADER) 
839 }
840 //____________________________________________________________________________________________________
841 void AliHLTTPCDisplayMain::ReadTrackData(){
842   // -- READ track data
843   
844   if ( fTracks ) delete fTracks; 
845   fTracks = new AliHLTTPCTrackArray;
846   
847 #if defined(HAVE_HOMERREADER) 
848   HOMERReader* reader = (HOMERReader*)fReader;
849   
850   ULong_t blk=~(ULong_t)0;
851   const Char_t* searchIDs[]={trksegID, trkID, NULL};
852   const Char_t** currentID=searchIDs;
853   do {
854     blk = reader->FindBlockNdx( (char*)*currentID, " CPT", 0xFFFFFFFF );
855   } while (blk==~(ULong_t)0 && *(++currentID)!=NULL);
856
857   while ( blk != ~(ULong_t)0 || (*currentID!=NULL && *(++currentID)!=NULL )) {
858     if (blk == ~(ULong_t)0) {
859       blk = reader->FindBlockNdx( (char*)*currentID, " CPT", 0xFFFFFFFF );
860       continue;
861     }
862
863     HLTDebug( "Found tracks in block %lu type %s\n", blk, *currentID );
864
865     const AliHLTTPCTrackletData* trackData = (const AliHLTTPCTrackletData*)reader->GetBlockData( blk );
866
867     if ( !trackData ) {
868       HLTError( "No track data for block %lu\n", blk );
869       blk = reader->FindBlockNdx( (char*)*currentID, " CPT", 0xFFFFFFFF, blk+1 );
870       continue;
871     }
872     
873     ULong_t spec = reader->GetBlockDataSpec( blk );     
874     Int_t slice = AliHLTTPCDefinitions::GetMinSliceNr( spec );  
875     Int_t patchmin = AliHLTTPCDefinitions::GetMinPatchNr( spec );
876     Int_t patchmax = AliHLTTPCDefinitions::GetMaxPatchNr( spec );
877     
878     HLTDebug( "%lu tracks found for slice %u - patch %u-%u\n", trackData->fTrackletCnt, slice, patchmin, patchmax );
879
880     fTracksPerSlice[slice] = trackData->fTrackletCnt; // Fill number if tracks per slice
881         
882     AliHLTTPCTrackSegmentData* tmp42 = (AliHLTTPCTrackSegmentData*) &(trackData->fTracklets[0]);
883     fTracks->FillTracks( trackData->fTrackletCnt, tmp42, slice, (*currentID==trksegID?1:0) );
884     
885     blk = reader->FindBlockNdx( (char*)*currentID, " CPT", 0xFFFFFFFF, blk+1 ); 
886   }
887     
888   SetupTracks(); 
889
890 #else
891   HLTFatal("HOMER raeder not available");
892 #endif // defined(HAVE_HOMERREADER) 
893 }
894
895 //----------------------------------------------------------------------------------------------------
896 //                 SETUP
897 //____________________________________________________________________________________________________
898 void AliHLTTPCDisplayMain::SetupCluster(Int_t slice, Int_t patch, UInt_t nofClusters, AliHLTTPCSpacePointData* data)  {  
899
900     if (data && slice>=0 && slice<36 && patch>=0 && patch<AliHLTTPCTransform::GetNPatches()) {
901         if (fClusters[slice][patch]!=NULL) {
902             delete(fClusters[slice][patch]);
903             fClusters[slice][patch]=NULL;
904         }
905         Int_t arraysize=nofClusters*sizeof(AliHLTTPCSpacePointData);
906         fClusters[slice][patch] = (AliHLTTPCSpacePointData*)new Byte_t[arraysize];
907         if (fClusters[slice][patch]) {
908             memcpy(fClusters[slice][patch], data, arraysize);
909             fNcl[slice][patch]=nofClusters;
910         } else {
911             fNcl[slice][patch]=nofClusters;
912             HLTError ( "Memory allocation failed!" );
913         }
914     } else HLTError ( "Invalid argument!" );
915 }
916
917 //____________________________________________________________________________________________________
918 void AliHLTTPCDisplayMain::SetupTracks() {
919
920     // Set USED cluster
921     Int_t ntracks = fTracks->GetNTracks();
922
923     for(Int_t j=0; j<ntracks; j++) {    
924         AliHLTTPCTrack *gtrack = fTracks->GetCheckedTrack(j); 
925         if(!gtrack) continue;
926
927         Int_t nHits = gtrack->GetNHits();
928         UInt_t *hitnum = gtrack->GetHitNumbers();
929
930         for(Int_t h=0; h<nHits; h++){
931           
932             UInt_t id=hitnum[h];
933             Int_t slice = (id>>25) & 0x7f;
934             Int_t patch = (id>>22) & 0x7;
935             UInt_t pos = id&0x3fffff;       
936                 
937             AliHLTTPCSpacePointData *points = fClusters[slice][patch];
938             
939             if(!points) {
940               HLTError ( "No points at slice %d patch %d position %d!", slice, patch, pos ); 
941               continue;
942             }
943  
944             if(pos>=fNcl[slice][patch]) {
945               HLTError ( "Pos is too large: pos %d ncl!", pos,fNcl[slice][patch] ); 
946               continue;
947             }
948             points[pos].fUsed = kTRUE;
949             points[pos].fTrackN = j;
950         }
951     }
952 }
953
954 // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
955 // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
956 // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
957 // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
958 // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
959 // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
960 // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
961 // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
962 // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
963 // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
964 // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
965 // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
966
967
968 //----------------------------------------------------------------------------------------------------
969 //                 SETTER
970 //____________________________________________________________________________________________________
971
972 //____________________________________________________________________________________________________
973 void AliHLTTPCDisplayMain::SetSliceArray() {
974     Int_t slice=0;
975     Int_t minSlice = fMinSlice; 
976     Int_t maxSlice = fMaxSlice; 
977     Int_t realslice = 0;
978
979     for (slice=0;slice< 36;slice++){
980         fSliceArray[slice] = kFALSE;
981     }
982
983     // Single Slice, or Range
984     if (minSlice > maxSlice) maxSlice += 17;
985         
986     for (slice=minSlice;slice<=maxSlice;slice++){
987         realslice = slice % 18;
988         fSliceArray[realslice] = kTRUE;
989         fSliceArray[realslice+18] = kTRUE;
990     }
991
992     // Pair of Slices
993     if (fSlicePair) {
994         minSlice = fMinSlice + 9;
995         maxSlice = fMaxSlice + 9;
996         
997         if (minSlice > maxSlice) maxSlice += 17;
998         
999         for (slice=minSlice;slice<=maxSlice;slice++){
1000             realslice = slice % 18;
1001             fSliceArray[realslice] = kTRUE;     
1002             fSliceArray[realslice+18] = kTRUE;
1003         }
1004     }
1005 }
1006
1007
1008 //----------------------------------------------------------------------------------------------------
1009 //                 GETTER
1010 //____________________________________________________________________________________________________
1011 Int_t AliHLTTPCDisplayMain::GetGlobalTrack(Int_t slice){
1012     // get global track out of the "selectTrack" parameters
1013     Int_t currenttrack= -1;
1014     Int_t trackcounter = 0;
1015     Int_t ntracks = fTracks->GetNTracks();
1016     
1017     if ( slice == fSelectTrackSlice) {
1018         for(Int_t j=0; j<ntracks; j++) {        
1019             
1020             AliHLTTPCTrack *gtrack = fTracks->GetCheckedTrack(j); 
1021             if(!gtrack) continue;
1022             
1023             // --- CHECK if track is should be drawn
1024             // select Single Track
1025             if(gtrack->GetSector() != fSelectTrackSlice) continue;
1026             
1027             if (trackcounter != fSelectTrack){
1028                 trackcounter++;  
1029                 continue;
1030             }
1031             trackcounter++;
1032             // +++
1033             //if((fPtThreshold > 0) && (gtrack->GetPt()< fPtThreshold)) continue;
1034             //if(gtrack->GetNHits() < fMinHits) continue;
1035             
1036             currenttrack = j;
1037             break;
1038         }
1039     }
1040
1041     return currenttrack;
1042 }
1043
1044 //----------------------------------------------------------------------------------------------------
1045 //                 EVENTS
1046 //____________________________________________________________________________________________________
1047 void AliHLTTPCDisplayMain::ExecPadEvent(Int_t event, Int_t px, Int_t py, TObject *selected){
1048    TCanvas *c = (TCanvas *) gTQSender;
1049
1050    if (event == 11 &&selected->InheritsFrom("TH2F")) {
1051         TH2F *hist = (TH2F*) selected;
1052
1053         Int_t binx = hist->GetXaxis()->FindBin(c->AbsPixeltoX(px)) -1 ;
1054 //      Int_t biny = hist->GetYaxis()->FindBin(c->AbsPixeltoY(py)) -1;
1055
1056         fPadCallback(fPt2Gui, binx);
1057   }
1058 }
1059
1060