From 753387c34c4f38e83c2552dcf4b2dca9f365e41f Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 4 Feb 2022 13:29:42 +0100 Subject: [PATCH 01/17] gotthard type can only have max 2 modules --- slsDetectorSoftware/src/DetectorImpl.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/slsDetectorSoftware/src/DetectorImpl.cpp b/slsDetectorSoftware/src/DetectorImpl.cpp index 15454ab23..c28fe4c0c 100644 --- a/slsDetectorSoftware/src/DetectorImpl.cpp +++ b/slsDetectorSoftware/src/DetectorImpl.cpp @@ -281,6 +281,13 @@ void DetectorImpl::addModule(const std::string &hostname) { // get type by connecting detectorType type = Module::getTypeFromDetector(host, port); + + // gotthard cannot have more than 2 modules (50um=1, 25um=2 + if ((type == GOTTHARD || type == GOTTHARD2) && modules.size() > 2) { + freeSharedMemory(); + throw sls::RuntimeError("Gotthard cannot have more than 2 modules"); + } + auto pos = modules.size(); modules.emplace_back( sls::make_unique(type, detectorIndex, pos, false)); From cfe627d3489422f4a6b6cbc5488345cb5a78cbc0 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 4 Feb 2022 14:47:52 +0100 Subject: [PATCH 02/17] gotthardu25 image reconstruction in gui --- slsDetectorGui/include/qDrawPlot.h | 3 +++ slsDetectorGui/src/qDrawPlot.cpp | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/slsDetectorGui/include/qDrawPlot.h b/slsDetectorGui/include/qDrawPlot.h index df96214bf..b13768037 100644 --- a/slsDetectorGui/include/qDrawPlot.h +++ b/slsDetectorGui/include/qDrawPlot.h @@ -91,8 +91,10 @@ class qDrawPlot : public QWidget, private Ui::PlotObject { void Update2dPlot(); void Update1dXYRange(); void Update2dXYRange(); + void rearrangeGotthard25data(double *data); static const int NUM_PEDESTAL_FRAMES = 20; + static const int NUM_GOTTHARD25_CHANS = 2560; sls::Detector *det; slsDetectorDefs::detectorType detType; @@ -164,4 +166,5 @@ class qDrawPlot : public QWidget, private Ui::PlotObject { uint32_t pixelMask{0}; uint32_t gainMask{0}; int gainOffset{0}; + bool gotthard25; }; diff --git a/slsDetectorGui/src/qDrawPlot.cpp b/slsDetectorGui/src/qDrawPlot.cpp index 40edc1538..54a4e129b 100644 --- a/slsDetectorGui/src/qDrawPlot.cpp +++ b/slsDetectorGui/src/qDrawPlot.cpp @@ -80,6 +80,10 @@ void qDrawPlot::SetupWidgetWindow() { fileSaveName = "Image"; } + gotthard25 = ((detType == slsDetectorDefs::GOTTHARD2 || + detType == slsDetectorDefs::GOTTHARD) && + det->size() == 2); + SetupPlots(); SetDataCallBack(true); det->registerAcquisitionFinishedCallback(&(GetAcquisitionFinishedCallBack), @@ -807,6 +811,11 @@ void qDrawPlot::GetData(detectorData *data, uint64_t frameIndex, isGainDataExtracted = false; } + // gotthard25um rearranging + if (gotthard25) { + rearrangeGotthard25data(rawData); + } + // title and frame index titles plotTitle = plotTitlePrefix + QString(data->fileName.c_str()).section('/', -1); @@ -1130,6 +1139,19 @@ void qDrawPlot::toDoublePixelData(double *dest, char *source, int size, } } +void qDrawPlot::rearrangeGotthard25data(double *data) { + const int nChans = NUM_GOTTHARD25_CHANS; + double temp[nChans] = {0.0}; + int nChansMod = nChans / 2; + for (int i = 0; i != nChansMod; ++i) { + // master module (interleave from front) + temp[i * 2] = data[i]; + // slave module (reverse interleave) + temp[(nChansMod - 1 - i) * 2 + 1] = data[nChansMod + i]; + } + memcpy(data, temp, nChans * sizeof(double)); +} + void qDrawPlot::UpdatePlot() { std::lock_guard lock(mPlots); LOG(logDEBUG) << "Update Plot"; From 20f3fb19af44205d937baaa88e6633eef9b8d8fe Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 4 Feb 2022 15:09:18 +0100 Subject: [PATCH 03/17] g25 option passed to hdf5 --- slsReceiverSoftware/src/DataProcessor.cpp | 4 +++- slsReceiverSoftware/src/HDF5VirtualFile.cpp | 4 ++-- slsReceiverSoftware/src/HDF5VirtualFile.h | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/slsReceiverSoftware/src/DataProcessor.cpp b/slsReceiverSoftware/src/DataProcessor.cpp index 700561924..b97da54df 100644 --- a/slsReceiverSoftware/src/DataProcessor.cpp +++ b/slsReceiverSoftware/src/DataProcessor.cpp @@ -213,7 +213,9 @@ void DataProcessor::CreateVirtualFile( if (virtualFile_) { delete virtualFile_; } - virtualFile_ = new HDF5VirtualFile(hdf5Lib); + gotthard25um = ((detectorType_ == GOTTHARD || detectorType_ == GOTTHARD2) && + (numModX * numModY) == 2); + virtualFile_ = new HDF5VirtualFile(hdf5Lib, gotthard25um); uint64_t numImagesProcessed = GetProcessedIndex() + 1; // maxframesperfile = 0 for infinite files diff --git a/slsReceiverSoftware/src/HDF5VirtualFile.cpp b/slsReceiverSoftware/src/HDF5VirtualFile.cpp index 71ef51099..8349291b9 100644 --- a/slsReceiverSoftware/src/HDF5VirtualFile.cpp +++ b/slsReceiverSoftware/src/HDF5VirtualFile.cpp @@ -5,8 +5,8 @@ #include -HDF5VirtualFile::HDF5VirtualFile(std::mutex *hdf5Lib) - : File(HDF5), hdf5Lib_(hdf5Lib) {} +HDF5VirtualFile::HDF5VirtualFile(std::mutex *hdf5Lib, bool g25) + : File(HDF5), hdf5Lib_(hdf5Lib), gotthard25um(g25) {} HDF5VirtualFile::~HDF5VirtualFile() { CloseFile(); } diff --git a/slsReceiverSoftware/src/HDF5VirtualFile.h b/slsReceiverSoftware/src/HDF5VirtualFile.h index a479bce2d..89b1c0b60 100644 --- a/slsReceiverSoftware/src/HDF5VirtualFile.h +++ b/slsReceiverSoftware/src/HDF5VirtualFile.h @@ -9,7 +9,7 @@ class HDF5VirtualFile : private virtual slsDetectorDefs, public File { public: - HDF5VirtualFile(std::mutex *hdf5Lib); + HDF5VirtualFile(std::mutex *hdf5Lib, bool g25); ~HDF5VirtualFile(); std::array GetFileAndDatasetName() const override; @@ -30,4 +30,5 @@ class HDF5VirtualFile : private virtual slsDetectorDefs, public File { H5File *fd_{nullptr}; std::string fileName_; std::string dataSetName_; + bool gotthard25um; }; \ No newline at end of file From f228fde6f77aeda2408393d8547d0c673abf75d8 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Mon, 7 Feb 2022 14:01:19 +0100 Subject: [PATCH 04/17] including stride and block for selecting hyperslab --- slsReceiverSoftware/src/DataProcessor.cpp | 5 ++-- slsReceiverSoftware/src/HDF5VirtualFile.cpp | 26 +++++++++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/slsReceiverSoftware/src/DataProcessor.cpp b/slsReceiverSoftware/src/DataProcessor.cpp index b97da54df..6f817e974 100644 --- a/slsReceiverSoftware/src/DataProcessor.cpp +++ b/slsReceiverSoftware/src/DataProcessor.cpp @@ -213,8 +213,9 @@ void DataProcessor::CreateVirtualFile( if (virtualFile_) { delete virtualFile_; } - gotthard25um = ((detectorType_ == GOTTHARD || detectorType_ == GOTTHARD2) && - (numModX * numModY) == 2); + bool gotthard25um = + ((detectorType_ == GOTTHARD || detectorType_ == GOTTHARD2) && + (numModX * numModY) == 2); virtualFile_ = new HDF5VirtualFile(hdf5Lib, gotthard25um); uint64_t numImagesProcessed = GetProcessedIndex() + 1; diff --git a/slsReceiverSoftware/src/HDF5VirtualFile.cpp b/slsReceiverSoftware/src/HDF5VirtualFile.cpp index 8349291b9..3b15831c4 100644 --- a/slsReceiverSoftware/src/HDF5VirtualFile.cpp +++ b/slsReceiverSoftware/src/HDF5VirtualFile.cpp @@ -103,19 +103,35 @@ void HDF5VirtualFile::CreateVirtualFile( ((numImagesCaught - framesSaved) > maxFramesPerFile) ? maxFramesPerFile : (numImagesCaught - framesSaved); + // starting location hsize_t start[3] = {framesSaved, 0, 0}; - hsize_t count[3] = {nDimx, nDimy, nDimz}; + // number of elements separating each block + hsize_t stride[3] = {1, 1, 1}; + // number of blocks + hsize_t count[3] = {1, 1, 1}; + // block size + hsize_t block[3] = {nDimx, nDimy, nDimz}; + + // starting location hsize_t startPara[2] = {framesSaved, 0}; - hsize_t countPara[2] = {nDimx, 1}; - // loop through readouts + // number of elements separating each block + hsize_t stridePara[3] = {1, 1}; + // number of blocks + hsize_t countPara[2] = {1, 1}; + // block size + hsize_t blockPara[3] = {nDimx, 1}; + + // loop through readouts (image) for (unsigned int i = 0; i < numModY * numModZ; ++i) { // setect data hyperslabs - vdsDataSpace.selectHyperslab(H5S_SELECT_SET, count, start); + vdsDataSpace.selectHyperslab(H5S_SELECT_SET, count, start, + stride, block); // select parameter hyperslabs vdsDataSpacePara.selectHyperslab(H5S_SELECT_SET, countPara, - startPara); + startPara, stridePara, + blockPara); // source file name std::ostringstream os; From f2cca765be03d6bb9186c4eed3544abade861ef2 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 10 Feb 2022 16:59:25 +0100 Subject: [PATCH 05/17] wip --- slsReceiverSoftware/src/HDF5VirtualFile.cpp | 170 +++++++++++++++++++- 1 file changed, 169 insertions(+), 1 deletion(-) diff --git a/slsReceiverSoftware/src/HDF5VirtualFile.cpp b/slsReceiverSoftware/src/HDF5VirtualFile.cpp index 3b15831c4..b52925fa1 100644 --- a/slsReceiverSoftware/src/HDF5VirtualFile.cpp +++ b/slsReceiverSoftware/src/HDF5VirtualFile.cpp @@ -28,7 +28,7 @@ void HDF5VirtualFile::CloseFile() { error.printErrorStack(); } } - +/* void HDF5VirtualFile::CreateVirtualFile( const std::string filePath, const std::string fileNamePrefix, const uint64_t fileIndex, const bool overWriteEnable, const bool silentMode, @@ -212,4 +212,172 @@ void HDF5VirtualFile::CreateVirtualFile( if (!silentMode) { LOG(logINFO) << "Virtual File: " << fileName_; } +} +*/ + +void HDF5VirtualFile::CreateVirtualFile( + const std::string filePath, const std::string fileNamePrefix, + const uint64_t fileIndex, const bool overWriteEnable, const bool silentMode, + const int modulePos, const int numUnitsPerReadout, + const uint32_t maxFramesPerFile, const uint64_t numImages, + const uint32_t nPixelsX, const uint32_t nPixelsY, + const uint32_t dynamicRange, const uint64_t numImagesCaught, + const int numModX, const int numModY, const DataType dataType, + const std::vector parameterNames, + const std::vector parameterDataTypes) { + // virtual file name + std::ostringstream osfn; + osfn << filePath << "/" << fileNamePrefix << "_virtual" + << "_" << fileIndex << ".h5"; + fileName_ = osfn.str(); + + uint64_t numModZ = numModX; + uint32_t nDimy = nPixelsY; + uint32_t nDimz = ((dynamicRange == 4) ? (nPixelsX / 2) : nPixelsX); + + std::lock_guard lock(*hdf5Lib_); + + try { + Exception::dontPrint(); // to handle errors + + // file + FileAccPropList fapl; + fapl.setFcloseDegree(H5F_CLOSE_STRONG); + fd_ = nullptr; + if (!overWriteEnable) + fd_ = new H5File(fileName_.c_str(), H5F_ACC_EXCL, + FileCreatPropList::DEFAULT, fapl); + else + fd_ = new H5File(fileName_.c_str(), H5F_ACC_TRUNC, + FileCreatPropList::DEFAULT, fapl); + + // attributes - version + double dValue = HDF5_WRITER_VERSION; + DataSpace dataspace_attr = DataSpace(H5S_SCALAR); + Attribute attribute = fd_->createAttribute( + "version", PredType::NATIVE_DOUBLE, dataspace_attr); + attribute.write(PredType::NATIVE_DOUBLE, &dValue); + + // virtual data dataspace + hsize_t vdsDims[3] = {numImagesCaught, numModY * nDimy, + numModZ * nDimz}; + DataSpace vdsDataSpace(3, vdsDims, nullptr); + + // property list (fill value and datatype) + int fill_value = -1; + DSetCreatPropList plist; + plist.setFillValue(dataType, &fill_value); + + // hyperslab + int numFiles = numImagesCaught / maxFramesPerFile; + if (numImagesCaught % maxFramesPerFile) + ++numFiles; + uint64_t framesSaved = 0; + // loop through files + for (int file = 0; file < numFiles; ++file) { + + uint64_t nDimx = + ((numImagesCaught - framesSaved) > maxFramesPerFile) + ? maxFramesPerFile + : (numImagesCaught - framesSaved); + + // static const int nImages = 1280 * nDimx; + // hsize_t coord[nImages][3]; + + // loop through readouts (image) + for (unsigned int iReadout = 0; iReadout < numModY * numModZ; + ++iReadout) { + + // memset(&coord, 0, sizeof(coord)); + /*for (int x = 0; x != (int)nDimx; ++x) { + for (int z = 0; z != 1280; ++z) { + coord[1280 * x + z][0] = x + iReadout * nDimx; + coord[1280 * x + z][2] = z; + } + }*/ + hsize_t coord[1280][3]; + memset(coord, 0, sizeof(coord)); + for (int z = 0; z != 1280; ++z) { + coord[z][0] = iReadout; + coord[z][2] = z; + } + /*for (int x = 0; x != nImages; ++x) { + for (int y = 0; y != 3; ++y) { + LOG(logDEBUG) << "coord[" << x << "][" << y << "]:\t" + << coord[x][y] << '\n'; + } + }*/ + + LOG(logINFO) << iReadout << " before selecting"; + vdsDataSpace.selectElements(H5S_SELECT_SET, 1280, + (const hsize_t *)coord); + LOG(logINFO) << iReadout << " after selecting"; + + LOG(logINFO) << "vds valid:" << vdsDataSpace.selectValid(); + + // source file name + std::ostringstream os; + os << filePath << "/" << fileNamePrefix << "_d" + << (modulePos * numUnitsPerReadout + iReadout) << "_f" + << file << '_' << fileIndex << ".h5"; + std::string srcFileName = os.str(); + LOG(logDEBUG1) << srcFileName; + + // find relative path + std::string relative_srcFileName = srcFileName; + { + size_t p = srcFileName.rfind('/', srcFileName.length()); + if (p != std::string::npos) + relative_srcFileName = (srcFileName.substr( + p + 1, srcFileName.length() - p)); + } + + // source dataset name + std::ostringstream osfn; + osfn << "/data"; + if (numImages > 1) + osfn << "_f" << std::setfill('0') << std::setw(12) << file; + std::string srcDatasetName = osfn.str(); + + // source data dataspace + hsize_t srcDims[3] = {nDimx, nDimy, nDimz}; + // hsize_t srcDimsMax[3] = {H5S_UNLIMITED, nDimy, nDimz}; + DataSpace srcDataSpace(3, srcDims); //, srcDimsMax); + /* + LOG(logINFO) << iReadout << " before selecting + src"; srcDataSpace.selectElements(H5S_SELECT_SET, 1280, + (const hsize_t + *)coord); LOG(logINFO) << iReadout << " after selecting src"; + LOG(logINFO) << "src valid:" << + srcDataSpace.selectValid(); + */ + // mapping of data property list + // int values[] = {53, 59, 61, 67}; /* New values to be written + // */ vdsDataSet->write(values, dataType, srcDataSpace, + // vdsDataSpace); + + LOG(logINFORED) << iReadout << " before vritual"; + plist.setVirtual(vdsDataSpace, relative_srcFileName.c_str(), + srcDatasetName.c_str(), srcDataSpace); + LOG(logINFORED) << iReadout << " before virtual"; + + // H5Sclose(srcDataspace); + } + framesSaved += nDimx; + } + // data dataset + dataSetName_ = "data"; + DataSet vdsDataSet(fd_->createDataSet(dataSetName_.c_str(), dataType, + vdsDataSpace, plist)); + + fd_->close(); + } catch (const Exception &error) { + error.printErrorStack(); + CloseFile(); + throw sls::RuntimeError( + "Could not create/overwrite virtual HDF5 handles"); + } + if (!silentMode) { + LOG(logINFO) << "Virtual File: " << fileName_; + } } \ No newline at end of file From a1ee681135e7cefc6db3a233bdb782b8a759490f Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 24 Feb 2022 11:15:03 +0100 Subject: [PATCH 06/17] - framescaught and frameindex now returns a vector for each port - progress looks at activated or enabled ports, so progress does not stagnate - (eiger) disable datastreaming also for virtual servers only for 10g - missing packets also takes care of disabled ports --- RELEASE.txt | 4 + python/slsdet/detector.py | 4 +- python/src/detector.cpp | 12 +-- .../slsDetectorFunctionList.c | 19 ++-- slsDetectorSoftware/include/sls/Detector.h | 8 +- slsDetectorSoftware/src/CmdProxy.cpp | 13 --- slsDetectorSoftware/src/CmdProxy.h | 16 ++-- slsDetectorSoftware/src/Detector.cpp | 11 ++- slsDetectorSoftware/src/DetectorImpl.cpp | 2 +- slsDetectorSoftware/src/Module.cpp | 48 ++++++++-- slsDetectorSoftware/src/Module.h | 4 +- .../tests/test-CmdProxy-rx.cpp | 32 ++++--- slsReceiverSoftware/src/ClientInterface.cpp | 20 ++-- slsReceiverSoftware/src/DataProcessor.cpp | 21 +--- slsReceiverSoftware/src/DataProcessor.h | 11 +-- slsReceiverSoftware/src/Implementation.cpp | 70 +++++++------- slsReceiverSoftware/src/Implementation.h | 4 +- slsReceiverSoftware/src/Listener.cpp | 20 +++- slsReceiverSoftware/src/Listener.h | 96 ++----------------- 19 files changed, 183 insertions(+), 232 deletions(-) diff --git a/RELEASE.txt b/RELEASE.txt index 23e0e1ade..d1f28e103 100755 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -42,6 +42,10 @@ This document describes the differences between v7.0.0 and v6.x.x - start non blocking acquisition at modular level - hostname cmd failed when connecting to servers in update mode (ctb, moench, jungfrau, eiger) - missingpackets signed (negative => extra packets) +- framescaught and frameindex now returns a vector for each port +- progress looks at activated or enabled ports, so progress does not stagnate +- (eiger) disable datastreaming also for virtual servers only for 10g +- missing packets also takes care of disabled ports 2. Resolved Issues diff --git a/python/slsdet/detector.py b/python/slsdet/detector.py index 1d2ec6218..b9a990804 100755 --- a/python/slsdet/detector.py +++ b/python/slsdet/detector.py @@ -599,7 +599,7 @@ class Detector(CppDetectorApi): @property @element def rx_framescaught(self): - """Number of frames caught by receiver.""" + """Number of frames caught by each port in receiver.""" return self.getFramesCaught() @property @@ -1905,7 +1905,7 @@ class Detector(CppDetectorApi): @property @element def rx_frameindex(self): - """Current frame index received in receiver during acquisition.""" + """Current frame index received for each port in receiver during acquisition.""" return self.getRxCurrentFrameIndex() @property diff --git a/python/src/detector.cpp b/python/src/detector.cpp index f796c3cbe..b9a87f95c 100644 --- a/python/src/detector.cpp +++ b/python/src/detector.cpp @@ -487,13 +487,17 @@ void init_det(py::module &m) { Detector::getReceiverStatus, py::arg() = Positions{}) .def("getFramesCaught", - (Result(Detector::*)(sls::Positions) const) & + (Result>(Detector::*)(sls::Positions) const) & Detector::getFramesCaught, py::arg() = Positions{}) .def("getNumMissingPackets", (Result>(Detector::*)(sls::Positions) const) & Detector::getNumMissingPackets, py::arg() = Positions{}) + .def("getRxCurrentFrameIndex", + (Result>(Detector::*)(sls::Positions) const) & + Detector::getRxCurrentFrameIndex, + py::arg() = Positions{}) .def("getNextFrameNumber", (Result(Detector::*)(sls::Positions) const) & Detector::getNextFrameNumber, @@ -1647,9 +1651,5 @@ void init_det(py::module &m) { Detector::getMeasurementTime, py::arg() = Positions{}) .def("getUserDetails", - (std::string(Detector::*)() const) & Detector::getUserDetails) - .def("getRxCurrentFrameIndex", - (Result(Detector::*)(sls::Positions) const) & - Detector::getRxCurrentFrameIndex, - py::arg() = Positions{}); + (std::string(Detector::*)() const) & Detector::getUserDetails); } diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c index 0955523a1..6ee0c43d4 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorFunctionList.c @@ -2285,15 +2285,17 @@ void *start_timer(void *arg) { } int skipData = 0; + int tgEnable = send_to_ten_gig; if (!eiger_virtual_activate || - (!eiger_virtual_left_datastream && !eiger_virtual_right_datastream)) { + (tgEnable && + (!eiger_virtual_left_datastream && !eiger_virtual_right_datastream))) { skipData = 1; LOG(logWARNING, ("Not sending Left and Right datastream\n")); } - if (!eiger_virtual_left_datastream) { + if (tgEnable && !eiger_virtual_left_datastream) { LOG(logWARNING, ("Not sending Left datastream\n")); } - if (!eiger_virtual_right_datastream) { + if (tgEnable && !eiger_virtual_right_datastream) { LOG(logWARNING, ("Not sending Right datastream\n")); } @@ -2303,7 +2305,6 @@ void *start_timer(void *arg) { int dr = eiger_dynamicrange; double bytesPerPixel = (double)dr / 8.00; - int tgEnable = send_to_ten_gig; int datasize = (tgEnable ? 4096 : 1024); int packetsize = datasize + sizeof(sls_detector_header); int maxPacketsPerFrame = (tgEnable ? 4 : 16) * dr; @@ -2465,14 +2466,16 @@ void *start_timer(void *arg) { } } } - if (eiger_virtual_left_datastream && i >= startval && - i <= endval) { + if ((!tgEnable || + (tgEnable && eiger_virtual_left_datastream)) && + i >= startval && i <= endval) { usleep(eiger_virtual_transmission_delay_left); sendUDPPacket(iRxEntry, 0, packetData, packetsize); LOG(logDEBUG1, ("Sent left packet: %d\n", i)); } - if (eiger_virtual_right_datastream && i >= startval && - i <= endval) { + if ((!tgEnable || + (tgEnable && eiger_virtual_right_datastream)) && + i >= startval && i <= endval) { usleep(eiger_virtual_transmission_delay_right); sendUDPPacket(iRxEntry, 1, packetData2, packetsize); LOG(logDEBUG1, ("Sent right packet: %d\n", i)); diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index ba10ac797..16a036b74 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -586,12 +586,17 @@ class Detector { /** Options: IDLE, TRANSMITTING, RUNNING */ Result getReceiverStatus(Positions pos = {}) const; - Result getFramesCaught(Positions pos = {}) const; + /** Gets the number of frames caught for each port in receiver. */ + Result> getFramesCaught(Positions pos = {}) const; /** Gets the number of missing packets for each port in receiver. Negative * number denotes extra packets. */ Result> getNumMissingPackets(Positions pos = {}) const; + /** Gets frame index for each port in receiver. */ + Result> + getRxCurrentFrameIndex(Positions pos = {}) const; + /** [Eiger][Jungfrau][Moench][CTB] */ Result getNextFrameNumber(Positions pos = {}) const; @@ -1902,7 +1907,6 @@ class Detector { */ std::string getUserDetails() const; - Result getRxCurrentFrameIndex(Positions pos = {}) const; ///@} private: diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index a4c08c50c..c2bdba22b 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -1286,19 +1286,6 @@ std::string CmdProxy::RxMissingPackets(int action) { WrongNumberOfParameters(0); } auto mp = det->getNumMissingPackets(std::vector{det_id}); - /* - auto tmp = det->getNumMissingPackets(std::vector{det_id}); - // convert to signed missing packets (to get excess) - Result> mp(tmp.size()); - for (unsigned int i = 0; i < mp.size(); ++i) { - mp[i] = static_cast(tmp[i]); - } - OR - Result> tmp; - for (auto val : tmp) { - mp.push_back(static_cast(val)); - } - */ os << OutString(mp) << '\n'; } else if (action == defs::PUT_ACTION) { throw sls::RuntimeError("Cannot put"); diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index b0c8ee303..d6bca310c 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -860,6 +860,7 @@ class CmdProxy { {"status", &CmdProxy::DetectorStatus}, {"rx_framescaught", &CmdProxy::rx_framescaught}, {"rx_missingpackets", &CmdProxy::RxMissingPackets}, + {"rx_frameindex", &CmdProxy::rx_frameindex}, {"nextframenumber", &CmdProxy::nextframenumber}, {"trigger", &CmdProxy::Trigger}, {"scan", &CmdProxy::Scan}, @@ -1084,8 +1085,7 @@ class CmdProxy { {"framecounter", &CmdProxy::framecounter}, {"runtime", &CmdProxy::runtime}, {"frametime", &CmdProxy::frametime}, - {"user", &CmdProxy::UserDetails}, - {"rx_frameindex", &CmdProxy::rx_frameindex} + {"user", &CmdProxy::UserDetails} }; @@ -1533,11 +1533,11 @@ class CmdProxy { "to IDLE or STOPPED. Goes to stop server."); GET_COMMAND(rx_framescaught, getFramesCaught, - "\n\tNumber of frames caught by receiver."); + "\n\tNumber of frames caught by each port in receiver."); - GET_COMMAND(rx_missingpackets, getNumMissingPackets, - "\n\tNumber of missing packets for each port in receiver. " - "Negative number denotes extra packets."); + GET_COMMAND( + rx_frameindex, getRxCurrentFrameIndex, + "\n\tCurrent frame index received in receiver during acquisition."); INTEGER_COMMAND_VEC_ID( nextframenumber, getNextFrameNumber, setNextFrameNumber, @@ -2251,10 +2251,6 @@ class CmdProxy { "ns|us|ms|s]\n\t[Jungfrau][Mythen3][Gotthard2][Moench][" "CTB] Timestamp at a frame start." "\n\t[Gotthard2] not in burst and auto mode."); - - GET_COMMAND( - rx_frameindex, getRxCurrentFrameIndex, - "\n\tCurrent frame index received in receiver during acquisition."); }; } // namespace sls diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 025370bf7..380065a5c 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -793,7 +793,7 @@ Result Detector::getReceiverStatus(Positions pos) const { return pimpl->Parallel(&Module::getReceiverStatus, pos); } -Result Detector::getFramesCaught(Positions pos) const { +Result> Detector::getFramesCaught(Positions pos) const { return pimpl->Parallel(&Module::getFramesCaughtByReceiver, pos); } @@ -802,6 +802,11 @@ Detector::getNumMissingPackets(Positions pos) const { return pimpl->Parallel(&Module::getNumMissingPackets, pos); } +Result> +Detector::getRxCurrentFrameIndex(Positions pos) const { + return pimpl->Parallel(&Module::getReceiverCurrentFrameIndex, pos); +} + Result Detector::getNextFrameNumber(Positions pos) const { return pimpl->Parallel(&Module::getNextFrameNumber, pos); } @@ -2311,10 +2316,6 @@ Result Detector::getMeasurementTime(Positions pos) const { std::string Detector::getUserDetails() const { return pimpl->getUserDetails(); } -Result Detector::getRxCurrentFrameIndex(Positions pos) const { - return pimpl->Parallel(&Module::getReceiverCurrentFrameIndex, pos); -} - std::vector Detector::getPortNumbers(int start_port) { int num_sockets_per_detector = pimpl->getNumberofUDPInterfaces({}).tsquash( "Number of UDP Interfaces is not consistent among modules"); diff --git a/slsDetectorSoftware/src/DetectorImpl.cpp b/slsDetectorSoftware/src/DetectorImpl.cpp index 15454ab23..86df25719 100644 --- a/slsDetectorSoftware/src/DetectorImpl.cpp +++ b/slsDetectorSoftware/src/DetectorImpl.cpp @@ -1142,7 +1142,7 @@ int DetectorImpl::acquire() { if (acquisition_finished != nullptr) { int status = Parallel(&Module::getRunStatus, {}).squash(ERROR); auto a = Parallel(&Module::getReceiverProgress, {}); - double progress = (*std::min_element(a.begin(), a.end())); + double progress = (*std::max_element(a.begin(), a.end())); acquisition_finished(progress, status, acqFinished_p); } diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index 599a754b8..ba0207e18 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -866,8 +866,26 @@ double Module::getReceiverProgress() const { return sendToReceiver(F_GET_RECEIVER_PROGRESS); } -int64_t Module::getFramesCaughtByReceiver() const { - return sendToReceiver(F_GET_RECEIVER_FRAMES_CAUGHT); +std::vector Module::getFramesCaughtByReceiver() const { + // TODO!(Erik) Refactor + LOG(logDEBUG1) << "Getting frames caught"; + if (shm()->useReceiverFlag) { + auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort); + client.Send(F_GET_RECEIVER_FRAMES_CAUGHT); + if (client.Receive() == FAIL) { + throw ReceiverError( + "Receiver " + std::to_string(moduleIndex) + + " returned error: " + client.readErrorMessage()); + } else { + auto nports = client.Receive(); + std::vector retval(nports); + client.Receive(retval); + LOG(logDEBUG1) << "Frames caught of Receiver" << moduleIndex << ": " + << sls::ToString(retval); + return retval; + } + } + throw RuntimeError("No receiver to get frames caught."); } std::vector Module::getNumMissingPackets() const { @@ -892,6 +910,28 @@ std::vector Module::getNumMissingPackets() const { throw RuntimeError("No receiver to get missing packets."); } +std::vector Module::getReceiverCurrentFrameIndex() const { + // TODO!(Erik) Refactor + LOG(logDEBUG1) << "Getting frame index"; + if (shm()->useReceiverFlag) { + auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort); + client.Send(F_GET_RECEIVER_FRAME_INDEX); + if (client.Receive() == FAIL) { + throw ReceiverError( + "Receiver " + std::to_string(moduleIndex) + + " returned error: " + client.readErrorMessage()); + } else { + auto nports = client.Receive(); + std::vector retval(nports); + client.Receive(retval); + LOG(logDEBUG1) << "Frame index of Receiver" << moduleIndex << ": " + << sls::ToString(retval); + return retval; + } + } + throw RuntimeError("No receiver to get frame index."); +} + uint64_t Module::getNextFrameNumber() const { return sendToDetector(F_GET_NEXT_FRAME_NUMBER); } @@ -2743,10 +2783,6 @@ int64_t Module::getMeasurementTime() const { return sendToDetectorStop(F_GET_MEASUREMENT_TIME); } -uint64_t Module::getReceiverCurrentFrameIndex() const { - return sendToReceiver(F_GET_RECEIVER_FRAME_INDEX); -} - // private void Module::checkArgs(const void *args, size_t args_size, void *retval, diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index 217b35075..84fb18e25 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -199,8 +199,9 @@ class Module : public virtual slsDetectorDefs { runStatus getRunStatus() const; runStatus getReceiverStatus() const; double getReceiverProgress() const; - int64_t getFramesCaughtByReceiver() const; + std::vector getFramesCaughtByReceiver() const; std::vector getNumMissingPackets() const; + std::vector getReceiverCurrentFrameIndex() const; uint64_t getNextFrameNumber() const; void setNextFrameNumber(uint64_t value); void sendSoftwareTrigger(const bool block); @@ -576,7 +577,6 @@ class Module : public virtual slsDetectorDefs { int64_t getNumberOfFramesFromStart() const; int64_t getActualTime() const; int64_t getMeasurementTime() const; - uint64_t getReceiverCurrentFrameIndex() const; private: void checkArgs(const void *args, size_t args_size, void *retval, diff --git a/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp b/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp index ca3c94a95..71800384e 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp @@ -99,7 +99,11 @@ TEST_CASE("rx_framescaught", "[.cmd][.rx]") { { std::ostringstream oss; proxy.Call("rx_framescaught", {}, -1, GET, oss); - REQUIRE(oss.str() == "rx_framescaught 0\n"); + if (det.getNumberofUDPInterfaces() == 1) { + REQUIRE(oss.str() == "rx_framescaught [0]\n"); + } else { + REQUIRE(oss.str() == "rx_framescaught [0, 0]\n"); + } } // Currently disabled may activate if we have a stable env @@ -138,6 +142,19 @@ TEST_CASE("rx_missingpackets", "[.cmd][.rx]") { } } +TEST_CASE("rx_frameindex", "[.cmd][.rx]") { + Detector det; + CmdProxy proxy(&det); + proxy.Call("rx_frameindex", {}, -1, GET); + + // This is a get only command + REQUIRE_THROWS(proxy.Call("rx_frameindex", {"2"}, -1, PUT)); + std::ostringstream oss; + proxy.Call("rx_frameindex", {}, 0, GET, oss); + std::string s = (oss.str()).erase(0, strlen("rx_frameindex ")); + REQUIRE(std::stoi(s) >= 0); +} + /* Network Configuration (Detector<->Receiver) */ TEST_CASE("rx_printconfig", "[.cmd][.rx]") { @@ -884,16 +901,3 @@ TEST_CASE("rx_jsonpara", "[.cmd][.rx]") { } /* Insignificant */ - -TEST_CASE("rx_frameindex", "[.cmd][.rx]") { - Detector det; - CmdProxy proxy(&det); - proxy.Call("rx_frameindex", {}, -1, GET); - - // This is a get only command - REQUIRE_THROWS(proxy.Call("rx_frameindex", {"2"}, -1, PUT)); - std::ostringstream oss; - proxy.Call("rx_frameindex", {}, 0, GET, oss); - std::string s = (oss.str()).erase(0, strlen("rx_frameindex ")); - REQUIRE(std::stoi(s) >= 0); -} diff --git a/slsReceiverSoftware/src/ClientInterface.cpp b/slsReceiverSoftware/src/ClientInterface.cpp index 9fa919359..fab78cb26 100644 --- a/slsReceiverSoftware/src/ClientInterface.cpp +++ b/slsReceiverSoftware/src/ClientInterface.cpp @@ -847,9 +847,13 @@ int ClientInterface::get_file_index(Interface &socket) { } int ClientInterface::get_frame_index(Interface &socket) { - uint64_t retval = impl()->getCurrentFrameIndex(); - LOG(logDEBUG1) << "frame index:" << retval; - return socket.sendResult(retval); + auto retval = impl()->getCurrentFrameIndex(); + LOG(logDEBUG1) << "frames index:" << sls::ToString(retval); + auto size = static_cast(retval.size()); + socket.Send(OK); + socket.Send(size); + socket.Send(retval); + return OK; } int ClientInterface::get_missing_packets(Interface &socket) { @@ -863,9 +867,13 @@ int ClientInterface::get_missing_packets(Interface &socket) { } int ClientInterface::get_frames_caught(Interface &socket) { - int64_t retval = impl()->getFramesCaught(); - LOG(logDEBUG1) << "frames caught:" << retval; - return socket.sendResult(retval); + auto retval = impl()->getFramesCaught(); + LOG(logDEBUG1) << "frames caught:" << sls::ToString(retval); + auto size = static_cast(retval.size()); + socket.Send(OK); + socket.Send(size); + socket.Send(retval); + return OK; } int ClientInterface::set_file_write(Interface &socket) { diff --git a/slsReceiverSoftware/src/DataProcessor.cpp b/slsReceiverSoftware/src/DataProcessor.cpp index 700561924..e4426aafb 100644 --- a/slsReceiverSoftware/src/DataProcessor.cpp +++ b/slsReceiverSoftware/src/DataProcessor.cpp @@ -52,19 +52,7 @@ DataProcessor::~DataProcessor() { DeleteFiles(); } /** getters */ -bool DataProcessor::GetStartedFlag() { return startedFlag_; } - -uint64_t DataProcessor::GetNumFramesCaught() { return numFramesCaught_; } - -uint64_t DataProcessor::GetNumCompleteFramesCaught() { - return numCompleteFramesCaught_; -} - -uint64_t DataProcessor::GetCurrentFrameIndex() { return currentFrameIndex_; } - -uint64_t DataProcessor::GetProcessedIndex() { - return currentFrameIndex_ - firstIndex_; -} +bool DataProcessor::GetStartedFlag() const { return startedFlag_; } void DataProcessor::SetFifo(Fifo *fifo) { fifo_ = fifo; } @@ -72,7 +60,6 @@ void DataProcessor::ResetParametersforNewAcquisition() { StopRunning(); startedFlag_ = false; numFramesCaught_ = 0; - numCompleteFramesCaught_ = 0; firstIndex_ = 0; currentFrameIndex_ = 0; firstStreamerFrame_ = true; @@ -215,10 +202,9 @@ void DataProcessor::CreateVirtualFile( } virtualFile_ = new HDF5VirtualFile(hdf5Lib); - uint64_t numImagesProcessed = GetProcessedIndex() + 1; // maxframesperfile = 0 for infinite files uint32_t framesPerFile = - ((maxFramesPerFile == 0) ? numImagesProcessed + 1 : maxFramesPerFile); + ((maxFramesPerFile == 0) ? numFramesCaught_ : maxFramesPerFile); // TODO: assumption 1: create virtual file even if no data in other // files (they exist anyway) assumption2: virtual file max frame index @@ -344,9 +330,6 @@ uint64_t DataProcessor::ProcessAnImage(char *buf) { currentFrameIndex_ = fnum; numFramesCaught_++; uint32_t nump = header.packetNumber; - if (nump == generalData_->packetsPerFrame) { - numCompleteFramesCaught_++; - } LOG(logDEBUG1) << "DataProcessing " << index << ": fnum:" << fnum; diff --git a/slsReceiverSoftware/src/DataProcessor.h b/slsReceiverSoftware/src/DataProcessor.h index 14034ccf8..ebd5c4ffa 100644 --- a/slsReceiverSoftware/src/DataProcessor.h +++ b/slsReceiverSoftware/src/DataProcessor.h @@ -36,13 +36,7 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject { ~DataProcessor() override; - bool GetStartedFlag(); - uint64_t GetNumFramesCaught(); - uint64_t GetNumCompleteFramesCaught(); - /** (-1 if no frames have been caught */ - uint64_t GetCurrentFrameIndex(); - /** (-1 if no frames have been caught) */ - uint64_t GetProcessedIndex(); + bool GetStartedFlag() const; void SetFifo(Fifo *f); void ResetParametersforNewAcquisition(); @@ -178,9 +172,6 @@ class DataProcessor : private virtual slsDetectorDefs, public ThreadObject { /** Number of frames caught */ uint64_t numFramesCaught_{0}; - /** Number of complete frames caught */ - uint64_t numCompleteFramesCaught_{0}; - /** Frame Number of latest processed frame number */ std::atomic currentFrameIndex_{0}; diff --git a/slsReceiverSoftware/src/Implementation.cpp b/slsReceiverSoftware/src/Implementation.cpp index fae4c1180..14a2545f1 100644 --- a/slsReceiverSoftware/src/Implementation.cpp +++ b/slsReceiverSoftware/src/Implementation.cpp @@ -453,51 +453,51 @@ void Implementation::setFramesPerFile(const uint32_t i) { * ************************************************/ slsDetectorDefs::runStatus Implementation::getStatus() const { return status; } -uint64_t Implementation::getFramesCaught() const { - uint64_t min = -1; - uint32_t flagsum = 0; - - for (const auto &it : dataProcessor) { - flagsum += it->GetStartedFlag(); - min = std::min(min, it->GetNumCompleteFramesCaught()); +std::vector Implementation::getFramesCaught() const { + std::vector numFramesCaught(numUDPInterfaces); + int index = 0; + for (const auto &it : listener) { + if (it->GetStartedFlag()) { + numFramesCaught[index] = it->GetNumCompleteFramesCaught(); + } + ++index; } - // no data processed - if (flagsum != dataProcessor.size()) - return 0; - - return min; + return numFramesCaught; } -uint64_t Implementation::getCurrentFrameIndex() const { - uint64_t max = 0; - uint32_t flagsum = 0; - +std::vector Implementation::getCurrentFrameIndex() const { + std::vector frameIndex(numUDPInterfaces); + int index = 0; for (const auto &it : listener) { - flagsum += it->GetStartedFlag(); - max = std::max(max, it->GetCurrentFrameIndex()); + if (it->GetStartedFlag()) { + frameIndex[index] = it->GetCurrentFrameIndex(); + } + ++index; } - // no data processed - if (flagsum != listener.size()) - return 0; - return max; + return frameIndex; } double Implementation::getProgress() const { - // get minimum of processed frame indices - uint64_t currentFrameIndex = 0; - uint32_t flagsum = 0; + if (!activated || (!detectorDataStream[0] && !detectorDataStream[1])) { + return 100.00; + } + // if disabled, considering only 1 port + double totalFrames = (double)(numberOfTotalFrames * listener.size()); + if (!detectorDataStream[0] || !detectorDataStream[1]) { + totalFrames /= 2; + } + + double progress = 0; + int index = 0; for (const auto &it : listener) { - flagsum += it->GetStartedFlag(); - currentFrameIndex = std::max(currentFrameIndex, it->GetListenedIndex()); + if (detectorDataStream[index] && it->GetStartedFlag()) { + progress += (it->GetListenedIndex() + 1) / totalFrames; + } + ++index; } - // no data processed - if (flagsum != listener.size()) { - currentFrameIndex = -1; - } - - return (100.00 * - ((double)(currentFrameIndex + 1) / (double)numberOfTotalFrames)); + progress *= 100; + return progress; } std::vector Implementation::getNumMissingPackets() const { @@ -627,7 +627,7 @@ void Implementation::stopReceiver() { // print summary uint64_t tot = 0; for (int i = 0; i < numUDPInterfaces; i++) { - int nf = dataProcessor[i]->GetNumCompleteFramesCaught(); + int nf = listener[i]->GetNumCompleteFramesCaught(); tot += nf; std::string mpMessage = std::to_string(mp[i]); if (mp[i] < 0) { diff --git a/slsReceiverSoftware/src/Implementation.h b/slsReceiverSoftware/src/Implementation.h index 8264c7c34..e798f1a20 100644 --- a/slsReceiverSoftware/src/Implementation.h +++ b/slsReceiverSoftware/src/Implementation.h @@ -84,8 +84,8 @@ class Implementation : private virtual slsDetectorDefs { * * * ************************************************/ runStatus getStatus() const; - uint64_t getFramesCaught() const; - uint64_t getCurrentFrameIndex() const; + std::vector getFramesCaught() const; + std::vector getCurrentFrameIndex() const; double getProgress() const; std::vector getNumMissingPackets() const; void setScan(slsDetectorDefs::scanParameters s); diff --git a/slsReceiverSoftware/src/Listener.cpp b/slsReceiverSoftware/src/Listener.cpp index 8229d22c3..a5c6dfda1 100644 --- a/slsReceiverSoftware/src/Listener.cpp +++ b/slsReceiverSoftware/src/Listener.cpp @@ -36,12 +36,22 @@ Listener::~Listener() = default; uint64_t Listener::GetPacketsCaught() const { return numPacketsCaught; } +uint64_t Listener::GetNumCompleteFramesCaught() const { + return numCompleteFramesCaught; +} + uint64_t Listener::GetLastFrameIndexCaught() const { return lastCaughtFrameIndex; } int64_t Listener::GetNumMissingPacket(bool stoppedFlag, uint64_t numPackets) const { + if (!activated) { + return 0; + } + if (!(*detectorDataStream)) { + return 0; + } if (!stoppedFlag) { return (numPackets - numPacketsCaught); } @@ -53,11 +63,11 @@ int64_t Listener::GetNumMissingPacket(bool stoppedFlag, numPacketsCaught; } -bool Listener::GetStartedFlag() { return startedFlag; } +bool Listener::GetStartedFlag() const { return startedFlag; } -uint64_t Listener::GetCurrentFrameIndex() { return lastCaughtFrameIndex; } +uint64_t Listener::GetCurrentFrameIndex() const { return lastCaughtFrameIndex; } -uint64_t Listener::GetListenedIndex() { +uint64_t Listener::GetListenedIndex() const { return lastCaughtFrameIndex - firstIndex; } @@ -67,6 +77,7 @@ void Listener::ResetParametersforNewAcquisition() { StopRunning(); startedFlag = false; numPacketsCaught = 0; + numCompleteFramesCaught = 0; firstIndex = 0; currentFrameIndex = 0; lastCaughtFrameIndex = 0; @@ -607,6 +618,9 @@ uint32_t Listener::ListenToAnImage(char *buf) { // complete image new_header->detHeader.packetNumber = numpackets; // number of packets caught new_header->detHeader.frameNumber = currentFrameIndex; + if (numpackets == pperFrame) { + ++numCompleteFramesCaught; + } ++currentFrameIndex; return imageSize; } diff --git a/slsReceiverSoftware/src/Listener.h b/slsReceiverSoftware/src/Listener.h index 9a02449b3..9cf127b68 100644 --- a/slsReceiverSoftware/src/Listener.h +++ b/slsReceiverSoftware/src/Listener.h @@ -51,53 +51,19 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject { */ ~Listener(); - /** - * Get Packets caught - * @return Packets caught - */ uint64_t GetPacketsCaught() const; - - /** - * Get Last Frame index caught - * @return last frame index caught - */ + uint64_t GetNumCompleteFramesCaught() const; uint64_t GetLastFrameIndexCaught() const; - - /** Get number of missing packets, returns negative values in case to extra - * packet */ + /** negative values in case of extra packets */ int64_t GetNumMissingPacket(bool stoppedFlag, uint64_t numPackets) const; + bool GetStartedFlag() const; + uint64_t GetCurrentFrameIndex() const; + uint64_t GetListenedIndex() const; - bool GetStartedFlag(); - - uint64_t GetCurrentFrameIndex(); - /** (-1 if no frames have been caught) */ - uint64_t GetListenedIndex(); - - /** - * Set Fifo pointer to the one given - * @param f address of Fifo pointer - */ void SetFifo(Fifo *f); - - /** - * Reset parameters for new acquisition - */ void ResetParametersforNewAcquisition(); - - /** - * Set GeneralData pointer to the one given - * @param g address of GeneralData (Detector Data) pointer - */ void SetGeneralData(GeneralData *g); - - /** - * Creates UDP Sockets - */ void CreateUDPSockets(); - - /** - * Shuts down and deletes UDP Sockets - */ void ShutDownUDPSocket(); /** @@ -116,10 +82,6 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject { void SetHardCodedPosition(uint16_t r, uint16_t c); private: - /** - * Record First Acquisition Index - * @param fnum frame index to record - */ void RecordFirstIndex(uint64_t fnum); /** @@ -146,55 +108,25 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject { */ uint32_t ListenToAnImage(char *buf); - /** - * Print Fifo Statistics - */ void PrintFifoStatistics(); - /** type of thread */ static const std::string TypeName; - - /** GeneralData (Detector Data) object */ GeneralData *generalData{nullptr}; - - /** Fifo structure */ Fifo *fifo; // individual members - /** Detector Type */ detectorType myDetectorType; - - /** Receiver Status */ std::atomic *status; - - /** UDP Socket - Detector to Receiver */ std::unique_ptr udpSocket{nullptr}; - - /** UDP Port Number */ uint32_t *udpPortNumber; - - /** ethernet interface */ std::string *eth; - - /** UDP Socket Buffer Size */ int *udpSocketBufferSize; - - /** actual UDP Socket Buffer Size (double due to kernel bookkeeping) */ + /** double due to kernel bookkeeping */ int *actualUDPSocketBufferSize; - - /** frames per file */ uint32_t *framesPerFile; - - /** frame discard policy */ frameDiscardPolicy *frameDiscardMode; - - /** Activated/Deactivated */ bool *activated; - - /** detector data stream */ bool *detectorDataStream; - - /** Silent Mode */ bool *silentMode; /** row hardcoded as 1D or 2d, @@ -209,15 +141,12 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject { // acquisition start /** Aquisition Started flag */ std::atomic startedFlag{false}; - /** Frame Number of First Frame */ uint64_t firstIndex{0}; // for acquisition summary - /** Number of complete Packets caught */ std::atomic numPacketsCaught{0}; - - /** Last Frame Index caught from udp network */ + std::atomic numCompleteFramesCaught{0}; std::atomic lastCaughtFrameIndex{0}; // parameters to acquire image @@ -225,25 +154,16 @@ class Listener : private virtual slsDetectorDefs, public ThreadObject { * ( always check startedFlag for validity first) */ uint64_t currentFrameIndex{0}; - /** True if there is a packet carry over from previous Image */ bool carryOverFlag{false}; - - /** Carry over packet buffer */ std::unique_ptr carryOverPacket; - /** Listening buffer for one packet - might be removed when we can peek and * eiger fnum is in header */ std::unique_ptr listeningPacket; - - /** if the udp socket is connected */ std::atomic udpSocketAlive{false}; - // for print progress during acquisition - /** number of packets for statistic */ + // for print progress during acquisition*/ uint32_t numPacketsStatistic{0}; - - /** number of images for statistic */ uint32_t numFramesStatistic{0}; /** From b9016fad1224fa2a16b2db15110d91a5423b9a07 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 24 Feb 2022 11:26:17 +0100 Subject: [PATCH 07/17] reverting to normal command parsing for missing packets --- slsDetectorSoftware/src/CmdProxy.cpp | 21 --------------------- slsDetectorSoftware/src/CmdProxy.h | 6 +++++- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/slsDetectorSoftware/src/CmdProxy.cpp b/slsDetectorSoftware/src/CmdProxy.cpp index c2bdba22b..0e8a1a3db 100644 --- a/slsDetectorSoftware/src/CmdProxy.cpp +++ b/slsDetectorSoftware/src/CmdProxy.cpp @@ -1274,27 +1274,6 @@ std::string CmdProxy::DetectorStatus(int action) { return os.str(); } -std::string CmdProxy::RxMissingPackets(int action) { - std::ostringstream os; - os << cmd << ' '; - if (action == defs::HELP_ACTION) { - os << "Number of missing packets for each port in receiver. If " - "negative, they are packets in excess. " - << '\n'; - } else if (action == defs::GET_ACTION) { - if (!args.empty()) { - WrongNumberOfParameters(0); - } - auto mp = det->getNumMissingPackets(std::vector{det_id}); - os << OutString(mp) << '\n'; - } else if (action == defs::PUT_ACTION) { - throw sls::RuntimeError("Cannot put"); - } else { - throw sls::RuntimeError("Unknown action"); - } - return os.str(); -} - std::string CmdProxy::Scan(int action) { std::ostringstream os; os << cmd << ' '; diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index d6bca310c..4efcfe4ed 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -859,7 +859,7 @@ class CmdProxy { {"rx_status", &CmdProxy::ReceiverStatus}, {"status", &CmdProxy::DetectorStatus}, {"rx_framescaught", &CmdProxy::rx_framescaught}, - {"rx_missingpackets", &CmdProxy::RxMissingPackets}, + {"rx_missingpackets", &CmdProxy::rx_missingpackets}, {"rx_frameindex", &CmdProxy::rx_frameindex}, {"nextframenumber", &CmdProxy::nextframenumber}, {"trigger", &CmdProxy::Trigger}, @@ -1535,6 +1535,10 @@ class CmdProxy { GET_COMMAND(rx_framescaught, getFramesCaught, "\n\tNumber of frames caught by each port in receiver."); + GET_COMMAND(rx_missingpackets, getNumMissingPackets, + "\n\tNumber of missing packets for each port in receiver. If " + "negative, they are packets in excess. "); + GET_COMMAND( rx_frameindex, getRxCurrentFrameIndex, "\n\tCurrent frame index received in receiver during acquisition."); From 5a5d4eadf197f58f1f0a13665e692398f6ffe0bd Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 24 Feb 2022 11:27:29 +0100 Subject: [PATCH 08/17] minor --- slsDetectorSoftware/src/CmdProxy.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index 4efcfe4ed..f41b04622 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -1539,9 +1539,9 @@ class CmdProxy { "\n\tNumber of missing packets for each port in receiver. If " "negative, they are packets in excess. "); - GET_COMMAND( - rx_frameindex, getRxCurrentFrameIndex, - "\n\tCurrent frame index received in receiver during acquisition."); + GET_COMMAND(rx_frameindex, getRxCurrentFrameIndex, + "\n\tCurrent frame index received for each port in receiver " + "during acquisition."); INTEGER_COMMAND_VEC_ID( nextframenumber, getNextFrameNumber, setNextFrameNumber, From 4db34effda17909480d191fdb3f404e31eb13ead Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 24 Feb 2022 11:57:00 +0100 Subject: [PATCH 09/17] fixed tests --- .../tests/test-CmdProxy-rx.cpp | 32 +++++++++++++------ .../tests/test-CircularFifo.cpp | 8 ++--- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp b/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp index 71800384e..45a6a6e5c 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-rx.cpp @@ -93,13 +93,15 @@ TEST_CASE("rx_framescaught", "[.cmd][.rx]") { CmdProxy proxy(&det); // This ensures 0 caught frames + auto prev_val = det.getFileWrite(); det.setFileWrite(false); // avoid writing or error on file creation det.startReceiver(); det.stopReceiver(); { std::ostringstream oss; proxy.Call("rx_framescaught", {}, -1, GET, oss); - if (det.getNumberofUDPInterfaces() == 1) { + if (det.getNumberofUDPInterfaces().tsquash( + "inconsistent number of interfaces") == 1) { REQUIRE(oss.str() == "rx_framescaught [0]\n"); } else { REQUIRE(oss.str() == "rx_framescaught [0, 0]\n"); @@ -115,10 +117,15 @@ TEST_CASE("rx_framescaught", "[.cmd][.rx]") { // proxy.Call("rx_framescaught", {}, -1, GET, oss); // REQUIRE(oss.str() == "rx_framescaught 1\n"); // } + + for (int i = 0; i != det.size(); ++i) { + det.setFileWrite(prev_val[i], {i}); + } } TEST_CASE("rx_missingpackets", "[.cmd][.rx]") { Detector det; + auto prev_val = det.getFileWrite(); det.setFileWrite(false); // avoid writing or error on file creation CmdProxy proxy(&det); { @@ -127,8 +134,12 @@ TEST_CASE("rx_missingpackets", "[.cmd][.rx]") { det.stopReceiver(); std::ostringstream oss; proxy.Call("rx_missingpackets", {}, -1, GET, oss); - std::string s = (oss.str()).erase(0, strlen("rx_missingpackets [")); - REQUIRE(std::stoi(s) > 0); + if (det.getNumberofUDPInterfaces().tsquash( + "inconsistent number of interfaces") == 1) { + REQUIRE(oss.str() != "rx_missingpackets [0]\n"); + } else { + REQUIRE(oss.str() != "rx_missingpackets [0, 0]\n"); + } } { // 0 missing packets (takes into account that acquisition is stopped) @@ -137,8 +148,15 @@ TEST_CASE("rx_missingpackets", "[.cmd][.rx]") { det.stopReceiver(); std::ostringstream oss; proxy.Call("rx_missingpackets", {}, -1, GET, oss); - std::string s = (oss.str()).erase(0, strlen("rx_missingpackets [")); - REQUIRE(std::stoi(s) == 0); + if (det.getNumberofUDPInterfaces().tsquash( + "inconsistent number of interfaces") == 1) { + REQUIRE(oss.str() == "rx_missingpackets [0]\n"); + } else { + REQUIRE(oss.str() == "rx_missingpackets [0, 0]\n"); + } + } + for (int i = 0; i != det.size(); ++i) { + det.setFileWrite(prev_val[i], {i}); } } @@ -149,10 +167,6 @@ TEST_CASE("rx_frameindex", "[.cmd][.rx]") { // This is a get only command REQUIRE_THROWS(proxy.Call("rx_frameindex", {"2"}, -1, PUT)); - std::ostringstream oss; - proxy.Call("rx_frameindex", {}, 0, GET, oss); - std::string s = (oss.str()).erase(0, strlen("rx_frameindex ")); - REQUIRE(std::stoi(s) >= 0); } /* Network Configuration (Detector<->Receiver) */ diff --git a/slsReceiverSoftware/tests/test-CircularFifo.cpp b/slsReceiverSoftware/tests/test-CircularFifo.cpp index 5da9bf39f..db1523c0b 100644 --- a/slsReceiverSoftware/tests/test-CircularFifo.cpp +++ b/slsReceiverSoftware/tests/test-CircularFifo.cpp @@ -34,8 +34,8 @@ TEST_CASE("Push pop") { for (size_t i = 0; i != vec.size(); ++i) { fifo.push(p); ++p; - CHECK(fifo.getDataValue() == i + 1); - CHECK(fifo.getFreeValue() == 4 - i); + CHECK(fifo.getDataValue() == (int)(i + 1)); + CHECK(fifo.getFreeValue() == (int)(4 - i)); } CHECK(fifo.isEmpty() == false); @@ -44,8 +44,8 @@ TEST_CASE("Push pop") { for (size_t i = 0; i != vec.size(); ++i) { fifo.pop(p); CHECK(*p == vec[i]); - CHECK(fifo.getDataValue() == 4 - i); - CHECK(fifo.getFreeValue() == i + 1); + CHECK(fifo.getDataValue() == (int)(4 - i)); + CHECK(fifo.getFreeValue() == (int)(i + 1)); } CHECK(fifo.isEmpty() == true); From 06281ccae9944ba709ad0da96d16374513091ec9 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 17 Mar 2022 12:11:51 +0100 Subject: [PATCH 10/17] firmware reverses slave channels --- slsDetectorGui/include/qDrawPlot.h | 2 +- slsDetectorGui/src/qDrawPlot.cpp | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/slsDetectorGui/include/qDrawPlot.h b/slsDetectorGui/include/qDrawPlot.h index b13768037..2c8739040 100644 --- a/slsDetectorGui/include/qDrawPlot.h +++ b/slsDetectorGui/include/qDrawPlot.h @@ -94,7 +94,7 @@ class qDrawPlot : public QWidget, private Ui::PlotObject { void rearrangeGotthard25data(double *data); static const int NUM_PEDESTAL_FRAMES = 20; - static const int NUM_GOTTHARD25_CHANS = 2560; + static const int NUM_GOTTHARD25_CHANS = 1280; sls::Detector *det; slsDetectorDefs::detectorType detType; diff --git a/slsDetectorGui/src/qDrawPlot.cpp b/slsDetectorGui/src/qDrawPlot.cpp index 80b848b49..5101c11dd 100644 --- a/slsDetectorGui/src/qDrawPlot.cpp +++ b/slsDetectorGui/src/qDrawPlot.cpp @@ -1156,15 +1156,14 @@ void qDrawPlot::toDoublePixelData(double *dest, char *source, int size, void qDrawPlot::rearrangeGotthard25data(double *data) { const int nChans = NUM_GOTTHARD25_CHANS; - double temp[nChans] = {0.0}; - int nChansMod = nChans / 2; - for (int i = 0; i != nChansMod; ++i) { - // master module (interleave from front) + double temp[nChans * 2] = {0.0}; + for (int i = 0; i != nChans; ++i) { + // master module temp[i * 2] = data[i]; - // slave module (reverse interleave) - temp[(nChansMod - 1 - i) * 2 + 1] = data[nChansMod + i]; + // slave module + temp[i * 2 + 1] = data[nChans + i]; } - memcpy(data, temp, nChans * sizeof(double)); + memcpy(data, temp, nChans * 2 * sizeof(double)); } void qDrawPlot::UpdatePlot() { From 3e5b8840b467149b9d0af45a12daac151f5bfe9a Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 17 Mar 2022 12:21:29 +0100 Subject: [PATCH 11/17] wip --- RELEASE.txt | 2 +- slsReceiverSoftware/src/HDF5VirtualFile.cpp | 170 +------------------- 2 files changed, 2 insertions(+), 170 deletions(-) diff --git a/RELEASE.txt b/RELEASE.txt index 2b46be795..c72a50339 100755 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -50,7 +50,7 @@ This document describes the differences between v7.0.0 and v6.x.x - added geometry to metadata - 10g eiger nextframenumber get fixed. - stop, able to set nextframenumber to a consistent (max + 1) for all modules if different (eiger/ctb/jungfrau/moench) - +- gotthard 25 um image reconstructed in gui and virtual hdf5 (firmware updated for slave to reverse channels) 2. Resolved Issues ================== diff --git a/slsReceiverSoftware/src/HDF5VirtualFile.cpp b/slsReceiverSoftware/src/HDF5VirtualFile.cpp index b52925fa1..6c5f3202c 100644 --- a/slsReceiverSoftware/src/HDF5VirtualFile.cpp +++ b/slsReceiverSoftware/src/HDF5VirtualFile.cpp @@ -28,7 +28,7 @@ void HDF5VirtualFile::CloseFile() { error.printErrorStack(); } } -/* + void HDF5VirtualFile::CreateVirtualFile( const std::string filePath, const std::string fileNamePrefix, const uint64_t fileIndex, const bool overWriteEnable, const bool silentMode, @@ -213,171 +213,3 @@ void HDF5VirtualFile::CreateVirtualFile( LOG(logINFO) << "Virtual File: " << fileName_; } } -*/ - -void HDF5VirtualFile::CreateVirtualFile( - const std::string filePath, const std::string fileNamePrefix, - const uint64_t fileIndex, const bool overWriteEnable, const bool silentMode, - const int modulePos, const int numUnitsPerReadout, - const uint32_t maxFramesPerFile, const uint64_t numImages, - const uint32_t nPixelsX, const uint32_t nPixelsY, - const uint32_t dynamicRange, const uint64_t numImagesCaught, - const int numModX, const int numModY, const DataType dataType, - const std::vector parameterNames, - const std::vector parameterDataTypes) { - // virtual file name - std::ostringstream osfn; - osfn << filePath << "/" << fileNamePrefix << "_virtual" - << "_" << fileIndex << ".h5"; - fileName_ = osfn.str(); - - uint64_t numModZ = numModX; - uint32_t nDimy = nPixelsY; - uint32_t nDimz = ((dynamicRange == 4) ? (nPixelsX / 2) : nPixelsX); - - std::lock_guard lock(*hdf5Lib_); - - try { - Exception::dontPrint(); // to handle errors - - // file - FileAccPropList fapl; - fapl.setFcloseDegree(H5F_CLOSE_STRONG); - fd_ = nullptr; - if (!overWriteEnable) - fd_ = new H5File(fileName_.c_str(), H5F_ACC_EXCL, - FileCreatPropList::DEFAULT, fapl); - else - fd_ = new H5File(fileName_.c_str(), H5F_ACC_TRUNC, - FileCreatPropList::DEFAULT, fapl); - - // attributes - version - double dValue = HDF5_WRITER_VERSION; - DataSpace dataspace_attr = DataSpace(H5S_SCALAR); - Attribute attribute = fd_->createAttribute( - "version", PredType::NATIVE_DOUBLE, dataspace_attr); - attribute.write(PredType::NATIVE_DOUBLE, &dValue); - - // virtual data dataspace - hsize_t vdsDims[3] = {numImagesCaught, numModY * nDimy, - numModZ * nDimz}; - DataSpace vdsDataSpace(3, vdsDims, nullptr); - - // property list (fill value and datatype) - int fill_value = -1; - DSetCreatPropList plist; - plist.setFillValue(dataType, &fill_value); - - // hyperslab - int numFiles = numImagesCaught / maxFramesPerFile; - if (numImagesCaught % maxFramesPerFile) - ++numFiles; - uint64_t framesSaved = 0; - // loop through files - for (int file = 0; file < numFiles; ++file) { - - uint64_t nDimx = - ((numImagesCaught - framesSaved) > maxFramesPerFile) - ? maxFramesPerFile - : (numImagesCaught - framesSaved); - - // static const int nImages = 1280 * nDimx; - // hsize_t coord[nImages][3]; - - // loop through readouts (image) - for (unsigned int iReadout = 0; iReadout < numModY * numModZ; - ++iReadout) { - - // memset(&coord, 0, sizeof(coord)); - /*for (int x = 0; x != (int)nDimx; ++x) { - for (int z = 0; z != 1280; ++z) { - coord[1280 * x + z][0] = x + iReadout * nDimx; - coord[1280 * x + z][2] = z; - } - }*/ - hsize_t coord[1280][3]; - memset(coord, 0, sizeof(coord)); - for (int z = 0; z != 1280; ++z) { - coord[z][0] = iReadout; - coord[z][2] = z; - } - /*for (int x = 0; x != nImages; ++x) { - for (int y = 0; y != 3; ++y) { - LOG(logDEBUG) << "coord[" << x << "][" << y << "]:\t" - << coord[x][y] << '\n'; - } - }*/ - - LOG(logINFO) << iReadout << " before selecting"; - vdsDataSpace.selectElements(H5S_SELECT_SET, 1280, - (const hsize_t *)coord); - LOG(logINFO) << iReadout << " after selecting"; - - LOG(logINFO) << "vds valid:" << vdsDataSpace.selectValid(); - - // source file name - std::ostringstream os; - os << filePath << "/" << fileNamePrefix << "_d" - << (modulePos * numUnitsPerReadout + iReadout) << "_f" - << file << '_' << fileIndex << ".h5"; - std::string srcFileName = os.str(); - LOG(logDEBUG1) << srcFileName; - - // find relative path - std::string relative_srcFileName = srcFileName; - { - size_t p = srcFileName.rfind('/', srcFileName.length()); - if (p != std::string::npos) - relative_srcFileName = (srcFileName.substr( - p + 1, srcFileName.length() - p)); - } - - // source dataset name - std::ostringstream osfn; - osfn << "/data"; - if (numImages > 1) - osfn << "_f" << std::setfill('0') << std::setw(12) << file; - std::string srcDatasetName = osfn.str(); - - // source data dataspace - hsize_t srcDims[3] = {nDimx, nDimy, nDimz}; - // hsize_t srcDimsMax[3] = {H5S_UNLIMITED, nDimy, nDimz}; - DataSpace srcDataSpace(3, srcDims); //, srcDimsMax); - /* - LOG(logINFO) << iReadout << " before selecting - src"; srcDataSpace.selectElements(H5S_SELECT_SET, 1280, - (const hsize_t - *)coord); LOG(logINFO) << iReadout << " after selecting src"; - LOG(logINFO) << "src valid:" << - srcDataSpace.selectValid(); - */ - // mapping of data property list - // int values[] = {53, 59, 61, 67}; /* New values to be written - // */ vdsDataSet->write(values, dataType, srcDataSpace, - // vdsDataSpace); - - LOG(logINFORED) << iReadout << " before vritual"; - plist.setVirtual(vdsDataSpace, relative_srcFileName.c_str(), - srcDatasetName.c_str(), srcDataSpace); - LOG(logINFORED) << iReadout << " before virtual"; - - // H5Sclose(srcDataspace); - } - framesSaved += nDimx; - } - // data dataset - dataSetName_ = "data"; - DataSet vdsDataSet(fd_->createDataSet(dataSetName_.c_str(), dataType, - vdsDataSpace, plist)); - - fd_->close(); - } catch (const Exception &error) { - error.printErrorStack(); - CloseFile(); - throw sls::RuntimeError( - "Could not create/overwrite virtual HDF5 handles"); - } - if (!silentMode) { - LOG(logINFO) << "Virtual File: " << fileName_; - } -} \ No newline at end of file From ca0aa7144c550d4dc6ff4ef53005d6bf350c5bc3 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 17 Mar 2022 12:53:32 +0100 Subject: [PATCH 12/17] hdf5 for g25um --- slsReceiverSoftware/src/HDF5VirtualFile.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/slsReceiverSoftware/src/HDF5VirtualFile.cpp b/slsReceiverSoftware/src/HDF5VirtualFile.cpp index 6c5f3202c..519dfe1f0 100644 --- a/slsReceiverSoftware/src/HDF5VirtualFile.cpp +++ b/slsReceiverSoftware/src/HDF5VirtualFile.cpp @@ -103,14 +103,13 @@ void HDF5VirtualFile::CreateVirtualFile( ((numImagesCaught - framesSaved) > maxFramesPerFile) ? maxFramesPerFile : (numImagesCaught - framesSaved); - // starting location - hsize_t start[3] = {framesSaved, 0, 0}; + // number of elements separating each block - hsize_t stride[3] = {1, 1, 1}; + hsize_t stride[3] = {1, 1, 2}; // number of blocks - hsize_t count[3] = {1, 1, 1}; + hsize_t count[3] = {nDimx, nDimy, nDimz}; // block size - hsize_t block[3] = {nDimx, nDimy, nDimz}; + hsize_t block[3] = {1, 1, 1}; // starting location hsize_t startPara[2] = {framesSaved, 0}; @@ -124,6 +123,9 @@ void HDF5VirtualFile::CreateVirtualFile( // loop through readouts (image) for (unsigned int i = 0; i < numModY * numModZ; ++i) { + // starting location + hsize_t start[3] = {framesSaved, 0, i}; + // setect data hyperslabs vdsDataSpace.selectHyperslab(H5S_SELECT_SET, count, start, stride, block); From afbc414afeebaabdc4580cf8203fcd810490ff0b Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 17 Mar 2022 13:08:40 +0100 Subject: [PATCH 13/17] works for both g25 and normal --- slsReceiverSoftware/src/HDF5VirtualFile.cpp | 26 +++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/slsReceiverSoftware/src/HDF5VirtualFile.cpp b/slsReceiverSoftware/src/HDF5VirtualFile.cpp index 519dfe1f0..03ab02008 100644 --- a/slsReceiverSoftware/src/HDF5VirtualFile.cpp +++ b/slsReceiverSoftware/src/HDF5VirtualFile.cpp @@ -104,8 +104,10 @@ void HDF5VirtualFile::CreateVirtualFile( ? maxFramesPerFile : (numImagesCaught - framesSaved); + // starting location + hsize_t start[3] = {framesSaved, 0, 0}; // number of elements separating each block - hsize_t stride[3] = {1, 1, 2}; + hsize_t stride[3] = {1, 1, 1}; // number of blocks hsize_t count[3] = {nDimx, nDimy, nDimz}; // block size @@ -120,11 +122,18 @@ void HDF5VirtualFile::CreateVirtualFile( // block size hsize_t blockPara[3] = {nDimx, 1}; + // interleaving for g2 + if (gotthard25um) { + stride[2] = 2; + } + // loop through readouts (image) for (unsigned int i = 0; i < numModY * numModZ; ++i) { - // starting location - hsize_t start[3] = {framesSaved, 0, i}; + // interleaving for g2 + if (gotthard25um) { + start[2] = i; + } // setect data hyperslabs vdsDataSpace.selectHyperslab(H5S_SELECT_SET, count, start, @@ -183,10 +192,13 @@ void HDF5VirtualFile::CreateVirtualFile( // H5Sclose(srcDataspace); // H5Sclose(srcDataspace_para); - start[2] += nDimz; - if (start[2] >= (numModZ * nDimz)) { - start[2] = 0; - start[1] += nDimy; + + if (!gotthard25um) { + start[2] += nDimz; + if (start[2] >= (numModZ * nDimz)) { + start[2] = 0; + start[1] += nDimy; + } } startPara[1]++; } From 570651a9f8db8f85488dd32d0a2db12aa567bc6b Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 17 Mar 2022 13:09:54 +0100 Subject: [PATCH 14/17] minor --- slsReceiverSoftware/src/HDF5VirtualFile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsReceiverSoftware/src/HDF5VirtualFile.cpp b/slsReceiverSoftware/src/HDF5VirtualFile.cpp index 03ab02008..7ee6f94e8 100644 --- a/slsReceiverSoftware/src/HDF5VirtualFile.cpp +++ b/slsReceiverSoftware/src/HDF5VirtualFile.cpp @@ -130,7 +130,7 @@ void HDF5VirtualFile::CreateVirtualFile( // loop through readouts (image) for (unsigned int i = 0; i < numModY * numModZ; ++i) { - // interleaving for g2 + // interleaving for g2 (start is 0 and 1) if (gotthard25um) { start[2] = i; } From 2b35101b1717993e000dc4ded23511a89d2a7b0a Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Tue, 22 Mar 2022 10:23:22 +0100 Subject: [PATCH 15/17] moved shm numUdpInterfaces initialization up front, moved updating this value in DetectorImpl::setHostname to DetectorImpl::addModule for more readability, renamed getNumberofUdpInterfaces to an updateNumberofUdpInterfaces as the shm was being updated and is used only in setHostname, everywhere else getNumberofUdpInterfaces is replaced by getNumberofUdpInterfacesFromShm --- slsDetectorSoftware/src/Detector.cpp | 8 ++++---- slsDetectorSoftware/src/DetectorImpl.cpp | 22 +++++++++------------- slsDetectorSoftware/src/DetectorImpl.h | 1 - slsDetectorSoftware/src/Module.cpp | 7 +++---- slsDetectorSoftware/src/Module.h | 2 +- 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 6342d7745..cd1c1cf44 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -871,7 +871,7 @@ Result Detector::getScanErrorMessage(Positions pos) const { Result Detector::getNumberofUDPInterfaces(Positions pos) const { // also called by vetostream (for gotthard2) - return pimpl->getNumberofUDPInterfaces(pos); + return pimpl->Parallel(&Module::getNumberofUDPInterfacesFromShm, pos); } void Detector::setNumberofUDPInterfaces(int n, Positions pos) { @@ -1739,7 +1739,7 @@ Result Detector::getVetoStream(Positions pos) const { // 3gbe auto r3 = pimpl->Parallel(&Module::getVetoStream, pos); // 10gbe (debugging interface) opens 2nd udp interface in receiver - auto r10 = pimpl->getNumberofUDPInterfaces(pos); + auto r10 = getNumberofUDPInterfaces(pos); Result res(r3.size()); for (unsigned int i = 0; i < res.size(); ++i) { @@ -1761,7 +1761,7 @@ void Detector::setVetoStream(defs::streamingInterface interface, pimpl->Parallel(&Module::setVetoStream, pos, LOW_LATENCY_LINK); // 10gbe (debugging interface) opens 2nd udp interface in receiver - int old_numinterfaces = pimpl->getNumberofUDPInterfaces(pos).tsquash( + int old_numinterfaces = getNumberofUDPInterfaces(pos).tsquash( "retrieved inconsistent number of udp interfaces"); int numinterfaces = (((interface & defs::streamingInterface::ETHERNET_10GB) == @@ -2355,7 +2355,7 @@ Result Detector::getRxCurrentFrameIndex(Positions pos) const { } std::vector Detector::getPortNumbers(int start_port) { - int num_sockets_per_detector = pimpl->getNumberofUDPInterfaces({}).tsquash( + int num_sockets_per_detector = getNumberofUDPInterfaces({}).tsquash( "Number of UDP Interfaces is not consistent among modules"); std::vector res; res.reserve(size()); diff --git a/slsDetectorSoftware/src/DetectorImpl.cpp b/slsDetectorSoftware/src/DetectorImpl.cpp index 15454ab23..fa4838bad 100644 --- a/slsDetectorSoftware/src/DetectorImpl.cpp +++ b/slsDetectorSoftware/src/DetectorImpl.cpp @@ -245,15 +245,6 @@ void DetectorImpl::setHostname(const std::vector &name) { addModule(hostname); } updateDetectorSize(); - - // update zmq port (especially for eiger) - int numInterfaces = modules[0]->getNumberofUDPInterfaces(); - if (numInterfaces == 2) { - for (size_t i = 0; i < modules.size(); ++i) { - modules[i]->setClientStreamingPort(DEFAULT_ZMQ_CL_PORTNO + - i * numInterfaces); - } - } } void DetectorImpl::addModule(const std::string &hostname) { @@ -288,11 +279,20 @@ void DetectorImpl::addModule(const std::string &hostname) { modules[pos]->setControlPort(port); modules[pos]->setStopPort(port + 1); modules[pos]->setHostname(host, shm()->initialChecks); + // module type updated by now shm()->detType = Parallel(&Module::getDetectorType, {}) .tsquash("Inconsistent detector types."); // for moench and ctb modules[pos]->updateNumberOfChannels(); + + // for eiger, jungfrau, gotthard2 + modules[pos]->updateNumberofUDPInterfaces(); + + // update zmq port in case numudpinterfaces changed + int numInterfaces = modules[pos]->getNumberofUDPInterfacesFromShm(); + modules[pos]->setClientStreamingPort(DEFAULT_ZMQ_CL_PORTNO + + pos * numInterfaces); } void DetectorImpl::updateDetectorSize() { @@ -1361,10 +1361,6 @@ std::vector DetectorImpl::readProgrammingFile(const std::string &fname) { return buffer; } -sls::Result DetectorImpl::getNumberofUDPInterfaces(Positions pos) const { - return Parallel(&Module::getNumberofUDPInterfaces, pos); -} - sls::Result DetectorImpl::getDefaultDac(defs::dacIndex index, defs::detectorSettings sett, Positions pos) { diff --git a/slsDetectorSoftware/src/DetectorImpl.h b/slsDetectorSoftware/src/DetectorImpl.h index c51f80251..e3b0ab985 100644 --- a/slsDetectorSoftware/src/DetectorImpl.h +++ b/slsDetectorSoftware/src/DetectorImpl.h @@ -291,7 +291,6 @@ class DetectorImpl : public virtual slsDetectorDefs { */ std::vector readProgrammingFile(const std::string &fname); - sls::Result getNumberofUDPInterfaces(Positions pos) const; void setNumberofUDPInterfaces(int n, Positions pos); sls::Result getDefaultDac(defs::dacIndex index, defs::detectorSettings sett, diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index 1fcfdb3fb..d02374db3 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -936,9 +936,8 @@ int Module::getNumberofUDPInterfacesFromShm() const { return shm()->numUDPInterfaces; } -int Module::getNumberofUDPInterfaces() const { +void Module::updateNumberofUDPInterfaces() { shm()->numUDPInterfaces = sendToDetector(F_GET_NUM_INTERFACES); - return shm()->numUDPInterfaces; } void Module::setNumberofUDPInterfaces(int n) { @@ -1146,7 +1145,7 @@ std::string Module::printReceiverConfiguration() { << getReceiverHostname(); if (shm()->detType == JUNGFRAU) { - os << "\nNumber of Interfaces:\t" << getNumberofUDPInterfaces() + os << "\nNumber of Interfaces:\t" << getNumberofUDPInterfacesFromShm() << "\nSelected Interface:\t" << getSelectedUDPInterface(); } @@ -3183,10 +3182,10 @@ void Module::initializeModuleStructure(detectorType type) { sls::strcpy_safe(shm()->rxHostname, "none"); shm()->rxTCPPort = DEFAULT_PORTNO + 2; shm()->useReceiverFlag = false; + shm()->numUDPInterfaces = 1; shm()->zmqport = DEFAULT_ZMQ_CL_PORTNO + moduleIndex * shm()->numUDPInterfaces; shm()->zmqip = IpAddr{}; - shm()->numUDPInterfaces = 1; shm()->stoppedFlag = false; // get the Module parameters based on type diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index 375911ceb..99d0690ef 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -218,7 +218,7 @@ class Module : public virtual slsDetectorDefs { * * * ************************************************/ int getNumberofUDPInterfacesFromShm() const; - int getNumberofUDPInterfaces() const; + void updateNumberofUDPInterfaces(); void setNumberofUDPInterfaces(int n); int getSelectedUDPInterface() const; void selectUDPInterface(int n); From fc21a6763d1452effabe7376e5023f69c5fccc3d Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Wed, 23 Mar 2022 12:03:51 +0100 Subject: [PATCH 16/17] fix and minor removing comments --- slsReceiverSoftware/src/DataProcessor.cpp | 2 +- slsReceiverSoftware/src/HDF5VirtualFile.cpp | 88 ++++++++------------- 2 files changed, 36 insertions(+), 54 deletions(-) diff --git a/slsReceiverSoftware/src/DataProcessor.cpp b/slsReceiverSoftware/src/DataProcessor.cpp index 5ad3b6707..a22abdfc1 100644 --- a/slsReceiverSoftware/src/DataProcessor.cpp +++ b/slsReceiverSoftware/src/DataProcessor.cpp @@ -217,7 +217,7 @@ void DataProcessor::CreateVirtualFile( filePath, fileNamePrefix, fileIndex, overWriteEnable, silentMode, modulePos, numUnitsPerReadout, framesPerFile, numImages, generalData_->nPixelsX, generalData_->nPixelsY, dynamicRange, - numImagesProcessed, numModX, numModY, dataFile_->GetPDataType(), + numFramesCaught_, numModX, numModY, dataFile_->GetPDataType(), dataFile_->GetParameterNames(), dataFile_->GetParameterDataTypes()); } diff --git a/slsReceiverSoftware/src/HDF5VirtualFile.cpp b/slsReceiverSoftware/src/HDF5VirtualFile.cpp index 7ee6f94e8..015ad0ae3 100644 --- a/slsReceiverSoftware/src/HDF5VirtualFile.cpp +++ b/slsReceiverSoftware/src/HDF5VirtualFile.cpp @@ -73,12 +73,10 @@ void HDF5VirtualFile::CreateVirtualFile( "version", PredType::NATIVE_DOUBLE, dataspace_attr); attribute.write(PredType::NATIVE_DOUBLE, &dValue); - // virtual data dataspace + // virtual dataspace hsize_t vdsDims[3] = {numImagesCaught, numModY * nDimy, numModZ * nDimz}; DataSpace vdsDataSpace(3, vdsDims, nullptr); - - // virtual parameter dataspace hsize_t vdsDimsPara[2] = {numImagesCaught, (unsigned int)numModY * numModZ}; DataSpace vdsDataSpacePara(2, vdsDimsPara, nullptr); @@ -91,64 +89,54 @@ void HDF5VirtualFile::CreateVirtualFile( // property list for parameters (datatype) std::vector plistPara(paraSize); - // hyperslab - int numMajorHyperslab = numImagesCaught / maxFramesPerFile; + // hyperslab (files) + int numFiles = numImagesCaught / maxFramesPerFile; if (numImagesCaught % maxFramesPerFile) - ++numMajorHyperslab; + ++numFiles; uint64_t framesSaved = 0; - // loop through files - for (int hyperSlab = 0; hyperSlab < numMajorHyperslab; ++hyperSlab) { + for (int iFile = 0; iFile < numFiles; ++iFile) { uint64_t nDimx = ((numImagesCaught - framesSaved) > maxFramesPerFile) ? maxFramesPerFile : (numImagesCaught - framesSaved); - // starting location - hsize_t start[3] = {framesSaved, 0, 0}; - // number of elements separating each block - hsize_t stride[3] = {1, 1, 1}; - // number of blocks - hsize_t count[3] = {nDimx, nDimy, nDimz}; - // block size - hsize_t block[3] = {1, 1, 1}; + hsize_t startLocation[3] = {framesSaved, 0, 0}; + hsize_t strideBetweenBlocks[3] = {1, 1, 1}; + hsize_t numBlocks[3] = {nDimx, nDimy, nDimz}; + hsize_t blockSize[3] = {1, 1, 1}; - // starting location - hsize_t startPara[2] = {framesSaved, 0}; - // number of elements separating each block - hsize_t stridePara[3] = {1, 1}; - // number of blocks - hsize_t countPara[2] = {1, 1}; - // block size - hsize_t blockPara[3] = {nDimx, 1}; + hsize_t startLocationPara[2] = {framesSaved, 0}; + hsize_t strideBetweenBlocksPara[3] = {1, 1}; + hsize_t numBlocksPara[2] = {1, 1}; + hsize_t blockSizePara[3] = {nDimx, 1}; // interleaving for g2 if (gotthard25um) { - stride[2] = 2; + strideBetweenBlocks[2] = 2; } - // loop through readouts (image) - for (unsigned int i = 0; i < numModY * numModZ; ++i) { + for (unsigned int iReadout = 0; iReadout < numModY * numModZ; + ++iReadout) { - // interleaving for g2 (start is 0 and 1) + // interleaving for g2 (startLocation is 0 and 1) if (gotthard25um) { - start[2] = i; + startLocation[2] = iReadout; } - // setect data hyperslabs - vdsDataSpace.selectHyperslab(H5S_SELECT_SET, count, start, - stride, block); + vdsDataSpace.selectHyperslab(H5S_SELECT_SET, numBlocks, + startLocation, strideBetweenBlocks, + blockSize); - // select parameter hyperslabs - vdsDataSpacePara.selectHyperslab(H5S_SELECT_SET, countPara, - startPara, stridePara, - blockPara); + vdsDataSpacePara.selectHyperslab( + H5S_SELECT_SET, numBlocksPara, startLocationPara, + strideBetweenBlocksPara, blockSizePara); // source file name std::ostringstream os; os << filePath << "/" << fileNamePrefix << "_d" - << (modulePos * numUnitsPerReadout + i) << "_f" << hyperSlab - << '_' << fileIndex << ".h5"; + << (modulePos * numUnitsPerReadout + iReadout) << "_f" + << iFile << '_' << fileIndex << ".h5"; std::string srcFileName = os.str(); LOG(logDEBUG1) << srcFileName; @@ -165,25 +153,20 @@ void HDF5VirtualFile::CreateVirtualFile( std::ostringstream osfn; osfn << "/data"; if (numImages > 1) - osfn << "_f" << std::setfill('0') << std::setw(12) - << hyperSlab; + osfn << "_f" << std::setfill('0') << std::setw(12) << iFile; std::string srcDatasetName = osfn.str(); - // source data dataspace + // source dataspace hsize_t srcDims[3] = {nDimx, nDimy, nDimz}; hsize_t srcDimsMax[3] = {H5S_UNLIMITED, nDimy, nDimz}; DataSpace srcDataSpace(3, srcDims, srcDimsMax); - - // source parameter dataspace hsize_t srcDimsPara[1] = {nDimx}; hsize_t srcDimsMaxPara[1] = {H5S_UNLIMITED}; DataSpace srcDataSpacePara(1, srcDimsPara, srcDimsMaxPara); - // mapping of data property list + // mapping of property list plist.setVirtual(vdsDataSpace, relative_srcFileName.c_str(), srcDatasetName.c_str(), srcDataSpace); - - // mapping of parameter property list for (unsigned int p = 0; p < paraSize; ++p) { plistPara[p].setVirtual( vdsDataSpacePara, relative_srcFileName.c_str(), @@ -194,22 +177,21 @@ void HDF5VirtualFile::CreateVirtualFile( // H5Sclose(srcDataspace_para); if (!gotthard25um) { - start[2] += nDimz; - if (start[2] >= (numModZ * nDimz)) { - start[2] = 0; - start[1] += nDimy; + startLocation[2] += nDimz; + if (startLocation[2] >= (numModZ * nDimz)) { + startLocation[2] = 0; + startLocation[1] += nDimy; } } - startPara[1]++; + startLocationPara[1]++; } framesSaved += nDimx; } - // data dataset + // datasets dataSetName_ = "data"; DataSet vdsDataSet(fd_->createDataSet(dataSetName_.c_str(), dataType, vdsDataSpace, plist)); - // parameter dataset for (unsigned int p = 0; p < paraSize; ++p) { DataSet vdsDataSetPara(fd_->createDataSet( parameterNames[p].c_str(), parameterDataTypes[p], From ea1222ac5b82531b046e46ef2c5d9f11dd311716 Mon Sep 17 00:00:00 2001 From: redford_s Date: Fri, 25 Mar 2022 18:20:32 +0100 Subject: [PATCH 17/17] Solved problem in photon finder --- slsDetectorCalibration/singlePhotonDetector.h | 46 ++++++++++++------- slsDetectorCalibration/single_photon_hit.h | 4 ++ 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/slsDetectorCalibration/singlePhotonDetector.h b/slsDetectorCalibration/singlePhotonDetector.h index 083e25f7b..96d239c97 100644 --- a/slsDetectorCalibration/singlePhotonDetector.h +++ b/slsDetectorCalibration/singlePhotonDetector.h @@ -429,23 +429,28 @@ class singlePhotonDetector : public analogDetector { for (ic = -(clusterSize / 2); ic < (clusterSize / 2) + 1; ic++) { - if ((iy + ir) >= iy && (iy + ir) < ny && - (ix + ic) >= ix && (ix + ic) < nx) { + if ((iy + ir) >= 0 && (iy + ir) < ny && + (ix + ic) >= 0 && (ix + ic) < nx) { + + + if ((iy + ir) >= iy && (ix + ic) >= ix ) { val[(iy + ir) * nx + ix + ic] = subtractPedestal(data, ix + ic, iy + ir, cm); - v = &(val[(iy + ir) * nx + ix + ic]); - tot += *v; - if (ir <= 0 && ic <= 0) - bl += *v; - if (ir <= 0 && ic >= 0) - br += *v; - if (ir >= 0 && ic <= 0) - tl += *v; - if (ir >= 0 && ic >= 0) - tr += *v; - if (*v > max) { - max = *v; - } + + } + v = &(val[(iy + ir) * nx + ix + ic]); + tot += *v; + if (ir <= 0 && ic <= 0) + bl += *v; + if (ir <= 0 && ic >= 0) + br += *v; + if (ir >= 0 && ic <= 0) + tl += *v; + if (ir >= 0 && ic >= 0) + tr += *v; + if (*v > max) //{ + max = *v; + //} } } } @@ -513,12 +518,19 @@ class singlePhotonDetector : public analogDetector { for (ic = -(clusterSize / 2); ic < (clusterSize / 2) + 1; ic++) { if ((iy + ir) >= 0 && (iy + ir) < ny && - (ix + ic) >= 0 && (ix + ic) < nx) - (clusters + nph) + (ix + ic) >= 0 && (ix + ic) < nx) { + (clusters + nph) ->set_data(val[(iy + ir) * nx + ix + ic], ic, ir); + if (val[(iy + ir) * nx + ix + ic]>max) + good=0; + } } } + if (good==0) { + (clusters + nph)->print(); + cout << max << " " << val[iy * nx + ix] << endl; + } good = 1; if (eMin > 0 && tot < eMin) good = 0; diff --git a/slsDetectorCalibration/single_photon_hit.h b/slsDetectorCalibration/single_photon_hit.h index 919f6af4b..0317e6e4d 100644 --- a/slsDetectorCalibration/single_photon_hit.h +++ b/slsDetectorCalibration/single_photon_hit.h @@ -216,14 +216,18 @@ class single_photon_hit { // int ix, iy; + printf("***************\n"); + printf("** %d %d **\n",x,y); for (int iy = 0; iy < dy; iy++) { for (int ix = 0; ix < dx; ix++) { printf("%d \t", data[ix + iy * dx]); } printf("\n"); } + printf("***************\n"); } + /** assign the value to the element of the cluster matrix, with relative coordinates where the center of the cluster is (0,0) \param v value to be