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