pedestalbug fixed, trylock changed to lock, binary has qtip

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorGui@228 af1100a4-978c-4157-bff7-07162d2ba061
This commit is contained in:
l_maliakal_d 2013-08-16 13:48:03 +00:00
parent 3c92f26be7
commit 061bd4251c
2 changed files with 115 additions and 133 deletions

View File

@ -999,6 +999,11 @@ Displays minimum, maximum and sum of values for each plot.
</widget> </widget>
</widget> </widget>
<widget class="QWidget" name="page_8"> <widget class="QWidget" name="page_8">
<property name="toolTip">
<string>&lt;nobr&gt;
All values between &lt;b&gt;from&lt;/b&gt; and &lt;b&gt;to&lt;/b&gt; will be reset to 1, others to 0.
&lt;/nobr&gt;</string>
</property>
<widget class="QWidget" name="horizontalLayoutWidget_11"> <widget class="QWidget" name="horizontalLayoutWidget_11">
<property name="geometry"> <property name="geometry">
<rect> <rect>
@ -1020,6 +1025,11 @@ Displays minimum, maximum and sum of values for each plot.
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="toolTip">
<string>&lt;nobr&gt;
All values between &lt;b&gt;from&lt;/b&gt; and &lt;b&gt;to&lt;/b&gt; will be reset to 1, others to 0.
&lt;/nobr&gt;</string>
</property>
<property name="text"> <property name="text">
<string>Binary</string> <string>Binary</string>
</property> </property>
@ -1326,7 +1336,7 @@ Displays minimum, maximum and sum of values for each plot.
<rect> <rect>
<x>10</x> <x>10</x>
<y>20</y> <y>20</y>
<width>346</width> <width>341</width>
<height>26</height> <height>26</height>
</rect> </rect>
</property> </property>

View File

@ -725,40 +725,36 @@ int qDrawPlot::GetData(detectorData *data,int fIndex){
//angle plotting //angle plotting
if(anglePlot){ if(anglePlot){
while(1){ LockLastImageArray();
if(!pthread_mutex_trylock(&(last_image_complete_mutex))){ //set title
//set title plotTitle=QString(plotTitle_prefix)+QString(data->fileName).section('/',-1);
plotTitle=QString(plotTitle_prefix)+QString(data->fileName).section('/',-1); // Title
// Title histTitle[0] = temp_title;
histTitle[0] = temp_title;
if(data->angles==NULL){ if(data->angles==NULL){
cout<<"\n\nWARNING:RETURNED NULL instead of angles."<<endl; cout<<"\n\nWARNING:RETURNED NULL instead of angles."<<endl;
lastImageNumber= currentFrame+1; lastImageNumber= currentFrame+1;
nAnglePixelsX = nPixelsX; nAnglePixelsX = nPixelsX;
histNBins = nAnglePixelsX; histNBins = nAnglePixelsX;
nHists=1; nHists=1;
memcpy(histXAngleAxis,histXAxis,nAnglePixelsX*sizeof(double)); memcpy(histXAngleAxis,histXAxis,nAnglePixelsX*sizeof(double));
memcpy(histYAngleAxis,data->values,nAnglePixelsX*sizeof(double)); memcpy(histYAngleAxis,data->values,nAnglePixelsX*sizeof(double));
SetHistXAxisTitle("Channel Number"); SetHistXAxisTitle("Channel Number");
}
else{
lastImageNumber= currentFrame+1;
nAnglePixelsX = data->npoints;
histNBins = nAnglePixelsX;
nHists=1;
if(histXAngleAxis) delete [] histXAngleAxis; histXAngleAxis = new double[nAnglePixelsX];
if(histYAngleAxis) delete [] histYAngleAxis; histYAngleAxis = new double[nAnglePixelsX];
memcpy(histXAngleAxis,data->angles,nAnglePixelsX*sizeof(double));
memcpy(histYAngleAxis,data->values,nAnglePixelsX*sizeof(double));
SetHistXAxisTitle("Angles");
}
pthread_mutex_unlock(&(last_image_complete_mutex));
break;
}
} }
else{
lastImageNumber= currentFrame+1;
nAnglePixelsX = data->npoints;
histNBins = nAnglePixelsX;
nHists=1;
if(histXAngleAxis) delete [] histXAngleAxis; histXAngleAxis = new double[nAnglePixelsX];
if(histYAngleAxis) delete [] histYAngleAxis; histYAngleAxis = new double[nAnglePixelsX];
memcpy(histXAngleAxis,data->angles,nAnglePixelsX*sizeof(double));
memcpy(histYAngleAxis,data->values,nAnglePixelsX*sizeof(double));
SetHistXAxisTitle("Angles");
}
UnlockLastImageArray();
currentFrame++; currentFrame++;
return 0; return 0;
} }
@ -796,98 +792,82 @@ int qDrawPlot::GetData(detectorData *data,int fIndex){
//if scan //if scan
//alframes //alframes
if(scanArgument==qDefs::AllFrames){ if(scanArgument==qDefs::AllFrames){
while(1){ LockLastImageArray();
if(!pthread_mutex_trylock(&(last_image_complete_mutex))){ //set title
//set title plotTitle=QString(plotTitle_prefix)+QString(data->fileName).section('/',-1);
plotTitle=QString(plotTitle_prefix)+QString(data->fileName).section('/',-1); //variables
//variables lastImageNumber= currentFrame+1;
lastImageNumber= currentFrame+1; //title
//title imageTitle = temp_title;
imageTitle = temp_title; //copy data
//copy data memcpy(lastImageArray+(currentScanDivLevel*nPixelsX),data->values,nPixelsX*sizeof(double));
memcpy(lastImageArray+(currentScanDivLevel*nPixelsX),data->values,nPixelsX*sizeof(double)); UnlockLastImageArray();
pthread_mutex_unlock(&(last_image_complete_mutex));
break;
}
}
currentFrame++; currentFrame++;
currentScanDivLevel++; currentScanDivLevel++;
return 0; return 0;
} }
//file index //file index
if(scanArgument==qDefs::FileIndex){ if(scanArgument==qDefs::FileIndex){
while(1){ LockLastImageArray();
if(!pthread_mutex_trylock(&(last_image_complete_mutex))){ //set title
//set title plotTitle=QString(plotTitle_prefix)+QString(data->fileName).section('/',-1);
plotTitle=QString(plotTitle_prefix)+QString(data->fileName).section('/',-1); //variables
//variables if(currentFrameIndex == 0) currentScanDivLevel = 0;
if(currentFrameIndex == 0) currentScanDivLevel = 0; lastImageNumber= currentFrame+1;
lastImageNumber= currentFrame+1; //title
//title imageTitle = temp_title;
imageTitle = temp_title; cout<<"lastImageNumber:"<<lastImageNumber<<endl;
cout<<"lastImageNumber:"<<lastImageNumber<<endl; cout<<"currentScanDivLevel:"<<currentScanDivLevel<<endl;
cout<<"currentScanDivLevel:"<<currentScanDivLevel<<endl; //copy data
//copy data for(unsigned int px=0;px<nPixelsX;px++) lastImageArray[currentScanDivLevel*nPixelsX+px] += data->values[px];
for(unsigned int px=0;px<nPixelsX;px++) lastImageArray[currentScanDivLevel*nPixelsX+px] += data->values[px]; UnlockLastImageArray();
pthread_mutex_unlock(&(last_image_complete_mutex));
break;
}
}
currentFrame++; currentFrame++;
currentScanDivLevel++; currentScanDivLevel++;
return 0; return 0;
} }
//level0 //level0
if(scanArgument==qDefs::Level0){ if(scanArgument==qDefs::Level0){
while(1){ LockLastImageArray();
if(!pthread_mutex_trylock(&(last_image_complete_mutex))){ //set title
//set title plotTitle=QString(plotTitle_prefix)+QString(data->fileName).section('/',-1);
plotTitle=QString(plotTitle_prefix)+QString(data->fileName).section('/',-1); //get scanvariable0
//get scanvariable0 int ci = 0, fi = 0, p = 0, di = 0; double cs0 = 0 , cs1 = 0;
int ci = 0, fi = 0, p = 0, di = 0; double cs0 = 0 , cs1 = 0; fileIOStatic::getVariablesFromFileName(string(data->fileName), ci, fi, p, cs0, cs1, di);
fileIOStatic::getVariablesFromFileName(string(data->fileName), ci, fi, p, cs0, cs1, di); //variables
//variables if(cs0!=currentScanValue) {
if(cs0!=currentScanValue) { if(backwardScanPlot) currentScanDivLevel--;
if(backwardScanPlot) currentScanDivLevel--; else currentScanDivLevel++;
else currentScanDivLevel++;
}
currentScanValue = cs0;
lastImageNumber= currentFrame+1;
//title
imageTitle = temp_title;
//copy data
for(unsigned int px=0;px<nPixelsX;px++) lastImageArray[currentScanDivLevel*nPixelsX+px] += data->values[px];
pthread_mutex_unlock(&(last_image_complete_mutex));
break;
}
} }
currentScanValue = cs0;
lastImageNumber= currentFrame+1;
//title
imageTitle = temp_title;
//copy data
for(unsigned int px=0;px<nPixelsX;px++) lastImageArray[currentScanDivLevel*nPixelsX+px] += data->values[px];
UnlockLastImageArray();
currentFrame++; currentFrame++;
return 0; return 0;
} }
//level1 //level1
if(scanArgument==qDefs::Level1){ if(scanArgument==qDefs::Level1){
while(1){ LockLastImageArray();
if(!pthread_mutex_trylock(&(last_image_complete_mutex))){ //set title
//set title plotTitle=QString(plotTitle_prefix)+QString(data->fileName).section('/',-1);
plotTitle=QString(plotTitle_prefix)+QString(data->fileName).section('/',-1); //get scanvariable1
//get scanvariable1 int ci = 0, fi = 0, p = 0, di = 0; double cs0 = 0 , cs1 = 0;
int ci = 0, fi = 0, p = 0, di = 0; double cs0 = 0 , cs1 = 0; fileIOStatic::getVariablesFromFileName(string(data->fileName), ci, fi, p, cs0, cs1, di);
fileIOStatic::getVariablesFromFileName(string(data->fileName), ci, fi, p, cs0, cs1, di); //variables
//variables if(cs1!=currentScanValue){
if(cs1!=currentScanValue){ if(backwardScanPlot) currentScanDivLevel--;
if(backwardScanPlot) currentScanDivLevel--; else currentScanDivLevel++;
else currentScanDivLevel++;
}
currentScanValue = cs1;
lastImageNumber= currentFrame+1;
//title
imageTitle = temp_title;
//copy data
for(unsigned int px=0;px<nPixelsX;px++) lastImageArray[currentScanDivLevel*nPixelsX+px] += data->values[px];
pthread_mutex_unlock(&(last_image_complete_mutex));
break;
}
} }
currentScanValue = cs1;
lastImageNumber= currentFrame+1;
//title
imageTitle = temp_title;
//copy data
for(unsigned int px=0;px<nPixelsX;px++) lastImageArray[currentScanDivLevel*nPixelsX+px] += data->values[px];
UnlockLastImageArray();
currentFrame++; currentFrame++;
return 0; return 0;
} }
@ -917,19 +897,20 @@ int qDrawPlot::GetData(detectorData *data,int fIndex){
//recalculating pedestal //recalculating pedestal
if(startPedestalCal){ if(startPedestalCal){
pedestalCount++;
//start adding frames to get to the pedestal value //start adding frames to get to the pedestal value
if(pedestalCount<NUM_PEDESTAL_FRAMES){ if(pedestalCount<NUM_PEDESTAL_FRAMES){
for(unsigned int px=0;px<nPixelsX;px++) for(unsigned int px=0;px<nPixelsX;px++)
tempPedestalVals[px] += data->values[px]; tempPedestalVals[px] += data->values[px];//cout<<"tempPedestalVals[200]:"<<tempPedestalVals[200]<<endl;
memcpy(histYAxis[0],data->values,nPixelsX*sizeof(double)); memcpy(histYAxis[0],data->values,nPixelsX*sizeof(double));
pedestalCount++;
} }
//calculate the pedestal value //calculate the pedestal value
else if(pedestalCount==NUM_PEDESTAL_FRAMES){ else if(pedestalCount==NUM_PEDESTAL_FRAMES){
cout << "Pedestal Calculated" << endl; cout << "Pedestal Calculated" << endl;
for(unsigned int px=0;px<nPixelsX;px++) for(unsigned int px=0;px<nPixelsX;px++)
tempPedestalVals[px] = tempPedestalVals[px]/(double)NUM_PEDESTAL_FRAMES; tempPedestalVals[px] = tempPedestalVals[px]/(double)NUM_PEDESTAL_FRAMES;//cout<<"tempPedestalVals[200]:"<<tempPedestalVals[200]<<endl;
memcpy(pedestalVals,tempPedestalVals,nPixelsX*sizeof(double)); memcpy(pedestalVals,tempPedestalVals,nPixelsX*sizeof(double));//cout<<"pedestalVals[200]:"<<pedestalVals[200]<<endl;
startPedestalCal = 0; startPedestalCal = 0;
} }
} }
@ -1733,24 +1714,19 @@ void qDrawPlot::RecalculatePedestal(){
#ifdef VERBOSE #ifdef VERBOSE
cout << "Recalculating Pedestal" << endl; cout << "Recalculating Pedestal" << endl;
#endif #endif
while(1){ LockLastImageArray();
if(!pthread_mutex_trylock(&(last_image_complete_mutex))){ startPedestalCal = 1;
startPedestalCal = 1; pedestalCount = 0;
pedestalCount = 0;
//create array //create array
if(pedestalVals) delete [] pedestalVals; pedestalVals = new double[nPixelsX*nPixelsY]; if(pedestalVals) delete [] pedestalVals; pedestalVals = new double[nPixelsX*nPixelsY];
if(tempPedestalVals) delete [] tempPedestalVals; tempPedestalVals = new double[nPixelsX*nPixelsY]; if(tempPedestalVals) delete [] tempPedestalVals; tempPedestalVals = new double[nPixelsX*nPixelsY];
//reset all values //reset all values
for(unsigned int px=0;px<(nPixelsX*nPixelsY);px++) for(unsigned int px=0;px<(nPixelsX*nPixelsY);px++)
pedestalVals[px] = 0; pedestalVals[px] = 0;
for(unsigned int px=0;px<(nPixelsX*nPixelsY);px++) for(unsigned int px=0;px<(nPixelsX*nPixelsY);px++)
tempPedestalVals[px] = 0; tempPedestalVals[px] = 0;
UnlockLastImageArray();
pthread_mutex_unlock(&(last_image_complete_mutex));
break;
}
}
} }
@ -1771,13 +1747,9 @@ void qDrawPlot::ResetAccumulate(){
#ifdef VERBOSE #ifdef VERBOSE
cout << "Resetting Accumulation" << endl; cout << "Resetting Accumulation" << endl;
#endif #endif
while(1){ LockLastImageArray();
if(!pthread_mutex_trylock(&(last_image_complete_mutex))){ resetAccumulate = true;
resetAccumulate = true; UnlockLastImageArray();
pthread_mutex_unlock(&(last_image_complete_mutex));
break;
}
}
} }