]>
Commit | Line | Data |
---|---|---|
a6c02c85 | 1 | // @(#) $Id$ |
4aa41877 | 2 | // Original: AliHLTMemHandler.cxx,v 1.52 2005/06/14 10:55:21 cvetan |
a6c02c85 | 3 | |
297174de | 4 | //************************************************************************** |
5 | //* This file is property of and copyright by the ALICE HLT Project * | |
6 | //* ALICE Experiment at CERN, All rights reserved. * | |
7 | //* * | |
8 | //* Primary Authors: U. Frankenfeld, A. Vestbo, C. Loizides * | |
9 | //* Matthias Richter <Matthias.Richter@ift.uib.no> * | |
10 | //* for The ALICE HLT Project. * | |
11 | //* * | |
12 | //* Permission to use, copy, modify and distribute this software and its * | |
13 | //* documentation strictly for non-commercial purposes is hereby granted * | |
14 | //* without fee, provided that the above copyright notice appears in all * | |
15 | //* copies and that both the copyright notice and this permission notice * | |
16 | //* appear in the supporting documentation. The authors make no claims * | |
17 | //* about the suitability of this software for any purpose. It is * | |
18 | //* provided "as is" without express or implied warranty. * | |
19 | //************************************************************************** | |
5578cf60 | 20 | |
ad7e2f5e | 21 | // @file AliHLTTPCMemHandler.cxx |
22 | // @author U. Frankenfeld, A. Vestbo, C. Loizides, maintained by | |
23 | // Matthias Richter | |
24 | // @date | |
25 | // @brief input interface base class for the TPC tracking code before | |
26 | // migration to the HLT component framework | |
a6c02c85 | 27 | |
0ba35c53 | 28 | #include <cassert> |
a6c02c85 | 29 | #include "AliHLTTPCRootTypes.h" |
a6c02c85 | 30 | #include "AliHLTTPCDigitData.h" |
31 | #include "AliHLTTPCLogging.h" | |
32 | #include "AliHLTTPCTransform.h" | |
33 | #include "AliHLTTPCTrackSegmentData.h" | |
34 | #include "AliHLTTPCSpacePointData.h" | |
35 | #include "AliHLTTPCTrackArray.h" | |
36 | #include "AliHLTTPCMemHandler.h" | |
ad7e2f5e | 37 | #include "TMath.h" |
a6c02c85 | 38 | |
39 | #if __GNUC__ >= 3 | |
40 | using namespace std; | |
41 | #endif | |
42 | ||
43 | ClassImp(AliHLTTPCMemHandler) | |
44 | ||
45 | AliHLTTPCMemHandler::AliHLTTPCMemHandler() | |
6235cd38 | 46 | : |
47 | fRowMin(0), | |
48 | fRowMax(0), | |
49 | fSlice(0), | |
50 | fPatch(0), | |
51 | fInBinary(NULL), | |
52 | fOutBinary(NULL), | |
53 | fPt(NULL), | |
54 | fSize(0), | |
55 | fIsRandom(kFALSE), | |
56 | fNRandom(0), | |
57 | fNGenerate(0), | |
58 | fNUsed(0), | |
59 | fNDigits(0), | |
60 | fDPt(NULL), | |
61 | fRandomDigits(NULL), | |
62 | fDummy(0) | |
a6c02c85 | 63 | { |
64 | //Constructor | |
a6c02c85 | 65 | Init(0,0); |
a6c02c85 | 66 | ResetROI(); |
67 | } | |
68 | ||
a6c02c85 | 69 | AliHLTTPCMemHandler::~AliHLTTPCMemHandler() |
70 | { | |
71 | //Destructor | |
72 | if(fPt) delete[] fPt; | |
73 | if(fRandomDigits) delete [] fRandomDigits; | |
74 | if(fDPt) delete [] fDPt; | |
75 | } | |
76 | ||
77 | void AliHLTTPCMemHandler::Init(Int_t s,Int_t p, Int_t *r) | |
78 | { | |
79 | //init handler | |
0ba35c53 | 80 | assert(s<fgkNSlice); |
81 | if (s>fgkNSlice) { | |
82 | fSlice=0; | |
83 | fPatch=0; | |
84 | fRowMin=0; | |
85 | fRowMax=0; | |
86 | if (r) *r=0; | |
87 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Init","sector coordinates") | |
88 | <<"Invalid slice no " << s <<ENDLOG; | |
89 | return; | |
90 | } | |
a6c02c85 | 91 | fSlice=s;fPatch=p; |
92 | if(r) { | |
93 | fRowMin=r[0]; | |
94 | fRowMax=r[1]; | |
95 | }else{ | |
96 | fRowMin=AliHLTTPCTransform::GetFirstRow(p); | |
97 | fRowMax=AliHLTTPCTransform::GetLastRow(p); | |
98 | } | |
99 | ResetROI(); | |
100 | } | |
101 | ||
102 | void AliHLTTPCMemHandler::ResetROI() | |
103 | { | |
104 | //Resets the Look-up table for Region of Interest mode. | |
105 | for(Int_t i=fRowMin; i<=fRowMax; i++) | |
106 | { | |
107 | fEtaMinTimeBin[i] = 0; | |
108 | fEtaMaxTimeBin[i] = AliHLTTPCTransform::GetNTimeBins()-1; | |
109 | } | |
110 | } | |
111 | ||
ad7e2f5e | 112 | void AliHLTTPCMemHandler::SetROI(const Float_t *eta,Int_t */*slice*/) |
a6c02c85 | 113 | { |
114 | // Init the Look-up table for the Region of Interest mode. | |
115 | // Here you can specify a certain etaregion, - all data | |
116 | // outside this region will be discarded: | |
117 | // eta[0] = mimium eta | |
118 | // eta[1] = maximum eta | |
119 | // slice[0] = mimumum slice | |
120 | // slice[1] = maximum slice | |
121 | ||
122 | ||
ad7e2f5e | 123 | if(TMath::Abs(eta[1])<.00001) |
a6c02c85 | 124 | { |
125 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::SetROI","Eta Values") | |
0ba35c53 | 126 | <<"Bad ROI parameters."<<ENDLOG; |
a6c02c85 | 127 | for(Int_t i=fRowMin; i<=fRowMax; i++) |
128 | { | |
129 | fEtaMinTimeBin[i]=0; | |
130 | fEtaMaxTimeBin[i]=0; | |
131 | } | |
132 | return; | |
133 | } | |
134 | ||
135 | for(Int_t i=fRowMin; i<=fRowMax; i++) | |
136 | { | |
137 | Int_t sector,row; | |
138 | Float_t xyz[3]; | |
139 | ||
140 | Float_t thetamax = 2*atan(exp(-1.*eta[1])); | |
141 | ||
142 | xyz[0] = AliHLTTPCTransform::Row2X(i); | |
143 | xyz[1]=0; | |
144 | xyz[2] = xyz[0]/tan(thetamax); | |
145 | AliHLTTPCTransform::Slice2Sector(fSlice,i,sector,row); | |
146 | AliHLTTPCTransform::Local2Raw(xyz,sector,row); | |
147 | ||
148 | fEtaMinTimeBin[i] = (Int_t)xyz[2]; | |
149 | ||
ad7e2f5e | 150 | if(TMath::Abs(eta[0])<.00001) |
a6c02c85 | 151 | fEtaMaxTimeBin[i] = 445; |
152 | else | |
153 | { | |
154 | Float_t thetamin = 2*atan(exp(-1.*eta[0])); | |
155 | xyz[0] = AliHLTTPCTransform::Row2X(i); | |
156 | xyz[1] = AliHLTTPCTransform::GetMaxY(i); | |
157 | Float_t radii = sqrt(pow(xyz[0],2) + pow(xyz[1],2)); | |
158 | xyz[2] = radii/tan(thetamin); | |
159 | AliHLTTPCTransform::Local2Raw(xyz,sector,row); | |
160 | fEtaMaxTimeBin[i] = (Int_t)xyz[2]; | |
161 | } | |
162 | } | |
163 | ||
164 | } | |
165 | ||
166 | Bool_t AliHLTTPCMemHandler::SetBinaryInput(char *name) | |
167 | { | |
168 | //Set the input binary file. | |
169 | fInBinary = fopen(name,"r"); | |
170 | if(!fInBinary){ | |
171 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::SetBinaryInput","File Open") | |
172 | <<"Error opening file "<<name<<ENDLOG; | |
173 | return kFALSE; | |
174 | } | |
175 | return kTRUE; | |
176 | } | |
177 | ||
178 | Bool_t AliHLTTPCMemHandler::SetBinaryInput(FILE *file) | |
179 | { | |
180 | //Set the input binary file. | |
181 | fInBinary = file; | |
182 | if(!fInBinary){ | |
183 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::SetBinaryInput","File Open") | |
184 | <<"Pointer to File = 0x0 "<<ENDLOG; | |
185 | return kFALSE; | |
186 | } | |
187 | return kTRUE; | |
188 | } | |
189 | ||
190 | void AliHLTTPCMemHandler::CloseBinaryInput() | |
191 | { | |
192 | //Close the input file. | |
193 | if(!fInBinary){ | |
194 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::CloseBinaryInput","File Close") | |
195 | <<"Nothing to Close"<<ENDLOG; | |
196 | return; | |
197 | } | |
198 | fclose(fInBinary); | |
199 | fInBinary =0; | |
200 | } | |
201 | ||
202 | Bool_t AliHLTTPCMemHandler::SetBinaryOutput(char *name) | |
203 | { | |
204 | //Set the binary output file. | |
205 | fOutBinary = fopen(name,"w"); | |
206 | if(!fOutBinary){ | |
207 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::SetBinaryOutput","File Open") | |
208 | <<"Pointer to File = 0x0 "<<ENDLOG; | |
209 | return kFALSE; | |
210 | } | |
211 | return kTRUE; | |
212 | } | |
213 | ||
214 | Bool_t AliHLTTPCMemHandler::SetBinaryOutput(FILE *file) | |
215 | { | |
216 | //Set the binary output file. | |
217 | fOutBinary = file; | |
218 | if(!fOutBinary){ | |
219 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::SetBinaryOutput","File Open") | |
220 | <<"Pointer to File = 0x0 "<<ENDLOG; | |
221 | return kFALSE; | |
222 | } | |
223 | return kTRUE; | |
224 | } | |
225 | ||
226 | void AliHLTTPCMemHandler::CloseBinaryOutput() | |
227 | { | |
228 | //close binary | |
229 | if(!fOutBinary){ | |
230 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::CloseBinaryOutPut","File Close") | |
231 | <<"Nothing to Close"<<ENDLOG; | |
232 | return; | |
233 | } | |
234 | fclose(fOutBinary); | |
235 | fOutBinary =0; | |
236 | } | |
237 | ||
238 | UInt_t AliHLTTPCMemHandler::GetFileSize() | |
239 | { | |
240 | //Returns the file size in bytes of the input file. | |
241 | if(!fInBinary){ | |
242 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::GetFileSize","File") | |
243 | <<"No Input File"<<ENDLOG; | |
244 | return 0; | |
245 | } | |
246 | fseek(fInBinary,0,SEEK_END); | |
247 | UInt_t size = (UInt_t) ftell(fInBinary); | |
248 | rewind(fInBinary); | |
249 | return size; | |
250 | } | |
251 | ||
252 | Byte_t *AliHLTTPCMemHandler::Allocate() | |
253 | { | |
254 | //Allocate | |
255 | return Allocate(GetFileSize()); | |
256 | } | |
257 | ||
258 | Byte_t *AliHLTTPCMemHandler::Allocate(AliHLTTPCTrackArray *array) | |
259 | { | |
260 | //Allocate memory for tracks in memory. Used by TrackArray2Binary() | |
261 | if(!array){ | |
262 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Allocate","Memory") | |
263 | <<"Pointer to AliHLTTPCTrackArray = 0x0 "<<ENDLOG; | |
264 | return 0; | |
265 | } | |
266 | return Allocate(array->GetOutSize()); | |
267 | } | |
268 | ||
269 | Byte_t *AliHLTTPCMemHandler::Allocate(UInt_t size) | |
270 | { | |
271 | //Allocate memory of size in bytes. | |
272 | if(fPt){ | |
273 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Allocate","Memory") | |
274 | <<"Delete Memory"<<ENDLOG; | |
275 | Free(); | |
276 | } | |
277 | fPt = new Byte_t[size]; | |
278 | fSize = size; | |
279 | memset(fPt,0,fSize); | |
280 | LOG(AliHLTTPCLog::kDebug,"AliHLTTPCMemHandler::Allocate","Memory") | |
281 | <<AliHLTTPCLog::kDec<<"Allocate "<<size<<" Bytes of Memory"<<ENDLOG; | |
282 | return fPt; | |
283 | } | |
284 | ||
285 | void AliHLTTPCMemHandler::Free() | |
286 | { | |
287 | //Clear the memory, if allocated. | |
288 | if(!fPt){ | |
289 | // LOG(AliHLTTPCLog::kInformational,"AliHLTTPCMemHandler::Free","Memory") | |
290 | // <<"No Memory allocated - can't Free"<<ENDLOG; | |
291 | return; | |
292 | } | |
293 | delete[] fPt; | |
294 | fPt = 0; | |
295 | fSize =0; | |
296 | } | |
297 | ||
298 | ///////////////////////////////////////// Random | |
299 | void AliHLTTPCMemHandler::SetRandomSeed() | |
300 | { | |
301 | //If you are adding random data to the original data. | |
302 | time_t *tp=0; | |
303 | SetRandomSeed(time(tp)); | |
304 | } | |
305 | ||
306 | void AliHLTTPCMemHandler::SetRandomCluster(Int_t maxnumber) | |
307 | { | |
308 | //If you are adding random data to the original data. | |
309 | ||
310 | fIsRandom = kTRUE; | |
311 | fNRandom = maxnumber; | |
312 | fNDigits = 0; | |
313 | if(fRandomDigits) delete [] fRandomDigits; | |
314 | fRandomDigits = new AliHLTTPCRandomDigitData[fNRandom*9]; | |
315 | if(fDPt) delete [] fDPt; | |
316 | fDPt = new AliHLTTPCRandomDigitData *[fNRandom*9]; | |
317 | } | |
318 | ||
319 | void AliHLTTPCMemHandler::QSort(AliHLTTPCRandomDigitData **a, Int_t first, Int_t last) | |
320 | { | |
321 | ||
322 | // Sort array of AliHLTTPCRandomDigitData pointers using a quicksort algorithm. | |
323 | // Uses CompareDigits() to compare objects. | |
324 | // Thanks to Root! | |
325 | ||
326 | static AliHLTTPCRandomDigitData *tmp; | |
327 | static int i; // "static" to save stack space | |
328 | int j; | |
329 | ||
330 | while (last - first > 1) { | |
331 | i = first; | |
332 | j = last; | |
333 | for (;;) { | |
334 | while (++i < last && CompareDigits(a[i], a[first]) < 0) | |
335 | ; | |
336 | while (--j > first && CompareDigits(a[j], a[first]) > 0) | |
337 | ; | |
338 | if (i >= j) | |
339 | break; | |
340 | ||
341 | tmp = a[i]; | |
342 | a[i] = a[j]; | |
343 | a[j] = tmp; | |
344 | } | |
345 | if (j == first) { | |
346 | ++first; | |
347 | continue; | |
348 | } | |
349 | tmp = a[first]; | |
350 | a[first] = a[j]; | |
351 | a[j] = tmp; | |
352 | ||
353 | if (j - first < last - (j + 1)) { | |
354 | QSort(a, first, j); | |
355 | first = j + 1; // QSort(j + 1, last); | |
356 | } else { | |
357 | QSort(a, j + 1, last); | |
358 | last = j; // QSort(first, j); | |
359 | } | |
360 | } | |
361 | } | |
362 | ||
363 | UInt_t AliHLTTPCMemHandler::GetRandomSize() const | |
364 | { | |
365 | //get random size | |
366 | Int_t nrandom = 0; | |
367 | for(Int_t r=fRowMin;r<=fRowMax;r++){ | |
368 | Int_t npad=AliHLTTPCTransform::GetNPads(r); | |
369 | nrandom += Int_t (fNGenerate * ((Double_t) npad/141.)); | |
370 | } | |
371 | return 9 * nrandom * sizeof(AliHLTTPCDigitData); | |
372 | } | |
373 | ||
374 | void AliHLTTPCMemHandler::Generate(Int_t row) | |
375 | { | |
376 | //Generate random data on row, if you didn't | |
377 | //ask for this, nothing happens here. | |
378 | ||
379 | if(!fIsRandom) return; | |
380 | ResetRandom(); | |
381 | fNDigits = 0; | |
382 | Int_t npad=AliHLTTPCTransform::GetNPads(row); | |
383 | Int_t ntime = fEtaMaxTimeBin[row] - fEtaMinTimeBin[row]; | |
384 | Int_t nrandom = Int_t (fNGenerate * ((Double_t) npad/141.) * | |
385 | (Double_t) ntime/(Double_t) AliHLTTPCTransform::GetNTimeBins() ); | |
386 | ||
387 | for(Int_t n=0;n<nrandom;n++){ | |
388 | Int_t pad = (int)((float)rand()/RAND_MAX*npad); | |
389 | Int_t time =(int)((float)rand()/RAND_MAX*ntime+fEtaMinTimeBin[row] ); | |
390 | Int_t charge = (int)((float)rand()/RAND_MAX*AliHLTTPCTransform::GetADCSat()); | |
391 | DigitizePoint(row,pad,time,charge); | |
392 | } | |
393 | QSort(fDPt,0,fNDigits); | |
394 | } | |
395 | ||
396 | ||
397 | void AliHLTTPCMemHandler::DigitizePoint(Int_t row, Int_t pad, | |
398 | Int_t time,Int_t charge) | |
399 | { | |
400 | //Making one single random cluster. | |
401 | for(Int_t j=-1;j<2;j++){ | |
402 | for(Int_t k=-1;k<2;k++){ | |
403 | Int_t dcharge = charge; | |
404 | if(j) dcharge /=2; | |
405 | if(k) dcharge /=2; | |
406 | if(dcharge<10) continue; | |
407 | Int_t dpad = j + pad; | |
408 | Int_t dtime = k + time; | |
409 | ||
410 | if(dpad<0||dpad>=AliHLTTPCTransform::GetNPads(row)) continue; | |
411 | if(dtime<0||dtime>=AliHLTTPCTransform::GetNTimeBins()) continue; | |
412 | ||
413 | fRandomDigits[fNDigits].fCharge = dcharge; | |
414 | fRandomDigits[fNDigits].fRow = row; | |
415 | fRandomDigits[fNDigits].fPad = dpad; | |
416 | fRandomDigits[fNDigits].fTime = dtime; | |
417 | fDPt[fNDigits] = &fRandomDigits[fNDigits]; | |
418 | fNDigits++; | |
419 | } | |
420 | } | |
421 | } | |
422 | ||
423 | ///////////////////////////////////////// Digit IO | |
5578cf60 | 424 | Bool_t AliHLTTPCMemHandler::Memory2BinaryFile(UInt_t nrow,AliHLTTPCDigitRowData *data) |
a6c02c85 | 425 | { |
426 | //Write data to the outputfile as is. No run-length encoding is done. | |
5578cf60 | 427 | |
a6c02c85 | 428 | if(!fOutBinary){ |
429 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Memory2Binary","File") | |
430 | <<"No Output File"<<ENDLOG; | |
431 | return kFALSE; | |
432 | } | |
433 | if(!data){ | |
434 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Memory2Binary","Memory") | |
435 | <<"Pointer to AliHLTTPCDigitRowData = 0x0 "<<ENDLOG; | |
436 | return kFALSE; | |
437 | } | |
438 | ||
439 | AliHLTTPCDigitRowData *rowPt = data; | |
440 | Int_t outsize = 0; | |
441 | for(UInt_t i=0;i<nrow;i++){ | |
442 | Int_t size = sizeof(AliHLTTPCDigitData) * rowPt->fNDigit | |
443 | + sizeof(AliHLTTPCDigitRowData); | |
444 | outsize += size; | |
445 | fwrite(rowPt,size,1,fOutBinary); | |
446 | Byte_t *bytePt =(Byte_t *) rowPt; | |
447 | bytePt += size; | |
448 | rowPt = (AliHLTTPCDigitRowData *) bytePt; | |
449 | } | |
450 | LOG(AliHLTTPCLog::kDebug,"AliHLTTPCMemHandler::Memory2Binary","Memory") | |
451 | <<AliHLTTPCLog::kDec<<"Wrote "<<outsize<<" Bytes to Memory (" | |
452 | <<nrow<<" Rows)"<<ENDLOG; | |
453 | return kTRUE; | |
454 | } | |
455 | ||
a38a7850 | 456 | Bool_t AliHLTTPCMemHandler::Binary2Memory(UInt_t & nrow,AliHLTTPCDigitRowData *data,UInt_t& sz) |
a6c02c85 | 457 | { |
458 | //Read inputfile into memory as is, and store it in data. | |
459 | // No run-length encoding is assumed. | |
460 | ||
461 | if(!fInBinary){ | |
462 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Binary2Memory","File") | |
463 | <<"No Input File"<<ENDLOG; | |
464 | return kFALSE; | |
465 | } | |
466 | if(!data){ | |
467 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Binary2Memory","Memory") | |
468 | <<"Pointer to AliHLTTPCDigitRowData = 0x0 "<<ENDLOG; | |
469 | return kFALSE; | |
470 | } | |
471 | rewind(fInBinary); | |
472 | AliHLTTPCDigitRowData *rowPt = data; | |
473 | UInt_t rowcount = 0; | |
298ef463 | 474 | UInt_t outsize =0; |
a6c02c85 | 475 | while(!feof(fInBinary)){ |
476 | Byte_t *bytePt =(Byte_t *) rowPt; | |
477 | ||
5578cf60 | 478 | if (sz<outsize+sizeof(AliHLTTPCDigitRowData)) { |
479 | LOG(AliHLTTPCLog::kFatal,"AliHLTTPCMemHandler::Binary2Memory","Memory") | |
480 | << "target data buffer too small" <<ENDLOG; | |
481 | return kFALSE; | |
482 | } | |
a6c02c85 | 483 | if(fread(rowPt,sizeof(AliHLTTPCDigitRowData),1,fInBinary)!=1) break; |
484 | ||
485 | bytePt += sizeof(AliHLTTPCDigitRowData); | |
486 | outsize += sizeof(AliHLTTPCDigitRowData); | |
487 | ||
298ef463 | 488 | UInt_t size = sizeof(AliHLTTPCDigitData) * rowPt->fNDigit; |
a6c02c85 | 489 | |
5578cf60 | 490 | if (sz<outsize+size) { |
491 | LOG(AliHLTTPCLog::kFatal,"AliHLTTPCMemHandler::Binary2Memory","Memory") | |
492 | << "target data buffer too small" <<ENDLOG; | |
493 | return kFALSE; | |
494 | } | |
a6c02c85 | 495 | //if(fread(bytePt,size,1,fInBinary)!=1) break; |
496 | fread(bytePt,size,1,fInBinary); | |
497 | bytePt += size; | |
498 | outsize += size; | |
499 | rowPt = (AliHLTTPCDigitRowData *) bytePt; | |
500 | rowcount++; | |
501 | } | |
502 | nrow= rowcount; | |
503 | LOG(AliHLTTPCLog::kDebug,"AliHLTTPCMemHandler::Binary2Memory","Memory") | |
504 | <<AliHLTTPCLog::kDec<<"Wrote "<<outsize<<" Bytes to Memory (" | |
505 | <<rowcount<<" Rows)"<<ENDLOG; | |
a38a7850 | 506 | sz = outsize; |
a6c02c85 | 507 | return kTRUE; |
508 | } | |
509 | ||
510 | void AliHLTTPCMemHandler::AddData(AliHLTTPCDigitData *data,UInt_t & ndata, | |
511 | UInt_t /*row*/,UShort_t pad,UShort_t time,UShort_t charge) const | |
512 | { | |
513 | //add some data | |
514 | data[ndata].fPad = pad; | |
515 | data[ndata].fTime = time; | |
516 | data[ndata].fCharge = charge; | |
517 | ndata++; | |
518 | } | |
519 | ||
520 | void AliHLTTPCMemHandler::AddRandom(AliHLTTPCDigitData *data, UInt_t & ndata) | |
521 | { | |
522 | //add some random data | |
523 | data[ndata].fPad = fDPt[fNUsed]->fPad; | |
524 | data[ndata].fTime = fDPt[fNUsed]->fTime; | |
525 | data[ndata].fCharge = fDPt[fNUsed]->fCharge; | |
526 | ndata++; | |
527 | fNUsed++; | |
528 | } | |
529 | ||
530 | void AliHLTTPCMemHandler::MergeDataRandom(AliHLTTPCDigitData *data, UInt_t & ndata, | |
531 | UInt_t row, UShort_t pad, UShort_t time, UShort_t charge) | |
532 | { | |
533 | //merge random data | |
534 | data[ndata].fPad = pad; | |
535 | data[ndata].fTime = time; | |
536 | data[ndata].fCharge = charge; | |
537 | while(ComparePoints(row,pad,time)==0){ | |
538 | Int_t ch = data[ndata].fCharge + fDPt[fNUsed]->fCharge; | |
539 | if(charge>=AliHLTTPCTransform::GetADCSat()) ch = AliHLTTPCTransform::GetADCSat(); | |
540 | data[ndata].fCharge = ch; | |
541 | fNUsed++; | |
542 | } | |
543 | ndata++; | |
544 | } | |
545 | ||
546 | void AliHLTTPCMemHandler::AddDataRandom(AliHLTTPCDigitData *data, UInt_t & ndata, | |
547 | UInt_t row, UShort_t pad, UShort_t time, UShort_t charge) | |
548 | { | |
549 | //add data random | |
550 | Int_t action; | |
551 | while((action=ComparePoints(row,pad,time))==1){ | |
552 | AddRandom(data,ndata); | |
553 | } | |
554 | if(action==0){ | |
555 | MergeDataRandom(data,ndata,row,pad,time,charge); | |
556 | } | |
557 | if(action<0){ | |
558 | AddData(data,ndata,row,pad,time,charge); | |
559 | } | |
560 | } | |
561 | ||
562 | void AliHLTTPCMemHandler::Write(UInt_t *comp, UInt_t & index, | |
563 | UInt_t & subindex, UShort_t value) const | |
564 | { | |
565 | //write compressed data | |
566 | UInt_t shift[3] = {0,10,20}; | |
567 | if(subindex==0) comp[index] =0; //clean up memory | |
568 | comp[index] |= (value&0x03ff)<<shift[subindex]; | |
569 | if(subindex == 2){ | |
570 | subindex = 0; | |
571 | index++; | |
572 | } | |
573 | else subindex++; | |
574 | } | |
575 | ||
576 | UShort_t AliHLTTPCMemHandler::Read(UInt_t *comp, UInt_t & index, UInt_t & subindex) const | |
577 | { | |
578 | //read compressed data | |
579 | UInt_t shift[3] = {0,10,20}; | |
580 | UShort_t value = (comp[index]>>shift[subindex])&0x03ff; | |
581 | if(subindex == 2){ | |
582 | subindex = 0; | |
583 | index++; | |
584 | } | |
585 | else subindex++; | |
586 | ||
587 | return value; | |
588 | } | |
589 | ||
ad7e2f5e | 590 | UShort_t AliHLTTPCMemHandler::Test(const UInt_t *comp, |
a6c02c85 | 591 | UInt_t index, UInt_t subindex) const |
592 | { | |
593 | //supi dupi test | |
594 | UInt_t shift[3] = {0,10,20}; | |
595 | return (comp[index]>>shift[subindex])&0x03ff; | |
596 | } | |
597 | ||
598 | Int_t AliHLTTPCMemHandler::Memory2CompMemory(UInt_t nrow, | |
599 | AliHLTTPCDigitRowData *data,UInt_t *comp) | |
600 | { | |
601 | //Performs run-length encoding on data stored in memory pointed to by data. | |
602 | //The compressed data is written to comp. | |
603 | if(!comp){ | |
604 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Memory2CompMemory","Memory") | |
605 | <<"Pointer to compressed data = 0x0 "<<ENDLOG; | |
606 | return 0; | |
607 | } | |
608 | if(!data){ | |
609 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Memory2CompMemory","Memory") | |
610 | <<"Pointer to AliHLTTPCDigitRowData = 0x0 "<<ENDLOG; | |
611 | return 0; | |
612 | } | |
613 | AliHLTTPCDigitRowData *rowPt = data; | |
614 | UInt_t index=0; | |
615 | UInt_t subindex=0; | |
616 | ||
617 | for(UInt_t i=0;i<nrow;i++){ | |
618 | UShort_t value = rowPt->fRow; | |
619 | Write(comp,index,subindex,value); | |
620 | UShort_t maxpad=0; | |
621 | UShort_t npad=0; | |
622 | Int_t ddd[1000]; | |
623 | for(Int_t d=0;d<200;d++) ddd[d]=0; | |
624 | for(UInt_t dig=0;dig<rowPt->fNDigit;dig++){ | |
625 | if(rowPt->fDigitData[dig].fPad <200){ | |
626 | ddd[rowPt->fDigitData[dig].fPad]++; | |
627 | } | |
628 | } | |
629 | for(Int_t d=0;d<200;d++){ | |
630 | if(ddd[d]){ | |
631 | npad++; | |
632 | maxpad =d; | |
633 | } | |
634 | } | |
635 | Write(comp,index,subindex,npad); | |
636 | UInt_t digit=0; | |
637 | for(UShort_t pad=0;pad <= maxpad;pad++){ | |
638 | if(digit>=rowPt->fNDigit || rowPt->fDigitData[digit].fPad != pad) | |
639 | continue; | |
640 | Write(comp,index,subindex,pad); | |
641 | // write zero if time != 0 | |
642 | if(digit<rowPt->fNDigit && rowPt->fDigitData[digit].fPad == pad){ | |
643 | if(rowPt->fDigitData[digit].fTime>0){ | |
644 | Write(comp,index,subindex,0); | |
645 | Write(comp,index,subindex,rowPt->fDigitData[digit].fTime); | |
646 | } | |
647 | } | |
648 | while(digit<rowPt->fNDigit && rowPt->fDigitData[digit].fPad == pad){ | |
649 | UShort_t charge = rowPt->fDigitData[digit].fCharge; | |
650 | if(charge>=1023){ | |
651 | charge=1023; | |
652 | } | |
653 | Write(comp,index,subindex,charge); | |
654 | if(digit+1<rowPt->fNDigit&&rowPt->fDigitData[digit+1].fPad == pad){ | |
655 | if(rowPt->fDigitData[digit].fTime +1 != | |
656 | rowPt->fDigitData[digit+1].fTime){ | |
657 | Write(comp,index,subindex,0); | |
658 | UShort_t nzero = rowPt->fDigitData[digit+1].fTime - | |
659 | (rowPt->fDigitData[digit].fTime +1); | |
660 | Write(comp,index,subindex,nzero); | |
661 | } | |
662 | } | |
663 | digit++; | |
664 | } | |
665 | Write(comp,index,subindex,0); | |
666 | Write(comp,index,subindex,0); | |
667 | } | |
668 | ||
669 | Int_t size = sizeof(AliHLTTPCDigitData) * rowPt->fNDigit+ | |
670 | sizeof(AliHLTTPCDigitRowData); | |
671 | Byte_t *bytePt =(Byte_t *) rowPt; | |
672 | bytePt += size; | |
673 | rowPt = (AliHLTTPCDigitRowData *) bytePt; | |
674 | } | |
675 | while(subindex) | |
676 | Write(comp,index,subindex,0); | |
677 | return index * sizeof(UInt_t); | |
678 | } | |
679 | ||
680 | Int_t AliHLTTPCMemHandler::CompMemory2Memory(UInt_t nrow, | |
a38a7850 | 681 | AliHLTTPCDigitRowData *data,UInt_t *comp, UInt_t& sz) |
a6c02c85 | 682 | { |
683 | //Uncompress the run-length encoded data in memory pointed to by comp, and | |
684 | // store it in data. | |
685 | ||
686 | if(!comp){ | |
687 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::CompMemory2Memory","Memory") | |
688 | <<"Pointer to compressed data = 0x0 "<<ENDLOG; | |
689 | return 0; | |
690 | } | |
691 | if(!data){ | |
692 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::CompMemory2Memory","Memory") | |
693 | <<"Pointer to AliHLTTPCDigitRowData = 0x0 "<<ENDLOG; | |
694 | return 0; | |
695 | } | |
696 | Int_t outsize=0; | |
697 | ||
698 | AliHLTTPCDigitRowData *rowPt = data; | |
699 | UInt_t index=0; | |
700 | UInt_t subindex=0; | |
701 | ||
702 | for(UInt_t i=0;i<nrow;i++){ | |
703 | UInt_t ndigit=0; | |
704 | UInt_t row =Read(comp,index,subindex); | |
705 | rowPt->fRow=row; | |
706 | Generate(row); | |
707 | UShort_t npad = Read(comp,index,subindex); | |
708 | for(UShort_t p=0;p<npad;p++){ | |
709 | UShort_t charge; | |
710 | UShort_t time =0; | |
711 | UShort_t pad = Read(comp,index,subindex); | |
712 | if(Test(comp,index,subindex)==0){ | |
713 | Read(comp,index,subindex); | |
714 | if( (time = Read(comp,index,subindex)) == 0 ){ | |
715 | continue; | |
716 | } | |
717 | } | |
718 | for(;;){ | |
719 | while( (charge=Read(comp,index,subindex)) != 0){ | |
720 | if(time>=fEtaMinTimeBin[row]&&time<=fEtaMaxTimeBin[row]) | |
721 | //AddData(rowPt->fDigitData,ndigit,row,pad,time,charge); | |
722 | //seems we are using this function... but dont know why | |
723 | AddDataRandom(rowPt->fDigitData,ndigit,row,pad,time,charge); | |
724 | time++; | |
725 | } | |
726 | UShort_t tshift = Read(comp,index,subindex); | |
727 | if(tshift == 0) break; | |
728 | time += tshift; | |
729 | } | |
730 | } | |
731 | rowPt->fNDigit = ndigit; | |
732 | Int_t size = sizeof(AliHLTTPCDigitData) * rowPt->fNDigit+ | |
733 | sizeof(AliHLTTPCDigitRowData); | |
734 | Byte_t *bytePt =(Byte_t *) rowPt; | |
735 | bytePt += size; | |
736 | outsize += size; | |
737 | rowPt = (AliHLTTPCDigitRowData *) bytePt; | |
738 | } | |
a38a7850 | 739 | sz = outsize; |
a6c02c85 | 740 | return outsize; |
741 | } | |
742 | ||
743 | UInt_t AliHLTTPCMemHandler::GetCompMemorySize(UInt_t nrow,AliHLTTPCDigitRowData *data) const | |
744 | { | |
745 | //Return the size of RLE data, after compressing data. | |
746 | ||
747 | if(!data){ | |
748 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::GetCompMemorySize","Memory") | |
749 | <<"Pointer to AliHLTTPCDigitRowData = 0x0 "<<ENDLOG; | |
750 | return 0; | |
751 | } | |
752 | AliHLTTPCDigitRowData *rowPt = data; | |
753 | UInt_t index=0; | |
754 | ||
755 | for(UInt_t i=0;i<nrow;i++){ | |
756 | index++; | |
757 | UShort_t maxpad=0; | |
758 | UShort_t npad=0; | |
759 | Int_t ddd[1000]; | |
760 | for(Int_t d=0;d<200;d++) ddd[d]=0; | |
761 | for(UInt_t dig=0;dig<rowPt->fNDigit;dig++){ | |
762 | if(rowPt->fDigitData[dig].fPad <200){ | |
763 | ddd[rowPt->fDigitData[dig].fPad]++; | |
764 | } | |
765 | } | |
766 | for(Int_t d=0;d<200;d++){ | |
767 | if(ddd[d]){ | |
768 | npad++; | |
769 | maxpad =d; | |
770 | } | |
771 | } | |
772 | index++; | |
773 | UInt_t digit=0; | |
774 | for(UShort_t pad=0;pad <= maxpad;pad++){ | |
775 | if(digit>=rowPt->fNDigit || rowPt->fDigitData[digit].fPad != pad) | |
776 | continue; | |
777 | index++; | |
778 | // write zero if time != 0 | |
779 | if(digit<rowPt->fNDigit && rowPt->fDigitData[digit].fPad == pad){ | |
780 | if(rowPt->fDigitData[digit].fTime>0){ | |
781 | index++; | |
782 | index++; | |
783 | } | |
784 | } | |
785 | while(digit<rowPt->fNDigit && rowPt->fDigitData[digit].fPad == pad){ | |
786 | index++; | |
787 | if(digit+1<rowPt->fNDigit&&rowPt->fDigitData[digit+1].fPad == pad){ | |
788 | if(rowPt->fDigitData[digit].fTime +1 != | |
789 | rowPt->fDigitData[digit+1].fTime){ | |
790 | index++; | |
791 | index++; | |
792 | } | |
793 | } | |
794 | digit++; | |
795 | } | |
796 | index++; | |
797 | index++; | |
798 | } | |
799 | ||
800 | Int_t size = sizeof(AliHLTTPCDigitData) * rowPt->fNDigit+ | |
801 | sizeof(AliHLTTPCDigitRowData); | |
802 | Byte_t *bytePt =(Byte_t *) rowPt; | |
803 | bytePt += size; | |
804 | rowPt = (AliHLTTPCDigitRowData *) bytePt; | |
805 | } | |
806 | while(index%3) | |
807 | index++; | |
808 | return (index/3) * sizeof(UInt_t); | |
809 | } | |
810 | ||
811 | UInt_t AliHLTTPCMemHandler::GetMemorySize(UInt_t nrow,UInt_t *comp) const | |
812 | { | |
813 | //get memory size | |
814 | if(!comp){ | |
815 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::GetMemorySize","Memory") | |
816 | <<"Pointer to compressed data = 0x0 "<<ENDLOG; | |
817 | return 0; | |
818 | } | |
819 | Int_t outsize=0; | |
820 | ||
821 | UInt_t index=0; | |
822 | UInt_t subindex=0; | |
823 | ||
824 | for(UInt_t i=0;i<nrow;i++){ | |
825 | UInt_t ndigit=0; | |
826 | Read(comp,index,subindex); | |
827 | UShort_t npad = Read(comp,index,subindex); | |
828 | for(UShort_t p=0;p<npad;p++){ | |
829 | Read(comp,index,subindex); | |
830 | if(Test(comp,index,subindex)==0){ | |
831 | Read(comp,index,subindex); | |
832 | if(Read(comp,index,subindex)== 0) continue; | |
833 | } | |
834 | for(;;){ | |
835 | while(Read(comp,index,subindex)!=0) ndigit++; | |
836 | if(Read(comp,index,subindex)==0) break; | |
837 | } | |
838 | } | |
839 | Int_t size = sizeof(AliHLTTPCDigitData) * ndigit+ | |
840 | sizeof(AliHLTTPCDigitRowData); | |
841 | outsize += size; | |
842 | } | |
843 | ||
844 | return outsize; | |
845 | } | |
846 | ||
847 | UInt_t AliHLTTPCMemHandler::GetNRow(UInt_t *comp,UInt_t size) | |
848 | { | |
849 | //get number of rows | |
850 | if(!comp){ | |
851 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::GetNRow","Memory") | |
852 | <<"Pointer to compressed data = 0x0 "<<ENDLOG; | |
853 | return 0; | |
854 | } | |
855 | size = size /4; | |
856 | UInt_t nrow=0; | |
857 | UInt_t index=0; | |
858 | UInt_t subindex=0; | |
859 | while(index<size-1){ //don't start with last word | |
860 | nrow++; | |
861 | UInt_t ndigit=0; | |
862 | Read(comp,index,subindex); | |
863 | UShort_t npad = Read(comp,index,subindex); | |
864 | for(UShort_t p=0;p<npad;p++){ | |
865 | Read(comp,index,subindex); | |
866 | if(Test(comp,index,subindex)==0){ | |
867 | Read(comp,index,subindex); | |
868 | if(Read(comp,index,subindex)==0)continue; | |
869 | } | |
870 | for(;;){ | |
871 | while(Read(comp,index,subindex)!=0) ndigit++; | |
872 | if(Read(comp,index,subindex)==0) break; | |
873 | } | |
874 | } | |
875 | } | |
876 | if(index==size-1){ //last word | |
877 | if(subindex<2){ | |
878 | if(Read(comp,index,subindex)!=0) nrow++; | |
879 | } | |
880 | } | |
881 | return nrow; | |
882 | } | |
883 | ||
884 | Bool_t AliHLTTPCMemHandler::CompMemory2CompBinary(UInt_t nrow,UInt_t *comp, | |
885 | UInt_t size) | |
886 | { | |
887 | //Write the RLE data in comp to the output file. | |
888 | ||
889 | if(!fOutBinary){ | |
890 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::CompMemory2CompBinary","File") | |
891 | <<"No Output File"<<ENDLOG; | |
892 | return kFALSE; | |
893 | } | |
894 | if(!comp){ | |
895 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::CompMemory2CompBinary","Memory") | |
896 | <<"Pointer to compressed data = 0x0 "<<ENDLOG; | |
897 | return kFALSE; | |
898 | } | |
899 | if(size==0) | |
900 | size=GetMemorySize(nrow,comp); | |
901 | if(!size){ | |
902 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::CompMemory2CompBinary","Memory") | |
903 | <<"Memory size = 0 "<<ENDLOG; | |
904 | return kFALSE; | |
905 | } | |
906 | UInt_t length = size/sizeof(UInt_t); | |
907 | fwrite(&length,sizeof(UInt_t),1,fOutBinary); | |
908 | fwrite(comp,size,1,fOutBinary); | |
909 | return kTRUE; | |
910 | } | |
911 | ||
912 | Bool_t AliHLTTPCMemHandler::CompBinary2CompMemory(UInt_t & nrow,UInt_t *comp) | |
913 | { | |
914 | //Read the RLE data from file, and store it in comp. No unpacking yet. | |
915 | ||
916 | if(!fInBinary){ | |
917 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::CompBinary2CompMemory","File") | |
918 | <<"No Output File"<<ENDLOG; | |
919 | return kFALSE; | |
920 | } | |
921 | if(!comp){ | |
922 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::CompBinary2CompMemory","Memory") | |
923 | <<"Pointer to compressed data = 0x0 "<<ENDLOG; | |
924 | return kFALSE; | |
925 | } | |
926 | rewind(fInBinary); | |
927 | UInt_t length; | |
928 | if(fread(&length,sizeof(UInt_t),1,fInBinary)!=1) return kFALSE; | |
929 | UInt_t size = length*sizeof(UInt_t); | |
930 | if(fread(comp,size,1,fInBinary)!=1) return kFALSE; | |
931 | // now find the number of dig | |
932 | nrow = GetNRow(comp,size); | |
933 | return kTRUE; | |
934 | } | |
935 | ||
a38a7850 | 936 | AliHLTTPCDigitRowData *AliHLTTPCMemHandler::CompBinary2Memory(UInt_t & nrow, UInt_t& sz ) |
a6c02c85 | 937 | { |
938 | // Read the RLE inputfile, unpack it and return the pointer to it. | |
939 | AliHLTTPCMemHandler * handler = new AliHLTTPCMemHandler(); | |
940 | handler->SetBinaryInput(fInBinary); | |
941 | UInt_t *comp =(UInt_t *)handler->Allocate(); | |
942 | handler->CompBinary2CompMemory(nrow,comp); | |
943 | UInt_t size = GetMemorySize(nrow,comp); | |
a38a7850 | 944 | sz = size; |
a6c02c85 | 945 | AliHLTTPCDigitRowData *data = (AliHLTTPCDigitRowData *)Allocate(size); |
946 | CompMemory2Memory(nrow,data,comp); | |
947 | handler->Free(); | |
948 | delete handler; | |
949 | return data; | |
950 | } | |
951 | ||
952 | Bool_t AliHLTTPCMemHandler::Memory2CompBinary(UInt_t nrow,AliHLTTPCDigitRowData *data) | |
953 | { | |
954 | //Perform RLE on the data, and write it to the output file. | |
955 | Bool_t out = kTRUE; | |
956 | AliHLTTPCMemHandler * handler = new AliHLTTPCMemHandler(); | |
957 | UInt_t size = GetCompMemorySize(nrow,data); | |
958 | UInt_t *comp =(UInt_t *)handler->Allocate(size); | |
959 | Memory2CompMemory(nrow,data,comp); | |
960 | CompMemory2CompBinary(nrow,comp,size); | |
961 | handler->Free(); | |
962 | delete handler; | |
963 | return out; | |
964 | } | |
965 | ||
966 | ||
967 | ///////////////////////////////////////// Point IO | |
968 | Bool_t AliHLTTPCMemHandler::Memory2Binary(UInt_t npoint,AliHLTTPCSpacePointData *data) | |
969 | { | |
970 | //Writing spacepoints stored in data to the outputfile. | |
971 | if(!fOutBinary){ | |
972 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Memory2Binary","File") | |
973 | <<"No Output File"<<ENDLOG; | |
974 | return kFALSE; | |
975 | } | |
976 | if(!data){ | |
977 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Memory2Binary","Memory") | |
978 | <<"Pointer to AliHLTTPCSpacePointData = 0x0 "<<ENDLOG; | |
979 | return kFALSE; | |
980 | } | |
981 | UInt_t size = npoint*sizeof(AliHLTTPCSpacePointData); | |
982 | fwrite(data,size,1,fOutBinary); | |
983 | ||
984 | return kTRUE; | |
985 | } | |
986 | ||
987 | Bool_t AliHLTTPCMemHandler::Transform(UInt_t npoint,AliHLTTPCSpacePointData *data,Int_t slice) | |
988 | { | |
989 | //Transform the space points in data, to global coordinates in slice. | |
990 | if(!data){ | |
991 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Transform","Memory") | |
992 | <<"Pointer to AliHLTTPCSpacePointData = 0x0 "<<ENDLOG; | |
993 | return kFALSE; | |
994 | } | |
995 | ||
996 | for(UInt_t i=0;i<npoint;i++){ | |
997 | Float_t xyz[3]; | |
998 | xyz[0] = data[i].fX; | |
999 | xyz[1] = data[i].fY; | |
1000 | xyz[2] = data[i].fZ; | |
1001 | AliHLTTPCTransform::Local2Global(xyz,slice); | |
1002 | data[i].fX = xyz[0]; | |
1003 | data[i].fY = xyz[1]; | |
1004 | data[i].fZ = xyz[2]; | |
1005 | } | |
1006 | return kTRUE; | |
1007 | } | |
1008 | ||
a38a7850 | 1009 | Bool_t AliHLTTPCMemHandler::Binary2Memory(UInt_t & npoint,AliHLTTPCSpacePointData *data, UInt_t& sz) |
a6c02c85 | 1010 | { |
1011 | //Read the space points in inputfile, and store it in data. | |
1012 | if(!fInBinary){ | |
1013 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Binary2Memory","File") | |
1014 | <<"No Input File"<<ENDLOG; | |
1015 | return kFALSE; | |
1016 | } | |
1017 | if(!data){ | |
1018 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Binary2Memory","Memory") | |
1019 | <<"Pointer to AliHLTTPCSpacePointData = 0x0 "<<ENDLOG; | |
1020 | return kFALSE; | |
1021 | } | |
1022 | ||
1023 | Int_t size = GetFileSize(); | |
a38a7850 | 1024 | sz = size; |
a6c02c85 | 1025 | npoint = size/sizeof(AliHLTTPCSpacePointData); |
1026 | if(size==0) { | |
1027 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Binary2Memory","File") | |
1028 | <<"File Size == 0"<<ENDLOG; | |
1029 | return kFALSE; | |
1030 | } | |
1031 | ||
1032 | if(fread(data,size,1,fInBinary)!=1){ | |
1033 | LOG(AliHLTTPCLog::kFatal,"AliHLTTPCMemHandler::Binary2Memory","File") | |
1034 | <<"File Read Error "<<ENDLOG; | |
1035 | return kFALSE; | |
1036 | } | |
1037 | if(size%sizeof(AliHLTTPCSpacePointData)){ | |
1038 | LOG(AliHLTTPCLog::kFatal,"AliHLTTPCMemHandler::Binary2Memory","File Size") | |
1039 | <<"File Size wrong "<<ENDLOG; | |
1040 | return kFALSE; | |
1041 | } | |
1042 | LOG(AliHLTTPCLog::kDebug,"AliHLTTPCMemHandler::Binary2Memory","File") | |
1043 | <<AliHLTTPCLog::kDec<<"Wrote "<<size<<" Bytes to Memory"<<ENDLOG; | |
1044 | return kTRUE; | |
1045 | } | |
1046 | ||
1047 | ///////////////////////////////////////// Track IO | |
1048 | Bool_t AliHLTTPCMemHandler::Memory2Binary(UInt_t ntrack,AliHLTTPCTrackSegmentData *data) | |
1049 | { | |
1050 | //Write the tracks stored in data, to outputfile. | |
1051 | if(!fOutBinary){ | |
1052 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Memory2Binary","File") | |
1053 | <<"No Output File"<<ENDLOG; | |
1054 | return kFALSE; | |
1055 | } | |
1056 | if(!data){ | |
1057 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Memory2Binary","Memory") | |
1058 | <<"Pointer to AliHLTTPCTrackSegmentData = 0x0 "<<ENDLOG; | |
1059 | return kFALSE; | |
1060 | } | |
1061 | AliHLTTPCTrackSegmentData *trackPt = data; | |
1062 | for(UInt_t i=0;i<ntrack;i++){ | |
1063 | Int_t size=sizeof(AliHLTTPCTrackSegmentData)+trackPt->fNPoints*sizeof(UInt_t); | |
1064 | fwrite(trackPt,size,1,fOutBinary); | |
1065 | Byte_t *bytePt = (Byte_t*) trackPt; | |
1066 | bytePt += size; | |
1067 | trackPt = (AliHLTTPCTrackSegmentData*) bytePt; | |
1068 | } | |
1069 | LOG(AliHLTTPCLog::kDebug,"AliHLTTPCMemHandler::Memory2Binary","File") | |
1070 | <<AliHLTTPCLog::kDec<<"Wrote "<<ntrack<<" Tracks to File"<<ENDLOG; | |
1071 | ||
1072 | return kTRUE; | |
1073 | } | |
1074 | ||
1075 | Bool_t AliHLTTPCMemHandler::Binary2Memory(UInt_t & ntrack,AliHLTTPCTrackSegmentData *data) | |
1076 | { | |
1077 | //Read the tracks in inputfile, and store it in data. | |
1078 | if(!fInBinary){ | |
1079 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Binary2Memory","File") | |
1080 | <<"No Input File"<<ENDLOG; | |
1081 | return kFALSE; | |
1082 | } | |
1083 | if(!data){ | |
1084 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Binary2Memory","Memory") | |
1085 | <<"Pointer to AliHLTTPCTrackSegmentData = 0x0 "<<ENDLOG; | |
1086 | return kFALSE; | |
1087 | } | |
1088 | ||
1089 | ntrack=0; | |
1090 | AliHLTTPCTrackSegmentData *trackPt = data; | |
1091 | rewind(fInBinary); | |
1092 | ||
1093 | while(!feof(fInBinary)){ | |
1094 | if(fread(trackPt,sizeof(AliHLTTPCTrackSegmentData),1,fInBinary)!=1) break; | |
1095 | Int_t size=trackPt->fNPoints*sizeof(UInt_t); | |
1096 | if(fread(trackPt->fPointIDs,size,1,fInBinary)!=1) break; | |
1097 | Byte_t *bytePt = (Byte_t*) trackPt; | |
1098 | bytePt += sizeof(AliHLTTPCTrackSegmentData)+size; | |
1099 | trackPt = (AliHLTTPCTrackSegmentData*) bytePt; | |
1100 | ntrack++; | |
1101 | } | |
1102 | LOG(AliHLTTPCLog::kDebug,"AliHLTTPCMemHandler::Binary2Memory","File") | |
1103 | <<AliHLTTPCLog::kDec<<"Wrote "<<ntrack<<" Tracks to Memory"<<ENDLOG; | |
1104 | return kTRUE; | |
1105 | } | |
1106 | ||
1107 | Bool_t AliHLTTPCMemHandler::TrackArray2Binary(AliHLTTPCTrackArray *array) | |
1108 | { | |
1109 | //Write the trackarray to the outputfile. | |
1110 | if(!fOutBinary){ | |
1111 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::TrackArray2Binary","File") | |
1112 | <<"No Output File"<<ENDLOG; | |
1113 | return kFALSE; | |
1114 | } | |
1115 | if(!array){ | |
1116 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::TrackArray2Binary","Memory") | |
1117 | <<"Pointer to AliHLTTPCTrackArray = 0x0 "<<ENDLOG; | |
1118 | return kFALSE; | |
1119 | } | |
1120 | AliHLTTPCTrackSegmentData *data = (AliHLTTPCTrackSegmentData *)Allocate(array); | |
1121 | ||
1122 | UInt_t ntrack; | |
1123 | TrackArray2Memory(ntrack,data,array); | |
1124 | Memory2Binary(ntrack,data); | |
1125 | Free(); | |
1126 | return kTRUE; | |
1127 | } | |
1128 | ||
1129 | Bool_t AliHLTTPCMemHandler::Binary2TrackArray(AliHLTTPCTrackArray *array) | |
1130 | { | |
1131 | //Read the tracks in inputfile, and fill it in trackarray. | |
1132 | //array should already be constructed. | |
1133 | if(!fInBinary){ | |
1134 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Binary2TrackArray","File") | |
1135 | <<"No Input File"<<ENDLOG; | |
1136 | return kFALSE; | |
1137 | } | |
1138 | if(!array){ | |
1139 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Binary2TrackArray","Memory") | |
1140 | <<"Pointer to AliHLTTPCTrackArray = 0x0 "<<ENDLOG; | |
1141 | return kFALSE; | |
1142 | } | |
1143 | AliHLTTPCTrackSegmentData *data = (AliHLTTPCTrackSegmentData *)Allocate(); | |
1144 | UInt_t ntrack; | |
1145 | Binary2Memory(ntrack,data); | |
1146 | Memory2TrackArray(ntrack,data,array); | |
1147 | Free(); | |
1148 | return kTRUE; | |
1149 | } | |
1150 | ||
1151 | Bool_t AliHLTTPCMemHandler::TrackArray2Memory(UInt_t & ntrack,AliHLTTPCTrackSegmentData *data,AliHLTTPCTrackArray *array) const | |
1152 | { | |
1153 | //Fill the trackarray into the AliTrackSegmentData structures before writing to outputfile. | |
1154 | if(!data){ | |
1155 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::TrackArray2Memory","Memory") | |
1156 | <<"Pointer to AliHLTTPCTrackSegmentData = 0x0 "<<ENDLOG; | |
1157 | return kFALSE; | |
1158 | } | |
1159 | if(!array){ | |
1160 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::TrackArray2Memory","Memory") | |
1161 | <<"Pointer to AliHLTTPCTrackArray = 0x0 "<<ENDLOG; | |
1162 | return kFALSE; | |
1163 | } | |
1164 | ||
1165 | array->WriteTracks(ntrack,data); | |
1166 | return kTRUE; | |
1167 | } | |
1168 | ||
1169 | Bool_t AliHLTTPCMemHandler::Memory2TrackArray(UInt_t ntrack,AliHLTTPCTrackSegmentData *data,AliHLTTPCTrackArray *array) const | |
1170 | { | |
1171 | //Fill the tracks in data into trackarray. | |
1172 | ||
1173 | if(!data){ | |
1174 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Memory2TrackArray","Memory") | |
1175 | <<"Pointer to AliHLTTPCTrackSegmentData = 0x0 "<<ENDLOG; | |
1176 | return kFALSE; | |
1177 | } | |
1178 | if(!array){ | |
1179 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Memory2TrackArray","Memory") | |
1180 | <<"Pointer to AliHLTTPCTrackArray = 0x0 "<<ENDLOG; | |
1181 | return kFALSE; | |
1182 | } | |
1183 | array->FillTracks(ntrack,data); | |
1184 | return kTRUE; | |
1185 | } | |
1186 | ||
1187 | Bool_t AliHLTTPCMemHandler::Memory2TrackArray(UInt_t ntrack,AliHLTTPCTrackSegmentData *data,AliHLTTPCTrackArray *array,Int_t slice) const | |
1188 | { | |
1189 | //Fill the tracks in data into trackarray, and rotate the tracks to global coordinates. | |
1190 | ||
1191 | if(!data){ | |
1192 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Memory2TrackArray","Memory") | |
1193 | <<"Pointer to AliHLTTPCTrackSegmentData = 0x0 "<<ENDLOG; | |
1194 | return kFALSE; | |
1195 | } | |
1196 | if(!array){ | |
1197 | LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Memory2TrackArray","Memory") | |
1198 | <<"Pointer to AliHLTTPCTrackArray = 0x0 "<<ENDLOG; | |
1199 | return kFALSE; | |
1200 | } | |
1201 | array->FillTracks(ntrack,data,slice); | |
1202 | return kTRUE; | |
1203 | } | |
1204 | ||
1205 | void AliHLTTPCMemHandler::UpdateRowPointer(AliHLTTPCDigitRowData *&tempPt) | |
1206 | { | |
1207 | //Update the data pointer to the next padrow in memory. | |
1208 | ||
1209 | Byte_t *tmp = (Byte_t*)tempPt; | |
1210 | Int_t size = sizeof(AliHLTTPCDigitRowData) + tempPt->fNDigit*sizeof(AliHLTTPCDigitData); | |
1211 | tmp += size; | |
1212 | tempPt = (AliHLTTPCDigitRowData*)tmp; | |
1213 | } | |
1214 | ||
1215 | Int_t AliHLTTPCMemHandler::ComparePoints(UInt_t /*row*/,UShort_t pad,UShort_t time) const | |
1216 | { | |
1217 | //compare two points | |
1218 | if(fNUsed>=fNDigits) return -2; | |
1219 | ||
1220 | if(pad==fDPt[fNUsed]->fPad&&time==fDPt[fNUsed]->fTime) return 0; | |
1221 | ||
1222 | if(pad<fDPt[fNUsed]->fPad) return -1; | |
1223 | if(pad==fDPt[fNUsed]->fPad&&time<fDPt[fNUsed]->fTime) return -1; | |
1224 | ||
1225 | return 1; | |
1226 | } | |
1227 | ||
ad7e2f5e | 1228 | Int_t AliHLTTPCMemHandler::CompareDigits(const AliHLTTPCRandomDigitData *a,const AliHLTTPCRandomDigitData *b) const |
a6c02c85 | 1229 | { |
1230 | //compare two digits | |
1231 | if(a->fPad==b->fPad && a->fTime == b->fTime) return 0; | |
1232 | ||
1233 | if(a->fPad<b->fPad) return -1; | |
1234 | if(a->fPad==b->fPad && a->fTime<b->fTime) return -1; | |
1235 | ||
1236 | return 1; | |
1237 | } |