More cosmetic
[u/mrichter/AliRoot.git] / HLT / src / AliL3MemHandler.cxx
CommitLineData
a472f00a 1/* $Id$
b661165c 2// Author: Uli Frankenfeld <mailto:franken@fi.uib.no>
a472f00a 3// -- Copyright &copy Uli
4// changes done by Constantin Loizides <mailto:loizides@ikf.physik.uni-frankfurt.de>
5*/
108615fc 6
7#include <math.h>
8#include <time.h>
9#include <iostream.h>
10#include <stdio.h>
d48c6b0b 11#include <string.h>
108615fc 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"
b661165c 21
77732228 22/** \class AliL3MemHandler
d66de409 23//_____________________________________________________________
b661165c 24// AliL3MemHandler
108615fc 25//
d66de409 26// The HLT Binary File handler
108615fc 27//
988340e0 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();
d66de409 71*/
72
dabd5c45 73ClassImp(AliL3MemHandler)
74
8cedc020 75AliL3MemHandler::AliL3MemHandler()
76{
dabd5c45 77 //Constructor
8cedc020 78
108615fc 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
ae97a0b9 93 Int_t row[2] = {0,175};
108615fc 94 Init(0,0,row);
95 ResetROI();
96}
97
98
8cedc020 99AliL3MemHandler::~AliL3MemHandler()
100{
988340e0 101 //Destructor
108615fc 102 if(fPt) delete[] fPt;
103 if(fDigits) delete [] fDigits;
104 if(fDPt) delete [] fDPt;
105}
106
8cedc020 107void AliL3MemHandler::ResetROI()
108{
988340e0 109 //Resets the Look-up table for Region of Interest mode.
8cedc020 110
111 for(Int_t i=fRowMin; i<=fRowMax; i++)
112 {
108615fc 113 fEtaMinTimeBin[i] = 0;
114 fEtaMaxTimeBin[i] = 445;
8cedc020 115 }
108615fc 116}
117
118
8cedc020 119void AliL3MemHandler::SetROI(Float_t *eta,Int_t *slice)
120{
988340e0 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
dabd5c45 128
129
8cedc020 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
108615fc 171}
172
8cedc020 173Bool_t AliL3MemHandler::SetBinaryInput(char *name)
174{
988340e0 175 //Set the input binary file.
176
108615fc 177 fInBinary = fopen(name,"r");
178 if(!fInBinary){
179 LOG(AliL3Log::kWarning,"AliL3MemHandler::SetBinaryInput","File Open")
95a00d93 180 <<"Error opening file "<<name<<ENDLOG;
108615fc 181 return kFALSE;
182 }
183 return kTRUE;
184}
185
8cedc020 186Bool_t AliL3MemHandler::SetBinaryInput(FILE *file)
187{
988340e0 188 //Set the input binary file.
189
108615fc 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
8cedc020 199void AliL3MemHandler::CloseBinaryInput()
200{
988340e0 201 //Close the input file.
202
108615fc 203 if(!fInBinary){
204 LOG(AliL3Log::kWarning,"AliL3MemHandler::CloseBinaryInput","File Close")
8cedc020 205 <<"Nothing to Close"<<ENDLOG;
108615fc 206 return;
207 }
208 fclose(fInBinary);
209 fInBinary =0;
210}
211
8cedc020 212Bool_t AliL3MemHandler::SetBinaryOutput(char *name)
213{
988340e0 214 //Set the binary output file.
108615fc 215 fOutBinary = fopen(name,"w");
216 if(!fOutBinary){
217 LOG(AliL3Log::kWarning,"AliL3MemHandler::SetBinaryOutput","File Open")
8cedc020 218 <<"Pointer to File = 0x0 "<<ENDLOG;
108615fc 219 return kFALSE;
220 }
221 return kTRUE;
222}
223
8cedc020 224Bool_t AliL3MemHandler::SetBinaryOutput(FILE *file)
225{
988340e0 226 //Set the binary output file.
227
108615fc 228 fOutBinary = file;
229 if(!fOutBinary){
230 LOG(AliL3Log::kWarning,"AliL3MemHandler::SetBinaryOutput","File Open")
8cedc020 231 <<"Pointer to File = 0x0 "<<ENDLOG;
108615fc 232 return kFALSE;
233 }
234 return kTRUE;
235}
236
8cedc020 237void AliL3MemHandler::CloseBinaryOutput()
238{
108615fc 239 if(!fOutBinary){
240 LOG(AliL3Log::kWarning,"AliL3MemHandler::CloseBinaryOutPut","File Close")
8cedc020 241 <<"Nothing to Close"<<ENDLOG;
108615fc 242 return;
243 }
244 fclose(fOutBinary);
245 fOutBinary =0;
246}
247
8cedc020 248UInt_t AliL3MemHandler::GetFileSize()
249{
988340e0 250 //Returns the file size in bytes of the input file.
251
108615fc 252 if(!fInBinary){
253 LOG(AliL3Log::kWarning,"AliL3MemHandler::GetFileSize","File")
8cedc020 254 <<"No Input File"<<ENDLOG;
108615fc 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
8cedc020 263Byte_t *AliL3MemHandler::Allocate()
264{
108615fc 265 return Allocate(GetFileSize());
266}
267
8cedc020 268Byte_t *AliL3MemHandler::Allocate(AliL3TrackArray *array)
269{
988340e0 270 //Allocate memory for tracks in memory. Used by TrackArray2Binary()
271
108615fc 272 if(!array){
273 LOG(AliL3Log::kWarning,"AliL3MemHandler::Allocate","Memory")
8cedc020 274 <<"Pointer to AliL3TrackArray = 0x0 "<<ENDLOG;
108615fc 275 return 0;
276 }
277 return Allocate(array->GetOutSize());
278}
279
8cedc020 280Byte_t *AliL3MemHandler::Allocate(UInt_t size)
281{
988340e0 282 //Allocate memory of size in bytes.
283
108615fc 284 if(fPt){
285 LOG(AliL3Log::kWarning,"AliL3MemHandler::Allocate","Memory")
8cedc020 286 <<"Delete Memory"<<ENDLOG;
108615fc 287 Free();
288 }
289 fPt = new Byte_t[size];
290 fSize = size;
d48c6b0b 291 memset(fPt,0,fSize);
108615fc 292 LOG(AliL3Log::kDebug,"AliL3MemHandler::Allocate","Memory")
293 <<AliL3Log::kDec<<"Allocate "<<size<<" Bytes of Memory"<<ENDLOG;
294 return fPt;
295}
296
8cedc020 297void AliL3MemHandler::Free()
298{
988340e0 299 //Clear the memory, if allocated.
300
108615fc 301 if(!fPt){
302 LOG(AliL3Log::kWarning,"AliL3MemHandler::Free","Memory")
8cedc020 303 <<"No Memory allocated - can't Free"<<ENDLOG;
108615fc 304 return;
305 }
306 delete[] fPt;
307 fPt = 0;
308 fSize =0;
309}
310
311///////////////////////////////////////// Random
8cedc020 312void AliL3MemHandler::SetRandomSeed()
313{
988340e0 314 //If you are adding random data to the original data.
108615fc 315 time_t *tp=0;
316 SetRandomSeed(time(tp));
317}
318
8cedc020 319void AliL3MemHandler::SetRandomCluster(Int_t maxnumber)
320{
988340e0 321 //If you are adding random data to the original data.
322
108615fc 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;
ffaac6c0 329 fDPt = new AliL3RandomDigitData *[fNRandom*9];
108615fc 330}
331
a472f00a 332void 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];
108615fc 363 a[j] = tmp;
a472f00a 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 }
108615fc 373}
374
8cedc020 375UInt_t AliL3MemHandler::GetRandomSize()
376{
108615fc 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
8cedc020 385void AliL3MemHandler::Generate(Int_t row)
386{
988340e0 387 //Generate random data on row, if you didn't ask for this, nothing happens here.
388
108615fc 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.) *
8cedc020 395 (Double_t) ntime/(Double_t) fTransformer->GetNTimeBins() );
396
108615fc 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);
8cedc020 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);
108615fc 407}
408
409
410void AliL3MemHandler::DigitizePoint(Int_t row, Int_t pad,
8cedc020 411 Int_t time,Int_t charge)
412{
988340e0 413 //Making one single random cluster.
108615fc 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;
8cedc020 422
108615fc 423 if(dpad<0||dpad>=fTransformer->GetNPads(row)) continue;
424 if(dtime<0||dtime>=fTransformer->GetNTimeBins()) continue;
8cedc020 425
108615fc 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
8cedc020 437Bool_t AliL3MemHandler::Memory2Binary(UInt_t nrow,AliL3DigitRowData *data)
438{
988340e0 439 //Write data to the outputfile as is. No run-length encoding is done.
8cedc020 440
108615fc 441 if(!fOutBinary){
442 LOG(AliL3Log::kWarning,"AliL3MemHandler::Memory2Binary","File")
8cedc020 443 <<"No Output File"<<ENDLOG;
108615fc 444 return kFALSE;
445 }
446 if(!data){
447 LOG(AliL3Log::kWarning,"AliL3MemHandler::Memory2Binary","Memory")
8cedc020 448 <<"Pointer to AliL3DigitRowData = 0x0 "<<ENDLOG;
108615fc 449 return kFALSE;
450 }
8cedc020 451
108615fc 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
8cedc020 456 + sizeof(AliL3DigitRowData);
108615fc 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")
8cedc020 464 <<AliL3Log::kDec<<"Wrote "<<outsize<<" Bytes to Memory ("
465 <<nrow<<" Rows)"<<ENDLOG;
108615fc 466 return kTRUE;
467}
468
8cedc020 469Bool_t AliL3MemHandler::Binary2Memory(UInt_t & nrow,AliL3DigitRowData *data)
470{
988340e0 471 //Read inputfile into memory as is, and store it in data. No run-length encoding
472 // is assumed.
473
108615fc 474 if(!fInBinary){
475 LOG(AliL3Log::kWarning,"AliL3MemHandler::Binary2Memory","File")
8cedc020 476 <<"No Input File"<<ENDLOG;
108615fc 477 return kFALSE;
478 }
479 if(!data){
480 LOG(AliL3Log::kWarning,"AliL3MemHandler::Binary2Memory","Memory")
8cedc020 481 <<"Pointer to AliL3DigitRowData = 0x0 "<<ENDLOG;
108615fc 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
511void AliL3MemHandler::AddData(AliL3DigitData *data,UInt_t & ndata,
8cedc020 512 UInt_t row,UShort_t pad,UShort_t time,UShort_t charge)
513{
108615fc 514 data[ndata].fPad = pad;
515 data[ndata].fTime = time;
516 data[ndata].fCharge = charge;
517 ndata++;
518}
519
8cedc020 520void AliL3MemHandler::AddRandom(AliL3DigitData *data, UInt_t & ndata)
521{
108615fc 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
529void AliL3MemHandler::MergeDataRandom(AliL3DigitData *data, UInt_t & ndata,
8cedc020 530 UInt_t row, UShort_t pad, UShort_t time, UShort_t charge)
531{
108615fc 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
544void AliL3MemHandler::AddDataRandom(AliL3DigitData *data, UInt_t & ndata,
8cedc020 545 UInt_t row, UShort_t pad, UShort_t time, UShort_t charge)
546{
108615fc 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
559void AliL3MemHandler::Write(UInt_t *comp, UInt_t & index,
8cedc020 560 UInt_t & subindex, UShort_t value)
561{
108615fc 562 UInt_t shift[3] = {0,10,20};
b00ff616 563 if(subindex==0) comp[index] =0; //clean up memory
108615fc 564 comp[index] |= (value&0x03ff)<<shift[subindex];
565 if(subindex == 2){
566 subindex = 0;
567 index++;
568 }
569 else subindex++;
570}
571
8cedc020 572UShort_t AliL3MemHandler::Read(UInt_t *comp, UInt_t & index, UInt_t & subindex)
573{
108615fc 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
585UShort_t AliL3MemHandler::Test(UInt_t *comp,
8cedc020 586 UInt_t index, UInt_t subindex)
587{
108615fc 588 UInt_t shift[3] = {0,10,20};
589 return (comp[index]>>shift[subindex])&0x03ff;
590}
591
592Int_t AliL3MemHandler::Memory2CompMemory(UInt_t nrow,
8cedc020 593 AliL3DigitRowData *data,UInt_t *comp)
594{
988340e0 595 //Performs run-length encoding on data stored in memory pointed to by data.
596 //The compressed data is written to comp.
108615fc 597 if(!comp){
598 LOG(AliL3Log::kWarning,"AliL3MemHandler::Memory2CompMemory","Memory")
8cedc020 599 <<"Pointer to compressed data = 0x0 "<<ENDLOG;
108615fc 600 return 0;
601 }
602 if(!data){
603 LOG(AliL3Log::kWarning,"AliL3MemHandler::Memory2CompMemory","Memory")
8cedc020 604 <<"Pointer to AliL3DigitRowData = 0x0 "<<ENDLOG;
108615fc 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
674Int_t AliL3MemHandler::CompMemory2Memory(UInt_t nrow,
8cedc020 675 AliL3DigitRowData *data,UInt_t *comp)
676{
988340e0 677 //Uncompress the run-length encoded data in memory pointed to by comp, and
678 // store it in data.
679
108615fc 680 if(!comp){
681 LOG(AliL3Log::kWarning,"AliL3MemHandler::CompMemory2Memory","Memory")
8cedc020 682 <<"Pointer to compressed data = 0x0 "<<ENDLOG;
108615fc 683 return 0;
684 }
685 if(!data){
686 LOG(AliL3Log::kWarning,"AliL3MemHandler::CompMemory2Memory","Memory")
8cedc020 687 <<"Pointer to AliL3DigitRowData = 0x0 "<<ENDLOG;
108615fc 688 return 0;
689 }
690 Int_t outsize=0;
8cedc020 691
108615fc 692 AliL3DigitRowData *row_pt = data;
693 UInt_t index=0;
694 UInt_t subindex=0;
8cedc020 695
108615fc 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])
8cedc020 715 // AddData(row_pt->fDigitData,ndigit,row,pad,time,charge);
108615fc 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+
8cedc020 726 sizeof(AliL3DigitRowData);
108615fc 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
8cedc020 735UInt_t AliL3MemHandler::GetCompMemorySize(UInt_t nrow,AliL3DigitRowData *data)
736{
988340e0 737 //Return the size of RLE data, after compressing data.
738
108615fc 739 if(!data){
740 LOG(AliL3Log::kWarning,"AliL3MemHandler::GetCompMemorySize","Memory")
8cedc020 741 <<"Pointer to AliL3DigitRowData = 0x0 "<<ENDLOG;
108615fc 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++;
8cedc020 770 // write zero if time != 0
108615fc 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
803UInt_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
8cedc020 837UInt_t AliL3MemHandler::GetNRow(UInt_t *comp,UInt_t size)
838{
108615fc 839 if(!comp){
840 LOG(AliL3Log::kWarning,"AliL3MemHandler::GetNRow","Memory")
8cedc020 841 <<"Pointer to compressed data = 0x0 "<<ENDLOG;
108615fc 842 return 0;
843 }
844 size = size /4;
845 UInt_t nrow=0;
846 UInt_t index=0;
847 UInt_t subindex=0;
b00ff616 848 while(index<size-1){ //don't start with last word
108615fc 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 }
b00ff616 865 if(index==size-1){ //last word
866 if(subindex<2){
867 if(Read(comp,index,subindex)!=0) nrow++;
868 }
869 }
108615fc 870 return nrow;
871}
872
873Bool_t AliL3MemHandler::CompMemory2CompBinary(UInt_t nrow,UInt_t *comp,
8cedc020 874 UInt_t size)
875{
988340e0 876 //Write the RLE data in comp to the output file.
8cedc020 877
108615fc 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
8cedc020 901Bool_t AliL3MemHandler::CompBinary2CompMemory(UInt_t & nrow,UInt_t *comp)
902{
988340e0 903 //Read the RLE data from file, and store it in comp. No unpacking yet.
904
108615fc 905 if(!fInBinary){
906 LOG(AliL3Log::kWarning,"AliL3MemHandler::CompBinary2CompMemory","File")
8cedc020 907 <<"No Output File"<<ENDLOG;
108615fc 908 return kFALSE;
909 }
910 if(!comp){
911 LOG(AliL3Log::kWarning,"AliL3MemHandler::CompBinary2CompMemory","Memory")
8cedc020 912 <<"Pointer to compressed data = 0x0 "<<ENDLOG;
108615fc 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
8cedc020 925AliL3DigitRowData *AliL3MemHandler::CompBinary2Memory(UInt_t & nrow)
926{
988340e0 927 // Read the RLE inputfile, unpack it and return the pointer to it.
928
108615fc 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
8cedc020 941Bool_t AliL3MemHandler::Memory2CompBinary(UInt_t nrow,AliL3DigitRowData *data)
942{
988340e0 943 //Perform RLE on the data, and write it to the output file.
108615fc 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
8cedc020 957Bool_t AliL3MemHandler::Memory2Binary(UInt_t npoint,AliL3SpacePointData *data)
958{
988340e0 959 //Writing spacepoints stored in data to the outputfile.
108615fc 960 if(!fOutBinary){
961 LOG(AliL3Log::kWarning,"AliL3MemHandler::Memory2Binary","File")
8cedc020 962 <<"No Output File"<<ENDLOG;
108615fc 963 return kFALSE;
964 }
965 if(!data){
966 LOG(AliL3Log::kWarning,"AliL3MemHandler::Memory2Binary","Memory")
8cedc020 967 <<"Pointer to AliL3SpacePointData = 0x0 "<<ENDLOG;
108615fc 968 return kFALSE;
969 }
970 UInt_t size = npoint*sizeof(AliL3SpacePointData);
971 fwrite(data,size,1,fOutBinary);
8cedc020 972
108615fc 973 return kTRUE;
974}
975
976Bool_t AliL3MemHandler::Transform(UInt_t npoint,AliL3SpacePointData *data,
8cedc020 977 Int_t slice, AliL3Transform* trans)
978{
988340e0 979 //Transform the space points in data, to global coordinates in slice.
108615fc 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
8cedc020 1003Bool_t AliL3MemHandler::Binary2Memory(UInt_t & npoint,AliL3SpacePointData *data)
1004{
988340e0 1005 //Read the space points in inputfile, and store it in data.
108615fc 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
8cedc020 1070Bool_t AliL3MemHandler::Memory2Binary(UInt_t ntrack,AliL3TrackSegmentData *data)
1071{
988340e0 1072 //Write the tracks stored in data, to outputfile.
108615fc 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
8cedc020 1097Bool_t AliL3MemHandler::Binary2Memory(UInt_t & ntrack,AliL3TrackSegmentData *data)
1098{
988340e0 1099 //Read the tracks in inputfile, and store it in data.
1100
108615fc 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
8cedc020 1164Bool_t AliL3MemHandler::TrackArray2Binary(AliL3TrackArray *array)
1165{
988340e0 1166 //Write the trackarray to the outputfile.
108615fc 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
8cedc020 1185Bool_t AliL3MemHandler::Binary2TrackArray(AliL3TrackArray *array)
1186{
988340e0 1187 //Read the tracks in inputfile, and fill it in trackarray.
1188 //array should already be constructed.
108615fc 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
8cedc020 1207Bool_t AliL3MemHandler::TrackArray2Memory(UInt_t & ntrack,AliL3TrackSegmentData *data,AliL3TrackArray *array)
1208{
988340e0 1209 //Fill the trackarray into the AliTrackSegmentData structures before writing to outputfile.
108615fc 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
8cedc020 1224Bool_t AliL3MemHandler::Memory2TrackArray(UInt_t ntrack,AliL3TrackSegmentData *data,AliL3TrackArray *array)
1225{
988340e0 1226 //Fill the tracks in data into trackarray.
1227
108615fc 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
8cedc020 1242Bool_t AliL3MemHandler::Memory2TrackArray(UInt_t ntrack,AliL3TrackSegmentData *data,AliL3TrackArray *array,Int_t slice,
1243 AliL3Transform* trans)
1244{
988340e0 1245 //Fill the tracks in data into trackarray, and rotate the tracks to global coordinates.
1246
108615fc 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
9bd4d591 1266void AliL3MemHandler::UpdateRowPointer(AliL3DigitRowData *&tempPt)
1267{
8cedc020 1268 //Update the data pointer to the next padrow in memory.
9bd4d591 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}