Files
Jungfraujoch/tests/JFJochBrokerParserTest.cpp

135 lines
4.5 KiB
C++

// Copyright (2019-2022) Paul Scherrer Institute
// SPDX-License-Identifier: GPL-3.0-or-later
#include <catch2/catch.hpp>
#include "../broker/JFJochBrokerParser.h"
using namespace nlohmann::literals;
TEST_CASE("JFJochBrokerParser_DetectorGeometry_missing") {
nlohmann::json j;
j["bla"] = "x";
REQUIRE_THROWS(ParseDetectorGeometry(j));
}
TEST_CASE("JFJochBrokerParser_DetectorGeometry_wrong_type") {
nlohmann::json j;
j["standard_detector"] = "x";
REQUIRE_THROWS(ParseDetectorGeometry(j));
}
TEST_CASE("JFJochBrokerParser_DetectorGeometry_standard_detector") {
nlohmann::json j = R"(
{
"standard_geometry": {
"nmodules": 18,
"horizontal_stacking": 3,
"gap_x": 10,
"gap_y": 20,
"mirror_y": false
}
}
)"_json;
REQUIRE_NOTHROW(ParseDetectorGeometry(j));
JFJochProtoBuf::DetectorGeometry geom = ParseDetectorGeometry(j);
REQUIRE(geom.width_pxl() == 10 * 2 + 1030 * 3);
REQUIRE(geom.height_pxl() == 20 * 5 + 514 * 6);
REQUIRE(geom.module_geometry_size() == 18);
}
TEST_CASE("JFJochBrokerParser_DetectorGeometry_custom_detector") {
nlohmann::json j = R"(
{
"custom_geometry": [
{"x0": 0, "y0": 0, "fast_axis":"Xp", "slow_axis":"Yp"},
{"x0": 1999, "y0": 1999, "fast_axis":"Yn", "slow_axis":"Xn"}
]
}
)"_json;
REQUIRE_NOTHROW(ParseDetectorGeometry(j));
JFJochProtoBuf::DetectorGeometry geom = ParseDetectorGeometry(j);
REQUIRE(geom.width_pxl() == 2000);
REQUIRE(geom.height_pxl() == 2000);
REQUIRE(geom.module_geometry_size() == 2);
REQUIRE(geom.module_geometry(0).pixel0() == 0);
REQUIRE(geom.module_geometry(0).fast_direction_step() == 1);
REQUIRE(geom.module_geometry(0).slow_direction_step() == 2000);
REQUIRE(geom.module_geometry(1).pixel0() == 2000*2000-1);
REQUIRE(geom.module_geometry(1).fast_direction_step() == -2000);
REQUIRE(geom.module_geometry(1).slow_direction_step() == -1);
}
TEST_CASE("JFJochBrokerParser_DetectorSetup") {
nlohmann::json j = R"(
{
"standard_geometry": {
"nmodules": 4,
"horizontal_stacking": 2,
"gap_x": 10,
"gap_y": 20,
"mirror_y": false
},
"description": "PSI JUNGFRAU 2M",
"module_hostname": ["mx1", "mx2", "mx3", "mx4"],
"gain_files": [
"../../tests/test_data/gainMaps_M049.bin",
"../../tests/test_data/gainMaps_M049.bin",
"../../tests/test_data/gainMaps_M049.bin",
"../../tests/test_data/gainMaps_M049.bin"
]
}
)"_json;
REQUIRE_NOTHROW(ParseDetectorSetup(j));
auto detector = ParseDetectorSetup(j);
JFJochProtoBuf::Detector detector_pbuf = detector;
REQUIRE(detector_pbuf.geometry().width_pxl() == 1030 * 2 + 10);
REQUIRE(detector_pbuf.geometry().height_pxl() == 20 * 1 + 514 * 2);
REQUIRE(detector_pbuf.geometry().module_geometry_size() == 4);
REQUIRE(detector_pbuf.description() == "PSI JUNGFRAU 2M");
REQUIRE(detector_pbuf.module_hostname_size() == 4);
REQUIRE(detector_pbuf.module_hostname(2) == "mx3");
REQUIRE(detector.GetGainCalibration().size() == 4);
}
TEST_CASE("JFJochBrokerParser_ParseFacilityConfiguration") {
nlohmann::json j = R"(
{
"cfg": {
"source_name": "Swiss Light Source",
"source_name_short": "SLS",
"instrument_name": "X06SA VESPA",
"instrument_name_short": "VESPA",
"datastreams": 4,
"pedestal_g0_frames": 5000,
"pedestal_g1_frames": 333,
"pedestal_g2_frames": 333,
"frame_time_us": 0.0012,
"count_time_us": "950 us",
"spot_finding_period_us": " 2 ms",
"preview_period_us": "1 s",
"detector_ipv4": "10.10.25.0"
}
}
)"_json;
DiffractionExperiment x(DetectorGeometry(8));
ParseFacilityConfiguration(j, "cfg", x);
REQUIRE(x.GetSourceName() == "Swiss Light Source");
REQUIRE(x.GetSourceNameShort() == "SLS");
REQUIRE(x.GetInstrumentName() == "X06SA VESPA");
REQUIRE(x.GetInstrumentNameShort() == "VESPA");
REQUIRE(x.GetDataStreamsNum() == 4);
REQUIRE(x.GetPedestalG0Frames() == 5000);
REQUIRE(x.GetPedestalG1Frames() == 333);
REQUIRE(x.GetPedestalG2Frames() == 333);
REQUIRE(x.GetFrameTime().count() == 1200);
REQUIRE(x.GetImageCountTime().count() == 950);
REQUIRE(x.GetSpotFindingPeriod().count() == 2000);
REQUIRE(x.GetPreviewPeriod().count() == 1000*1000);
}