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