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