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