diff --git a/slsDetectorGui/CMakeLists.txt b/slsDetectorGui/CMakeLists.txt index 4e93e4596..ec1968c31 100755 --- a/slsDetectorGui/CMakeLists.txt +++ b/slsDetectorGui/CMakeLists.txt @@ -1,15 +1,5 @@ set(CMAKE_AUTOMOC ON) -set(ENV{QMAKESPEC} "/afs/psi.ch/intranet/Controls/Software/Trolltech/RHEL7-x86_64/Qt-4.8.2/mkspecs/linux-g++") -set(ENV{PATH} "/afs/psi.ch/intranet/Controls/Software/Trolltech/RHEL7-x86_64/Qt-4.8.2/bin:$PATH") - -link_directories( - /afs/psi.ch/intranet/Controls/Software/Trolltech/RHEL7-x86_64/Qt-4.8.2/lib - /afs/psi.ch/intranet/Controls/Software/Trolltech/RHEL7-x86_64/qwt-6.0.1/lib - /afs/psi.ch/intranet/Controls/Software/Trolltech/RHEL7-x86_64/qwtplot3d/lib - /afs/psi.ch/project/sls_det_software/dhanya_softwareDevelopment/mySoft/slsDetectorPackage/build/bin -) - set(SOURCES slsDetectorPlotting/src/SlsQt1DPlot.cxx slsDetectorPlotting/src/SlsQt1DZoomer.cxx @@ -27,7 +17,6 @@ set(SOURCES src/qTabDebugging.cpp src/qTabDeveloper.cpp src/qTabMessages.cpp - src/qServer.cpp ) set(FORMS @@ -62,7 +51,6 @@ set(HEADERS include/qTabDebugging.h include/qTabDeveloper.h include/qTabMessages.h - include/qServer.h ../slsDetectorSoftware/include ../slsSupportLib/include/versionAPI.h ../slsSupportLib/include/ServerSocket.h @@ -116,22 +104,3 @@ set_target_properties(slsDetectorGui PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) -add_executable(gui_client - client/qClient.h - client/qClient.cpp -) - -target_link_libraries(gui_client PUBLIC - slsProjectOptions - slsProjectWarnings - slsSupportLib - slsDetectorShared - pthread - rt -) - -set_target_properties(gui_client PROPERTIES - RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin -) - -install(TARGETS slsDetectorGui gui_client DESTINATION bin) diff --git a/slsDetectorGui/client/qClient.cpp b/slsDetectorGui/client/qClient.cpp deleted file mode 100755 index b301ba7a4..000000000 --- a/slsDetectorGui/client/qClient.cpp +++ /dev/null @@ -1,124 +0,0 @@ -#include "qClient.h" - -#include "qDefs.h" -#include "ClientSocket.h" -#include "logger.h" -#include "sls_detector_exceptions.h" - -#include -#include - -int main(int argc, char *argv[]) { - qClient *cl = 0; - cl = new qClient(argv[1]); - cl->executeLine(argc - 2, argv + 2); - delete cl; - return 0; -} - -qClient::qClient(char *h) - : controlPort(DEFAULT_GUI_PORTNO), stopPort(DEFAULT_GUI_PORTNO + 1) { - hostname.assign(h); -} - -qClient::~qClient() {} - -void qClient::executeLine(int narg, char *args[]) { - - std::string retval = ""; - std::string cmd = args[0]; - - // validate command structure - if (narg < 1) { - throw sls::RuntimeError("No command parsed. " + printCommands()); - } - - // help - if (cmd == "help") { - retval = printCommands(); - } - - // file name - else if (cmd == "status") { - - if (narg > 1) { - std::string argument = args[1]; - // start acquisition - if (argument == "start") - startAcquisition(); - else if (argument == "stop") - stopAcquisition(); - else { - throw sls::RuntimeError("Could not parse arguments. " + printCommands()); - } - } - retval = getStatus(); - } - - else if (cmd == "acquire") { - startAcquisition(true); - retval = getStatus(); - } - - else if (cmd == "exit") { - exitServer(); - retval.assign("Server exited successfully"); - } - - // unrecognized command - else { - throw sls::RuntimeError("Unrecognized command. " + printCommands()); - } - - // print result - FILE_LOG(logINFO) << cmd << ": " << retval; -} - -std::string qClient::printCommands() { - std::ostringstream os; - os << "\nexit \t exits servers in gui" << std::endl; - os << "status \t gets status of acquisition in gui. - can be running or " - "idle" - << std::endl; - os << "status i starts/stops acquistion in gui-non blocking. i is start " - "or stop" - << std::endl; - os << "acquire starts acquistion in gui-blocking" << std::endl; - return os.str(); -} - -std::string qClient::getStatus() { - int fnum = qDefs::QF_GET_DETECTOR_STATUS; - int retvals[2] = {static_cast(slsDetectorDefs::ERROR), 0}; - - auto client = sls::GuiSocket(hostname, controlPort); - client.sendCommandThenRead(fnum, nullptr, 0, retvals, sizeof(retvals)); - - slsDetectorDefs::runStatus status = static_cast(retvals[0]); - int progress = retvals[1]; - return std::to_string(progress) + std::string("% ") + - slsDetectorDefs::runStatusType(status); -} - -void qClient::startAcquisition(bool blocking) { - int fnum = qDefs::QF_START_ACQUISITION; - if (blocking) - fnum = qDefs::QF_START_AND_READ_ALL; - - auto client = sls::GuiSocket(hostname.c_str(), controlPort); - client.sendCommandThenRead(fnum, nullptr, 0, nullptr, 0); -} - -void qClient::stopAcquisition() { - int fnum = qDefs::QF_STOP_ACQUISITION; - - auto client = sls::GuiSocket(hostname, stopPort); - client.sendCommandThenRead(fnum, nullptr, 0, nullptr, 0); -} - -void qClient::exitServer() { - int fnum = qDefs::QF_EXIT_SERVER; - // closes both control and stop server - auto client = sls::GuiSocket(hostname, controlPort); - client.sendCommandThenRead(fnum, nullptr, 0, nullptr, 0); - } diff --git a/slsDetectorGui/client/qClient.h b/slsDetectorGui/client/qClient.h deleted file mode 100755 index 18db3fe14..000000000 --- a/slsDetectorGui/client/qClient.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include -#include - -class qClient { - - public: - qClient(char *h); - virtual ~qClient(); - void executeLine(int narg, char *args[]); - - private: - std::string printCommands(); - std::string getStatus(); - void startAcquisition(bool blocking = false); - void stopAcquisition(); - void exitServer(); - - std::string hostname; - int controlPort; - int stopPort; -}; diff --git a/slsDetectorGui/include/qCloneWidget.h b/slsDetectorGui/include/qCloneWidget.h index b151caafa..2aad84f10 100755 --- a/slsDetectorGui/include/qCloneWidget.h +++ b/slsDetectorGui/include/qCloneWidget.h @@ -20,44 +20,14 @@ class qCloneWidget : public QMainWindow { public: qCloneWidget(QWidget *parent, int id, QString title, QString xTitle, QString yTitle, QString zTitle, int numDim, - QString filePath, QString fileName, int fileIndex, + QString filePath, QString fileName, int imageIndex, bool displayStats, QString min, QString max, QString sum); ~qCloneWidget(); void SetupWidgetWindow(QString title, QString xTitle, QString yTitle, QString zTitle, int numDim); - - /** - * Get the 1D hist values to plot - * @param nHists Number of graphs in 1D - * @param histNBins Total Number of X axis values/channels in 1D - * @param histXAxis X Axis value in 1D - * @param histYAxis Y Axis value in 1D - * @param histTitle Title for all the graphs in 1D - * @param lines style of plot if lines or dots - * @param markers style of plot markers or not - */ void SetCloneHists(unsigned int nHists, int histNBins, double *histXAxis, std::vector histYAxis, QString histTitle, bool lines, bool markers); - - /** - * Get the 1D hist values to plot for angle plotting - * @param nbinsx number of bins in x axis - * @param xmin minimum in x axis - * @param xmax maximum in x axis - * @param nbinsy number of bins in y axis - * @param ymin minimum in y axis - * @param ymax maximum in y axis - * @param d data - */ - void SetCloneHists2D(int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, double *d); - - /** - * Set the range of the 1d plot - * @param IsXYRange array of x,y,min,max if these values are set - * @param XYRange array of set values of x,y, - * min, max - */ + void SetCloneHists2D(int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, double *d, QString frameIndexTitle); void SetRange(bool IsXYRange[], double XYRange[]); - SlsQt1DPlot *Get1dPlot(); public slots: diff --git a/slsDetectorGui/include/qDrawPlot.h b/slsDetectorGui/include/qDrawPlot.h index ec6a8aff4..66d595918 100755 --- a/slsDetectorGui/include/qDrawPlot.h +++ b/slsDetectorGui/include/qDrawPlot.h @@ -7,9 +7,13 @@ class SlsQtH1D; class SlsQt2DPlotLayout; class qCloneWidget; +class QGridLayout; +class QGroupBox; +class QwtSymbol; + /* #include "qwt_symbol.h" -#include + #include #include #include @@ -32,11 +36,13 @@ class qDrawPlot : public QWidget { /** Destructor */ ~qDrawPlot(); - bool isRunning(); + bool GetIsRunning(); // from measurement tabs int GetProgress(); int64_t GetCurrentFrameIndex(); int64_t GetCurrentMeasurementIndex(); + int GetNumMeasurements(); + void SetNumMeasurements(int val); // from plot tab void Select1dPlot(bool enable); void SetPlotTitlePrefix(QString title); @@ -74,6 +80,7 @@ class qDrawPlot : public QWidget { void CloseClones(); void SaveClones(); void SavePlot(); + void SetStopSignal(); private slots: @@ -93,19 +100,19 @@ class qDrawPlot : public QWidget { int LockLastImageArray(); int UnlockLastImageArray(); void SetStyle(SlsQtH1D *h); - void GetStatistics(double &min, double &max, double &sum, double *array, int size); + void GetStatistics(double &min, double &max, double &sum); void DetachHists(); - void UpdateXYRange(); static void GetProgressCallBack(double currentProgress, void *this_pointer); static void GetAcquisitionFinishedCallBack(double currentProgress, int detectorStatus, void *this_pointer); - static void GetMeasurementFinishedCallBack(int currentMeasurementIndex, void *this_pointer); static void GetDataCallBack(detectorData *data, uint64_t frameIndex, uint32_t subFrameIndex, void *this_pointer); void AcquisitionFinished(double currentProgress, int detectorStatus); - void MeasurementFinished(int currentMeasurementIndex); void GetData(detectorData *data, uint64_t frameIndex, uint32_t subFrameIndex); void toDoublePixelData(double *dest, char *source, int size, int databytes, int dr, double *gaindest = NULL); - void UpdatePlot(); - + void Update1dPlot(double* rawData); + void Update2dPlot(double* rawData, double* gainData); + void Update1dXYRange(); + void Update2dXYRange(); + static const int NUM_PEDESTAL_FRAMES = 20; multiSlsDetector *myDet; slsDetectorDefs::detectorType detType; @@ -123,7 +130,7 @@ class qDrawPlot : public QWidget { bool isRunning{false}; // titles - QString plotTitle_prefix{""}; + QString plotTitlePrefix{""}; QLabel *lblFrameIndexTitle1d{nullptr}; QString xTitle1d{"Channel Number"}; QString yTitle1d{"Counts"}; @@ -138,11 +145,11 @@ class qDrawPlot : public QWidget { unsigned int nHists{1}; double *datax1d{nullptr}; std::vector datay1d; - double *data2d{nullptr}; + double *data2d; //options - bool plotEnable{true}; - bool binary{false}; + bool isPlot{true}; + bool isBinary{false}; int binaryFrom{0}; int binaryTo{0}; int persistency{0}; @@ -151,12 +158,12 @@ class qDrawPlot : public QWidget { bool isMarkers{false}; QwtSymbol *marker{nullptr}; QwtSymbol *noMarker{nullptr}; - bool pedestal{false}; + bool isPedestal{false}; double *pedestalVals{nullptr}; double *tempPedestalVals{nullptr}; int pedestalCount{0}; - bool startPedestalCal{false}; - bool accumulate{false}; + bool resetPedestal{false}; + bool isAccumulate{false}; bool resetAccumulate{false}; QWidget *widgetStatistics{nullptr}; QLabel *lblMinDisp{nullptr}; @@ -166,23 +173,18 @@ class qDrawPlot : public QWidget { std::vector cloneWidgets; QString fileSavePath{"/tmp"}; QString fileSaveName{"Image"}; - double *gainImage{nullptr}; - bool gainDataExtracted{false}; - bool gainDataEnable{false}; - - unsigned int nPixelsX{0}; - unsigned int nPixelsY{0}; - double minPixelsY{0}; - double maxPixelsY{0}; - double startPixel{0}; - double endPixel{0}; - double pixelWidth{0}; + bool isGainDataExtracted{false}; + bool hasGainData{false}; int progress{0}; int64_t currentMeasurement{0}; int64_t currentFrame{0}; pthread_mutex_t lastImageCompleteMutex; + bool hasStopped{false}; + int numMeasurements{0}; + unsigned int nPixelsX{0}; + unsigned int nPixelsY{0}; const static int npixelsx_jctb = 400; int npixelsy_jctb{0}; }; diff --git a/slsDetectorGui/slsDetectorPlotting/include/SlsQt2DPlotLayout.h b/slsDetectorGui/slsDetectorPlotting/include/SlsQt2DPlotLayout.h index b1036be4d..1652cb4fa 100755 --- a/slsDetectorGui/slsDetectorPlotting/include/SlsQt2DPlotLayout.h +++ b/slsDetectorGui/slsDetectorPlotting/include/SlsQt2DPlotLayout.h @@ -1,7 +1,7 @@ #pragma once -#include #include +#include #include "SlsQt2DPlot.h" @@ -9,45 +9,38 @@ class QGridLayout; class QString; class QToolButton; +class SlsQt2DPlotLayout : public QGroupBox { + Q_OBJECT -class SlsQt2DPlotLayout: public QGroupBox{ - Q_OBJECT - -public: - + public: SlsQt2DPlotLayout(QWidget * = NULL); ~SlsQt2DPlotLayout(); - SlsQt2DPlot* GetPlot(){return the_plot;} - void SetXTitle(QString st); - void SetYTitle(QString st); - void SetZTitle(QString st); - void KeepZRangeIfSet(); -// recalculate zmin and zmax from plot and update z range -void SetZRange(bool isMin, bool isMax, double min, double max); -void SetInterpolate(bool enable); -void SetContour(bool enable); -void SetLogz(bool enable); - -private: - QGridLayout* the_layout; - QToolButton* btnInterpolate; - QToolButton* btnContour; - QToolButton* btnLogz; - SlsQt2DPlot* the_plot; + SlsQt2DPlot *GetPlot(); + void SetXTitle(QString st); + void SetYTitle(QString st); + void SetZTitle(QString st); + void SetInterpolate(bool enable); + void SetContour(bool enable); + void SetLogz(bool enable); + void KeepZRangeIfSet(); + // recalculate zmin and zmax from plot and update z range + void SetZRange(bool isMin, bool isMax, double min, double max); + public slots: + void UpdateZRange(double min, double max); + private: void Layout(); + + QGridLayout *the_layout; + QToolButton *btnInterpolate; + QToolButton *btnContour; + QToolButton *btnLogz; + SlsQt2DPlot *the_plot; + bool isLog; double zmin; double zmax; bool isZmin; bool isZmax; - -public slots: -void SetZScaleToLog(bool enable); -void ResetRange(); - -// update z range -void UpdateZRange(double min, double max) ; - }; diff --git a/slsDetectorGui/slsDetectorPlotting/src/SlsQt2DPlotLayout.cxx b/slsDetectorGui/slsDetectorPlotting/src/SlsQt2DPlotLayout.cxx index 67a0053f0..803353e78 100755 --- a/slsDetectorGui/slsDetectorPlotting/src/SlsQt2DPlotLayout.cxx +++ b/slsDetectorGui/slsDetectorPlotting/src/SlsQt2DPlotLayout.cxx @@ -25,14 +25,48 @@ SlsQt2DPlotLayout::~SlsQt2DPlotLayout(){ delete the_plot; } +SlsQt2DPlot* SlsQt2DPlotLayout::GetPlot(){ + return the_plot; +} + +void SlsQt2DPlotLayout::SetXTitle(QString st){ + QwtText title(st); + title.setFont(QFont("Sans Serif",11,QFont::Normal)); + GetPlot()->axisWidget(QwtPlot::xBottom)->setTitle(title); +} + +void SlsQt2DPlotLayout::SetYTitle(QString st){ + QwtText title(st); + title.setFont(QFont("Sans Serif",11,QFont::Normal)); + GetPlot()->axisWidget(QwtPlot::yLeft)->setTitle(title); +} + +void SlsQt2DPlotLayout::SetZTitle(QString st){ + QwtText title(st); + title.setFont(QFont("Sans Serif",11,QFont::Normal)); + GetPlot()->axisWidget(QwtPlot::yRight)->setTitle(title); +} + +void SlsQt2DPlotLayout::SetInterpolate(bool enable) { + the_plot->InterpolatedPlot(enable); +} + +void SlsQt2DPlotLayout::SetContour(bool enable) { + the_plot->showContour(enable); +} + +void SlsQt2DPlotLayout::SetLogz(bool enable) { + isLog = enable; + the_plot->LogZ(enable); + SetZRange(isZmin, isZmax, zmin, zmax); +} + void SlsQt2DPlotLayout::Layout(){ if(the_layout) delete the_layout; the_layout = new QGridLayout(this); the_layout->addWidget(the_plot,2,0,3,3); } - - void SlsQt2DPlotLayout::KeepZRangeIfSet() { UpdateZRange(zmin, zmax); } @@ -47,7 +81,6 @@ void SlsQt2DPlotLayout::SetZRange(bool isMin, bool isMax, double min, double max UpdateZRange(min, max); } - void SlsQt2DPlotLayout::UpdateZRange(double min, double max) { if(isLog) { the_plot->SetZMinimumToFirstGreaterThanZero(); @@ -68,35 +101,3 @@ void SlsQt2DPlotLayout::UpdateZRange(double min, double max) { the_plot->Update(); } -void SlsQt2DPlotLayout::SetInterpolate(bool enable) { - the_plot->InterpolatedPlot(enable); -} - -void SlsQt2DPlotLayout::SetContour(bool enable) { - the_plot->showContour(enable); -} - -void SlsQt2DPlotLayout::SetLogz(bool enable) { - isLog = enable; - the_plot->LogZ(enable); - SetZRange(isZmin, isZmax, zmin, zmax); -} - - -void SlsQt2DPlotLayout::SetXTitle(QString st){ - QwtText title(st); - title.setFont(QFont("Sans Serif",11,QFont::Normal)); - GetPlot()->axisWidget(QwtPlot::xBottom)->setTitle(title); -} - -void SlsQt2DPlotLayout::SetYTitle(QString st){ - QwtText title(st); - title.setFont(QFont("Sans Serif",11,QFont::Normal)); - GetPlot()->axisWidget(QwtPlot::yLeft)->setTitle(title); -} - -void SlsQt2DPlotLayout::SetZTitle(QString st){ - QwtText title(st); - title.setFont(QFont("Sans Serif",11,QFont::Normal)); - GetPlot()->axisWidget(QwtPlot::yRight)->setTitle(title); -} diff --git a/slsDetectorGui/src/qCloneWidget.cpp b/slsDetectorGui/src/qCloneWidget.cpp index c97c98bc2..31cf43c47 100755 --- a/slsDetectorGui/src/qCloneWidget.cpp +++ b/slsDetectorGui/src/qCloneWidget.cpp @@ -23,8 +23,8 @@ #include qCloneWidget::qCloneWidget(QWidget *parent, int id, QString title, QString xTitle, QString yTitle, QString zTitle, - int numDim, QString fPath, QString fName, int fIndex, bool displayStats, QString min, QString max, QString sum) : - QMainWindow(parent), id(id), filePath(fPath), fileName(fName), fileIndex(fIndex), cloneplot1D(nullptr), cloneplot2D(nullptr), + int numDim, QString fPath, QString fName, int iIndex, bool displayStats, QString min, QString max, QString sum) : + QMainWindow(parent), id(id), filePath(fPath), fileName(fName), imageIndex(iIndex), cloneplot1D(nullptr), cloneplot2D(nullptr), marker(nullptr), nomarker(nullptr), mainLayout(nullptr), boxPlot(nullptr), lblHistTitle(nullptr) { // Window title char winTitle[300], currTime[50]; @@ -142,29 +142,29 @@ void qCloneWidget::SetCloneHists(unsigned int nHists, int histNBins, double *his } } -void qCloneWidget::SetCloneHists2D(int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, double *d, QwtText frameIndexTitle) { +void qCloneWidget::SetCloneHists2D(int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, double *d, QString frameIndexTitle) { cloneplot2D->GetPlot()->SetData(nbinsx, xmin, xmax, nbinsy, ymin, ymax, d); cloneplot2D->KeepZRangeIfSet(); - cloneplot2D->setTitle(frameIndexTitle); + cloneplot2D->setTitle(frameIndexTitle.toAscii().constData()); } void qCloneWidget::SetRange(bool IsXYRange[], double XYRange[]) { - double XYRange[4] {0, 0, 0, 0}; - void* plot = cloneplot1D; - if (cloneplot2D) { - plot = cloneplot2D->GetPlot(); + if (cloneplot1D) { + cloneplot1D->SetXMinMax(XYRange[qDefs::XMIN], XYRange[qDefs::XMAX]); + cloneplot1D->SetYMinMax(XYRange[qDefs::YMIN], XYRange[qDefs::YMAX]); + cloneplot1D->Update(); + } else { + cloneplot2D->GetPlot()->SetXMinMax(XYRange[qDefs::XMIN], XYRange[qDefs::XMAX]); + cloneplot2D->GetPlot()->SetYMinMax(XYRange[qDefs::YMIN], XYRange[qDefs::YMAX]); + cloneplot2D->GetPlot()->Update(); } - - plot->SetXMinMax(XYRange[qDefs::XMIN], XYRange[qDefs::XMAX]); - plot->SetYMinMax(XYRange[qDefs::YMIN], XYRange[qDefs::YMAX]); - plot->Update(); } void qCloneWidget::SavePlot() { char cID[10]; sprintf(cID, "%d", id); //title - QString fName = filePath + Qstring('/') + fileName + Qstring('_') + imageIndex + Qstring('_') + QString(NowTime().c_str()) + QString(".png"); + QString fName = filePath + QString('/') + fileName + QString('_') + imageIndex + QString('_') + QString(NowTime().c_str()) + QString(".png"); FILE_LOG(logDEBUG) << "fname:" << fName.toAscii().constData(); //save QImage img(boxPlot->size().width(), boxPlot->size().height(), QImage::Format_RGB32); @@ -187,7 +187,7 @@ int qCloneWidget::SavePlotAutomatic() { char cID[10]; sprintf(cID, "%d", id); //title - QString fName = filePath + Qstring('/') + fileName + Qstring('_') + imageIndex + Qstring('_') + QString(NowTime().c_str()) + QString(".png"); + QString fName = filePath + QString('/') + fileName + QString('_') + imageIndex + QString('_') + QString(NowTime().c_str()) + QString(".png"); FILE_LOG(logDEBUG) << "fname:" << fName.toAscii().constData(); //save QImage img(boxPlot->size().width(), boxPlot->size().height(), QImage::Format_RGB32); diff --git a/slsDetectorGui/src/qDetectorMain.cpp b/slsDetectorGui/src/qDetectorMain.cpp index b0407c09c..12a6d74e0 100755 --- a/slsDetectorGui/src/qDetectorMain.cpp +++ b/slsDetectorGui/src/qDetectorMain.cpp @@ -283,7 +283,7 @@ void qDetectorMain::Initialization() { connect(tabs,SIGNAL(currentChanged(int)), this, SLOT(Refresh(int)));//( QWidget*))); // Measurement tab connect(tabMeasurement, SIGNAL(StartSignal()), this,SLOT(EnableTabs())); - connect(tabMeasurement, SIGNAL(FileNameChangedSignal(QString)), tablPlot, SLOT(SetSaveFileName(QString))); + connect(tabMeasurement, SIGNAL(FileNameChangedSignal(QString)), tabPlot, SLOT(SetSaveFileName(QString))); // Plot tab connect(tabPlot, SIGNAL(DisableZoomSignal(bool)), this, SLOT(SetZoomToolTip(bool))); diff --git a/slsDetectorGui/src/qDrawPlot.cpp b/slsDetectorGui/src/qDrawPlot.cpp index 753cbb32f..9c61b9243 100755 --- a/slsDetectorGui/src/qDrawPlot.cpp +++ b/slsDetectorGui/src/qDrawPlot.cpp @@ -5,6 +5,11 @@ #include "detectorData.h" #include "qCloneWidget.h" +#include +#include +#include +#include +#include "qwt_symbol.h" /* #include @@ -33,20 +38,18 @@ qDrawPlot::~qDrawPlot() { h != hists1d.end(); ++h) delete *h; hists1d.clear(); + if (datax1d) delete [] datax1d; for (auto &it : datay1d) delete [] it; - if (plot1d) - delete plot1d; - if (data2d) delete [] data2d; + + if (plot1d) + delete plot1d; if (plot2d) delete plot2d; - - if (gainImage) - delete [] gainImage; if (gainplot2d) delete gainplot2d; @@ -55,8 +58,6 @@ qDrawPlot::~qDrawPlot() { if (tempPedestalVals) delete [] tempPedestalVals; - StartOrStopThread(0); - for (auto &it : cloneWidgets) { delete it; } @@ -104,7 +105,7 @@ void qDrawPlot::SetupWidgetWindow() { fileSavePath = QString(temp.c_str()); temp = myDet->getFileName(); fileSaveName = QString(temp.c_str()); - } const sls::NonCriticalError &e) { + } catch (const std::exception &e) { qDefs::ExceptionMessage("Could not get file path or file name.", e.what(), "qDrawPlot::SetupWidgetWindow"); fileSavePath = "/tmp"; fileSaveName = "Image"; @@ -114,7 +115,6 @@ void qDrawPlot::SetupWidgetWindow() { SetupPlots(); SetDataCallBack(true); myDet->registerAcquisitionFinishedCallback(&(GetAcquisitionFinishedCallBack), this); - myDet->registerMeasurementFinishedCallback(&(GetMeasurementFinishedCallBack), this); myDet->registerProgressCallback(&(GetProgressCallBack), this); Initialization(); @@ -167,15 +167,13 @@ void qDrawPlot::SetupPlots() { nPixelsX = myDet->getTotalNumberOfChannelsInclGapPixels(slsDetectorDefs::X); nPixelsY = myDet->getTotalNumberOfChannelsInclGapPixels(slsDetectorDefs::Y); if (detType == slsDetectorDefs::MOENCH) { - npixelsy_jctb = (myDet->setTimer(slsDetectorDefs::SAMPLES, -1) * 2) / + npixelsy_jctb = (myDet->setTimer(slsDetectorDefs::ANALOG_SAMPLES, -1) * 2) / 25; // for moench 03 nPixelsX = npixelsx_jctb; nPixelsY = npixelsy_jctb; } FILE_LOG(logINFO) << "nPixelsX:" << nPixelsX; FILE_LOG(logINFO) << "nPixelsY:" << nPixelsY; - startPixel = -0.5; - endPixel = nPixelsY - 0.5; // plot layout layout = new QGridLayout; @@ -205,11 +203,10 @@ void qDrawPlot::SetupPlots() { if (datay1d.size()) { datay1d.clear(); } - datay1d.push_back(new double[nPixelsX]); + datay1d.push_back(new double[nPixelsX]); // default display data for (unsigned int px = 0; px < nPixelsX; ++px) { datax1d[px] = px; - datay1d[0][px] = 0; } // add a hist DetachHists(); @@ -220,7 +217,9 @@ void qDrawPlot::SetupPlots() { // setup 2d plot plot2d = new SlsQt2DPlotLayout(boxPlot); - // default display data + // default display data + if (data2d) + delete[] data2d; data2d = new double[nPixelsY * nPixelsX]; for (unsigned int px = 0; px < nPixelsX; ++px) for (unsigned int py = 0; py < nPixelsY; ++py) @@ -231,7 +230,7 @@ void qDrawPlot::SetupPlots() { sqrt(2); plot2d->setFont(QFont("Sans Serif", 9, QFont::Normal)); plot2d->GetPlot()->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, - startPixel, endPixel, data2d); + -0.5, nPixelsY - 0.5, data2d); plot2d->setTitle(""); plot2d->SetXTitle(xTitle2d); plot2d->SetYTitle(yTitle2d); @@ -240,23 +239,24 @@ void qDrawPlot::SetupPlots() { // gainplot gainplot2d = new SlsQt2DPlotLayout(boxPlot); - gainImage = new double[nPixelsY * nPixelsX]; + double* gainData = new double[nPixelsY * nPixelsX]; for (unsigned int px = 0; px < nPixelsX; ++px) for (unsigned int py = 0; py < nPixelsY; ++py) - gainImage[py * nPixelsX + px] = + gainData[py * nPixelsX + px] = sqrt(pow(0 + 1, 2) * pow(double(px) - nPixelsX / 2, 2) / pow(nPixelsX / 2, 2) / pow(1 + 1, 2) + pow(double(py) - nPixelsY / 2, 2) / pow(nPixelsY / 2, 2)) / sqrt(2); gainplot2d->setFont(QFont("Sans Serif", 9, QFont::Normal)); gainplot2d->GetPlot()->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, - startPixel, endPixel, gainImage); + -0.5, nPixelsY - 0.5, gainData); gainplot2d->setTitle(""); gainplot2d->setAlignment(Qt::AlignLeft); gainplot2d->GetPlot()->enableAxis(0, false); gainplot2d->GetPlot()->enableAxis(1, false); gainplot2d->GetPlot()->enableAxis(2, false); gainplot2d->hide(); + delete [] gainData; // layout of plots plotLayout = new QGridLayout(boxPlot); @@ -266,7 +266,7 @@ void qDrawPlot::SetupPlots() { plotLayout->addWidget(gainplot2d, 0, 4, 1, 1); } -bool qDrawPlot::isRunning() { +bool qDrawPlot::GetIsRunning() { return isRunning; } @@ -282,6 +282,15 @@ int64_t qDrawPlot::GetCurrentMeasurementIndex() { return currentMeasurement; } +int qDrawPlot::GetNumMeasurements() { + return numMeasurements; +} + +void qDrawPlot::SetNumMeasurements(int val) { + if (val >= 0) + numMeasurements = val; +} + void qDrawPlot::Select1dPlot(bool enable) { LockLastImageArray(); if (enable) { @@ -312,7 +321,7 @@ void qDrawPlot::Select1dPlot(bool enable) { void qDrawPlot::SetPlotTitlePrefix(QString title) { LockLastImageArray(); FILE_LOG(logINFO) << "Setting Title to " << title.toAscii().constData(); - plotTitle_prefix = title; + plotTitlePrefix = title; UnlockLastImageArray(); } @@ -416,12 +425,11 @@ void qDrawPlot::SetZRange(bool isZmin, bool isZmax, double zmin, double zmax) { void qDrawPlot::SetDataCallBack(bool enable) { LockLastImageArray(); FILE_LOG(logINFO) << "Setting data call back to " << std::boolalpha << enable << std::noboolalpha; - if (is1d) if (enable) { - plotEnable = true; + isPlot = true; myDet->registerDataCallback(&(GetDataCallBack), this); } else { - plotEnable = false; + isPlot = false; myDet->registerDataCallback(nullptr, this); } UnlockLastImageArray(); @@ -430,7 +438,7 @@ void qDrawPlot::SetDataCallBack(bool enable) { void qDrawPlot::SetBinary(bool enable, int from, int to) { LockLastImageArray(); FILE_LOG(logINFO) << (enable ? "Enabling" : "Disabling") << " Binary output from " << from << " to " << to; - binary = enable; + isBinary = enable; binaryFrom = from; binaryTo = to; UnlockLastImageArray(); @@ -440,6 +448,12 @@ void qDrawPlot::SetPersistency(int val) { LockLastImageArray(); FILE_LOG(logINFO) << "Setting Persistency to " << val; persistency = val; + for(int i = datay1d.size(); i <= val; ++i) { + datay1d[i] = new double [nPixelsX]; + SlsQtH1D* h = new SlsQtH1D("", nPixelsX, datax1d, datay1d[i]); + h->SetLineColor(i); + hists1d.append(h); + } UnlockLastImageArray(); } @@ -467,21 +481,21 @@ void qDrawPlot::Set1dLogY(bool enable) { void qDrawPlot::SetInterpolate(bool enable) { LockLastImageArray(); FILE_LOG(logINFO) << "Setting Interpolate to " << std::boolalpha << enable << std::noboolalpha; - plot2d->SetInterpolate(); + plot2d->SetInterpolate(enable); UnlockLastImageArray(); } void qDrawPlot::SetContour(bool enable) { LockLastImageArray(); FILE_LOG(logINFO) << "Setting Countour to " << std::boolalpha << enable << std::noboolalpha; - plot2d->SetContour(); + plot2d->SetContour(enable); UnlockLastImageArray(); } void qDrawPlot::SetLogz(bool enable) { LockLastImageArray(); FILE_LOG(logINFO) << "Setting Log Z to " << std::boolalpha << enable << std::noboolalpha; - plot2d->SetLogz(); + plot2d->SetLogz(enable); UnlockLastImageArray(); } @@ -502,7 +516,7 @@ void qDrawPlot::RecalculatePedestal() { LockLastImageArray(); FILE_LOG(logDEBUG) << "Recalculating Pedestal"; - startPedestalCal = true; + resetPedestal = true; pedestalCount = 0; if (pedestalVals != nullptr) @@ -521,7 +535,7 @@ void qDrawPlot::RecalculatePedestal() { void qDrawPlot::SetAccumulate(bool enable) { LockLastImageArray(); FILE_LOG(logINFO) << (enable ? "Enabling" : "Disabling") << " Accumulation"; - accumulate = enable; + isAccumulate = enable; UnlockLastImageArray(); } @@ -548,7 +562,7 @@ void qDrawPlot::DisplayStatistics(bool enable) { void qDrawPlot::EnableGainPlot(bool enable) { LockLastImageArray(); FILE_LOG(logINFO) << (enable ? "Enabling" : "Disabling") << " Gain Plot"; - gainDataEnable = enable; + hasGainData = enable; UnlockLastImageArray(); } @@ -559,35 +573,38 @@ void qDrawPlot::SetSaveFileName(QString val) { void qDrawPlot::ClonePlot() { LockLastImageArray(); + int index = 0; if (is1d) { - FILE_LOG(logINDO) << "Cloning 1D Image"; + FILE_LOG(logINFO) << "Cloning 1D Image"; qCloneWidget *q = new qCloneWidget( this, cloneWidgets.size(), boxPlot->title(), xTitle1d, yTitle1d, "", 1, fileSavePath, fileSaveName, currentFrame, displayStatistics, lblMinDisp->text(), lblMaxDisp->text(), lblSumDisp->text()); cloneWidgets.push_back(q); - cloneWidgets[i]->SetCloneHists(nHists, nPixelsX, datax1d, datay1d, + index = cloneWidgets.size(); + cloneWidgets[index]->SetCloneHists(nHists, nPixelsX, datax1d, datay1d, lblFrameIndexTitle1d->text(), isLines, isMarkers); } else { - FILE_LOG(logINDO) << "Cloning 2D Image"; + FILE_LOG(logINFO) << "Cloning 2D Image"; qCloneWidget *q = new qCloneWidget( this, cloneWidgets.size(), boxPlot->title(), xTitle2d, yTitle2d, zTitle2d, 2, fileSavePath, fileSaveName, currentFrame, displayStatistics, lblMinDisp->text(), lblMaxDisp->text(), lblSumDisp->text()); cloneWidgets.push_back(q); - cloneWidgets[i]->SetCloneHists2D(nPixelsX, -0.5, nPixelsX - 0.5, - nPixelsY, startPixel, endPixel, + index = cloneWidgets.size(); + cloneWidgets[index]->SetCloneHists2D(nPixelsX, -0.5, nPixelsX - 0.5, + nPixelsY, -0.5, nPixelsY - 0.5, data2d, plot2d->title()); } if (isXYRange[qDefs::XMIN] || isXYRange[qDefs::XMAX] ||isXYRange[qDefs::YMIN] ||isXYRange[qDefs::YMAX]) { - cloneWidgets[i]->SetRange(isXYRange, XYRange); + cloneWidgets[index]->SetRange(isXYRange, XYRange); } UnlockLastImageArray(); - cloneWidgets[i]->show(); + cloneWidgets[index]->show(); // to remember which all clone widgets were closed - connect(cloneWidgets[i], SIGNAL(CloneClosedSignal(int)), this, SLOT(CloneCloseEvent(int))); + connect(cloneWidgets[index], SIGNAL(CloneClosedSignal(int)), this, SLOT(CloneCloseEvent(int))); } void qDrawPlot::CloseClones() { @@ -599,7 +616,7 @@ void qDrawPlot::CloseClones() { void qDrawPlot::CloneCloseEvent(int id) { FILE_LOG(logDEBUG) << "Closing Clone " << id; - cloneWidgets.erase(cloneWidgets.begin() + id; + cloneWidgets.erase(cloneWidgets.begin() + id); } void qDrawPlot::SaveClones() { @@ -607,7 +624,7 @@ void qDrawPlot::SaveClones() { char errID[200]; std::string errMessage = "The Snapshots with ID's: "; bool success = true; - for (int i = 0; i < cloneWidgets.size(); ++i) { + for (unsigned int i = 0; i < cloneWidgets.size(); ++i) { if (cloneWidgets[i]->SavePlotAutomatic()) { success = false; sprintf(errID, "%d", i); @@ -632,7 +649,7 @@ void qDrawPlot::SavePlot() { QPainter painter(&savedImage); render(&painter); - QString fName = fileSavePath + Qstring('/') + fileSaveName + Qstring('_') + currentFrame + Qstring('_') + QString(NowTime().c_str()) + QString(".png"); + QString fName = fileSavePath + QString('/') + fileSaveName + QString('_') + currentFrame + QString('_') + QString(NowTime().c_str()) + QString(".png"); fName = QFileDialog::getSaveFileName( 0, tr("Save Image"), fName, tr("PNG Files (*.png);;XPM Files(*.xpm);;JPEG Files(*.jpg)"), 0, @@ -659,21 +676,20 @@ int qDrawPlot::UnlockLastImageArray() { void qDrawPlot::SetStyle(SlsQtH1D *h) { h->setStyle(isLines ? QwtPlotCurve::Lines : QwtPlotCurve::Dots); #if QWT_VERSION < 0x060000 - h->setSymbol(isMarkers ? *marker : *nomarker); + h->setSymbol(isMarkers ? *marker : *noMarker); #else - h->setSymbol(isMarkers ? marker : nomarker); + h->setSymbol(isMarkers ? marker : noMarker); #endif } void qDrawPlot::GetStatistics(double &min, double &max, double &sum) { FILE_LOG(logDEBUG) << "Calculating Statistics"; - double *array = data2d; + double* array = data2d; int size = nPixelsX * nPixelsY; if(is1d) { array = datay1d[0]; size = nPixelsX; } - , int size for (int i = 0; i < size; ++i) { if (array[i] < min) min = array[i]; @@ -689,35 +705,9 @@ void qDrawPlot::DetachHists() { } } -void qDrawPlot::UpdateXYRange() { - if (XYRangeChanged) { - void* plot = plot1d; - if (!is1d) { - plot = plot2d->GetPlot(); - } - - if (!isXYRange[qDefs::XMIN] || !isXYRange[qDefs::XMAX]) { - plot->EnableXAutoScaling(); - } else { - if (!isXYRange[qDefs::XMIN]) - XYRange[qDefs::XMIN] = plot->GetXMinimum(); - if (!isXYRange[qDefs::XMAX]) - XYRange[qDefs::XMAX] = plot->GetXMaximum(); - plot->SetXMinMax(XYRange[qDefs::XMIN], XYRange[qDefs::XMAX]); - } - - if (!isXYRange[qDefs::YMIN] || !isXYRange[qDefs::YMAX]) { - plot->EnableYAutoScaling(); - } else { - if (!isXYRange[qDefs::YMIN]) - XYRange[qDefs::YMIN] = plot->GetYMinimum(); - if (!isXYRange[qDefs::YMAX]) - XYRange[qDefs::YMAX] = plot->GetYMaximum(); - plot->SetYMinMax(XYRange[qDefs::YMIN], XYRange[qDefs::YMAX]); - } - XYRangeChanged = false; - plot->Update(); - } +void qDrawPlot::SetStopSignal() { + FILE_LOG(logDEBUG) << "Stop Acquisition signal"; + hasStopped = true; } void qDrawPlot::StartAcquisition() { @@ -726,11 +716,12 @@ void qDrawPlot::StartAcquisition() { progress = 0; currentMeasurement = -1; currentFrame = -1; + hasStopped = false; boxPlot->setTitle("Old Plot"); // check acquiring flag (from previous exit) or if running try{ if (myDet->getAcquiringFlag()) { - if (myDet->getRunStatus() != IDLE) { + if (myDet->getRunStatus() != slsDetectorDefs::IDLE) { qDefs::Message(qDefs::WARNING, "Could not start acquisition as it is already in progress.\nClick start when finished.", "qDrawPlot::StartAcquisition"); isRunning = false; emit AcquireFinishedSignal(); @@ -739,7 +730,7 @@ void qDrawPlot::StartAcquisition() { } CATCH_DISPLAY("Could not get detector stats.", "qDrawPlot::StartAcquisition"); // ensure data streaming in receiver (if plot enabled) - if (plotEnable) { + if (isPlot) { try { if (myDet->enableDataStreamingFromReceiver() != 1) { myDet->enableDataStreamingFromReceiver(1); @@ -747,13 +738,30 @@ void qDrawPlot::StartAcquisition() { } CATCH_DISPLAY("Could not enable data streaming in Receiver.", "qDrawPlot::StartAcquisition"); } + // refixing all the zooming + /* + plot2d->GetPlot()->SetXMinMax(-0.5, nPixelsX + 0.5); + plot2d->GetPlot()->SetYMinMax(-0.5, nPixelsY + 0.5); + plot2d->GetPlot()->SetZoom(-0.5, -0.5, nPixelsX, nPixelsY); + if (boxPlot->title() == "Sample Plot") + plot2d->GetPlot()->UnZoom(); + else + plot2d->GetPlot()->UnZoom(false); +*/ // acquisition in another thread, so signal it emit AcquireSignal(); } void qDrawPlot::AcquireThread() { try { - myDet->acquire(); + for (int i = 0; i < numMeasurements; ++i) { + ++currentMeasurement; + myDet->acquire(); + FILE_LOG(logINFO) << "Measurement finished [ Measurement:" << currentMeasurement << " ]" ; + if (hasStopped) { + break; + } + } } catch (const std::exception &e) { qDefs::ExceptionMessage("Acquire unsuccessful.", e.what(), "qDrawPlot::AcquireThread"); // handle acquire exception @@ -776,18 +784,13 @@ void qDrawPlot::GetAcquisitionFinishedCallBack(double currentProgress, int detec FILE_LOG(logDEBUG) << "Acquisition Finished Call back successful"; } -void qDrawPlot::GetMeasurementFinishedCallBack(int currentMeasurementIndex, void *this_pointer) { - ((qDrawPlot *)this_pointer)->MeasurementFinished(currentMeasurementIndex); - FILE_LOG(logDEBUG) << "Measurement Finished Call back successful"; -} - void qDrawPlot::GetDataCallBack(detectorData *data, uint64_t frameIndex, uint32_t subFrameIndex, void *this_pointer) { ((qDrawPlot *)this_pointer)->GetData(data, frameIndex, subFrameIndex); FILE_LOG(logDEBUG) << "Get Data Call back successful"; } void qDrawPlot::AcquisitionFinished(double currentProgress, int detectorStatus) { - std::string status = slsDetectorDefs::runStatusType(detectorStatus); + std::string status = slsDetectorDefs::runStatusType(static_cast(detectorStatus)); if (detectorStatus == slsDetectorDefs::ERROR) { qDefs::Message(qDefs::WARNING, std::string("The acquisiton has ended abruptly. Current Detector Status: ") + status + std::string("."), "qDrawPlot::AcquisitionFinished"); @@ -800,12 +803,7 @@ void qDrawPlot::AcquisitionFinished(double currentProgress, int detectorStatus) emit AcquireFinishedSignal(); } -void qDrawPlot::MeasurementFinished(int currentMeasurementIndex) { - FILE_LOG(logINFO) << "Measurement finished [ Measurement:" << currentMeasurementIndex << " ]" ; - currentMeasurement = currentMeasurementIndex + 1; -} - -int qDrawPlot::GetData(detectorData *data, uint64_t frameIndex, uint32_t subFrameIndex) { +void qDrawPlot::GetData(detectorData *data, uint64_t frameIndex, uint32_t subFrameIndex) { LockLastImageArray(); FILE_LOG(logDEBUG) @@ -824,282 +822,216 @@ int qDrawPlot::GetData(detectorData *data, uint64_t frameIndex, uint32_t subFram progress = (int)data->progressIndex; currentFrame = frameIndex; - FILE_LOG(logDEBUG) << "[ Progress:" << progress << ", Frame:" << currentFrame << " ]";s - - // title and frame index titles - boxPlot->setTitle(QString(plotTitle_prefix) + QString(data->fileName).section('/', -1);); - QString indexTitle = QString("%1 %2").arg(frameIndex, ((int32_t)subFrameIndex != -1) ? subFrameIndex, ""); + FILE_LOG(logDEBUG) << "[ Progress:" << progress << ", Frame:" << currentFrame << " ]"; //FIXME: check npixelsx and npixelsY (change to this new val, if it is not, and look out for sideeffects) // convert data to double - double* data = new double[nPixelsX * nPixelsY]; - if (gainDataEnable) { - data->dgainvalues = new double[nPixelsX * nPixelsY]; - //FIXMEL: values dont exist1!! - toDoublePixelData(data->values, data->cvalues, nPixelsX * nPixelsY, data->databytes, data->dynamicRange, data->dgainvalues); - } else - toDoublePixelData(data->values, data->cvalues, nPixelsX * nPixelsY, data->databytes, data->dynamicRange); + unsigned int nPixels = nPixelsX * (is1d ? 1 : nPixelsY); + double* rawData = new double[nPixels]; + double* gainData = nullptr; + if (hasGainData) { + gainData = new double[nPixels]; + toDoublePixelData(rawData, data->data, nPixels, data->databytes, data->dynamicRange, gainData); + } else { + toDoublePixelData(rawData, data->data, nPixels, data->databytes, data->dynamicRange); + } + // title and frame index titles + boxPlot->setTitle(plotTitlePrefix + QString(data->fileName.c_str()).section('/', -1)); + QString indexTitle = QString("%1").arg(frameIndex); + if ((int)subFrameIndex != -1) { + indexTitle = QString("%1 %2").arg(frameIndex, subFrameIndex); + } + + // calculate pedestal + if (resetPedestal) { + // add pedestals frames + if (pedestalCount < NUM_PEDESTAL_FRAMES) { + for (unsigned int px = 0; px < nPixels; ++px) + tempPedestalVals[px] += rawData[px]; + pedestalCount++; + } + // calculate the pedestal value + if (pedestalCount == NUM_PEDESTAL_FRAMES) { + FILE_LOG(logINFO) << "Pedestal Calculated after " << NUM_PEDESTAL_FRAMES << " frames"; + for (unsigned int px = 0; px < nPixels; ++px) + tempPedestalVals[px] = tempPedestalVals[px] / (double)NUM_PEDESTAL_FRAMES; + memcpy(pedestalVals, tempPedestalVals, nPixels * sizeof(double)); + resetPedestal = false; + } + } - // 1d if (is1d) { - // Persistency - if (currentPersistency < persistency) - currentPersistency++; - else - currentPersistency = persistency; // when reducing persistency - nHists = currentPersistency + 1; - // FIXME: souldNT WORK BECAUSE NTO COPIED TO DATAY1d yet - if (currentPersistency) { - // allocate if not existing - for (int i = datay1d.size(); i <= val; ++i) { - datay1d.push_back(new double[nPixelsX]); - } - // copy data to previous - for (int i = currentPersistency; i > 0; --i) - memcpy(datay1d[i], datay1d[i - 1], nPixelsX * sizeof(double)); - } lblFrameIndexTitle1d->setText(indexTitle); - - DetachHists(); - plot1d->SetXTitle(xTitle1d.toAscii().constData()); - plot1d->SetYTitle(yTitle1d.toAscii().constData()); - - - } - - // 2d - else { - plot2d->setTitle(indexTitle); - plot2d->SetXTitle(xTitle2d); - plot2d->SetYTitle(yTitle2d); - plot2d->SetZTitle(zTitle2d); - - + Update1dPlot(rawData); + } else { + plot2d->setTitle(indexTitle.toAscii().constData()); + if (hasGainData) + gainplot2d->setTitle(indexTitle.toAscii().constData()); + Update2dPlot(rawData, gainData); } - - - - // 1d - if (is1d) { - - - - - - // 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)) { - 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; - } - } - } - // 2d - else { - // Titles - title2d = temp_title; - - // jungfrau mask gain - if (data->dgainvalues != NULL) { - memcpy(gainImage, data->dgainvalues, - nPixelsX * nPixelsY * sizeof(double)); - gainDataExtracted = true; - } else - gainDataExtracted = false; - - // 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 * nPixelsY); ++px) - tempPedestalVals[px] += data->values[px]; - memcpy(data2d, data->values, - nPixelsX * nPixelsY * sizeof(double)); - pedestalCount++; - } - // calculate the pedestal value - if (pedestalCount == NUM_PEDESTAL_FRAMES) { - std::cout << "Pedestal Calculated" << '\n'; - for (unsigned int px = 0; px < (nPixelsX * nPixelsY); ++px) - tempPedestalVals[px] = - tempPedestalVals[px] / (double)NUM_PEDESTAL_FRAMES; - memcpy(pedestalVals, tempPedestalVals, - nPixelsX * nPixelsY * sizeof(double)); - startPedestalCal = 0; - } - } - - // normal data - if (((!isPedestal) & (!accumulate) & (!binary)) || - (resetAccumulate)) { - memcpy(data2d, data->values, - nPixelsX * nPixelsY * sizeof(double)); - resetAccumulate = false; - } - // pedestal or accumulate or binary - else { - double temp; - 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 += data2d[px]; - // after all processing - data2d[px] = temp; - } - } - } - /* pthread_mutex_unlock(&(lastImageCompleteMutex)); - }*/ - plotRequired = true; - //UnlockLastImageArray(); // fixme: do not unlock, let it plot. - -#ifdef VERYVERBOSE - cprintf(BLUE, "currentframe:%d \tcurrentframeindex:%d\n", currentFrame, - currentFrameIndex); -#endif - currentFrame++; - UpdatePlot(); - - -#ifdef VERYVERBOSE - std::cout << "Exiting GetData function" << '\n'; -#endif - return 0; -} - - -void qDrawPlot::UpdatePlot() { -#ifdef VERYVERBOSE - std::cout << "Entering UpdatePlot function\n"; -#endif - if (!plotEnable || !plotRequired) { - UnlockLastImageArray(); - return; + if (displayStatistics) { + double min = 0, max = 0, sum = 0; + GetStatistics(min, max, sum); + lblMinDisp->setText(QString("%1").arg(min)); + lblMaxDisp->setText(QString("%1").arg(max)); + lblSumDisp->setText(QString("%1").arg(sum)); } - // so that it doesnt plot every single thing -#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 - if (is1d) { -#ifdef VERYVERBOSE - std::cout << "Last Image Number:" << lastImageNumber << '\n'; -#endif - if (nPixelsX) { - DetachHists(); - plot1d->SetXTitle(xTitle1d.toAscii().constData()); - plot1d->SetYTitle(yTitle1d.toAscii().constData()); - - for (int hist_num = 0; hist_num < (int)nHists; ++hist_num) { - SlsQtH1D *h; - if (hist_num + 1 > hists1d.size()) { - hists1d.append(h = new SlsQtH1D("", nPixelsX, datax1d, datay1d[0])); - h->SetLineColor(hist_num); - } else { - h = hists1d.at(hist_num); - h->SetData(nPixelsX, datax1d, datay1d[hist_num]); - } - SetStyle(h); - lblFrameIndexTitle1d->setText(title1d[0].c_str()); - h->Attach(plot1d); - } - } - } // 2-d plot stuff - else { - plot2d->GetPlot()->SetData(nPixelsX, -0.5, nPixelsX - 0.5, - nPixelsY, startPixel, endPixel,data2d); - plot2d->setTitle(title2d.c_str()); - plot2d->SetXTitle(xTitle2d); - plot2d->SetYTitle(yTitle2d); - plot2d->SetZTitle(zTitle2d); - // recalculate if z is set - plot2d->KeepZRangeIfSet(); - if (gainDataExtracted) { - gainplot2d->GetPlot()->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, - startPixel, endPixel, gainImage); - gainplot2d->setTitle(title2d.c_str()); - gainplot2d->setFixedWidth(plot2d->width() / 4); - gainplot2d->setFixedHeight(plot2d->height() / 4); - gainplot2d->show(); - } else - gainplot2d->hide(); - } - UpdateXYRange(); - // Display Statistics - if (displayStatistics) { - double min = 0, max = 0, sum = 0; - GetStatistics(min, max, sum); - lblMinDisp->setText(QString("%1").arg(min)); - lblMaxDisp->setText(QString("%1").arg(max)); - lblSumDisp->setText(QString("%1").arg(sum)); - } - - // set plot title - boxPlot->setTitle(plotTitle); - // to notify the measurement finished when its done - plotRequired = false; - UnlockLastImageArray(); - - -#ifdef VERYVERBOSE - std::cout << "Exiting UpdatePlot function\n"; -#endif } +void qDrawPlot::Update1dPlot(double* rawData) { + // persistency + if (currentPersistency < persistency) + currentPersistency++; + else + currentPersistency = persistency; // when reducing persistency + nHists = currentPersistency + 1; + if (currentPersistency) { + // copy previous data + for (int i = currentPersistency; i > 0; --i) + memcpy(datay1d[i], datay1d[i - 1], nPixelsX * sizeof(double)); + } + // pedestal + if (isPedestal) { + for (unsigned int px = 0; px < nPixelsX; ++px) { + rawData[px] =- (pedestalVals[px]); + } + } + // accumulate + if (resetAccumulate) { + resetAccumulate = false; + } + else if (isAccumulate) { + for (unsigned int px = 0; px < nPixelsX; ++px) { + rawData[px] += datay1d[0][px]; + } + } + // binary + if (isBinary) { + for (unsigned int px = 0; px < nPixelsX; ++px) { + if ((rawData[px] >= binaryFrom) && (rawData[px] <= binaryTo)) + rawData[px] = 1; + else + rawData[px] = 0; + } + } + memcpy(datay1d[0], rawData, nPixelsX * sizeof(double)); + // Plot data + DetachHists(); + plot1d->SetXTitle(xTitle1d.toAscii().constData()); + plot1d->SetYTitle(yTitle1d.toAscii().constData()); + for (unsigned int i = 0; i < nHists; ++i) { + SlsQtH1D* h = hists1d.at(i); + h->SetData(nPixelsX, datax1d, datay1d[i]); + SetStyle(h); + h->Attach(plot1d); + } + Update1dXYRange(); +} + +void qDrawPlot::Update2dPlot(double* rawData, double* gainData) { + unsigned int nPixels = nPixelsX * nPixelsY; + // pedestal + if (isPedestal) { + for (unsigned int px = 0; px < nPixels; ++px) { + rawData[px] =- (pedestalVals[px]); + } + } + // accumulate + if (resetAccumulate) { + resetAccumulate = false; + } + else if (isAccumulate) { + for (unsigned int px = 0; px < nPixels; ++px) { + rawData[px] += data2d[px]; + } + } + // binary + if (isBinary) { + for (unsigned int px = 0; px < nPixels; ++px) { + if ((rawData[px] >= binaryFrom) && (rawData[px] <= binaryTo)) + rawData[px] = 1; + else + rawData[px] = 0; + } + } + memcpy(data2d, rawData, nPixels * sizeof(double)); + + // Plot data + plot2d->SetXTitle(xTitle2d); + plot2d->SetYTitle(yTitle2d); + plot2d->SetZTitle(zTitle2d); + plot2d->GetPlot()->SetData(nPixelsX, -0.5, nPixelsX - 0.5, + nPixelsY, -0.5, nPixelsY - 0.5, data2d); + plot2d->KeepZRangeIfSet(); + if (hasGainData) { + gainplot2d->GetPlot()->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, + -0.5, nPixelsY - 0.5, gainData); + gainplot2d->setFixedWidth(plot2d->width() / 4); + gainplot2d->setFixedHeight(plot2d->height() / 4); + gainplot2d->show(); + } else { + gainplot2d->hide(); + } + Update2dXYRange(); +} + +void qDrawPlot::Update1dXYRange() { + if (XYRangeChanged) { + if (!isXYRange[qDefs::XMIN] || !isXYRange[qDefs::XMAX]) { + plot1d->EnableXAutoScaling(); + } else { + if (!isXYRange[qDefs::XMIN]) + XYRange[qDefs::XMIN] = plot1d->GetXMinimum(); + if (!isXYRange[qDefs::XMAX]) + XYRange[qDefs::XMAX] = plot1d->GetXMaximum(); + plot1d->SetXMinMax(XYRange[qDefs::XMIN], XYRange[qDefs::XMAX]); + } + + if (!isXYRange[qDefs::YMIN] || !isXYRange[qDefs::YMAX]) { + plot1d->EnableYAutoScaling(); + } else { + if (!isXYRange[qDefs::YMIN]) + XYRange[qDefs::YMIN] = plot1d->GetYMinimum(); + if (!isXYRange[qDefs::YMAX]) + XYRange[qDefs::YMAX] = plot1d->GetYMaximum(); + plot1d->SetYMinMax(XYRange[qDefs::YMIN], XYRange[qDefs::YMAX]); + } + XYRangeChanged = false; + plot1d->Update(); + } +} + +void qDrawPlot::Update2dXYRange() { + if (XYRangeChanged) { + if (!isXYRange[qDefs::XMIN] || !isXYRange[qDefs::XMAX]) { + plot2d->GetPlot()->EnableXAutoScaling(); + } else { + if (!isXYRange[qDefs::XMIN]) + XYRange[qDefs::XMIN] = plot2d->GetPlot()->GetXMinimum(); + if (!isXYRange[qDefs::XMAX]) + XYRange[qDefs::XMAX] = plot2d->GetPlot()->GetXMaximum(); + plot2d->GetPlot()->SetXMinMax(XYRange[qDefs::XMIN], XYRange[qDefs::XMAX]); + } + + if (!isXYRange[qDefs::YMIN] || !isXYRange[qDefs::YMAX]) { + plot2d->GetPlot()->EnableYAutoScaling(); + } else { + if (!isXYRange[qDefs::YMIN]) + XYRange[qDefs::YMIN] = plot2d->GetPlot()->GetYMinimum(); + if (!isXYRange[qDefs::YMAX]) + XYRange[qDefs::YMAX] = plot2d->GetPlot()->GetYMaximum(); + plot2d->GetPlot()->SetYMinMax(XYRange[qDefs::YMIN], XYRange[qDefs::YMAX]); + } + XYRangeChanged = false; + plot2d->GetPlot()->Update(); + } +} + void qDrawPlot::toDoublePixelData(double *dest, char *source, int size, int databytes, int dr, double *gaindest) { int ichan = 0; int ibyte = 0; @@ -1170,211 +1102,3 @@ void qDrawPlot::toDoublePixelData(double *dest, char *source, int size, int data } } - - - - -void qDrawPlot::StartStopDaqToggle(bool stop_if_running) { -#ifdef VERYVERBOSE - std::cout << "Entering StartStopDaqToggle(" << stop_if_running << ")\n"; -#endif - - if (isRunning) { - - StartOrStopThread(0); - isRunning = !isRunning; - } else if (!stop_if_running) { - - currentMeasurement = 0; - currentFrame = 0; - lastImageNumber = 0; - - - - if (!StartOrStopThread(0)) { - std::cout << "Resetting image number" << '\n'; - lastImageNumber = 0; - } - StartOrStopThread(1); - - isRunning = !isRunning; - } - -} - - - -bool qDrawPlot::StartOrStopThread(bool start) { -#ifdef VERYVERBOSE - std::cout << "StartOrStopThread:" << start << '\n'; -#endif - static bool firstTime = true; - static bool gui_acquisition_thread_running = 0; - static pthread_t gui_acquisition_thread; - static pthread_mutex_t gui_acquisition_start_stop_mutex = - PTHREAD_MUTEX_INITIALIZER; - - pthread_mutex_lock(&gui_acquisition_start_stop_mutex); - // stop part, before start or restart - if (gui_acquisition_thread_running) { - std::cout << "Stopping current acquisition thread ...." << '\n'; - gui_acquisition_thread_running = 0; - } - - // start part - if (start) { - progress = 0; - // sets up the measurement parameters - SetupMeasurement(); - - // refixing all the zooming - plot2d->GetPlot()->SetXMinMax(-0.5, nPixelsX + 0.5); - plot2d->GetPlot()->SetYMinMax(startPixel, endPixel); - plot2d->GetPlot()->SetZoom(-0.5, startPixel, nPixelsX, - endPixel - startPixel); - if (boxPlot->title() == "Sample Plot") - plot2d->GetPlot()->UnZoom(); - else - plot2d->GetPlot()->UnZoom(false); - /*XYRangeChanged = true;*/ - boxPlot->setTitle("Old_Plot.raw"); - - cprintf(BLUE, "Starting new acquisition thread ....\n"); - // 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); - // 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; -#ifdef VERYVERBOSE - std::cout << "Started acquiring thread" << '\n'; -#endif - } - pthread_mutex_unlock(&gui_acquisition_start_stop_mutex); - return gui_acquisition_thread_running; -} - -void qDrawPlot::SetScanArgument(int scanArg) { -#ifdef VERYVERBOSE - std::cout << "SetScanArgument function:" << scanArg - << " running:" << isRunning << '\n'; -#endif - scanArgument = scanArg; - - LockLastImageArray(); - - if (is1d) - DetachHists(); - - - maxPixelsY = 0; - minPixelsY = 0; - nPixelsX = myDet->getTotalNumberOfChannelsInclGapPixels(slsDetectorDefs::X); - nPixelsY = myDet->getTotalNumberOfChannelsInclGapPixels(slsDetectorDefs::Y); - if (detType == slsDetectorDefs::MOENCH) { - npixelsy_jctb = (myDet->setTimer(slsDetectorDefs::SAMPLES, -1) * 2) / - 25; // for moench 03 - nPixelsX = npixelsx_jctb; - nPixelsY = npixelsy_jctb; - } - - if (minPixelsY > maxPixelsY) { - double temp = minPixelsY; - minPixelsY = maxPixelsY; - maxPixelsY = temp; - backwardScanPlot = true; - } else - backwardScanPlot = false; - - // 1d - if (datax1d) - delete[] datax1d; - datax1d = new double[nPixelsX]; - - for (auto &it : datay1d) { - delete[] it; - } - if (datay1d.size()) { - datay1d.clear(); - } - datay1d.push_back(new double[nPixelsX]); - - // 2d - if (data2d) - delete[] data2d; - data2d = new double[nPixelsY * nPixelsX]; - if (gainImage) - delete[] gainImage; - gainImage = new double[nPixelsY * nPixelsX]; - - // initializing 1d x axis - for (unsigned int px = 0; px < nPixelsX; ++px) - datax1d[px] = px; /*+10;*/ - - // initializing 2d array - - memset(data2d, 0, nPixelsY * nPixelsX * sizeof(double)); - memset(gainImage, 0, nPixelsY * nPixelsX * sizeof(double)); - - - UnlockLastImageArray(); - -} - -void qDrawPlot::SetupMeasurement() { - LockLastImageArray(); - // Defaults - if (!isRunning) - plotRequired = 0; - currentFrame = 0; - - // if(!is1d) - if (!isRunning) - lastImageNumber = 0; /**Just now */ - // initializing 2d array - memset(data2d, 0, nPixelsY * nPixelsX * sizeof(double)); - memset(gainImage, 0, nPixelsY * nPixelsX * sizeof(double)); - - // 1d with no scan - if ((!originally2D)) { - if (!isRunning) { - maxPixelsY = 100; - minPixelsY = 0; - startPixel = -0.5; - endPixel = nPixelsY - 0.5; - } - } else { - // 2d with no scan - if ((originally2D) ) { - maxPixelsY = nPixelsY - 1; - minPixelsY = 0; - } - - // 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); - } - - } - - /* - std::cout<<"nPixelsX:"< +#include #include @@ -177,10 +178,6 @@ void qTabMeasurement::EnableWidgetsforTimingMode() { break; } - // to let qdrawplot know that triggers or frames are used - myPlot->setFrameEnabled(lblNumFrames->isEnabled()); - myPlot->setTriggerEnabled(lblNumTriggers->isEnabled()); - CheckAcqPeriodGreaterThanExp(); } @@ -226,24 +223,13 @@ void qTabMeasurement::SetTimingMode(int val) { void qTabMeasurement::GetNumMeasurements() { FILE_LOG(logDEBUG) << "Getting number of measurements"; disconnect(spinNumMeasurements, SIGNAL(valueChanged(int)), this, SLOT(SetNumMeasurements(int))); - - try { - auto retval = myDet->setTimer(slsDetectorDefs::MEASUREMENTS_NUMBER); - if (retval == -1) { - qDefs::Message(qDefs::WARNING, "Number of measurements is inconsistent for all detectors.", "qTabMeasurement::GetNumMeasurements"); - } - spinNumMeasurements->setValue(retval); - } CATCH_DISPLAY ("Could not get number of measurements.", "qTabMeasurement::GetNumMeasurements") - + spinNumFrames->setValue(myPlot->GetNumMeasurements()); connect(spinNumMeasurements, SIGNAL(valueChanged(int)), this, SLOT(SetNumMeasurements(int))); } void qTabMeasurement::SetNumMeasurements(int val) { FILE_LOG(logINFO) << "Setting Number of Measurements to " << val; - - try { - myDet->setTimer(slsDetectorDefs::MEASUREMENTS_NUMBER, val); - } CATCH_HANDLE("Could not set number of measurements.", "qTabMeasurement::SetNumMeasurements", this, &qTabMeasurement::GetNumMeasurements) + myPlot->SetNumMeasurements(val); } void qTabMeasurement::GetNumFrames() { @@ -588,6 +574,7 @@ void qTabMeasurement::StartAcquisition() { void qTabMeasurement::StopAcquisition() { FILE_LOG(logINFORED) << "Stopping Acquisition"; try{ + myPlot->SetStopSignal(); myDet->stopAcquisition(); } CATCH_DISPLAY("Could not stop acquisition.", "qTabMeasurement::StopAcquisition") } @@ -611,7 +598,7 @@ void qTabMeasurement::Enable(bool enable) { void qTabMeasurement::Refresh() { FILE_LOG(logDEBUG) << "**Updating Measurement Tab"; - if (!myPlot->isRunning()) { + if (!myPlot->GetIsRunning()) { GetTimingMode(); GetNumMeasurements(); GetNumFrames(); diff --git a/slsDetectorGui/src/qTabPlot.cpp b/slsDetectorGui/src/qTabPlot.cpp index 41cd157b5..f3a387ad0 100755 --- a/slsDetectorGui/src/qTabPlot.cpp +++ b/slsDetectorGui/src/qTabPlot.cpp @@ -211,7 +211,7 @@ void qTabPlot::Select1DPlot(bool enable) { chkZMax->setEnabled(!enable); dispZMin->setEnabled(!enable); dispZMax->setEnabled(!enable); - myplot->Select1dPlot(enable); + myPlot->Select1dPlot(enable); SetTitles(); SetXYRange(); if (!is1d) { @@ -485,7 +485,7 @@ void qTabPlot::SetXYRange() { connect(dispYMax, SIGNAL(editingFinished()), this, SLOT(SetYRange())); // to update plot with range - myplot->SetXYRangeChanged(); + myPlot->SetXYRangeChanged(); myPlot->DisableZoom(disablezoom); emit DisableZoomSignal(disablezoom); } @@ -589,7 +589,7 @@ void qTabPlot::MaintainAspectRatio(int dimension) { myPlot->IsXYRangeValues(true, qDefs::YMAX); // to update plot with range - myplot->SetXYRangeChanged(); + myPlot->SetXYRangeChanged(); myPlot->DisableZoom(true); emit DisableZoomSignal(true); } @@ -671,7 +671,7 @@ void qTabPlot::SetStreamingFrequency() { void qTabPlot::Refresh() { FILE_LOG(logDEBUG) << "**Updating Plot Tab"; - if (!myPlot->isRunning()) { + if (!myPlot->GetIsRunning()) { boxPlotType->setEnabled(true); // streaming frequency diff --git a/slsDetectorSoftware/include/detectorData.h b/slsDetectorSoftware/include/detectorData.h index 7737a453c..9be0215ca 100755 --- a/slsDetectorSoftware/include/detectorData.h +++ b/slsDetectorSoftware/include/detectorData.h @@ -18,14 +18,13 @@ class detectorData { * @param fIndex file index */ detectorData(double progress, std::string fname, int x, int y, char *d, int dbytes, int dr, uint64_t fIndex) : - progressIndex(progress), fileName(fname), nx(x), ny(y), data(d), databytes(dbytes), dynamicRange(dr), gain(nullptr), fileIndex(fIndex) {}; + progressIndex(progress), fileName(fname), fileIndex(fIndex), nx(x), ny(y), data(d), databytes(dbytes), dynamicRange(dr) {}; /** * Destructor - * Also deletes gain * data has to be deleted by caller */ - ~detectorData() {if(gain) delete [] gain;}; + ~detectorData() {}; int64_t getChannel(int i) { int off=dynamicRange/8; @@ -54,7 +53,6 @@ class detectorData { int nx; int ny; char* data; - double* gain; int databytes; int dynamicRange; }; diff --git a/slsDetectorSoftware/include/multiSlsDetector.h b/slsDetectorSoftware/include/multiSlsDetector.h index 6dfeaf1e4..f2003c8c9 100755 --- a/slsDetectorSoftware/include/multiSlsDetector.h +++ b/slsDetectorSoftware/include/multiSlsDetector.h @@ -2093,16 +2093,6 @@ class multiSlsDetector : public virtual slsDetectorDefs { */ void registerAcquisitionFinishedCallback(void (*func)(double, int, void *), void *pArg); - - /** - * register callback for accessing measurement final data - * @param func function to be called at the end of the acquisition. - * gets measurement index - * @param pArg argument - */ - void registerMeasurementFinishedCallback(void (*func)(int, void *), - void *pArg); - /** * register callback for accessing detector progress * @param func function to be called at the end of the acquisition. @@ -2302,9 +2292,6 @@ class multiSlsDetector : public virtual slsDetectorDefs { void (*acquisition_finished)(double, int, void *){nullptr}; void *acqFinished_p{nullptr}; - void (*measurement_finished)(int, void *){nullptr}; - void *measFinished_p{nullptr}; - void (*progress_call)(double, void *){nullptr}; void *pProgressCallArg{nullptr}; diff --git a/slsDetectorSoftware/include/slsDetectorUsers.h b/slsDetectorSoftware/include/slsDetectorUsers.h index 35ffbc134..e29f44ce6 100755 --- a/slsDetectorSoftware/include/slsDetectorUsers.h +++ b/slsDetectorSoftware/include/slsDetectorUsers.h @@ -823,14 +823,6 @@ public: */ void registerAcquisitionFinishedCallback(void( *func)(double,int, void*), void *pArg); - /** - * register callback for accessing measurement final data in client, - * @param func function to be called at the end of the acquisition. - * gets measurement index - * @param pArg argument - */ - void registerMeasurementFinishedCallback(void( *func)(int, void*), void *pArg); - /** * register callback for accessing detector progress in client, * @param func function to be called at the end of the acquisition. diff --git a/slsDetectorSoftware/src/multiSlsDetector.cpp b/slsDetectorSoftware/src/multiSlsDetector.cpp index 88986047a..f24d4bb54 100755 --- a/slsDetectorSoftware/src/multiSlsDetector.cpp +++ b/slsDetectorSoftware/src/multiSlsDetector.cpp @@ -1109,9 +1109,7 @@ int64_t multiSlsDetector::setTimer(timerIndex index, int64_t t, int detPos) { case FRAME_NUMBER: case CYCLES_NUMBER: case STORAGE_CELL_NUMBER: - case MEASUREMENTS_NUMBER: - throw RuntimeError("Cannot set number of frames, cycles,storage cells or " - "measurements individually."); + throw RuntimeError("Cannot set number of frames, cycles or storage cells individually."); default: break; } @@ -1129,7 +1127,6 @@ int64_t multiSlsDetector::setTimer(timerIndex index, int64_t t, int detPos) { case FRAME_NUMBER: case CYCLES_NUMBER: case STORAGE_CELL_NUMBER: - case MEASUREMENTS_NUMBER: setTotalProgress(); break; default: @@ -3969,7 +3966,6 @@ int multiSlsDetector::dumpDetectorSetup(const std::string &fname, int level) { names.emplace_back("period"); names.emplace_back("frames"); names.emplace_back("cycles"); - names.emplace_back("measurements"); names.emplace_back("timing"); switch (type) { @@ -4075,12 +4071,6 @@ void multiSlsDetector::registerAcquisitionFinishedCallback(void (*func)(double, acqFinished_p = pArg; } -void multiSlsDetector::registerMeasurementFinishedCallback(void (*func)(int, void *), - void *pArg) { - measurement_finished = func; - measFinished_p = pArg; -} - void multiSlsDetector::registerProgressCallback(void (*func)(double, void *), void *pArg) { progress_call = func; pProgressCallArg = pArg; @@ -4102,7 +4092,7 @@ void multiSlsDetector::registerDataCallback(void (*userCallback)(detectorData *, } int multiSlsDetector::setTotalProgress() { - int nf = 1, nc = 1, ns = 1, nm = 1; + int nf = 1, nc = 1, ns = 1; if (multi_shm()->timerValue[FRAME_NUMBER] != 0) { nf = multi_shm()->timerValue[FRAME_NUMBER]; @@ -4116,13 +4106,9 @@ int multiSlsDetector::setTotalProgress() { ns = multi_shm()->timerValue[STORAGE_CELL_NUMBER] + 1; } - if (multi_shm()->timerValue[MEASUREMENTS_NUMBER] > 0) { - nm = multi_shm()->timerValue[MEASUREMENTS_NUMBER]; - } + totalProgress = nf * nc * ns; - totalProgress = nm * nf * nc * ns; - - FILE_LOG(logDEBUG1) << "nm " << nm << " nf " << nf << " nc " << nc << " ns " << ns; + FILE_LOG(logDEBUG1) << "nf " << nf << " nc " << nc << " ns " << ns; FILE_LOG(logDEBUG1) << "Set total progress " << totalProgress << std::endl; return totalProgress; } @@ -4170,11 +4156,6 @@ int multiSlsDetector::acquire() { multi_shm()->stoppedFlag = 0; setJoinThreadFlag(false); - int nm = multi_shm()->timerValue[MEASUREMENTS_NUMBER]; - if (nm < 1) { - nm = 1; - } - // verify receiver is idle if (receiver) { std::lock_guard lock(mg); @@ -4188,58 +4169,44 @@ int multiSlsDetector::acquire() { startProcessingThread(); // resets frames caught in receiver - if (receiver) { + if (receiver && multi_shm()->stoppedFlag == 0) { std::lock_guard lock(mg); if (resetFramesCaught() == FAIL) { multi_shm()->stoppedFlag = 1; } } - // loop through measurements - for (int im = 0; im < nm; ++im) { - if (multi_shm()->stoppedFlag != 0) { - break; - } - - // start receiver - if (receiver) { - std::lock_guard lock(mg); - if (startReceiver() == FAIL) { - FILE_LOG(logERROR) << "Start receiver failed "; - stopReceiver(); - multi_shm()->stoppedFlag = 1; - break; - } - // let processing thread listen to these packets - sem_post(&sem_newRTAcquisition); + // start receiver + if (receiver && multi_shm()->stoppedFlag == 0) { + std::lock_guard lock(mg); + if (startReceiver() == FAIL) { + FILE_LOG(logERROR) << "Start receiver failed "; + stopReceiver(); + multi_shm()->stoppedFlag = 1; } + // let processing thread listen to these packets + sem_post(&sem_newRTAcquisition); + } + if (multi_shm()->stoppedFlag == 0) startAndReadAll(); - // stop receiver - std::lock_guard lock(mg); - if (receiver) { - if (stopReceiver() == FAIL) { - multi_shm()->stoppedFlag = 1; - } else { - if (dataReady != nullptr) { - sem_wait(&sem_endRTAcquisition); // waits for receiver's - } - // external process to be - // done sending data to gui + // stop receiver + std::lock_guard lock(mg); + if (receiver) { + if (stopReceiver() == FAIL) { + multi_shm()->stoppedFlag = 1; + } else { + if (dataReady != nullptr) { + sem_wait(&sem_endRTAcquisition); // waits for receiver's } + // external process to be + // done sending data to gui } - int findex = 0; - findex = incrementFileIndex(); + } + + incrementFileIndex(); - if (measurement_finished != nullptr) { - measurement_finished(im, measFinished_p); - } - if (multi_shm()->stoppedFlag != 0) { - break; - } - - } // end measurements loop im // waiting for the data processing thread to finish! setJoinThreadFlag(true); diff --git a/slsDetectorSoftware/src/slsDetector.cpp b/slsDetectorSoftware/src/slsDetector.cpp index d46fdef09..2f9535d46 100755 --- a/slsDetectorSoftware/src/slsDetector.cpp +++ b/slsDetectorSoftware/src/slsDetector.cpp @@ -312,7 +312,6 @@ void slsDetector::initializeDetectorStructure(detectorType type) { shm()->timerValue[ACTUAL_TIME] = 0; shm()->timerValue[MEASUREMENT_TIME] = 0; shm()->timerValue[PROGRESS] = 0; - shm()->timerValue[MEASUREMENTS_NUMBER] = 1; shm()->timerValue[FRAMES_FROM_START] = 0; shm()->timerValue[FRAMES_FROM_START_PG] = 0; shm()->timerValue[ANALOG_SAMPLES] = 1; @@ -1522,15 +1521,6 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t) { FILE_LOG(logDEBUG1) << "Setting " << getTimerType(index) << " to " << t << " ns/value"; - // meausurement is only shm level - if (index == MEASUREMENTS_NUMBER) { - if (t >= 0) { - shm()->timerValue[index] = t; - FILE_LOG(logDEBUG1) << getTimerType(index) << ": " << t; - } - return shm()->timerValue[index]; - } - // send to detector int64_t oldtimer = shm()->timerValue[index]; if (shm()->onlineFlag == ONLINE_FLAG) { diff --git a/slsDetectorSoftware/src/slsDetectorCommand.cpp b/slsDetectorSoftware/src/slsDetectorCommand.cpp index c03514678..d0909c4af 100755 --- a/slsDetectorSoftware/src/slsDetectorCommand.cpp +++ b/slsDetectorSoftware/src/slsDetectorCommand.cpp @@ -610,13 +610,6 @@ slsDetectorCommand::slsDetectorCommand(multiSlsDetector *det) { descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdTimer; ++i; - /*! \page timing - - measurements [i] sets/gets number of measurements. \c Returns \c (long long int) - */ - descrToFuncMap[i].m_pFuncName = "measurements"; - descrToFuncMap[i].m_pFuncPtr = &slsDetectorCommand::cmdTimer; - ++i; - /*! \page timing - samples [i] sets/gets number of samples (both analog and digital) expected from the ctb. Used in CHIP TEST BOARD and MOENCH only. \c Returns \c (long long int) */ @@ -4484,8 +4477,6 @@ std::string slsDetectorCommand::cmdTimer(int narg, const char * const args[], in index = FRAME_NUMBER; else if (cmd == "cycles") index = CYCLES_NUMBER; - else if (cmd == "measurements") - index = MEASUREMENTS_NUMBER; // also does digital sample else if (cmd == "samples") index = ANALOG_SAMPLES; diff --git a/slsDetectorSoftware/src/slsDetectorUsers.cpp b/slsDetectorSoftware/src/slsDetectorUsers.cpp index 69b538ebe..390329c6a 100755 --- a/slsDetectorSoftware/src/slsDetectorUsers.cpp +++ b/slsDetectorSoftware/src/slsDetectorUsers.cpp @@ -406,10 +406,6 @@ void slsDetectorUsers::registerAcquisitionFinishedCallback(void( *func)(double,i detector.registerAcquisitionFinishedCallback(func,pArg); } -void slsDetectorUsers::registerMeasurementFinishedCallback(void( *func)(int,void*), void *pArg) { - detector.registerMeasurementFinishedCallback(func,pArg); -} - void slsDetectorUsers::registerProgressCallback(void( *func)(double,void*), void *pArg) { detector.registerProgressCallback(func,pArg); } diff --git a/slsSupportLib/include/sls_detector_defs.h b/slsSupportLib/include/sls_detector_defs.h index b5132aeb8..a66a02f6c 100755 --- a/slsSupportLib/include/sls_detector_defs.h +++ b/slsSupportLib/include/sls_detector_defs.h @@ -29,7 +29,6 @@ /** default ports */ #define DEFAULT_PORTNO 1952 #define DEFAULT_UDP_PORTNO 50001 -#define DEFAULT_GUI_PORTNO 65001 #define DEFAULT_ZMQ_CL_PORTNO 30001 #define DEFAULT_ZMQ_RX_PORTNO 30001 @@ -115,7 +114,6 @@ class slsDetectorDefs { */ PROGRESS, /**< fraction of measurement elapsed - only get! */ - MEASUREMENTS_NUMBER, FRAMES_FROM_START, FRAMES_FROM_START_PG, ANALOG_SAMPLES, @@ -927,12 +925,12 @@ format \param s can be FRAME_NUMBER,ACQUISITION_TIME,FRAME_PERIOD, DELAY_AFTER_TRIGGER,GATES_NUMBER, CYCLES_NUMBER, ACTUAL_TIME,MEASUREMENT_TIME, - PROGRESS,MEASUREMENTS_NUMBER,FRAMES_FROM_START,FRAMES_FROM_START_PG,ANALOG_SAMPLES,DIGITAL_SAMPLES,SUBFRAME_ACQUISITION_TIME,STORAGE_CELL_NUMBER, + PROGRESS,FRAMES_FROM_START,FRAMES_FROM_START_PG,ANALOG_SAMPLES,DIGITAL_SAMPLES,SUBFRAME_ACQUISITION_TIME,STORAGE_CELL_NUMBER, SUBFRAME_DEADTIME \returns std::string frame_number,acquisition_time,frame_period, delay_after_trigger,gates_number, cycles_number, actual_time,measurement_time, - progress,measurements_number,frames_from_start,frames_from_start_pg,analog_samples, digital_samples,subframe_acquisition_time,storage_cell_number, + progress,frames_from_start,frames_from_start_pg,analog_samples, digital_samples,subframe_acquisition_time,storage_cell_number, SUBFRAME_DEADTIME */ static std::string getTimerType(timerIndex t) { @@ -955,8 +953,6 @@ format return std::string("measurement_time"); case PROGRESS: return std::string("progress"); - case MEASUREMENTS_NUMBER: - return std::string("measurements_number"); case FRAMES_FROM_START: return std::string("frames_from_start"); case FRAMES_FROM_START_PG: