]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/comp/AliHLTTPCCompModelDeconverter.cxx
coding conventions and compilation warnings and work on adaptive TPC data compression...
[u/mrichter/AliRoot.git] / HLT / TPCLib / comp / AliHLTTPCCompModelDeconverter.cxx
1 // $Id$
2
3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project        * 
5 //* ALICE Experiment at CERN, All rights reserved.                         *
6 //*                                                                        *
7 //* Primary Authors: Timm Steinbeck <timm@kip.uni-heidelberg.de>           *
8 //*                  for The ALICE HLT Project.                            *
9 //*                                                                        *
10 //* Permission to use, copy, modify and distribute this software and its   *
11 //* documentation strictly for non-commercial purposes is hereby granted   *
12 //* without fee, provided that the above copyright notice appears in all   *
13 //* copies and that both the copyright notice and this permission notice   *
14 //* appear in the supporting documentation. The authors make no claims     *
15 //* about the suitability of this software for any purpose. It is          *
16 //* provided "as is" without express or implied warranty.                  *
17 //**************************************************************************
18
19 /** @file   AliHLTTPCCompModelDeconverter.cxx
20     @author Timm Steinbeck
21     @date   
22     @brief  A copy processing component for the HLT. */
23
24 #if __GNUC__ >= 3
25 using namespace std;
26 #endif
27
28 #include "AliHLTTPCCompModelDeconverter.h"
29 #include "AliHLTTPCTransform.h"
30 #include "AliHLTTPCTrack.h"
31 #include "AliHLTTPCModelTrack.h"
32 #include "AliHLTTPCCompDataCompressorHelper.h"
33 #include <cerrno>
34
35 AliHLTTPCCompModelDeconverter::AliHLTTPCCompModelDeconverter():
36     fInputTrackArray("AliHLTTPCModelTrack"),
37     fTrackClusterModelData(0),
38     fTrackClusterModelDataSize(0),
39     fRemainingClustersModelData(0),
40     fRemainingClustersModelDataSize(0)
41     {
42       // see header file for class documentation
43       Init();
44     }
45
46 AliHLTTPCCompModelDeconverter::~AliHLTTPCCompModelDeconverter()
47     {
48       // see header file for class documentation
49     }
50
51 int AliHLTTPCCompModelDeconverter::Init()
52     {
53       // see header file for class documentation
54       fInputTrackArray.Reset();
55       fTrackClusterModelData = 0;
56       fTrackClusterModelDataSize = 0;
57       fRemainingClustersModelData = 0;
58       fRemainingClustersModelDataSize = 0;
59       return 0;
60     }
61
62
63 int AliHLTTPCCompModelDeconverter::SetTrackClusterModelInputData( AliHLTUInt8_t* data, UInt_t size )
64     {
65       // see header file for class documentation
66       fTrackClusterModelData = data;
67       fTrackClusterModelDataSize = size;
68       
69       AliHLTUInt8_t* inputPtr = fTrackClusterModelData;
70       AliHLTUInt8_t* inputEndPtr = fTrackClusterModelData+fTrackClusterModelDataSize;
71       
72       AliHLTUInt32_t version = *(AliHLTUInt32_t*)inputPtr;
73       inputPtr += sizeof(AliHLTUInt32_t);
74       if ( version != 0 )
75         {
76           HLTError( "Unsupported version %hu. Only version 0 supported currently.", version );
77           return EIO;
78         }
79       
80       while ( inputPtr+sizeof(AliHLTTPCTrackModel)+AliHLTTPCTransform::GetNRows()*sizeof(AliHLTTPCClusterModel) <= inputEndPtr )
81         {
82           AliHLTTPCModelTrack *track = (AliHLTTPCModelTrack*)fInputTrackArray.NextTrack();
83           if ( !track )
84             {
85               HLTError( "Error obtaining model track from track array." );
86               return EIO;
87             }
88           Int_t slice = ((AliHLTTPCClusterModel*)( inputPtr+sizeof(AliHLTTPCTrackModel) ))[ AliHLTTPCTransform::GetNRows()-1 ].fSlice;
89           track->Init(slice,-1);
90           AliHLTTPCTrackModel *model = track->GetModel();
91           AliHLTTPCClusterModel *clusters = track->GetClusters();
92           memcpy( model, inputPtr, sizeof(AliHLTTPCTrackModel) );
93           memcpy( clusters, inputPtr+sizeof(AliHLTTPCTrackModel), AliHLTTPCTransform::GetNRows()*sizeof(AliHLTTPCClusterModel) );
94           track->FillTrack();
95           
96           // validation test
97           //HLTInfo("track->GetNClusters() %d  GetNPresentClusters() %d", track->GetNClusters(), track->GetNPresentClusters());
98           
99           inputPtr += sizeof(AliHLTTPCTrackModel)+AliHLTTPCTransform::GetNRows()*sizeof(AliHLTTPCClusterModel);
100         }
101       
102       if ( inputPtr!=inputEndPtr )
103         {
104           HLTError( "Data format inconsistency on reading track model data." );
105           return EIO;
106         }
107       
108       return 0;
109     }
110
111 int AliHLTTPCCompModelDeconverter::SetRemainingClustersModelInputData( AliHLTUInt8_t* data, UInt_t size )
112     {
113       // see header file for class documentation
114       fRemainingClustersModelData = data;
115       fRemainingClustersModelDataSize = size;
116       
117       AliHLTUInt32_t version = *(AliHLTUInt32_t*)data;
118       if ( version != 0 )
119         {
120           HLTError( "Unsupported version %hu. Only version 0 supported currently.", version );
121           return EIO;
122         }
123       return 0;
124     }
125
126 int AliHLTTPCCompModelDeconverter::DeconvertTracks( AliHLTUInt8_t* data, UInt_t& size )
127     {
128       // see header file for class documentation
129       AliHLTTPCTrackletData* outPtr = (AliHLTTPCTrackletData*)data;
130       UInt_t blockSize = fInputTrackArray.WriteTracks( outPtr->fTrackletCnt, outPtr->fTracklets );
131       if ( blockSize >= size )
132         {
133           HLTError( "Output size is bigger than allowed (%u instead of %u)",
134                     (unsigned)blockSize, (unsigned)size );
135           size = 0;
136           return ENOBUFS;
137         }
138       size = blockSize;
139       
140       
141       UInt_t clusterCounts[36][6];
142       memset( clusterCounts, 0, sizeof(UInt_t)*36*6 );
143       
144       AliHLTTPCTrackSegmentData* tracklet = outPtr->fTracklets;
145       
146       // validation test
147       //HLTInfo("fTrackletCnt = %d", outPtr->fTrackletCnt);
148       //HLTInfo("tracklet Points = %d", tracklet->fNPoints);
149       
150       for ( UInt_t ii = 0; ii<outPtr->fTrackletCnt; ii++ )
151         {
152           // validation test
153           //HLTInfo("Tracklet points %d", tracklet->fNPoints);
154           for ( UInt_t jj=0; jj<tracklet->fNPoints; jj++ )
155             {
156               //validation test
157               //HLTInfo("Hello World %d !",jj);
158               UInt_t slice, partition;
159               slice = (tracklet->fPointIDs[jj]>>25) & 0x7f;
160               partition = (tracklet->fPointIDs[jj]>>22) & 0x7;
161               tracklet->fPointIDs[jj] = (clusterCounts[slice][partition] & ((1<<22)-1)) | ((partition & 0x7) << 22) | ((slice & 0x7F) << 25);
162               clusterCounts[slice][partition]++;
163             }
164           tracklet = (AliHLTTPCTrackSegmentData*) ( ((AliHLTUInt8_t*)tracklet)+sizeof(AliHLTTPCTrackSegmentData)+tracklet->fNPoints*sizeof(UInt_t) );
165         }
166       
167       return 0;
168     }
169
170 int AliHLTTPCCompModelDeconverter::DeconvertClusters( UInt_t slice, UInt_t patch, AliHLTUInt8_t* data, UInt_t& size )
171     {
172       // see header file for class documentation
173       if ( size<sizeof(AliHLTTPCClusterData) )
174         return ENOBUFS;
175       Int_t charge;
176       Float_t pad,time,sigmaY2,sigmaZ2;
177       AliHLTTPCClusterData* clusterData = (AliHLTTPCClusterData*)data;
178       clusterData->fSpacePointCnt = 0;
179       AliHLTTPCSpacePointData* clusters = clusterData->fSpacePoints;
180       unsigned long outSize = sizeof(AliHLTTPCClusterData);
181       for(Int_t i=0; i<fInputTrackArray.GetNTracks(); i++)
182         {
183           AliHLTTPCModelTrack *track = (AliHLTTPCModelTrack*)fInputTrackArray.GetCheckedTrack(i);
184           if(!track)
185             continue;
186           for(Int_t padrow=AliHLTTPCTransform::GetFirstRow(patch); padrow <= AliHLTTPCTransform::GetLastRow(patch); padrow++)
187             {
188               if(!track->IsPresent(padrow))
189                 continue;
190               UInt_t thisSlice = track->GetClusterModel(padrow)->fSlice;
191               if ( thisSlice != slice )
192                 continue;
193               if ( clusterData->fSpacePointCnt >= (1<<22) )
194                 {
195                   HLTError( "Too many clusters for slice %d patch %d", slice, patch );
196                   break;
197                 }
198               if ( size<=outSize+sizeof(AliHLTTPCSpacePointData) )
199                 {
200                   HLTError( "Not enough output space (%u bytes)", (unsigned)size );
201                   return ENOBUFS;
202                 }
203               track->GetPad(padrow,pad);
204               track->GetTime(padrow,time);
205               track->GetClusterCharge(padrow,charge);
206               //NEW: Get parameters to create parSigma correctly
207               //track->GetCrossingAngleLUT(padrow);
208               //track->CalculateClusterWidths(padrow,kTRUE); // calculates parSigmas (with parametrisation) in raw coordinates
209               //HLTInfo("dangle %f", track->GetCrossingAngleLUT(padrow));
210               //HLTInfo("dparsigma %f",track->GetParSigmaY2(padrow));
211               track->GetSigmaY2(padrow,sigmaY2);
212               //AliHLTTPCClusterModel* test1 = track->GetClusterModel(padrow);
213               //HLTInfo("DsigmaY deconv. : %f",test1->fDSigmaY);
214               //HLTInfo("sigmaY2 deconv.: %f",sigmaY2);
215               track->GetSigmaZ2(padrow,sigmaZ2);
216               Float_t xyz[3];
217               AliHLTTPCTransform::RawHLT2Local( xyz, slice, padrow, pad, time );
218               clusters[clusterData->fSpacePointCnt].fX = xyz[0];
219               clusters[clusterData->fSpacePointCnt].fY = xyz[1];
220               clusters[clusterData->fSpacePointCnt].fZ = xyz[2];
221               clusters[clusterData->fSpacePointCnt].fPadRow = padrow;
222               clusters[clusterData->fSpacePointCnt].fSigmaY2 = sigmaY2*pow(AliHLTTPCTransform::GetPadPitchWidth(patch),2);
223               clusters[clusterData->fSpacePointCnt].fSigmaZ2 = sigmaZ2*pow(AliHLTTPCTransform::GetZWidth(),2);;
224               clusters[clusterData->fSpacePointCnt].fCharge = charge;
225               clusters[clusterData->fSpacePointCnt].fUsed = kTRUE;
226               clusters[clusterData->fSpacePointCnt].fTrackN = i;
227               clusters[clusterData->fSpacePointCnt].fID = (clusterData->fSpacePointCnt & ((1<<22)-1)) | ((patch & 0x7) << 22) | ((slice & 0x7F) << 25);
228               clusterData->fSpacePointCnt++;
229               outSize += sizeof(AliHLTTPCSpacePointData);
230             }
231         }
232       
233     if ( fRemainingClustersModelDataSize )
234       {
235         AliHLTUInt8_t* inputPtr = fRemainingClustersModelData+sizeof(AliHLTUInt32_t);
236         AliHLTUInt8_t* inputEndPtr = inputPtr+fRemainingClustersModelDataSize;
237         for ( UInt_t thisSlice=0; thisSlice<36; thisSlice++ )
238           {
239             for ( UInt_t thisPatch=0; thisPatch<6; thisPatch++ )
240               {
241                 AliHLTUInt8_t rowCount = *inputPtr;
242                 inputPtr++;
243                 if ( !rowCount )
244                   {
245                     if ( thisSlice==slice && thisPatch==patch )
246                       break;
247                     continue;
248                   }
249                 for ( UInt_t jj=0; jj < rowCount; jj++ )
250                     {
251                       AliHLTTPCRemainingRow *thisRow = (AliHLTTPCRemainingRow*)inputPtr;
252                       if ( inputPtr+sizeof(AliHLTTPCRemainingRow)>inputEndPtr )
253                         {
254                           HLTError( "Corrupt input data, cannot read row data for row %u of slice %u, partition %u", (unsigned)jj, (unsigned)thisSlice, (unsigned)thisPatch );
255                           return EIO;
256                         }
257                       AliHLTTPCRemainingCluster *cl = thisRow->fClusters;
258                       if ( inputPtr+sizeof(AliHLTTPCRemainingRow)+thisRow->fNClusters*sizeof(AliHLTTPCRemainingCluster)>inputEndPtr )
259                         {
260                           HLTError( "Corrupt input data, unable to read clusters for row %u, slice %u, partition %u", (unsigned)jj, (unsigned)thisSlice, (unsigned)thisPatch );
261                           return EIO;
262                         }
263                       Int_t padrow = thisRow->fPadRow;
264                       if ( slice==thisSlice && patch==thisPatch )
265                         {
266                           for ( UInt_t ii=0; ii<thisRow->fNClusters; ii++ )
267                             {
268                               Float_t xyz[3];
269                               AliHLTTPCTransform::RawHLT2Local( xyz, slice, padrow, cl[ii].fPad, cl[ii].fTime );
270                               clusters[clusterData->fSpacePointCnt].fX = xyz[0];
271                               clusters[clusterData->fSpacePointCnt].fY = xyz[1];
272                               clusters[clusterData->fSpacePointCnt].fZ = xyz[2];
273                               clusters[clusterData->fSpacePointCnt].fPadRow = padrow;
274                               clusters[clusterData->fSpacePointCnt].fSigmaY2 = cl[ii].fSigmaY2*pow(AliHLTTPCTransform::GetPadPitchWidth(patch),2);
275                               clusters[clusterData->fSpacePointCnt].fSigmaZ2 = cl[ii].fSigmaZ2*pow(AliHLTTPCTransform::GetZWidth(),2);;
276                               clusters[clusterData->fSpacePointCnt].fCharge = cl[ii].fCharge;
277                               clusters[clusterData->fSpacePointCnt].fUsed = kFALSE;
278                               clusters[clusterData->fSpacePointCnt].fTrackN = -1;
279                               clusters[clusterData->fSpacePointCnt].fID = (clusterData->fSpacePointCnt & ((1<<22)-1)) | ((patch & 0x7) << 22) | ((slice & 0x7F) << 25);
280                               clusterData->fSpacePointCnt++;
281                               outSize += sizeof(AliHLTTPCSpacePointData);
282                             }
283                         }
284                       inputPtr += sizeof(AliHLTTPCRemainingRow)+thisRow->fNClusters*sizeof(AliHLTTPCRemainingCluster);
285                     }
286                 
287               }
288             if ( thisSlice==slice )
289               break;
290           }
291       }
292     
293     size = outSize;
294     return 0;
295     }