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