From d095ecb2d01a4a3503582657582bf3e9147444b1 Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Thu, 11 Jun 2026 13:19:49 +0200 Subject: [PATCH] added tests for master file --- .../tests/acquire/ExpectedState.cpp | 18 +++++++++ .../tests/acquire/ExpectedState.h | 6 +++ .../tests/checks/MasterFileChecks.h | 26 ++++++++++++ .../tests/master_file/ReadersH5.h | 40 +++++++++++++++++++ .../tests/master_file/ReadersJson.h | 22 ++++++++++ slsReceiverSoftware/src/MasterAttributes.cpp | 4 +- slsReceiverSoftware/src/MasterAttributes.h | 2 +- 7 files changed, 115 insertions(+), 3 deletions(-) diff --git a/slsDetectorSoftware/tests/acquire/ExpectedState.cpp b/slsDetectorSoftware/tests/acquire/ExpectedState.cpp index 17a5edcf0..a63e3e479 100644 --- a/slsDetectorSoftware/tests/acquire/ExpectedState.cpp +++ b/slsDetectorSoftware/tests/acquire/ExpectedState.cpp @@ -136,6 +136,14 @@ int get_num_udp_interfaces(const Detector &det) { "Inconsistent number of UDP interfaces"); } +std::vector get_udp_port_types(const Detector &det) { + return det.getPortPositionList(); +} + +std::vector get_udp_ports_disabled(const Detector &det) { + return det.getRxDisabledUDPPortIndices(); +} + int get_read_n_rows(const Detector &det) { return det.getReadNRows().tsquash("Inconsistent number of read rows"); } @@ -184,6 +192,10 @@ acq::JungfrauExpectedState build_jungfrau_specific_state(const Detector &det) { e.exptime = get_exptime(det); e.period = get_period(det); e.num_udp_interfaces = get_num_udp_interfaces(det); + if (e.num_udp_interfaces == 2) { + e.udp_port_types = get_udp_port_types(det); + e.udp_ports_disabled = get_udp_ports_disabled(det); + } e.read_n_rows = get_read_n_rows(det); e.readout_speed = get_readout_speed(det); return e; @@ -195,6 +207,10 @@ acq::MoenchExpectedState build_moench_specific_state(const Detector &det) { e.exptime = get_exptime(det); e.period = get_period(det); e.num_udp_interfaces = get_num_udp_interfaces(det); + if (e.num_udp_interfaces == 2) { + e.udp_port_types = get_udp_port_types(det); + e.udp_ports_disabled = get_udp_ports_disabled(det); + } e.read_n_rows = get_read_n_rows(det); e.readout_speed = get_readout_speed(det); return e; @@ -213,6 +229,8 @@ acq::EigerExpectedState build_eiger_specific_state(const Detector &det) { e.sub_exptime = sub_exptime; e.sub_period = sub_period; e.quad = det.getQuad().tsquash("Inconsistent quad setting"); + e.udp_port_types = get_udp_port_types(det); + e.udp_ports_disabled = get_udp_ports_disabled(det); e.read_n_rows = get_read_n_rows(det); { for (auto item : det.getRateCorrection()) diff --git a/slsDetectorSoftware/tests/acquire/ExpectedState.h b/slsDetectorSoftware/tests/acquire/ExpectedState.h index 06b457cef..bff309485 100644 --- a/slsDetectorSoftware/tests/acquire/ExpectedState.h +++ b/slsDetectorSoftware/tests/acquire/ExpectedState.h @@ -31,6 +31,8 @@ struct JungfrauExpectedState { ns exptime{}; ns period{}; int num_udp_interfaces{}; + std::vector udp_port_types; + std::vector udp_ports_disabled; int read_n_rows{}; defs::speedLevel readout_speed{}; }; @@ -40,6 +42,8 @@ struct MoenchExpectedState { ns exptime{}; ns period{}; int num_udp_interfaces{}; + std::vector udp_port_types; + std::vector udp_ports_disabled; int read_n_rows{}; defs::speedLevel readout_speed{}; }; @@ -54,6 +58,8 @@ struct EigerExpectedState { ns sub_exptime{}; ns sub_period{}; bool quad{}; + std::vector udp_port_types; + std::vector udp_ports_disabled; int read_n_rows{}; std::vector rate_corrections{}; defs::speedLevel readout_speed{}; diff --git a/slsDetectorSoftware/tests/checks/MasterFileChecks.h b/slsDetectorSoftware/tests/checks/MasterFileChecks.h index db5fff20f..d5770913e 100644 --- a/slsDetectorSoftware/tests/checks/MasterFileChecks.h +++ b/slsDetectorSoftware/tests/checks/MasterFileChecks.h @@ -128,6 +128,22 @@ void check_num_udp_interfaces(CheckerT &checker, const int &value) { value); } +template +void check_udp_ports_type(CheckerT &checker, + const std::vector &value) { + REQUIRE(value.size() == 2); + std::vector ports = {ToString(value[0]), ToString(value[1])}; + checker.template check>( + MasterAttributes::N_UDP_PORTS_TYPE.data(), ports); +} + +template +void check_udp_ports_disabled(CheckerT &checker, + const std::vector &value) { + checker.template check>( + MasterAttributes::N_UDP_PORTS_DISABLED.data(), value); +} + template void check_read_n_rows(CheckerT &checker, const int &value) { checker.template check(MasterAttributes::N_NUMBER_OF_ROWS.data(), @@ -318,6 +334,10 @@ void check_jungfrau_metadata(CheckerT &checker, check_exptime(checker, st.exptime); check_period(checker, st.period); check_num_udp_interfaces(checker, st.num_udp_interfaces); + if (st.num_udp_interfaces == 2) { + check_udp_ports_type(checker, st.udp_port_types); + check_udp_ports_disabled(checker, st.udp_ports_disabled); + } check_read_n_rows(checker, st.read_n_rows); check_readout_speed(checker, st.readout_speed); } @@ -331,6 +351,10 @@ void check_moench_metadata(CheckerT &checker, check_exptime(checker, st.exptime); check_period(checker, st.period); check_num_udp_interfaces(checker, st.num_udp_interfaces); + if (st.num_udp_interfaces == 2) { + check_udp_ports_type(checker, st.udp_port_types); + check_udp_ports_disabled(checker, st.udp_ports_disabled); + } check_read_n_rows(checker, st.read_n_rows); check_readout_speed(checker, st.readout_speed); } @@ -349,6 +373,8 @@ void check_eiger_metadata(CheckerT &checker, check_sub_exptime(checker, st.sub_exptime); check_sub_period(checker, st.sub_period); check_quad(checker, st.quad); + check_udp_ports_type(checker, st.udp_port_types); + check_udp_ports_disabled(checker, st.udp_ports_disabled); check_read_n_rows(checker, st.read_n_rows); check_rate_corrections(checker, st.rate_corrections); check_readout_speed(checker, st.readout_speed); diff --git a/slsDetectorSoftware/tests/master_file/ReadersH5.h b/slsDetectorSoftware/tests/master_file/ReadersH5.h index fcd4fa9f7..699e30529 100644 --- a/slsDetectorSoftware/tests/master_file/ReadersH5.h +++ b/slsDetectorSoftware/tests/master_file/ReadersH5.h @@ -238,6 +238,23 @@ template <> struct Reader> { } }; +template <> struct Reader> { + static std::vector read(const H5Context &ctx, const std::string &name, + AccessType access) { + if (access == AccessType::Attribute) { + throw RuntimeError("'std::vector' attribute access not " + "supported for HDF5"); + } + require_dataset(ctx, name); + auto ds = ctx.file.openDataSet(HDF5_GROUP + name); + auto len = get_1d_size(ds); + std::vector out{}; + out.resize(len); + ds.read(out.data(), H5::PredType::NATIVE_INT); + return out; + } +}; + template <> struct Reader> { static std::vector read(const H5Context &ctx, const std::string &name, AccessType access) { @@ -255,6 +272,29 @@ template <> struct Reader> { } }; +template <> struct Reader> { + static std::vector + read(const H5Context &ctx, const std::string &name, AccessType access) { + if (access == AccessType::Attribute) { + throw RuntimeError( + "'std::vector' attribute access not " + "supported for HDF5"); + } + require_dataset(ctx, name); + auto ds = ctx.file.openDataSet(HDF5_GROUP + name); + H5::StrType strType(H5::PredType::C_S1, H5T_VARIABLE); + std::vector raw; + raw.resize(get_1d_size(ds)); + ds.read(raw.data(), strType); + std::vector out; + out.reserve(raw.size()); + for (auto c : raw) { + out.emplace_back(c); + } + return out; + } +}; + template <> struct Reader> { static std::map read(const H5Context &ctx, const std::string &name, AccessType access) { diff --git a/slsDetectorSoftware/tests/master_file/ReadersJson.h b/slsDetectorSoftware/tests/master_file/ReadersJson.h index 013f8f0fd..4eb8b2a8b 100644 --- a/slsDetectorSoftware/tests/master_file/ReadersJson.h +++ b/slsDetectorSoftware/tests/master_file/ReadersJson.h @@ -120,6 +120,17 @@ template <> struct Reader> { } }; +template <> struct Reader> { + static std::vector read(const JsonContext &ctx, + const std::string &name, AccessType access) { + std::vector out{}; + for (const auto &item : ctx.doc[name.c_str()].GetArray()) { + out.push_back(item.GetInt()); + } + return out; + } +}; + template <> struct Reader> { static std::vector read(const JsonContext &ctx, const std::string &name, AccessType access) { @@ -131,6 +142,17 @@ template <> struct Reader> { } }; +template <> struct Reader> { + static std::vector + read(const JsonContext &ctx, const std::string &name, AccessType access) { + std::vector out{}; + for (const auto &item : ctx.doc[name.c_str()].GetArray()) { + out.push_back(item.GetString()); + } + return out; + } +}; + template <> struct Reader> { static std::map read(const JsonContext &ctx, const std::string &name, AccessType access) { diff --git a/slsReceiverSoftware/src/MasterAttributes.cpp b/slsReceiverSoftware/src/MasterAttributes.cpp index 03dd0a8ae..8ef96cd46 100644 --- a/slsReceiverSoftware/src/MasterAttributes.cpp +++ b/slsReceiverSoftware/src/MasterAttributes.cpp @@ -721,12 +721,12 @@ void MasterAttributes::WriteHDF5UDPPortsType(H5::Group *group) { #endif void MasterAttributes::WriteBinaryUDPPortsDisabled(writer *w) { - WriteBinary(w, N_UDP_PORTS_DISBLED.data(), udpPortsDisabled); + WriteBinary(w, N_UDP_PORTS_DISABLED.data(), udpPortsDisabled); } #ifdef HDF5C void MasterAttributes::WriteHDF5UDPPortsDisabled(H5::Group *group) { - WriteHDF5Int(group, N_UDP_PORTS_DISBLED.data(), udpPortsDisabled); + WriteHDF5Int(group, N_UDP_PORTS_DISABLED.data(), udpPortsDisabled); } #endif diff --git a/slsReceiverSoftware/src/MasterAttributes.h b/slsReceiverSoftware/src/MasterAttributes.h index 114ac5625..88a4bf975 100644 --- a/slsReceiverSoftware/src/MasterAttributes.h +++ b/slsReceiverSoftware/src/MasterAttributes.h @@ -127,7 +127,7 @@ class MasterAttributes { inline static const std::string_view N_SCAN_PARAMETERS = "Scan Parameters"; inline static const std::string_view N_ADDITIONAL_JSON_HEADER = "Additional JSON Header"; - inline static const std::string_view N_UDP_PORTS_DISBLED = + inline static const std::string_view N_UDP_PORTS_DISABLED = "UDP Ports Disabled"; inline static const std::string_view N_UDP_PORTS_TYPE = "UDP Ports Type";