+void AliL3Hough::PrepareForNextPatch(Int_t nextpatch)
+{
+ // Prepare the parameter space for the processing of
+ // the next read patch. According to the already
+ // accumulated number of gaps in parameter space
+ // bins, the routine updates the dynamic
+ // pointers used in order to jump rapidly during the
+ // filling of the parameter space.
+
+ char buf[256];
+ sprintf(buf,"Prepare For Patch %d",nextpatch);
+ fBenchmark->Start(buf);
+
+ UChar_t lastpatchlastrow;
+ if(fLastPatch == -1)
+ lastpatchlastrow = 0;
+ else
+ lastpatchlastrow = AliL3Transform::GetLastRowOnDDL(fLastPatch)+1;
+ UChar_t nextpatchfirstrow;
+ if(nextpatch==0)
+ nextpatchfirstrow = 0;
+ else
+ nextpatchfirstrow = AliL3Transform::GetFirstRowOnDDL(nextpatch)-1;
+
+ UChar_t *trackfirstrow = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetTrackFirstRow();
+ UChar_t *tracklastrow = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetTrackLastRow();
+
+ for(Int_t i=0; i<fNEtaSegments; i++)
+ {
+ UChar_t *gapcount = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetGapCount(i);
+ UChar_t *currentrowcount = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetCurrentRowCount(i);
+ UChar_t *prevbin = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetPrevBin(i);
+ UChar_t *nextbin = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetNextBin(i);
+ UChar_t *nextrow = ((AliL3HoughTransformerRow *)fHoughTransformer[0])->GetNextRow(i);
+
+ AliL3Histogram *hist = fHoughTransformer[0]->GetHistogram(i);
+ Int_t xmin = hist->GetFirstXbin();
+ Int_t xmax = hist->GetLastXbin();
+ Int_t ymin = hist->GetFirstYbin();
+ Int_t ymax = hist->GetLastYbin();
+ Int_t nxbins = hist->GetNbinsX()+2;
+
+ if(fLastPatch != -1) {
+ UChar_t lastyvalue = 0;
+ Int_t endybin = ymin - 1;
+ for(Int_t ybin=nextrow[ymin]; ybin<=ymax; ybin = nextrow[++ybin])
+ {
+ UChar_t lastxvalue = 0;
+ UChar_t maxvalue = 0;
+ Int_t endxbin = xmin - 1;
+ for(Int_t xbin=xmin; xbin<=xmax; xbin++)
+ {
+ Int_t bin = xbin + ybin*nxbins;
+ UChar_t value = 0;
+ if(gapcount[bin] < MAX_N_GAPS) {
+ if(tracklastrow[bin] > lastpatchlastrow) {
+ if(lastpatchlastrow > currentrowcount[bin])
+ gapcount[bin] += (lastpatchlastrow-currentrowcount[bin]-1);
+ }
+ else {
+ if(tracklastrow[bin] > currentrowcount[bin])
+ gapcount[bin] += (tracklastrow[bin]-currentrowcount[bin]-1);
+ }
+ if(gapcount[bin] < MAX_N_GAPS) {
+ value = 1;
+ maxvalue = 1;
+ if(trackfirstrow[bin] < nextpatchfirstrow)
+ currentrowcount[bin] = nextpatchfirstrow;
+ else
+ currentrowcount[bin] = trackfirstrow[bin];
+ }
+ }
+ if(value > 0)
+ {
+ nextbin[xbin + ybin*nxbins] = (UChar_t)xbin;
+ prevbin[xbin + ybin*nxbins] = (UChar_t)xbin;
+ if(value > lastxvalue)
+ {
+ UChar_t *tempnextbin = nextbin + endxbin + 1 + ybin*nxbins;
+ memset(tempnextbin,(UChar_t)xbin,xbin-endxbin-1);
+ }
+ endxbin = xbin;
+ }
+ else
+ {
+ prevbin[xbin + ybin*nxbins] = (UChar_t)endxbin;
+ }
+ lastxvalue = value;
+ }
+ UChar_t *tempnextbin = nextbin + endxbin + 1 + ybin*nxbins;
+ memset(tempnextbin,(UChar_t)(xmax+1),xmax-endxbin);
+ if(maxvalue > 0)
+ {
+ nextrow[ybin] = (UChar_t)ybin;
+ if(maxvalue > lastyvalue)
+ {
+ UChar_t *tempnextrow = nextrow + endybin + 1;
+ memset(tempnextrow,(UChar_t)ybin,ybin-endybin-1);
+ }
+ endybin = ybin;
+ }
+ lastyvalue = maxvalue;
+ }
+ UChar_t *tempnextrow = nextrow + endybin + 1;
+ memset(tempnextrow,(UChar_t)(ymax+1),ymax-endybin+1);
+ }
+ else {
+ UChar_t lastyvalue = 0;
+ Int_t endybin = ymin - 1;
+ for(Int_t ybin=ymin; ybin<=ymax; ybin++)
+ {
+ UChar_t maxvalue = 0;
+ for(Int_t xbin=xmin; xbin<=xmax; xbin++)
+ {
+ Int_t bin = xbin + ybin*nxbins;
+ if(gapcount[bin] < MAX_N_GAPS) {
+ maxvalue = 1;
+ if(trackfirstrow[bin] < nextpatchfirstrow)
+ currentrowcount[bin] = nextpatchfirstrow;
+ else
+ currentrowcount[bin] = trackfirstrow[bin];
+ }
+ }
+ if(maxvalue > 0)
+ {
+ nextrow[ybin] = (UChar_t)ybin;
+ if(maxvalue > lastyvalue)
+ {
+ UChar_t *tempnextrow = nextrow + endybin + 1;
+ memset(tempnextrow,(UChar_t)ybin,ybin-endybin-1);
+ }
+ endybin = ybin;
+ }
+ lastyvalue = maxvalue;
+ }
+ UChar_t *tempnextrow = nextrow + endybin + 1;
+ memset(tempnextrow,(UChar_t)(ymax+1),ymax-endybin+1);
+ }
+ }
+
+ fBenchmark->Stop(buf);
+}
+