removed the normal timer on the updateplot, it shold now plot as soon as it gets the data

This commit is contained in:
Dhanya Maliakal
2016-11-10 12:23:01 +01:00
parent a0b28503d0
commit 3c48065b5a
2 changed files with 211 additions and 213 deletions

View File

@ -101,7 +101,7 @@ public:
/** Get minimum Plot timer - between plots */ /** Get minimum Plot timer - between plots */
double GetMinimumPlotTimer(){return PLOT_TIMER_MS;}; double GetMinimumPlotTimer(){return PLOT_TIMER_MS;};
/** Set Plot timer - between plots in ms*/ /** Set Plot timer - between plots in ms*/
void SetPlotTimer(double time){timerValue = time;}; void SetPlotTimer(double time);
/** Set Plot frame factor - between plots, also for receiver if exists */ /** Set Plot frame factor - between plots, also for receiver if exists */
void SetFrameFactor(int frame); void SetFrameFactor(int frame);
@ -293,9 +293,6 @@ private slots:
/** To update plot /** To update plot
* */ * */
void UpdatePlot(); void UpdatePlot();
/** To stop updating plot
* */
void StopUpdatePlot();
/** To start or stop acquisition /** To start or stop acquisition
* @param start is 1 to start and 0 to stop acquisition * @param start is 1 to start and 0 to stop acquisition
* */ * */
@ -322,6 +319,8 @@ private:
/** The sls detector object */ /** The sls detector object */
multiSlsDetector *myDet; multiSlsDetector *myDet;
/** detectot type */
slsDetectorDefs::detectorType detType;
/** Widgets needed to plot the clone */ /** Widgets needed to plot the clone */
@ -423,7 +422,6 @@ double pixelWidth;
/** Current Image Number */ /** Current Image Number */
unsigned int lastImageNumber; unsigned int lastImageNumber;
int last_plot_number;
/** Number of graphs in 1D */ /** Number of graphs in 1D */
unsigned int nHists; unsigned int nHists;
@ -586,6 +584,7 @@ void ResetZMinZMaxSignal(bool,bool,double,double);
void SetCurrentMeasurementSignal(int); void SetCurrentMeasurementSignal(int);
void saveErrorSignal(QString); void saveErrorSignal(QString);
void AcquisitionErrorSignal(QString); void AcquisitionErrorSignal(QString);
void UpdatePlotSignal();
}; };

View File

@ -63,7 +63,8 @@ void qDrawPlot::SetupWidgetWindow(){
#endif #endif
// Depending on whether the detector is 1d or 2d // Depending on whether the detector is 1d or 2d
switch(myDet->getDetectorsType()){ detType = myDet->getDetectorsType();
switch(detType){
case slsDetectorDefs::MYTHEN: originally2D = false; break; case slsDetectorDefs::MYTHEN: originally2D = false; break;
case slsDetectorDefs::EIGER: originally2D = true; break; case slsDetectorDefs::EIGER: originally2D = true; break;
case slsDetectorDefs::GOTTHARD: originally2D = false; break; case slsDetectorDefs::GOTTHARD: originally2D = false; break;
@ -77,7 +78,7 @@ void qDrawPlot::SetupWidgetWindow(){
//initialization //initialization
data_pause_over = true;//to get the first image data_pause_over = true;
currentMeasurement = 0; currentMeasurement = 0;
currentFrame = 0; currentFrame = 0;
@ -89,7 +90,7 @@ void qDrawPlot::SetupWidgetWindow(){
acquisitionPeriod = 0; acquisitionPeriod = 0;
exposureTime = 0; exposureTime = 0;
currentFileIndex = 0; currentFileIndex = 0;
currentFrameIndex = 0; currentFrameIndex = -1;
stop_signal = 0; stop_signal = 0;
pthread_mutex_init(&last_image_complete_mutex,NULL); pthread_mutex_init(&last_image_complete_mutex,NULL);
@ -120,7 +121,6 @@ void qDrawPlot::SetupWidgetWindow(){
pixelWidth = 0; pixelWidth = 0;
lastImageNumber = 0; lastImageNumber = 0;
last_plot_number = 0;
nHists = 0; nHists = 0;
histNBins = 0; histNBins = 0;
@ -234,8 +234,6 @@ void qDrawPlot::SetupWidgetWindow(){
boxPlot->setAlignment(Qt::AlignHCenter); boxPlot->setAlignment(Qt::AlignHCenter);
boxPlot->setFont(QFont("Sans Serif",11,QFont::Normal)); boxPlot->setFont(QFont("Sans Serif",11,QFont::Normal));
boxPlot->setTitle("Sample Plot"); boxPlot->setTitle("Sample Plot");
plot_update_timer = new QTimer(this);
connect(plot_update_timer, SIGNAL(timeout()), this, SLOT(UpdatePlot()));
data_pause_timer = new QTimer(this); data_pause_timer = new QTimer(this);
connect(data_pause_timer, SIGNAL(timeout()), this, SLOT(UpdatePause())); connect(data_pause_timer, SIGNAL(timeout()), this, SLOT(UpdatePause()));
@ -345,6 +343,7 @@ void qDrawPlot::SetupWidgetWindow(){
void qDrawPlot::Initialization(){ void qDrawPlot::Initialization(){
connect(this, SIGNAL(UpdatePlotSignal()), this, SLOT(UpdatePlot()));
connect(this, SIGNAL(InterpolateSignal(bool)),plot2D, SIGNAL(InterpolateSignal(bool))); connect(this, SIGNAL(InterpolateSignal(bool)),plot2D, SIGNAL(InterpolateSignal(bool)));
connect(this, SIGNAL(ContourSignal(bool)), plot2D, SIGNAL(ContourSignal(bool))); connect(this, SIGNAL(ContourSignal(bool)), plot2D, SIGNAL(ContourSignal(bool)));
connect(this, SIGNAL(LogzSignal(bool)), plot2D, SLOT(SetZScaleToLog(bool))); connect(this, SIGNAL(LogzSignal(bool)), plot2D, SLOT(SetZScaleToLog(bool)));
@ -374,7 +373,6 @@ void qDrawPlot::StartStopDaqToggle(bool stop_if_running){
// Reset Current Measurement // Reset Current Measurement
currentMeasurement = 0; currentMeasurement = 0;
emit SetCurrentMeasurementSignal(currentMeasurement); emit SetCurrentMeasurementSignal(currentMeasurement);
//to get the first image
data_pause_over = true; data_pause_over = true;
//in case of error message //in case of error message
alreadyDisplayed = false; alreadyDisplayed = false;
@ -417,7 +415,7 @@ void qDrawPlot::StartStopDaqToggle(bool stop_if_running){
fileName = QString(myDet->getFileName().c_str()); fileName = QString(myDet->getFileName().c_str());
//update index //update index
currentFileIndex = myDet->getFileIndex(); currentFileIndex = myDet->getFileIndex();
currentFrameIndex = 0; currentFrameIndex = -1;
StartDaq(true); StartDaq(true);
running=!running; running=!running;
@ -441,13 +439,11 @@ void qDrawPlot::StartDaq(bool start){
#endif #endif
ResetDaqForGui(); ResetDaqForGui();
StartDaqForGui(); StartDaqForGui();
UpdatePlot();
}else{ }else{
#ifdef VERBOSE #ifdef VERBOSE
cout << "Start Daq(false) function" << endl; cout << "Start Daq(false) function" << endl;
#endif #endif
StopDaqForGui(); StopDaqForGui();
StopUpdatePlot();
} }
} }
@ -459,7 +455,6 @@ int qDrawPlot::ResetDaqForGui(){
if(!StopDaqForGui()) return 0; if(!StopDaqForGui()) return 0;
cout << "Resetting image number" << endl; cout << "Resetting image number" << endl;
lastImageNumber = 0; lastImageNumber = 0;
last_plot_number = -1;
return 1; return 1;
} }
@ -642,6 +637,7 @@ void qDrawPlot::SetupMeasurement(){
// Defaults // Defaults
if(!running) if(!running)
stop_signal = 0; stop_signal = 0;
currentFrameIndex = -1;
currentFrame = 0; currentFrame = 0;
//for 2d scans //for 2d scans
currentScanDivLevel = 0; currentScanDivLevel = 0;
@ -778,11 +774,11 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){
#endif #endif
// secondary title necessary to differentiate between frames when not saving data // secondary title necessary to differentiate between frames when not saving data
char temp_title[2000]; char temp_title[2000];
//findex is used because in the receiver, you cannot know the frame index as many frames are in 1 file. //findex is the frame index given by receiver, cannot be derived from file name
if(fIndex!=-1){ if(fIndex!=-1){
currentFrameIndex=fIndex; currentFrameIndex=fIndex;
sprintf(temp_title,"#%d",fIndex); sprintf(temp_title,"#%d",fIndex);
if((myDet->getDetectorsType()==slsDetectorDefs::EIGER) && (subIndex != -1)) if((detType==slsDetectorDefs::EIGER) && (subIndex != -1))
sprintf(temp_title,"#%d %d",fIndex,subIndex); sprintf(temp_title,"#%d %d",fIndex,subIndex);
}else{ }else{
if(fileSaveEnable) strcpy(temp_title,"#%d"); if(fileSaveEnable) strcpy(temp_title,"#%d");
@ -792,7 +788,8 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){
sprintf(temp_title,"#%d %d",fIndex,subIndex); sprintf(temp_title,"#%d %d",fIndex,subIndex);
//Plot Disabled //Plot Disabled
if(!plotEnable) return 0; if(!plotEnable)
return 0;
//angle plotting //angle plotting
if(anglePlot){ if(anglePlot){
@ -851,11 +848,13 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){
#ifdef VERYVERBOSE #ifdef VERYVERBOSE
cout << "Exiting GetData Function " << endl; cout << "Exiting GetData Function " << endl;
#endif #endif
emit UpdatePlotSignal();
return 0; return 0;
} }
//nth frame or delay decision (data copied later on)
if (detType == slsDetectorDefs::MYTHEN){
//Nth Frame //Nth Frame
if(frameFactor){ if(frameFactor){
//plots if numfactor becomes 0 //plots if numfactor becomes 0
@ -867,8 +866,6 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){
} }
} }
//Not Nth Frame, to check time out(NOT for Scans and angle plots) //Not Nth Frame, to check time out(NOT for Scans and angle plots)
else{ else{
if (scanArgument == qDefs::None) { if (scanArgument == qDefs::None) {
@ -877,11 +874,10 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){
return 0; return 0;
} }
data_pause_over=false; data_pause_over=false;
data_pause_timer->start((int)(PLOT_TIMER_MS/2)); data_pause_timer->start((int)(timerValue));
}
} }
} }
//if scan //if scan
@ -899,6 +895,7 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){
UnlockLastImageArray(); UnlockLastImageArray();
currentFrame++; currentFrame++;
currentScanDivLevel++; currentScanDivLevel++;
emit UpdatePlotSignal();
return 0; return 0;
} }
//file index //file index
@ -916,6 +913,7 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){
UnlockLastImageArray(); UnlockLastImageArray();
currentFrame++; currentFrame++;
currentScanDivLevel++; currentScanDivLevel++;
emit UpdatePlotSignal();
return 0; return 0;
} }
//level0 //level0
@ -939,6 +937,7 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){
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(); UnlockLastImageArray();
currentFrame++; currentFrame++;
emit UpdatePlotSignal();
return 0; return 0;
} }
//level1 //level1
@ -962,13 +961,15 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){
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(); UnlockLastImageArray();
currentFrame++; currentFrame++;
emit UpdatePlotSignal();
return 0; return 0;
} }
//normal measurement or 1d scans //normal measurement or 1d scans
if(!pthread_mutex_trylock(&(last_image_complete_mutex))){ 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);
// only if you got the lock, do u need to remember lastimagenumber to plot // only if you got the lock, do u need to remember lastimagenumber to plot
@ -1148,17 +1149,18 @@ int qDrawPlot::GetData(detectorData *data,int fIndex, int subIndex){
} }
} }
pthread_mutex_unlock(&(last_image_complete_mutex)); /* pthread_mutex_unlock(&(last_image_complete_mutex));
} }*/
UnlockLastImageArray();
#ifdef VERYVERBOSE #ifdef VERYVERBOSE
cout<<"currentframe:"<<currentFrame<<"\tcurrentframeindex:"<<currentFrameIndex<<endl; cprintf(BLUE,"currentframe:%d \tcurrentframeindex:%d\n",currentFrame,currentFrameIndex);
#endif #endif
emit UpdatePlotSignal();
currentFrame++; currentFrame++;
} }
//if(frameFactor)
#ifdef VERYVERBOSE #ifdef VERYVERBOSE
cout << "Exiting GetData function" << endl; cout << "Exiting GetData function" << endl;
#endif #endif
@ -1264,10 +1266,12 @@ int qDrawPlot::MeasurementFinished(int currentMeasurementIndex, int fileIndex){
#ifdef VERBOSE #ifdef VERBOSE
cout << "Entering Measurement Finished with currentMeasurement " << currentMeasurementIndex << " and fileIndex " << fileIndex << endl; cout << "Entering Measurement Finished with currentMeasurement " << currentMeasurementIndex << " and fileIndex " << fileIndex << endl;
#endif #endif
//to make sure it plots the last frame before setting lastimagearray all to 0
//if(plot_in_scope==2) //to make sure it plots the last frame
//usleep(5*1000*1000); while(currentFrameIndex!=-1){
//usleep(500*1000); usleep(2000);
}
currentMeasurement = currentMeasurementIndex+1; currentMeasurement = currentMeasurementIndex+1;
currentFileIndex = fileIndex; currentFileIndex = fileIndex;
#ifdef VERBOSE #ifdef VERBOSE
@ -1331,13 +1335,14 @@ void qDrawPlot::UpdatePlot(){
#ifdef VERYVERBOSE #ifdef VERYVERBOSE
cout << "Entering UpdatePlot function" << endl; cout << "Entering UpdatePlot function" << endl;
#endif #endif
plot_update_timer->stop();
// only if no plot isnt enabled // only if no plot isnt enabled
if(plotEnable){ if(plotEnable){
LockLastImageArray(); LockLastImageArray();
//so that it doesnt plot every single thing //so that it doesnt plot every single thing
if(lastImageNumber && lastImageNumber!=last_plot_number){ #ifdef VERYVERBOSE
cprintf(GREEN,"Updating Plot\n");
#endif
//so as to not plot it again and to let measurment finished know its done plotting it
//1-d plot stuff //1-d plot stuff
if(plot_in_scope==1){ if(plot_in_scope==1){
#ifdef VERYVERBOSE #ifdef VERYVERBOSE
@ -1453,20 +1458,12 @@ void qDrawPlot::UpdatePlot(){
if(saveAll) SavePlotAutomatic(); if(saveAll) SavePlotAutomatic();
} }
} }
last_plot_number=lastImageNumber;
//set plot title //set plot title
boxPlot->setTitle(plotTitle); boxPlot->setTitle(plotTitle);
} currentFrameIndex = -1;
UnlockLastImageArray(); UnlockLastImageArray();
} }
//if acq stopped before this line, it continues from here, shouldnt restart plotting timer
if(!stop_signal){
if(!frameFactor)
plot_update_timer->start((int)timerValue);
else
plot_update_timer->start((int)PLOT_TIMER_MS);
}
#ifdef VERYVERBOSE #ifdef VERYVERBOSE
cout << "Exiting UpdatePlot function" << endl; cout << "Exiting UpdatePlot function" << endl;
#endif #endif
@ -1476,17 +1473,6 @@ void qDrawPlot::UpdatePlot(){
//------------------------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------------------------
void qDrawPlot::StopUpdatePlot(){
#ifdef VERYVERBOSE
cout << "Entering StopUpdatePlot()" << endl;
#endif
plot_update_timer->stop();
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
void qDrawPlot::ClonePlot(){ void qDrawPlot::ClonePlot(){
int i; int i;
@ -1732,7 +1718,6 @@ int qDrawPlot::UpdateTrimbitPlot(bool fromDetector,bool Histogram){
LockLastImageArray(); LockLastImageArray();
slsDetectorDefs::detectorType detType = myDet->getDetectorsType();
if(detType == slsDetectorDefs::MYTHEN){ if(detType == slsDetectorDefs::MYTHEN){
//get trimbits //get trimbits
@ -1950,6 +1935,20 @@ void qDrawPlot::ResetAccumulate(){
//------------------------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------------------------
void qDrawPlot::SetPlotTimer(double time){
timerValue = time;
/*if(myDet->setReceiverOnline()==slsDetectorDefs::ONLINE_FLAG){
time = myDet->setReceiverReadTimer(timerValue);
#ifdef VERBOSE
cout << "Receiver read timer set to : " << time << endl;
#endif
qDefs::checkErrorMessage(myDet,"qDrawPlot::SetPlotTimer");
}*/
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
void qDrawPlot::SetFrameFactor(int frame){ void qDrawPlot::SetFrameFactor(int frame){
frameFactor = frame; frameFactor = frame;
if(myDet->setReceiverOnline()==slsDetectorDefs::ONLINE_FLAG){ if(myDet->setReceiverOnline()==slsDetectorDefs::ONLINE_FLAG){