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