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