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