Line data Source code
1 : // $Id$
2 :
3 : //**************************************************************************
4 : //* This file is property of and copyright by the ALICE HLT Project *
5 : //* ALICE Experiment at CERN, All rights reserved. *
6 : //* *
7 : //* Primary Authors: U. Frankenfeld, A. Vestbo, C. Loizides *
8 : //* Matthias Richter <Matthias.Richter@ift.uib.no> *
9 : //* for The ALICE HLT Project. *
10 : //* *
11 : //* Permission to use, copy, modify and distribute this software and its *
12 : //* documentation strictly for non-commercial purposes is hereby granted *
13 : //* without fee, provided that the above copyright notice appears in all *
14 : //* copies and that both the copyright notice and this permission notice *
15 : //* appear in the supporting documentation. The authors make no claims *
16 : //* about the suitability of this software for any purpose. It is *
17 : //* provided "as is" without express or implied warranty. *
18 : //**************************************************************************
19 :
20 : // @file AliHLTTPCMemHandler.cxx
21 : // @author U. Frankenfeld, A. Vestbo, C. Loizides, maintained by
22 : // Matthias Richter
23 : // @date
24 : // @brief input interface base class for the TPC tracking code before
25 : // migration to the HLT component framework
26 :
27 : #include <cassert>
28 : #include "AliHLTTPCDigitData.h"
29 : #include "AliHLTTPCLogging.h"
30 : #include "AliHLTTPCGeometry.h"
31 : #include "AliHLTTPCSpacePointData.h"
32 : #include "AliHLTTPCMemHandler.h"
33 : #include "TMath.h"
34 :
35 : using namespace std;
36 :
37 6 : ClassImp(AliHLTTPCMemHandler)
38 :
39 : AliHLTTPCMemHandler::AliHLTTPCMemHandler()
40 : :
41 0 : fRowMin(0),
42 0 : fRowMax(0),
43 0 : fSlice(0),
44 0 : fPatch(0),
45 0 : fInBinary(NULL),
46 0 : fOutBinary(NULL),
47 0 : fPt(NULL),
48 0 : fSize(0),
49 0 : fIsRandom(kFALSE),
50 0 : fNRandom(0),
51 0 : fNGenerate(0),
52 0 : fNUsed(0),
53 0 : fNDigits(0),
54 0 : fDPt(NULL),
55 0 : fRandomDigits(NULL),
56 0 : fDummy(0)
57 0 : {
58 : //Constructor
59 0 : Init(0,0);
60 0 : ResetROI();
61 0 : }
62 :
63 : AliHLTTPCMemHandler::~AliHLTTPCMemHandler()
64 0 : {
65 : //Destructor
66 0 : if(fPt) delete[] fPt;
67 0 : if(fRandomDigits) delete [] fRandomDigits;
68 0 : if(fDPt) delete [] fDPt;
69 0 : }
70 :
71 : void AliHLTTPCMemHandler::Init(Int_t s,Int_t p, Int_t *r)
72 : {
73 : //init handler
74 0 : assert(s<fgkNSlice);
75 0 : if (s>fgkNSlice) {
76 0 : fSlice=0;
77 0 : fPatch=0;
78 0 : fRowMin=0;
79 0 : fRowMax=0;
80 0 : if (r) *r=0;
81 0 : LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Init","sector coordinates")
82 0 : <<"Invalid slice no " << s <<ENDLOG;
83 : return;
84 : }
85 0 : fSlice=s;fPatch=p;
86 0 : if(r) {
87 0 : fRowMin=r[0];
88 0 : fRowMax=r[1];
89 0 : }else{
90 0 : fRowMin=AliHLTTPCGeometry::GetFirstRow(p);
91 0 : fRowMax=AliHLTTPCGeometry::GetLastRow(p);
92 : }
93 0 : ResetROI();
94 0 : }
95 :
96 : void AliHLTTPCMemHandler::ResetROI()
97 : {
98 : //Resets the Look-up table for Region of Interest mode.
99 0 : for(Int_t i=fRowMin; i<=fRowMax; i++)
100 : {
101 0 : fEtaMinTimeBin[i] = 0;
102 0 : fEtaMaxTimeBin[i] = AliHLTTPCGeometry::GetNTimeBins()-1;
103 : }
104 0 : }
105 :
106 : void AliHLTTPCMemHandler::SetROI(const Float_t *eta,Int_t */*slice*/)
107 : {
108 : // Init the Look-up table for the Region of Interest mode.
109 : // Here you can specify a certain etaregion, - all data
110 : // outside this region will be discarded:
111 : // eta[0] = mimium eta
112 : // eta[1] = maximum eta
113 : // slice[0] = mimumum slice
114 : // slice[1] = maximum slice
115 :
116 :
117 0 : if(TMath::Abs(eta[1])<.00001)
118 : {
119 0 : LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::SetROI","Eta Values")
120 0 : <<"Bad ROI parameters."<<ENDLOG;
121 0 : for(Int_t i=fRowMin; i<=fRowMax; i++)
122 : {
123 0 : fEtaMinTimeBin[i]=0;
124 0 : fEtaMaxTimeBin[i]=0;
125 : }
126 0 : return;
127 : }
128 :
129 0 : for(Int_t i=fRowMin; i<=fRowMax; i++)
130 : {
131 0 : Int_t sector,row;
132 0 : Float_t xyz[3];
133 :
134 0 : Float_t thetamax = 2*atan(exp(-1.*eta[1]));
135 :
136 0 : xyz[0] = AliHLTTPCGeometry::Row2X(i);
137 0 : xyz[1]=0;
138 0 : xyz[2] = xyz[0]/tan(thetamax);
139 0 : AliHLTTPCGeometry::Slice2Sector(fSlice,i,sector,row);
140 0 : AliHLTTPCGeometry::Local2Raw(xyz,sector,row);
141 :
142 0 : fEtaMinTimeBin[i] = (Int_t)xyz[2];
143 :
144 0 : if(TMath::Abs(eta[0])<.00001)
145 0 : fEtaMaxTimeBin[i] = 445;
146 : else
147 : {
148 0 : Float_t thetamin = 2*atan(exp(-1.*eta[0]));
149 0 : xyz[0] = AliHLTTPCGeometry::Row2X(i);
150 0 : xyz[1] = AliHLTTPCGeometry::GetMaxY(i);
151 0 : Float_t radii = sqrt(pow(xyz[0],2) + pow(xyz[1],2));
152 0 : xyz[2] = radii/tan(thetamin);
153 0 : AliHLTTPCGeometry::Local2Raw(xyz,sector,row);
154 0 : fEtaMaxTimeBin[i] = (Int_t)xyz[2];
155 : }
156 0 : }
157 :
158 0 : }
159 :
160 : Bool_t AliHLTTPCMemHandler::SetBinaryInput(char *name)
161 : {
162 : //Set the input binary file.
163 0 : fInBinary = fopen(name,"r");
164 0 : if(!fInBinary){
165 0 : LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::SetBinaryInput","File Open")
166 0 : <<"Error opening file "<<name<<ENDLOG;
167 0 : return kFALSE;
168 : }
169 0 : return kTRUE;
170 0 : }
171 :
172 : Bool_t AliHLTTPCMemHandler::SetBinaryInput(FILE *file)
173 : {
174 : //Set the input binary file.
175 0 : fInBinary = file;
176 0 : if(!fInBinary){
177 0 : LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::SetBinaryInput","File Open")
178 0 : <<"Pointer to File = 0x0 "<<ENDLOG;
179 0 : return kFALSE;
180 : }
181 0 : return kTRUE;
182 0 : }
183 :
184 : void AliHLTTPCMemHandler::CloseBinaryInput()
185 : {
186 : //Close the input file.
187 0 : if(!fInBinary){
188 0 : LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::CloseBinaryInput","File Close")
189 0 : <<"Nothing to Close"<<ENDLOG;
190 : return;
191 : }
192 0 : fclose(fInBinary);
193 0 : fInBinary =0;
194 0 : }
195 :
196 : Bool_t AliHLTTPCMemHandler::SetBinaryOutput(char *name)
197 : {
198 : //Set the binary output file.
199 0 : fOutBinary = fopen(name,"w");
200 0 : if(!fOutBinary){
201 0 : LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::SetBinaryOutput","File Open")
202 0 : <<"Pointer to File = 0x0 "<<ENDLOG;
203 0 : return kFALSE;
204 : }
205 0 : return kTRUE;
206 0 : }
207 :
208 : Bool_t AliHLTTPCMemHandler::SetBinaryOutput(FILE *file)
209 : {
210 : //Set the binary output file.
211 0 : fOutBinary = file;
212 0 : if(!fOutBinary){
213 0 : LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::SetBinaryOutput","File Open")
214 0 : <<"Pointer to File = 0x0 "<<ENDLOG;
215 0 : return kFALSE;
216 : }
217 0 : return kTRUE;
218 0 : }
219 :
220 : void AliHLTTPCMemHandler::CloseBinaryOutput()
221 : {
222 : //close binary
223 0 : if(!fOutBinary){
224 0 : LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::CloseBinaryOutPut","File Close")
225 0 : <<"Nothing to Close"<<ENDLOG;
226 : return;
227 : }
228 0 : fclose(fOutBinary);
229 0 : fOutBinary =0;
230 0 : }
231 :
232 : UInt_t AliHLTTPCMemHandler::GetFileSize()
233 : {
234 : //Returns the file size in bytes of the input file.
235 0 : if(!fInBinary){
236 0 : LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::GetFileSize","File")
237 0 : <<"No Input File"<<ENDLOG;
238 0 : return 0;
239 : }
240 0 : fseek(fInBinary,0,SEEK_END);
241 0 : long size=ftell(fInBinary);
242 0 : rewind(fInBinary);
243 0 : if (size<0) return 0;
244 0 : return (UInt_t)size;
245 0 : }
246 :
247 : Byte_t *AliHLTTPCMemHandler::Allocate()
248 : {
249 : //Allocate
250 0 : return Allocate(GetFileSize());
251 : }
252 :
253 : Byte_t *AliHLTTPCMemHandler::Allocate(UInt_t size)
254 : {
255 : //Allocate memory of size in bytes.
256 0 : if(fPt){
257 0 : LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Allocate","Memory")
258 0 : <<"Delete Memory"<<ENDLOG;
259 0 : Free();
260 0 : }
261 0 : fPt = new Byte_t[size];
262 0 : fSize = size;
263 0 : memset(fPt,0,fSize);
264 0 : LOG(AliHLTTPCLog::kDebug,"AliHLTTPCMemHandler::Allocate","Memory")
265 0 : <<AliHLTTPCLog::kDec<<"Allocate "<<size<<" Bytes of Memory"<<ENDLOG;
266 0 : return fPt;
267 : }
268 :
269 : void AliHLTTPCMemHandler::Free()
270 : {
271 : //Clear the memory, if allocated.
272 0 : if(!fPt){
273 : // LOG(AliHLTTPCLog::kInformational,"AliHLTTPCMemHandler::Free","Memory")
274 : // <<"No Memory allocated - can't Free"<<ENDLOG;
275 : return;
276 : }
277 0 : delete[] fPt;
278 0 : fPt = 0;
279 0 : fSize =0;
280 0 : }
281 :
282 : ///////////////////////////////////////// Random
283 : void AliHLTTPCMemHandler::SetRandomSeed()
284 : {
285 : //If you are adding random data to the original data.
286 : time_t *tp=0;
287 0 : SetRandomSeed(time(tp));
288 0 : }
289 :
290 : void AliHLTTPCMemHandler::SetRandomCluster(Int_t maxnumber)
291 : {
292 : //If you are adding random data to the original data.
293 :
294 0 : fIsRandom = kTRUE;
295 0 : fNRandom = maxnumber;
296 0 : fNDigits = 0;
297 0 : if(fRandomDigits) delete [] fRandomDigits;
298 0 : fRandomDigits = new AliHLTTPCRandomDigitData[fNRandom*9];
299 0 : if(fDPt) delete [] fDPt;
300 0 : fDPt = new AliHLTTPCRandomDigitData *[fNRandom*9];
301 0 : }
302 :
303 : void AliHLTTPCMemHandler::QSort(AliHLTTPCRandomDigitData **a, Int_t first, Int_t last)
304 : {
305 :
306 : // Sort array of AliHLTTPCRandomDigitData pointers using a quicksort algorithm.
307 : // Uses CompareDigits() to compare objects.
308 : // Thanks to Root!
309 :
310 : static AliHLTTPCRandomDigitData *tmp;
311 : static int i; // "static" to save stack space
312 : int j;
313 :
314 0 : while (last - first > 1) {
315 0 : i = first;
316 : j = last;
317 0 : for (;;) {
318 0 : while (++i < last && CompareDigits(a[i], a[first]) < 0)
319 : ;
320 0 : while (--j > first && CompareDigits(a[j], a[first]) > 0)
321 : ;
322 0 : if (i >= j)
323 : break;
324 :
325 0 : tmp = a[i];
326 0 : a[i] = a[j];
327 0 : a[j] = tmp;
328 : }
329 0 : if (j == first) {
330 0 : ++first;
331 0 : continue;
332 : }
333 0 : tmp = a[first];
334 0 : a[first] = a[j];
335 0 : a[j] = tmp;
336 :
337 0 : if (j - first < last - (j + 1)) {
338 0 : QSort(a, first, j);
339 : first = j + 1; // QSort(j + 1, last);
340 0 : } else {
341 0 : QSort(a, j + 1, last);
342 : last = j; // QSort(first, j);
343 : }
344 : }
345 0 : }
346 :
347 : UInt_t AliHLTTPCMemHandler::GetRandomSize() const
348 : {
349 : //get random size
350 : Int_t nrandom = 0;
351 0 : for(Int_t r=fRowMin;r<=fRowMax;r++){
352 0 : Int_t npad=AliHLTTPCGeometry::GetNPads(r);
353 0 : nrandom += Int_t (fNGenerate * ((Double_t) npad/141.));
354 : }
355 0 : return 9 * nrandom * sizeof(AliHLTTPCDigitData);
356 : }
357 :
358 : void AliHLTTPCMemHandler::DigitizePoint(Int_t row, Int_t pad,
359 : Int_t time,Int_t charge)
360 : {
361 : //Making one single random cluster.
362 0 : for(Int_t j=-1;j<2;j++){
363 0 : for(Int_t k=-1;k<2;k++){
364 : Int_t dcharge = charge;
365 0 : if(j) dcharge /=2;
366 0 : if(k) dcharge /=2;
367 0 : if(dcharge<10) continue;
368 0 : Int_t dpad = j + pad;
369 0 : Int_t dtime = k + time;
370 :
371 0 : if(dpad<0||dpad>=AliHLTTPCGeometry::GetNPads(row)) continue;
372 0 : if(dtime<0||dtime>=AliHLTTPCGeometry::GetNTimeBins()) continue;
373 :
374 0 : fRandomDigits[fNDigits].fCharge = dcharge;
375 0 : fRandomDigits[fNDigits].fRow = row;
376 0 : fRandomDigits[fNDigits].fPad = dpad;
377 0 : fRandomDigits[fNDigits].fTime = dtime;
378 0 : fDPt[fNDigits] = &fRandomDigits[fNDigits];
379 0 : fNDigits++;
380 0 : }
381 : }
382 0 : }
383 :
384 : ///////////////////////////////////////// Digit IO
385 : Bool_t AliHLTTPCMemHandler::Memory2BinaryFile(UInt_t nrow,AliHLTTPCDigitRowData *data)
386 : {
387 : //Write data to the outputfile as is. No run-length encoding is done.
388 :
389 0 : if(!fOutBinary){
390 0 : LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Memory2Binary","File")
391 0 : <<"No Output File"<<ENDLOG;
392 0 : return kFALSE;
393 : }
394 0 : if(!data){
395 0 : LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Memory2Binary","Memory")
396 0 : <<"Pointer to AliHLTTPCDigitRowData = 0x0 "<<ENDLOG;
397 0 : return kFALSE;
398 : }
399 :
400 : AliHLTTPCDigitRowData *rowPt = data;
401 : Int_t outsize = 0;
402 0 : for(UInt_t i=0;i<nrow;i++){
403 0 : Int_t size = sizeof(AliHLTTPCDigitData) * rowPt->fNDigit
404 0 : + sizeof(AliHLTTPCDigitRowData);
405 0 : outsize += size;
406 0 : fwrite(rowPt,size,1,fOutBinary);
407 : Byte_t *bytePt =(Byte_t *) rowPt;
408 0 : bytePt += size;
409 0 : rowPt = (AliHLTTPCDigitRowData *) bytePt;
410 : }
411 0 : LOG(AliHLTTPCLog::kDebug,"AliHLTTPCMemHandler::Memory2Binary","Memory")
412 0 : <<AliHLTTPCLog::kDec<<"Wrote "<<outsize<<" Bytes to Memory ("
413 0 : <<nrow<<" Rows)"<<ENDLOG;
414 : return kTRUE;
415 0 : }
416 :
417 : void AliHLTTPCMemHandler::AddData(AliHLTTPCDigitData *data,UInt_t & ndata,
418 : UInt_t /*row*/,UShort_t pad,UShort_t time,UShort_t charge) const
419 : {
420 : //add some data
421 0 : data[ndata].fPad = pad;
422 0 : data[ndata].fTime = time;
423 0 : data[ndata].fCharge = charge;
424 0 : ndata++;
425 0 : }
426 :
427 : void AliHLTTPCMemHandler::AddRandom(AliHLTTPCDigitData *data, UInt_t & ndata)
428 : {
429 : //add some random data
430 0 : data[ndata].fPad = fDPt[fNUsed]->fPad;
431 0 : data[ndata].fTime = fDPt[fNUsed]->fTime;
432 0 : data[ndata].fCharge = fDPt[fNUsed]->fCharge;
433 0 : ndata++;
434 0 : fNUsed++;
435 0 : }
436 :
437 : void AliHLTTPCMemHandler::MergeDataRandom(AliHLTTPCDigitData *data, UInt_t & ndata,
438 : UInt_t row, UShort_t pad, UShort_t time, UShort_t charge)
439 : {
440 : //merge random data
441 0 : data[ndata].fPad = pad;
442 0 : data[ndata].fTime = time;
443 0 : data[ndata].fCharge = charge;
444 0 : while(ComparePoints(row,pad,time)==0){
445 0 : Int_t ch = data[ndata].fCharge + fDPt[fNUsed]->fCharge;
446 0 : if(charge>=AliHLTTPCGeometry::GetADCSat()) ch = AliHLTTPCGeometry::GetADCSat();
447 0 : data[ndata].fCharge = ch;
448 0 : fNUsed++;
449 : }
450 0 : ndata++;
451 0 : }
452 :
453 : void AliHLTTPCMemHandler::AddDataRandom(AliHLTTPCDigitData *data, UInt_t & ndata,
454 : UInt_t row, UShort_t pad, UShort_t time, UShort_t charge)
455 : {
456 : //add data random
457 : Int_t action;
458 0 : while((action=ComparePoints(row,pad,time))==1){
459 0 : AddRandom(data,ndata);
460 : }
461 0 : if(action==0){
462 0 : MergeDataRandom(data,ndata,row,pad,time,charge);
463 0 : }
464 0 : if(action<0){
465 0 : AddData(data,ndata,row,pad,time,charge);
466 0 : }
467 0 : }
468 :
469 : void AliHLTTPCMemHandler::Write(UInt_t *comp, UInt_t & index,
470 : UInt_t & subindex, UShort_t value) const
471 : {
472 : //write compressed data
473 0 : UInt_t shift[3] = {0,10,20};
474 0 : if(subindex==0) comp[index] =0; //clean up memory
475 0 : comp[index] |= (value&0x03ff)<<shift[subindex];
476 0 : if(subindex == 2){
477 0 : subindex = 0;
478 0 : index++;
479 0 : }
480 0 : else subindex++;
481 0 : }
482 :
483 : UShort_t AliHLTTPCMemHandler::Read(UInt_t *comp, UInt_t & index, UInt_t & subindex) const
484 : {
485 : //read compressed data
486 0 : UInt_t shift[3] = {0,10,20};
487 0 : UShort_t value = (comp[index]>>shift[subindex])&0x03ff;
488 0 : if(subindex == 2){
489 0 : subindex = 0;
490 0 : index++;
491 0 : }
492 0 : else subindex++;
493 :
494 0 : return value;
495 0 : }
496 :
497 : UShort_t AliHLTTPCMemHandler::Test(const UInt_t *comp,
498 : UInt_t index, UInt_t subindex) const
499 : {
500 : //supi dupi test
501 0 : UInt_t shift[3] = {0,10,20};
502 0 : return (comp[index]>>shift[subindex])&0x03ff;
503 0 : }
504 :
505 : Int_t AliHLTTPCMemHandler::Memory2CompMemory(UInt_t nrow,
506 : AliHLTTPCDigitRowData *data,UInt_t *comp)
507 : {
508 : //Performs run-length encoding on data stored in memory pointed to by data.
509 : //The compressed data is written to comp.
510 0 : if(!comp){
511 0 : LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Memory2CompMemory","Memory")
512 0 : <<"Pointer to compressed data = 0x0 "<<ENDLOG;
513 0 : return 0;
514 : }
515 0 : if(!data){
516 0 : LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Memory2CompMemory","Memory")
517 0 : <<"Pointer to AliHLTTPCDigitRowData = 0x0 "<<ENDLOG;
518 0 : return 0;
519 : }
520 : AliHLTTPCDigitRowData *rowPt = data;
521 0 : UInt_t index=0;
522 0 : UInt_t subindex=0;
523 :
524 0 : for(UInt_t i=0;i<nrow;i++){
525 0 : UShort_t value = rowPt->fRow;
526 0 : Write(comp,index,subindex,value);
527 : UShort_t maxpad=0;
528 : UShort_t npad=0;
529 0 : Int_t ddd[1000];
530 0 : for(Int_t d=0;d<200;d++) ddd[d]=0;
531 0 : for(UInt_t dig=0;dig<rowPt->fNDigit;dig++){
532 0 : if(rowPt->fDigitData[dig].fPad <200){
533 0 : ddd[rowPt->fDigitData[dig].fPad]++;
534 0 : }
535 : }
536 0 : for(Int_t d=0;d<200;d++){
537 0 : if(ddd[d]){
538 0 : npad++;
539 0 : maxpad =d;
540 0 : }
541 : }
542 0 : Write(comp,index,subindex,npad);
543 : UInt_t digit=0;
544 0 : for(UShort_t pad=0;pad <= maxpad;pad++){
545 0 : if(digit>=rowPt->fNDigit || rowPt->fDigitData[digit].fPad != pad)
546 : continue;
547 0 : Write(comp,index,subindex,pad);
548 : // write zero if time != 0
549 0 : if(digit<rowPt->fNDigit && rowPt->fDigitData[digit].fPad == pad){
550 0 : if(rowPt->fDigitData[digit].fTime>0){
551 0 : Write(comp,index,subindex,0);
552 0 : Write(comp,index,subindex,rowPt->fDigitData[digit].fTime);
553 0 : }
554 : }
555 0 : while(digit<rowPt->fNDigit && rowPt->fDigitData[digit].fPad == pad){
556 0 : UShort_t charge = rowPt->fDigitData[digit].fCharge;
557 0 : if(charge>=1023){
558 : charge=1023;
559 : }
560 0 : Write(comp,index,subindex,charge);
561 0 : if(digit+1<rowPt->fNDigit&&rowPt->fDigitData[digit+1].fPad == pad){
562 0 : if(rowPt->fDigitData[digit].fTime +1 !=
563 0 : rowPt->fDigitData[digit+1].fTime){
564 0 : Write(comp,index,subindex,0);
565 0 : UShort_t nzero = rowPt->fDigitData[digit+1].fTime -
566 0 : (rowPt->fDigitData[digit].fTime +1);
567 0 : Write(comp,index,subindex,nzero);
568 0 : }
569 : }
570 : digit++;
571 : }
572 0 : Write(comp,index,subindex,0);
573 0 : Write(comp,index,subindex,0);
574 0 : }
575 :
576 0 : Int_t size = sizeof(AliHLTTPCDigitData) * rowPt->fNDigit+
577 : sizeof(AliHLTTPCDigitRowData);
578 0 : Byte_t *bytePt =(Byte_t *) rowPt;
579 0 : bytePt += size;
580 0 : rowPt = (AliHLTTPCDigitRowData *) bytePt;
581 0 : }
582 0 : while(subindex)
583 0 : Write(comp,index,subindex,0);
584 0 : return index * sizeof(UInt_t);
585 0 : }
586 :
587 : UInt_t AliHLTTPCMemHandler::GetCompMemorySize(UInt_t nrow,AliHLTTPCDigitRowData *data) const
588 : {
589 : //Return the size of RLE data, after compressing data.
590 :
591 0 : if(!data){
592 0 : LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::GetCompMemorySize","Memory")
593 0 : <<"Pointer to AliHLTTPCDigitRowData = 0x0 "<<ENDLOG;
594 0 : return 0;
595 : }
596 : AliHLTTPCDigitRowData *rowPt = data;
597 : UInt_t index=0;
598 :
599 0 : for(UInt_t i=0;i<nrow;i++){
600 0 : index++;
601 : UShort_t maxpad=0;
602 : UShort_t npad=0;
603 0 : Int_t ddd[1000];
604 0 : for(Int_t d=0;d<200;d++) ddd[d]=0;
605 0 : for(UInt_t dig=0;dig<rowPt->fNDigit;dig++){
606 0 : if(rowPt->fDigitData[dig].fPad <200){
607 0 : ddd[rowPt->fDigitData[dig].fPad]++;
608 0 : }
609 : }
610 0 : for(Int_t d=0;d<200;d++){
611 0 : if(ddd[d]){
612 0 : npad++;
613 0 : maxpad =d;
614 0 : }
615 : }
616 0 : index++;
617 : UInt_t digit=0;
618 0 : for(UShort_t pad=0;pad <= maxpad;pad++){
619 0 : if(digit>=rowPt->fNDigit || rowPt->fDigitData[digit].fPad != pad)
620 : continue;
621 0 : index++;
622 : // write zero if time != 0
623 0 : if(digit<rowPt->fNDigit && rowPt->fDigitData[digit].fPad == pad){
624 0 : if(rowPt->fDigitData[digit].fTime>0){
625 0 : index++;
626 0 : index++;
627 0 : }
628 : }
629 0 : while(digit<rowPt->fNDigit && rowPt->fDigitData[digit].fPad == pad){
630 0 : index++;
631 0 : if(digit+1<rowPt->fNDigit&&rowPt->fDigitData[digit+1].fPad == pad){
632 0 : if(rowPt->fDigitData[digit].fTime +1 !=
633 0 : rowPt->fDigitData[digit+1].fTime){
634 0 : index++;
635 0 : index++;
636 0 : }
637 : }
638 : digit++;
639 : }
640 : index++;
641 0 : index++;
642 0 : }
643 :
644 0 : Int_t size = sizeof(AliHLTTPCDigitData) * rowPt->fNDigit+
645 : sizeof(AliHLTTPCDigitRowData);
646 0 : Byte_t *bytePt =(Byte_t *) rowPt;
647 0 : bytePt += size;
648 0 : rowPt = (AliHLTTPCDigitRowData *) bytePt;
649 0 : }
650 0 : while(index%3)
651 0 : index++;
652 0 : return (index/3) * sizeof(UInt_t);
653 0 : }
654 :
655 : UInt_t AliHLTTPCMemHandler::GetMemorySize(UInt_t nrow,UInt_t *comp) const
656 : {
657 : //get memory size
658 0 : if(!comp){
659 0 : LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::GetMemorySize","Memory")
660 0 : <<"Pointer to compressed data = 0x0 "<<ENDLOG;
661 0 : return 0;
662 : }
663 : Int_t outsize=0;
664 :
665 0 : UInt_t index=0;
666 0 : UInt_t subindex=0;
667 :
668 0 : for(UInt_t i=0;i<nrow;i++){
669 : UInt_t ndigit=0;
670 0 : Read(comp,index,subindex);
671 0 : UShort_t npad = Read(comp,index,subindex);
672 0 : for(UShort_t p=0;p<npad;p++){
673 0 : Read(comp,index,subindex);
674 0 : if(Test(comp,index,subindex)==0){
675 0 : Read(comp,index,subindex);
676 0 : if(Read(comp,index,subindex)== 0) continue;
677 : }
678 : for(;;){
679 0 : while(Read(comp,index,subindex)!=0) ndigit++;
680 0 : if(Read(comp,index,subindex)==0) break;
681 : }
682 : }
683 0 : Int_t size = sizeof(AliHLTTPCDigitData) * ndigit+
684 : sizeof(AliHLTTPCDigitRowData);
685 0 : outsize += size;
686 : }
687 :
688 : return outsize;
689 0 : }
690 :
691 : UInt_t AliHLTTPCMemHandler::GetNRow(UInt_t *comp,UInt_t size)
692 : {
693 : //get number of rows
694 0 : if(!comp){
695 0 : LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::GetNRow","Memory")
696 0 : <<"Pointer to compressed data = 0x0 "<<ENDLOG;
697 0 : return 0;
698 : }
699 0 : size = size /4;
700 : UInt_t nrow=0;
701 0 : UInt_t index=0;
702 0 : UInt_t subindex=0;
703 0 : while(index<size-1){ //don't start with last word
704 0 : nrow++;
705 : UInt_t ndigit=0;
706 0 : Read(comp,index,subindex);
707 0 : UShort_t npad = Read(comp,index,subindex);
708 0 : for(UShort_t p=0;p<npad;p++){
709 0 : Read(comp,index,subindex);
710 0 : if(Test(comp,index,subindex)==0){
711 0 : Read(comp,index,subindex);
712 0 : if(Read(comp,index,subindex)==0)continue;
713 : }
714 : for(;;){
715 0 : while(Read(comp,index,subindex)!=0) ndigit++;
716 0 : if(Read(comp,index,subindex)==0) break;
717 : }
718 : }
719 : }
720 0 : if(index==size-1){ //last word
721 0 : if(subindex<2){
722 0 : if(Read(comp,index,subindex)!=0) nrow++;
723 : }
724 : }
725 : return nrow;
726 0 : }
727 :
728 : Bool_t AliHLTTPCMemHandler::CompMemory2CompBinary(UInt_t nrow,UInt_t *comp,
729 : UInt_t size)
730 : {
731 : //Write the RLE data in comp to the output file.
732 :
733 0 : if(!fOutBinary){
734 0 : LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::CompMemory2CompBinary","File")
735 0 : <<"No Output File"<<ENDLOG;
736 0 : return kFALSE;
737 : }
738 0 : if(!comp){
739 0 : LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::CompMemory2CompBinary","Memory")
740 0 : <<"Pointer to compressed data = 0x0 "<<ENDLOG;
741 0 : return kFALSE;
742 : }
743 0 : if(size==0)
744 0 : size=GetMemorySize(nrow,comp);
745 0 : if(!size){
746 0 : LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::CompMemory2CompBinary","Memory")
747 0 : <<"Memory size = 0 "<<ENDLOG;
748 0 : return kFALSE;
749 : }
750 0 : UInt_t length = size/sizeof(UInt_t);
751 0 : fwrite(&length,sizeof(UInt_t),1,fOutBinary);
752 0 : fwrite(comp,size,1,fOutBinary);
753 : return kTRUE;
754 0 : }
755 :
756 :
757 : Bool_t AliHLTTPCMemHandler::Memory2CompBinary(UInt_t nrow,AliHLTTPCDigitRowData *data)
758 : {
759 : //Perform RLE on the data, and write it to the output file.
760 : Bool_t out = kTRUE;
761 0 : AliHLTTPCMemHandler * handler = new AliHLTTPCMemHandler();
762 0 : UInt_t size = GetCompMemorySize(nrow,data);
763 0 : UInt_t *comp =(UInt_t *)handler->Allocate(size);
764 0 : Memory2CompMemory(nrow,data,comp);
765 0 : CompMemory2CompBinary(nrow,comp,size);
766 0 : handler->Free();
767 0 : delete handler;
768 0 : return out;
769 0 : }
770 :
771 :
772 : ///////////////////////////////////////// Point IO
773 : Bool_t AliHLTTPCMemHandler::Memory2Binary(UInt_t npoint,AliHLTTPCSpacePointData *data)
774 : {
775 : //Writing spacepoints stored in data to the outputfile.
776 0 : if(!fOutBinary){
777 0 : LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Memory2Binary","File")
778 0 : <<"No Output File"<<ENDLOG;
779 0 : return kFALSE;
780 : }
781 0 : if(!data){
782 0 : LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Memory2Binary","Memory")
783 0 : <<"Pointer to AliHLTTPCSpacePointData = 0x0 "<<ENDLOG;
784 0 : return kFALSE;
785 : }
786 0 : UInt_t size = npoint*sizeof(AliHLTTPCSpacePointData);
787 0 : fwrite(data,size,1,fOutBinary);
788 :
789 : return kTRUE;
790 0 : }
791 :
792 : Bool_t AliHLTTPCMemHandler::Transform(UInt_t npoint,AliHLTTPCSpacePointData *data,Int_t slice)
793 : {
794 : //Transform the space points in data, to global coordinates in slice.
795 0 : if(!data){
796 0 : LOG(AliHLTTPCLog::kWarning,"AliHLTTPCMemHandler::Transform","Memory")
797 0 : <<"Pointer to AliHLTTPCSpacePointData = 0x0 "<<ENDLOG;
798 0 : return kFALSE;
799 : }
800 :
801 0 : for(UInt_t i=0;i<npoint;i++){
802 0 : Float_t xyz[3];
803 0 : xyz[0] = data[i].fX;
804 0 : xyz[1] = data[i].fY;
805 0 : xyz[2] = data[i].fZ;
806 0 : AliHLTTPCGeometry::Local2Global(xyz,slice);
807 0 : data[i].fX = xyz[0];
808 0 : data[i].fY = xyz[1];
809 0 : data[i].fZ = xyz[2];
810 0 : }
811 0 : return kTRUE;
812 0 : }
813 :
814 : void AliHLTTPCMemHandler::UpdateRowPointer(AliHLTTPCDigitRowData *&tempPt)
815 : {
816 : //Update the data pointer to the next padrow in memory.
817 :
818 0 : Byte_t *tmp = (Byte_t*)tempPt;
819 0 : Int_t size = sizeof(AliHLTTPCDigitRowData) + tempPt->fNDigit*sizeof(AliHLTTPCDigitData);
820 0 : tmp += size;
821 0 : tempPt = (AliHLTTPCDigitRowData*)tmp;
822 0 : }
823 :
824 : Int_t AliHLTTPCMemHandler::ComparePoints(UInt_t /*row*/,UShort_t pad,UShort_t time) const
825 : {
826 : //compare two points
827 0 : if(fNUsed>=fNDigits) return -2;
828 :
829 0 : if(pad==fDPt[fNUsed]->fPad&&time==fDPt[fNUsed]->fTime) return 0;
830 :
831 0 : if(pad<fDPt[fNUsed]->fPad) return -1;
832 0 : if(pad==fDPt[fNUsed]->fPad&&time<fDPt[fNUsed]->fTime) return -1;
833 :
834 0 : return 1;
835 0 : }
836 :
837 : Int_t AliHLTTPCMemHandler::CompareDigits(const AliHLTTPCRandomDigitData *a,const AliHLTTPCRandomDigitData *b) const
838 : {
839 : //compare two digits
840 0 : if(a->fPad==b->fPad && a->fTime == b->fTime) return 0;
841 :
842 0 : if(a->fPad<b->fPad) return -1;
843 0 : if(a->fPad==b->fPad && a->fTime<b->fTime) return -1;
844 :
845 0 : return 1;
846 0 : }
|