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