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