3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Timm Steinbeck <timm@kip.uni-heidelberg.de> *
8 //* for The ALICE HLT Project. *
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 //**************************************************************************
19 /** @file AliHLTTPCCompModelDeconverter.cxx
20 @author Timm Steinbeck
22 @brief A copy processing component for the HLT. */
28 #include "AliHLTTPCCompModelDeconverter.h"
29 #include "AliHLTTPCTransform.h"
30 #include "AliHLTTPCTrack.h"
31 #include "AliHLTTPCModelTrack.h"
32 #include "AliHLTTPCCompDataCompressorHelper.h"
35 AliHLTTPCCompModelDeconverter::AliHLTTPCCompModelDeconverter():
36 fInputTrackArray("AliHLTTPCModelTrack"),
37 fTrackClusterModelData(0),
38 fTrackClusterModelDataSize(0),
39 fRemainingClustersModelData(0),
40 fRemainingClustersModelDataSize(0)
42 // see header file for class documentation
46 AliHLTTPCCompModelDeconverter::~AliHLTTPCCompModelDeconverter()
48 // see header file for class documentation
51 int AliHLTTPCCompModelDeconverter::Init()
53 // see header file for class documentation
54 fInputTrackArray.Reset();
55 fTrackClusterModelData = 0;
56 fTrackClusterModelDataSize = 0;
57 fRemainingClustersModelData = 0;
58 fRemainingClustersModelDataSize = 0;
63 int AliHLTTPCCompModelDeconverter::SetTrackClusterModelInputData( AliHLTUInt8_t* data, UInt_t size )
65 // see header file for class documentation
66 fTrackClusterModelData = data;
67 fTrackClusterModelDataSize = size;
69 AliHLTUInt8_t* inputPtr = fTrackClusterModelData;
70 AliHLTUInt8_t* inputEndPtr = fTrackClusterModelData+fTrackClusterModelDataSize;
72 AliHLTUInt32_t version = *(AliHLTUInt32_t*)inputPtr;
73 inputPtr += sizeof(AliHLTUInt32_t);
76 HLTError( "Unsupported version %hu. Only version 0 supported currently.", version );
80 while ( inputPtr+sizeof(AliHLTTPCTrackModel)+AliHLTTPCTransform::GetNRows()*sizeof(AliHLTTPCClusterModel) <= inputEndPtr )
82 AliHLTTPCModelTrack *track = (AliHLTTPCModelTrack*)fInputTrackArray.NextTrack();
85 HLTError( "Error obtaining model track from track array." );
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) );
97 //HLTInfo("track->GetNClusters() %d GetNPresentClusters() %d", track->GetNClusters(), track->GetNPresentClusters());
99 inputPtr += sizeof(AliHLTTPCTrackModel)+AliHLTTPCTransform::GetNRows()*sizeof(AliHLTTPCClusterModel);
102 if ( inputPtr!=inputEndPtr )
104 HLTError( "Data format inconsistency on reading track model data." );
111 int AliHLTTPCCompModelDeconverter::SetRemainingClustersModelInputData( AliHLTUInt8_t* data, UInt_t size )
113 // see header file for class documentation
114 fRemainingClustersModelData = data;
115 fRemainingClustersModelDataSize = size;
117 AliHLTUInt32_t version = *(AliHLTUInt32_t*)data;
120 HLTError( "Unsupported version %hu. Only version 0 supported currently.", version );
126 int AliHLTTPCCompModelDeconverter::DeconvertTracks( AliHLTUInt8_t* data, UInt_t& size )
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 )
133 HLTError( "Output size is bigger than allowed (%u instead of %u)",
134 (unsigned)blockSize, (unsigned)size );
141 UInt_t clusterCounts[36][6];
142 memset( clusterCounts, 0, sizeof(UInt_t)*36*6 );
144 AliHLTTPCTrackSegmentData* tracklet = outPtr->fTracklets;
147 //HLTInfo("fTrackletCnt = %d", outPtr->fTrackletCnt);
148 //HLTInfo("tracklet Points = %d", tracklet->fNPoints);
150 for ( UInt_t ii = 0; ii<outPtr->fTrackletCnt; ii++ )
153 //HLTInfo("Tracklet points %d", tracklet->fNPoints);
154 for ( UInt_t jj=0; jj<tracklet->fNPoints; jj++ )
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]++;
164 tracklet = (AliHLTTPCTrackSegmentData*) ( ((AliHLTUInt8_t*)tracklet)+sizeof(AliHLTTPCTrackSegmentData)+tracklet->fNPoints*sizeof(UInt_t) );
170 int AliHLTTPCCompModelDeconverter::DeconvertClusters( UInt_t slice, UInt_t patch, AliHLTUInt8_t* data, UInt_t& size )
172 // see header file for class documentation
173 if ( size<sizeof(AliHLTTPCClusterData) )
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++)
183 AliHLTTPCModelTrack *track = (AliHLTTPCModelTrack*)fInputTrackArray.GetCheckedTrack(i);
186 for(Int_t padrow=AliHLTTPCTransform::GetFirstRow(patch); padrow <= AliHLTTPCTransform::GetLastRow(patch); padrow++)
188 if(!track->IsPresent(padrow))
190 UInt_t thisSlice = track->GetClusterModel(padrow)->fSlice;
191 if ( thisSlice != slice )
193 if ( clusterData->fSpacePointCnt >= (1<<22) )
195 HLTError( "Too many clusters for slice %d patch %d", slice, patch );
198 if ( size<=outSize+sizeof(AliHLTTPCSpacePointData) )
200 HLTError( "Not enough output space (%u bytes)", (unsigned)size );
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);
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);
233 if ( fRemainingClustersModelDataSize )
235 AliHLTUInt8_t* inputPtr = fRemainingClustersModelData+sizeof(AliHLTUInt32_t);
236 AliHLTUInt8_t* inputEndPtr = inputPtr+fRemainingClustersModelDataSize;
237 for ( UInt_t thisSlice=0; thisSlice<36; thisSlice++ )
239 for ( UInt_t thisPatch=0; thisPatch<6; thisPatch++ )
241 AliHLTUInt8_t rowCount = *inputPtr;
245 if ( thisSlice==slice && thisPatch==patch )
249 for ( UInt_t jj=0; jj < rowCount; jj++ )
251 AliHLTTPCRemainingRow *thisRow = (AliHLTTPCRemainingRow*)inputPtr;
252 if ( inputPtr+sizeof(AliHLTTPCRemainingRow)>inputEndPtr )
254 HLTError( "Corrupt input data, cannot read row data for row %u of slice %u, partition %u", (unsigned)jj, (unsigned)thisSlice, (unsigned)thisPatch );
257 AliHLTTPCRemainingCluster *cl = thisRow->fClusters;
258 if ( inputPtr+sizeof(AliHLTTPCRemainingRow)+thisRow->fNClusters*sizeof(AliHLTTPCRemainingCluster)>inputEndPtr )
260 HLTError( "Corrupt input data, unable to read clusters for row %u, slice %u, partition %u", (unsigned)jj, (unsigned)thisSlice, (unsigned)thisPatch );
263 Int_t padrow = thisRow->fPadRow;
264 if ( slice==thisSlice && patch==thisPatch )
266 for ( UInt_t ii=0; ii<thisRow->fNClusters; ii++ )
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);
284 inputPtr += sizeof(AliHLTTPCRemainingRow)+thisRow->fNClusters*sizeof(AliHLTTPCRemainingCluster);
288 if ( thisSlice==slice )