From 73152572a5327732672a081d3fd8be68ead64da1 Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Tue, 21 Aug 2012 16:52:41 +0000 Subject: [PATCH] a rough idea of a scan is implemented with all frames git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorGui@37 af1100a4-978c-4157-bff7-07162d2ba061 --- slsDetectorGui/include/qDrawPlot.h | 12 +- slsDetectorGui/include/qTabPlot.h | 6 + slsDetectorGui/slsDetectorGui.pro | 2 +- slsDetectorGui/src/qDrawPlot.cpp | 202 ++++++++++++++--------------- slsDetectorGui/src/qTabPlot.cpp | 105 +++++++++++---- 5 files changed, 185 insertions(+), 142 deletions(-) diff --git a/slsDetectorGui/include/qDrawPlot.h b/slsDetectorGui/include/qDrawPlot.h index d8aceb9a1..e269a1bd4 100644 --- a/slsDetectorGui/include/qDrawPlot.h +++ b/slsDetectorGui/include/qDrawPlot.h @@ -126,6 +126,8 @@ void SavePlot(); void SetPersistency(int val); /** sets style of plot to dotted */ void SetDottedPlot(bool enable){plotDotted = enable;}; +/** sets the scan argument to prepare the plot*/ +void SetScanArgument(int scanArg){scanArgument = scanArg;}; @@ -166,10 +168,7 @@ static void* DataStartAcquireThread(void *this_pointer); static int GetDataCallBack(detectorData *data, void *this_pointer); /** This is called by the GetDataCallBack function to copy the data */ int GetData(detectorData *data); -/** This is called by the detector class to copy the scan data it jus acquired */ -static int GetScanDataCallBack(detectorData *data, void *this_pointer); -/** This is called by the GetDataCallBack function to copy the scan data */ -int GetScanData(detectorData *data); + @@ -195,7 +194,7 @@ void UpdatePause(){data_pause_over=true;}; - +private: /** The sls detector object */ multiSlsDetector *myDet; @@ -329,7 +328,8 @@ bool isFrameEnabled; bool isTriggerEnabled; /** scan arguments*/ -enum scanArguments{None,Level0,Level1,FileIndex,AllFrames}; +enum scanArgumentList{None,Level0,Level1,FileIndex,AllFrames}; +int scanArgument; diff --git a/slsDetectorGui/include/qTabPlot.h b/slsDetectorGui/include/qTabPlot.h index c161d3456..0d75a9d76 100644 --- a/slsDetectorGui/include/qTabPlot.h +++ b/slsDetectorGui/include/qTabPlot.h @@ -19,6 +19,7 @@ class qDrawPlot; #include #include + /** *@short sets up the Plot parameters */ @@ -70,6 +71,11 @@ private: static QString defaultImageYAxisTitle; static QString defaultImageZAxisTitle; + /** scans */ + static const QString modeNames[5]; + + + /** methods */ /** Sets up the widget */ diff --git a/slsDetectorGui/slsDetectorGui.pro b/slsDetectorGui/slsDetectorGui.pro index c7593e21e..a57c8e744 100644 --- a/slsDetectorGui/slsDetectorGui.pro +++ b/slsDetectorGui/slsDetectorGui.pro @@ -6,7 +6,7 @@ UI_HEADERS_DIR = forms/include RESOURCES += icons.qrc -DEFINES += VERBOSE DACS_INT VERYVERBOSE +DEFINES += VERBOSE DACS_INT #VERYVERBOSE target.path += $(DESTDIR) diff --git a/slsDetectorGui/src/qDrawPlot.cpp b/slsDetectorGui/src/qDrawPlot.cpp index dcf77f9e1..bd54aac77 100644 --- a/slsDetectorGui/src/qDrawPlot.cpp +++ b/slsDetectorGui/src/qDrawPlot.cpp @@ -86,6 +86,7 @@ void qDrawPlot::SetupWidgetWindow(){ data_pause_over = true;//to get the first image isFrameEnabled = false; isTriggerEnabled = false; + scanArgument = None; // This is so that it initially stop and plots running = 1; for(int i=0;igetPositions(); numPos = ((numPos==0)?1:numPos); + int numScan0 = myDet->getScanSteps(0); numScan0 = ((numScan0==0)?1:numScan0); + int numScan1 = myDet->getScanSteps(1); numScan1 = ((numScan1==0)?1:numScan1); + + number_of_exposures = number_of_exposures * numPos * numScan0 * numScan1; cout << "\tNumber of Exposures:" << number_of_exposures << endl; + + // ExposureTime exposureTime= ((double)(myDet->setTimer(slsDetectorDefs::ACQUISITION_TIME,-1))*1E-9); cout << "\tExposure Time:" << setprecision (10) << exposureTime << endl; @@ -253,8 +268,15 @@ bool qDrawPlot::StartOrStopThread(bool start){ stop_signal = 0; oldFrameNumber = 0; histNBins = nPixelsX; - if(!image_data) image_data = new double[nPixelsX*nPixelsY]; - if(!lastImageArray) lastImageArray = new double[nPixelsX*nPixelsY]; + + /**delete it if it exists and create again and for originally 1d, initalize it with all 0*/ + if(image_data) delete [] image_data; + image_data = new double[nPixelsY*nPixelsX]; + //if(!image_data) image_data = new double[nPixelsY*nPixelsX]; + //if(!lastImageArray) lastImageArray = new double[nPixelsY*nPixelsX]; + if(lastImageArray) delete [] lastImageArray; + lastImageArray = new double[nPixelsY*nPixelsX]; + if(!histXAxis) histXAxis = new double [nPixelsX]; for(unsigned int px=0;pxstart((int)(PLOT_TIMER_MS/2)); - }//if frame factor or last frame of last measurement... for all other factors, RETURN - else{ - if(((currentFrame+1==number_of_exposures)&&(currentMeasurement+1==number_of_measurements)) - ||(!((currentFrame)%frameFactor))) - oldCopy = false;//if this works, then we forget old data - else{ - //lastImageNumber= currentFrame+1; - currentFrame++; - currentIndex++; - progress=(int)data->progressIndex; - //if theres an old copy, try to get lock again - if(oldCopy){ -#ifdef VERBOSE - cout << "Copying old data: " << oldFrameNumber << endl; -#endif - if(!pthread_mutex_trylock(&(last_image_complete_mutex))){ - char temp_title[2000]; - // only if you got the lock, do u need to remember lastimagenumber to plot - lastImageNumber= currentFrame; - //1d - if(plot_in_scope==1){ - // Titles - sprintf(temp_title,"Frame Index%d",oldFrameNumber); histTitle[0] = temp_title; - // copy data//memcpy(histXAxis, xvalues,nPixelsX*sizeof(double)); - for(int i=currentPersistency;i>0;i--) - memcpy(histYAxis[i],yvalues[i-1],nPixelsX*sizeof(double)); - memcpy(histYAxis[0],yvalues[0],nPixelsX*sizeof(double)); - }//2d - else{ - // Titles - sprintf(temp_title,"Image Index %d",oldFrameNumber); - imageTitle = temp_title; - // copy data - //memcpy(lastImageArray,image_data,nPixelsX*nPixelsY*sizeof(double)); - } - pthread_mutex_unlock(&(last_image_complete_mutex)); - } + /** all frames shouldnt go in here */ + if(scanArgument!=AllFrames){ + //not frame factor + if(!frameFactor){ + //if the time is not over, RETURN + if(!data_pause_over){ + //lastImageNumber= currentFrame+1; + currentFrame++; + currentIndex++; + return 0; + } + data_pause_over=false; + data_pause_timer->start((int)(PLOT_TIMER_MS/2)); + }//if frame factor or last frame of last measurement... for all other factors, RETURN + else{ + if(((currentFrame+1==number_of_exposures)&&(currentMeasurement+1==number_of_measurements)) + ||(!((currentFrame)%frameFactor))) + oldCopy = false;//if this works, then we forget old data + else{ + //lastImageNumber= currentFrame+1; + currentFrame++; + currentIndex++; + progress=(int)data->progressIndex; + //if theres an old copy, try to get lock again + if(oldCopy){ +#ifdef VERBOSE + cout << "Copying old data: " << oldFrameNumber << endl; +#endif + if(!pthread_mutex_trylock(&(last_image_complete_mutex))){ + char temp_title[2000]; + // only if you got the lock, do u need to remember lastimagenumber to plot + lastImageNumber= currentFrame; + //1d + if(plot_in_scope==1){ + // Titles + sprintf(temp_title,"Frame Index%d",oldFrameNumber); histTitle[0] = temp_title; + // copy data//memcpy(histXAxis, xvalues,nPixelsX*sizeof(double)); + for(int i=currentPersistency;i>0;i--) + memcpy(histYAxis[i],yvalues[i-1],nPixelsX*sizeof(double)); + memcpy(histYAxis[0],yvalues[0],nPixelsX*sizeof(double)); + }//2d + else{ + // Titles + sprintf(temp_title,"Image Index %d",oldFrameNumber); + imageTitle = temp_title; + // copy data + //memcpy(lastImageArray,image_data,nPixelsX*nPixelsY*sizeof(double)); + } + pthread_mutex_unlock(&(last_image_complete_mutex)); + } + } + return 0; } - return 0; } } //if plot disabled, RETURN @@ -369,6 +394,21 @@ int qDrawPlot::GetData(detectorData *data){ #ifdef VERYVERBOSE cout << "Reading in image: " << currentIndex << endl; #endif + + //if scan argument is all frames + if(scanArgument==AllFrames){ + if(!pthread_mutex_trylock(&(last_image_complete_mutex))){ + lastImageNumber= currentFrame+1; + char temp_title[2000]; sprintf(temp_title,"Image Index %d",currentIndex); imageTitle = temp_title; + memcpy(lastImageArray+(currentFrame*nPixelsX),data->values,nPixelsX*sizeof(double)); + pthread_mutex_unlock(&(last_image_complete_mutex)); + } + currentFrame++; + currentIndex++; + return 0; + } + + if(!pthread_mutex_trylock(&(last_image_complete_mutex))){ char temp_title[2000]; // only if you got the lock, do u need to remember lastimagenumber to plot @@ -434,61 +474,6 @@ int qDrawPlot::GetData(detectorData *data){ return 0; } - -//------------------------------------------------------------------------------------------------------------------------------------------------- - - -int qDrawPlot::GetScanDataCallBack(detectorData *data, void *this_pointer){ - ((qDrawPlot*)this_pointer)->GetScanData(data); - return 0; -} - - -//------------------------------------------------------------------------------------------------------------------------------------------------- - - -int qDrawPlot::GetScanData(detectorData *data){/* -#ifdef VERYVERBOSE - cout << "Entering GetScanDatafunction"<progressIndex; - //lastImageNumber= currentFrame+1; - currentThrehold++; - return 0; - } - //what comes here has plot enabled AND (frame factor OR data pause over ) - progress=(int)data->progressIndex; - -#ifdef VERYVERBOSE - cout<<"Reading in image: "<values,nPixelsX*sizeof(double)); - - pthread_mutex_unlock(&(last_image_complete_mutex)); - } - currentThrehold++; - - } -#ifdef VERYVERBOSE - cout<<"Exiting GetScanData function"<0&&nPixelsY>0){ @@ -601,7 +587,7 @@ void qDrawPlot::UpdatePlot(){ } // if a measurement is over else{ - currentMeasurement++; + currentMeasurement++;cout<<"currentMeasurement:"<addButton(radioAllFrames,3); // Plot Axis - myPlot->SetPlotTitle(defaultPlotTitle); - dispTitle->setText(defaultPlotTitle); dispTitle->setEnabled(false); dispXAxis->setEnabled(false); dispYAxis->setEnabled(false); @@ -128,13 +127,18 @@ void qTabPlot::SetupWidgetWindow(){ // Depending on whether the detector is 1d or 2d switch(myDet->getDetectorsType()){ - case slsDetectorDefs::MYTHEN: isOrginallyOneD = true; Select1DPlot(true); break; - case slsDetectorDefs::EIGER: isOrginallyOneD = false; Select1DPlot(false);break; - case slsDetectorDefs::GOTTHARD: isOrginallyOneD = true; Select1DPlot(true);break; + case slsDetectorDefs::MYTHEN: isOrginallyOneD = true; break; + case slsDetectorDefs::EIGER: isOrginallyOneD = false; break; + case slsDetectorDefs::GOTTHARD: isOrginallyOneD = true; break; default: cout << "ERROR: Detector Type is Generic" << endl; exit(-1); } + + Select1DPlot(isOrginallyOneD); + + //to check if this should be enabled + EnableScanBox(); } @@ -143,6 +147,8 @@ void qTabPlot::SetupWidgetWindow(){ void qTabPlot::Select1DPlot(bool b){ isOneD = b; + dispTitle->setText(defaultPlotTitle); + myPlot->SetPlotTitle(defaultPlotTitle); if(b){ box1D->show(); box2D->hide(); @@ -169,7 +175,6 @@ void qTabPlot::Select1DPlot(bool b){ myPlot->Select2DPlot(); } - boxScan->setEnabled(false); } @@ -386,11 +391,13 @@ void qTabPlot::SetPlot(){ #endif if(radioNoPlot->isChecked()){ cout << " - No Plot" << endl; - Select1DPlot(isOrginallyOneD); + + //Select1DPlot(isOrginallyOneD); + //if(isOrginallyOneD) {box1D->show(); box2D->hide();} + //if(!isOrginallyOneD){box2D->show(); box1D->hide();} myPlot->EnablePlot(false); //if enable is true, disable everything - if(isOrginallyOneD) {box1D->show(); box1D->setEnabled(false); box2D->hide();} - if(!isOrginallyOneD){box2D->show(); box2D->setEnabled(false); box1D->hide();} + boxSnapshot->setEnabled(false); boxSave->setEnabled(false); boxFrequency->setEnabled(false); @@ -398,10 +405,11 @@ void qTabPlot::SetPlot(){ boxScan->setEnabled(false); }else if(radioDataGraph->isChecked()){ cout << " - DataGraph" << endl; + myPlot->EnablePlot(true); //if enable is true, disable everything - if(isOrginallyOneD) {box1D->show();box1D->setEnabled(true);} else box1D->hide(); - if(!isOrginallyOneD){box2D->show();box2D->setEnabled(true);} else box2D->hide(); + if(isOrginallyOneD) {box1D->show(); box2D->hide();} + if(!isOrginallyOneD) {box2D->show(); box1D->hide();} Select1DPlot(isOrginallyOneD); boxSnapshot->setEnabled(true); boxSave->setEnabled(true); @@ -504,6 +512,9 @@ void qTabPlot::EnableScanBox(int mode,int id){ radioLevel0->setEnabled(mode0); radioLevel1->setEnabled(mode1); }else EnablingNthFrameFunction(enableNFrame); + + //sets the scan argument + SetScanArgument(); } @@ -533,27 +544,67 @@ void qTabPlot::EnablingNthFrameFunction(bool enable){ //------------------------------------------------------------------------------------------------------------------------------------------------- void qTabPlot::SetScanArgument(){ - switch(btnGroupScan->checkedId()){ - //let qdrawplot know which scan argument - //myPlot-> + //as default from histogram and default titles are set here if scanbox is disabled + Select1DPlot(isOrginallyOneD); - //level0 - case 0: - break; + //this function is also called just to update, could be no scan + if(boxScan->isEnabled()){ - //level1 - case 1: - break; + //setting the title according to the scans + QString mainTitle = QString(" Level 0 : ") + modeNames[myDet->getScanMode(0)] + + QString(" | Level 1 : ") + modeNames[myDet->getScanMode(1)] + QString(""); + dispTitle->setText(mainTitle); + myPlot->SetPlotTitle(mainTitle); - //file index - case 2: - break; - //all frames - case 3: - break; - } + //let qdrawplot know which scan argument + myPlot->SetScanArgument(btnGroupScan->checkedId()+1); + /** What happens for 2d????*/ + //settings the x and y titles + switch(btnGroupScan->checkedId()){ + //level0 + case 0: + dispXAxis->setText("Channel Number"); + dispYAxis->setText("Scan Level 0"); + myPlot->SetHistXAxisTitle("Channel Number"); + myPlot->SetHistYAxisTitle("Scan Level 0"); + myPlot->Select1DPlot(); + break; + + //level1 + case 1: + dispXAxis->setText("Channel Number"); + dispYAxis->setText("Scan Level 1"); + myPlot->SetHistXAxisTitle("Channel Number"); + myPlot->SetHistYAxisTitle("Scan Level 1"); + myPlot->Select1DPlot(); + break; + + //file index + case 2: + dispXAxis->setText("Channel Number"); + dispYAxis->setText("File Index"); + myPlot->SetHistXAxisTitle("Channel Number"); + myPlot->SetHistYAxisTitle("File Index"); + myPlot->Select1DPlot(); + break; + + //all frames + case 3: + Select1DPlot(false); + dispXAxis->setText("Channel Number"); + dispYAxis->setText("Threshold"); + dispZAxis->setText("Intensity"); + myPlot->SetImageXAxisTitle("Channel Number"); + myPlot->SetImageYAxisTitle("Threshold"); + myPlot->SetImageZAxisTitle("Intensity"); + myPlot->Select2DPlot(); + break; + } + }else //done here so that it isnt set by default each time + myPlot->SetScanArgument(0); + }