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