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