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