]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/src/AliL3MemHandler.cxx
4f9aea8ad66937345122caf61dbaadd6cd4da087
[u/mrichter/AliRoot.git] / HLT / src / AliL3MemHandler.cxx
1 // $Id$
2
3 // Author: Uli Frankenfeld <mailto:franken@fi.uib.no>, Anders Vestbo <mailto:vestbo$fi.uib.no>
4 //*-- Copyright &copy Uli 
5 // changes done by Constantin Loizides <mailto:loizides@ikf.physik.uni-frankfurt.de>
6
7 #include "AliL3StandardIncludes.h"
8
9 #include "AliL3Logging.h"
10 #include "AliL3Transform.h"
11 #include "AliL3TrackSegmentData.h"
12 #include "AliL3SpacePointData.h"
13 #include "AliL3TrackArray.h"
14 #include "AliL3MemHandler.h"
15
16 /** \class AliL3MemHandler 
17 //<pre>
18 //_____________________________________________________________
19 // AliL3MemHandler
20 //
21 // The HLT Binary File handler 
22 //
23 //  This class does all the memory I/O handling of HLT binary files.
24 //  
25 //  Examples:
26 //  ---------
27 //
28 //  1) Reading a binary file:
29 //  
30 //  AliL3MemHandler file;
31 //  file.SetBinaryInput(filename);
32 //  file.Init(slice,patch);
33 //
34 //  UInt_t nrowss;
35 //  AliL3DigitRowData *data = file.CompBinary2Memory(nrowss);
36 //  
37 //  for(int i=0; i<nrows; i++) 
38 //    {
39 //    
40 //    AliL3DigitData *dataPt = (AliL3DigitData*)data->fDigitData;
41 //    for(int j=0; j<data->fNDigit; j++) 
42 //      {
43 //        pad = dataPt[j].fPad;
44 //        time = dataPt[j].fTime;
45 //        charge = dataPt[j].fCharge;
46 //      }
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;
62 //  newfile.Init(slice,patch);
63 //  newfile.SetBinaryOutput(newfilename);
64 //  newfile.Memory2CompBinary((UInt_t)NumberOfRowsInPatch,(AliL3DigitRowData*)data);
65 //  newfile.CloseBinaryOutput();
66 //
67 //
68 // Compressed file format:
69 // -----------------------
70 //
71 // The data is RLE encoded and currently using _10_ bit range for the ADC-values.
72 //</pre> 
73 */  
74   
75 ClassImp(AliL3MemHandler)
76   
77 AliL3MemHandler::AliL3MemHandler()
78 {
79   //Constructor
80   
81   fPt = 0;
82   fSize =0;
83   fInBinary = 0;
84   fOutBinary = 0;
85   fNRandom = 0;
86   Init(0,0);
87   IsRandom = kFALSE;
88   fDigits = 0;
89   fDPt =0;
90   fNGenerate = 0;
91   fNUsed = 0;
92   fNDigits = 0;
93   ResetROI();
94 }
95
96
97 AliL3MemHandler::~AliL3MemHandler()
98 {
99   //Destructor
100   if(fPt) delete[] fPt;
101   if(fDigits) delete [] fDigits;
102   if(fDPt) delete [] fDPt;
103 }
104
105 void AliL3MemHandler::Init(Int_t s,Int_t p, Int_t *r)
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
118 void AliL3MemHandler::ResetROI()
119 {
120   //Resets the Look-up table for Region of Interest mode.
121   
122   for(Int_t i=fRowMin; i<=fRowMax; i++)
123     {
124       fEtaMinTimeBin[i] = 0;
125       fEtaMaxTimeBin[i] = AliL3Transform::GetNTimeBins()-1;
126     }
127 }
128
129 void AliL3MemHandler::SetROI(Float_t *eta,Int_t *slice)
130 {
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
138
139
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       
159       xyz[0] = AliL3Transform::Row2X(i);
160       xyz[1]=0;
161       xyz[2] = xyz[0]/tan(thetamax);
162       AliL3Transform::Slice2Sector(fSlice,i,sector,row);
163       AliL3Transform::Local2Raw(xyz,sector,row);
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]));
172           xyz[0] = AliL3Transform::Row2X(i);
173           xyz[1] = AliL3Transform::GetMaxY(i);
174           Float_t radii = sqrt(pow(xyz[0],2) + pow(xyz[1],2));
175           xyz[2] = radii/tan(thetamin);
176           AliL3Transform::Local2Raw(xyz,sector,row);
177           fEtaMaxTimeBin[i] = (Int_t)xyz[2];
178         }
179     }
180   
181 }
182
183 Bool_t AliL3MemHandler::SetBinaryInput(char *name)
184 {
185   //Set the input binary file.
186
187   fInBinary = fopen(name,"r");
188   if(!fInBinary){
189     LOG(AliL3Log::kWarning,"AliL3MemHandler::SetBinaryInput","File Open")
190       <<"Error opening file "<<name<<ENDLOG;
191     return kFALSE;
192   }
193   return kTRUE;
194 }
195
196 Bool_t AliL3MemHandler::SetBinaryInput(FILE *file)
197 {
198   //Set the input binary file.
199
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
209 void AliL3MemHandler::CloseBinaryInput()
210 {
211   //Close the input file.
212
213   if(!fInBinary){
214     LOG(AliL3Log::kWarning,"AliL3MemHandler::CloseBinaryInput","File Close")
215       <<"Nothing to Close"<<ENDLOG;
216     return;
217   }
218   fclose(fInBinary);
219   fInBinary =0;
220 }
221
222 Bool_t AliL3MemHandler::SetBinaryOutput(char *name)
223 {
224   //Set the binary output file.
225     fOutBinary = fopen(name,"w");
226   if(!fOutBinary){
227     LOG(AliL3Log::kWarning,"AliL3MemHandler::SetBinaryOutput","File Open")
228       <<"Pointer to File = 0x0 "<<ENDLOG;
229     return kFALSE;
230   }
231   return kTRUE;
232 }
233
234 Bool_t AliL3MemHandler::SetBinaryOutput(FILE *file)
235 {
236   //Set the binary output file.
237   
238   fOutBinary = file;
239   if(!fOutBinary){
240     LOG(AliL3Log::kWarning,"AliL3MemHandler::SetBinaryOutput","File Open")
241       <<"Pointer to File = 0x0 "<<ENDLOG;
242     return kFALSE;
243   }
244   return kTRUE;
245 }
246
247 void AliL3MemHandler::CloseBinaryOutput()
248 {
249   if(!fOutBinary){
250     LOG(AliL3Log::kWarning,"AliL3MemHandler::CloseBinaryOutPut","File Close")
251       <<"Nothing to Close"<<ENDLOG;
252     return;
253   }
254   fclose(fOutBinary);
255   fOutBinary =0;
256 }
257
258 UInt_t AliL3MemHandler::GetFileSize()
259 {
260   //Returns the file size in bytes of the input file.
261   
262   if(!fInBinary){
263     LOG(AliL3Log::kWarning,"AliL3MemHandler::GetFileSize","File")
264       <<"No Input File"<<ENDLOG;
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
273 Byte_t *AliL3MemHandler::Allocate()
274 {
275   return Allocate(GetFileSize()); 
276 }
277
278 Byte_t *AliL3MemHandler::Allocate(AliL3TrackArray *array)
279 {
280   //Allocate memory for tracks in memory. Used by TrackArray2Binary()
281   
282   if(!array){
283     LOG(AliL3Log::kWarning,"AliL3MemHandler::Allocate","Memory")
284       <<"Pointer to AliL3TrackArray = 0x0 "<<ENDLOG;
285     return 0;
286   }
287   return Allocate(array->GetOutSize()); 
288 }
289
290 Byte_t *AliL3MemHandler::Allocate(UInt_t size)
291 {
292   //Allocate memory of size in bytes.
293   
294   if(fPt){
295     LOG(AliL3Log::kWarning,"AliL3MemHandler::Allocate","Memory")
296       <<"Delete Memory"<<ENDLOG;
297     Free();
298   } 
299   fPt = new Byte_t[size];
300   fSize = size;
301   memset(fPt,0,fSize);
302   LOG(AliL3Log::kDebug,"AliL3MemHandler::Allocate","Memory")
303   <<AliL3Log::kDec<<"Allocate "<<size<<" Bytes of Memory"<<ENDLOG;
304   return fPt;
305 }
306
307 void AliL3MemHandler::Free()
308 {
309   //Clear the memory, if allocated.
310   
311   if(!fPt){
312     LOG(AliL3Log::kWarning,"AliL3MemHandler::Free","Memory")
313       <<"No Memory allocated - can't Free"<<ENDLOG;
314     return;
315   }  
316   delete[] fPt;
317   fPt = 0;
318   fSize =0;
319 }
320
321 ///////////////////////////////////////// Random
322 void AliL3MemHandler::SetRandomSeed()
323 {
324   //If you are adding random data to the original data.
325   time_t *tp=0;
326   SetRandomSeed(time(tp));
327 }
328
329 void AliL3MemHandler::SetRandomCluster(Int_t maxnumber)
330 {
331   //If you are adding random data to the original data.
332   
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;
339   fDPt = new AliL3RandomDigitData *[fNRandom*9];
340 }
341
342 void 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];
373       a[j] = tmp;
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    }
383 }
384
385 UInt_t AliL3MemHandler::GetRandomSize()
386 {
387   Int_t nrandom = 0;
388   for(Int_t r=fRowMin;r<=fRowMax;r++){
389     Int_t npad=AliL3Transform::GetNPads(r);
390     nrandom  += Int_t (fNGenerate * ((Double_t) npad/141.));
391   }
392   return 9 * nrandom * sizeof(AliL3DigitData);
393 }
394
395 void AliL3MemHandler::Generate(Int_t row)
396 {
397   //Generate random data on row, if you didn't ask for this, nothing happens here.
398   
399   if(!IsRandom) return;
400   ResetRandom();
401   fNDigits = 0;
402   Int_t npad=AliL3Transform::GetNPads(row);
403   Int_t ntime = fEtaMaxTimeBin[row] - fEtaMinTimeBin[row];
404   Int_t nrandom  = Int_t (fNGenerate * ((Double_t) npad/141.) * 
405                           (Double_t) ntime/(Double_t) AliL3Transform::GetNTimeBins() );
406   
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] );
410     Int_t charge = (int)((float)rand()/RAND_MAX*AliL3Transform::GetADCSat());
411     DigitizePoint(row,pad,time,charge);
412   }
413   QSort(fDPt,0,fNDigits);
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);
417 }
418
419
420 void AliL3MemHandler::DigitizePoint(Int_t row, Int_t pad, 
421                                     Int_t time,Int_t charge)
422 {
423   //Making one single random cluster.
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;
432       
433       if(dpad<0||dpad>=AliL3Transform::GetNPads(row))  continue;
434       if(dtime<0||dtime>=AliL3Transform::GetNTimeBins()) continue;
435       
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  
447 Bool_t AliL3MemHandler::Memory2Binary(UInt_t nrow,AliL3DigitRowData *data)
448 {
449   //Write data to the outputfile as is. No run-length encoding is done.
450   
451   if(!fOutBinary){
452     LOG(AliL3Log::kWarning,"AliL3MemHandler::Memory2Binary","File")
453       <<"No Output File"<<ENDLOG;
454     return kFALSE;
455   }
456   if(!data){
457     LOG(AliL3Log::kWarning,"AliL3MemHandler::Memory2Binary","Memory")
458       <<"Pointer to AliL3DigitRowData = 0x0 "<<ENDLOG;
459     return kFALSE;
460   }
461   
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 
466       + sizeof(AliL3DigitRowData);
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")
474     <<AliL3Log::kDec<<"Wrote "<<outsize<<" Bytes to Memory ("
475     <<nrow<<" Rows)"<<ENDLOG;
476   return kTRUE;
477 }
478
479 Bool_t AliL3MemHandler::Binary2Memory(UInt_t & nrow,AliL3DigitRowData *data)
480 {
481   //Read inputfile into memory as is, and store it in data. No run-length encoding
482   // is assumed.
483
484   if(!fInBinary){
485     LOG(AliL3Log::kWarning,"AliL3MemHandler::Binary2Memory","File")
486       <<"No Input File"<<ENDLOG;
487     return kFALSE;
488   }
489   if(!data){
490     LOG(AliL3Log::kWarning,"AliL3MemHandler::Binary2Memory","Memory")
491       <<"Pointer to AliL3DigitRowData = 0x0 "<<ENDLOG;
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
521 void AliL3MemHandler::AddData(AliL3DigitData *data,UInt_t & ndata,
522                               UInt_t row,UShort_t pad,UShort_t time,UShort_t charge)
523 {
524   data[ndata].fPad = pad;
525   data[ndata].fTime = time;
526   data[ndata].fCharge = charge;
527   ndata++;
528 }
529
530 void AliL3MemHandler::AddRandom(AliL3DigitData *data, UInt_t & ndata)
531 {
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
539 void AliL3MemHandler::MergeDataRandom(AliL3DigitData *data, UInt_t & ndata,
540                                       UInt_t row, UShort_t pad, UShort_t time, UShort_t charge)
541 {
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;
547     if(charge>=AliL3Transform::GetADCSat()) ch = AliL3Transform::GetADCSat();
548     data[ndata].fCharge = ch;
549     fNUsed++;
550   }
551   ndata++;
552 }
553
554 void AliL3MemHandler::AddDataRandom(AliL3DigitData *data, UInt_t & ndata,
555                    UInt_t row, UShort_t pad, UShort_t time, UShort_t charge)
556 {
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
569 void AliL3MemHandler::Write(UInt_t *comp, UInt_t & index, 
570                             UInt_t & subindex, UShort_t value)
571 {
572   UInt_t shift[3] = {0,10,20};
573   if(subindex==0) comp[index] =0; //clean up memory
574   comp[index] |= (value&0x03ff)<<shift[subindex];
575   if(subindex == 2){
576     subindex = 0;
577     index++;
578   }
579   else subindex++;
580 }
581
582 UShort_t AliL3MemHandler::Read(UInt_t *comp, UInt_t & index, UInt_t & subindex)
583 {
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
595 UShort_t AliL3MemHandler::Test(UInt_t *comp, 
596                                UInt_t index, UInt_t  subindex)
597 {
598   UInt_t shift[3] = {0,10,20};
599   return (comp[index]>>shift[subindex])&0x03ff;
600 }
601
602 Int_t AliL3MemHandler::Memory2CompMemory(UInt_t nrow,
603                                          AliL3DigitRowData *data,UInt_t *comp)
604 {
605   //Performs run-length encoding on data stored in memory pointed to by data.
606   //The compressed data is written to comp.
607   if(!comp){
608     LOG(AliL3Log::kWarning,"AliL3MemHandler::Memory2CompMemory","Memory")
609       <<"Pointer to compressed data = 0x0 "<<ENDLOG;
610     return 0;
611   }
612   if(!data){
613     LOG(AliL3Log::kWarning,"AliL3MemHandler::Memory2CompMemory","Memory")
614       <<"Pointer to AliL3DigitRowData = 0x0 "<<ENDLOG;
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;
654         if(charge>=1023){
655           charge=1023;
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     }
672     
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
684 Int_t AliL3MemHandler::CompMemory2Memory(UInt_t  nrow,
685                                          AliL3DigitRowData *data,UInt_t *comp)
686 {
687   //Uncompress the run-length encoded data in memory pointed to by comp, and
688   //  store it in data.
689    
690   if(!comp){
691     LOG(AliL3Log::kWarning,"AliL3MemHandler::CompMemory2Memory","Memory")
692       <<"Pointer to compressed data = 0x0 "<<ENDLOG;
693     return 0;
694   }
695   if(!data){
696     LOG(AliL3Log::kWarning,"AliL3MemHandler::CompMemory2Memory","Memory")
697       <<"Pointer to AliL3DigitRowData = 0x0 "<<ENDLOG;
698     return 0;
699   }
700   Int_t outsize=0;
701   
702   AliL3DigitRowData *row_pt = data;
703   UInt_t index=0;
704   UInt_t subindex=0;
705   
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])
725             //          AddData(row_pt->fDigitData,ndigit,row,pad,time,charge);
726             AddDataRandom(row_pt->fDigitData,ndigit,row,pad,time,charge);
727           time++;
728         }
729         UShort_t tshift = Read(comp,index,subindex);
730         if(tshift == 0) break;
731         time += tshift;
732       }
733     }
734     row_pt->fNDigit = ndigit;
735     Int_t size = sizeof(AliL3DigitData) * row_pt->fNDigit+
736       sizeof(AliL3DigitRowData);
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
745 UInt_t AliL3MemHandler::GetCompMemorySize(UInt_t nrow,AliL3DigitRowData *data)
746 {
747   //Return the size of RLE data, after compressing data.
748   
749   if(!data){
750     LOG(AliL3Log::kWarning,"AliL3MemHandler::GetCompMemorySize","Memory")
751       <<"Pointer to AliL3DigitRowData = 0x0 "<<ENDLOG;
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++;
780       //    write zero if time != 0
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
813 UInt_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
847 UInt_t AliL3MemHandler::GetNRow(UInt_t *comp,UInt_t size)
848 {
849   if(!comp){
850     LOG(AliL3Log::kWarning,"AliL3MemHandler::GetNRow","Memory")
851       <<"Pointer to compressed data = 0x0 "<<ENDLOG;
852     return 0;
853   }
854   size = size /4;
855   UInt_t nrow=0;
856   UInt_t index=0;
857   UInt_t subindex=0;
858   while(index<size-1){ //don't start with last word
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   }
875   if(index==size-1){  //last word
876     if(subindex<2){
877       if(Read(comp,index,subindex)!=0) nrow++;
878     }
879   }
880   return nrow;
881 }
882
883 Bool_t AliL3MemHandler::CompMemory2CompBinary(UInt_t nrow,UInt_t *comp,
884                                               UInt_t size)
885 {
886   //Write the RLE data in comp to the output file.
887   
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
911 Bool_t AliL3MemHandler::CompBinary2CompMemory(UInt_t & nrow,UInt_t *comp)
912 {
913   //Read the RLE data from file, and store it in comp. No unpacking yet.
914
915   if(!fInBinary){
916     LOG(AliL3Log::kWarning,"AliL3MemHandler::CompBinary2CompMemory","File")
917       <<"No Output File"<<ENDLOG;
918     return kFALSE;
919   }
920   if(!comp){
921     LOG(AliL3Log::kWarning,"AliL3MemHandler::CompBinary2CompMemory","Memory")
922       <<"Pointer to compressed data = 0x0 "<<ENDLOG;
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
935 AliL3DigitRowData *AliL3MemHandler::CompBinary2Memory(UInt_t & nrow)
936 {
937   // Read the RLE inputfile, unpack it and return the pointer to it.
938   
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
951 Bool_t AliL3MemHandler::Memory2CompBinary(UInt_t nrow,AliL3DigitRowData *data)
952 {
953   //Perform RLE on the data, and write it to the output file.
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  
967 Bool_t AliL3MemHandler::Memory2Binary(UInt_t npoint,AliL3SpacePointData *data)
968 {
969   //Writing spacepoints stored in data to the outputfile.
970   if(!fOutBinary){
971     LOG(AliL3Log::kWarning,"AliL3MemHandler::Memory2Binary","File")
972       <<"No Output File"<<ENDLOG;
973     return kFALSE;
974   }
975   if(!data){
976     LOG(AliL3Log::kWarning,"AliL3MemHandler::Memory2Binary","Memory")
977       <<"Pointer to AliL3SpacePointData = 0x0 "<<ENDLOG;
978     return kFALSE;
979   }
980   UInt_t size = npoint*sizeof(AliL3SpacePointData);
981   fwrite(data,size,1,fOutBinary);
982   
983   return kTRUE;
984 }
985
986 Bool_t AliL3MemHandler::Transform(UInt_t npoint,AliL3SpacePointData *data,Int_t slice)
987 {
988   //Transform the space points in data, to global coordinates in slice.
989   if(!data){
990     LOG(AliL3Log::kWarning,"AliL3MemHandler::Transform","Memory")
991     <<"Pointer to AliL3SpacePointData = 0x0 "<<ENDLOG;
992     return kFALSE;
993   }
994   
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;
1000     AliL3Transform::Local2Global(xyz,slice);
1001     data[i].fX = xyz[0];
1002     data[i].fY = xyz[1];
1003     data[i].fZ = xyz[2];
1004   }
1005   return kTRUE;
1006 }
1007
1008 Bool_t AliL3MemHandler::Binary2Memory(UInt_t & npoint,AliL3SpacePointData *data)
1009 {
1010   //Read the space points in inputfile, and store it in data.
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  
1075 Bool_t AliL3MemHandler::Memory2Binary(UInt_t ntrack,AliL3TrackSegmentData *data)
1076 {
1077   //Write the tracks stored in data, to outputfile.
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
1102 Bool_t AliL3MemHandler::Binary2Memory(UInt_t & ntrack,AliL3TrackSegmentData *data)
1103 {
1104   //Read the tracks in inputfile, and store it in data.
1105   
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
1169 Bool_t AliL3MemHandler::TrackArray2Binary(AliL3TrackArray *array)
1170 {
1171   //Write the trackarray to the outputfile.
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);
1183
1184   UInt_t ntrack;
1185   TrackArray2Memory(ntrack,data,array);
1186   Memory2Binary(ntrack,data);
1187   Free();
1188   return kTRUE;
1189 }
1190
1191 Bool_t AliL3MemHandler::Binary2TrackArray(AliL3TrackArray *array)
1192 {
1193   //Read the tracks in inputfile, and fill it in trackarray. 
1194   //array should already be constructed.
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
1213 Bool_t AliL3MemHandler::TrackArray2Memory(UInt_t & ntrack,AliL3TrackSegmentData *data,AliL3TrackArray *array)
1214 {
1215   //Fill the trackarray into the AliTrackSegmentData structures before writing to outputfile.
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   }
1226
1227   array->WriteTracks(ntrack,data);
1228   return kTRUE;
1229 }
1230
1231 Bool_t AliL3MemHandler::Memory2TrackArray(UInt_t ntrack,AliL3TrackSegmentData *data,AliL3TrackArray *array)
1232 {
1233   //Fill the tracks in data into trackarray.
1234   
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
1249 Bool_t AliL3MemHandler::Memory2TrackArray(UInt_t ntrack,AliL3TrackSegmentData *data,AliL3TrackArray *array,Int_t slice)
1250 {
1251   //Fill the tracks in data into trackarray, and rotate the tracks to global coordinates.
1252     
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   }
1263   array->FillTracks(ntrack,data,slice);
1264   return kTRUE;
1265 }
1266
1267 void AliL3MemHandler::UpdateRowPointer(AliL3DigitRowData *&tempPt)
1268 {
1269   //Update the data pointer to the next padrow in memory.
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 }