Changed test in AliDigits2RootFile to check for charge below threshold, not charge...
[u/mrichter/AliRoot.git] / HLT / comp / AliL3Compress.cxx
CommitLineData
5bf93292 1//$Id$
2
3// Author: Anders Vestbo <mailto:vestbo$fi.uib.no>
4//*-- Copyright &copy ASV
5
6#include <stdio.h>
7#include <stream.h>
8#include <stdlib.h>
029912b7 9#include <TH1.h>
10#include <TH2.h>
11#include <TRandom.h>
5bf93292 12
13#include "AliL3Compress.h"
14#include "AliL3TrackArray.h"
15#include "AliL3ModelTrack.h"
029912b7 16#include "AliL3Transform.h"
17#include "AliL3MemHandler.h"
be6ddb10 18#include "AliL3FileHandler.h"
5bf93292 19#include "bitio.h"
20
029912b7 21//_____________________________________________________________
22//
23// AliL3Compress
24//
25// Class for compressing and uncompressing data.
26
5bf93292 27ClassImp(AliL3Compress)
28
29AliL3Compress::AliL3Compress()
30{
95a00d93 31 fTracks=0;
be6ddb10 32 SetBitNumbers(0,0,0,0);
029912b7 33 fSlice =0;
34 fPatch=0;
35 fDigits=0;
36 fDPt=0;
37}
38
be6ddb10 39AliL3Compress::AliL3Compress(Int_t slice,Int_t patch,Char_t *path)
029912b7 40{
41 fSlice=slice;
42 fPatch=patch;
be6ddb10 43 SetBitNumbers(0,0,0,0);
029912b7 44 fTracks=0;
45 fDigits=0;
46 fDPt=0;
be6ddb10 47 sprintf(fPath,"%s",path);
5bf93292 48}
49
50AliL3Compress::~AliL3Compress()
51{
95a00d93 52 if(fTracks)
53 delete fTracks;
029912b7 54 if(fDigits)
55 delete [] fDigits;
56 if(fDPt)
57 delete [] fDPt;
58}
59
60void AliL3Compress::SetBitNumbers(Int_t pad,Int_t time,Int_t charge,Int_t shape)
61{
62 fNumPadBits=pad;
63 fNumTimeBits=time;
64 fNumChargeBits=charge;
65 fNumShapeBits=shape;
5bf93292 66}
67
be6ddb10 68void AliL3Compress::WriteFile(AliL3TrackArray *tracks)
5bf93292 69{
be6ddb10 70 Char_t fname[100];
71 sprintf(fname,"%s/tracks_m_%d_%d.raw",fPath,fSlice,fPatch);
72 FILE *file = fopen(fname,"w");
5bf93292 73 Short_t ntracks = tracks->GetNTracks();
95a00d93 74 //cout<<"Writing "<<ntracks<<" tracks to file"<<endl;
75
76 Int_t count=0;
77 AliL3ClusterModel *clusters=0;
78 AliL3TrackModel *model=0;
5bf93292 79 for(Int_t i=0; i<ntracks; i++)
80 {
81 AliL3ModelTrack *track = (AliL3ModelTrack*)tracks->GetCheckedTrack(i);
82 if(!track) continue;
029912b7 83
84 track->FillModel();
95a00d93 85 model = track->GetModel();
86 if(model->fNClusters==0) continue;
87 clusters = track->GetClusters();
88 //cout<<"Writing "<<(int)model->fNClusters<<" clusters"<<endl;
5bf93292 89 if(fwrite(model,sizeof(AliL3TrackModel),1,file)!=1) break;
95a00d93 90 //cout<<"Writing "<<(int)model->fNClusters<<" clusters to file"<<endl;
91 if(fwrite(clusters,model->fNClusters*sizeof(AliL3ClusterModel),1,file)!=1) break;
029912b7 92 //track->Print();
95a00d93 93 count++;
029912b7 94
5bf93292 95 }
95a00d93 96 cout<<"Wrote "<<count<<" tracks "<<endl;
5bf93292 97 fclose(file);
98}
99
be6ddb10 100void AliL3Compress::ReadFile(Char_t which)
5bf93292 101{
be6ddb10 102 //Read the trackfile.
103
104 Char_t fname[100];
105 if(which == 'm')
106 sprintf(fname,"%s/tracks_m_%d_%d.raw",fPath,fSlice,fPatch);
107 else if(which == 'u')
108 sprintf(fname,"%s/tracks_u_%d_%d.raw",fPath,fSlice,fPatch);
109 else
110 {
111 cerr<<"AliL3Compress::ReadFile() : Wrong option"<<endl;
112 return;
113 }
114
115 FILE *file = fopen(fname,"r");
029912b7 116 if(!file)
117 {
be6ddb10 118 cerr<<"Cannot open file "<<fname<<endl;
029912b7 119 return;
120 }
121
95a00d93 122 if(fTracks)
123 delete fTracks;
124 fTracks = new AliL3TrackArray("AliL3ModelTrack");
5bf93292 125
be6ddb10 126 cout<<"Reading file "<<fname<<endl;
5bf93292 127 while(!feof(file))
128 {
95a00d93 129 AliL3ModelTrack *track = (AliL3ModelTrack*)fTracks->NextTrack();
029912b7 130 track->Init(fSlice,fPatch);
5bf93292 131 AliL3TrackModel *model = track->GetModel();
132 AliL3ClusterModel *clusters = track->GetClusters();
029912b7 133 //cout<<"Reading model "<<(int)model<<endl;
5bf93292 134 if(fread(model,sizeof(AliL3TrackModel),1,file)!=1) break;
029912b7 135 //cout<<"Reading clusters "<<(int)clusters<<endl;
5bf93292 136 if(fread(clusters,(model->fNClusters)*sizeof(AliL3ClusterModel),1,file)!=1) break;
029912b7 137 //cout<<"Filling track"<<endl;
138 track->FillTrack();
139 //track->Print();
5bf93292 140 }
029912b7 141
142 fTracks->RemoveLast();
95a00d93 143 cout<<"Read "<<fTracks->GetNTracks()<<" tracks from file"<<endl;
5bf93292 144 fclose(file);
145}
146
be6ddb10 147void AliL3Compress::CompressFile()
5bf93292 148{
be6ddb10 149 if(fNumTimeBits==0)
150 {
151 cerr<<"AliL3Compress::CompressFile() : Bitnumbers not set"<<endl;
152 return;
153 }
5bf93292 154
be6ddb10 155 Char_t fname[100];
156 sprintf(fname,"%s/tracks_c_%d_%d.raw",fPath,fSlice,fPatch);
157 BIT_FILE *output = OpenOutputBitFile(fname);
158
159 sprintf(fname,"%s/tracks_m_%d_%d.raw",fPath,fSlice,fPatch);
160 FILE *input = fopen(fname,"r");
161 if(!input)
162 {
163 cerr<<"AliL3Compress::CompressFile() : Error opening file: "<<fname<<endl;
164 return;
165 }
5bf93292 166
167 AliL3TrackModel track;
168 AliL3ClusterModel cluster;
169 Int_t temp;
029912b7 170 Short_t power;
171
172 Int_t timeo,pado,chargeo,shapeo;
173 timeo=pado=chargeo=shapeo=0;
5bf93292 174 while(!feof(input))
175 {
176 if(fread(&track,sizeof(AliL3TrackModel),1,input)!=1) break;
95a00d93 177
178 if(output->mask != 0x80) //Write the current byte to file.
179 {
180 if(putc(output->rack,output->file )!=output->rack)
181 cerr<<"AliL3Compress::ComressFile : Error writing to bitfile"<<endl;
182 output->mask=0x80;
029912b7 183 output->rack=0;
95a00d93 184 }
029912b7 185
186 //Write track parameters:
5bf93292 187 fwrite(&track,sizeof(AliL3TrackModel),1,output->file);
5bf93292 188 for(Int_t i=0; i<track.fNClusters; i++)
189 {
190 if(fread(&cluster,sizeof(AliL3ClusterModel),1,input)!=1) break;
029912b7 191
192 //Write empty flag:
193 temp = (Int_t)cluster.fPresent;
194 OutputBit(output,temp);
195 if(!temp) continue;
196
197 //Write time information:
5bf93292 198 temp = (Int_t)cluster.fDTime;
199 if(temp<0)
200 OutputBit(output,0);
201 else
202 OutputBit(output,1);
029912b7 203 power = 1<<fNumTimeBits;
204 if(abs(temp)>=power)
205 {
206 timeo++;
207 temp=power - 1;
208 }
209 OutputBits(output,abs(temp),fNumTimeBits);
210
211 //Write pad information:
5bf93292 212 temp = (Int_t)cluster.fDPad;
213 if(temp<0)
214 OutputBit(output,0);
215 else
216 OutputBit(output,1);
029912b7 217 power = 1<<fNumPadBits;
218 if(abs(temp)>=power)
219 {
220 pado++;
221 temp=power - 1;
222 }
223 OutputBits(output,abs(temp),fNumPadBits);
224
225 //Write charge information:
5bf93292 226 temp = (Int_t)cluster.fDCharge;
029912b7 227 if(temp<0)
228 OutputBit(output,0);
229 else
230 OutputBit(output,1);
231 power = 1<<fNumChargeBits;
232 if(abs(temp)>=power)
233 {
234 chargeo++;
235 temp=power - 1;
236 }
237 OutputBits(output,abs(temp),fNumChargeBits);
5bf93292 238
029912b7 239 //Write shape information:
240 temp = (Int_t)cluster.fDSigmaY2;
241 power = 1<<fNumShapeBits;
242 if(abs(temp) >= power)
243 {
244 shapeo++;
245 temp = power - 1;
246 }
247 OutputBits(output,abs(temp),fNumShapeBits);
248
249 temp = (Int_t)cluster.fDSigmaZ2;
250 if(abs(temp) >= power)
251 {
252 shapeo++;
253 temp=power - 1;
254 }
255 OutputBits(output,abs(temp),fNumShapeBits);
5bf93292 256 }
5bf93292 257 }
95a00d93 258
5bf93292 259 fclose(input);
260 CloseOutputBitFile(output);
029912b7 261
262 cout<<endl<<"There was following number of overflows: "<<endl
263 <<"Pad "<<pado<<endl
264 <<"Time "<<timeo<<endl
265 <<"Charge "<<chargeo<<endl
266 <<"Shape "<<shapeo<<endl;
5bf93292 267}
268
be6ddb10 269void AliL3Compress::ExpandFile()
5bf93292 270{
be6ddb10 271 if(fNumTimeBits==0)
272 {
273 cerr<<"AliL3Compress::ExpandFile() : Bitnumbers not set"<<endl;
274 return;
275 }
276
277 Char_t fname[100];
278 sprintf(fname,"%s/tracks_c_%d_%d.raw",fPath,fSlice,fPatch);
279 BIT_FILE *input = OpenInputBitFile(fname);
280
281 sprintf(fname,"%s/tracks_u_%d_%d.raw",fPath,fSlice,fPatch);
282 FILE *output = fopen(fname,"w");
283 if(!output)
284 {
285 cerr<<"AliL3Compress::ExpandFile() : Error opening file: "<<fname<<endl;
286 return;
287 }
95a00d93 288
289 AliL3TrackModel trackmodel;
290 AliL3ClusterModel *clusters=0;
029912b7 291 Int_t count=0;
5bf93292 292
029912b7 293 clusters = new AliL3ClusterModel[(NumRows[fPatch])];
95a00d93 294 while(!feof(input->file))
5bf93292 295 {
029912b7 296 input->mask=0x80;//make sure we read a new byte from file.
95a00d93 297
029912b7 298 //Read and write track:
95a00d93 299 if(fread(&trackmodel,sizeof(AliL3TrackModel),1,input->file)!=1) break;
300 fwrite(&trackmodel,sizeof(AliL3TrackModel),1,output);
029912b7 301
302 for(Int_t i=0; i<NumRows[fPatch]; i++)
95a00d93 303 {
304 Int_t temp,sign;
029912b7 305
306 //Read empty flag:
95a00d93 307 temp = InputBit(input);
308 if(!temp)
309 {
310 clusters[i].fPresent=kFALSE;
311 continue;
312 }
313 clusters[i].fPresent=kTRUE;
029912b7 314
315 //Read time information:
95a00d93 316 sign=InputBit(input);
029912b7 317 temp = InputBits(input,fNumTimeBits);
95a00d93 318 if(!sign)
319 temp*=-1;
320 clusters[i].fDTime = temp;
029912b7 321
322 //Read pad information:
95a00d93 323 sign=InputBit(input);
029912b7 324 temp = InputBits(input,fNumPadBits);
95a00d93 325 if(!sign)
326 temp*=-1;
327 clusters[i].fDPad = temp;
029912b7 328
329 //Read charge information:
330 sign = InputBit(input);
331 temp=InputBits(input,fNumChargeBits);
332 if(!sign)
333 temp*=-1;
95a00d93 334 clusters[i].fDCharge = temp;
029912b7 335
336 //Read shape information:
337 temp = InputBits(input,fNumShapeBits);
338 clusters[i].fDSigmaY2 = temp;
339
340 temp = InputBits(input,fNumShapeBits);
341 clusters[i].fDSigmaZ2 = temp;
95a00d93 342 }
029912b7 343
344
345 count++;
95a00d93 346 fwrite(clusters,(trackmodel.fNClusters)*sizeof(AliL3ClusterModel),1,output);
029912b7 347
5bf93292 348 }
029912b7 349
350 delete [] clusters;
95a00d93 351 fclose(output);
5bf93292 352 CloseInputBitFile(input);
353}
029912b7 354
355void AliL3Compress::CreateDigitArray(Int_t maxnumber)
356{
357 fNUsed=0;
358 fNDigits = 0;
359 fMaxDigits=maxnumber;
360 if(fDigits) delete [] fDigits;
361 fDigits = new AliL3RandomDigitData[maxnumber];
362 if(fDPt) delete [] fDPt;
363 fDPt = new AliL3RandomDigitData*[maxnumber];
364}
365
be6ddb10 366void AliL3Compress::RestoreData()
029912b7 367{
368
369 //Read the uncompressed file:
be6ddb10 370 ReadFile('u');
029912b7 371
372 CreateDigitArray(100000);
373
374 Float_t pad,time,sigmaY2,sigmaZ2;
375 Int_t charge;
376 for(Int_t j=NRows[fPatch][0]; j<=NRows[fPatch][1]; j++)
377 {
378 for(Int_t i=0; i<fTracks->GetNTracks(); i++)
379 {
380 AliL3ModelTrack *track = (AliL3ModelTrack*)fTracks->GetCheckedTrack(i);
381 if(!track) continue;
382 if(!track->GetPad(j,pad) ||
383 !track->GetTime(j,time) ||
384 !track->GetClusterCharge(j,charge) ||
385 !track->GetXYWidth(j,sigmaY2) ||
386 !track->GetZWidth(j,sigmaZ2))
387 continue;
388
389 CreateDigits(j,pad,time,charge,sigmaY2,sigmaZ2);
390 }
391 }
392
393 QSort(fDPt,0,fNDigits);
394}
395
396void AliL3Compress::PrintDigits()
397{
398 Int_t pad,time,charge,row;
399 for(Int_t i=0; i<fNDigits; i++)
400 {
401 row = fDPt[i]->fRow;
402 pad = fDPt[i]->fPad;
403 time = fDPt[i]->fTime;
404 charge = fDPt[i]->fCharge;
405 if(i>0 && row != fDPt[i-1]->fRow)
406 cout<<"---Padrow "<<row<<"---"<<endl;
407 cout<<"Pad "<<pad<<" time "<<time<<" charge "<<charge<<endl;
408 }
409}
410
be6ddb10 411void AliL3Compress::WriteRestoredData()
029912b7 412{
be6ddb10 413 Char_t fname[100];
414
029912b7 415 //Get the remaining raw data array:
416 AliL3MemHandler *mem = new AliL3MemHandler();
be6ddb10 417 sprintf(fname,"%s/remains_%d_%d.raw",fPath,fSlice,fPatch);
418 mem->SetBinaryInput(fname);
029912b7 419 UInt_t numdigits;
420 AliL3DigitRowData *origRow = mem->CompBinary2Memory(numdigits);
421 mem->CloseBinaryInput();
422
423 //Allocate memory for the merged data:
424 UInt_t size = mem->GetAllocatedSize() + fNDigits*sizeof(AliL3DigitData);
be6ddb10 425 cout<<"Allocating "<<size<<" bytes for merged data array "<<endl;
029912b7 426 Byte_t *data = new Byte_t[size];
427 memset(data,0,size);
428 AliL3DigitRowData *tempRow = (AliL3DigitRowData*)data;
429
430 Int_t ndigits,action,charge;
431 UShort_t pad,time;
be6ddb10 432
433 UInt_t digit_counter;
434 Int_t row_counter=0;
029912b7 435 for(Int_t i=NRows[fPatch][0]; i<=NRows[fPatch][1]; i++)
436 {
437 tempRow->fRow = i;
438 ndigits=0;
439 AliL3DigitData *origDig = origRow->fDigitData;
440 AliL3DigitData *tempDig = tempRow->fDigitData;
be6ddb10 441 if((Int_t)origRow->fRow != i)
442 cerr<<"AliL3Compress::WriteRestoredData() : Mismatching row numbering "<<(Int_t)origRow->fRow<<" "<<i<<endl;
443
444 //cout<<"Writing row "<<i<<" with "<<(Int_t)origRow->fNDigit<<" old digits"<<endl;
445 digit_counter=0;
029912b7 446
447 while(1)
448 {
be6ddb10 449 while(digit_counter < origRow->fNDigit)
029912b7 450 {
be6ddb10 451 pad = origDig[digit_counter].fPad;
452 time = origDig[digit_counter].fTime;
453 charge = origDig[digit_counter].fCharge;
454 digit_counter++;
029912b7 455 while((action=ComparePoints(i,pad,time)) == 1)
456 {
457 tempDig[ndigits].fPad = fDPt[fNUsed]->fPad;
458 tempDig[ndigits].fTime = fDPt[fNUsed]->fTime;
459 tempDig[ndigits].fCharge = fDPt[fNUsed]->fCharge;
460 ndigits++;
461 fNUsed++;
be6ddb10 462
029912b7 463 }
464 if(action == 0)
465 {
466 tempDig[ndigits].fPad = pad;
467 tempDig[ndigits].fTime = time;
468 tempDig[ndigits].fCharge = charge;
469 ndigits++;
470 }
471 }
be6ddb10 472
473 if(fNUsed >= fNDigits)
474 break;
029912b7 475 if(fDPt[fNUsed]->fRow != i) //we are on a new row
476 break;
477 tempDig[ndigits].fPad = fDPt[fNUsed]->fPad;
478 tempDig[ndigits].fTime = fDPt[fNUsed]->fTime;
479 tempDig[ndigits].fCharge = fDPt[fNUsed]->fCharge;
480 ndigits++;
481 fNUsed++;
482 }
be6ddb10 483 //cout<<"Writing "<<ndigits<<" digits on row "<<i<<endl;
484 if(ndigits < 4)
485 {
486 row_counter++;
487 cout<<"Few digits on row "<<i<<endl;
488 }
029912b7 489 tempRow->fNDigit = ndigits;
490 Int_t size = sizeof(AliL3DigitData)*tempRow->fNDigit + sizeof(AliL3DigitRowData);
491 Byte_t *byte_pt = (Byte_t*)tempRow;
492 byte_pt += size;
493 tempRow = (AliL3DigitRowData*)byte_pt;
494 mem->UpdateRowPointer(origRow);
495 }
496
be6ddb10 497 if(row_counter != NumRows[fPatch])
498 cerr<<"AliL3Compress::WriteRestoredData() : Written rows: "<<row_counter<<" total rows "<<NumRows[fPatch]<<endl;
499
500 mem->Free();
501 sprintf(fname,"%s/restored_%d_%d.raw",fPath,fSlice,fPatch);
502 mem->SetBinaryOutput(fname);
029912b7 503 mem->Memory2CompBinary((UInt_t)NumRows[fPatch],(AliL3DigitRowData*)data);
504 mem->CloseBinaryOutput();
505
506 delete [] data;
507 delete mem;
be6ddb10 508
029912b7 509}
510
511void AliL3Compress::CreateDigits(Int_t row,Float_t pad,Float_t time,Int_t charge,Float_t sigmaY2,Float_t sigmaZ2)
512{
513 //Create raw data out of the cluster.
514
515 AliL3Transform *tr = new AliL3Transform();
516 TRandom *random = new TRandom();
517
518 Int_t entries=10000;
519 TH1F *hist1 = new TH1F("hist1","",tr->GetNPads(row),0,tr->GetNPads(row)-1);
520 TH1F *hist2 = new TH1F("hist2","",tr->GetNTimeBins(),0,tr->GetNTimeBins()-1);
521 TH2F *hist3 = new TH2F("hist3","",tr->GetNPads(row),0,tr->GetNPads(row)-1,tr->GetNTimeBins(),0,tr->GetNTimeBins()-1);
522
523 //Convert back the sigmas:
524 Float_t padw,timew;
525 if(fPatch < 3)
526 padw = tr->GetPadPitchWidthLow();
527 else
528 padw = tr->GetPadPitchWidthUp();
529 timew = tr->GetZWidth();
530
531 if(fPatch < 3)
532 sigmaY2 = sigmaY2/2.07;
533 sigmaY2 = sigmaY2/0.108;
534 sigmaY2 = sigmaY2/(padw*padw);
535 sigmaY2 = sigmaY2 - 1./12;
536
537 if(fPatch < 3)
538 sigmaZ2 = sigmaZ2/1.77;
539 sigmaZ2 = sigmaZ2/0.169;
540 sigmaZ2 = sigmaZ2/(timew*timew);
541 sigmaZ2 = sigmaZ2 - 1./12;
542
543 if(sigmaY2 <= 0 || sigmaZ2 <= 0)
544 {
545 cerr<<"AliL3Compress::CreateDigits() : Wrong sigmas : "<<sigmaY2<<" "<<sigmaZ2<<endl;
546 return;
547 }
548
549 //Create the distributions in pad and time:
550 for(Int_t i=0; i<entries; i++)
551 {
552 hist1->Fill(random->Gaus(pad,sqrt(sigmaY2)));
553 hist2->Fill(random->Gaus(time,sqrt(sigmaZ2)));
554 }
555
556 //Create the cluster:
557 Int_t bin1,bin2;
558 Double_t content1,content2,dpad,dtime;
559 for(Int_t i=0; i<hist1->GetEntries(); i++)
560 {
561 bin1 = hist1->GetBin(i);
562 content1 = hist1->GetBinContent(bin1);
563 if((Int_t)content1==0) continue;
564 content1 = charge*content1/entries;
565 dpad = hist1->GetBinCenter(bin1);
566 for(Int_t j=0; j<hist2->GetEntries(); j++)
567 {
568 bin2 = hist2->GetBin(j);
569 content2 = hist2->GetBinContent(bin2);
570 if((Int_t)content2==0) continue;
571 content2 = content1*content2/entries;
572 dtime = hist2->GetBinCenter(bin2);
573 hist3->Fill(dpad,dtime,content2);
574 }
575 }
576
577 //Fill it into the digit array:
578 for(Int_t i=0; i<hist3->GetNbinsX(); i++)
579 {
580 for(Int_t j=0; j<hist3->GetNbinsY(); j++)
581 {
582 bin1 = hist3->GetBin(i,j);
583 content1 = hist3->GetBinContent(bin1);
584 if((Int_t)content1 < 3) continue;
585 if(content1 >= 1024)
586 content1 = 1023;
587 if(fNDigits >= fMaxDigits)
588 {
589 cerr<<"AliL3Compress::CreateDigits() : Array index out of range : "<<fNDigits<<endl;
590 return;
591 }
592 fDigits[fNDigits].fCharge=(Int_t)content1;
593 fDigits[fNDigits].fRow = row;
594 fDigits[fNDigits].fPad = (Int_t)hist3->GetXaxis()->GetBinCenter(i);
595 fDigits[fNDigits].fTime = (Int_t)hist3->GetYaxis()->GetBinCenter(j);
596 fDPt[fNDigits] = &fDigits[fNDigits];
597 fNDigits++;
598 }
599 }
600
601 delete random;
602 delete hist1;
603 delete hist2;
604 delete hist3;
605 delete tr;
606}
607
608void AliL3Compress::QSort(AliL3RandomDigitData **a, Int_t first, Int_t last)
609{
610
611 // Sort array of AliL3RandomDigitData pointers using a quicksort algorithm.
612 // Uses CompareDigits() to compare objects.
613 // Thanks to Root!
614
615 static AliL3RandomDigitData *tmp;
616 static int i; // "static" to save stack space
617 int j;
618
619 while (last - first > 1) {
620 i = first;
621 j = last;
622 for (;;) {
623 while (++i < last && CompareDigits(a[i], a[first]) < 0)
624 ;
625 while (--j > first && CompareDigits(a[j], a[first]) > 0)
626 ;
627 if (i >= j)
628 break;
629
630 tmp = a[i];
631 a[i] = a[j];
632 a[j] = tmp;
633 }
634 if (j == first) {
635 ++first;
636 continue;
637 }
638 tmp = a[first];
639 a[first] = a[j];
640 a[j] = tmp;
641 if (j - first < last - (j + 1)) {
642 QSort(a, first, j);
643 first = j + 1; // QSort(j + 1, last);
644 } else {
645 QSort(a, j + 1, last);
646 last = j; // QSort(first, j);
647 }
648 }
649}
be6ddb10 650
651void AliL3Compress::WriteRootFile(Char_t *digitsfile,Char_t *rootfile)
652{
653 Char_t fname[100];
654 AliL3MemHandler *mem = new AliL3MemHandler();
655 sprintf(fname,"%s/restored_%d_%d.raw",fPath,fSlice,fPatch);
656 mem->SetBinaryInput(fname);
657 UInt_t ndigits;
658 AliL3DigitRowData *rowPt = (AliL3DigitRowData*)mem->CompBinary2Memory(ndigits);
659 mem->CloseBinaryInput();
660
661 AliL3FileHandler *file = new AliL3FileHandler();
662 if(!file->SetAliInput(digitsfile))
663 {
664 cerr<<"AliL3Compress::WriteRootFile() : Error opening file: "<<digitsfile<<endl;
665 return;
666 }
667 file->Init(fSlice,fPatch,NRows[fPatch]);
668 file->AliDigits2RootFile(rowPt,rootfile);
669 file->CloseAliInput();
670
671 delete mem;
672 delete file;
673}