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