From 5790e4961b04da6f2cbb11bcea8777916e9fa095 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Fri, 13 Aug 2021 17:10:46 +0200 Subject: [PATCH] wip --- python/slsdet/detector.py | 8 ++- slsDetectorGui/src/qTabSettings.cpp | 1 - .../slsDetectorServer_defs.h | 1 + .../jungfrauDetectorServer/RegisterDefs.h | 9 +++ .../slsDetectorFunctionList.c | 62 +++++++++++++++++-- .../slsDetectorServer_defs.h | 3 + .../include/slsDetectorFunctionList.h | 2 + .../src/slsDetectorServer_funcs.c | 20 ++++-- slsDetectorSoftware/include/sls/Detector.h | 18 +++--- slsDetectorSoftware/src/CmdProxy.h | 16 ++--- slsDetectorSoftware/src/Detector.cpp | 16 ++--- slsDetectorSoftware/src/Module.cpp | 22 +++---- slsDetectorSoftware/src/Module.h | 5 +- .../tests/test-CmdProxy-eiger.cpp | 30 --------- slsDetectorSoftware/tests/test-CmdProxy.cpp | 37 +++++++++++ slsReceiverSoftware/src/ClientInterface.cpp | 7 ++- slsReceiverSoftware/src/GeneralData.h | 3 + slsReceiverSoftware/src/Implementation.cpp | 4 +- slsReceiverSoftware/src/Implementation.h | 4 +- slsReceiverSoftware/src/MasterAttributes.h | 10 ++- slsReceiverSoftware/src/receiver_defs.h | 1 - slsSupportLib/include/sls/DataSocket.h | 2 +- slsSupportLib/src/DataSocket.cpp | 2 +- 23 files changed, 192 insertions(+), 91 deletions(-) diff --git a/python/slsdet/detector.py b/python/slsdet/detector.py index f614c712f..35c2ac9f9 100755 --- a/python/slsdet/detector.py +++ b/python/slsdet/detector.py @@ -1848,11 +1848,13 @@ class Detector(CppDetectorApi): @element def partialread(self): """ - [Eiger] Number of rows to read out per half module + [Eiger] Number of rows to read out per half module starting from the centre. + [Jungfrau] Number of rows to read per module starting from the centre. Note ---- - Options: 0 - 256. 256 is default. \n - The permissible values depend on dynamic range and 10Gbe enabled. + [Eiger] Options: 1 - 256. 256 is default. \n + [Eiger]The permissible values depend on dynamic range and 10Gbe enabled.\n\n + [Jungfrau] Options: 8 - 512 (multiples of 8) """ return self.getPartialReadout() diff --git a/slsDetectorGui/src/qTabSettings.cpp b/slsDetectorGui/src/qTabSettings.cpp index 677b1864b..158cd6de1 100644 --- a/slsDetectorGui/src/qTabSettings.cpp +++ b/slsDetectorGui/src/qTabSettings.cpp @@ -473,7 +473,6 @@ void qTabSettings::Refresh() { GetThresholdEnergies(); // eiger else if (spinThreshold->isEnabled()) { - LOG(logINFOBLUE) << "calling it!"; GetThresholdEnergy(); } diff --git a/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h index a4c350c68..4cccd8768 100644 --- a/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/eigerDetectorServer/slsDetectorServer_defs.h @@ -120,6 +120,7 @@ enum MASTERINDEX { MASTER_HARDWARE, OW_MASTER, OW_SLAVE }; #define MAX_TRIMBITS_VALUE (63) +#define MIN_ROWS_PER_READOUT (1) #define MAX_ROWS_PER_READOUT (256) #define MAX_PACKETS_PER_REQUEST (256) diff --git a/slsDetectorServers/jungfrauDetectorServer/RegisterDefs.h b/slsDetectorServers/jungfrauDetectorServer/RegisterDefs.h index c6c0eae69..287c438d8 100644 --- a/slsDetectorServers/jungfrauDetectorServer/RegisterDefs.h +++ b/slsDetectorServers/jungfrauDetectorServer/RegisterDefs.h @@ -167,6 +167,15 @@ #define ADC_PORT_INVERT_ADC_3_OFST (24) #define ADC_PORT_INVERT_ADC_3_MSK (0x000000FF << ADC_PORT_INVERT_ADC_3_OFST) +/** Partial Readout Register */ +#define PARTIAL_READOUT_REG (0x44 << MEM_MAP_SHIFT) + +#define PARTIAL_READOUT_NUM_ROWS_OFST (0) +#define PARTIAL_READOUT_NUM_ROWS_MSK (0x0000003F << PARTIAL_READOUT_NUM_ROWS_OFST) +#define PARTIAL_READOUT_ENBL_OFST (7) +#define PARTIAL_READOUT_ENBL_MSK (0x00000001 << PARTIAL_READOUT_ENBL_OFST) + + /* Configuration Register */ #define CONFIG_REG (0x4D << MEM_MAP_SHIFT) diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c index 5116f0529..ecc2ad3de 100644 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c @@ -480,6 +480,7 @@ void setupDetector() { setFilterCell(DEFAULT_FILTER_CELL); } disableCurrentSource(); + setPartialReadout(MAX_ROWS_PER_READOUT); } int resetToDefaultDacs(int hardReset) { @@ -1596,6 +1597,39 @@ int *getDetectorPosition() { return detPos; } /* jungfrau specific - powerchip, autocompdisable, asictimer, clockdiv, pll, * flashing fpga */ +int setPartialReadout(int value) { + if (value < 0 || (value % PARTIAL_READOUT_MULTIPLE != 0)) + return FAIL; + + // regval is numpackets - 1 + int regval = (value / PARTIAL_READOUT_MULTIPLE) - 1; + uint32_t addr = PARTIAL_READOUT_REG; + LOG(logINFO, ("Setting Partial Readout: %d (regval:%d)\n", value, regval)); + bus_w(addr, bus_r(addr) &~PARTIAL_READOUT_NUM_ROWS_MSK); + bus_w(addr, bus_r(addr) | ((regval << PARTIAL_READOUT_NUM_ROWS_OFST) & PARTIAL_READOUT_NUM_ROWS_MSK)); + + if (value == MAX_ROWS_PER_READOUT) { + LOG(logINFO, ("Disabling Partial Readout\n")); + bus_w(addr, bus_r(addr) &~PARTIAL_READOUT_ENBL_MSK); + } else { + LOG(logINFO, ("Enabling Partial Readout\n")); + bus_w(addr, bus_r(addr) | PARTIAL_READOUT_ENBL_MSK); + } + return OK; +} + +int getPartialReadout() { + int enable = (bus_r(PARTIAL_READOUT_REG) & PARTIAL_READOUT_ENBL_MSK); + int regval = ((bus_r(PARTIAL_READOUT_REG) & PARTIAL_READOUT_NUM_ROWS_MSK) >> PARTIAL_READOUT_NUM_ROWS_OFST); + + int maxRegval = (MAX_ROWS_PER_READOUT/ PARTIAL_READOUT_MULTIPLE) - 1; + if ((regval == maxRegval && enable) || (regval != maxRegval && !enable)) { + return -1; + } + + return (regval + 1) * PARTIAL_READOUT_MULTIPLE; +} + void initReadoutConfiguration() { LOG(logINFO, ("Initializing Readout Configuration:\n" @@ -2263,6 +2297,8 @@ void *start_timer(void *arg) { return NULL; } + int transmissionDelayUs = getTransmissionDelayFrame() * 1000; + int numInterfaces = getNumberofUDPInterfaces(); int64_t periodNs = getPeriod(); int numFrames = (getNumFrames() * getNumTriggers() * @@ -2271,17 +2307,36 @@ void *start_timer(void *arg) { const int npixels = 256 * 256 * 8; const int dataSize = 8192; const int packetsize = dataSize + sizeof(sls_detector_header); - const int packetsPerFrame = numInterfaces == 1 ? 128 : 64; - int transmissionDelayUs = getTransmissionDelayFrame() * 1000; + int maxPacketsPerFrame = 128; + int maxRows = MAX_ROWS_PER_READOUT; + if (numInterfaces == 2) { + maxPacketsPerFrame /= 2; + maxRows /= 2; + } + int partialReadout = getPartialReadout(); + if (partialReadout == -1) { + partialReadout = MAX_ROWS_PER_READOUT; + } + const int packetsPerFrame = (maxPacketsPerFrame * partialReadout) / maxRows; + + //LOG(logINFOBLUE, ("packetsperframe:%d numFrames:%d partial:%d maxpacketsperframe:%d maxrows:%d \n", packetsPerFrame, numFrames, partialReadout, maxPacketsPerFrame, maxRows)); + + // starting packet number + //const int startPnum = (128 / 2) - () // Generate data char imageData[DATA_BYTES]; memset(imageData, 0, DATA_BYTES); + const int pixelsPerPacket = dataSize / 2; + int pixelVal = 0; for (int i = 0; i < npixels; ++i) { // avoiding gain also being divided when gappixels enabled in call // back + if (i > 0 && i % pixelsPerPacket == 0) { + ++pixelVal; + } *((uint16_t *)(imageData + i * sizeof(uint16_t))) = - virtual_image_test_mode ? 0x0FFE : (uint16_t)i; + virtual_image_test_mode ? 0x0FFE : (uint16_t)pixelVal; } // Send data @@ -2289,7 +2344,6 @@ void *start_timer(void *arg) { uint64_t frameNr = 0; getNextFrameNumber(&frameNr); for (int iframes = 0; iframes != numFrames; ++iframes) { - usleep(transmissionDelayUs); // check if manual stop diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer_defs.h index 8d29fe307..c07c2a330 100644 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer_defs.h @@ -114,6 +114,9 @@ enum CLKINDEX { RUN_CLK, ADC_CLK, DBIT_CLK, NUM_CLOCKS }; #define DAC_MIN_MV (0) #define DAC_MAX_MV (2500) #define MAX_FILTER_CELL_VAL (12) +#define MIN_ROWS_PER_READOUT (8) +#define MAX_ROWS_PER_READOUT (512) +#define PARTIAL_READOUT_MULTIPLE (8) //512 rows/128packets * 2 interfaces /* Defines in the Firmware */ #define MAX_TIMESLOT_VAL (0x1F) diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h index 402794ea7..e793fbf35 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h @@ -449,6 +449,8 @@ void setDigitalIODelay(uint64_t pinMask, int delay); // jungfrau specific - powerchip, autocompdisable, clockdiv, asictimer, clock, // pll, flashing firmware #ifdef JUNGFRAUD +int setPartialReadout(int value); +int getPartialReadout(); void initReadoutConfiguration(); int powerChip(int on); int isChipConfigured(); diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index 6db47e92a..ab76904c5 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -4726,7 +4726,7 @@ int set_partial_readout(int file_des) { return printSocketReadError(); LOG(logDEBUG1, ("Setting partial readout: %u\n", arg)); -#ifndef EIGERD +#if !defined(EIGERD) && !defined(JUNGFRAUD) functionNotImplemented(); #else // only set @@ -4734,11 +4734,12 @@ int set_partial_readout(int file_des) { if (arg <= 0 || arg > MAX_ROWS_PER_READOUT) { ret = FAIL; sprintf(mess, - "Could not set partial readout. Must be between 1 " + "Could not set partial readout. Must be between %d " "and %d\n", - MAX_ROWS_PER_READOUT); + MIN_ROWS_PER_READOUT, MAX_ROWS_PER_READOUT); LOG(logERROR, (mess)); } else { +#ifdef EIGERD int dr = setDynamicRange(GET_FLAG); int isTenGiga = enableTenGigabitEthernet(GET_FLAG); unsigned int maxnl = MAX_ROWS_PER_READOUT; @@ -4753,7 +4754,16 @@ int set_partial_readout(int file_des) { arg, dr, isTenGiga ? "enabled" : "disabled", arg, maxnp, maxnl); LOG(logERROR, (mess)); - } else { + } else +#elif JUNGFRAU + if (arg % PARTIAL_READOUT_MULTIPLE != 0) { + ret = FAIL; + sprintf(mess, + "Could not set %d partial readout. %d must be a multiple of %d\n", arg, PARTIAL_READOUT_MULTIPLE); + LOG(logERROR, (mess)); + } else +#endif + { if (setPartialReadout(arg) == FAIL) { ret = FAIL; sprintf(mess, "Could not set partial readout to %d.\n", arg); @@ -4783,7 +4793,7 @@ int get_partial_readout(int file_des) { LOG(logDEBUG1, ("Getting partial readout\n")); -#ifndef EIGERD +#if !defined(EIGERD) && !defined(JUNGFRAUD) functionNotImplemented(); #else // get only diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index 37790f857..5615fd8bb 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -509,6 +509,15 @@ class Detector { /** [CTB] Options: 0-255 \n [Gotthard2] Options: 0-7 */ void setDBITPipeline(int value, Positions pos = {}); + /** [Eiger][Jungfrau] */ + Result getPartialReadout(Positions pos = {}) const; + + /** [Eiger] Number of lines to read out per half module + * Options: 0 - 256. 256 is default. The permissible values depend on + * dynamic range and 10Gbe enabled. \n[Jungfrau] Number of rows per module starting from the centre. Options: 8 - 512, must be multiples of 8. Default is 512. + */ + void setPartialReadout(const int lines, Positions pos = {}); + ///@{ /** @name Acquisition */ @@ -1048,15 +1057,6 @@ class Detector { */ void setRateCorrection(ns dead_time, Positions pos = {}); - /** [Eiger] */ - Result getPartialReadout(Positions pos = {}) const; - - /** [Eiger] Number of lines to read out per half module - * Options: 0 - 256. 256 is default. The permissible values depend on - * dynamic range and 10Gbe enabled. - */ - void setPartialReadout(const int lines, Positions pos = {}); - /** [Eiger] */ Result getInterruptSubframe(Positions pos = {}) const; diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index 3192afc5b..7bd0ab759 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -593,6 +593,7 @@ class CmdProxy { {"vhighvoltage", "highvoltage"}, {"digitest", "imagetest"}, {"filter", "filterresistor"}, + {"readnlines", "partialread"}, /** temperature */ @@ -716,7 +717,6 @@ class CmdProxy { {"rx_datastream", "rx_zmqstream"}, /* Eiger Specific */ - {"readnlines", "partialread"}, {"resmat", "partialreset"}, /* Jungfrau Specific */ @@ -807,6 +807,7 @@ class CmdProxy { {"filterresistor", &CmdProxy::filterresistor}, {"currentsource", &CmdProxy::CurrentSource}, {"dbitpipeline", &CmdProxy::dbitpipeline}, + {"partialread", &CmdProxy::partialread}, /** temperature */ {"templist", &CmdProxy::templist}, @@ -915,7 +916,6 @@ class CmdProxy { {"subdeadtime", &CmdProxy::subdeadtime}, {"overflow", &CmdProxy::overflow}, {"ratecorr", &CmdProxy::RateCorrection}, - {"partialread", &CmdProxy::partialread}, {"interruptsubframe", &CmdProxy::interruptsubframe}, {"measuredperiod", &CmdProxy::measuredperiod}, {"measuredsubperiod", &CmdProxy::measuredsubperiod}, @@ -1369,6 +1369,12 @@ class CmdProxy { "clock for latching digital bits.\n\t[Gotthard2] " "Options: 0-7\n\t[CTB] Options: 0-255"); + INTEGER_COMMAND_VEC_ID( + partialread, getPartialReadout, setPartialReadout, StringTo, + "[1 - 256]\n\t[Eiger] Number of rows to readout per half module " + "starting from the centre. Options: 0 - 256. 256 is default. The " + "permissible values depend on dynamic range and 10Gbe enabled.\n[8-512 (multiple of 8)]\n\t[Jungfrau] Number of rows per module starting from the centre. Options: 8 - 512, must be multiples of 8. Default is 512."); + /** temperature */ GET_COMMAND_NOID( templist, getTemperatureList, @@ -1809,12 +1815,6 @@ class CmdProxy { "[0, 1]\n\t[Eiger] Enable or disable show overflow flag in " "32 bit mode. Default is disabled."); - INTEGER_COMMAND_VEC_ID( - partialread, getPartialReadout, setPartialReadout, StringTo, - "[1 - 256]\n\t[Eiger] Number of rows to readout per half module " - "starting from the centre. Options: 0 - 256. 256 is default. The " - "permissible values depend on dynamic range and 10Gbe enabled."); - INTEGER_COMMAND_VEC_ID( interruptsubframe, getInterruptSubframe, setInterruptSubframe, StringTo, diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 1efbfb6d0..bd75817fd 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -732,6 +732,14 @@ void Detector::setDBITPipeline(int value, Positions pos) { pimpl->Parallel(&Module::setDBITPipeline, pos, value); } +Result Detector::getPartialReadout(Positions pos) const { + return pimpl->Parallel(&Module::getPartialReadout, pos); +} + +void Detector::setPartialReadout(const int lines, Positions pos) { + pimpl->Parallel(&Module::setPartialReadout, pos, lines); +} + // Acquisition void Detector::acquire() { pimpl->acquire(); } @@ -1372,14 +1380,6 @@ void Detector::updateRxRateCorrections() { } } -Result Detector::getPartialReadout(Positions pos) const { - return pimpl->Parallel(&Module::getPartialReadout, pos); -} - -void Detector::setPartialReadout(const int lines, Positions pos) { - pimpl->Parallel(&Module::setPartialReadout, pos, lines); -} - Result Detector::getInterruptSubframe(Positions pos) const { return pimpl->Parallel(&Module::getInterruptSubframe, pos); } diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index cd3ebf98e..fbff82223 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -734,6 +734,17 @@ void Module::setDBITPipeline(int value) { sendToDetector(F_SET_DBIT_PIPELINE, value, nullptr); } +int Module::getPartialReadout() const { + return sendToDetector(F_GET_PARTIAL_READOUT); +} + +void Module::setPartialReadout(const int value) { + sendToDetector(F_SET_PARTIAL_READOUT, value, nullptr); + if (shm()->useReceiverFlag) { + sendToReceiver(F_SET_RECEIVER_PARTIAL_READOUT, value, nullptr); + } +} + // Acquisition void Module::startReceiver() { @@ -1469,17 +1480,6 @@ void Module::sendReceiverRateCorrections(const std::vector &t) { } } -int Module::getPartialReadout() const { - return sendToDetector(F_GET_PARTIAL_READOUT); -} - -void Module::setPartialReadout(const int value) { - sendToDetector(F_SET_PARTIAL_READOUT, value, nullptr); - if (shm()->useReceiverFlag) { - sendToReceiver(F_SET_RECEIVER_PARTIAL_READOUT, value, nullptr); - } -} - bool Module::getInterruptSubframe() const { return sendToDetector(F_GET_INTERRUPT_SUBFRAME); } diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index f2509b644..f53f40168 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -178,7 +178,8 @@ class Module : public virtual slsDetectorDefs { void setCurrentSource(defs::currentSrcParameters par); int getDBITPipeline() const; void setDBITPipeline(int value); - + int getPartialReadout() const; + void setPartialReadout(const int value); /************************************************** * * * Acquisition * @@ -337,8 +338,6 @@ class Module : public virtual slsDetectorDefs { void setDefaultRateCorrection(); void setRateCorrection(int64_t t = 0); void sendReceiverRateCorrections(const std::vector &t); - int getPartialReadout() const; - void setPartialReadout(const int value); bool getInterruptSubframe() const; void setInterruptSubframe(const bool enable); int64_t getMeasuredPeriod() const; diff --git a/slsDetectorSoftware/tests/test-CmdProxy-eiger.cpp b/slsDetectorSoftware/tests/test-CmdProxy-eiger.cpp index 00074fe85..7482c30d0 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-eiger.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-eiger.cpp @@ -374,36 +374,6 @@ TEST_CASE("ratecorr", "[.cmd]") { } } -TEST_CASE("partialread", "[.cmd]") { - Detector det; - CmdProxy proxy(&det); - auto det_type = det.getDetectorType().squash(); - if (det_type == defs::EIGER) { - auto prev_val = det.getPartialReadout(); - { - std::ostringstream oss; - proxy.Call("partialread", {"256"}, -1, PUT, oss); - REQUIRE(oss.str() == "partialread 256\n"); - } - { - std::ostringstream oss; - proxy.Call("partialread", {}, -1, GET, oss); - REQUIRE(oss.str() == "partialread 256\n"); - } - { - std::ostringstream oss; - proxy.Call("partialread", {"16"}, -1, PUT, oss); - REQUIRE(oss.str() == "partialread 16\n"); - } - REQUIRE_THROWS(proxy.Call("partialread", {"0"}, -1, PUT)); - for (int i = 0; i != det.size(); ++i) { - det.setPartialReadout(prev_val[i], {i}); - } - } else { - REQUIRE_THROWS(proxy.Call("partialread", {}, -1, GET)); - } -} - TEST_CASE("interruptsubframe", "[.cmd]") { Detector det; CmdProxy proxy(&det); diff --git a/slsDetectorSoftware/tests/test-CmdProxy.cpp b/slsDetectorSoftware/tests/test-CmdProxy.cpp index 4aaa3421b..919b6098f 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy.cpp @@ -1494,6 +1494,43 @@ TEST_CASE("dbitpipeline", "[.cmd]") { } } +TEST_CASE("partialread", "[.cmd]") { + Detector det; + CmdProxy proxy(&det); + auto det_type = det.getDetectorType().squash(); + if (det_type == defs::EIGER || det_type == defs::JUNGFRAU) { + auto prev_val = det.getPartialReadout(); + { + std::ostringstream oss; + proxy.Call("partialread", {"256"}, -1, PUT, oss); + REQUIRE(oss.str() == "partialread 256\n"); + } + { + std::ostringstream oss; + proxy.Call("partialread", {}, -1, GET, oss); + REQUIRE(oss.str() == "partialread 256\n"); + } + { + std::ostringstream oss; + proxy.Call("partialread", {"16"}, -1, PUT, oss); + REQUIRE(oss.str() == "partialread 16\n"); + } + if (det_type == defs::JUNGFRAU) { + REQUIRE_THROWS(proxy.Call("partialread", {"7"}, -1, PUT)); + REQUIRE_THROWS(proxy.Call("partialread", {"20"}, -1, PUT)); + REQUIRE_THROWS(proxy.Call("partialread", {"44"}, -1, PUT)); + REQUIRE_THROWS(proxy.Call("partialread", {"513"}, -1, PUT)); + REQUIRE_THROWS(proxy.Call("partialread", {"1"}, -1, PUT)); + } + REQUIRE_THROWS(proxy.Call("partialread", {"0"}, -1, PUT)); + for (int i = 0; i != det.size(); ++i) { + det.setPartialReadout(prev_val[i], {i}); + } + } else { + REQUIRE_THROWS(proxy.Call("partialread", {}, -1, GET)); + } +} + TEST_CASE("currentsource", "[.cmd]") { Detector det; CmdProxy proxy(&det); diff --git a/slsReceiverSoftware/src/ClientInterface.cpp b/slsReceiverSoftware/src/ClientInterface.cpp index 2980fd0ee..7ebe53533 100644 --- a/slsReceiverSoftware/src/ClientInterface.cpp +++ b/slsReceiverSoftware/src/ClientInterface.cpp @@ -414,9 +414,11 @@ int ClientInterface::setup_receiver(Interface &socket) { std::to_string(arg.quad) + " due to fifo strucutre memory allocation"); } - impl()->setPartialReadout(arg.partialReadout); impl()->setThresholdEnergy(arg.thresholdEnergyeV[0]); } + if (myDetectorType == EIGER || myDetectorType == JUNGFRAU) { + impl()->setPartialReadout(arg.partialReadout); + } if (myDetectorType == MYTHEN3) { std::array val; for (int i = 0; i < 3; ++i) { @@ -1408,6 +1410,9 @@ int ClientInterface::set_partial_readout(Interface &socket) { auto arg = socket.Receive(); if (arg >= 0) { verifyIdle(socket); + if (myDetectorType != EIGER && myDetectorType != JUNGFRAU) { + throw RuntimeError("Could not set partial readout. Not implemented for this detector"); + } LOG(logDEBUG1) << "Setting Partial Readout:" << arg; impl()->setPartialReadout(arg); } diff --git a/slsReceiverSoftware/src/GeneralData.h b/slsReceiverSoftware/src/GeneralData.h index 975cdd8bd..4e577b08d 100644 --- a/slsReceiverSoftware/src/GeneralData.h +++ b/slsReceiverSoftware/src/GeneralData.h @@ -51,6 +51,7 @@ class GeneralData { uint32_t vetoPacketSize{0}; uint32_t vetoImageSize{0}; uint32_t vetoHsize{0}; + uint32_t maxRowsPerReadout{0}; GeneralData(){}; virtual ~GeneralData(){}; @@ -339,6 +340,7 @@ class EigerData : public GeneralData { threadsPerReceiver = 2; headerPacketSize = 40; standardheader = true; + maxRowsPerReadout = 256; }; /** @@ -384,6 +386,7 @@ class JungfrauData : public GeneralData { defaultFifoDepth = 2500; standardheader = true; defaultUdpSocketBufferSize = (1000 * 1024 * 1024); + maxRowsPerReadout = 512; }; /** diff --git a/slsReceiverSoftware/src/Implementation.cpp b/slsReceiverSoftware/src/Implementation.cpp index 43c4fd0be..65e725beb 100644 --- a/slsReceiverSoftware/src/Implementation.cpp +++ b/slsReceiverSoftware/src/Implementation.cpp @@ -477,8 +477,8 @@ std::vector Implementation::getNumMissingPackets() const { int np = generalData->packetsPerFrame; uint64_t totnp = np; // partial readout - if (partialReadout != MAX_EIGER_ROWS_PER_READOUT) { - totnp = ((partialReadout * np) / MAX_EIGER_ROWS_PER_READOUT); + if (partialReadout != generalData->maxRowsPerReadout) { + totnp = ((partialReadout * np) / generalData->maxRowsPerReadout); } totnp *= numberOfTotalFrames; mp[i] = listener[i]->GetNumMissingPacket(stoppedFlag, totnp); diff --git a/slsReceiverSoftware/src/Implementation.h b/slsReceiverSoftware/src/Implementation.h index 3d7bd1e8b..75d23392e 100644 --- a/slsReceiverSoftware/src/Implementation.h +++ b/slsReceiverSoftware/src/Implementation.h @@ -219,7 +219,7 @@ class Implementation : private virtual slsDetectorDefs { /* [Eiger] */ void setDeactivatedPadding(const bool enable); int getPartialReadout() const; - /* [Eiger] */ + /* [Eiger][Jungfrau] */ void setPartialReadout(const int value); /** [Eiger] */ void setThresholdEnergy(const int value); @@ -352,7 +352,7 @@ class Implementation : private virtual slsDetectorDefs { bool activated{true}; std::array detectorDataStream = {{true, true}}; bool deactivatedPaddingEnable{true}; - int partialReadout{MAX_EIGER_ROWS_PER_READOUT}; + int partialReadout{0}; int thresholdEnergyeV{-1}; std::array thresholdAllEnergyeV = {{-1, -1, -1}}; std::vector rateCorrections; diff --git a/slsReceiverSoftware/src/MasterAttributes.h b/slsReceiverSoftware/src/MasterAttributes.h index d68c5c0cd..fd3a14d3f 100644 --- a/slsReceiverSoftware/src/MasterAttributes.h +++ b/slsReceiverSoftware/src/MasterAttributes.h @@ -336,7 +336,8 @@ class JungfrauMasterAttributes : public MasterAttributes { oss << MasterAttributes::GetBinaryMasterAttributes() << "Exptime : " << sls::ToString(exptime) << '\n' << "Period : " << sls::ToString(period) << '\n' - << "Number of UDP Interfaces : " << numUDPInterfaces << '\n'; + << "Number of UDP Interfaces : " << numUDPInterfaces << '\n' + << "Partial Readout (rows) : " << partialReadout << '\n'; std::string message = oss.str(); MasterAttributes::WriteBinaryAttributes(fd, message); }; @@ -352,6 +353,13 @@ class JungfrauMasterAttributes : public MasterAttributes { "Number of UDP Interfaces", PredType::NATIVE_INT, dataspace); dataset.write(&numUDPInterfaces, PredType::NATIVE_INT); } + // partialReadout + { + DataSpace dataspace = DataSpace(H5S_SCALAR); + DataSet dataset = group->createDataSet( + "Partial readout (rows)", PredType::NATIVE_INT, dataspace); + dataset.write(&partialReadout, PredType::NATIVE_INT); + } }; #endif }; diff --git a/slsReceiverSoftware/src/receiver_defs.h b/slsReceiverSoftware/src/receiver_defs.h index fa46fbef8..f70ac5025 100755 --- a/slsReceiverSoftware/src/receiver_defs.h +++ b/slsReceiverSoftware/src/receiver_defs.h @@ -43,7 +43,6 @@ // parameters to calculate fifo depth #define SAMPLE_TIME_IN_NS (100000000) // 100ms -#define MAX_EIGER_ROWS_PER_READOUT (256) // to differentiate between gotthard and short gotthard #define GOTTHARD_PACKET_SIZE (1286) diff --git a/slsSupportLib/include/sls/DataSocket.h b/slsSupportLib/include/sls/DataSocket.h index 6a5eba8bb..79022cb17 100644 --- a/slsSupportLib/include/sls/DataSocket.h +++ b/slsSupportLib/include/sls/DataSocket.h @@ -26,7 +26,7 @@ class DataSocket { DataSocket &operator=(DataSocket const &) = delete; int getSocketId() const { return sockfd_; } int getFnum() const { return fnum_; } - int setFnum(const int fnum); + void setFnum(const int fnum); int Send(const void *buffer, size_t size); diff --git a/slsSupportLib/src/DataSocket.cpp b/slsSupportLib/src/DataSocket.cpp index 6314317bd..09c20ebda 100644 --- a/slsSupportLib/src/DataSocket.cpp +++ b/slsSupportLib/src/DataSocket.cpp @@ -42,7 +42,7 @@ DataSocket &DataSocket::operator=(DataSocket &&move) noexcept { return *this; } -int DataSocket::setFnum(const int fnum) { +void DataSocket::setFnum(const int fnum) { fnum_ = fnum; }