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