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