From 039a725c5c0d4148a378e22f7e715a17b973f475 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 28 Jun 2019 11:57:37 +0200 Subject: [PATCH] WIP. removed qServer --- slsDetectorGui/forms/form_detectormain.ui | 1 - slsDetectorGui/include/qDetectorMain.h | 12 - slsDetectorGui/include/qDrawPlot.h | 46 +- slsDetectorGui/include/qServer.h | 47 -- slsDetectorGui/include/qTabMeasurement.h | 6 +- slsDetectorGui/src/qDetectorMain.cpp | 43 +- slsDetectorGui/src/qDrawPlot.cpp | 499 ++++------------------ slsDetectorGui/src/qServer.cpp | 159 ------- slsDetectorGui/src/qTabMeasurement.cpp | 23 +- 9 files changed, 107 insertions(+), 729 deletions(-) delete mode 100755 slsDetectorGui/include/qServer.h delete mode 100755 slsDetectorGui/src/qServer.cpp diff --git a/slsDetectorGui/forms/form_detectormain.ui b/slsDetectorGui/forms/form_detectormain.ui index aaac9ffff..756135ad4 100755 --- a/slsDetectorGui/forms/form_detectormain.ui +++ b/slsDetectorGui/forms/form_detectormain.ui @@ -244,7 +244,6 @@ - diff --git a/slsDetectorGui/include/qDetectorMain.h b/slsDetectorGui/include/qDetectorMain.h index a3ce92e94..a7e24e0dd 100755 --- a/slsDetectorGui/include/qDetectorMain.h +++ b/slsDetectorGui/include/qDetectorMain.h @@ -12,7 +12,6 @@ class qTabSettings; class qTabDebugging; class qTabDeveloper; class qTabMessages; -class qServer; class multiSlsDetector; @@ -35,15 +34,6 @@ class qDetectorMain : public QMainWindow, private Ui::DetectorMainObject { QWidget *parent = 0); ~qDetectorMain(); - /** - * Starts or stops Acquisition From gui client - * @param start 1 for start and 0 to stop - * @returns success or fail - */ - int StartStopAcquisitionFromClient(bool start); - bool isPlotRunning(); - int GetProgress(); - private slots: void EnableModes(QAction *action); void ExecuteUtilities(QAction *action); @@ -57,7 +47,6 @@ class qDetectorMain : public QMainWindow, private Ui::DetectorMainObject { void ResizeMainWindow(bool b); void EnableTabs(); void SetZoomToolTip(bool disable); - void UncheckServer(); protected: void resizeEvent(QResizeEvent *event); @@ -92,7 +81,6 @@ class qDetectorMain : public QMainWindow, private Ui::DetectorMainObject { qTabDebugging* tabDebugging; qTabDeveloper* tabDeveloper; qTabMessages* tabMessages; - qServer* myServer; int isDeveloper; int heightPlotWindow; int heightCentralWidget; diff --git a/slsDetectorGui/include/qDrawPlot.h b/slsDetectorGui/include/qDrawPlot.h index 984404ee9..b5379d899 100755 --- a/slsDetectorGui/include/qDrawPlot.h +++ b/slsDetectorGui/include/qDrawPlot.h @@ -32,14 +32,11 @@ class qDrawPlot : public QWidget { /** Destructor */ ~qDrawPlot(); - // measurement tab - void SetClientInitiated(); - bool GetClientInitiated(); - // main bool isRunning(); // from measurement tabs int GetProgress(); - int GetCurrentFrameIndex(); + int64_t GetCurrentFrameIndex(); + int64_t GetCurrentMeasurementIndex(); // from plot tab void Select1dPlot(bool enable); void SetPlotTitlePrefix(QString title); @@ -57,14 +54,7 @@ class qDrawPlot : public QWidget { void SetZRange(bool isZmin, bool isZmax, double zmin, double zmax); void SetDataCallBack(bool enable); void SetBinary(bool enable, int from = 0, int to = 0); - - - /** Starts or stop acquisition - * Calls startDaq() function - * @param stop_if_running is 0 to stop acquisition and 1 to start - * acquisition - */ - void StartStopDaqToggle(bool stop_if_running = 0); + void StartAcquisition(); public slots: void SetPersistency(int val); @@ -92,13 +82,9 @@ class qDrawPlot : public QWidget { void UpdatePlot(); - void StartDaq(bool start); - void ShowAcquisitionErrorMessage(QString status); signals: void UpdatingPlotFinished(); - void SetCurrentMeasurementSignal(int); - void AcquisitionErrorSignal(QString); void UpdatePlotSignal(); private: @@ -116,11 +102,9 @@ class qDrawPlot : public QWidget { - int StartDaqForGui(); - int StopDaqForGui(); + bool StartOrStopThread(bool start); void SetupMeasurement(); - int ResetDaqForGui(); static void *DataStartAcquireThread(void *this_pointer); static int GetDataCallBack(detectorData *data, int fIndex, int subIndex, void *this_pointer); int GetData(detectorData *data, int fIndex, int subIndex); @@ -146,11 +130,8 @@ class qDrawPlot : public QWidget { QGridLayout *plotLayout{nullptr}; bool is1d{true}; - bool plotEnable{true}; - bool plotRequired{false};/**?? */ - bool running{false}; + bool isRunning{false}; int progress{0}; - bool clientInitiated{false}; // titles QString plotTitle{""}; @@ -210,19 +191,10 @@ class qDrawPlot : public QWidget { double endPixel{0}; double pixelWidth{0}; - int currentMeasurement{0}; - int currentFrame{0}; - int currentFileIndex{0}; - int currentFrameIndex{0}; - pthread_mutex_t lastImageCompleteMutex; - unsigned int lastImageNumber{0}; - int numberofFrames{0}; - double acquisitionPeriod{0}; - double exposureTime{0}; - - /** prevents err msg displaying twice when detector stopped, "transmitting" - */ - bool alreadyDisplayed{false}; + int64_t currentMeasurement{0}; + int64_t currentFrame{0}; + int64_t lastImageNumber{0}; + pthread_mutex_t lastImageCompleteMutex; const static int npixelsx_jctb = 400; int npixelsy_jctb{0}; diff --git a/slsDetectorGui/include/qServer.h b/slsDetectorGui/include/qServer.h deleted file mode 100755 index c6f4e8c71..000000000 --- a/slsDetectorGui/include/qServer.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include "qDefs.h" -#include "ServerSocket.h" -class qDetectorMain; -class ServerInterface2; - -#include -#include - -class qServer : public QWidget { - Q_OBJECT - - public: - qServer(qDetectorMain *t); - ~qServer(); - void CreateServers(); - void DestroyServers(); - - private: - void FunctionTable(); - void DecodeFunction(sls::ServerInterface2 &socket); - void ServerThread(bool isControlServer); - void GetStatus(sls::ServerInterface2 &socket); - void StartAcquisition(sls::ServerInterface2 &socket); - void StopsAcquisition(sls::ServerInterface2 &socket); - void Acquire(sls::ServerInterface2 &socket); - void ExitServer(sls::ServerInterface2 &socket); - - signals: - // to update the Listening to Gui check box - void ServerStoppedSignal(); - - private: - void (qServer::*flist[qDefs::QF_NUM_FUNCTIONS])(sls::ServerInterface2 &socket); - qDetectorMain *mainTab; - bool tcpThreadCreated{false}; - bool killTCPServerThread{false}; - std::future controlStatus; - std::future stopStatus; - int controlPort; - int stopPort; - std::unique_ptr controlSocket{nullptr}; - std::unique_ptr stopSocket{nullptr}; - - -}; diff --git a/slsDetectorGui/include/qTabMeasurement.h b/slsDetectorGui/include/qTabMeasurement.h index e3f721859..94ad4c53a 100755 --- a/slsDetectorGui/include/qTabMeasurement.h +++ b/slsDetectorGui/include/qTabMeasurement.h @@ -15,14 +15,9 @@ public: qTabMeasurement(QWidget *parent, multiSlsDetector* detector, qDrawPlot* plot); ~qTabMeasurement(); - bool GetStartStatus(); - void ClentStartAcquisition(); - int GetProgress(); void Refresh(); public slots: - void SetCurrentMeasurement(int val); - void StopAcquisition(); void UpdateFinished(); private slots: @@ -39,6 +34,7 @@ private slots: void SetRunIndex(int val); void UpdateProgress(); void StartAcquisition(); + void StopAcquisition(); private: void SetupWidgetWindow(); diff --git a/slsDetectorGui/src/qDetectorMain.cpp b/slsDetectorGui/src/qDetectorMain.cpp index 41ee7a75f..db4d92f32 100755 --- a/slsDetectorGui/src/qDetectorMain.cpp +++ b/slsDetectorGui/src/qDetectorMain.cpp @@ -9,7 +9,6 @@ #include "qTabDebugging.h" #include "qTabDeveloper.h" #include "qTabMessages.h" -#include "qServer.h" #include "versionAPI.h" @@ -140,14 +139,8 @@ qDetectorMain::~qDetectorMain() { delete tabDeveloper; if (tabMessages) delete tabMessages; - if (myServer) - delete myServer; } -bool qDetectorMain::isPlotRunning() { return myPlot->isRunning(); } - -int qDetectorMain::GetProgress() { return tabMeasurement->GetProgress(); } - void qDetectorMain::SetUpWidgetWindow() { // Layout @@ -171,7 +164,6 @@ void qDetectorMain::SetUpWidgetWindow() { tabAdvanced = new qTabAdvanced(this, myDet); tabDebugging = new qTabDebugging(this, myDet); tabDeveloper = new qTabDeveloper(this, myDet); - myServer = new qServer(this); // creating the scroll area widgets for the tabs QScrollArea *scroll[NumberOfTabs]; @@ -299,7 +291,6 @@ void qDetectorMain::Initialization() { // When the acquisition is finished, must update the meas tab connect(myPlot, SIGNAL(UpdatingPlotFinished()), this, SLOT(EnableTabs())); connect(myPlot, SIGNAL(UpdatingPlotFinished()), tabMeasurement, SLOT(UpdateFinished())); - connect(myPlot, SIGNAL(SetCurrentMeasurementSignal(int)), tabMeasurement, SLOT(SetCurrentMeasurement(int))); // menubar // Modes Menu @@ -309,8 +300,6 @@ void qDetectorMain::Initialization() { // Help Menu connect(menuHelp, SIGNAL(triggered(QAction *)), this, SLOT(ExecuteHelp(QAction *))); - // server - connect(myServer, SIGNAL(ServerStoppedSignal()), this, SLOT(UncheckServer())); } void qDetectorMain::LoadConfigFile(const std::string fName) { @@ -350,19 +339,8 @@ void qDetectorMain::LoadConfigFile(const std::string fName) { void qDetectorMain::EnableModes(QAction *action) { bool enable; - // listen to gui client - if (action == actionListenGuiClient) { - disconnect(menuModes, SIGNAL(triggered(QAction *)), this, - SLOT(EnableModes(QAction *))); - if (actionListenGuiClient->isChecked()) - myServer->CreateServers(); - else - myServer->DestroyServers(); - connect(menuModes, SIGNAL(triggered(QAction *)), this, - SLOT(EnableModes(QAction *))); - } // Set DebugMode - else if (action == actionDebug) { + if (action == actionDebug) { enable = actionDebug->isChecked(); tabs->setTabEnabled(DEBUGGING, enable); FILE_LOG(logINFO) << "Debug Mode: " @@ -738,22 +716,3 @@ void qDetectorMain::SetZoomToolTip(bool disable) { else dockWidgetPlot->setToolTip(zoomToolTip); } - -int qDetectorMain::StartStopAcquisitionFromClient(bool start) { - FILE_LOG(logINFO) << (start ? "Start" : "Stop") - << " Acquisition From Client"; - - if (start) { - if (tabMeasurement->GetStartStatus() != start) { - tabMeasurement->ClentStartAcquisition(); - } - } else { - tabMeasurement->StopAcquisition(); - } - - return slsDetectorDefs::OK; -} - -void qDetectorMain::UncheckServer() { - actionListenGuiClient->setChecked(false); -} diff --git a/slsDetectorGui/src/qDrawPlot.cpp b/slsDetectorGui/src/qDrawPlot.cpp index 9550169cd..f903793bb 100755 --- a/slsDetectorGui/src/qDrawPlot.cpp +++ b/slsDetectorGui/src/qDrawPlot.cpp @@ -120,12 +120,10 @@ void qDrawPlot::SetupWidgetWindow() { myDet->registerProgressCallback(&(GetProgressCallBack), this); Initialization(); - StartStopDaqToggle(); } void qDrawPlot::Initialization() { connect(this, SIGNAL(UpdatePlotSignal()), this, SLOT(UpdatePlot())); - connect(this, SIGNAL(AcquisitionErrorSignal(QString)), this, SLOT(ShowAcquisitionErrorMessage(QString))); } void qDrawPlot::SetupStatistics() { @@ -273,25 +271,20 @@ void qDrawPlot::SetupPlots() { plotLayout->addWidget(gainplot2d, 0, 4, 1, 1); } - -void qDrawPlot::SetClientInitiated() { - clientInitiated = true; -} - -bool qDrawPlot::GetClientInitiated() { - return clientInitiated; -} - bool qDrawPlot::isRunning() { - return running; + return isRunning; } int qDrawPlot::GetProgress() { return progress; } -int qDrawPlot::GetCurrentFrameIndex() { - return currentFrameIndex; +int64_t qDrawPlot::GetCurrentFrameIndex() { + return currentFrame; +} + +int64_t qDrawPlot::GetCurrentMeasurementIndex() { + return currentMeasurement; } void qDrawPlot::Select1dPlot(bool enable) { @@ -659,26 +652,6 @@ void qDrawPlot::SavePlot() { } } } - - - - - - - - - - - - - - - - - - - - int qDrawPlot::LockLastImageArray() { return pthread_mutex_lock(&lastImageCompleteMutex); @@ -752,7 +725,13 @@ void qDrawPlot::UpdateXYRange() { } } - +void qDrawPlot::StartAcquisition() { + FILE_LOG(logDEBUG) << "Starting Acquisition in qDrawPlot"; + currentMeasurement = 0; + currentFrame = 0; + lastImageNumber = 0; + +} @@ -845,105 +824,35 @@ void qDrawPlot::UpdateXYRange() { - - - -int qDrawPlot::StartDaqForGui() { return StartOrStopThread(1) ? 1 : 0; } - -int qDrawPlot::StopDaqForGui() { return StartOrStopThread(0) ? 0 : 1; } - - void qDrawPlot::StartStopDaqToggle(bool stop_if_running) { #ifdef VERYVERBOSE std::cout << "Entering StartStopDaqToggle(" << stop_if_running << ")\n"; #endif - // static bool running = 1; - if (running) { // stopping - StartDaq(false); - running = !running; - } else if (!stop_if_running) { // then start - // Reset Current Measurement + + if (isRunning) { + + StartOrStopThread(0); + isRunning = !isRunning; + } else if (!stop_if_running) { + currentMeasurement = 0; - emit SetCurrentMeasurementSignal(currentMeasurement); - // in case of error message - alreadyDisplayed = false; + currentFrame = 0; + lastImageNumber = 0; - /* - // Number of Exposures - int numFrames = - (isFrameEnabled)*((int)myDet->setTimer(slsDetectorDefs::FRAME_NUMBER,-1)); - int numTriggers = - (isTriggerEnabled)*((int)myDet->setTimer(slsDetectorDefs::CYCLES_NUMBER,-1)); - numFrames = ((numFrames==0)?1:numFrames); - numTriggers = ((numTriggers==0)?1:numTriggers); - numberofFrames = numFrames * numTriggers; - std::cout << "\tNumber of Frames per Scan/Measurement:" << - numberofFrames <<'\n'; - //get #scansets for level 0 and level 1 - int numScan0 = myDet->getScanSteps(0); numScan0 = - ((numScan0==0)?1:numScan0); int numScan1 = myDet->getScanSteps(1); - numScan1 = ((numScan1==0)?1:numScan1); int - numPos=myDet->getPositions(); - number_of_exposures = numberofFrames * numScan0 * numScan1; - if(anglePlot) number_of_exposures = numScan0 * numScan1;// * - numPos; std::cout << "\tNumber of Exposures Per Measurement:" << - number_of_exposures <<'\n'; - */ - // ExposureTime - exposureTime = - ((double)(myDet->setTimer(slsDetectorDefs::ACQUISITION_TIME, -1)) * - 1E-9); - std::cout << "\tExposure Time:" << std::setprecision(10) << exposureTime - << '\n'; - // Acquisition Period - acquisitionPeriod = - ((double)(myDet->setTimer(slsDetectorDefs::FRAME_PERIOD, -1)) * - 1E-9); - std::cout << "\tAcquisition Period:" << std::setprecision(10) - << acquisitionPeriod << '\n'; - std::cout << "\tFile Index:" << myDet->getFileIndex() << '\n'; + if (!StartOrStopThread(0)) { + std::cout << "Resetting image number" << '\n'; + lastImageNumber = 0; + } + StartOrStopThread(1); - // update file path and file name - fileSavePath = QString(myDet->getFilePath().c_str()); - fileSaveName = QString(myDet->getFileName().c_str()); - // update index - currentFileIndex = myDet->getFileIndex(); - currentFrameIndex = 0; - - StartDaq(true); - running = !running; - - qDefs::checkErrorMessage(myDet, "qDrawPlot::StartStopDaqToggle"); + isRunning = !isRunning; } - /** if this is set during client initation */ - clientInitiated = false; } -void qDrawPlot::StartDaq(bool start) { - if (start) { -#ifdef VERBOSE - std::cout << "Start Daq(true) function" << '\n'; -#endif - ResetDaqForGui(); - StartDaqForGui(); - } else { -#ifdef VERBOSE - std::cout << "Start Daq(false) function" << '\n'; -#endif - StopDaqForGui(); - } -} -int qDrawPlot::ResetDaqForGui() { - if (!StopDaqForGui()) - return 0; - std::cout << "Resetting image number" << '\n'; - lastImageNumber = 0; - return 1; -} bool qDrawPlot::StartOrStopThread(bool start) { #ifdef VERYVERBOSE @@ -1002,7 +911,7 @@ bool qDrawPlot::StartOrStopThread(bool start) { void qDrawPlot::SetScanArgument(int scanArg) { #ifdef VERYVERBOSE std::cout << "SetScanArgument function:" << scanArg - << " running:" << running << '\n'; + << " running:" << isRunning << '\n'; #endif scanArgument = scanArg; @@ -1011,35 +920,6 @@ void qDrawPlot::SetScanArgument(int scanArg) { if (is1d) DetachHists(); - // Number of Exposures - must be calculated here to get npixelsy for - // allframes/frameindex scans - int numFrames = (isFrameEnabled) * - ((int)myDet->setTimer(slsDetectorDefs::FRAME_NUMBER, -1)); - int numTriggers = - (isTriggerEnabled) * - ((int)myDet->setTimer(slsDetectorDefs::CYCLES_NUMBER, -1)); - int numStoragecells = 0; - if (detType == slsDetectorDefs::JUNGFRAU) - numStoragecells = - (int)myDet->setTimer(slsDetectorDefs::STORAGE_CELL_NUMBER, -1); - numFrames = ((numFrames == 0) ? 1 : numFrames); - numTriggers = ((numTriggers == 0) ? 1 : numTriggers); - numStoragecells = ((numStoragecells <= 0) ? 1 : numStoragecells + 1); - numberofFrames = numFrames * numTriggers * numStoragecells; - std::cout << "\tNumber of Frames per Scan/Measurement:" << numberofFrames - << '\n'; - // get #scansets for level 0 and level 1 - int numScan0 = myDet->getScanSteps(0); - numScan0 = ((numScan0 == 0) ? 1 : numScan0); - int numScan1 = myDet->getScanSteps(1); - numScan1 = ((numScan1 == 0) ? 1 : numScan1); - // int numPos=myDet->getPositions(); - - number_of_exposures = numberofFrames * numScan0 * numScan1; - if (anglePlot) - number_of_exposures = numScan0 * numScan1; // * numPos; - std::cout << "\tNumber of Exposures Per Measurement:" << number_of_exposures - << '\n'; maxPixelsY = 0; minPixelsY = 0; @@ -1052,32 +932,6 @@ void qDrawPlot::SetScanArgument(int scanArg) { nPixelsY = npixelsy_jctb; } - // cannot do this in between measurements , so update instantly - if (scanArgument == qDefs::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; - } else if (scanArgument == qDefs::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; - } else if (scanArgument == qDefs::AllFrames) - nPixelsY = number_of_exposures; - else if (scanArgument == qDefs::FileIndex) - nPixelsY = numberofFrames; - if (minPixelsY > maxPixelsY) { double temp = minPixelsY; minPixelsY = maxPixelsY; @@ -1117,81 +971,38 @@ void qDrawPlot::SetScanArgument(int scanArg) { memset(data2d, 0, nPixelsY * nPixelsX * sizeof(double)); memset(gainImage, 0, nPixelsY * nPixelsX * sizeof(double)); - /*for(int py=0;py<(int)nPixelsY;++py) - for(int px=0;px<(int)nPixelsX;++px) { - data2d[py*nPixelsX+px] = 0; - gainImage[py*nPixelsX+px] = 0; - } - */ - // histogram - if (histogram) { - int iloop = 0; - int numSteps = ((histTo - histFrom) / (histSize)) + 1; - std::cout << "numSteps:" << numSteps << " histFrom:" << histFrom - << " histTo:" << histTo << " histSize:" << histSize << endl; - histogramSamples.resize(numSteps); - startPixel = histFrom - (histSize / 2); - std::cout << "startpixel:" << startPixel << endl; - endPixel = histTo + (histSize / 2); - std::cout << "endpixel:" << endPixel << endl; - while (startPixel < endPixel) { - histogramSamples[iloop].interval.setInterval( - startPixel, startPixel + histSize, QwtInterval::ExcludeMaximum); - histogramSamples[iloop].value = 0; - startPixel += histSize; - iloop++; - } - - // print values - std::cout << "Histogram Intervals:" << '\n'; - for (int j = 0; j < histogramSamples.size(); ++j) { - std::cout << j - << ":\tmin:" << histogramSamples[j].interval.minValue() - << "" - "\t\tmax:" - << histogramSamples[j].interval.maxValue() - << "\t\tvalue:" << histogramSamples[j].value << endl; - } - } UnlockLastImageArray(); - qDefs::checkErrorMessage(myDet, "qDrawPlot::SetScanArgument"); } void qDrawPlot::SetupMeasurement() { #ifdef VERYVERBOSE - std::cout << "SetupMeasurement function:" << running << '\n'; + std::cout << "SetupMeasurement function:" << isRunning << '\n'; #endif LockLastImageArray(); #ifdef VERYVERBOSE std::cout << "locklastimagearray\n"; #endif // Defaults - if (!running) + if (!isRunning) plotRequired = 0; currentFrame = 0; // if(!is1d) - if (!running) + if (!isRunning) lastImageNumber = 0; /**Just now */ // initializing 2d array memset(data2d, 0, nPixelsY * nPixelsX * sizeof(double)); memset(gainImage, 0, nPixelsY * nPixelsX * sizeof(double)); - /* - for(int py=0;py<(int)nPixelsY;++py) - for(int px=0;px<(int)nPixelsX;++px) { - data2d[py*nPixelsX+px] = 0; - gainImage[py*nPixelsX+px] = 0; - } - */ + // 1d with no scan if ((!originally2D) && (scanArgument == qDefs::None)) { #ifdef VERYVERBOSE std::cout << "1D\n"; #endif - if (!running) { + if (!isRunning) { maxPixelsY = 100; minPixelsY = 0; startPixel = -0.5; @@ -1207,27 +1018,6 @@ void qDrawPlot::SetupMeasurement() { minPixelsY = 0; } - // all frames - else if (scanArgument == qDefs::AllFrames) { - maxPixelsY = number_of_exposures - 1; - minPixelsY = 0; - if (!running) - nPixelsY = number_of_exposures; - } // frame index - else if (scanArgument == qDefs::FileIndex) { - maxPixelsY = numberofFrames - 1; - minPixelsY = 0; - if (!running) - nPixelsY = numberofFrames; - } // level0 or level1 - else { - currentScanValue = minPixelsY; - if (backwardScanPlot) { - currentScanValue = maxPixelsY; - currentScanDivLevel = nPixelsY - 1; - } - } - // cannot divide by 0 if (nPixelsY == 1) { pixelWidth = 0; @@ -1262,8 +1052,7 @@ void qDrawPlot::SetupMeasurement() { void *qDrawPlot::DataStartAcquireThread(void *this_pointer) { // stream data from receiver to the gui - if (((qDrawPlot *)this_pointer)->myDet->setReceiverOnline() == - slsDetectorDefs::ONLINE_FLAG) { + if (((qDrawPlot *)this_pointer)->myDet->setReceiverOnline() == slsDetectorDefs::ONLINE_FLAG) { // if receiver data up streaming not on, switch it on if (((qDrawPlot *)this_pointer) @@ -1310,15 +1099,9 @@ int qDrawPlot::GetData(detectorData *data, int fIndex, int subIndex) { // set progress progress = (int)data->progressIndex; - // TODO! - // currentFrameIndex = - // fileIOStatic::getIndicesFromFileName(std::string(data->fileSaveName),currentFileIndex); + // currentFrameIndex = fileIOStatic::getIndicesFromFileName(std::string(data->fileSaveName),currentFileIndex); currentFileIndex = data->fileIndex; - // happens if receiver sends a null and empty file name - /*if(std::string(data->fileSaveName).empty()){ - std::cout << "Received empty file name. Exiting function - without updating data for plot." <<'\n'; return -1; - }*/ + #ifdef VERYVERBOSE std::cout << "progress:" << progress << '\n'; #endif @@ -1372,132 +1155,62 @@ int qDrawPlot::GetData(detectorData *data, int fIndex, int subIndex) { // Titles title1d[0] = temp_title; - // histogram - if (histogram) { - resetAccumulate = false; - lastImageNumber = currentFrame + 1; + // Persistency + if (currentPersistency < persistency) + currentPersistency++; + else + currentPersistency = persistency; + nHists = currentPersistency + 1; - int numValues = nPixelsX; - if (originally2D) - numValues = nPixelsX * nPixelsY; + // copy data + for (int i = currentPersistency; i > 0; i--) + memcpy(datay1d[i], datay1d[i - 1], nPixelsX * sizeof(double)); - // clean up graph - if (histogramArgument == qDefs::Intensity) { - for (int j = 0; j < histogramSamples.size(); ++j) { - histogramSamples[j].value = 0; - } - } - - int val = 0; - for (int i = 0; i < numValues; ++i) { - // frequency of intensity - if (histogramArgument == qDefs::Intensity) { - // ignore outside limits - if ((data->values[i] < histFrom) || - (data->values[i] > histTo)) - continue; - // check for intervals, increment if validates - for (int j = 0; j < histogramSamples.size(); ++j) { - if (histogramSamples[j].interval.contains( - data->values[i])) - histogramSamples[j].value += 1; - } - } - // get sum of data pixels - else - val += data->values[i]; - } - - if (histogramArgument != qDefs::Intensity) { - std::cout << "histogramArgument != qDefs::Intensity\n"; - // val /= numValues; - - // //find scan value - // int ci = 0, fi = 0; - // double cs0 = 0, cs1 = 0; - // fileIOStatic::getVariablesFromFileName(std::string(data->fileSaveName), - // ci, fi, cs0, cs1); - - // int scanval = -1; - // if (cs0 != -1) - // scanval = cs0; - // else - // scanval = cs1; - - // //ignore outside limits - // if ((scanval < histFrom) || (scanval > histTo) || - // (scanval == -1)) - // scanval = -1; - // //check for intervals, increment if validates - // for (int j = 0; j < histogramSamples.size(); ++j) { - // if (histogramSamples[j].interval.contains(scanval)) { - // histogramSamples[j].value = val; - // cout << "j:" << j << " scanval:" << scanval << " - // val:" << val << endl; - // } - // } - } - - } - // not histogram - else { - // Persistency - if (currentPersistency < persistency) - currentPersistency++; - else - currentPersistency = persistency; - nHists = currentPersistency + 1; - - // copy data - for (int i = currentPersistency; i > 0; i--) - memcpy(datay1d[i], datay1d[i - 1], nPixelsX * sizeof(double)); - - // recalculating pedestal - if (startPedestalCal) { - // start adding frames to get to the pedestal value - if (pedestalCount < NUM_PEDESTAL_FRAMES) { - for (unsigned int px = 0; px < nPixelsX; ++px) - tempPedestalVals[px] += data->values[px]; - memcpy(datay1d[0], data->values, nPixelsX * sizeof(double)); - pedestalCount++; - } - // calculate the pedestal value - if (pedestalCount == NUM_PEDESTAL_FRAMES) { - cout << "Pedestal Calculated" << '\n'; - for (unsigned int px = 0; px < nPixelsX; ++px) - tempPedestalVals[px] = tempPedestalVals[px] / - (double)NUM_PEDESTAL_FRAMES; - memcpy(pedestalVals, tempPedestalVals, - nPixelsX * sizeof(double)); - startPedestalCal = 0; - } - } - - // normal data - if (((!isPedestal) & (!accumulate) & (!binary)) || - (resetAccumulate)) { + // recalculating pedestal + if (startPedestalCal) { + // start adding frames to get to the pedestal value + if (pedestalCount < NUM_PEDESTAL_FRAMES) { + for (unsigned int px = 0; px < nPixelsX; ++px) + tempPedestalVals[px] += data->values[px]; memcpy(datay1d[0], data->values, nPixelsX * sizeof(double)); - resetAccumulate = false; + pedestalCount++; } - // pedestal or accumulate - else { - double temp; // cannot overwrite cuz of accumulate - for (unsigned int px = 0; px < (nPixelsX * nPixelsY); - ++px) { - temp = data->values[px]; - if (isPedestal) - temp = data->values[px] - (pedestalVals[px]); - if (binary) { - if ((temp >= binaryFrom) && (temp <= binaryTo)) - temp = 1; - else - temp = 0; - } - if (accumulate) - temp += datay1d[0][px]; - // after all processing - datay1d[0][px] = temp; + // calculate the pedestal value + if (pedestalCount == NUM_PEDESTAL_FRAMES) { + cout << "Pedestal Calculated" << '\n'; + for (unsigned int px = 0; px < nPixelsX; ++px) + tempPedestalVals[px] = tempPedestalVals[px] / + (double)NUM_PEDESTAL_FRAMES; + memcpy(pedestalVals, tempPedestalVals, + nPixelsX * sizeof(double)); + startPedestalCal = 0; + } + } + + // normal data + if (((!isPedestal) & (!accumulate) & (!binary)) || + (resetAccumulate)) { + memcpy(datay1d[0], data->values, nPixelsX * sizeof(double)); + resetAccumulate = false; + } + // pedestal or accumulate + else { + double temp; // cannot overwrite cuz of accumulate + for (unsigned int px = 0; px < (nPixelsX * nPixelsY); + ++px) { + temp = data->values[px]; + if (isPedestal) + temp = data->values[px] - (pedestalVals[px]); + if (binary) { + if ((temp >= binaryFrom) && (temp <= binaryTo)) + temp = 1; + else + temp = 0; } + if (accumulate) + temp += datay1d[0][px]; + // after all processing + datay1d[0][px] = temp; } } } @@ -1609,7 +1322,12 @@ int qDrawPlot::AcquisitionFinished(double currentProgress, int detectorStatus) { #ifdef VERBOSE std::cout << "Error in Acquisition\n\n"; #endif - emit AcquisitionErrorSignal(status); + qDefs::Message(qDefs::WARNING, + std::string("The acquisiton has ended abruptly. " + "Current Detector Status: ") + + status.toAscii().constData() + + std::string("."), + "qDrawPlot::ShowAcquisitionErrorMessage"); } #ifdef VERBOSE // all measurements are over @@ -1621,22 +1339,6 @@ int qDrawPlot::AcquisitionFinished(double currentProgress, int detectorStatus) { // this lets the measurement tab know its over, and to enable tabs emit UpdatingPlotFinished(); - // calculate s curve inflection point - int l1 = 0, l2 = 0, j; - if ((histogram) && (histogramArgument != qDefs::Intensity)) { - for (j = 0; j < histogramSamples.size() - 2; ++j) { - l1 = histogramSamples[j + 1].value - histogramSamples[j].value; - l2 = histogramSamples[j + 2].value - histogramSamples[j + 1].value; - if (l1 > l2) { - std::cout << "***** s curve inflectionfound at " - << histogramSamples[j].interval.maxValue() - << "" - "or j at " - << j << " with l1 " << l1 << " and l2 " << l2 << '\n'; - } - } - } - return 0; } @@ -1645,17 +1347,6 @@ int qDrawPlot::GetProgressCallBack(double currentProgress, void *this_pointer) { return 0; } -void qDrawPlot::ShowAcquisitionErrorMessage(QString status) { - if (!alreadyDisplayed) { - alreadyDisplayed = true; - qDefs::Message(qDefs::WARNING, - std::string("The acquisiton has ended abruptly. " - "Current Detector Status: ") + - status.toAscii().constData() + - std::string("."), - "qDrawPlot::ShowAcquisitionErrorMessage"); - } -} int qDrawPlot::GetMeasurementFinishedCallBack(int currentMeasurementIndex, int fileIndex, diff --git a/slsDetectorGui/src/qServer.cpp b/slsDetectorGui/src/qServer.cpp deleted file mode 100755 index 7ff98832a..000000000 --- a/slsDetectorGui/src/qServer.cpp +++ /dev/null @@ -1,159 +0,0 @@ -#include "qServer.h" -#include "qDetectorMain.h" - -#include "ServerInterface2.h" -#include "string_utils.h" -#include "container_utils.h" - -#include -#include -#include - -qServer::qServer(qDetectorMain *t) - : mainTab(t), controlPort(DEFAULT_GUI_PORTNO), stopPort(DEFAULT_GUI_PORTNO + 1), - controlSocket(nullptr), stopSocket(nullptr) { - FILE_LOG(logDEBUG) << "Client Server ready"; -} - -qServer::~qServer() {} - -void qServer::FunctionTable() { - flist[qDefs::QF_GET_DETECTOR_STATUS] = &qServer::GetStatus; - flist[qDefs::QF_START_ACQUISITION] = &qServer::StartAcquisition; - flist[qDefs::QF_STOP_ACQUISITION] = &qServer::StopsAcquisition; - flist[qDefs::QF_START_AND_READ_ALL] = &qServer::Acquire; - flist[qDefs::QF_EXIT_SERVER] = &qServer::ExitServer; -} - -void qServer::DecodeFunction(sls::ServerInterface2 &socket) { - qDefs::qFuncNames fnum; - socket.Receive(fnum); - - if (fnum < 0 || fnum >= qDefs::QF_NUM_FUNCTIONS) { - throw sls::RuntimeError("Unrecognized Function enum " + std::to_string(fnum) + "\n"); - } - - FILE_LOG(logDEBUG1) << "calling function fnum: " << fnum << " (" - << qDefs::getQFunctionNameFromEnum(fnum) << ")"; - (this->*flist[static_cast(fnum)])(socket); - FILE_LOG(logDEBUG1) << "Function " << qDefs::getQFunctionNameFromEnum(fnum) << " finished"; -} - -void qServer::CreateServers() { - if (!tcpThreadCreated) { - FILE_LOG(logINFO) << "Starting Gui Servers"; - tcpThreadCreated = true; - try { - // start control server - controlStatus = std::async(std::launch::async, &qServer::ServerThread, this, true); - FILE_LOG(logDEBUG) << "Gui control server thread created successfully."; - // start stop server - stopStatus = std::async(std::launch::async, &qServer::ServerThread, this, false); - FILE_LOG(logDEBUG) << "Gui stop server thread created successfully."; - - } catch (...) { - std::string mess = "Could not create Gui TCP servers"; - FILE_LOG(logERROR) << mess; - qDefs::Message(qDefs::WARNING, mess, "qServer::CreateServers"); - DestroyServers(); - } - } -} - -void qServer::DestroyServers() { - if (tcpThreadCreated) { - FILE_LOG(logINFO) << "Shutting down Gui TCP Sockets"; - killTCPServerThread = true; - if (controlSocket) - controlSocket->shutDownSocket(); - if (stopSocket) - stopSocket->shutDownSocket(); - controlStatus.wait(); - stopStatus.wait(); - tcpThreadCreated = false; - killTCPServerThread = false; - FILE_LOG(logDEBUG) << "Server threads stopped successfully."; - } -} - -void qServer::ServerThread(bool isControlServer) { - if (isControlServer) { - FILE_LOG(logDEBUG) << "Starting Gui Server (Control port: " << controlPort << ")"; - controlSocket = sls::make_unique(controlPort); - } else { - FILE_LOG(logDEBUG) << "Starting Gui Server (Stop port: " << stopPort << ")"; - stopSocket = sls::make_unique(stopPort); - } - - while (true) { - try{ - auto socket = (isControlServer ? controlSocket->accept() : stopSocket->accept()); - try{ - DecodeFunction(socket); - } catch(const sls::RuntimeError &e) { - - if (strstr(e.what(), "exit")) { - FILE_LOG(logINFO) << "Exiting " << (isControlServer ? "Control" : "Stop") << "Server"; - break; - } - char mess[MAX_STR_LENGTH]; - sls::strcpy_safe(mess, e.what()); - socket.Send(qDefs::FAIL); - socket.Send(mess); - } - } catch (const sls::RuntimeError &e) { - FILE_LOG(logERROR) << "Accept failed"; - } - - // Destroy server - if (killTCPServerThread) { - FILE_LOG(logINFO) << "Exiting " << (isControlServer ? "Control" : "Stop") << "Server"; - break; - } - } - FILE_LOG(logDEBUG) << "Stopped gui server thread"; -} - -void qServer::GetStatus(sls::ServerInterface2 &socket) { - slsDetectorDefs::runStatus status = slsDetectorDefs::ERROR; - int progress = 0; - if (mainTab->isPlotRunning()) - status = slsDetectorDefs::RUNNING; - else - status = slsDetectorDefs::IDLE; - - progress = mainTab->GetProgress(); - - int retvals[2] = {static_cast(status), progress}; - socket.sendResult(retvals); -} - -void qServer::StartAcquisition(sls::ServerInterface2 &socket) { - if (mainTab->StartStopAcquisitionFromClient(true) == slsDetectorDefs::FAIL) { - throw sls::RuntimeError("Could not start acquistion in Gui"); - } - socket.Send(slsDetectorDefs::OK); -} - -void qServer::StopsAcquisition(sls::ServerInterface2 &socket) { - if (mainTab->StartStopAcquisitionFromClient(false) == slsDetectorDefs::FAIL) { - throw sls::RuntimeError("Could not stop acquistion in Gui"); - } - socket.Send(slsDetectorDefs::OK); -} - -void qServer::Acquire(sls::ServerInterface2 &socket) { - if (mainTab->StartStopAcquisitionFromClient(true) == slsDetectorDefs::FAIL) { - throw sls::RuntimeError("Could not start blocking acquistion in Gui"); - } - // blocking - usleep(5000); - while (mainTab->isPlotRunning()) { - usleep(5000); - } - socket.Send(slsDetectorDefs::OK); -} - -void qServer::ExitServer(sls::ServerInterface2 &socket) { - throw sls::RuntimeError("Server exited"); -} \ No newline at end of file diff --git a/slsDetectorGui/src/qTabMeasurement.cpp b/slsDetectorGui/src/qTabMeasurement.cpp index daaa0a8fa..86e9b5445 100755 --- a/slsDetectorGui/src/qTabMeasurement.cpp +++ b/slsDetectorGui/src/qTabMeasurement.cpp @@ -20,21 +20,6 @@ qTabMeasurement::~qTabMeasurement() { delete progressTimer; } -bool qTabMeasurement::GetStartStatus(){ - return (!btnStart->isEnabled()); -} - -void qTabMeasurement::ClentStartAcquisition(){ - StartAcquisition(); - myPlot->SetClientInitiated(); - while (myPlot->GetClientInitiated()) - usleep(500); -} - -int qTabMeasurement::GetProgress(){ - return progressBar->value(); -} - void qTabMeasurement::SetupWidgetWindow() { // palette red = QPalette(); @@ -536,13 +521,6 @@ void qTabMeasurement::SetRunIndex(int val) { } CATCH_HANDLE("Could not set acquisition file index.", "qTabMeasurement::SetRunIndex", this, &qTabMeasurement::GetRunIndex) } -void qTabMeasurement::SetCurrentMeasurement(int val) { - FILE_LOG(logDEBUG) << "Setting Current Measurement"; - if ((val) < spinNumMeasurements->value()) { - lblCurrentMeasurement->setText(QString::number(val)); - } -} - void qTabMeasurement::ResetProgress() { FILE_LOG(logDEBUG) << "Resetting progress"; lblCurrentFrame->setText(QString::number(0)); @@ -554,6 +532,7 @@ void qTabMeasurement::UpdateProgress() { FILE_LOG(logDEBUG) << "Updating progress"; progressBar->setValue(myPlot->GetProgress()); lblCurrentFrame->setText(QString::number(myPlot->GetCurrentFrameIndex())); + lblCurrentMeasurement->setText(QString::number(myPlot->GetCurrentMeasurementIndex())); } int qTabMeasurement::VerifyOutputDirectoryError() {