diff --git a/slsDetectorGui/include/qCloneWidget.h b/slsDetectorGui/include/qCloneWidget.h index ce4183792..b151caafa 100755 --- a/slsDetectorGui/include/qCloneWidget.h +++ b/slsDetectorGui/include/qCloneWidget.h @@ -36,7 +36,7 @@ class qCloneWidget : public QMainWindow { * @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, std::vector histTitle, bool lines, bool markers); + 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 diff --git a/slsDetectorGui/include/qDrawPlot.h b/slsDetectorGui/include/qDrawPlot.h index b5379d899..ec6a8aff4 100755 --- a/slsDetectorGui/include/qDrawPlot.h +++ b/slsDetectorGui/include/qDrawPlot.h @@ -79,13 +79,11 @@ class qDrawPlot : public QWidget { private slots: void SetSaveFileName(QString val); void CloneCloseEvent(int id); - - - void UpdatePlot(); + void AcquireThread(); signals: - void UpdatingPlotFinished(); - void UpdatePlotSignal(); + void AcquireSignal(); + void AcquireFinishedSignal(); private: void SetupWidgetWindow(); @@ -98,23 +96,15 @@ class qDrawPlot : public QWidget { void GetStatistics(double &min, double &max, double &sum, double *array, int size); void DetachHists(); void UpdateXYRange(); - - - - - - bool StartOrStopThread(bool start); - void SetupMeasurement(); - 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); - static int GetAcquisitionFinishedCallBack(double currentProgress, int detectorStatus, void *this_pointer); - int AcquisitionFinished(double currentProgress, int detectorStatus); - static int GetMeasurementFinishedCallBack(int currentMeasurementIndex, int fileIndex, void *this_pointer); - int MeasurementFinished(int currentMeasurementIndex, int fileIndex); - static int GetProgressCallBack(double currentProgress, void *this_pointer); + 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(); static const int NUM_PEDESTAL_FRAMES = 20; multiSlsDetector *myDet; @@ -131,14 +121,10 @@ class qDrawPlot : public QWidget { bool is1d{true}; bool isRunning{false}; - int progress{0}; - + // titles - QString plotTitle{""}; QString plotTitle_prefix{""}; QLabel *lblFrameIndexTitle1d{nullptr}; - std::vector title1d; - std::string title2d{""}; QString xTitle1d{"Channel Number"}; QString yTitle1d{"Counts"}; QString xTitle2d{"Pixel"}; @@ -155,11 +141,12 @@ class qDrawPlot : public QWidget { double *data2d{nullptr}; //options - bool binary{false}; + bool plotEnable{true}; + bool binary{false}; int binaryFrom{0}; int binaryTo{0}; int persistency{0}; - int currentPersistency0}; + int currentPersistency{0}; bool isLines{true}; bool isMarkers{false}; QwtSymbol *marker{nullptr}; @@ -191,9 +178,9 @@ class qDrawPlot : public QWidget { double endPixel{0}; double pixelWidth{0}; + int progress{0}; int64_t currentMeasurement{0}; int64_t currentFrame{0}; - int64_t lastImageNumber{0}; pthread_mutex_t lastImageCompleteMutex; const static int npixelsx_jctb = 400; diff --git a/slsDetectorGui/src/qCloneWidget.cpp b/slsDetectorGui/src/qCloneWidget.cpp index 7576f20ed..c97c98bc2 100755 --- a/slsDetectorGui/src/qCloneWidget.cpp +++ b/slsDetectorGui/src/qCloneWidget.cpp @@ -124,7 +124,7 @@ void qCloneWidget::SetupWidgetWindow(QString title, QString xTitle, QString yTit resize(500, 350); } -void qCloneWidget::SetCloneHists(unsigned int nHists, int histNBins, double *histXAxis, std::vector histYAxis, std::vector histTitle, bool lines, bool markers) { +void qCloneWidget::SetCloneHists(unsigned int nHists, int histNBins, double *histXAxis, std::vector histYAxis, QString histTitle, bool lines, bool markers) { //for each plot, create hists for (unsigned int hist_num = 0; hist_num < nHists; ++hist_num) { SlsQtH1D *h = new SlsQtH1D("1d plot", histNBins, histXAxis, histYAxis[hist_num]); @@ -138,13 +138,14 @@ void qCloneWidget::SetCloneHists(unsigned int nHists, int histNBins, double *his cloneplot1D_hists.append(h); h->Attach(cloneplot1D); - lblHistTitle->setText(QString(histTitle[0].c_str())); + lblHistTitle->setText(histTitle); } } -void qCloneWidget::SetCloneHists2D(int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, double *d) { +void qCloneWidget::SetCloneHists2D(int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, double *d, QwtText frameIndexTitle) { cloneplot2D->GetPlot()->SetData(nbinsx, xmin, xmax, nbinsy, ymin, ymax, d); cloneplot2D->KeepZRangeIfSet(); + cloneplot2D->setTitle(frameIndexTitle); } void qCloneWidget::SetRange(bool IsXYRange[], double XYRange[]) { diff --git a/slsDetectorGui/src/qDetectorMain.cpp b/slsDetectorGui/src/qDetectorMain.cpp index db4d92f32..b0407c09c 100755 --- a/slsDetectorGui/src/qDetectorMain.cpp +++ b/slsDetectorGui/src/qDetectorMain.cpp @@ -699,7 +699,7 @@ void qDetectorMain::EnableTabs() { tabDeveloper->Refresh(); tabPlot->Refresh(); - myPlot->StartStopDaqToggle(); + myPlot->StartAcquisition(); } else { // to enable scan box tabPlot->Refresh(); // to start adc timer diff --git a/slsDetectorGui/src/qDrawPlot.cpp b/slsDetectorGui/src/qDrawPlot.cpp index f903793bb..753cbb32f 100755 --- a/slsDetectorGui/src/qDrawPlot.cpp +++ b/slsDetectorGui/src/qDrawPlot.cpp @@ -5,6 +5,7 @@ #include "detectorData.h" #include "qCloneWidget.h" + /* #include #include @@ -19,6 +20,7 @@ #include */ + qDrawPlot::qDrawPlot(QWidget *parent, multiSlsDetector *detector) : QWidget(parent), myDet(detector) { SetupWidgetWindow(); @@ -111,18 +113,15 @@ void qDrawPlot::SetupWidgetWindow() { SetupStatistics(); SetupPlots(); SetDataCallBack(true); - - // other call backs - myDet->registerAcquisitionFinishedCallback( - &(GetAcquisitionFinishedCallBack), this); - myDet->registerMeasurementFinishedCallback( - &(GetMeasurementFinishedCallBack), this); + myDet->registerAcquisitionFinishedCallback(&(GetAcquisitionFinishedCallBack), this); + myDet->registerMeasurementFinishedCallback(&(GetMeasurementFinishedCallBack), this); myDet->registerProgressCallback(&(GetProgressCallBack), this); Initialization(); } void qDrawPlot::Initialization() { + connect(this, SIGNAL(AcquireSignal()), this, SLOT(AcquireThread())); connect(this, SIGNAL(UpdatePlotSignal()), this, SLOT(UpdatePlot())); } @@ -196,10 +195,6 @@ void qDrawPlot::SetupPlots() { plot1d->SetXTitle(xTitle1d.toAscii().constData()); plot1d->SetYTitle(yTitle1d.toAscii().constData()); plot1d->hide(); - if (title1d.size()) { - title1d.clear(); - } - title1d.push_back(""); // setup data if (datax1d) delete[] datax1d; @@ -237,7 +232,7 @@ void qDrawPlot::SetupPlots() { plot2d->setFont(QFont("Sans Serif", 9, QFont::Normal)); plot2d->GetPlot()->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, startPixel, endPixel, data2d); - plot2d->setTitle(title2d.c_str()); + plot2d->setTitle(""); plot2d->SetXTitle(xTitle2d); plot2d->SetYTitle(yTitle2d); plot2d->SetZTitle(zTitle2d); @@ -256,7 +251,7 @@ void qDrawPlot::SetupPlots() { gainplot2d->setFont(QFont("Sans Serif", 9, QFont::Normal)); gainplot2d->GetPlot()->SetData(nPixelsX, -0.5, nPixelsX - 0.5, nPixelsY, startPixel, endPixel, gainImage); - gainplot2d->setTitle(title2d.c_str()); + gainplot2d->setTitle(""); gainplot2d->setAlignment(Qt::AlignLeft); gainplot2d->GetPlot()->enableAxis(0, false); gainplot2d->GetPlot()->enableAxis(1, false); @@ -423,8 +418,10 @@ void qDrawPlot::SetDataCallBack(bool enable) { FILE_LOG(logINFO) << "Setting data call back to " << std::boolalpha << enable << std::noboolalpha; if (is1d) if (enable) { + plotEnable = true; myDet->registerDataCallback(&(GetDataCallBack), this); } else { + plotEnable = false; myDet->registerDataCallback(nullptr, this); } UnlockLastImageArray(); @@ -442,8 +439,6 @@ void qDrawPlot::SetBinary(bool enable, int from, int to) { void qDrawPlot::SetPersistency(int val) { LockLastImageArray(); FILE_LOG(logINFO) << "Setting Persistency to " << val; - for (int i = datay1d.size(); i <= val; ++i) - datay1d.push_back(new double[nPixelsX]); persistency = val; UnlockLastImageArray(); } @@ -568,21 +563,21 @@ void qDrawPlot::ClonePlot() { FILE_LOG(logINDO) << "Cloning 1D Image"; qCloneWidget *q = new qCloneWidget( this, cloneWidgets.size(), boxPlot->title(), xTitle1d, yTitle1d, "", 1, - fileSavePath, fileSaveName, lastImageNumber, displayStatistics, lblMinDisp->text(), + fileSavePath, fileSaveName, currentFrame, displayStatistics, lblMinDisp->text(), lblMaxDisp->text(), lblSumDisp->text()); cloneWidgets.push_back(q); cloneWidgets[i]->SetCloneHists(nHists, nPixelsX, datax1d, datay1d, - title1d, isLines, isMarkers); + lblFrameIndexTitle1d->text(), isLines, isMarkers); } else { FILE_LOG(logINDO) << "Cloning 2D Image"; qCloneWidget *q = new qCloneWidget( this, cloneWidgets.size(), boxPlot->title(), xTitle2d, yTitle2d, zTitle2d, 2, - fileSavePath, fileSaveName, lastImageNumber, displayStatistics, lblMinDisp->text(), + 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, - data2d); + data2d, plot2d->title()); } if (isXYRange[qDefs::XMIN] || isXYRange[qDefs::XMAX] ||isXYRange[qDefs::YMIN] ||isXYRange[qDefs::YMAX]) { @@ -637,7 +632,7 @@ void qDrawPlot::SavePlot() { QPainter painter(&savedImage); render(&painter); - QString fName = fileSavePath + Qstring('/') + fileSaveName + Qstring('_') + lastImageNumber + 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, @@ -727,98 +722,453 @@ void qDrawPlot::UpdateXYRange() { void qDrawPlot::StartAcquisition() { FILE_LOG(logDEBUG) << "Starting Acquisition in qDrawPlot"; - currentMeasurement = 0; - currentFrame = 0; - lastImageNumber = 0; + isRunning = true; + progress = 0; + currentMeasurement = -1; + currentFrame = -1; + boxPlot->setTitle("Old Plot"); + // check acquiring flag (from previous exit) or if running + try{ + if (myDet->getAcquiringFlag()) { + if (myDet->getRunStatus() != 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(); + } + } + } CATCH_DISPLAY("Could not get detector stats.", "qDrawPlot::StartAcquisition"); + + // ensure data streaming in receiver (if plot enabled) + if (plotEnable) { + try { + if (myDet->enableDataStreamingFromReceiver() != 1) { + myDet->enableDataStreamingFromReceiver(1); + } + } CATCH_DISPLAY("Could not enable data streaming in Receiver.", "qDrawPlot::StartAcquisition"); + } + + // acquisition in another thread, so signal it + emit AcquireSignal(); +} + +void qDrawPlot::AcquireThread() { + try { + myDet->acquire(); + } catch (const std::exception &e) { + qDefs::ExceptionMessage("Acquire unsuccessful.", e.what(), "qDrawPlot::AcquireThread"); + // handle acquire exception + try{ + myDet->stopAcquisition(); + myDet->stopReceiver(); + } CATCH_DISPLAY("Could not stop acquisition.", "qDrawPlot::AcquireThread"); + isRunning = false; + emit AcquireFinishedSignal(); + } +} + +void qDrawPlot::GetProgressCallBack(double currentProgress, void *this_pointer) { + ((qDrawPlot *)this_pointer)->progress = currentProgress; + FILE_LOG(logDEBUG) << "Progress Call back successful"; +} + +void qDrawPlot::GetAcquisitionFinishedCallBack(double currentProgress, int detectorStatus, void *this_pointer) { + ((qDrawPlot *)this_pointer)->AcquisitionFinished(currentProgress, detectorStatus); + 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); + if (detectorStatus == slsDetectorDefs::ERROR) { + qDefs::Message(qDefs::WARNING, std::string("The acquisiton has ended abruptly. Current Detector Status: ") + status + std::string("."), "qDrawPlot::AcquisitionFinished"); + FILE_LOG(logERROR) << "Acquisition finished [Status: ERROR]"; + } else { + FILE_LOG(logINFO) << "Acquisition finished [ Status:" << status << ", Progress: " << currentProgress << " ]" ; + } + + isRunning = false; + 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) { + LockLastImageArray(); + + FILE_LOG(logDEBUG) + << "* GetData Callback *" << std::endl + << "frame index: " << frameIndex << std::endl + << "sub frame index: " << subFrameIndex << std::endl + << "Data [" << std::endl + << "\t progress: " << data->progressIndex << std::endl + << "\t file name: " << data->fileName << std::endl + << "\t nx: " << data->nx << std::endl + << "\t ny: " << data->ny << std::endl + << "\t data bytes: " << data->databytes << std::endl + << "\t dynamic range: " << data->dynamicRange << std::endl + << "\t file index: " << data->fileIndex << std::endl + << "]"; + + 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, ""); + + //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); + + + // 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); + + + } + + + + + // 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; + } + // 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::toDoublePixelData(double *dest, char *source, int size, int databytes, int dr, double *gaindest) { + int ichan = 0; + int ibyte = 0; + int halfbyte = 0; + char cbyte = '\0'; + switch (dr) { - - - - - - - - - - void qDrawPlot::toDoublePixelData(double *dest, char *source, int size, - int databytes, int dr, double *gaindest) { - int ichan = 0; - int ibyte = 0; - int halfbyte = 0; - char cbyte = '\0'; - - switch (dr) { - - case 4: - for (ibyte = 0; ibyte < databytes; ++ibyte) { - cbyte = source[ibyte]; - for (halfbyte = 1; halfbyte >= 0; --halfbyte) { - dest[ichan] = (cbyte >> (halfbyte * 4)) & 0xf; - ++ichan; - } + case 4: + for (ibyte = 0; ibyte < databytes; ++ibyte) { + cbyte = source[ibyte]; + for (halfbyte = 1; halfbyte >= 0; --halfbyte) { + dest[ichan] = (cbyte >> (halfbyte * 4)) & 0xf; + ++ichan; } - break; + } + break; - case 8: - for (ichan = 0; ichan < databytes; ++ichan) { - dest[ichan] = *((u_int8_t *)source); - ++source; - } - break; + case 8: + for (ichan = 0; ichan < databytes; ++ichan) { + dest[ichan] = *((u_int8_t *)source); + ++source; + } + break; - case 16: - if (detType == slsDetectorDefs::JUNGFRAU || - detType == slsDetectorDefs::MOENCH) { + case 16: + if (detType == slsDetectorDefs::JUNGFRAU || + detType == slsDetectorDefs::MOENCH) { - // show gain plot - if (gaindest != NULL) { - for (ichan = 0; ichan < size; ++ichan) { - if ((*((u_int16_t *)source)) == 0xFFFF) { - gaindest[ichan] = 0xFFFF; - dest[ichan] = 0xFFFF; - } else { - gaindest[ichan] = - (((*((u_int16_t *)source)) & 0xC000) >> 14); - dest[ichan] = ((*((u_int16_t *)source)) & 0x3FFF); - } - source += 2; - } - } - - // only data plot - else { - for (ichan = 0; ichan < size; ++ichan) { - /*if ( (*((u_int16_t*)source)) == 0xFFFF ) - dest[ichan] = 0xFFFF; - else*/ + // show gain plot + if (gaindest != NULL) { + for (ichan = 0; ichan < size; ++ichan) { + if ((*((u_int16_t *)source)) == 0xFFFF) { + gaindest[ichan] = 0xFFFF; + dest[ichan] = 0xFFFF; + } else { + gaindest[ichan] = + (((*((u_int16_t *)source)) & 0xC000) >> 14); dest[ichan] = ((*((u_int16_t *)source)) & 0x3FFF); - source += 2; } + source += 2; } - break; } - // other detectors - for (ichan = 0; ichan < size; ++ichan) { - dest[ichan] = *((u_int16_t *)source); - source += 2; - } - break; - - default: - for (ichan = 0; ichan < size; ++ichan) { - dest[ichan] = *((u_int32_t *)source); - source += 4; + // only data plot + else { + for (ichan = 0; ichan < size; ++ichan) { + dest[ichan] = ((*((u_int16_t *)source)) & 0x3FFF); + source += 2; + } } break; } + + // other detectors + for (ichan = 0; ichan < size; ++ichan) { + dest[ichan] = *((u_int16_t *)source); + source += 2; + } + break; + + default: + for (ichan = 0; ichan < size; ++ichan) { + dest[ichan] = *((u_int32_t *)source); + source += 4; + } + break; } +} @@ -950,10 +1300,8 @@ void qDrawPlot::SetScanArgument(int scanArg) { } if (datay1d.size()) { datay1d.clear(); - title1d.clear(); } datay1d.push_back(new double[nPixelsX]); - title1d.push_back(""); // 2d if (data2d) @@ -978,13 +1326,7 @@ void qDrawPlot::SetScanArgument(int scanArg) { } void qDrawPlot::SetupMeasurement() { -#ifdef VERYVERBOSE - std::cout << "SetupMeasurement function:" << isRunning << '\n'; -#endif LockLastImageArray(); -#ifdef VERYVERBOSE - std::cout << "locklastimagearray\n"; -#endif // Defaults if (!isRunning) plotRequired = 0; @@ -998,10 +1340,7 @@ void qDrawPlot::SetupMeasurement() { memset(gainImage, 0, nPixelsY * nPixelsX * sizeof(double)); // 1d with no scan - if ((!originally2D) && (scanArgument == qDefs::None)) { -#ifdef VERYVERBOSE - std::cout << "1D\n"; -#endif + if ((!originally2D)) { if (!isRunning) { maxPixelsY = 100; minPixelsY = 0; @@ -1009,11 +1348,8 @@ void qDrawPlot::SetupMeasurement() { endPixel = nPixelsY - 0.5; } } else { -#ifdef VERYVERBOSE - std::cout << "2D\n"; -#endif // 2d with no scan - if ((originally2D) && (scanArgument == qDefs::None)) { + if ((originally2D) ) { maxPixelsY = nPixelsY - 1; minPixelsY = 0; } @@ -1029,10 +1365,6 @@ void qDrawPlot::SetupMeasurement() { endPixel = maxPixelsY + (pixelWidth / 2); } - if (histogram) { - startPixel = histFrom - (histSize / 2); - endPixel = histTo + (histSize / 2); - } } /* @@ -1044,418 +1376,5 @@ void qDrawPlot::SetupMeasurement() { std::cout<<"endPixel:"<myDet->setReceiverOnline() == slsDetectorDefs::ONLINE_FLAG) { - - // if receiver data up streaming not on, switch it on - if (((qDrawPlot *)this_pointer) - ->myDet->enableDataStreamingFromReceiver() != 1) { - // switch on receiver - if (((qDrawPlot *)this_pointer) - ->myDet->enableDataStreamingFromReceiver(1) != 1) { - qDefs::checkErrorMessage(((qDrawPlot *)this_pointer)->myDet, - "qDrawPlot::DataStartAcquireThread"); - return this_pointer; - } - } - } - - if (((qDrawPlot *)this_pointer)->myDet->getAcquiringFlag() == true) { - ((qDrawPlot *)this_pointer)->myDet->setAcquiringFlag(false); - } - ((qDrawPlot *)this_pointer)->myDet->acquire(); - - return this_pointer; -} - -int qDrawPlot::GetDataCallBack(detectorData *data, int fIndex, int subIndex, - void *this_pointer) { - ((qDrawPlot *)this_pointer)->GetData(data, fIndex, subIndex); - return 0; -} - -int qDrawPlot::GetData(detectorData *data, int fIndex, int subIndex) { -#ifdef VERYVERBOSE - std::cout << "******Entering GetDatafunction********\n"; - std::cout << "fIndex " << fIndex << '\n'; - std::cout << "subIndex " << subIndex << '\n'; - std::cout << "fname " << data->fileSaveName << '\n'; - std::cout << "npoints " << data->npoints << '\n'; - std::cout << "npy " << data->npy << '\n'; - std::cout << "progress " << data->progressIndex << '\n'; - if (data->values != NULL) - std::cout << "values " << data->values << '\n'; - std::cout << "databytes " << data->databytes << '\n'; - std::cout << "dynamicRange " << data->dynamicRange << '\n'; - std::cout << "fileIndex " << data->fileIndex << '\n'; -#endif - - // set progress - progress = (int)data->progressIndex; - // currentFrameIndex = fileIOStatic::getIndicesFromFileName(std::string(data->fileSaveName),currentFileIndex); - currentFileIndex = data->fileIndex; - -#ifdef VERYVERBOSE - std::cout << "progress:" << progress << '\n'; -#endif - // secondary title necessary to differentiate between frames when not - // saving data - char temp_title[2000]; - // findex is the frame index given by receiver, cannot be derived from - // file name - if (fIndex != -1) { - currentFrameIndex = fIndex; - sprintf(temp_title, "#%d", fIndex); - if ((detType == slsDetectorDefs::EIGER) && (subIndex != -1)) - sprintf(temp_title, "#%d %d", fIndex, subIndex); - } else { - - sprintf(temp_title, "#%d", currentFrame); - } - if (subIndex != -1) - sprintf(temp_title, "#%d %d", fIndex, subIndex); - - // Plot Disabled - if (!plotEnable) - return 0; - - // convert char* to double - if (data->values == NULL) { - data->values = new double[nPixelsX * nPixelsY]; - if (gainDataEnable) { - data->dgainvalues = new double[nPixelsX * nPixelsY]; - 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); - } - - // normal measurement or 1d scans - LockLastImageArray();//fixme: lock from beginning - /*if(!pthread_mutex_trylock(&(lastImageCompleteMutex))){*/ - // set title - plotTitle = QString(plotTitle_prefix) + - QString(data->fileSaveName).section('/', -1); - // only if you got the lock, do u need to remember lastimagenumber to - // plot - lastImageNumber = currentFrame + 1; - // cout<<"got last imagenumber:"< 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)) { - 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++; - emit UpdatePlotSignal(); - - -#ifdef VERYVERBOSE - std::cout << "Exiting GetData function" << '\n'; -#endif - return 0; -} - -int qDrawPlot::GetAcquisitionFinishedCallBack(double currentProgress, - int detectorStatus, - void *this_pointer) { - ((qDrawPlot *)this_pointer) - ->AcquisitionFinished(currentProgress, detectorStatus); -#ifdef VERYVERBOSE - std::cout << "acquisition finished callback worked ok\n"; -#endif - return 0; -} - -int qDrawPlot::AcquisitionFinished(double currentProgress, int detectorStatus) { -#ifdef VERBOSE - std::cout << "\nEntering Acquisition Finished with status "; -#endif - QString status = QString(slsDetectorDefs::runStatusType( - slsDetectorDefs::runStatus(detectorStatus)) - .c_str()); -#ifdef VERBOSE - std::cout << status.toAscii().constData() << " and progress " - << currentProgress << '\n'; -#endif - // error or stopped - if (detectorStatus == slsDetectorDefs::ERROR) { -#ifdef VERBOSE - std::cout << "Error in Acquisition\n\n"; -#endif - 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 - else if (currentProgress == 100) { - std::cout << "Acquisition Finished\n"; - } -#endif - StartStopDaqToggle(true); - // this lets the measurement tab know its over, and to enable tabs - emit UpdatingPlotFinished(); - - return 0; -} - -int qDrawPlot::GetProgressCallBack(double currentProgress, void *this_pointer) { - ((qDrawPlot *)this_pointer)->progress = currentProgress; - return 0; -} - - -int qDrawPlot::GetMeasurementFinishedCallBack(int currentMeasurementIndex, - int fileIndex, - void *this_pointer) { - ((qDrawPlot *)this_pointer) - ->MeasurementFinished(currentMeasurementIndex, fileIndex); - return 0; -} - -int qDrawPlot::MeasurementFinished(int currentMeasurementIndex, int fileIndex) { -#ifdef VERBOSE - std::cout << "Entering Measurement Finished with currentMeasurement " - << currentMeasurementIndex << " and fileIndex " << fileIndex - << '\n'; -#endif - - // to make sure it plots the last frame - while (plotRequired) { - usleep(2000); - } - - currentMeasurement = currentMeasurementIndex + 1; - currentFileIndex = fileIndex; -#ifdef VERBOSE - std::cout << "currentMeasurement:" << currentMeasurement << '\n'; -#endif - emit SetCurrentMeasurementSignal(currentMeasurement); - SetupMeasurement(); - /*if((myDet->setReceiverOnline()==slsDetectorDefs::ONLINE_FLAG) && - (myDet->getFramesCaughtByReceiver() == 0)) - boxPlot->setTitle("OLD_plot.raw");*/ - return 0; -} - -void qDrawPlot::UpdatePlot() { -#ifdef VERYVERBOSE - std::cout << "Entering UpdatePlot function\n"; -#endif - if (!plotEnable || !plotRequired) { - UnlockLastImageArray(); - return; - } - // 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 -} \ No newline at end of file diff --git a/slsDetectorGui/src/qTabMeasurement.cpp b/slsDetectorGui/src/qTabMeasurement.cpp index 86e9b5445..7f6295692 100755 --- a/slsDetectorGui/src/qTabMeasurement.cpp +++ b/slsDetectorGui/src/qTabMeasurement.cpp @@ -523,16 +523,18 @@ void qTabMeasurement::SetRunIndex(int val) { void qTabMeasurement::ResetProgress() { FILE_LOG(logDEBUG) << "Resetting progress"; - lblCurrentFrame->setText(QString::number(0)); - lblCurrentMeasurement->setText(QString::number(0)); + lblCurrentFrame->setText(""); + lblCurrentMeasurement->setText(""); progressBar->setValue(0); } void qTabMeasurement::UpdateProgress() { FILE_LOG(logDEBUG) << "Updating progress"; progressBar->setValue(myPlot->GetProgress()); - lblCurrentFrame->setText(QString::number(myPlot->GetCurrentFrameIndex())); - lblCurrentMeasurement->setText(QString::number(myPlot->GetCurrentMeasurementIndex())); + int64_t temp = myPlot->GetCurrentFrameIndex(); + lblCurrentFrame->setText(temp >= 0 ? QString::number(temp) : ""); + temp = myPlot->GetCurrentMeasurementIndex(); + lblCurrentMeasurement->setText(temp >= 0 ? QString::number(temp) : ""); } int qTabMeasurement::VerifyOutputDirectoryError() { @@ -574,8 +576,8 @@ void qTabMeasurement::StartAcquisition() { } FILE_LOG(logINFOBLUE) << "Starting Acquisition"; - lblCurrentFrame->setText(QString::number(0)); - lblCurrentMeasurement->setText(QString::number(0)); + lblCurrentFrame->setText(""); + lblCurrentMeasurement->setText(""); Enable(0); progressBar->setValue(0); progressTimer->start(100); diff --git a/slsDetectorSoftware/include/detectorData.h b/slsDetectorSoftware/include/detectorData.h index cf30bc124..7737a453c 100755 --- a/slsDetectorSoftware/include/detectorData.h +++ b/slsDetectorSoftware/include/detectorData.h @@ -1,71 +1,60 @@ - #include #include -#ifndef DETECTOR_DATA_H -#define DETECTOR_DATA_H +#pragma once /** - @short data structure to hold the detector data after postprocessing (e.g. to plot, store in a root tree etc.) + @short data structure to hold the detector data after postprocessing */ class detectorData { public: - /** @short The constructor - \param f_ind file index - \param fname file name to which the data are saved - \param np number of points in x coordinate defaults to the number of detector channels (1D detector) or dimension in x (2D detector) - \param ny dimension in y (2D detector) - \param cval pointer to data in char* format - \param dbytes number of bytes of image pointed to by cval pointer - \param dr dynamic range or bits per pixel - \param file_ind file index + /** + * Constructor + * @param progress progress index + * @param fname file name prefix + * @param nx number of detector channels (1D detector) or dimension in x (2D detector) + * @param ny dimension in y (2D detector) + * @param d pointer to data in char* format + * @param dbytes number of bytes of image pointed to by cval pointer + * @param dr dynamic range or bits per pixel + * @param fIndex file index */ - detectorData(double f_ind=-1, - const char *fname="", int np=-1, int ny=1, char *cval=NULL, int dbytes=0, int dr=0, - long long int file_ind=-1) : - progressIndex(f_ind), - npoints(np), npy(ny), cvalues(cval), databytes(dbytes), - dynamicRange(dr), dgainvalues(NULL), fileIndex(file_ind) { - strcpy(fileName,fname); - }; - - - int64_t getChannel(int i) { - int off=dynamicRange/8; - if (off==1) { - char val=*(cvalues+i); - return val; - } - if (off==2) { - int16_t val=*((int16_t*)(cvalues+i*off)); - return val; - } - if (off==4) { - int32_t val=*((int32_t*)(cvalues+i*off)); - return val; - } - if (off==8) { - int64_t val=*((int64_t*)(cvalues+i*off)); - return val; - } - return -1; - } + 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) {}; /** - @short The destructor - deletes also the arrays pointing to data/errors/angles if not NULL - cvalues are deleted by caller + * Destructor + * Also deletes gain + * data has to be deleted by caller */ - ~detectorData() {if(dgainvalues) delete [] dgainvalues;}; + ~detectorData() {if(gain) delete [] gain;}; + + int64_t getChannel(int i) { + int off=dynamicRange/8; + if (off==1) { + char val=*(data+i); + return val; + } + if (off==2) { + int16_t val=*((int16_t*)(data+i*off)); + return val; + } + if (off==4) { + int32_t val=*((int32_t*)(data+i*off)); + return val; + } + if (off==8) { + int64_t val=*((int64_t*)(data+i*off)); + return val; + } + return -1; + } //private: - double progressIndex;/**< @short file index */ - char fileName[1000];/**< @short file name */ - int npoints;/**< @short number of points */ - int npy;/**< @short dimensions in y coordinate*/ - char* cvalues; /**< @short pointer to the data as char arary */ - int databytes; /**< @short number of bytes of data. Used with cvalues */ - int dynamicRange; /**< @short dynamic range */ - double* dgainvalues; /**< @short pointer to gain data as double array for Jungfrau only in show gain mode */ - long long int fileIndex; /**< @short file index */ + double progressIndex; + std::string fileName; + uint64_t fileIndex; + int nx; + int ny; + char* data; + double* gain; + int databytes; + int dynamicRange; }; - - -#endif diff --git a/slsDetectorSoftware/include/multiSlsDetector.h b/slsDetectorSoftware/include/multiSlsDetector.h index e880f0f19..6dfeaf1e4 100755 --- a/slsDetectorSoftware/include/multiSlsDetector.h +++ b/slsDetectorSoftware/include/multiSlsDetector.h @@ -2091,16 +2091,16 @@ class multiSlsDetector : public virtual slsDetectorDefs { * gets detector status and progress index as arguments * @param pArg argument */ - void registerAcquisitionFinishedCallback(int (*func)(double, int, void *), + 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 detector status and progress index as arguments + * gets measurement index * @param pArg argument */ - void registerMeasurementFinishedCallback(int (*func)(int, int, void *), + void registerMeasurementFinishedCallback(void (*func)(int, void *), void *pArg); /** @@ -2109,7 +2109,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * gets detector status and progress index as arguments * @param pArg argument */ - void registerProgressCallback(int (*func)(double, void *), void *pArg); + void registerProgressCallback(void (*func)(double, void *), void *pArg); /** * register calbback for accessing detector final data, @@ -2120,7 +2120,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * s is for subframe number for eiger for 32 bit mode * @param pArg argument */ - void registerDataCallback(int (*userCallback)(detectorData *, int, int, + void registerDataCallback(void (*userCallback)(detectorData *, uint64_t, uint32_t, void *), void *pArg); @@ -2299,16 +2299,16 @@ class multiSlsDetector : public virtual slsDetectorDefs { /** detector data packed for the gui */ detectorData *thisData{nullptr}; - int (*acquisition_finished)(double, int, void *){nullptr}; + void (*acquisition_finished)(double, int, void *){nullptr}; void *acqFinished_p{nullptr}; - int (*measurement_finished)(int, int, void *){nullptr}; + void (*measurement_finished)(int, void *){nullptr}; void *measFinished_p{nullptr}; - int (*progress_call)(double, void *){nullptr}; + void (*progress_call)(double, void *){nullptr}; void *pProgressCallArg{nullptr}; - int (*dataReady)(detectorData *, int, int, void *){nullptr}; + void (*dataReady)(detectorData *, uint64_t, uint32_t, void *){nullptr}; void *pCallbackArg{nullptr}; }; diff --git a/slsDetectorSoftware/include/slsDetectorUsers.h b/slsDetectorSoftware/include/slsDetectorUsers.h index da3ec374d..35ffbc134 100755 --- a/slsDetectorSoftware/include/slsDetectorUsers.h +++ b/slsDetectorSoftware/include/slsDetectorUsers.h @@ -813,7 +813,7 @@ public: * @param pArg argument */ - void registerDataCallback(int( *userCallback)(detectorData* d, int f, int s, void*), void *pArg); + void registerDataCallback(void( *userCallback)(detectorData* d, uint64_t f, uint32_t s, void*), void *pArg); /** * register callback for accessing acquisition final data in client, @@ -821,15 +821,15 @@ public: * gets detector status and progress index as arguments * @param pArg argument */ - void registerAcquisitionFinishedCallback(int( *func)(double,int, void*), void *pArg); + 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 detector status and progress index as arguments + * gets measurement index * @param pArg argument */ - void registerMeasurementFinishedCallback(int( *func)(int,int, void*), void *pArg); + void registerMeasurementFinishedCallback(void( *func)(int, void*), void *pArg); /** * register callback for accessing detector progress in client, @@ -837,7 +837,7 @@ public: * gets detector status and progress index as arguments * @param pArg argument */ - void registerProgressCallback(int( *func)(double,void*), void *pArg); + void registerProgressCallback(void( *func)(double,void*), void *pArg); /** @short [usage strongly discouraged] sets parameters trough command line interface http://www.psi.ch/detectors/UsersSupportEN/slsDetectorClientHowTo.pdf diff --git a/slsDetectorSoftware/src/multiSlsDetector.cpp b/slsDetectorSoftware/src/multiSlsDetector.cpp index 38ba43453..88986047a 100755 --- a/slsDetectorSoftware/src/multiSlsDetector.cpp +++ b/slsDetectorSoftware/src/multiSlsDetector.cpp @@ -4069,24 +4069,24 @@ int multiSlsDetector::dumpDetectorSetup(const std::string &fname, int level) { return OK; } -void multiSlsDetector::registerAcquisitionFinishedCallback(int (*func)(double, int, void *), +void multiSlsDetector::registerAcquisitionFinishedCallback(void (*func)(double, int, void *), void *pArg) { acquisition_finished = func; acqFinished_p = pArg; } -void multiSlsDetector::registerMeasurementFinishedCallback(int (*func)(int, int, void *), +void multiSlsDetector::registerMeasurementFinishedCallback(void (*func)(int, void *), void *pArg) { measurement_finished = func; measFinished_p = pArg; } -void multiSlsDetector::registerProgressCallback(int (*func)(double, void *), void *pArg) { +void multiSlsDetector::registerProgressCallback(void (*func)(double, void *), void *pArg) { progress_call = func; pProgressCallArg = pArg; } -void multiSlsDetector::registerDataCallback(int (*userCallback)(detectorData *, int, int, void *), +void multiSlsDetector::registerDataCallback(void (*userCallback)(detectorData *, uint64_t, uint32_t, void *), void *pArg) { dataReady = userCallback; pCallbackArg = pArg; @@ -4233,7 +4233,7 @@ int multiSlsDetector::acquire() { findex = incrementFileIndex(); if (measurement_finished != nullptr) { - measurement_finished(im, findex, measFinished_p); + measurement_finished(im, measFinished_p); } if (multi_shm()->stoppedFlag != 0) { break; diff --git a/slsDetectorSoftware/src/slsDetectorUsers.cpp b/slsDetectorSoftware/src/slsDetectorUsers.cpp index 6a37dc0b7..69b538ebe 100755 --- a/slsDetectorSoftware/src/slsDetectorUsers.cpp +++ b/slsDetectorSoftware/src/slsDetectorUsers.cpp @@ -398,19 +398,19 @@ int slsDetectorUsers::setDetectorMode(int value, int detPos) { *********************************************************************/ -void slsDetectorUsers::registerDataCallback(int( *userCallback)(detectorData*, int, int, void*), void *pArg) { +void slsDetectorUsers::registerDataCallback(void( *userCallback)(detectorData*, uint64_t, uint32_t, void*), void *pArg) { detector.registerDataCallback(userCallback,pArg); } -void slsDetectorUsers::registerAcquisitionFinishedCallback(int( *func)(double,int, void*), void *pArg) { +void slsDetectorUsers::registerAcquisitionFinishedCallback(void( *func)(double,int, void*), void *pArg) { detector.registerAcquisitionFinishedCallback(func,pArg); } -void slsDetectorUsers::registerMeasurementFinishedCallback(int( *func)(int,int, void*), void *pArg) { +void slsDetectorUsers::registerMeasurementFinishedCallback(void( *func)(int,void*), void *pArg) { detector.registerMeasurementFinishedCallback(func,pArg); } -void slsDetectorUsers::registerProgressCallback(int( *func)(double,void*), void *pArg) { +void slsDetectorUsers::registerProgressCallback(void( *func)(double,void*), void *pArg) { detector.registerProgressCallback(func,pArg); }