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