works but needs to be verified. the void* in call back

This commit is contained in:
Dhanya Maliakal 2017-09-29 11:39:36 +02:00
parent 2bd5386c29
commit 9bdb361d08
2 changed files with 98 additions and 26 deletions

View File

@ -295,8 +295,10 @@ void SetStyle(SlsQtH1D* h){
void GetStatistics(double &min, double &max, double &sum, double* array, int size); void GetStatistics(double &min, double &max, double &sum, double* array, int size);
/**
* Convert data from
*/
void toDoublePixelData(double* dest, char* source,int size, int databytes);
private slots: private slots:
/** To update plot /** To update plot

View File

@ -796,7 +796,7 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){
cout << "fname " << data->fileName << endl; cout << "fname " << data->fileName << endl;
cout << "npoints " << data->npoints << endl; cout << "npoints " << data->npoints << endl;
cout << "npy " << data->npy << endl; cout << "npy " << data->npy << endl;
cout << "npy " << data->progressIndex << endl; cout << "progress " << data->progressIndex << endl;
cout << "values " << data->values << endl; cout << "values " << data->values << endl;
cout << "errors " << data->errors << endl; cout << "errors " << data->errors << endl;
cout << "angle " << data->angles << endl; cout << "angle " << data->angles << endl;
@ -834,8 +834,14 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){
return 0; return 0;
//angle plotting //angle plotting
if(anglePlot){ if(anglePlot){
// convert char* to double
double* finaldata = new double[nPixelsX*nPixelsY];
toDoublePixelData(finaldata, data->cvalues, nPixelsX*nPixelsY, data->databytes);
LockLastImageArray(); LockLastImageArray();
//set title //set title
plotTitle=QString(plotTitle_prefix)+QString(data->fileName).section('/',-1); plotTitle=QString(plotTitle_prefix)+QString(data->fileName).section('/',-1);
@ -849,7 +855,7 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){
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,finaldata,nAnglePixelsX*sizeof(double));
SetHistXAxisTitle("Channel Number"); SetHistXAxisTitle("Channel Number");
} }
@ -863,10 +869,10 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){
#ifdef CHECKINFERROR #ifdef CHECKINFERROR
int k = 0; int k = 0;
for(int i = 0; i < data->npoints; i++){ for(int i = 0; i < data->npoints; i++){
if(isinf(data->values[i])){ if(isinf(finaldata[i])){
//cout << "*** ERROR: value at " << i << " infinity" << endl; //cout << "*** ERROR: value at " << i << " infinity" << endl;
k++; k++;
data->values[i] = -1; finaldata[i] = -1;
} }
} }
if (k>0) { if (k>0) {
@ -876,14 +882,14 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){
cout << "angle min:" << m1 << endl; cout << "angle min:" << m1 << endl;
cout << "angle max:" << m2 << endl; cout << "angle max:" << m2 << endl;
cout << "angle sum:" << s1 << endl; cout << "angle sum:" << s1 << endl;
GetStatistics(m1,m2,s1,data->values,nAnglePixelsX); GetStatistics(m1,m2,s1,finaldata,nAnglePixelsX);
cout << "value min:" << m1 << endl; cout << "value min:" << m1 << endl;
cout << "value max:" << m2 << endl; cout << "value max:" << m2 << endl;
cout << "value sum:" << s1 << endl; cout << "value sum:" << s1 << endl;
} }
#endif #endif
memcpy(histXAngleAxis,data->angles,nAnglePixelsX*sizeof(double)); memcpy(histXAngleAxis,data->angles,nAnglePixelsX*sizeof(double));
memcpy(histYAngleAxis,data->values,nAnglePixelsX*sizeof(double)); memcpy(histYAngleAxis,finaldata,nAnglePixelsX*sizeof(double));
SetHistXAxisTitle("Angles"); SetHistXAxisTitle("Angles");
} }
UnlockLastImageArray(); UnlockLastImageArray();
@ -893,6 +899,7 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){
#endif #endif
emit UpdatePlotSignal(); emit UpdatePlotSignal();
plotRequired = true; plotRequired = true;
delete [] finaldata;
return 0; return 0;
} }
@ -923,6 +930,9 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){
} }
} }
// convert char* to double
double* finaldata = new double[nPixelsX*nPixelsY];
toDoublePixelData(finaldata, data->cvalues, nPixelsX*nPixelsY, data->databytes);
//if scan //if scan
//alframes //alframes
@ -935,12 +945,13 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){
//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),finaldata,nPixelsX*sizeof(double));
UnlockLastImageArray(); UnlockLastImageArray();
currentFrame++; currentFrame++;
currentScanDivLevel++; currentScanDivLevel++;
emit UpdatePlotSignal(); emit UpdatePlotSignal();
plotRequired = true; plotRequired = true;
delete [] finaldata;
return 0; return 0;
} }
//file index //file index
@ -954,12 +965,13 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){
//title //title
imageTitle = temp_title; imageTitle = temp_title;
//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] += finaldata[px];
UnlockLastImageArray(); UnlockLastImageArray();
currentFrame++; currentFrame++;
currentScanDivLevel++; currentScanDivLevel++;
emit UpdatePlotSignal(); emit UpdatePlotSignal();
plotRequired = true; plotRequired = true;
delete [] finaldata;
return 0; return 0;
} }
//level0 //level0
@ -980,11 +992,12 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){
//title //title
imageTitle = temp_title; imageTitle = temp_title;
//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] += finaldata[px];
UnlockLastImageArray(); UnlockLastImageArray();
currentFrame++; currentFrame++;
emit UpdatePlotSignal(); emit UpdatePlotSignal();
plotRequired = true; plotRequired = true;
delete [] finaldata;
return 0; return 0;
} }
//level1 //level1
@ -1005,11 +1018,12 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){
//title //title
imageTitle = temp_title; imageTitle = temp_title;
//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] += finaldata[px];
UnlockLastImageArray(); UnlockLastImageArray();
currentFrame++; currentFrame++;
emit UpdatePlotSignal(); emit UpdatePlotSignal();
plotRequired = true; plotRequired = true;
delete [] finaldata;
return 0; return 0;
} }
@ -1050,18 +1064,18 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){
//frequency of intensity //frequency of intensity
if(histogramArgument == qDefs::Intensity){ if(histogramArgument == qDefs::Intensity){
//ignore outside limits //ignore outside limits
if ((data->values[i] < histFrom) || (data->values[i] > histTo)) if ((finaldata[i] < histFrom) || (finaldata[i] > histTo))
continue; continue;
//check for intervals, increment if validates //check for intervals, increment if validates
for(int j=0;j<histogramSamples.size();j++){ for(int j=0;j<histogramSamples.size();j++){
if(histogramSamples[j].interval.contains(data->values[i])) if(histogramSamples[j].interval.contains(finaldata[i]))
histogramSamples[j].value += 1; histogramSamples[j].value += 1;
} }
} }
//get sum of data pixels //get sum of data pixels
else else
val += data->values[i]; val += finaldata[i];
} }
@ -1108,8 +1122,8 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){
//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] += finaldata[px];
memcpy(histYAxis[0],data->values,nPixelsX*sizeof(double)); memcpy(histYAxis[0],finaldata,nPixelsX*sizeof(double));
pedestalCount++; pedestalCount++;
} }
//calculate the pedestal value //calculate the pedestal value
@ -1124,16 +1138,16 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){
//normal data //normal data
if(((!pedestal)&(!accumulate)&(!binary)) || (resetAccumulate)){ if(((!pedestal)&(!accumulate)&(!binary)) || (resetAccumulate)){
memcpy(histYAxis[0],data->values,nPixelsX*sizeof(double)); memcpy(histYAxis[0],finaldata,nPixelsX*sizeof(double));
resetAccumulate = false; resetAccumulate = false;
} }
//pedestal or accumulate //pedestal or accumulate
else{ else{
double temp;//cannot overwrite cuz of accumulate double temp;//cannot overwrite cuz of accumulate
for(unsigned int px=0;px<(nPixelsX*nPixelsY);px++){ for(unsigned int px=0;px<(nPixelsX*nPixelsY);px++){
temp = data->values[px]; temp = finaldata[px];
if(pedestal) if(pedestal)
temp = data->values[px] - (pedestalVals[px]); temp = finaldata[px] - (pedestalVals[px]);
if(binary) { if(binary) {
if ((temp >= binaryFrom) && (temp <= binaryTo)) if ((temp >= binaryFrom) && (temp <= binaryTo))
temp = 1; temp = 1;
@ -1166,8 +1180,8 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){
//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*nPixelsY);px++) for(unsigned int px=0;px<(nPixelsX*nPixelsY);px++)
tempPedestalVals[px] += data->values[px]; tempPedestalVals[px] += finaldata[px];
memcpy(lastImageArray,data->values,nPixelsX*nPixelsY*sizeof(double)); memcpy(lastImageArray,finaldata,nPixelsX*nPixelsY*sizeof(double));
pedestalCount++; pedestalCount++;
} }
//calculate the pedestal value //calculate the pedestal value
@ -1182,16 +1196,16 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){
//normal data //normal data
if(((!pedestal)&(!accumulate)&(!binary)) || (resetAccumulate)){ if(((!pedestal)&(!accumulate)&(!binary)) || (resetAccumulate)){
memcpy(lastImageArray,data->values,nPixelsX*nPixelsY*sizeof(double)); memcpy(lastImageArray,finaldata,nPixelsX*nPixelsY*sizeof(double));
resetAccumulate = false; resetAccumulate = false;
} }
//pedestal or accumulate or binary //pedestal or accumulate or binary
else{ else{
double temp; double temp;
for(unsigned int px=0;px<(nPixelsX*nPixelsY);px++){ for(unsigned int px=0;px<(nPixelsX*nPixelsY);px++){
temp = data->values[px]; temp = finaldata[px];
if(pedestal) if(pedestal)
temp = data->values[px] - (pedestalVals[px]); temp = finaldata[px] - (pedestalVals[px]);
if(binary) { if(binary) {
if ((temp >= binaryFrom) && (temp <= binaryTo)) if ((temp >= binaryFrom) && (temp <= binaryTo))
temp = 1; temp = 1;
@ -1210,6 +1224,7 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){
}*/ }*/
UnlockLastImageArray(); UnlockLastImageArray();
delete [] finaldata;
#ifdef VERYVERBOSE #ifdef VERYVERBOSE
cprintf(BLUE,"currentframe:%d \tcurrentframeindex:%d\n",currentFrame,currentFrameIndex); cprintf(BLUE,"currentframe:%d \tcurrentframeindex:%d\n",currentFrame,currentFrameIndex);
#endif #endif
@ -1876,7 +1891,7 @@ int qDrawPlot::UpdateTrimbitPlot(bool fromDetector,bool Histogram){
//fill histogram values //fill histogram values
int value = 0; int value = 0;
for(i=0;i<actualPixelsX;i++){ for(i=0;i<actualPixelsX;i++){
if( (histTrimbits[i] <= TRIM_HISTOGRAM_XMAX) && (histTrimbits[i] >= 0)){//if(histogramSamples[j].interval.contains(data->values[i])) if( (histTrimbits[i] <= TRIM_HISTOGRAM_XMAX) && (histTrimbits[i] >= 0)){//if(histogramSamples[j].interval.contaifinaldataues[i]))
value = (int) histTrimbits[i]; value = (int) histTrimbits[i];
histogramSamples[value].value += 1; histogramSamples[value].value += 1;
} }
@ -2132,3 +2147,58 @@ void qDrawPlot::EnableGainPlot(bool e) {
#endif #endif
myDet->setGainDataEnableinDataCallback(e); myDet->setGainDataEnableinDataCallback(e);
} }
//-------------------------------------------------------------------------------------------------------------------------------------------------
void qDrawPlot::toDoublePixelData(double* dest, char* source,int size, int databytes) {
int dr = ((double)databytes/(double)size)*8;
int ichan=0;
int ibyte=0;
int halfbyte=0;
char cbyte = '\0';
int mask=0x00ffffff;
switch(dr) {
case 4:
for (ibyte = 0; ibyte < databytes; ++ibyte) {
cbyte = source[ibyte];
for (halfbyte = 0; halfbyte < 2; ++halfbyte) {
dest[ichan] = (cbyte >> (halfbyte * 4)) & 0xf;
++ichan;
}
}
break;
case 8:
for (ichan = 0; ichan < databytes; ++ichan)
dest[ichan] = source[ichan];
break;
case 16:
for (ichan = 0; ichan < size; ++ichan) {
dest[ichan] = *((u_int16_t*)source);
source += 2;
}
break;
default:
if (detType == slsDetectorDefs::MYTHEN) {
for (ichan=0; ichan < size; ++ichan) {
dest[ichan] = (*((u_int32_t*)source) & mask);
source += 4;
}
}
else {
for (ichan=0; ichan < size; ++ichan) {
dest[ichan] = *((u_int32_t*)source);
source += 4;
}
}
break;
}
}