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