updated number of measurements to be taken from the detector class

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorGui@54 af1100a4-978c-4157-bff7-07162d2ba061
This commit is contained in:
l_maliakal_d 2012-09-10 17:55:44 +00:00
parent b85e03adfd
commit f7078c3700
7 changed files with 253 additions and 166 deletions

View File

@ -94,9 +94,6 @@ public:
* @param stop_if_running is 0 to stop acquisition and 1 to start acquisition
*/
void StartStopDaqToggle(bool stop_if_running=0);
/** Set number of measurements
* @param num number of measurements to be set */
void setNumMeasurements(int num){number_of_measurements = num;};
/** Set frame enabled
* @param enable enable*/
void setFrameEnabled(bool enable){isFrameEnabled = enable;};
@ -168,6 +165,8 @@ int StartDaqForGui() {return StartOrStopThread(1) ? 1:0;}
int StopDaqForGui() {return StartOrStopThread(0) ? 0:1;}
/** Starts/stops Acquisition Thread */
bool StartOrStopThread(bool start);
/** Sets up measurement each time */
void SetupMeasurement();
/** Resets the acquisition parameter like lastimagenumber */
int ResetDaqForGui();
/** The function which is called when start acquisition thread is created */
@ -252,8 +251,6 @@ SlsQt2DPlotLayout* plot2D;
QVector<SlsQtH1D*> plot1D_hists;
/** Number of Measurements */
int number_of_measurements;
/** Current Measurement */
int currentMeasurement;
/** currentFrame */
@ -391,6 +388,8 @@ int scanArgument;
/** enable angle plot */
bool anglePlot;
/** prevents err msg displaying twice when detector stopped, "transmitting" */
bool alreadyDisplayed;

View File

@ -43,7 +43,7 @@ public:
/** To enable expert mode
* @param enable to enable if true
*/
void SetExpertMode(bool enable){expertMode = enable;SetupTimingMode();};
void SetExpertMode(bool enable);
@ -163,8 +163,6 @@ private:
enum{None, Auto, Trigger_Exp_Series, Trigger_Frame, Trigger_Readout, Gated, Gated_Start, Trigger_Window, NumTimingModes};
/** timer to update the progress*/
QTimer *progressTimer;
/** number of measurements*/
int numMeasurement;
/** current measurement */
int currentMeasurement;
/** tool tip variables*/

View File

@ -174,29 +174,30 @@ void qDetectorMain::SetUpDetector(){
//instantiate detector and set window title
myDet = new multiSlsDetector(detID);
string host = myDet->getHostname(detID);
cout<<"online:"<<myDet->setOnline();<<endl;
slsDetector *s = myDet->getSlsDetector(detID);
myDet = new multiSlsDetector();
string host = myDet->getHostname();
//if hostname doesnt exist even in shared memory
if(!host.length()){
#ifdef VERBOSE
cout << endl << "No Detector Connected at id:" << detID << endl;
cout << endl << "No Detector Connected." << endl;
#endif
char cIndex[10];
sprintf(cIndex,"%d",detID);
qDefs::Message(qDefs::CRITICAL,string("No Detector Connected at id : ")+string(cIndex),"Main");
exit(-1);
}//if the detector is not even connected
else if(s->setTCPSocket()==slsDetectorDefs::FAIL){
qDefs::Message(qDefs::CRITICAL,string("The detector ")+host+string(" is not connected. Exiting GUI."),"Main");
cout << "The detector " << host << "is not connected. Exiting GUI." << endl;
qDefs::Message(qDefs::CRITICAL,"No Detectors Connected. ","Main");
exit(-1);
}
else{
slsDetectorDefs::detectorType detType = myDet->getDetectorsType();
//check if the detector is not even connected
string offline = myDet->checkOnline();
if(!offline.empty()){
qDefs::Message(qDefs::CRITICAL,string("<nobr>The detector(s) <b>")+offline+string(" </b> is/are not connected. Exiting GUI.</nobr>"),"Main");
cout << "The detector(s) " << host << " is/are not connected. Exiting GUI." << endl;
exit(-1);
}
// Check if type valid. If not, exit
switch(detType){//digitalDetector decides if trimbits should be shown
slsDetectorDefs::detectorType detType = myDet->getDetectorsType();
switch(detType){
//digitalDetector decides if trimbits should be shown
case slsDetectorDefs::MYTHEN: digitalDetector = true; break;
case slsDetectorDefs::EIGER: digitalDetector = true; break;
case slsDetectorDefs::GOTTHARD: digitalDetector = false;break;
@ -214,7 +215,7 @@ void qDetectorMain::SetUpDetector(){
cout << endl << "Type : " << slsDetectorBase::getDetectorType(detType) << "\nDetector : " << host << endl;
#endif
myDet->setOnline(slsDetectorDefs::ONLINE_FLAG);
}
}

View File

@ -28,6 +28,7 @@ using namespace std;
//-------------------------------------------------------------------------------------------------------------------------------------------------
qDrawPlot::qDrawPlot(QWidget *parent,multiSlsDetector*& detector):
QWidget(parent),myDet(detector){
SetupWidgetWindow();
@ -35,8 +36,10 @@ qDrawPlot::qDrawPlot(QWidget *parent,multiSlsDetector*& detector):
StartStopDaqToggle(); //as default
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
qDrawPlot::~qDrawPlot(){
// Clear plot
Clear1DPlot();
@ -48,13 +51,14 @@ qDrawPlot::~qDrawPlot(){
for(int i=0;i<MAXCloneWindows;i++) delete winClone[i];
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
void qDrawPlot::SetupWidgetWindow(){
#ifdef VERBOSE
cout << "Setting up plot variables" << endl;
#endif
number_of_measurements=1;
currentMeasurement = 0;
stop_signal = 0;
pthread_mutex_init(&last_image_complete_mutex,NULL);
@ -95,6 +99,8 @@ void qDrawPlot::SetupWidgetWindow(){
isFrameEnabled = false;
isTriggerEnabled = false;
scanArgument = None;
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; }
@ -168,8 +174,10 @@ void qDrawPlot::SetupWidgetWindow(){
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
void qDrawPlot::Initialization(){
connect(this, SIGNAL(InterpolateSignal(bool)),plot2D, SIGNAL(InterpolateSignal(bool)));
connect(this, SIGNAL(ContourSignal(bool)), plot2D, SIGNAL(ContourSignal(bool)));
@ -183,8 +191,10 @@ void qDrawPlot::Initialization(){
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
void qDrawPlot::StartStopDaqToggle(bool stop_if_running){
#ifdef VERYVERBOSE
cout << "Entering StartStopDaqToggle(" << stop_if_running << ")" <<endl;
@ -195,14 +205,17 @@ void qDrawPlot::StartStopDaqToggle(bool stop_if_running){
running=!running;
}else if(!stop_if_running){ //then start
//Do the following only once before each n measurements
//number of measurements
int numMeasurements = (int)myDet->setTimer(slsDetectorDefs::MEASUREMENTS_NUMBER,-1);
// Reset Current Measurement
currentMeasurement = 0;
emit SetCurrentMeasurementSignal(currentMeasurement);
//to get the first image
data_pause_over = true;
//in case of error message
alreadyDisplayed = false;
// Number of Exposures
int numFrames = (isFrameEnabled)*((int)myDet->setTimer(slsDetectorDefs::FRAME_NUMBER,-1));
@ -245,8 +258,10 @@ void qDrawPlot::StartStopDaqToggle(bool stop_if_running){
}
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
void qDrawPlot::StartDaq(bool start){
if(start){
#ifdef VERBOSE
@ -264,8 +279,10 @@ void qDrawPlot::StartDaq(bool start){
}
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
int qDrawPlot::ResetDaqForGui(){
if(!StopDaqForGui()) return 0;
cout << "Resetting image number" << endl;
@ -273,8 +290,10 @@ int qDrawPlot::ResetDaqForGui(){
return 1;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
bool qDrawPlot::StartOrStopThread(bool start){
static bool firstTime = true;
static bool gui_acquisition_thread_running = 0;
@ -291,11 +310,38 @@ bool qDrawPlot::StartOrStopThread(bool start){
//start part
if(start){
progress = 0;
//sets up the measurement parameters
SetupMeasurement();
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);
// 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);
firstTime = false;
// This is set here and later reset to zero when all the plotting is done
// This is manually done instead of keeping track of thread because
// this thread returns immediately after executing the acquire command
gui_acquisition_thread_running=1;
cout << "Started acquiring threaddd:" << endl;
}
pthread_mutex_unlock(&gui_acquisition_start_stop_mutex);
return gui_acquisition_thread_running;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
void qDrawPlot::SetupMeasurement(){
if(myDet->getRunStatus()==slsDetectorDefs::IDLE)
cout<<endl<<endl<<"IDLE"<<endl;
else cout<<endl<<endl<<"ERRORRRRRR: "<<myDet->getRunStatus()<<endl;
// Defaults
progress = 0;
currentFrame = 0;
stop_signal = 0;
histTitle[0] = "";
@ -376,29 +422,12 @@ bool qDrawPlot::StartOrStopThread(bool start){
for(int px=0;px<nPixelsX;px++)
lastImageArray[py*nPixelsX+px] = 0;
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);
// 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);
firstTime = false;
// This is set here and later reset to zero when all the plotting is done
// This is manually done instead of keeping track of thread because
// this thread returns immediately after executing the acquire command
gui_acquisition_thread_running=1;
cout << "Started acquiring threaddd:" << endl;
}
pthread_mutex_unlock(&gui_acquisition_start_stop_mutex);
return gui_acquisition_thread_running;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
void* qDrawPlot::DataStartAcquireThread(void *this_pointer){
cout << "before acquire ...." << endl;
((qDrawPlot*)this_pointer)->myDet->acquire(1);
@ -406,19 +435,24 @@ void* qDrawPlot::DataStartAcquireThread(void *this_pointer){
return this_pointer;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
int qDrawPlot::GetDataCallBack(detectorData *data, void *this_pointer){
((qDrawPlot*)this_pointer)->GetData(data);
return 0;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
int qDrawPlot::GetData(detectorData *data){
#ifdef VERYVERBOSE
cout << "Entering GetDatafunction" << endl;
#endif
cout<<"progress:"<<(int)data->progressIndex<<endl;
if(!stop_signal){
//set title
@ -623,37 +657,50 @@ int qDrawPlot::AcquisitionFinished(double currentProgress,int detectorStatus){
cout << "Entering Acquisition Finished with status " <<
slsDetectorBase::runStatusType((slsDetectorDefs::runStatus(detectorStatus))) << " and progress " << currentProgress << endl;
#endif
//error
if(currentProgress!=100){
//error or stopped
if((stop_signal)||(detectorStatus==slsDetectorDefs::ERROR)){
#ifdef VERBOSE
cout << "Error in Acquisition" << endl;
#endif
//just to be sure
stop_signal = 1;
StartStopDaqToggle(true);
emit AcquisitionErrorSignal();
}
//normal stop
else if(!stop_signal){
currentMeasurement++;
cout<<"currentMeasurement:"<<currentMeasurement<<endl;
// To start the next measurement
if(currentMeasurement!=number_of_measurements){
emit SetCurrentMeasurementSignal(currentMeasurement);
StopDaqForGui();
StartDaq(true);
}// if all the measurements are over
else{
//all measurements are over
if(currentProgress==100){
#ifdef VERBOSE
cout << "Acquisition Finished" << endl;
#endif
StartStopDaqToggle(true);
emit UpdatingPlotFinished();
}
else{//next measurement
currentMeasurement++;
#ifdef VERBOSE
cout << "currentMeasurement:" << currentMeasurement << endl;
#endif
emit SetCurrentMeasurementSignal(currentMeasurement);
SetupMeasurement();
}
}
return 0;
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
void qDrawPlot::ShowAcquisitionErrorMessage(){
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");
}
}
//-------------------------------------------------------------------------------------------------------------------------------------------------

View File

@ -346,6 +346,26 @@ void qTabAdvanced::UpdatePlot(){
cout << "Updating Plot" << endl;
#endif
int nPixelsX = myDet->getTotalNumberOfChannels();
int *histXAxis = new int[nPixelsX];
int *histYAxis = new int[100];
for(int i=0;i<nPixelsX;i++) histXAxis[i] = i;
int channelsPerDetector;
/*
for(int det=0;det<myDet->getNumberOfDetectors();det++){
slsDetector *s = myDet->getSlsDetector(det);
channelsPerDetector=s->getTotalNumberOfChannels();
if(s->chanregs){
for(int i=0;i<channelsPerDetector;i++){
memcpy(histYAxis + (det*channelsPerDetector*sizeof(int)),s->chanregs,channelsPerDetector*sizeof(int));
}
}
}
*/
cout<<"histyaxis[500]:"<<histYAxis[500]<<endl;
}

View File

@ -46,7 +46,7 @@ qTabDataOutput::~qTabDataOutput(){
//-------------------------------------------------------------------------------------------------------------------------------------------------
void qTabDataOutput::SetupWidgetWindow(){
void qTabDataOutput::SetupWidgetWindow(){cout<<"in here"<<endl;
// Detector Type
detType=myDet->getDetectorsType();

View File

@ -48,7 +48,7 @@ qTabMeasurement::~qTabMeasurement(){
void qTabMeasurement::SetupWidgetWindow(){
//Number of measurements
numMeasurement=1;
spinNumMeasurements->setValue((int)myDet->setTimer(slsDetectorDefs::MEASUREMENTS_NUMBER,-1));
//Timer to update the progress bar
progressTimer = new QTimer(this);
@ -66,6 +66,7 @@ void qTabMeasurement::SetupWidgetWindow(){
"<nobr> #period#</nobr><br><br>")+
QString("<nobr><font color=\"red\"><b>Acquisition Period</b> should be"
" greater than or equal to <b>Exposure Time</b>.</font></nobr>");
//File Name
dispFileName->setText(QString(myDet->getFileName().c_str()));
//File Index
@ -92,6 +93,24 @@ void qTabMeasurement::SetupWidgetWindow(){
//-------------------------------------------------------------------------------------------------------------------------------------------------
void qTabMeasurement::SetExpertMode(bool enable){
expertMode = enable;
lblNumProbes->setEnabled(enable);
spinNumProbes->setEnabled(enable);
//Number of Probes
if((enable)&&(myDet->getDetectorsType()==slsDetectorDefs::MYTHEN)){
int val = (int)myDet->setTimer(slsDetectorDefs::PROBES_NUMBER,-1);
spinNumProbes->setValue(val);
#ifdef VERBOSE
cout << "Getting number of probes : " << val << endl;
#endif
}
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
void qTabMeasurement::SetupTimingMode(){
//Get timing mode from detector
slsDetectorDefs::externalCommunicationMode mode = myDet->setExternalCommunicationMode();
@ -251,16 +270,6 @@ void qTabMeasurement::Enable(bool enable){
//-------------------------------------------------------------------------------------------------------------------------------------------------
void qTabMeasurement::setNumMeasurements(int val){
#ifdef VERBOSE
cout << "Setting Number of Measurements to " << val << endl;
#endif
numMeasurement = val;
myPlot->setNumMeasurements(val);
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
void qTabMeasurement::setFileName(const QString& fName){
myDet->setFileName(fName.toAscii().data());
#ifdef VERBOSE
@ -302,13 +311,13 @@ void qTabMeasurement::startStopAcquisition(){
#ifdef VERBOSE
cout << "Stopping Acquisition" << endl<< endl;
#endif
emit StopSignal();
myDet->stopAcquisition();
progressTimer->stop();
btnStartStop->setText("Start");
btnStartStop->setIcon(*iconStart);
btnStartStop->setChecked(false);
Enable(1);
emit StopSignal();
}
}
@ -342,7 +351,8 @@ void qTabMeasurement::SetCurrentMeasurement(int val){
void qTabMeasurement::UpdateProgress(){
progressBar->setValue((int)(((currentMeasurement*100)+(myPlot->GetProgress()))/numMeasurement));
//progressBar->setValue((int)(((currentMeasurement*100)+(myPlot->GetProgress()))/spinNumMeasurements->value()));
progressBar->setValue((int)myPlot->GetProgress());
lblProgressIndex->setText(QString::number(myDet->getFileIndex()));
}
@ -350,12 +360,22 @@ void qTabMeasurement::UpdateProgress(){
//-------------------------------------------------------------------------------------------------------------------------------------------------
void qTabMeasurement::setNumMeasurements(int val){
myDet->setTimer(slsDetectorDefs::MEASUREMENTS_NUMBER,val);
#ifdef VERBOSE
cout << "Setting Number of Measurements to " << (int)myDet->setTimer(slsDetectorDefs::MEASUREMENTS_NUMBER,-1) << endl;
#endif
}
//-------------------------------------------------------------------------------------------------------------------------------------------------
void qTabMeasurement::setNumFrames(int val){
myDet->setTimer(slsDetectorDefs::FRAME_NUMBER,val);
#ifdef VERBOSE
cout << "Setting number of frames to " << (int)myDet->setTimer(slsDetectorDefs::FRAME_NUMBER,-1) << endl;
#endif
}
@ -567,11 +587,11 @@ void qTabMeasurement::SetTimingMode(int mode){
}
if(mode!=None){//Number of Probes
if((myDet->getDetectorsType()==slsDetectorDefs::MYTHEN)&&(expertMode)){
//Number of Probes
if((expertMode)&&(myDet->getDetectorsType()==slsDetectorDefs::MYTHEN)){
lblNumProbes->setEnabled(true); spinNumProbes->setEnabled(true);
}
}
//To disconnect all the signals before changing their values
DeInitialization();
@ -703,6 +723,8 @@ void qTabMeasurement::EnableFileWrite(bool enable){
void qTabMeasurement::Refresh(){
//Number of measurements
spinNumMeasurements->setValue((int)myDet->setTimer(slsDetectorDefs::MEASUREMENTS_NUMBER,-1));
//File Name
dispFileName->setText(QString(myDet->getFileName().c_str()));
//File Index