]>
Commit | Line | Data |
---|---|---|
3e87ef69 | 1 | // @(#) $Id$ |
5bf93292 | 2 | |
3 | // Author: Anders Vestbo <mailto:vestbo$fi.uib.no> | |
3e87ef69 | 4 | //*-- Copyright © ALICE HLT Group |
5bf93292 | 5 | |
4994a25d | 6 | #include "AliL3StandardIncludes.h" |
5bf93292 | 7 | |
3e87ef69 | 8 | #include "bitio.h" |
9 | #include "AliL3RootTypes.h" | |
10 | #include "AliL3Models.h" | |
11 | #include "AliL3DigitData.h" | |
4994a25d | 12 | #include "AliL3Logging.h" |
5bf93292 | 13 | #include "AliL3TrackArray.h" |
14 | #include "AliL3ModelTrack.h" | |
029912b7 | 15 | #include "AliL3Transform.h" |
16 | #include "AliL3MemHandler.h" | |
1f1942b8 | 17 | #include "AliL3DataCompressorHelper.h" |
3e87ef69 | 18 | #include "AliL3DataCompressor.h" |
6f388e0d | 19 | #include "AliL3SpacePointData.h" |
3e87ef69 | 20 | |
21 | #if 0 | |
22 | #ifdef use_root | |
23 | #include <TH1.h> | |
24 | #include <TH2.h> | |
25 | #include <TRandom.h> | |
26 | #endif | |
92a876e2 | 27 | #ifdef use_aliroot |
be6ddb10 | 28 | #include "AliL3FileHandler.h" |
92a876e2 | 29 | #endif |
3e87ef69 | 30 | #endif |
31 | ||
32 | #include "AliL3Compress.h" | |
33 | ||
0bd0c1ef | 34 | #if __GNUC__ == 3 |
3e87ef69 | 35 | using namespace std; |
36 | #endif | |
5bf93292 | 37 | |
029912b7 | 38 | //_____________________________________________________________ |
39 | // | |
40 | // AliL3Compress | |
41 | // | |
42 | // Class for compressing and uncompressing data. | |
43 | ||
5bf93292 | 44 | ClassImp(AliL3Compress) |
45 | ||
46 | AliL3Compress::AliL3Compress() | |
47 | { | |
95a00d93 | 48 | fTracks=0; |
029912b7 | 49 | fSlice =0; |
50 | fPatch=0; | |
2357bb38 | 51 | fWriteShape=kFALSE; |
3e87ef69 | 52 | fEvent=-1; |
029912b7 | 53 | } |
54 | ||
3e87ef69 | 55 | AliL3Compress::AliL3Compress(Int_t slice,Int_t patch,Char_t *path,Bool_t writeshape,Int_t event) |
029912b7 | 56 | { |
3e87ef69 | 57 | fEvent=event; |
029912b7 | 58 | fSlice=slice; |
59 | fPatch=patch; | |
029912b7 | 60 | fTracks=0; |
be6ddb10 | 61 | sprintf(fPath,"%s",path); |
2357bb38 | 62 | fWriteShape=writeshape; |
5bf93292 | 63 | } |
64 | ||
65 | AliL3Compress::~AliL3Compress() | |
66 | { | |
95a00d93 | 67 | if(fTracks) |
68 | delete fTracks; | |
029912b7 | 69 | } |
70 | ||
3e87ef69 | 71 | Bool_t AliL3Compress::WriteFile(AliL3TrackArray *tracks,Char_t *filename) |
029912b7 | 72 | { |
3e87ef69 | 73 | Char_t fname[1024]; |
74 | if(filename) | |
75 | sprintf(fname,"%s/comp/%s",fPath,filename); | |
76 | else if(fEvent<0) | |
77 | sprintf(fname,"%s/comp/tracks_m_%d_%d.raw",fPath,fSlice,fPatch); | |
78 | else | |
79 | sprintf(fname,"%s/comp/tracks_m_%d_%d_%d.raw",fPath,fEvent,fSlice,fPatch); | |
5bf93292 | 80 | |
be6ddb10 | 81 | FILE *file = fopen(fname,"w"); |
2357bb38 | 82 | if(!file) |
83 | { | |
84 | cerr<<"AliL3Compress::WriteFile : Error opening file "<<fname<<endl; | |
3e87ef69 | 85 | return kFALSE; |
2357bb38 | 86 | } |
5bf93292 | 87 | Short_t ntracks = tracks->GetNTracks(); |
95a00d93 | 88 | |
89 | Int_t count=0; | |
90 | AliL3ClusterModel *clusters=0; | |
91 | AliL3TrackModel *model=0; | |
5bf93292 | 92 | for(Int_t i=0; i<ntracks; i++) |
93 | { | |
94 | AliL3ModelTrack *track = (AliL3ModelTrack*)tracks->GetCheckedTrack(i); | |
95 | if(!track) continue; | |
3e87ef69 | 96 | |
4a838220 | 97 | //Do not save useless tracks or clusters: |
3e87ef69 | 98 | //if(track->GetNPresentClusters() == 0) |
99 | //continue; | |
4a838220 | 100 | |
029912b7 | 101 | track->FillModel(); |
95a00d93 | 102 | model = track->GetModel(); |
0a86fbb7 | 103 | //if(model->fNClusters==0) continue; |
95a00d93 | 104 | clusters = track->GetClusters(); |
5bf93292 | 105 | if(fwrite(model,sizeof(AliL3TrackModel),1,file)!=1) break; |
0a86fbb7 | 106 | //if(fwrite(clusters,model->fNClusters*sizeof(AliL3ClusterModel),1,file)!=1) break; |
107 | if(fwrite(clusters,AliL3Transform::GetNRows(fPatch)*sizeof(AliL3ClusterModel),1,file)!=1) break; | |
95a00d93 | 108 | count++; |
029912b7 | 109 | |
5bf93292 | 110 | } |
111 | fclose(file); | |
3e87ef69 | 112 | return kTRUE; |
5bf93292 | 113 | } |
114 | ||
3e87ef69 | 115 | Bool_t AliL3Compress::ReadFile(Char_t which,Char_t *filename) |
5bf93292 | 116 | { |
be6ddb10 | 117 | //Read the trackfile. |
118 | ||
3e87ef69 | 119 | Char_t fname[1024]; |
120 | if(filename) | |
121 | sprintf(fname,"%s/comp/%s",fPath,filename); | |
be6ddb10 | 122 | else |
123 | { | |
3e87ef69 | 124 | if(which == 'm') |
125 | { | |
126 | if(fEvent<0) | |
127 | sprintf(fname,"%s/comp/tracks_m_%d_%d.raw",fPath,fSlice,fPatch); | |
128 | else | |
129 | sprintf(fname,"%s/comp/tracks_m_%d_%d_%d.raw",fPath,fEvent,fSlice,fPatch); | |
130 | } | |
131 | else if(which == 'u') | |
132 | { | |
133 | if(fEvent<0) | |
134 | sprintf(fname,"%s/comp/tracks_u_%d_%d.raw",fPath,fSlice,fPatch); | |
135 | else | |
136 | sprintf(fname,"%s/comp/tracks_u_%d_%d_%d.raw",fPath,fEvent,fSlice,fPatch); | |
137 | } | |
138 | else | |
139 | { | |
140 | cerr<<"AliL3Compress::ReadFile() : Wrong option"<<endl; | |
141 | return kFALSE; | |
142 | } | |
be6ddb10 | 143 | } |
144 | ||
145 | FILE *file = fopen(fname,"r"); | |
029912b7 | 146 | if(!file) |
147 | { | |
2357bb38 | 148 | cerr<<"AliL3Compress::ReadFile : Cannot open file "<<fname<<endl; |
3e87ef69 | 149 | return kFALSE; |
029912b7 | 150 | } |
151 | ||
95a00d93 | 152 | if(fTracks) |
153 | delete fTracks; | |
154 | fTracks = new AliL3TrackArray("AliL3ModelTrack"); | |
5bf93292 | 155 | |
156 | while(!feof(file)) | |
157 | { | |
95a00d93 | 158 | AliL3ModelTrack *track = (AliL3ModelTrack*)fTracks->NextTrack(); |
029912b7 | 159 | track->Init(fSlice,fPatch); |
5bf93292 | 160 | AliL3TrackModel *model = track->GetModel(); |
161 | AliL3ClusterModel *clusters = track->GetClusters(); | |
162 | if(fread(model,sizeof(AliL3TrackModel),1,file)!=1) break; | |
0a86fbb7 | 163 | //if(fread(clusters,model->fNClusters*sizeof(AliL3ClusterModel),1,file)!=1) break; |
164 | if(fread(clusters,AliL3Transform::GetNRows(fPatch)*sizeof(AliL3ClusterModel),1,file)!=1) break; | |
029912b7 | 165 | track->FillTrack(); |
5bf93292 | 166 | } |
029912b7 | 167 | |
168 | fTracks->RemoveLast(); | |
5bf93292 | 169 | fclose(file); |
3e87ef69 | 170 | return kTRUE; |
5bf93292 | 171 | } |
172 | ||
3e87ef69 | 173 | Bool_t AliL3Compress::CompressFile() |
5bf93292 | 174 | { |
be6ddb10 | 175 | Char_t fname[100]; |
3e87ef69 | 176 | if(fEvent<0) |
177 | sprintf(fname,"%s/comp/tracks_c_%d_%d.raw",fPath,fSlice,fPatch); | |
178 | else | |
179 | sprintf(fname,"%s/comp/tracks_c_%d_%d_%d.raw",fPath,fEvent,fSlice,fPatch); | |
be6ddb10 | 180 | BIT_FILE *output = OpenOutputBitFile(fname); |
181 | ||
3e87ef69 | 182 | if(fEvent<0) |
183 | sprintf(fname,"%s/comp/tracks_m_%d_%d.raw",fPath,fSlice,fPatch); | |
184 | else | |
185 | sprintf(fname,"%s/comp/tracks_m_%d_%d_%d.raw",fPath,fEvent,fSlice,fPatch); | |
186 | ||
be6ddb10 | 187 | FILE *input = fopen(fname,"r"); |
188 | if(!input) | |
189 | { | |
190 | cerr<<"AliL3Compress::CompressFile() : Error opening file: "<<fname<<endl; | |
3e87ef69 | 191 | return kFALSE; |
be6ddb10 | 192 | } |
5bf93292 | 193 | |
194 | AliL3TrackModel track; | |
195 | AliL3ClusterModel cluster; | |
196 | Int_t temp; | |
2357bb38 | 197 | Int_t power; |
029912b7 | 198 | |
6f388e0d | 199 | Int_t timeo,pado,chargeo,padshapeo,timeshapeo; |
200 | timeo=pado=chargeo=padshapeo=timeshapeo=0; | |
5bf93292 | 201 | while(!feof(input)) |
202 | { | |
203 | if(fread(&track,sizeof(AliL3TrackModel),1,input)!=1) break; | |
95a00d93 | 204 | |
205 | if(output->mask != 0x80) //Write the current byte to file. | |
206 | { | |
92a876e2 | 207 | //cerr<<"\nAliL3Compress::CompressFile() : Writing overhead bits!!!"<<endl; |
95a00d93 | 208 | if(putc(output->rack,output->file )!=output->rack) |
209 | cerr<<"AliL3Compress::ComressFile : Error writing to bitfile"<<endl; | |
210 | output->mask=0x80; | |
029912b7 | 211 | output->rack=0; |
95a00d93 | 212 | } |
029912b7 | 213 | |
214 | //Write track parameters: | |
5bf93292 | 215 | fwrite(&track,sizeof(AliL3TrackModel),1,output->file); |
3e87ef69 | 216 | |
217 | Int_t origslice=-1,slice,clustercount=0; | |
0a86fbb7 | 218 | for(Int_t i=0; i<AliL3Transform::GetNRows(fPatch); i++) |
5bf93292 | 219 | { |
220 | if(fread(&cluster,sizeof(AliL3ClusterModel),1,input)!=1) break; | |
029912b7 | 221 | |
222 | //Write empty flag: | |
223 | temp = (Int_t)cluster.fPresent; | |
224 | OutputBit(output,temp); | |
225 | if(!temp) continue; | |
226 | ||
3e87ef69 | 227 | if(cluster.fSlice<0 || cluster.fSlice>35) |
228 | { | |
229 | cerr<<"AliL3DataCompress::CompressFile : Fucked up slice number :"<<cluster.fSlice<<endl; | |
230 | exit(5); | |
231 | } | |
232 | ||
233 | //Write slice number of first point | |
234 | if(clustercount==0) | |
235 | { | |
236 | origslice = cluster.fSlice; | |
237 | OutputBits(output,origslice,6); //Need 6 bits to encode slice number | |
238 | } | |
239 | else | |
240 | { | |
241 | slice = cluster.fSlice; | |
242 | if(slice == origslice) | |
6f388e0d | 243 | OutputBit(output,0); //No change of slice |
3e87ef69 | 244 | else |
245 | { | |
246 | OutputBit(output,1); | |
247 | OutputBits(output,slice,6); | |
248 | origslice=slice; | |
249 | } | |
250 | } | |
251 | ||
029912b7 | 252 | //Write time information: |
3e87ef69 | 253 | temp = (Int_t)rint(cluster.fDTime); |
5bf93292 | 254 | if(temp<0) |
255 | OutputBit(output,0); | |
256 | else | |
257 | OutputBit(output,1); | |
1f1942b8 | 258 | power = 1<<(AliL3DataCompressorHelper::GetNTimeBits()-1); |
029912b7 | 259 | if(abs(temp)>=power) |
260 | { | |
1f1942b8 | 261 | //cout<<abs(temp)<<" "<<power<<endl; |
029912b7 | 262 | timeo++; |
263 | temp=power - 1; | |
264 | } | |
1f1942b8 | 265 | OutputBits(output,abs(temp),(AliL3DataCompressorHelper::GetNTimeBits()-1)); |
029912b7 | 266 | |
267 | //Write pad information: | |
3e87ef69 | 268 | temp = (Int_t)rint(cluster.fDPad); |
5bf93292 | 269 | if(temp<0) |
270 | OutputBit(output,0); | |
271 | else | |
272 | OutputBit(output,1); | |
1f1942b8 | 273 | power = 1<<(AliL3DataCompressorHelper::GetNPadBits()-1); |
029912b7 | 274 | if(abs(temp)>=power) |
275 | { | |
276 | pado++; | |
277 | temp=power - 1; | |
278 | } | |
1f1942b8 | 279 | OutputBits(output,abs(temp),(AliL3DataCompressorHelper::GetNPadBits()-1)); |
029912b7 | 280 | |
281 | //Write charge information: | |
5bf93292 | 282 | temp = (Int_t)cluster.fDCharge; |
1f1942b8 | 283 | power = 1<<(AliL3DataCompressorHelper::GetNChargeBits()); |
029912b7 | 284 | if(abs(temp)>=power) |
285 | { | |
286 | chargeo++; | |
287 | temp=power - 1; | |
288 | } | |
1f1942b8 | 289 | OutputBits(output,abs(temp),(AliL3DataCompressorHelper::GetNChargeBits())); |
029912b7 | 290 | |
2357bb38 | 291 | if(fWriteShape) |
029912b7 | 292 | { |
2357bb38 | 293 | //Write shape information: |
5a31e9df | 294 | temp = (Int_t)rint(cluster.fDSigmaY); |
2357bb38 | 295 | if(temp<0) |
296 | OutputBit(output,0); | |
297 | else | |
298 | OutputBit(output,1); | |
1f1942b8 | 299 | power = 1<<(AliL3DataCompressorHelper::GetNShapeBits()-1); |
2357bb38 | 300 | if(abs(temp) >= power) |
301 | { | |
6f388e0d | 302 | padshapeo++; |
2357bb38 | 303 | temp = power - 1; |
304 | } | |
1f1942b8 | 305 | OutputBits(output,abs(temp),(AliL3DataCompressorHelper::GetNShapeBits()-1)); |
2357bb38 | 306 | |
5a31e9df | 307 | temp = (Int_t)rint(cluster.fDSigmaZ); |
2357bb38 | 308 | if(temp<0) |
309 | OutputBit(output,0); | |
310 | else | |
311 | OutputBit(output,1); | |
1f1942b8 | 312 | power = 1<<(AliL3DataCompressorHelper::GetNShapeBits()-1); |
2357bb38 | 313 | if(abs(temp) >= power) |
314 | { | |
6f388e0d | 315 | timeshapeo++; |
2357bb38 | 316 | temp=power - 1; |
317 | } | |
1f1942b8 | 318 | OutputBits(output,abs(temp),(AliL3DataCompressorHelper::GetNShapeBits()-1)); |
029912b7 | 319 | } |
3e87ef69 | 320 | |
321 | clustercount++; | |
5bf93292 | 322 | } |
5bf93292 | 323 | } |
95a00d93 | 324 | |
5bf93292 | 325 | fclose(input); |
326 | CloseOutputBitFile(output); | |
6f388e0d | 327 | if(pado || timeo || chargeo || padshapeo || timeshapeo) |
f64c4364 | 328 | { |
329 | cout<<endl<<"Saturations: "<<endl | |
330 | <<"Pad "<<pado<<endl | |
331 | <<"Time "<<timeo<<endl | |
332 | <<"Charge "<<chargeo<<endl | |
6f388e0d | 333 | <<"Padshape "<<padshapeo<<endl |
334 | <<"Timeshape "<<timeshapeo<<endl<<endl; | |
f64c4364 | 335 | } |
3e87ef69 | 336 | return kTRUE; |
5bf93292 | 337 | } |
338 | ||
3e87ef69 | 339 | Bool_t AliL3Compress::ExpandFile() |
5bf93292 | 340 | { |
be6ddb10 | 341 | Char_t fname[100]; |
3e87ef69 | 342 | if(fEvent<0) |
343 | sprintf(fname,"%s/comp/tracks_c_%d_%d.raw",fPath,fSlice,fPatch); | |
344 | else | |
345 | sprintf(fname,"%s/comp/tracks_c_%d_%d_%d.raw",fPath,fEvent,fSlice,fPatch); | |
be6ddb10 | 346 | BIT_FILE *input = OpenInputBitFile(fname); |
347 | ||
3e87ef69 | 348 | if(fEvent<0) |
349 | sprintf(fname,"%s/comp/tracks_u_%d_%d.raw",fPath,fSlice,fPatch); | |
350 | else | |
351 | sprintf(fname,"%s/comp/tracks_u_%d_%d_%d.raw",fPath,fEvent,fSlice,fPatch); | |
be6ddb10 | 352 | FILE *output = fopen(fname,"w"); |
353 | if(!output) | |
354 | { | |
355 | cerr<<"AliL3Compress::ExpandFile() : Error opening file: "<<fname<<endl; | |
3e87ef69 | 356 | return kFALSE; |
be6ddb10 | 357 | } |
95a00d93 | 358 | |
359 | AliL3TrackModel trackmodel; | |
360 | AliL3ClusterModel *clusters=0; | |
029912b7 | 361 | Int_t count=0; |
5bf93292 | 362 | |
4a838220 | 363 | clusters = new AliL3ClusterModel[(AliL3Transform::GetNRows(fPatch))]; |
95a00d93 | 364 | while(!feof(input->file)) |
5bf93292 | 365 | { |
029912b7 | 366 | input->mask=0x80;//make sure we read a new byte from file. |
95a00d93 | 367 | |
029912b7 | 368 | //Read and write track: |
95a00d93 | 369 | if(fread(&trackmodel,sizeof(AliL3TrackModel),1,input->file)!=1) break; |
370 | fwrite(&trackmodel,sizeof(AliL3TrackModel),1,output); | |
2357bb38 | 371 | |
372 | memset(clusters,0,AliL3Transform::GetNRows(fPatch)*sizeof(AliL3ClusterModel)); | |
3e87ef69 | 373 | Int_t origslice=-1,clustercount=0; |
0a86fbb7 | 374 | for(Int_t i=0; i<AliL3Transform::GetNRows(fPatch); i++) |
95a00d93 | 375 | { |
376 | Int_t temp,sign; | |
029912b7 | 377 | |
378 | //Read empty flag: | |
95a00d93 | 379 | temp = InputBit(input); |
380 | if(!temp) | |
381 | { | |
382 | clusters[i].fPresent=kFALSE; | |
383 | continue; | |
384 | } | |
385 | clusters[i].fPresent=kTRUE; | |
029912b7 | 386 | |
3e87ef69 | 387 | //Read slice information |
388 | if(clustercount==0) | |
389 | { | |
390 | temp = InputBits(input,6); | |
391 | clusters[i].fSlice = temp; | |
392 | origslice = temp; | |
393 | } | |
394 | else | |
395 | { | |
396 | temp = InputBit(input); | |
397 | if(!temp)//no change | |
398 | clusters[i].fSlice = origslice; | |
399 | else | |
400 | { | |
401 | temp = InputBits(input,6);//read new slice | |
402 | clusters[i].fSlice = temp; | |
403 | origslice = temp;//store new slice | |
404 | } | |
405 | } | |
406 | ||
029912b7 | 407 | //Read time information: |
95a00d93 | 408 | sign=InputBit(input); |
1f1942b8 | 409 | temp = InputBits(input,(AliL3DataCompressorHelper::GetNTimeBits()-1)); |
95a00d93 | 410 | if(!sign) |
411 | temp*=-1; | |
412 | clusters[i].fDTime = temp; | |
029912b7 | 413 | |
414 | //Read pad information: | |
95a00d93 | 415 | sign=InputBit(input); |
1f1942b8 | 416 | temp = InputBits(input,(AliL3DataCompressorHelper::GetNPadBits()-1)); |
95a00d93 | 417 | if(!sign) |
418 | temp*=-1; | |
419 | clusters[i].fDPad = temp; | |
029912b7 | 420 | |
421 | //Read charge information: | |
1f1942b8 | 422 | temp=InputBits(input,(AliL3DataCompressorHelper::GetNChargeBits())); |
95a00d93 | 423 | clusters[i].fDCharge = temp; |
029912b7 | 424 | |
2357bb38 | 425 | if(fWriteShape) |
426 | { | |
427 | //Read shape information: | |
428 | sign = InputBit(input); | |
1f1942b8 | 429 | temp = InputBits(input,(AliL3DataCompressorHelper::GetNShapeBits()-1)); |
2357bb38 | 430 | if(!sign) |
431 | temp*=-1; | |
1f1942b8 | 432 | clusters[i].fDSigmaY = temp; |
2357bb38 | 433 | |
434 | sign = InputBit(input); | |
1f1942b8 | 435 | temp = InputBits(input,(AliL3DataCompressorHelper::GetNShapeBits()-1)); |
2357bb38 | 436 | if(!sign) |
437 | temp*=-1; | |
1f1942b8 | 438 | clusters[i].fDSigmaZ = temp; |
2357bb38 | 439 | } |
3e87ef69 | 440 | clustercount++; |
95a00d93 | 441 | } |
029912b7 | 442 | count++; |
0a86fbb7 | 443 | //fwrite(clusters,(trackmodel.fNClusters)*sizeof(AliL3ClusterModel),1,output); |
444 | fwrite(clusters,AliL3Transform::GetNRows(fPatch)*sizeof(AliL3ClusterModel),1,output); | |
5bf93292 | 445 | } |
029912b7 | 446 | |
447 | delete [] clusters; | |
95a00d93 | 448 | fclose(output); |
5bf93292 | 449 | CloseInputBitFile(input); |
3e87ef69 | 450 | return kTRUE; |
5bf93292 | 451 | } |
029912b7 | 452 | |
6f388e0d | 453 | void AliL3Compress::CompressRemaining(AliL3SpacePointData *clusters[36][6],UInt_t nclusters[36][6]) |
454 | { | |
455 | //Write the remaining clusters in a compressed format. | |
456 | ||
457 | Char_t filename[1024]; | |
458 | Int_t nrows = AliL3Transform::GetNRows(); | |
459 | Int_t *npoints = new Int_t[nrows]; | |
460 | for(Int_t slice=0; slice<=35; slice++) | |
461 | { | |
462 | for(Int_t patch=0; patch < 1; patch++) | |
463 | { | |
464 | sprintf(filename,"%s/comp/remains_%d_%d_%d.raw",fPath,fEvent,slice,-1); | |
465 | BIT_FILE *output = OpenOutputBitFile(filename); | |
466 | if(!output) | |
467 | { | |
468 | cerr<<"AliL3Compress::CompressRemaining : Cannot open file "<<filename<<endl; | |
469 | exit(5); | |
470 | } | |
471 | AliL3SpacePointData *cl = clusters[slice][patch]; | |
472 | memset(npoints,0,nrows*sizeof(Int_t)); | |
473 | ||
474 | UInt_t i; | |
475 | for(i=0; i<nclusters[slice][patch]; i++) | |
476 | { | |
477 | if(cl[i].fCharge == 0) continue; //has been used | |
478 | npoints[cl[i].fPadRow]++; | |
479 | } | |
480 | Int_t rowspresent=0; | |
481 | for(Int_t j=0; j<nrows; j++) | |
482 | { | |
483 | if(!npoints[j]) continue; | |
484 | rowspresent++; | |
485 | } | |
486 | ||
487 | //Write number of padrows with clusters | |
488 | OutputBits(output,rowspresent,8); | |
489 | ||
490 | Int_t last_padrow=-1; | |
491 | for(i=0; i<nclusters[slice][patch]; i++) | |
492 | { | |
493 | if(cl[i].fCharge == 0) continue; //has been used | |
494 | Int_t padrow = cl[i].fPadRow; | |
495 | if(padrow != last_padrow) | |
496 | { | |
497 | OutputBits(output,padrow,8);//Write padrow # | |
498 | if(npoints[padrow] >= 1<<10) | |
499 | { | |
500 | cerr<<"AliL3Compress::CompressRemaining : Too many remaining clusters "<<npoints[padrow]<<endl; | |
501 | exit(5); | |
502 | } | |
503 | OutputBits(output,npoints[padrow],10);//Write number of clusters on this padrow | |
504 | last_padrow = padrow; | |
505 | } | |
506 | ||
507 | Float_t xyz[3] = {cl[i].fX,cl[i].fY,cl[i].fZ}; | |
508 | Int_t sector,row,buff; | |
509 | AliL3Transform::Slice2Sector(slice,padrow,sector,row); | |
510 | AliL3Transform::Global2Raw(xyz,sector,row); | |
511 | ||
1f1942b8 | 512 | Float_t padw = sqrt(cl[i].fSigmaY2) / AliL3Transform::GetPadPitchWidth(AliL3Transform::GetPatch(padrow)); |
513 | Float_t timew = sqrt(cl[i].fSigmaZ2) / AliL3Transform::GetZWidth(); | |
6f388e0d | 514 | |
5a31e9df | 515 | //Check for saturation in the widths. |
516 | //Basically only store a certain number of decimals here, and cut the widths which is higher: | |
517 | if(padw >= (1<<AliL3DataCompressorHelper::GetNShapeBitsRemaining()) / AliL3DataCompressorHelper::GetPadPrecisionFactor()) | |
518 | padw = (1<<AliL3DataCompressorHelper::GetNShapeBitsRemaining()) / AliL3DataCompressorHelper::GetPadPrecisionFactor() - 1/AliL3DataCompressorHelper::GetPadPrecisionFactor(); | |
519 | if(timew >= (1<<AliL3DataCompressorHelper::GetNShapeBitsRemaining()) / AliL3DataCompressorHelper::GetTimePrecisionFactor()) | |
520 | timew = (1<<AliL3DataCompressorHelper::GetNShapeBitsRemaining()) / AliL3DataCompressorHelper::GetTimePrecisionFactor() - 1/AliL3DataCompressorHelper::GetTimePrecisionFactor();; | |
521 | ||
6f388e0d | 522 | //Write pad |
5a31e9df | 523 | buff = (Int_t)rint(xyz[1]*AliL3DataCompressorHelper::GetPadPrecisionFactor()); |
6f388e0d | 524 | if(buff<0) |
525 | { | |
526 | cerr<<"AliL3Compress:CompressRemaining : Wrong pad value "<<buff<<endl; | |
527 | exit(5); | |
528 | } | |
5a31e9df | 529 | OutputBits(output,buff,AliL3DataCompressorHelper::GetNPadBitsRemaining()); |
530 | ||
6f388e0d | 531 | //Write time |
5a31e9df | 532 | buff = (Int_t)rint(xyz[2]*AliL3DataCompressorHelper::GetTimePrecisionFactor()); |
6f388e0d | 533 | if(buff<0) |
534 | { | |
535 | cerr<<"AliL3Compress:CompressRemaining : Wrong time value "<<buff<<endl; | |
536 | exit(5); | |
537 | } | |
5a31e9df | 538 | OutputBits(output,buff,AliL3DataCompressorHelper::GetNTimeBitsRemaining()); |
539 | ||
6f388e0d | 540 | //Write widths |
5a31e9df | 541 | buff = (Int_t)rint(padw*AliL3DataCompressorHelper::GetPadPrecisionFactor()); |
542 | OutputBits(output,buff,AliL3DataCompressorHelper::GetNShapeBitsRemaining()); | |
543 | buff = (Int_t)rint(timew*AliL3DataCompressorHelper::GetTimePrecisionFactor()); | |
544 | OutputBits(output,buff,AliL3DataCompressorHelper::GetNShapeBitsRemaining()); | |
6f388e0d | 545 | |
546 | //Write charge | |
547 | buff = cl[i].fCharge; | |
5a31e9df | 548 | if(buff >= 1<<(AliL3DataCompressorHelper::GetNChargeBits())) |
549 | buff = (1<<(AliL3DataCompressorHelper::GetNChargeBits()))-1; | |
550 | OutputBits(output,buff,AliL3DataCompressorHelper::GetNChargeBits()); | |
6f388e0d | 551 | } |
552 | ||
553 | CloseOutputBitFile(output); | |
554 | } | |
555 | ||
556 | } | |
557 | delete [] npoints; | |
558 | } | |
559 | ||
560 | void AliL3Compress::ExpandRemaining(TempCluster **clusters,Int_t *ncl,const Int_t maxpoints) | |
561 | { | |
562 | //Expand the remaining clusters stored using function CompressRemaining | |
563 | ||
564 | Char_t filename[1024]; | |
565 | Int_t buff; | |
566 | for(Int_t slice=0; slice<=35; slice++) | |
567 | { | |
568 | for(Int_t p=0; p<1; p++) | |
569 | { | |
570 | sprintf(filename,"%s/comp/remains_%d_%d_%d.raw",fPath,fEvent,slice,-1); | |
571 | BIT_FILE *input = OpenInputBitFile(filename); | |
572 | ||
573 | //Read number of padrows | |
574 | buff = InputBits(input,8); | |
575 | Int_t nrows = buff; | |
576 | ||
577 | for(Int_t i=0; i<nrows; i++) | |
578 | { | |
579 | //Read padrow | |
580 | buff = InputBits(input,8); | |
581 | Int_t padrow = buff; | |
582 | ||
583 | //Read nclusters; | |
584 | buff = InputBits(input,10); | |
585 | Int_t npoints = buff; | |
586 | ||
587 | for(Int_t i=0; i<npoints; i++) | |
588 | { | |
589 | clusters[slice][ncl[slice]].padrow = padrow; | |
590 | ||
591 | //Read pad | |
5a31e9df | 592 | buff = InputBits(input,AliL3DataCompressorHelper::GetNPadBitsRemaining()); |
593 | clusters[slice][ncl[slice]].pad = (Float_t)buff/AliL3DataCompressorHelper::GetPadPrecisionFactor(); | |
6f388e0d | 594 | |
595 | //Read time | |
5a31e9df | 596 | buff = InputBits(input,AliL3DataCompressorHelper::GetNTimeBitsRemaining()); |
597 | clusters[slice][ncl[slice]].time = (Float_t)buff/AliL3DataCompressorHelper::GetTimePrecisionFactor(); | |
6f388e0d | 598 | |
599 | //Read widths | |
5a31e9df | 600 | buff = InputBits(input,AliL3DataCompressorHelper::GetNShapeBitsRemaining()); |
601 | clusters[slice][ncl[slice]].sigmaY2 = pow((Float_t)buff/AliL3DataCompressorHelper::GetPadPrecisionFactor(),2); | |
602 | buff = InputBits(input,AliL3DataCompressorHelper::GetNShapeBitsRemaining()); | |
603 | clusters[slice][ncl[slice]].sigmaZ2 = pow((Float_t)buff/AliL3DataCompressorHelper::GetPadPrecisionFactor(),2); | |
6f388e0d | 604 | |
605 | //Read charge | |
5a31e9df | 606 | buff = InputBits(input,AliL3DataCompressorHelper::GetNChargeBits()); |
6f388e0d | 607 | clusters[slice][ncl[slice]].charge = buff; |
5a31e9df | 608 | |
6f388e0d | 609 | ncl[slice]++; |
610 | } | |
611 | ||
612 | } | |
613 | CloseInputBitFile(input); | |
614 | } | |
615 | } | |
616 | } | |
617 | ||
3e87ef69 | 618 | void AliL3Compress::PrintCompRatio(ofstream *outfile) |
029912b7 | 619 | { |
029912b7 | 620 | AliL3MemHandler *mem = new AliL3MemHandler(); |
3e87ef69 | 621 | Char_t fname[1024]; |
622 | UInt_t remain_size=0,digit_size=0; | |
623 | for(Int_t i=0; i<36; i++) | |
029912b7 | 624 | { |
3e87ef69 | 625 | if(fEvent<0) |
626 | sprintf(fname,"%s/comp/remains_%d_%d.raw",fPath,i,-1); | |
627 | else | |
628 | sprintf(fname,"%s/comp/remains_%d_%d_%d.raw",fPath,fEvent,i,-1); | |
629 | mem->SetBinaryInput(fname); | |
630 | remain_size += mem->GetFileSize(); | |
631 | mem->CloseBinaryInput(); | |
632 | ||
633 | sprintf(fname,"%s/binaries/digits_c8_%d_%d_%d.raw",fPath,fEvent,i,-1); | |
634 | mem->SetBinaryInput(fname); | |
635 | digit_size += mem->GetFileSize(); | |
636 | mem->CloseBinaryInput(); | |
029912b7 | 637 | } |
638 | ||
4a838220 | 639 | |
3e87ef69 | 640 | if(fEvent<0) |
641 | sprintf(fname,"%s/comp/tracks_c_%d_%d.raw",fPath,fSlice,fPatch); | |
642 | else | |
643 | sprintf(fname,"%s/comp/tracks_c_%d_%d_%d.raw",fPath,fEvent,fSlice,fPatch); | |
029912b7 | 644 | |
3e87ef69 | 645 | mem->SetBinaryInput(fname); |
646 | UInt_t compress_size = mem->GetFileSize(); | |
92a876e2 | 647 | mem->CloseBinaryInput(); |
92a876e2 | 648 | |
3e87ef69 | 649 | if(digit_size==0) |
92a876e2 | 650 | { |
0a86fbb7 | 651 | cerr<<"AliL3Compress::PrintCompRatio : Zero digit size, not able to obtain comp. ratios!"<<endl; |
652 | return; | |
92a876e2 | 653 | } |
92a876e2 | 654 | |
3e87ef69 | 655 | Float_t compratio = (Float_t)(compress_size + remain_size)/(Float_t)digit_size; |
1f1942b8 | 656 | Float_t entropy[2]; |
5a31e9df | 657 | Int_t track_size = GetEntropy(entropy[0],entropy[1])*sizeof(AliL3TrackModel); |
f64c4364 | 658 | if(outfile) |
f64c4364 | 659 | { |
3e87ef69 | 660 | ofstream &out = *outfile; |
5a31e9df | 661 | out<<compress_size<<' '<<remain_size<<' '<<digit_size<<' '<<track_size<<' '<<entropy[0]<<' '<<entropy[1]<<endl; |
f64c4364 | 662 | } |
1f1942b8 | 663 | |
3e87ef69 | 664 | cout<<"=========================================="<<endl; |
665 | cout<<"Original digits size : "<<digit_size/1000<<" kByte ( 100 % )"<<endl; | |
666 | cout<<"Compressed file size : "<<compress_size/1000<<" kByte ( "<<(Float_t)compress_size*100/(Float_t)digit_size<<" % )"<<endl; | |
5a31e9df | 667 | cout<<"Remaining file size : "<<remain_size/1000<<" kByte ( "<<(Float_t)remain_size*100/(Float_t)digit_size<<" % )"<<endl; |
668 | cout<<"Relative track size : "<<track_size/1000<<" kByte ( "<<(Float_t)track_size*100/(Float_t)digit_size<<" % )"<<endl; | |
669 | cout<<"Relative cluster size: "<<(compress_size-track_size)/1000<<" kByte ( "<<(Float_t)(compress_size-track_size)*100/(Float_t)digit_size<<" % )"<<endl; | |
3e87ef69 | 670 | cout<<"---------------------- "<<endl; |
671 | cout<<"Compression ratio : "<<compratio*100<<" %"<<endl; | |
672 | cout<<"=========================================="<<endl; | |
5a31e9df | 673 | cout<<"Entropy of residuals : "<<entropy[0]<<" "<<entropy[1]<<endl; |
be6ddb10 | 674 | } |
1f1942b8 | 675 | |
5a31e9df | 676 | Int_t AliL3Compress::GetEntropy(Float_t &pad_entropy,Float_t &time_entropy) |
1f1942b8 | 677 | { |
678 | //Calculate the entropy of the quantized residuals in both directions | |
679 | ||
680 | if(!ReadFile('m')) | |
5a31e9df | 681 | return 0; |
1f1942b8 | 682 | const Int_t nmax=100000; |
683 | Float_t pads[nmax]; | |
684 | Float_t times[nmax]; | |
685 | memset(&pads[0],0,nmax*sizeof(Float_t)); | |
686 | memset(×[0],0,nmax*sizeof(Float_t)); | |
687 | Float_t counter=0; | |
688 | ||
689 | for(Int_t i=0; i<fTracks->GetNTracks(); i++) | |
690 | { | |
691 | AliL3ModelTrack *track = (AliL3ModelTrack*)fTracks->GetCheckedTrack(i); | |
692 | if(!track) continue; | |
693 | for(Int_t padrow=0; padrow<AliL3Transform::GetNRows(); padrow++) | |
694 | { | |
695 | if(!track->IsPresent(padrow)) continue; | |
696 | Int_t dpad = abs((Int_t)rint(track->GetClusterModel(padrow)->fDPad)); | |
697 | Int_t dtime = abs((Int_t)rint(track->GetClusterModel(padrow)->fDTime)); | |
698 | if(dpad >= nmax || dtime >= nmax) | |
699 | { | |
700 | cerr<<"AliL3Compress::GetEntropy : Quantization out of range: "<<dpad<<" "<<dtime<<endl; | |
701 | break; | |
702 | } | |
703 | pads[dpad]++; | |
704 | times[dtime]++; | |
705 | counter++; | |
706 | } | |
707 | } | |
708 | pad_entropy=time_entropy=0; | |
709 | for(Int_t i=0; i<nmax; i++) | |
710 | { | |
711 | if(pads[i]>0) | |
712 | pad_entropy += (pads[i]/counter)*(log(pads[i]/counter)/log(2.0)); | |
713 | if(times[i]>0) | |
714 | time_entropy += (times[i]/counter)*(log(times[i]/counter)/log(2.0)); | |
715 | } | |
716 | ||
717 | pad_entropy*=-1; | |
718 | time_entropy*=-1; | |
5a31e9df | 719 | return fTracks->GetNTracks(); |
1f1942b8 | 720 | } |