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