mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-13 05:17:13 +02:00
fixed gettrimbits, histogram(still more),start stop,scans,not accessign shared memory duign acquisition
git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorGui@55 af1100a4-978c-4157-bff7-07162d2ba061
This commit is contained in:
@ -8,6 +8,7 @@
|
||||
#include "qDrawPlot.h"
|
||||
#include "qCloneWidget.h"
|
||||
#include "slsDetector.h"
|
||||
#include"fileIOStatic.h"
|
||||
|
||||
// Project Class Headers
|
||||
#include "slsDetector.h"
|
||||
@ -76,7 +77,6 @@ void qDrawPlot::SetupWidgetWindow(){
|
||||
minPixelsY = 0;
|
||||
//2d
|
||||
lastImageArray = 0;
|
||||
image_data = 0;
|
||||
//1d
|
||||
nHists = 0;
|
||||
histNBins = 0;
|
||||
@ -103,7 +103,9 @@ void qDrawPlot::SetupWidgetWindow(){
|
||||
alreadyDisplayed = false;
|
||||
// This is so that it initially stop and plots
|
||||
running = 1;
|
||||
for(int i=0;i<MAX_1DPLOTS;i++) {histYAxis[i]=0;yvalues[i]=0; }
|
||||
for(int i=0;i<MAX_1DPLOTS;i++)
|
||||
histYAxis[i]=0;
|
||||
|
||||
|
||||
// clone
|
||||
for(int i=0;i<MAXCloneWindows;i++) winClone[i]=0;
|
||||
@ -170,7 +172,9 @@ void qDrawPlot::SetupWidgetWindow(){
|
||||
noMarker = new QwtSymbol();
|
||||
|
||||
|
||||
|
||||
//filepath and file name
|
||||
filePath = QString(myDet->getFilePath().c_str());
|
||||
fileName = QString(myDet->getFileName().c_str());
|
||||
|
||||
}
|
||||
|
||||
@ -186,7 +190,7 @@ void qDrawPlot::Initialization(){
|
||||
|
||||
connect(this, SIGNAL(SetZRangeSignal(double,double)), plot2D, SLOT(SetZRange(double,double)));
|
||||
|
||||
connect(this, SIGNAL(AcquisitionErrorSignal()), this, SLOT(ShowAcquisitionErrorMessage()));
|
||||
connect(this, SIGNAL(AcquisitionErrorSignal(QString)), this, SLOT(ShowAcquisitionErrorMessage(QString)));
|
||||
|
||||
|
||||
}
|
||||
@ -205,8 +209,6 @@ void qDrawPlot::StartStopDaqToggle(bool stop_if_running){
|
||||
running=!running;
|
||||
}else if(!stop_if_running){ //then start
|
||||
|
||||
//number of measurements
|
||||
int numMeasurements = (int)myDet->setTimer(slsDetectorDefs::MEASUREMENTS_NUMBER,-1);
|
||||
// Reset Current Measurement
|
||||
currentMeasurement = 0;
|
||||
emit SetCurrentMeasurementSignal(currentMeasurement);
|
||||
@ -235,7 +237,7 @@ void qDrawPlot::StartStopDaqToggle(bool stop_if_running){
|
||||
if(anglePlot) number_of_exposures = numScan0 * numScan1;
|
||||
|
||||
|
||||
cout << "\tNumber of Exposures:" << number_of_exposures << endl;
|
||||
cout << "\tNumber of Exposures Per Measurement:" << number_of_exposures << endl;
|
||||
|
||||
// ExposureTime
|
||||
exposureTime= ((double)(myDet->setTimer(slsDetectorDefs::ACQUISITION_TIME,-1))*1E-9);
|
||||
@ -244,6 +246,8 @@ void qDrawPlot::StartStopDaqToggle(bool stop_if_running){
|
||||
acquisitionPeriod= ((double)(myDet->setTimer(slsDetectorDefs::FRAME_PERIOD,-1))*1E-9);
|
||||
cout << "\tAcquisition Period:" << setprecision (10) << acquisitionPeriod << endl;
|
||||
|
||||
cout << "\tFile Index:" << myDet->getFileIndex() << endl;
|
||||
|
||||
//to take the first data if frameFactor
|
||||
numFactor = 0;
|
||||
|
||||
@ -252,6 +256,10 @@ void qDrawPlot::StartStopDaqToggle(bool stop_if_running){
|
||||
lastSavedFrame = -1;
|
||||
lastSavedMeasurement = -1;
|
||||
|
||||
//update file path and file name
|
||||
filePath = QString(myDet->getFilePath().c_str());
|
||||
fileName = QString(myDet->getFileName().c_str());
|
||||
|
||||
|
||||
StartDaq(true);
|
||||
running=!running;
|
||||
@ -312,13 +320,15 @@ bool qDrawPlot::StartOrStopThread(bool start){
|
||||
if(start){
|
||||
progress = 0;
|
||||
//sets up the measurement parameters
|
||||
SetupMeasurement();
|
||||
SetupMeasurement(myDet->getFileIndex());
|
||||
|
||||
cout << "Starting new acquisition threadddd ...." << endl;
|
||||
// Setting the callback function to get data from detector class
|
||||
myDet->registerDataCallback(&(GetDataCallBack),this);
|
||||
//Setting the callback function to alert when acquisition finished from detector class
|
||||
myDet->registerAcquisitionFinishedCallback(&(GetAcquisitionFinishedCallBack),this);
|
||||
//Setting the callback function to alert when each measurement finished from detector class
|
||||
myDet->registerMeasurementFinishedCallback(&(GetMeasurementFinishedCallBack),this);
|
||||
// Start acquiring data from server
|
||||
if(!firstTime) pthread_join(gui_acquisition_thread,NULL);//wait until he's finished, ie. exits
|
||||
pthread_create(&gui_acquisition_thread, NULL,DataStartAcquireThread, (void*) this);
|
||||
@ -337,69 +347,37 @@ bool qDrawPlot::StartOrStopThread(bool start){
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
void qDrawPlot::SetupMeasurement(){
|
||||
if(myDet->getRunStatus()==slsDetectorDefs::IDLE)
|
||||
cout<<endl<<endl<<"IDLE"<<endl;
|
||||
else cout<<endl<<endl<<"ERRORRRRRR: "<<myDet->getRunStatus()<<endl;
|
||||
// Defaults
|
||||
currentFrame = 0;
|
||||
stop_signal = 0;
|
||||
histTitle[0] = "";
|
||||
void qDrawPlot::SetScanArgument(int scanArg){
|
||||
#ifdef VERBOSE
|
||||
cout << "SetScanArgument function" << endl;
|
||||
#endif
|
||||
scanArgument = scanArg;
|
||||
|
||||
//for 2d scans
|
||||
int currentIndex = myDet->getFileIndex();
|
||||
currentScanValue = 0;
|
||||
currentScanDivLevel = 0;
|
||||
LockLastImageArray();
|
||||
|
||||
nPixelsX = myDet->getTotalNumberOfChannels();
|
||||
nPixelsY = 100;//if number of exposures, this should be checked before acquisition
|
||||
|
||||
if(scanArgument!=None){
|
||||
if(scanArgument==AllFrames){
|
||||
maxPixelsY = currentIndex + number_of_exposures - 1;
|
||||
minPixelsY = currentIndex;
|
||||
nPixelsY = number_of_exposures;
|
||||
}else if(scanArgument==FileIndex){
|
||||
maxPixelsY = currentIndex + number_of_frames - 1;
|
||||
minPixelsY = currentIndex;
|
||||
nPixelsY = number_of_frames;
|
||||
}else if(scanArgument==Level0){
|
||||
//no need to check if numsteps=0,cuz otherwise this mode wont be set in plot tab
|
||||
int numSteps = myDet->getScanSteps(0);
|
||||
double *values = new double[numSteps];
|
||||
myDet->getScanSteps(0,values);
|
||||
//cannot do this in between measurements , so update instantly
|
||||
if(scanArgument==Level0){
|
||||
//no need to check if numsteps=0,cuz otherwise this mode wont be set in plot tab
|
||||
int numSteps = myDet->getScanSteps(0);
|
||||
double *values = new double[numSteps];
|
||||
myDet->getScanSteps(0,values);
|
||||
|
||||
maxPixelsY = values[numSteps-1];
|
||||
minPixelsY = values[0];
|
||||
nPixelsY = numSteps;
|
||||
currentScanValue = values[0];
|
||||
}
|
||||
else {
|
||||
//no need to check if numsteps=0,cuz otherwise this mode wont be set in plot tab
|
||||
int numSteps = myDet->getScanSteps(1);
|
||||
double *values = new double[numSteps];
|
||||
myDet->getScanSteps(1,values);
|
||||
maxPixelsY = values[numSteps-1];
|
||||
minPixelsY = values[0];
|
||||
nPixelsY = numSteps;
|
||||
}else if(scanArgument==Level1) {
|
||||
//no need to check if numsteps=0,cuz otherwise this mode wont be set in plot tab
|
||||
int numSteps = myDet->getScanSteps(1);
|
||||
double *values = new double[numSteps];
|
||||
myDet->getScanSteps(1,values);
|
||||
|
||||
maxPixelsY = values[numSteps-1];
|
||||
minPixelsY = values[0];
|
||||
nPixelsY = numSteps;
|
||||
currentScanValue = values[0];
|
||||
}
|
||||
pixelWidth = (maxPixelsY -minPixelsY)/(nPixelsY-1);
|
||||
startPixel = minPixelsY -(pixelWidth/2);
|
||||
endPixel = maxPixelsY + (pixelWidth/2);
|
||||
}else{//no scan
|
||||
nPixelsY = 100;//number_of_exposures;
|
||||
maxPixelsY = 100;
|
||||
minPixelsY = 0;
|
||||
startPixel = -0.5;
|
||||
endPixel = nPixelsY-0.5;
|
||||
maxPixelsY = values[numSteps-1];
|
||||
minPixelsY = values[0];
|
||||
nPixelsY = numSteps;
|
||||
}
|
||||
cout<<"nPixelsY:"<<nPixelsY<<endl;
|
||||
cout<<"minPixelsY:"<<minPixelsY<<endl;
|
||||
cout<<"maxPixelsY:"<<maxPixelsY<<endl;
|
||||
cout<<"startPixel:"<<startPixel<<endl;
|
||||
cout<<"endPixel:"<<endPixel<<endl;
|
||||
|
||||
|
||||
|
||||
//1d
|
||||
if(histXAxis) delete [] histXAxis; histXAxis = new double [nPixelsX];
|
||||
@ -408,20 +386,87 @@ void qDrawPlot::SetupMeasurement(){
|
||||
//2d
|
||||
if(lastImageArray) delete [] lastImageArray; lastImageArray = new double[nPixelsY*nPixelsX];
|
||||
|
||||
//sorta useless
|
||||
if(yvalues[0]) delete [] yvalues[0]; yvalues[0] = new double [nPixelsX];
|
||||
if(image_data) delete [] image_data; image_data = new double[nPixelsY*nPixelsX];
|
||||
|
||||
//initializing 1d xaxis
|
||||
for(unsigned int px=0;px<nPixelsX;px++) histXAxis[px] = px;/*+10;*/
|
||||
|
||||
histYAxis[0][4] = 190.56;
|
||||
//initializing 1d x axis
|
||||
for(unsigned int px=0;px<(int)nPixelsX;px++) histXAxis[px] = px;/*+10;*/
|
||||
|
||||
//initializing 2d array
|
||||
for(int py=0;py<nPixelsY;py++)
|
||||
for(int px=0;px<nPixelsX;px++)
|
||||
for(int py=0;py<(int)nPixelsY;py++)
|
||||
for(int px=0;px<(int)nPixelsX;px++)
|
||||
lastImageArray[py*nPixelsX+px] = 0;
|
||||
|
||||
|
||||
|
||||
|
||||
UnlockLastImageArray();
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
void qDrawPlot::SetupMeasurement(int currentIndex){
|
||||
#ifdef VERBOSE
|
||||
cout << "SetupMeasurement function" << endl;
|
||||
#endif
|
||||
|
||||
LockLastImageArray();
|
||||
|
||||
// Defaults
|
||||
if(!running)
|
||||
stop_signal = 0;
|
||||
currentFrame = 0;
|
||||
//for 2d scans
|
||||
currentScanDivLevel = 0;
|
||||
lastImageNumber = 0;
|
||||
|
||||
//initializing 2d array
|
||||
for(int py=0;py<(int)nPixelsY;py++)
|
||||
for(int px=0;px<(int)nPixelsX;px++)
|
||||
lastImageArray[py*nPixelsX+px] = 0;
|
||||
|
||||
|
||||
//no scan
|
||||
if(scanArgument==None){
|
||||
if(!running){
|
||||
maxPixelsY = 100;
|
||||
minPixelsY = 0;
|
||||
startPixel = -0.5;
|
||||
endPixel = nPixelsY-0.5;
|
||||
}
|
||||
}
|
||||
else {//all frames
|
||||
if(scanArgument==AllFrames){
|
||||
maxPixelsY = currentIndex + number_of_exposures - 1;
|
||||
minPixelsY = currentIndex;
|
||||
if(!running) nPixelsY = number_of_exposures;
|
||||
}//file index
|
||||
else if(scanArgument==FileIndex){
|
||||
maxPixelsY = currentIndex + number_of_frames - 1;
|
||||
minPixelsY = currentIndex;
|
||||
if(!running) nPixelsY = number_of_frames;
|
||||
}//level0 or level1
|
||||
else currentScanValue = minPixelsY;
|
||||
|
||||
//cannot divide by 0
|
||||
if(nPixelsY==1){
|
||||
pixelWidth = 0;
|
||||
startPixel = minPixelsY-0.5;
|
||||
endPixel = minPixelsY+0.5;
|
||||
}else{
|
||||
pixelWidth = (maxPixelsY -minPixelsY)/(nPixelsY-1);
|
||||
startPixel = minPixelsY -(pixelWidth/2);
|
||||
endPixel = maxPixelsY + (pixelWidth/2);
|
||||
}
|
||||
}
|
||||
|
||||
cout<<"\nnPixelsY:"<<nPixelsY<<endl;
|
||||
cout<<"minPixelsY:"<<minPixelsY;
|
||||
cout<<"\tmaxPixelsY:"<<maxPixelsY<<endl;
|
||||
cout<<"startPixel:"<<startPixel;
|
||||
cout<<"\tendPixel:"<<endPixel<<endl<<endl;
|
||||
|
||||
UnlockLastImageArray();
|
||||
}
|
||||
|
||||
|
||||
@ -452,15 +497,15 @@ int qDrawPlot::GetData(detectorData *data){
|
||||
#ifdef VERYVERBOSE
|
||||
cout << "Entering GetDatafunction" << endl;
|
||||
#endif
|
||||
cout<<"progress:"<<(int)data->progressIndex<<endl;
|
||||
if(!stop_signal){
|
||||
|
||||
//set title
|
||||
SetPlotTitle(QString(data->fileName).section('/',-1));
|
||||
//set progress
|
||||
progress=(int)data->progressIndex;
|
||||
|
||||
|
||||
#ifdef VERBOSE
|
||||
cout << "progress:" << progress << endl;
|
||||
#endif
|
||||
|
||||
//Plot Disabled
|
||||
if(!plotEnable) return 0;
|
||||
@ -522,7 +567,7 @@ int qDrawPlot::GetData(detectorData *data){
|
||||
lastImageNumber= currentFrame+1;
|
||||
//title
|
||||
char temp_title[2000];
|
||||
sprintf(temp_title,"Image Index %d",myDet->getFileIndexFromFileName(string(data->fileName)));
|
||||
sprintf(temp_title,"Image Index %d",fileIOStatic::getFileIndexFromFileName(string(data->fileName)));
|
||||
imageTitle = temp_title;
|
||||
//copy data
|
||||
memcpy(lastImageArray+(currentScanDivLevel*nPixelsX),data->values,nPixelsX*sizeof(double));
|
||||
@ -536,7 +581,7 @@ int qDrawPlot::GetData(detectorData *data){
|
||||
if(scanArgument==FileIndex){
|
||||
if(!pthread_mutex_trylock(&(last_image_complete_mutex))){
|
||||
//variables
|
||||
int currentIndex = myDet->getFileIndexFromFileName(string(data->fileName));
|
||||
int currentIndex = fileIOStatic::getFileIndexFromFileName(string(data->fileName));
|
||||
if(currentIndex == minPixelsY) currentScanDivLevel = 0;
|
||||
lastImageNumber= currentFrame+1;
|
||||
//title
|
||||
@ -556,8 +601,10 @@ int qDrawPlot::GetData(detectorData *data){
|
||||
if(!pthread_mutex_trylock(&(last_image_complete_mutex))){
|
||||
//get scanvariable0
|
||||
int currentIndex = 0, p = 0; double cs0 = 0 , cs1 = 0;
|
||||
myDet->getVariablesFromFileName(string(data->fileName), currentIndex, p, cs0, cs1);
|
||||
fileIOStatic::getVariablesFromFileName(string(data->fileName), currentIndex, p, cs0, cs1);
|
||||
int currentScanVariable0 = (int)cs0;
|
||||
cout<<"currentScanValue:"<<currentScanValue<<endl;
|
||||
cout<<"currentScanVariable0:"<<currentScanVariable0<<endl;
|
||||
//variables
|
||||
if(currentScanVariable0!=currentScanValue) currentScanDivLevel++;
|
||||
currentScanValue = currentScanVariable0;
|
||||
@ -577,7 +624,7 @@ int qDrawPlot::GetData(detectorData *data){
|
||||
if(!pthread_mutex_trylock(&(last_image_complete_mutex))){
|
||||
//get scanvariable1
|
||||
int currentIndex = 0, p = 0; double cs0 = 0 , cs1 = 0;
|
||||
myDet->getVariablesFromFileName(string(data->fileName), currentIndex, p, cs0, cs1);
|
||||
fileIOStatic::getVariablesFromFileName(string(data->fileName), currentIndex, p, cs0, cs1);
|
||||
int currentScanVariable1 = (int)cs1;
|
||||
//variables
|
||||
if(currentScanVariable1!=currentScanValue) currentScanDivLevel++;
|
||||
@ -618,14 +665,13 @@ int qDrawPlot::GetData(detectorData *data){
|
||||
//2d
|
||||
else{
|
||||
// Titles
|
||||
sprintf(temp_title,"Image Index %d",myDet->getFileIndexFromFileName(string(data->fileName)));
|
||||
sprintf(temp_title,"Image Index %d",fileIOStatic::getFileIndexFromFileName(string(data->fileName)));
|
||||
imageTitle = temp_title;
|
||||
// manufacture data for now
|
||||
for(unsigned int px=0;px<nPixelsX;px++)
|
||||
for(unsigned int py=0;py<nPixelsY;py++)
|
||||
image_data[py*nPixelsX+px] = sqrt(pow(currentFrame+1,2)*pow(double(px)-nPixelsX/2,2)/pow(nPixelsX/2,2)/pow(number_of_exposures+1,2) + pow(double(py)-nPixelsY/2,2)/pow(nPixelsY/2,2))/sqrt(2);
|
||||
lastImageArray[py*nPixelsX+px] = sqrt(pow(currentFrame+1,2)*pow(double(px)-nPixelsX/2,2)/pow(nPixelsX/2,2)/pow(number_of_exposures+1,2) + pow(double(py)-nPixelsY/2,2)/pow(nPixelsY/2,2))/sqrt(2);
|
||||
// copy data
|
||||
memcpy(lastImageArray,image_data,nPixelsX*nPixelsY*sizeof(double));
|
||||
//SHOULD BE memcpy(lastImageArray,data->values,nPixelsX*nPixelsY*sizeof(double));
|
||||
}
|
||||
pthread_mutex_unlock(&(last_image_complete_mutex));
|
||||
@ -653,38 +699,30 @@ int qDrawPlot::GetAcquisitionFinishedCallBack(double currentProgress,int detecto
|
||||
|
||||
|
||||
int qDrawPlot::AcquisitionFinished(double currentProgress, int detectorStatus){
|
||||
QString status = QString(slsDetectorBase::runStatusType(slsDetectorDefs::runStatus(detectorStatus)).c_str());
|
||||
#ifdef VERBOSE
|
||||
cout << "Entering Acquisition Finished with status " <<
|
||||
slsDetectorBase::runStatusType((slsDetectorDefs::runStatus(detectorStatus))) << " and progress " << currentProgress << endl;
|
||||
cout << "\nEntering Acquisition Finished with status " << status.toAscii().constData() << " and progress " << currentProgress << endl;
|
||||
#endif
|
||||
//error or stopped
|
||||
if((stop_signal)||(detectorStatus==slsDetectorDefs::ERROR)){
|
||||
#ifdef VERBOSE
|
||||
cout << "Error in Acquisition" << endl;
|
||||
cout << "Error in Acquisition" << endl << endl;
|
||||
#endif
|
||||
//just to be sure
|
||||
stop_signal = 1;
|
||||
StartStopDaqToggle(true);
|
||||
emit AcquisitionErrorSignal();
|
||||
//stop_signal = 1;//just to be sure
|
||||
emit AcquisitionErrorSignal(status);
|
||||
}
|
||||
else{
|
||||
//all measurements are over
|
||||
if(currentProgress==100){
|
||||
|
||||
//all measurements are over
|
||||
else if(currentProgress==100){
|
||||
#ifdef VERBOSE
|
||||
cout << "Acquisition Finished" << endl;
|
||||
cout << "Acquisition Finished" << endl << endl;
|
||||
#endif
|
||||
StartStopDaqToggle(true);
|
||||
emit UpdatingPlotFinished();
|
||||
}
|
||||
else{//next measurement
|
||||
currentMeasurement++;
|
||||
#ifdef VERBOSE
|
||||
cout << "currentMeasurement:" << currentMeasurement << endl;
|
||||
#endif
|
||||
emit SetCurrentMeasurementSignal(currentMeasurement);
|
||||
SetupMeasurement();
|
||||
}
|
||||
}
|
||||
|
||||
StartStopDaqToggle(true);
|
||||
//this lets the measurement tab know its over, and to enable tabs
|
||||
emit UpdatingPlotFinished();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -692,12 +730,12 @@ int qDrawPlot::AcquisitionFinished(double currentProgress, int detectorStatus){
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
void qDrawPlot::ShowAcquisitionErrorMessage(){
|
||||
void qDrawPlot::ShowAcquisitionErrorMessage(QString status){
|
||||
if(!alreadyDisplayed){
|
||||
alreadyDisplayed = true;
|
||||
int detStatus = (int)myDet->getRunStatus();
|
||||
string status = slsDetectorBase::runStatusType(slsDetectorDefs::runStatus(detStatus));
|
||||
qDefs::Message(qDefs::WARNING,string("<nobr>The acquisiton has ended abruptly. Current Detector Status: ")+status+string(".</nobr>"),"Dock");
|
||||
qDefs::Message(qDefs::WARNING,string("<nobr>The acquisiton has ended abruptly. "
|
||||
"Current Detector Status: ")+status.toAscii().constData()+
|
||||
string(".</nobr>"),"Dock");
|
||||
}
|
||||
}
|
||||
|
||||
@ -705,8 +743,38 @@ void qDrawPlot::ShowAcquisitionErrorMessage(){
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
int qDrawPlot::GetMeasurementFinishedCallBack(int currentMeasurementIndex, int fileIndex, void *this_pointer){
|
||||
((qDrawPlot*)this_pointer)->MeasurementFinished(currentMeasurementIndex, fileIndex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
int qDrawPlot::MeasurementFinished(int currentMeasurementIndex, int fileIndex){
|
||||
#ifdef VERBOSE
|
||||
cout << "Entering Measurement Finished with currentMeasurement " << currentMeasurementIndex << " and fileIndex " << fileIndex << endl;
|
||||
#endif
|
||||
//to make sure it plots the last frame before setting lastimagearray all to 0
|
||||
if(plot_in_scope==2) usleep(500000);
|
||||
|
||||
currentMeasurement = currentMeasurementIndex + 1;
|
||||
#ifdef VERBOSE
|
||||
cout << "currentMeasurement:" << currentMeasurement << endl;
|
||||
#endif
|
||||
emit SetCurrentMeasurementSignal(currentMeasurement);
|
||||
SetupMeasurement(fileIndex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
void qDrawPlot::SelectPlot(int i){ //1 for 1D otherwise 2D
|
||||
if(i==1){
|
||||
Clear1DPlot();
|
||||
plot1D->SetXTitle(histXAxisTitle.toAscii().constData());
|
||||
plot1D->SetYTitle(histYAxisTitle.toAscii().constData());
|
||||
plot1D->show();
|
||||
@ -724,13 +792,16 @@ void qDrawPlot::SelectPlot(int i){ //1 for 1D otherwise 2D
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
void qDrawPlot::Clear1DPlot(){
|
||||
for(QVector<SlsQtH1D*>::iterator h = plot1D_hists.begin();
|
||||
h!=plot1D_hists.end();h++) (*h)->Detach(plot1D); //clear plot
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@ -813,6 +884,7 @@ void qDrawPlot::UpdatePlot(){
|
||||
|
||||
if(plotEnable) UnlockLastImageArray();
|
||||
|
||||
|
||||
//if acqq stopped before this line, it continues from here, shouldnt restart plotting timer
|
||||
if(!stop_signal){
|
||||
if(!frameFactor)
|
||||
@ -823,8 +895,10 @@ void qDrawPlot::UpdatePlot(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
void qDrawPlot::StopUpdatePlot(){
|
||||
#ifdef VERYVERBOSE
|
||||
cout << "Entering StopUpdatePlot()" << endl;
|
||||
@ -832,8 +906,10 @@ void qDrawPlot::StopUpdatePlot(){
|
||||
plot_update_timer->stop();
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
void qDrawPlot::ClonePlot(){
|
||||
int i=0;
|
||||
bool found = false;
|
||||
@ -850,8 +926,16 @@ void qDrawPlot::ClonePlot(){
|
||||
// save height to keep maintain same height of plot
|
||||
int preheight = height();
|
||||
|
||||
string sFilePath;
|
||||
if(running) sFilePath = filePath.toAscii().constData();
|
||||
else sFilePath = myDet->getFilePath();
|
||||
|
||||
|
||||
|
||||
LockLastImageArray();
|
||||
|
||||
// create clone
|
||||
winClone[i] = new qCloneWidget(this,i,boxPlot->title(),(int)plot_in_scope,plot1D,plot2D,myDet->getFilePath());
|
||||
winClone[i] = new qCloneWidget(this,i,boxPlot->title(),(int)plot_in_scope,plot1D,plot2D,sFilePath);
|
||||
if(plot_in_scope==1){
|
||||
plot1D = new SlsQt1DPlot(boxPlot);
|
||||
plot1D->setFont(QFont("Sans Serif",9,QFont::Normal));
|
||||
@ -885,6 +969,10 @@ void qDrawPlot::ClonePlot(){
|
||||
plot2D->SetZTitle(imageZAxisTitle);
|
||||
plotLayout->addWidget(plot2D,1,1,1,1);
|
||||
}
|
||||
|
||||
UnlockLastImageArray();
|
||||
|
||||
|
||||
setMinimumHeight(preheight);
|
||||
resize(width(),preheight);
|
||||
|
||||
@ -899,8 +987,10 @@ void qDrawPlot::ClonePlot(){
|
||||
connect(winClone[i], SIGNAL(CloneClosedSignal(int)),this, SLOT(CloneCloseEvent(int)));
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
void qDrawPlot::SaveClones(){
|
||||
char errID[200];
|
||||
string errMessage= "The Snapshots with ID's: ";
|
||||
@ -922,6 +1012,7 @@ void qDrawPlot::SaveClones(){
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
void qDrawPlot::CloseClones(){
|
||||
for(int i=0;i<MAXCloneWindows;i++)
|
||||
if(winClone[i])
|
||||
@ -929,8 +1020,10 @@ void qDrawPlot::CloseClones(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
void qDrawPlot::CloneCloseEvent(int id){
|
||||
winClone[id]=0;
|
||||
#ifdef VERBOSE
|
||||
@ -938,15 +1031,20 @@ void qDrawPlot::CloneCloseEvent(int id){
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
void qDrawPlot::SavePlot(){
|
||||
// render image
|
||||
QImage savedImage(size().width(),size().height(),QImage::Format_RGB32);
|
||||
QPainter painter(&savedImage);
|
||||
render(&painter);
|
||||
|
||||
QString fName = QString(myDet->getFilePath().c_str());
|
||||
QString fName;
|
||||
if(running) fName = filePath;
|
||||
else fName = QString(myDet->getFilePath().c_str());
|
||||
|
||||
if(boxPlot->title().contains('.')){
|
||||
fName.append(QString('/')+boxPlot->title());
|
||||
fName.replace(".dat",".png");
|
||||
@ -965,6 +1063,7 @@ void qDrawPlot::SavePlot(){
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
|
||||
void qDrawPlot::SaveAll(bool enable){
|
||||
string msg = string("The Files will be saved as:\n")+
|
||||
@ -973,19 +1072,27 @@ void qDrawPlot::SaveAll(bool enable){
|
||||
qDefs::Message(qDefs::INFORMATION,msg,"Dock");
|
||||
saveAll = enable;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
void qDrawPlot::SavePlotAutomatic(){
|
||||
//no need to save the same plot many times
|
||||
if((currentFrame>lastSavedFrame)&&(currentMeasurement>=lastSavedMeasurement)){
|
||||
|
||||
QString qFilePath;
|
||||
if(running) qFilePath = filePath;
|
||||
else qFilePath = QString(myDet->getFilePath().c_str());
|
||||
|
||||
|
||||
lastSavedFrame = currentFrame;
|
||||
lastSavedMeasurement = currentMeasurement;
|
||||
char cID[10];
|
||||
sprintf(cID,"%d",lastSavedFrame);
|
||||
//title
|
||||
QString fName = QString(myDet->getFilePath().c_str());
|
||||
QString fName = qFilePath;
|
||||
if(boxPlot->title().contains('.')){
|
||||
fName.append(QString('/')+boxPlot->title());
|
||||
fName.replace(".dat",".png");
|
||||
@ -1007,6 +1114,7 @@ void qDrawPlot::SavePlotAutomatic(){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@ -1021,15 +1129,15 @@ void qDrawPlot::ShowSaveErrorMessage(QString fileName){
|
||||
|
||||
|
||||
void qDrawPlot::SetPersistency(int val){
|
||||
for(int i=0;i<=val;i++){
|
||||
if(!yvalues[i]) yvalues[i] = new double [nPixelsX];
|
||||
for(int i=0;i<=val;i++)
|
||||
if(!histYAxis[i]) histYAxis[i] = new double [nPixelsX];
|
||||
}
|
||||
persistency = val;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
void qDrawPlot::EnablePlot(bool enable){
|
||||
#ifdef VERBOSE
|
||||
cout << "Plotting set to:" << enable << endl;
|
||||
@ -1041,8 +1149,10 @@ void qDrawPlot::EnablePlot(bool enable){
|
||||
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
void qDrawPlot::DisableZoom(bool disable){
|
||||
if(plot_in_scope==1)
|
||||
plot1D->DisableZoom(disable);
|
||||
@ -1050,4 +1160,133 @@ void qDrawPlot::DisableZoom(bool disable){
|
||||
plot2D->GetPlot()->DisableZoom(disable);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
int qDrawPlot::UpdateTrimbitPlot(bool fromDetector,bool Histogram){
|
||||
int ret,i,actualPixelsX;
|
||||
double *temp;
|
||||
#ifdef VERBOSE
|
||||
if(fromDetector) cout << "Geting Trimbits from Detector: ";
|
||||
else cout << "Getting Trimbits from Shared Memory: ";
|
||||
if(Histogram) cout << "Histogram" << endl;
|
||||
else cout << "Data Graph" << endl;
|
||||
#endif
|
||||
|
||||
|
||||
switch(myDet->getDetectorsType()){
|
||||
|
||||
|
||||
case slsDetectorDefs::MYTHEN:
|
||||
//get trimbits
|
||||
actualPixelsX = myDet->getTotalNumberOfChannels();
|
||||
temp = new double[actualPixelsX];
|
||||
ret = myDet->getChanRegs(temp,fromDetector);
|
||||
if(!ret){
|
||||
qDefs::Message(qDefs::WARNING,"No Trimbit data found in shared memory.","Dock");
|
||||
return qDefs::FAIL;
|
||||
}
|
||||
|
||||
//defining axes
|
||||
if(Histogram) nPixelsX = TRIM_HISTOGRAM_XMAX;
|
||||
else nPixelsX = actualPixelsX;
|
||||
if(histXAxis) delete [] histXAxis; histXAxis = new double [nPixelsX];
|
||||
if(histYAxis[0]) delete [] histYAxis[0];histYAxis[0] = new double [nPixelsX];
|
||||
//initializing
|
||||
for(unsigned int px=0;px<nPixelsX;px++) histXAxis[px] = px;
|
||||
for(int i=0;i<nPixelsX;i++) histYAxis[0][i] = 0;
|
||||
|
||||
//clear/select plot and set titles
|
||||
Clear1DPlot();
|
||||
Select1DPlot();
|
||||
|
||||
if(!Histogram){
|
||||
//data
|
||||
memcpy(histYAxis[0],temp,nPixelsX*sizeof(double));
|
||||
//title
|
||||
SetPlotTitle("Trimbits Plot - Data Graph");
|
||||
plot1D->SetXTitle("Channel Number");
|
||||
plot1D->SetYTitle("Trimbits");
|
||||
//set plot parameters
|
||||
SlsQtH1D* h;
|
||||
plot1D_hists.append(h=new SlsQtH1D("1d plot",nPixelsX,histXAxis,GetHistYAxis(0)));
|
||||
h->SetLineColor(1);
|
||||
h->setTitle(GetHistTitle(0));
|
||||
//attach plot
|
||||
h->Attach(plot1D);
|
||||
}else{
|
||||
//data
|
||||
for(i=0;i<actualPixelsX;i++){
|
||||
if((temp[i]<=TRIM_HISTOGRAM_XMAX))/**shouldnt be the case*/
|
||||
histYAxis[0][(int)temp[i]]+=1;
|
||||
//else cout<<"OUT OF BOUNDS:"<<i<<"-"<<temp[i]<<endl;
|
||||
}
|
||||
|
||||
/* for(i=0;i<TRIM_HISTOGRAM_XMAX;i++)
|
||||
if((histYAxis[0][i]<=TRIM_HISTOGRAM_XMAX)&&(histYAxis[0][i]>0))
|
||||
cout<<"HIsty["<<i<<"]:"<<histYAxis[0][i]<<endl;*/
|
||||
|
||||
//title
|
||||
SetPlotTitle("Trimbits Plot - Histogram");
|
||||
plot1D->SetXTitle("Trimbits");
|
||||
plot1D->SetYTitle("Frequency");
|
||||
//set plot parameters
|
||||
SlsQtH1D* h;
|
||||
plot1D_hists.append(h=new SlsQtH1D("1d plot",nPixelsX,histXAxis,GetHistYAxis(0)));
|
||||
h->SetLineColor(1);
|
||||
h->setTitle(GetHistTitle(0));
|
||||
//attach plot
|
||||
h->Attach(plot1D);
|
||||
|
||||
}
|
||||
#ifdef VERBOSE
|
||||
cout << "Trimbits Plot updated" << endl;
|
||||
#endif
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
//2d
|
||||
case slsDetectorDefs::EIGER:
|
||||
//defining axes
|
||||
nPixelsX = 100;/**??*/
|
||||
nPixelsY = 100;
|
||||
if(lastImageArray) delete [] lastImageArray; lastImageArray = new double[nPixelsY*nPixelsX];
|
||||
//initializing 2d array
|
||||
for(int py=0;py<(int)nPixelsY;py++)
|
||||
for(int px=0;px<(int)nPixelsX;px++)
|
||||
lastImageArray[py*nPixelsX+px] = 0;
|
||||
//get trimbits
|
||||
ret = 1;/*myDet->getChanRegs(lastImageArray,fromDetector);*/
|
||||
if(!ret){
|
||||
qDefs::Message(qDefs::WARNING,"No Trimbit data found in shared memory.","Dock");
|
||||
return qDefs::FAIL;
|
||||
}
|
||||
//clear/select plot and set titles
|
||||
Select2DPlot();
|
||||
plot2D->GetPlot()->SetData(nPixelsX,-0.5,nPixelsX-0.5,nPixelsY,-0.5,nPixelsY-0.5,lastImageArray);
|
||||
plot2D->setTitle("Image");
|
||||
plot2D->SetXTitle("Pixel");
|
||||
plot2D->SetYTitle("Pixel");
|
||||
plot2D->SetZTitle("Trimbits");
|
||||
plot2D->UpdateNKeepSetRangeIfSet();
|
||||
#ifdef VERBOSE
|
||||
cout << "Trimbits Plot updated" << endl;
|
||||
#endif
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//shouldnt be here
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return qDefs::OK;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user