Files
Jungfraujoch/tests/JFJochBrokerParserTest.cpp

211 lines
6.8 KiB
C++

// Copyright (2019-2023) Paul Scherrer Institute
#include <catch2/catch_all.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));
DetectorGeometry geom = ParseDetectorGeometry(j);
REQUIRE(geom.GetWidth() == 10 * 2 + 1030 * 3);
REQUIRE(geom.GetHeight() == 20 * 5 + 514 * 6);
REQUIRE(geom.GetModulesNum() == 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));
DetectorGeometry geom = ParseDetectorGeometry(j);
REQUIRE(geom.GetWidth() == 2000);
REQUIRE(geom.GetHeight() == 2000);
REQUIRE(geom.GetModulesNum() == 2);
REQUIRE(geom.GetPixel0(0) == 0);
REQUIRE(geom.GetFastDirectionStep(0) == 1);
REQUIRE(geom.GetSlowDirectionStep(0) == geom.GetWidth());
REQUIRE(geom.GetPixel0(1) == 2000*geom.GetWidth()-1);
REQUIRE(geom.GetFastDirectionStep(1) == -geom.GetWidth());
REQUIRE(geom.GetSlowDirectionStep(1) == -1);
}
TEST_CASE("JFJochBrokerParser_DetectorGeometry_custom_detector_mirror_y") {
nlohmann::json j = R"(
{
"custom_geometry": [
{"x0": 0, "y0": 0, "fast_axis":"Xp", "slow_axis":"Yp"},
{"x0": 1799, "y0": 1999, "fast_axis":"Yn", "slow_axis":"Xn"}
],
"custom_geometry_mirror_y": true
}
)"_json;
REQUIRE_NOTHROW(ParseDetectorGeometry(j));
DetectorGeometry geom = ParseDetectorGeometry(j);
REQUIRE(geom.GetWidth() == 1800);
REQUIRE(geom.GetHeight() == 2000);
REQUIRE(geom.GetModulesNum() == 2);
REQUIRE(geom.GetPixel0(0) == 1999 * geom.GetWidth());
REQUIRE(geom.GetFastDirectionStep(0) == 1);
REQUIRE(geom.GetSlowDirectionStep(0) == -geom.GetWidth());
REQUIRE(geom.GetPixel0(1) == 1799);
REQUIRE(geom.GetFastDirectionStep(1) == geom.GetWidth());
REQUIRE(geom.GetSlowDirectionStep(1) == -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",
"udp_interface_count": 1,
"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);
REQUIRE(detector.GetGeometry().GetWidth() == 1030 * 2 + 10);
REQUIRE(detector.GetGeometry().GetHeight() == 20 * 1 + 514 * 2);
REQUIRE(detector.GetGeometry().GetModulesNum() == 4);
REQUIRE(detector.GetDescription() == "PSI JUNGFRAU 2M");
REQUIRE(detector.GetDetectorModuleHostname().size() == 4);
REQUIRE(detector.GetDetectorModuleHostname()[2] == "mx3");
REQUIRE(detector.GetGainCalibration().size() == 4);
REQUIRE(detector.GetUDPInterfaceCount() == 1);
}
TEST_CASE("JFJochBrokerParser_DetectorType_implicit") {
nlohmann::json j = R"(
{
"standard_geometry": {
"nmodules": 4,
"horizontal_stacking": 2,
"gap_x": 10,
"gap_y": 20,
"mirror_y": false
},
"description": "PSI JUNGFRAU 2M",
"udp_interface_count": 1,
"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);
REQUIRE(detector.GetDetectorType() == DetectorType::JUNGFRAU);
}
TEST_CASE("JFJochBrokerParser_DetectorType_EIGER") {
nlohmann::json j = R"(
{
"standard_geometry": {
"nmodules": 4,
"horizontal_stacking": 2,
"gap_x": 10,
"gap_y": 20,
"mirror_y": false
},
"description": "PSI JUNGFRAU 2M",
"udp_interface_count": 1,
"module_hostname": ["mx1", "mx2", "mx3", "mx4", "mx5", "mx6", "mx7", "mx8"],
"trim_files": ["a","b","c","d","e","f","g","h"],
"type": "eiger"
}
)"_json;
REQUIRE_NOTHROW(ParseDetectorSetup(j));
auto detector = ParseDetectorSetup(j);
REQUIRE(detector.GetDetectorType() == DetectorType::EIGER);
}
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",
"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.GetPedestalG0Frames() == 5000);
REQUIRE(x.GetPedestalG1Frames() == 333);
REQUIRE(x.GetPedestalG2Frames() == 333);
REQUIRE(x.GetFrameTime().count() == 1200);
REQUIRE(x.GetImageCountTime().count() == 950);
REQUIRE(x.GetPreviewPeriod().count() == 1000*1000);
}