diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index 86e8d2372..90f2cd6ac 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -992,7 +992,8 @@ class Detector { /** Returns multi level ROIs */ std::vector getRxROI() const; - /** Returns port level ROIs. Max 2 ports and hence max 2 elements per readout */ + /** Returns port level ROIs. Max 2 ports and hence max 2 elements per + * readout */ std::vector getRxROI(int module_id) const; /** only at multi module level without gap pixels. At most, 1 ROI per UDP diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index b2d70937c..06e44a308 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -1383,9 +1383,7 @@ void Detector::setRxArping(bool value, Positions pos) { pimpl->Parallel(&Module::setRxArping, pos, value); } -std::vector Detector::getRxROI() const { - return pimpl->getRxROI(); -} +std::vector Detector::getRxROI() const { return pimpl->getRxROI(); } std::vector Detector::getRxROI(int module_id) const { return pimpl->getRxROI(module_id); @@ -1398,7 +1396,6 @@ void Detector::setRxROI(const std::vector &args) { void Detector::clearRxROI() { pimpl->clearRxROI(); } - // File Result Detector::getFileFormat(Positions pos) const { diff --git a/slsDetectorSoftware/src/DetectorImpl.cpp b/slsDetectorSoftware/src/DetectorImpl.cpp index 5727edb78..497791140 100644 --- a/slsDetectorSoftware/src/DetectorImpl.cpp +++ b/slsDetectorSoftware/src/DetectorImpl.cpp @@ -1676,7 +1676,7 @@ std::vector DetectorImpl::getRxROI(int module_id) const { } if (module_id >= (int)modules.size()) { throw RuntimeError("Invalid module id: " + std::to_string(module_id)); - } + } if (module_id >= 0) { return modules[module_id]->getRxROI(); } @@ -1783,9 +1783,10 @@ void DetectorImpl::convertGlobalRoiToPortLevel( throw RuntimeError("Only up to 2 ports per module supported."); } if (numPorts != (int)portRois.size()) { - throw RuntimeError("Number of port ROIs does not match number of ports in module. Expected: " + - std::to_string(numPorts) + ", got: " + - std::to_string(portRois.size())); + throw RuntimeError("Number of port ROIs does not match number of ports " + "in module. Expected: " + + std::to_string(numPorts) + + ", got: " + std::to_string(portRois.size())); } for (int port = 0; port < numPorts; ++port) { @@ -1812,20 +1813,22 @@ void DetectorImpl::convertGlobalRoiToPortLevel( clipped.xmin = std::max(userRoi.xmin, portRoi.xmin) - portRoi.xmin; clipped.xmax = std::min(userRoi.xmax, portRoi.xmax) - portRoi.xmin; LOG(logDEBUG1) << "User ROI: " << ToString(userRoi) - << ", Port ROI: " << ToString(portRoi) << " clipped roi:"<< ToString(clipped); + << ", Port ROI: " << ToString(portRoi) + << " clipped roi:" << ToString(clipped); if (modSize.y > 1) { - clipped.ymin = std::max(userRoi.ymin, portRoi.ymin) - portRoi.ymin; - clipped.ymax = std::min(userRoi.ymax, portRoi.ymax) - portRoi.ymin; + clipped.ymin = + std::max(userRoi.ymin, portRoi.ymin) - portRoi.ymin; + clipped.ymax = + std::min(userRoi.ymax, portRoi.ymax) - portRoi.ymin; } - LOG(logDEBUG1) << "Clipped ROI for port " << port - << ": " << ToString(clipped); + LOG(logDEBUG1) << "Clipped ROI for port " << port << ": " + << ToString(clipped); // Check if port ROI already exists for this port if (!portRois[port].completeRoi() && !portRois[port].noRoi()) { throw RuntimeError( "Multiple ROIs specified for the same port " + - std::to_string(port) + - " with ROI: " + ToString(userRoi)); + std::to_string(port) + " with ROI: " + ToString(userRoi)); } portRois[port] = clipped; } @@ -1846,12 +1849,14 @@ void DetectorImpl::setRxROI(const std::vector &args) { } validateROIs(args); - int nPortsPerModule = Parallel(&Module::getNumberofUDPInterfacesFromShm, {}).tsquash("Inconsistent number of udp ports set up per module"); + int nPortsPerModule = + Parallel(&Module::getNumberofUDPInterfacesFromShm, {}) + .tsquash("Inconsistent number of udp ports set up per module"); for (size_t iModule = 0; iModule < modules.size(); ++iModule) { auto moduleGlobalRoi = getModuleROI(iModule); LOG(logDEBUG1) << "Module " << iModule - << " Global ROI: " << ToString(moduleGlobalRoi); + << " Global ROI: " << ToString(moduleGlobalRoi); // at most 2 rois per module (for each port) std::vector portRois(nPortsPerModule); @@ -1865,8 +1870,8 @@ void DetectorImpl::setRxROI(const std::vector &args) { // print the rois for debugging LOG(logDEBUG1) << "Module " << iModule << " RxROIs:"; for (size_t iPort = 0; iPort != portRois.size(); iPort++) { - LOG(logDEBUG1) - << " Port " << iPort << ": " << ToString(portRois[iPort]); + LOG(logDEBUG1) << " Port " << iPort << ": " + << ToString(portRois[iPort]); } modules[iModule]->setRxROI(portRois); } @@ -1874,10 +1879,12 @@ void DetectorImpl::setRxROI(const std::vector &args) { modules[0]->setRxROIMetadata(args); } -void DetectorImpl::clearRxROI() { - int nPortsPerModule = Parallel(&Module::getNumberofUDPInterfacesFromShm, {}).tsquash("Inconsistent number of udp ports set up per module"); +void DetectorImpl::clearRxROI() { + int nPortsPerModule = + Parallel(&Module::getNumberofUDPInterfacesFromShm, {}) + .tsquash("Inconsistent number of udp ports set up per module"); for (size_t iModule = 0; iModule < modules.size(); ++iModule) { - modules[iModule]->setRxROI(std::vector(nPortsPerModule)); + modules[iModule]->setRxROI(std::vector(nPortsPerModule)); } modules[0]->setRxROIMetadata(std::vector(1)); } diff --git a/slsDetectorSoftware/src/DetectorImpl.h b/slsDetectorSoftware/src/DetectorImpl.h index 34f53e28a..5b2789e0b 100644 --- a/slsDetectorSoftware/src/DetectorImpl.h +++ b/slsDetectorSoftware/src/DetectorImpl.h @@ -428,9 +428,9 @@ class DetectorImpl : public virtual slsDetectorDefs { void validateROIs(const std::vector &rois); defs::xy calculatePosition(int moduleIndex) const; defs::ROI getModuleROI(int moduleIndex) const; - void convertGlobalRoiToPortLevel( - const defs::ROI &userRoi, const defs::ROI &moduleRoi, - std::vector &portRois) const; + void convertGlobalRoiToPortLevel(const defs::ROI &userRoi, + const defs::ROI &moduleRoi, + std::vector &portRois) const; const int detectorIndex{0}; SharedMemory shm{0, -1}; diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index 6a3161928..440386080 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -1526,7 +1526,7 @@ std::vector Module::getRxROI() const { // check number of ports if (!shm()->useReceiverFlag) { throw RuntimeError("No receiver to get ROI."); - } + } auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort); client.Send(F_RECEIVER_GET_RECEIVER_ROI); client.setFnum(F_RECEIVER_GET_RECEIVER_ROI); @@ -1561,12 +1561,12 @@ void Module::setRxROI(const std::vector &portRois) { client.setFnum(F_RECEIVER_SET_RECEIVER_ROI); int size = static_cast(portRois.size()); client.Send(size); - if (size > 0) + if (size > 0) client.Send(portRois); if (client.Receive() == FAIL) { throw ReceiverError("Receiver " + std::to_string(moduleIndex) + " returned error: " + client.readErrorMessage()); - } + } } std::vector Module::getRxROIMetadata() const { @@ -1587,8 +1587,7 @@ std::vector Module::getRxROIMetadata() const { throw RuntimeError("Invalid number of ROI metadata: " + std::to_string(size) + ". Min: 1."); } - LOG(logDEBUG1) << "ROI metadata of Receiver: " - << ToString(retval); + LOG(logDEBUG1) << "ROI metadata of Receiver: " << ToString(retval); return retval; } diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-rx.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-rx.cpp index 4172f4559..df9edbacd 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-rx.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-rx.cpp @@ -7,8 +7,8 @@ #include "sls/sls_detector_defs.h" #include "test-Caller-global.h" -#include #include +#include #include "sls/versionAPI.h" #include "tests/globals.h" @@ -502,8 +502,7 @@ TEST_CASE("rx_roi", "[.cmdcall]") { {"[95," + std::to_string(detsize.x + 5) + ", -1, -1]"}, -1, PUT)); // module level not allowed - REQUIRE_THROWS(caller.call( - "rx_roi", {"[5, 10, -1, -1]"}, 0, PUT)); + REQUIRE_THROWS(caller.call("rx_roi", {"[5, 10, -1, -1]"}, 0, PUT)); // vector of rois // square brackets missing @@ -518,18 +517,23 @@ TEST_CASE("rx_roi", "[.cmdcall]") { if (det.size() == 2) { auto moduleSize = det.getModuleSize()[0]; - std::string stringMin = std::to_string(moduleSize.x); - std::string stringMax = std::to_string(moduleSize.x + 1); + std::string stringMin = std::to_string(moduleSize.x); + std::string stringMax = std::to_string(moduleSize.x + 1); // separated by space is allowed REQUIRE_NOTHROW(caller.call( - "rx_roi", {"[5, 10, -1, -1]", "[" + stringMin + ", " + stringMax + ", -1, -1]"}, -1, PUT)); + "rx_roi", + {"[5, 10, -1, -1]", + "[" + stringMin + ", " + stringMax + ", -1, -1]"}, + -1, PUT)); std::ostringstream oss; // separated by semicolon is allowed - REQUIRE_NOTHROW(caller.call( - "rx_roi", {"[5, 10, -1, -1];[" + stringMin + ", " + stringMax + ", -1, -1]"}, -1, PUT, oss)); - REQUIRE(oss.str() == - "rx_roi [[5, 10], [" + stringMin + ", " + stringMax + "]]\n"); + REQUIRE_NOTHROW(caller.call("rx_roi", + {"[5, 10, -1, -1];[" + stringMin + + ", " + stringMax + ", -1, -1]"}, + -1, PUT, oss)); + REQUIRE(oss.str() == "rx_roi [[5, 10], [" + stringMin + ", " + + stringMax + "]]\n"); // verify individual roi { @@ -537,12 +541,14 @@ TEST_CASE("rx_roi", "[.cmdcall]") { stringMax = std::to_string(moduleSize.x + 50); std::ostringstream oss, oss1; REQUIRE_NOTHROW(caller.call( - "rx_roi", {"[" + stringMin + ", " + stringMax + "]"}, -1, PUT, oss)); - REQUIRE(oss.str() == - "rx_roi [[" + stringMin + ", " + stringMax + "]]\n"); - REQUIRE_NOTHROW( - caller.call("rx_roi", {}, 0, GET, oss1)); - REQUIRE(oss1.str() == "rx_roi [[" + stringMin + ", " + std::to_string(moduleSize.x - 1) + "]]\n"); + "rx_roi", {"[" + stringMin + ", " + stringMax + "]"}, + -1, PUT, oss)); + REQUIRE(oss.str() == "rx_roi [[" + stringMin + ", " + + stringMax + "]]\n"); + REQUIRE_NOTHROW(caller.call("rx_roi", {}, 0, GET, oss1)); + REQUIRE(oss1.str() == "rx_roi [[" + stringMin + ", " + + std::to_string(moduleSize.x - 1) + + "]]\n"); } } } @@ -587,8 +593,7 @@ TEST_CASE("rx_roi", "[.cmdcall]") { {"[95, 100, 0, " + std::to_string(detsize.y + 5) + "]"}, -1, PUT)); // module level not allowed - REQUIRE_THROWS(caller.call( - "rx_roi", {"[5, 10, 20, 30]"}, 0, PUT)); + REQUIRE_THROWS(caller.call("rx_roi", {"[5, 10, 20, 30]"}, 0, PUT)); // vector of rois // square brackets missing @@ -603,24 +608,29 @@ TEST_CASE("rx_roi", "[.cmdcall]") { REQUIRE_THROWS(caller.call( "rx_roi", {"[0, 10, 0, 10];[0, 10, 9, 11]"}, -1, PUT)); - int numinterfaces = det.getNumberofUDPInterfaces().tsquash( - "inconsistent number of interfaces"); + "inconsistent number of interfaces"); // multiple ports horizontally - if (det_type == defs::EIGER || (det.size() == 2 && det.getModuleGeometry().x > 1)) { - std::string stringMin = std::to_string(portSize.x); - std::string stringMax = std::to_string(portSize.x + 1); + if (det_type == defs::EIGER || + (det.size() == 2 && det.getModuleGeometry().x > 1)) { + std::string stringMin = std::to_string(portSize.x); + std::string stringMax = std::to_string(portSize.x + 1); // separated by space is allowed REQUIRE_NOTHROW(caller.call( - "rx_roi", {"[5, 10, 20, 30]", "[" + stringMin + ", " + stringMax + ", 20, 30]"}, -1, PUT)); + "rx_roi", + {"[5, 10, 20, 30]", + "[" + stringMin + ", " + stringMax + ", 20, 30]"}, + -1, PUT)); std::ostringstream oss; // separated by semicolon is allowed - REQUIRE_NOTHROW(caller.call( - "rx_roi", {"[5, 10, 20, 30];[" + stringMin + ", " + stringMax + ", 20, 30]"}, -1, PUT, oss)); - REQUIRE(oss.str() == - "rx_roi [[5, 10, 20, 30], [" + stringMin + ", " + stringMax + ", 20, 30]]\n"); + REQUIRE_NOTHROW(caller.call("rx_roi", + {"[5, 10, 20, 30];[" + stringMin + + ", " + stringMax + ", 20, 30]"}, + -1, PUT, oss)); + REQUIRE(oss.str() == "rx_roi [[5, 10, 20, 30], [" + stringMin + + ", " + stringMax + ", 20, 30]]\n"); // verify individual roi { @@ -628,36 +638,52 @@ TEST_CASE("rx_roi", "[.cmdcall]") { stringMax = std::to_string(portSize.x + delta); std::ostringstream oss, oss1; REQUIRE_NOTHROW(caller.call( - "rx_roi", {"[" + stringMin + ", " + stringMax + ", 20, 30]"}, -1, PUT, oss)); - REQUIRE(oss.str() == "rx_roi [[" + stringMin + ", " + stringMax + ", 20, 30]]\n"); - REQUIRE_NOTHROW( - caller.call("rx_roi", {}, 0, GET, oss1)); + "rx_roi", + {"[" + stringMin + ", " + stringMax + ", 20, 30]"}, -1, + PUT, oss)); + REQUIRE(oss.str() == "rx_roi [[" + stringMin + ", " + + stringMax + ", 20, 30]]\n"); + REQUIRE_NOTHROW(caller.call("rx_roi", {}, 0, GET, oss1)); // eiger returns 2 values for 2 ports per module if (det_type == defs::EIGER) { - REQUIRE(oss1.str() == "rx_roi [[" + stringMin + ", " + std::to_string(portSize.x - 1) + ", 20, 30], [0, " + std::to_string(delta) + ", 20, 30]]\n"); + REQUIRE(oss1.str() == + "rx_roi [[" + stringMin + ", " + + std::to_string(portSize.x - 1) + + ", 20, 30], [0, " + std::to_string(delta) + + ", 20, 30]]\n"); } - // others return only 1 roi per module (1 port per module) + // others return only 1 roi per module (1 port per module) else { - REQUIRE(oss1.str() == "rx_roi [[" + stringMin + ", " + std::to_string(portSize.x - 1) + ", 20, 30]]\n"); + REQUIRE(oss1.str() == + "rx_roi [[" + stringMin + ", " + + std::to_string(portSize.x - 1) + + ", 20, 30]]\n"); } } } // multiple ports vertically - if (((det_type == defs::JUNGFRAU || det_type == defs::MOENCH) && (numinterfaces == 2)) || - (det.size() == 2 && det.getModuleGeometry().y > 1)) { - std::string stringMin = std::to_string(portSize.y); - std::string stringMax = std::to_string(portSize.y + 1); + if (((det_type == defs::JUNGFRAU || det_type == defs::MOENCH) && + (numinterfaces == 2)) || + (det.size() == 2 && det.getModuleGeometry().y > 1)) { + std::string stringMin = std::to_string(portSize.y); + std::string stringMax = std::to_string(portSize.y + 1); // separated by space is allowed - REQUIRE_NOTHROW(caller.call( - "rx_roi", {"[5, 10, 20, 30]", "[25, 28, " + stringMin + ", " + stringMax + "]"}, -1, PUT)); + REQUIRE_NOTHROW( + caller.call("rx_roi", + {"[5, 10, 20, 30]", "[25, 28, " + stringMin + + ", " + stringMax + "]"}, + -1, PUT)); std::ostringstream oss; // separated by semicolon is allowed - REQUIRE_NOTHROW(caller.call( - "rx_roi", {"[5, 10, 20, 30];[25, 28, " + stringMin + ", " + stringMax + "]"}, -1, PUT, oss)); - REQUIRE(oss.str() == - "rx_roi [[5, 10, 20, 30], [25, 28, " + stringMin + ", " + stringMax + "]]\n"); + REQUIRE_NOTHROW( + caller.call("rx_roi", + {"[5, 10, 20, 30];[25, 28, " + stringMin + + ", " + stringMax + "]"}, + -1, PUT, oss)); + REQUIRE(oss.str() == "rx_roi [[5, 10, 20, 30], [25, 28, " + + stringMin + ", " + stringMax + "]]\n"); // verify individual roi { @@ -665,22 +691,37 @@ TEST_CASE("rx_roi", "[.cmdcall]") { stringMax = std::to_string(portSize.y + delta); std::ostringstream oss, oss1; REQUIRE_NOTHROW(caller.call( - "rx_roi", {"[ 20, 30, " + stringMin + ", " + stringMax + "]"}, -1, PUT, oss)); - REQUIRE(oss.str() == "rx_roi [[20, 30, " + stringMin + ", " + stringMax + "]]\n"); - REQUIRE_NOTHROW( - caller.call("rx_roi", {}, 0, GET, oss1)); - - // non-eiger with 2 interfaces returns 2 values for 2 ports per module - if ((det_type == defs::JUNGFRAU || det_type == defs::MOENCH) && (numinterfaces == 2)) { - REQUIRE(oss1.str() == "rx_roi [[20, 30, " + stringMin + ", " + std::to_string(portSize.y - 1) + "], [20, 30, 0, " + std::to_string(delta) + "]]\n"); + "rx_roi", + {"[ 20, 30, " + stringMin + ", " + stringMax + "]"}, -1, + PUT, oss)); + REQUIRE(oss.str() == "rx_roi [[20, 30, " + stringMin + + ", " + stringMax + "]]\n"); + REQUIRE_NOTHROW(caller.call("rx_roi", {}, 0, GET, oss1)); + + // non-eiger with 2 interfaces returns 2 values for 2 ports + // per module + if ((det_type == defs::JUNGFRAU || + det_type == defs::MOENCH) && + (numinterfaces == 2)) { + REQUIRE(oss1.str() == + "rx_roi [[20, 30, " + stringMin + ", " + + std::to_string(portSize.y - 1) + + "], [20, 30, 0, " + std::to_string(delta) + + "]]\n"); } - // others return only 1 roi per module (1 port per module) + // others return only 1 roi per module (1 port per module) else { // (eiger 2 ports) if (det_type == defs::EIGER) { - REQUIRE(oss1.str() == "rx_roi [[20, 30, " + stringMin + ", " + std::to_string(portSize.y - 1) + "], [-1, -1]]\n"); + REQUIRE(oss1.str() == + "rx_roi [[20, 30, " + stringMin + ", " + + std::to_string(portSize.y - 1) + + "], [-1, -1]]\n"); } else { - REQUIRE(oss1.str() == "rx_roi [[20, 30, " + stringMin + ", " + std::to_string(portSize.y - 1) + "]]\n"); + REQUIRE(oss1.str() == + "rx_roi [[20, 30, " + stringMin + ", " + + std::to_string(portSize.y - 1) + + "]]\n"); } } } @@ -700,7 +741,7 @@ TEST_CASE("rx_roi", "[.cmdcall]") { "inconsistent file index values in test"); auto prev_fname = det.getFileNamePrefix().tsquash( "inconsistent file name prefix values in test"); - + det.setFileWrite(true); det.setFilePath("/tmp"); det.setFileNamePrefix("test"); @@ -736,7 +777,6 @@ TEST_CASE("rx_roi", "[.cmdcall]") { } } - TEST_CASE("rx_clearroi", "[.cmdcall]") { Detector det; Caller caller(&det); diff --git a/slsReceiverSoftware/src/DataProcessor.cpp b/slsReceiverSoftware/src/DataProcessor.cpp index 73959a6cf..a863e39d5 100644 --- a/slsReceiverSoftware/src/DataProcessor.cpp +++ b/slsReceiverSoftware/src/DataProcessor.cpp @@ -227,8 +227,8 @@ std::string DataProcessor::CreateVirtualFile( return masterFileUtility::CreateVirtualHDF5File( filePath, fileNamePrefix, fileIndex, overWriteEnable, silentMode, modulePos, generalData->numUDPInterfaces, framesPerFile, - generalData->nPixelsX, ny, generalData->dynamicRange, - numFramesCaught, numModX, numModY, dataFile->GetPDataType(), + generalData->nPixelsX, ny, generalData->dynamicRange, numFramesCaught, + numModX, numModY, dataFile->GetPDataType(), dataFile->GetParameterNames(), dataFile->GetParameterDataTypes(), hdf5LibMutex, gotthard25um, multiRoiMetadata); } @@ -247,9 +247,9 @@ void DataProcessor::LinkFileInMaster(const std::string &masterFileName, if (virtualFileName.empty()) { fname = dataFile->GetFileName(); } - masterFileUtility::LinkHDF5FileInMaster(masterfname, fname, - dataFile->GetParameterNames(), - silentMode, hdf5LibMutex, multiRoiMetadata.size()); + masterFileUtility::LinkHDF5FileInMaster( + masterfname, fname, dataFile->GetParameterNames(), silentMode, + hdf5LibMutex, multiRoiMetadata.size()); } #endif @@ -702,7 +702,7 @@ void DataProcessor::CropImage(size_t &size, char *data) { ywidth = 1; ymin = 0; } - + // calculate total roi size double bytesPerPixel = generalData->dynamicRange / 8.00; int startOffset = (int)((nPixelsX * ymin + xmin) * bytesPerPixel); diff --git a/slsReceiverSoftware/src/DataStreamer.cpp b/slsReceiverSoftware/src/DataStreamer.cpp index e971dae30..8a8e83833 100644 --- a/slsReceiverSoftware/src/DataStreamer.cpp +++ b/slsReceiverSoftware/src/DataStreamer.cpp @@ -54,7 +54,7 @@ void DataStreamer::SetAdditionalJsonHeader( } void DataStreamer::SetPortROI(ROI roi) { - if (roi.completeRoi()) {//TODO: just not send zmq if not in roi? + if (roi.completeRoi()) { // TODO: just not send zmq if not in roi? portRoi = ROI(0, generalData->nPixelsX - 1, 0, generalData->nPixelsY - 1); } else { diff --git a/slsReceiverSoftware/src/Implementation.cpp b/slsReceiverSoftware/src/Implementation.cpp index 5e0940f4b..1c974063d 100644 --- a/slsReceiverSoftware/src/Implementation.cpp +++ b/slsReceiverSoftware/src/Implementation.cpp @@ -166,7 +166,6 @@ void Implementation::setDetectorType(const detectorType d) { SetLocalNetworkParameters(); SetupFifoStructure(); - // create threads for (int i = 0; i < generalData->numUDPInterfaces; ++i) { @@ -418,12 +417,11 @@ void Implementation::setPortROIs(const std::vector &args) { if (it.completeRoi() || it.noRoi()) { continue; // valid } - if (it.xmin < 0 || it.xmax < 0 || - it.xmin >= nx || it.xmax >= nx) { + if (it.xmin < 0 || it.xmax < 0 || it.xmin >= nx || it.xmax >= nx) { throw RuntimeError("Invalid ROIvx coordinates: " + ToString(it)); - } - if (ny > 1 && (it.ymin < 0 || it.ymax < 0 || - it.ymin >= ny || it.ymax >= ny)) { + } + if (ny > 1 && + (it.ymin < 0 || it.ymax < 0 || it.ymin >= ny || it.ymax >= ny)) { throw RuntimeError("Invalid ROI y coordinates: " + ToString(it)); } } diff --git a/slsReceiverSoftware/src/MasterFileUtility.cpp b/slsReceiverSoftware/src/MasterFileUtility.cpp index c9f0c1ee1..b05ec579f 100644 --- a/slsReceiverSoftware/src/MasterFileUtility.cpp +++ b/slsReceiverSoftware/src/MasterFileUtility.cpp @@ -49,7 +49,8 @@ std::string CreateMasterBinaryFile(const std::string &filePath, void LinkHDF5FileInMaster(std::string &masterFileName, std::string &dataFilename, std::vector parameterNames, - const bool silentMode, std::mutex *hdf5LibMutex, size_t multiRoiSize) { + const bool silentMode, std::mutex *hdf5LibMutex, + size_t multiRoiSize) { std::lock_guard lock(*hdf5LibMutex); std::unique_ptr fd{nullptr}; @@ -74,11 +75,10 @@ void LinkHDF5FileInMaster(std::string &masterFileName, if (multiRoiSize > 1) datasetname += ('_' + std::to_string(iRoi)); H5::DataSet dset = fd->openDataSet(datasetname); - std::string linkname = - std::string("/entry/data/") + datasetname; + std::string linkname = std::string("/entry/data/") + datasetname; if (H5Lcreate_external(dataFilename.c_str(), datasetname.c_str(), - masterfd.getLocId(), linkname.c_str(), - H5P_DEFAULT, H5P_DEFAULT) < 0) { + masterfd.getLocId(), linkname.c_str(), + H5P_DEFAULT, H5P_DEFAULT) < 0) { throw RuntimeError( "Could not create link to data dataset in master"); } @@ -91,9 +91,9 @@ void LinkHDF5FileInMaster(std::string &masterFileName, H5::DataSet pDset = fd->openDataSet(parameterDsetName.c_str()); linkname = std::string("/entry/data/") + parameterDsetName; if (H5Lcreate_external(dataFilename.c_str(), - parameterDsetName.c_str(), - masterfd.getLocId(), linkname.c_str(), - H5P_DEFAULT, H5P_DEFAULT) < 0) { + parameterDsetName.c_str(), + masterfd.getLocId(), linkname.c_str(), + H5P_DEFAULT, H5P_DEFAULT) < 0) { throw RuntimeError( "Could not create link to parameter dataset in master"); } @@ -169,13 +169,14 @@ std::string CreateMasterHDF5File(const std::string &filePath, return fileName; } -defs::ROI GetGlobalPortRoi(const int iPort, const defs::xy portSize, const int numPortsY) { +defs::ROI GetGlobalPortRoi(const int iPort, const defs::xy portSize, + const int numPortsY) { defs::xy portPos = {(iPort / numPortsY), (iPort % numPortsY)}; const int xmin = portSize.x * portPos.x; const int xmax = xmin + portSize.x - 1; const int ymin = portSize.y * portPos.y; const int ymax = ymin + portSize.y - 1; - return defs::ROI{xmin, xmax, ymin, ymax}; + return defs::ROI{xmin, xmax, ymin, ymax}; } int GetNumPortsInRoi(const defs::ROI roi, const defs::xy portSize) { @@ -194,32 +195,33 @@ std::string CreateVirtualHDF5File( 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 int nPixelsX, - const int nPixelsY, const uint32_t dynamicRange, - const uint64_t numImagesCaught, const int numModX, const int numModY, - const H5::DataType dataType, const std::vector parameterNames, + const uint32_t maxFramesPerFile, const int nPixelsX, const int nPixelsY, + const uint32_t dynamicRange, const uint64_t numImagesCaught, + const int numModX, const int numModY, const H5::DataType dataType, + const std::vector parameterNames, const std::vector parameterDataTypes, std::mutex *hdf5LibMutex, bool gotthard25um, std::vector multiRoi) { bool completeRoi = false; if (multiRoi.size() == 1 && multiRoi[0].completeRoi()) { - completeRoi = true; + completeRoi = true; } // roi not allowed in 4 bit mode and with gotthard 2 mods if (!completeRoi) { if (dynamicRange == 4) { - throw std::runtime_error("Skipping virtual hdf5 file since rx_roi is " - "enabled and it is in 4 bit mode."); + throw std::runtime_error( + "Skipping virtual hdf5 file since rx_roi is " + "enabled and it is in 4 bit mode."); } if (gotthard25um && (numModX * numModY) == 2) { - throw std::runtime_error("Skipping virtual hdf5 file since rx_roi is " - "enabled and there are 2 Gotthard 25um modules."); + throw std::runtime_error( + "Skipping virtual hdf5 file since rx_roi is " + "enabled and there are 2 Gotthard 25um modules."); } } - // virtual file name std::ostringstream osfn; osfn << filePath << "/" << fileNamePrefix << "_virtual" @@ -250,15 +252,16 @@ std::string CreateVirtualHDF5File( attribute.write(H5::PredType::NATIVE_DOUBLE, &dValue); for (size_t iRoi = 0; iRoi != multiRoi.size(); ++iRoi) { - + auto currentRoi = multiRoi[iRoi]; defs::xy detectorSize = {nPixelsX * numModX, nPixelsY * numModY}; if (completeRoi) { - currentRoi = defs::ROI{0, detectorSize.x - 1, - 0, detectorSize.y - 1}; + currentRoi = + defs::ROI{0, detectorSize.x - 1, 0, detectorSize.y - 1}; } - if (multiRoi[iRoi].completeRoi()&& iRoi != 0) - throw RuntimeError("Cannot have complete roi and multiple rois"); + if (multiRoi[iRoi].completeRoi() && iRoi != 0) + throw RuntimeError( + "Cannot have complete roi and multiple rois"); // get detector shape and number of ports in roi defs::xy portSize{nPixelsX, nPixelsY}; @@ -276,8 +279,8 @@ std::string CreateVirtualHDF5File( uint64_t nImages = numImagesCaught; int numFiles = numImagesCaught / maxFramesPerFile; if (numImagesCaught % maxFramesPerFile) - ++numFiles; - + ++numFiles; + hsize_t vdsDims[DATA_RANK] = {nImages, roiHeight, roiWidth}; hsize_t vdsDimsPara[VDS_PARA_RANK] = {nImages, nPortsInRoi}; H5::DataSpace vdsDataSpace(DATA_RANK, vdsDims, nullptr); @@ -296,7 +299,7 @@ std::string CreateVirtualHDF5File( // hyperslab (files) uint64_t framesSaved = 0; for (int iFile = 0; iFile != numFiles; ++iFile) { - + // images in src file uint64_t nSrcFileImages = numImagesCaught - framesSaved; if ((numImagesCaught - framesSaved) > maxFramesPerFile) @@ -309,7 +312,9 @@ std::string CreateVirtualHDF5File( hsize_t blockSizePara[VDS_PARA_RANK] = {nSrcFileImages, 1}; // following recalculated for every readout - hsize_t blockSize[DATA_RANK] = {nSrcFileImages, static_cast(nPixelsY), static_cast(nPixelsX)}; + hsize_t blockSize[DATA_RANK] = {nSrcFileImages, + static_cast(nPixelsY), + static_cast(nPixelsX)}; hsize_t startLocation[DATA_RANK] = {framesSaved, 0, 0}; hsize_t startLocationPara[VDS_PARA_RANK] = {framesSaved, 0}; @@ -318,18 +323,20 @@ std::string CreateVirtualHDF5File( strideBetweenBlocks[2] = 2; } - for (unsigned int iReadout = 0; iReadout < nTotalPorts; ++iReadout) { - auto globalPortRoi = GetGlobalPortRoi(iReadout, portSize, numModY); + for (unsigned int iReadout = 0; iReadout < nTotalPorts; + ++iReadout) { + auto globalPortRoi = + GetGlobalPortRoi(iReadout, portSize, numModY); if (!globalPortRoi.overlap(currentRoi)) - continue; + continue; // calculate start location (special for roi) int xmin = std::max(currentRoi.xmin, globalPortRoi.xmin); int xmax = std::min(currentRoi.xmax, globalPortRoi.xmax); int ymin = std::max(currentRoi.ymin, globalPortRoi.ymin); int ymax = std::min(currentRoi.ymax, globalPortRoi.ymax); - hsize_t portRoiHeight = ymax - ymin + 1; - hsize_t portRoiWidth = xmax - xmin + 1; + hsize_t portRoiHeight = ymax - ymin + 1; + hsize_t portRoiWidth = xmax - xmin + 1; // recalculating start location and block size if (!gotthard25um) { @@ -338,11 +345,12 @@ std::string CreateVirtualHDF5File( blockSize[1] = portRoiHeight; blockSize[2] = portRoiWidth; } - // interleaving for g2 (startLocation is 0 and 1) (g2 had no roi) + // interleaving for g2 (startLocation is 0 and 1) (g2 had no + // roi) else { ++startLocation[2]; } - + vdsDataSpace.selectHyperslab( H5S_SELECT_SET, numBlocks, startLocation, strideBetweenBlocks, blockSize); @@ -369,13 +377,15 @@ std::string CreateVirtualHDF5File( } // source dataspace - hsize_t srcDims[DATA_RANK] = {nSrcFileImages, portRoiHeight, portRoiWidth}; - hsize_t srcDimsMax[DATA_RANK] = {H5S_UNLIMITED, portRoiHeight, - portRoiWidth}; + hsize_t srcDims[DATA_RANK] = {nSrcFileImages, portRoiHeight, + portRoiWidth}; + hsize_t srcDimsMax[DATA_RANK] = { + H5S_UNLIMITED, portRoiHeight, portRoiWidth}; H5::DataSpace srcDataSpace(DATA_RANK, srcDims, srcDimsMax); hsize_t srcDimsPara[PARA_RANK] = {nSrcFileImages}; hsize_t srcDimsMaxPara[PARA_RANK] = {H5S_UNLIMITED}; - H5::DataSpace srcDataSpacePara(PARA_RANK, srcDimsPara, srcDimsMaxPara); + H5::DataSpace srcDataSpacePara(PARA_RANK, srcDimsPara, + srcDimsMaxPara); // temporary fixfor corner case bug: // (framescaught not multiple of framesperfile, // virtual parameter datasets error loading (bad scalar diff --git a/slsReceiverSoftware/src/MasterFileUtility.h b/slsReceiverSoftware/src/MasterFileUtility.h index 51360da74..cbf68be39 100644 --- a/slsReceiverSoftware/src/MasterFileUtility.h +++ b/slsReceiverSoftware/src/MasterFileUtility.h @@ -21,7 +21,8 @@ std::string CreateMasterBinaryFile(const std::string &filePath, void LinkHDF5FileInMaster(std::string &masterFileName, std::string &dataFilename, std::vector parameterNames, - const bool silentMode, std::mutex *hdf5LibMutex, size_t multiRoiSize); + const bool silentMode, std::mutex *hdf5LibMutex, + size_t multiRoiSize); std::string CreateMasterHDF5File(const std::string &filePath, const std::string &fileNamePrefix, @@ -29,17 +30,18 @@ std::string CreateMasterHDF5File(const std::string &filePath, const bool overWriteEnable, const bool silentMode, MasterAttributes *attr, std::mutex *hdf5LibMutex); -defs::ROI GetGlobalPortRoi(const int iPort, const defs::xy portSize, const int numPortsY); +defs::ROI GetGlobalPortRoi(const int iPort, const defs::xy portSize, + const int numPortsY); int GetNumPortsInRoi(const defs::ROI roi, const defs::xy portSize); std::string CreateVirtualHDF5File( 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 int nPixelsX, - const int nPixelsY, const uint32_t dynamicRange, - const uint64_t numImagesCaught, const int numModX, const int numModY, - const H5::DataType dataType, const std::vector parameterNames, + const uint32_t maxFramesPerFile, const int nPixelsX, const int nPixelsY, + const uint32_t dynamicRange, const uint64_t numImagesCaught, + const int numModX, const int numModY, const H5::DataType dataType, + const std::vector parameterNames, const std::vector parameterDataTypes, std::mutex *hdf5LibMutex, bool gotthard25um, std::vector multiRoi); diff --git a/slsSupportLib/include/sls/ToString.h b/slsSupportLib/include/sls/ToString.h index 71d9a1190..ea97a8436 100644 --- a/slsSupportLib/include/sls/ToString.h +++ b/slsSupportLib/include/sls/ToString.h @@ -349,5 +349,4 @@ std::vector StringTo(const std::vector &strings) { return result; } - } // namespace sls diff --git a/slsSupportLib/include/sls/sls_detector_defs.h b/slsSupportLib/include/sls/sls_detector_defs.h index 0f0a5dc0f..942774bbf 100644 --- a/slsSupportLib/include/sls/sls_detector_defs.h +++ b/slsSupportLib/include/sls/sls_detector_defs.h @@ -230,12 +230,8 @@ class slsDetectorDefs { ROI(int xmin, int xmax) : xmin(xmin), xmax(xmax){}; ROI(int xmin, int xmax, int ymin, int ymax) : xmin(xmin), xmax(xmax), ymin(ymin), ymax(ymax){}; - constexpr int width() const { - return (xmax - xmin + 1); - } - constexpr int height() const { - return (ymax - ymin + 1); - } + constexpr int width() const { return (xmax - xmin + 1); } + constexpr int height() const { return (ymax - ymin + 1); } constexpr std::array getIntArray() const { return std::array({xmin, xmax, ymin, ymax}); } @@ -252,7 +248,7 @@ class slsDetectorDefs { ymin = 0; ymax = 0; } - constexpr bool overlap(const ROI & other) const { + constexpr bool overlap(const ROI &other) const { return ((xmin <= other.xmax && xmax >= other.xmin) && (ymin <= other.ymax && ymax >= other.ymin)); }