diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index fc54317f2..ebe5de20a 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -914,7 +914,18 @@ class Detector { void setDataStream(const defs::portPosition port, const bool enable, Positions pos = {}); - /* list of possible port positions */ + /** List of disabled udp ports with index (moduleIndex * 2 + portIndex), + * where portIndex is 0 for BOTTOM/LEFT port, and 1 for TOP/RIGHT port + * [Eiger] LEFT, RIGHT + * [Jungfrau][Moench] throws for single UDP interface. Otherwise, TOP, + * BOTTOM + */ + std::vector getRxDisabledUDPPortIndices() const; + + /* list of possible port positions. + * [Eiger] TOP, BOTTOM + * [Jungfrau][Moench] LEFT, RIGHT + */ std::vector getPortPositionList() const; ///@} diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 550f2d18d..ace3523ea 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -1319,22 +1319,16 @@ void Detector::setTransmissionDelay(int step) { Result Detector::getDataStream(const defs::portPosition port, Positions pos) const { - return pimpl->Parallel(&Module::getDataStream, pos, port); + return pimpl->getDataStream(port, pos); } void Detector::setDataStream(const defs::portPosition port, const bool enable, Positions pos) { - // check num interfaces - auto numInterfaces = - pimpl->Parallel(&Module::getNumberofUDPInterfacesFromShm, {}) - .tsquash("Inconsistent number of UDP interfaces among modules"); - if (numInterfaces != 2) { - throw RuntimeError( - "Cannot enable/disable individual udp ports. Change number of udp " - "interfaces to 2 (cmd = numinterfaces)."); - } - pimpl->Parallel(&Module::setDataStream, pos, port, enable); - pimpl->updateRxUDPDatastreamMetadata(); + pimpl->setDataStream(port, enable, pos); +} + +std::vector Detector::getRxDisabledUDPPortIndices() const { + return pimpl->getRxDisabledUDPPortIndices(); } std::vector Detector::getPortPositionList() const { diff --git a/slsDetectorSoftware/src/DetectorImpl.cpp b/slsDetectorSoftware/src/DetectorImpl.cpp index abbd5d747..77d485681 100644 --- a/slsDetectorSoftware/src/DetectorImpl.cpp +++ b/slsDetectorSoftware/src/DetectorImpl.cpp @@ -1644,26 +1644,33 @@ void DetectorImpl::verifyUniqueHost( } } -std::vector DetectorImpl::getPortPositionList() const { - switch (shm()->detType) { - case defs::JUNGFRAU: - case defs::MOENCH: - return std::vector{defs::BOTTOM, defs::TOP}; - case defs::EIGER: - return std::vector{defs::LEFT, defs::RIGHT}; - default: - throw RuntimeError("port Position does not exist for this detector"); - } -} - -void DetectorImpl::updateRxUDPDatastreamMetadata() { - // check num interfaces +void DetectorImpl::assertTwoUDPInterfaces(const std::string &cmd) const { + // assert globally auto numInterfaces = Parallel(&Module::getNumberofUDPInterfacesFromShm, {}) .tsquash("Inconsistent number of UDP interfaces among modules"); if (numInterfaces != 2) { - throw RuntimeError("Invalid number of UDP interfaces. Expected 2."); + throw RuntimeError( + "Cannot " + cmd + + ". Change number of udp interfaces to 2 (cmd = numinterfaces)."); } +} + +Result DetectorImpl::getDataStream(const defs::portPosition port, + Positions pos) const { + assertTwoUDPInterfaces("get enable/disable UDP ports"); + return Parallel(&Module::getDataStream, pos, port); +} + +void DetectorImpl::setDataStream(const defs::portPosition port, + const bool enable, Positions pos) { + assertTwoUDPInterfaces("set enable/disable UDP ports"); + Parallel(&Module::setDataStream, pos, port, enable); + updateRxUDPDatastreamMetadata(); +} + +void DetectorImpl::updateRxUDPDatastreamMetadata() { + assertTwoUDPInterfaces("update Disbaled UDP ports metadata in receiver"); std::vector disable; auto portList = getPortPositionList(); @@ -1690,6 +1697,23 @@ void DetectorImpl::updateRxUDPDatastreamMetadata() { modules[0]->updateRxUDPPortDisableMetadata(disable); } +std::vector DetectorImpl::getRxDisabledUDPPortIndices() const { + assertTwoUDPInterfaces("get Disbaled UDP ports metadata from receiver"); + return modules[0]->getRxUDPPortDisableMetadata(); +} + +std::vector DetectorImpl::getPortPositionList() const { + switch (shm()->detType) { + case defs::JUNGFRAU: + case defs::MOENCH: + return std::vector{defs::BOTTOM, defs::TOP}; + case defs::EIGER: + return std::vector{defs::LEFT, defs::RIGHT}; + default: + throw RuntimeError("port Position does not exist for this detector"); + } +} + std::vector DetectorImpl::getRxROI(int module_id) const { if (shm()->detType == CHIPTESTBOARD || shm()->detType == defs::XILINX_CHIPTESTBOARD) { diff --git a/slsDetectorSoftware/src/DetectorImpl.h b/slsDetectorSoftware/src/DetectorImpl.h index 3953a1200..a1335f1be 100644 --- a/slsDetectorSoftware/src/DetectorImpl.h +++ b/slsDetectorSoftware/src/DetectorImpl.h @@ -310,8 +310,14 @@ class DetectorImpl : public virtual slsDetectorDefs { std::vector> verifyUniqueRxHost(const std::vector &names) const; - std::vector getPortPositionList() const; + void assertTwoUDPInterfaces(const std::string &cmd) const; + Result getDataStream(const defs::portPosition port, + Positions pos) const; + void setDataStream(const defs::portPosition port, const bool enable, + Positions pos); void updateRxUDPDatastreamMetadata(); + std::vector getRxDisabledUDPPortIndices() const; + std::vector getPortPositionList() const; defs::xy getPortGeometry() const; std::vector getRxROI(int module_id = -1) const; diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index 5f3eea663..9eccb52f2 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -1441,8 +1441,8 @@ void Module::updateRxUDPPortDisableMetadata(const std::vector &disable) { LOG(logDEBUG) << "Updating UDP port disable metadata in Receiver 0"; auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort); - client.Send(F_RECEIVER_UDP_PORT_DISABLE_META); - client.setFnum(F_RECEIVER_UDP_PORT_DISABLE_META); + client.Send(F_RECEIVER_SET_UDP_PORT_DISABLE_META); + client.setFnum(F_RECEIVER_SET_UDP_PORT_DISABLE_META); auto nports = static_cast(disable.size()); client.Send(nports); @@ -1455,6 +1455,29 @@ void Module::updateRxUDPPortDisableMetadata(const std::vector &disable) { } } +std::vector Module::getRxUDPPortDisableMetadata() const { + if (!shm()->useReceiverFlag) { + throw RuntimeError("No receiver to get disabled udp port indices."); + } + + LOG(logDEBUG) << "Getting UDP port disable metadata in Receiver 0"; + auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort); + + client.Send(F_RECEIVER_GET_UDP_PORT_DISABLE_META); + client.setFnum(F_RECEIVER_GET_UDP_PORT_DISABLE_META); + if (client.Receive() == FAIL) { + throw ReceiverError("Receiver " + std::to_string(moduleIndex) + + " returned error: " + client.readErrorMessage()); + } + auto nports = client.Receive(); + std::vector retval(nports); + client.Send(nports); + if (nports > 0) { + client.Receive(retval); + } + return retval; +} + // Receiver Config bool Module::getUseReceiverFlag() const { return shm()->useReceiverFlag; } diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index 40f0953d1..fa5ed9fa6 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -282,6 +282,7 @@ class Module : public virtual slsDetectorDefs { bool getDataStream(const portPosition port) const; void setDataStream(const portPosition port, const bool enable); void updateRxUDPPortDisableMetadata(const std::vector &disable); + std::vector getRxUDPPortDisableMetadata() const; /************************************************** * * diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-master-attributes.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-master-attributes.cpp index 8bf8c46d7..b4f7c7e62 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-master-attributes.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-master-attributes.cpp @@ -125,6 +125,24 @@ void read_from_h5_dataset(const H5::DataSet &dataset, const std::string &name, } #endif +/** std::vector */ +void read_from_json(const Document &doc, const std::string &name, + std::vector &retval) { + for (const auto &item : doc[name.c_str()].GetArray()) { + retval.push_back(item.GetInt()); + } +} +#ifdef HDF5C +void read_from_h5_dataset(const H5::DataSet &dataset, const std::string &name, + std::vector &retval) { + H5::DataSpace dataspace = dataset.getSpace(); + hsize_t dims[1]; + dataspace.getSimpleExtentDims(dims); + retval.resize(dims[0]); + dataset.read(retval.data(), H5::PredType::STD_I32LE); +} +#endif + /** std::vector */ void read_from_json(const Document &doc, const std::string &name, std::vector &retval) { @@ -658,14 +676,10 @@ void test_master_file_udp_interfaces_disable( if (num_udp_interfaces == 1) return; - // expected values - // auto disabled_udp_ports = det.getDisabled// + auto disabled_udp_ports = det.getRxDisabledUDPPortIndices(); - /* - REQUIRE_NOTHROW(check_master_file( - doc, MasterAttributes::N_NUM_UDP_INTERFACES.data(), - num_udp_interfaces)); - */ + REQUIRE_NOTHROW(check_master_file>( + doc, MasterAttributes::N_UDP_PORTS_DISBLED.data(), disabled_udp_ports)); } void test_master_file_read_n_rows(const Detector &det, diff --git a/slsReceiverSoftware/src/ClientInterface.cpp b/slsReceiverSoftware/src/ClientInterface.cpp index 69384d847..3d7fdb9f8 100644 --- a/slsReceiverSoftware/src/ClientInterface.cpp +++ b/slsReceiverSoftware/src/ClientInterface.cpp @@ -222,7 +222,8 @@ int ClientInterface::functionTable(){ flist[F_RECEIVER_GET_ROI_METADATA] = &ClientInterface::get_roi_metadata; flist[F_SET_RECEIVER_READOUT_SPEED] = &ClientInterface::set_readout_speed; flist[F_RECEIVER_GET_UDP_DATASTREAM] = &ClientInterface::get_port_udp_datastream; - flist[F_RECEIVER_UDP_PORT_DISABLE_META] = &ClientInterface::update_udp_port_disable_meta; + flist[F_RECEIVER_SET_UDP_PORT_DISABLE_META] = &ClientInterface::set_udp_port_disable_meta; + flist[F_RECEIVER_GET_UDP_PORT_DISABLE_META] = &ClientInterface::get_udp_port_disable_meta; for (int i = NUM_DET_FUNCTIONS + 1; i < NUM_REC_FUNCTIONS ; i++) { @@ -1918,7 +1919,7 @@ int ClientInterface::set_readout_speed(Interface &socket) { return socket.Send(OK); } -int ClientInterface::update_udp_port_disable_meta(Interface &socket) { +int ClientInterface::set_udp_port_disable_meta(Interface &socket) { auto nports = socket.Receive(); std::vector portsDisabled; if (nports > 0) { @@ -1928,7 +1929,8 @@ int ClientInterface::update_udp_port_disable_meta(Interface &socket) { } verifyIdle(socket); try { - impl()->updateUDPPortsDisabledMetadata(portsDisabled); + + impl()->setUDPPortsDisabledMetadata(portsDisabled); } catch (const std::exception &e) { throw RuntimeError("Could not update UDP ports disabled metadata [" + std::string(e.what()) + ']'); @@ -1936,4 +1938,16 @@ int ClientInterface::update_udp_port_disable_meta(Interface &socket) { return socket.Send(OK); } +int ClientInterface::get_udp_port_disable_meta(Interface &socket) { + auto retvals = impl()->getUDPPortsDisabledMetadata(); + LOG(logDEBUG1) << "Receiver disabled udp ports retval:" + << ToString(retvals); + socket.Send(OK); + auto size = static_cast(retvals.size()); + socket.Send(size); + if (size > 0) + socket.Send(retvals); + return OK; +} + } // namespace sls diff --git a/slsReceiverSoftware/src/ClientInterface.h b/slsReceiverSoftware/src/ClientInterface.h index 26d257169..ca1230c13 100644 --- a/slsReceiverSoftware/src/ClientInterface.h +++ b/slsReceiverSoftware/src/ClientInterface.h @@ -170,7 +170,8 @@ class ClientInterface : private virtual slsDetectorDefs { int set_dbit_reorder(ServerInterface &socket); int get_roi_metadata(ServerInterface &socket); int set_readout_speed(ServerInterface &socket); - int update_udp_port_disable_meta(ServerInterface &socket); + int set_udp_port_disable_meta(ServerInterface &socket); + int get_udp_port_disable_meta(ServerInterface &socket); Implementation *impl() { if (receiver != nullptr) { diff --git a/slsReceiverSoftware/src/Implementation.cpp b/slsReceiverSoftware/src/Implementation.cpp index 3c42308e7..3a3b5b45b 100644 --- a/slsReceiverSoftware/src/Implementation.cpp +++ b/slsReceiverSoftware/src/Implementation.cpp @@ -1715,11 +1715,15 @@ void Implementation::setUDPDataStream(const portPosition port, listener[i]->SetUDPDatastream(udpDataStream[i]); } -void Implementation::updateUDPPortsDisabledMetadata( +void Implementation::setUDPPortsDisabledMetadata( const std::vector &portsDisabled) { udpPortsDisabledMetadata = portsDisabled; } +std::vector Implementation::getUDPPortsDisabledMetadata() const { + return udpPortsDisabledMetadata; +} + int Implementation::getReadNRows() const { return readNRows; } void Implementation::setReadNRows(const int value) { diff --git a/slsReceiverSoftware/src/Implementation.h b/slsReceiverSoftware/src/Implementation.h index ce98e49aa..4a1999396 100644 --- a/slsReceiverSoftware/src/Implementation.h +++ b/slsReceiverSoftware/src/Implementation.h @@ -230,7 +230,8 @@ class Implementation : private virtual slsDetectorDefs { * [Eiger] deactivated at module level */ void setUDPDataStream(const portPosition port, const bool enable); - void updateUDPPortsDisabledMetadata(const std::vector &portsDisabled); + void setUDPPortsDisabledMetadata(const std::vector &portsDisabled); + std::vector getUDPPortsDisabledMetadata() const; int getReadNRows() const; /* [Eiger][Jungfrau][Moench] */ void setReadNRows(const int value); diff --git a/slsSupportLib/include/sls/sls_detector_funcs.h b/slsSupportLib/include/sls/sls_detector_funcs.h index 1ba0171c4..1678c3a8a 100755 --- a/slsSupportLib/include/sls/sls_detector_funcs.h +++ b/slsSupportLib/include/sls/sls_detector_funcs.h @@ -424,7 +424,8 @@ enum detFuncs { F_RECEIVER_GET_ROI_METADATA, F_SET_RECEIVER_READOUT_SPEED, F_RECEIVER_GET_UDP_DATASTREAM, - F_RECEIVER_UDP_PORT_DISABLE_META, + F_RECEIVER_SET_UDP_PORT_DISABLE_META, + F_RECEIVER_GET_UDP_PORT_DISABLE_META, NUM_REC_FUNCTIONS }; @@ -845,7 +846,8 @@ const char* getFunctionNameFromEnum(enum detFuncs func) { case F_RECEIVER_GET_ROI_METADATA: return "F_RECEIVER_GET_ROI_METADATA"; case F_SET_RECEIVER_READOUT_SPEED: return "F_SET_RECEIVER_READOUT_SPEED"; case F_RECEIVER_GET_UDP_DATASTREAM: return "F_RECEIVER_GET_UDP_DATASTREAM"; - case F_RECEIVER_UDP_PORT_DISABLE_META: return "F_RECEIVER_UDP_PORT_DISABLE_META"; + case F_RECEIVER_SET_UDP_PORT_DISABLE_META: return "F_RECEIVER_SET_UDP_PORT_DISABLE_META"; + case F_RECEIVER_GET_UDP_PORT_DISABLE_META: return "F_RECEIVER_GET_UDP_PORT_DISABLE_META"; case NUM_REC_FUNCTIONS: return "NUM_REC_FUNCTIONS";