Files
slsDetectorPackage/slsDetectorSoftware/tests/Caller/test-Caller-jungfrau.cpp
AliceMazzoleni99 28b2aa9673
All checks were successful
Build on RHEL9 / build (push) Successful in 3m50s
Build on RHEL8 / build (push) Successful in 4m46s
Run Simulator Tests on local RHEL9 / build (push) Successful in 14m37s
Build on local RHEL9 / build (push) Successful in 1m26s
Run Simulator Tests on local RHEL8 / build (push) Successful in 16m57s
Build on local RHEL8 / build (push) Successful in 3m33s
Dev/add simulator tests in GitHub workflows (#1337)
* added simulator tests in github workflows

* indentation error

* typo

* debug

* Logging for debugging

* added more debug lines

* more debugging

* debug

* debug

* debug

* dont throw if process does not exist

* debug

* added absolute path to sls_detector commands

* some refactoring in test scripts

* added absolute path to all slsdet command

* typo

* ../tests/scripts/test_frame_synchronizer.py

* raise exception upon failure for github workflows

* removed hidden tags

* some refactoring in test scripts

* some refactoring

* fixed CMakeLists

* fixed unsuccesful merge

* updated python tests using simulators

* debug import error

* debug module import

* python -m runs module pytest as script - everything in path available

* removed integartion tests

* enable file write not to log files

* run tests without log files

* increased sleep time for udp packets

* added logg level variable to cmake

* added testing policies to documenattion

* disabled check for num_frames for jungfrau & xilinx

* set log level as cmake cached variable

* disable tests for jungfrau and xilinx_ctb

* check frames for HDF5

* updated Documentation of Testing

* changed withdetectorsimulators to detectorintegration

* replaced [.cmdcall] with [.detectorintegration]

* check_file_size only disabled for jungfrau - disable for all roi tests

* changed time to wait after receive to 5 ms

* take into account half modules of eiger

* num udp interfaces needs to be consistent across modules

* suppressed warning enclosing if

* config added 2 udp ports per default for moench and jungfrau

* write detector output to console

* allow jungfrau to tests num frames, remove unused variable (numinterfaces), add comment for future to handle traceback to know which calling function threw the files unmatched, added documentation for tests (examples for .detectoritnegration and how to disable marked tests, removed addditional argumetns to disable for test_simulator as one can just use ~, removed the check that checks for jungfrau checking number of frames at master attributes and at rx test, removed unused advanced_test_settings in test_simulator script, the num_mods check for multiple modules is removed and default num  modules set to 1 for test_simulator (to be increased later), back to raising exception for killprocess

* removed integration tests from cmakelists.txt and cmk.sh, modified the tests workflow command to reflect the disable argument and removed xilinx_ctb from test (fix fromdeveloper merge to be done)

* filtering by actual name for disable certain tests on github workflow

* minor refactor

* wip

* wip

* changes to run on local rh9 runner instead of github workfloa

* modified yml to remove some leftover from github workflow

* test

* fix build_dir in scripts (github workflow) and pytest dir in gitea workflow

* making the local machine use python3.13 binary

* pythonpath added

* changes for build_Dir back

* allowing ctb api tests

* allowed ctb api tests and set up slsdetname envt variable for shared memory being reserved just for these tests

* added rh8 workflow for local runner on gitea

* remnants from rh9 local runner

* remnants from rh9 local runner

* conda env for all shell for local runner

* allowing hdf5 to build on local runner

* run all tests for both the runners

* refactored fixtures a bit and merged some tests that use one session for entire server

* test fail

* test fix

* adding github workflow to test without data file checks and without logs

* documentation changes

* unnecessary import in conftest

* allowing the session_simulator to test for multiple modules and interfaces etc

* allow test_simulator script to run for 2 modules for all modules except ctb and xilinx ctb

* run upon push

* removing the disable file check on github workflow

* minor adjustment

* testing without synch

* reverting to previous

* with log file

* without the space

* summary from file and more error extracts from file to terminal

* minor

* trying nlf for more details

* updated with no log file to print everything to screen  also for det and rxr

* trying a no throw

* stoi was more about indent in yaml

* tries

* wip

* debug

* number of frames inconsistent fix=>just take first one, only test xilinx

* jungfrau tests without frames caught check

* extend the disable file check to everywhere that creates files

* specify path for test_simulator

* withoutprinting ==

* wip

* back with printing===, but not parsing file for errors anymore

* lang?

* wip

* safe log?

* wip2

* wip

* dont split error as its streaming live, just raise

* with log files

* lang?

* last resort

* wip

* test no det with general tests

* show tests live

* also include hidden integration tests

* without extra summary?

* revert

* last resort again

* tsquash on int64_t?

* tsquash on int64_t? mroe print

* writing to /tmp?

* all tests

* might be the fix?

* write to file

* fixed a few quiet mode no log file tests

* work on any branch for github tests, work on also release candidates for gitea tests

* added frame synchronizer tests to github workflow

* moved tests to run_tests.yaml from cmake.yaml

* documentation

* disabled general tests

---------

Co-authored-by: Dhanya Thattil <dhanya.thattil@psi.ch>
2026-02-03 11:45:12 +01:00

798 lines
30 KiB
C++

// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#include "Caller.h"
#include "catch.hpp"
#include "sls/Detector.h"
#include "sls/sls_detector_defs.h"
#include <sstream>
#include "sls/versionAPI.h"
#include "test-Caller-global.h"
#include "tests/globals.h"
namespace sls {
using test::GET;
using test::PUT;
/* dacs */
TEST_CASE("Setting and reading back Jungfrau dacs",
"[.detectorintegration][.dacs]") {
// vb_comp, vdd_prot, vin_com, vref_prech, vb_pixbuf, vb_ds, vref_ds,
// vref_comp
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
SECTION("vb_comp") { test_dac_caller(defs::VB_COMP, "vb_comp", 1220); }
SECTION("vdd_prot") {
test_dac_caller(defs::VDD_PROT, "vdd_prot", 3000);
}
SECTION("vin_com") { test_dac_caller(defs::VIN_COM, "vin_com", 1053); }
SECTION("vref_prech") {
test_dac_caller(defs::VREF_PRECH, "vref_prech", 1450);
}
SECTION("vb_pixbuf") {
test_dac_caller(defs::VB_PIXBUF, "vb_pixbuf", 750);
}
SECTION("vb_ds") { test_dac_caller(defs::VB_DS, "vb_ds", 1000); }
SECTION("vref_ds") { test_dac_caller(defs::VREF_DS, "vref_ds", 480); }
SECTION("vref_comp") {
test_dac_caller(defs::VREF_COMP, "vref_comp", 420);
}
// eiger
REQUIRE_THROWS(caller.call("vthreshold", {}, -1, GET));
REQUIRE_THROWS(caller.call("vsvp", {}, -1, GET));
REQUIRE_THROWS(caller.call("vsvn", {}, -1, GET));
REQUIRE_THROWS(caller.call("vtrim", {}, -1, GET));
REQUIRE_THROWS(caller.call("vrpreamp", {}, -1, GET));
REQUIRE_THROWS(caller.call("vrshaper", {}, -1, GET));
REQUIRE_THROWS(caller.call("vtgstv", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcmp_ll", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcmp_lr", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcal", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcmp_rl", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcmp_rr", {}, -1, GET));
REQUIRE_THROWS(caller.call("rxb_rb", {}, -1, GET));
REQUIRE_THROWS(caller.call("rxb_lb", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcp", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcn", {}, -1, GET));
REQUIRE_THROWS(caller.call("vishaper", {}, -1, GET));
REQUIRE_THROWS(caller.call("iodelay", {}, -1, GET));
// mythen3
REQUIRE_THROWS(caller.call("vrpreamp", {}, -1, GET));
REQUIRE_THROWS(caller.call("vrshaper", {}, -1, GET));
REQUIRE_THROWS(caller.call("vrshaper_n", {}, -1, GET));
REQUIRE_THROWS(caller.call("vipre", {}, -1, GET));
REQUIRE_THROWS(caller.call("vishaper", {}, -1, GET));
REQUIRE_THROWS(caller.call("vdcsh", {}, -1, GET));
REQUIRE_THROWS(caller.call("vth1", {}, -1, GET));
REQUIRE_THROWS(caller.call("vth2", {}, -1, GET));
REQUIRE_THROWS(caller.call("vth3", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcal_n", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcal_p", {}, -1, GET));
REQUIRE_THROWS(caller.call("vtrim", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcassh", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcas", {}, -1, GET));
REQUIRE_THROWS(caller.call("vicin", {}, -1, GET));
REQUIRE_THROWS(caller.call("vipre_out", {}, -1, GET));
// gotthard2
REQUIRE_THROWS(caller.call("vref_h_adc", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_comp_fe", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_comp_adc", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcom_cds", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_rstore", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_opa_1st", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_comp_fe", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcom_adc1", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_l_adc", {}, -1, GET));
REQUIRE_THROWS(caller.call("vref_cds", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_cs", {}, -1, GET));
REQUIRE_THROWS(caller.call("vb_opa_fd", {}, -1, GET));
REQUIRE_THROWS(caller.call("vcom_adc2", {}, -1, GET));
}
}
/* Network Configuration (Detector<->Receiver) */
TEST_CASE("selinterface", "[.detectorintegration]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) {
auto prev_val = det.getSelectedUDPInterface().tsquash(
"inconsistent selected interface to test");
{
std::ostringstream oss;
caller.call("selinterface", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "selinterface 1\n");
}
{
std::ostringstream oss;
caller.call("selinterface", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "selinterface 0\n");
}
{
std::ostringstream oss;
caller.call("selinterface", {}, -1, GET, oss);
REQUIRE(oss.str() == "selinterface 0\n");
}
det.selectUDPInterface(prev_val);
REQUIRE_THROWS(caller.call("selinterface", {"2"}, -1, PUT));
} else {
REQUIRE_THROWS(caller.call("selinterface", {}, -1, GET));
}
}
/* Jungfrau/moench Specific */
TEST_CASE("temp_threshold", "[.detectorintegration]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) {
auto prev_val = det.getThresholdTemperature();
{
std::ostringstream oss;
caller.call("temp_threshold", {"65"}, -1, PUT, oss);
REQUIRE(oss.str() == "temp_threshold 65\n");
}
{
std::ostringstream oss;
caller.call("temp_threshold", {"70"}, -1, PUT, oss);
REQUIRE(oss.str() == "temp_threshold 70\n");
}
{
std::ostringstream oss;
caller.call("temp_threshold", {}, -1, GET, oss);
REQUIRE(oss.str() == "temp_threshold 70\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setThresholdTemperature(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("temp_threshold", {}, -1, GET));
REQUIRE_THROWS(caller.call("temp_threshold", {"70"}, -1, PUT));
}
}
TEST_CASE("chipversion", "[.detectorintegration]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
REQUIRE_NOTHROW(caller.call("chipversion", {}, -1, GET));
} else {
REQUIRE_THROWS(caller.call("chipversion", {}, -1, GET));
}
REQUIRE_THROWS(caller.call("chipversion", {"0"}, -1, PUT));
}
TEST_CASE("temp_control", "[.detectorintegration]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) {
auto prev_val = det.getTemperatureControl();
{
std::ostringstream oss;
caller.call("temp_control", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "temp_control 0\n");
}
{
std::ostringstream oss;
caller.call("temp_control", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "temp_control 1\n");
}
{
std::ostringstream oss;
caller.call("temp_control", {}, -1, GET, oss);
REQUIRE(oss.str() == "temp_control 1\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setTemperatureControl(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("temp_control", {}, -1, GET));
REQUIRE_THROWS(caller.call("temp_control", {"0"}, -1, PUT));
}
}
TEST_CASE("temp_event", "[.detectorintegration]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) {
{
std::ostringstream oss;
caller.call("temp_event", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "temp_event cleared\n");
}
{
std::ostringstream oss;
caller.call("temp_event", {}, -1, GET, oss);
REQUIRE(oss.str() == "temp_event 0\n");
}
} else {
REQUIRE_THROWS(caller.call("temp_event", {}, -1, GET));
REQUIRE_THROWS(caller.call("temp_event", {"0"}, -1, PUT));
}
}
TEST_CASE("autocompdisable", "[.detectorintegration]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
auto prev_val = det.getAutoComparatorDisable();
{
std::ostringstream oss;
caller.call("autocompdisable", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "autocompdisable 0\n");
}
{
std::ostringstream oss;
caller.call("autocompdisable", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "autocompdisable 1\n");
}
{
std::ostringstream oss;
caller.call("autocompdisable", {}, -1, GET, oss);
REQUIRE(oss.str() == "autocompdisable 1\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setAutoComparatorDisable(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("autocompdisable", {}, -1, GET));
REQUIRE_THROWS(caller.call("autocompdisable", {"0"}, -1, PUT));
}
}
TEST_CASE("compdisabletime", "[.detectorintegration]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
auto prev_val = det.getComparatorDisableTime();
{
std::ostringstream oss;
caller.call("compdisabletime", {"125ns"}, -1, PUT, oss);
REQUIRE(oss.str() == "compdisabletime 125ns\n");
}
{
std::ostringstream oss;
caller.call("compdisabletime", {}, -1, GET, oss);
REQUIRE(oss.str() == "compdisabletime 125ns\n");
}
{
std::ostringstream oss;
caller.call("compdisabletime", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "compdisabletime 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setComparatorDisableTime(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("compdisabletime", {}, -1, GET));
REQUIRE_THROWS(caller.call("compdisabletime", {"0"}, -1, PUT));
}
}
TEST_CASE("extrastoragecells", "[.detectorintegration]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
// chip version 1.0
if (det.getChipVersion().squash() * 10 == 10) {
auto prev_val = det.getNumberOfAdditionalStorageCells().tsquash(
"inconsistent #additional storage cells to test");
{
std::ostringstream oss;
caller.call("extrastoragecells", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "extrastoragecells 1\n");
}
{
std::ostringstream oss;
caller.call("extrastoragecells", {"15"}, -1, PUT, oss);
REQUIRE(oss.str() == "extrastoragecells 15\n");
}
{
std::ostringstream oss;
caller.call("extrastoragecells", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "extrastoragecells 0\n");
}
{
std::ostringstream oss;
caller.call("extrastoragecells", {}, -1, GET, oss);
REQUIRE(oss.str() == "extrastoragecells 0\n");
}
REQUIRE_THROWS(caller.call("extrastoragecells", {"16"}, -1, PUT));
det.setNumberOfAdditionalStorageCells(prev_val);
}
// chip version 1.1
else {
// cannot set number of addl. storage cells
REQUIRE_THROWS(caller.call("extrastoragecells", {"1"}, -1, PUT));
}
} else {
REQUIRE_THROWS(caller.call("extrastoragecells", {}, -1, GET));
REQUIRE_THROWS(caller.call("extrastoragecells", {"0"}, -1, PUT));
}
}
TEST_CASE("storagecell_start", "[.detectorintegration]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
auto prev_val = det.getStorageCellStart();
{
std::ostringstream oss;
caller.call("storagecell_start", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "storagecell_start 1\n");
}
// chip version 1.0
if (det.getChipVersion().squash() * 10 == 10) {
std::ostringstream oss;
caller.call("storagecell_start", {"15"}, -1, PUT, oss);
REQUIRE(oss.str() == "storagecell_start 15\n");
}
// chip version 1.1
else {
// max is 3
REQUIRE_THROWS(caller.call("storagecell_start", {"15"}, -1, PUT));
std::ostringstream oss;
caller.call("storagecell_start", {"3"}, -1, PUT, oss);
REQUIRE(oss.str() == "storagecell_start 3\n");
}
{
std::ostringstream oss;
caller.call("storagecell_start", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "storagecell_start 0\n");
}
{
std::ostringstream oss;
caller.call("storagecell_start", {}, -1, GET, oss);
REQUIRE(oss.str() == "storagecell_start 0\n");
}
REQUIRE_THROWS(caller.call("storagecell_start", {"16"}, -1, PUT));
for (int i = 0; i != det.size(); ++i) {
det.setStorageCellStart(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("storagecell_start", {}, -1, GET));
REQUIRE_THROWS(caller.call("storagecell_start", {"0"}, -1, PUT));
}
}
TEST_CASE("storagecell_delay", "[.detectorintegration]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
// chip version 1.0
if (det.getChipVersion().squash() * 10 == 10) {
auto prev_val = det.getStorageCellDelay();
{
std::ostringstream oss;
caller.call("storagecell_delay", {"1.62ms"}, -1, PUT, oss);
REQUIRE(oss.str() == "storagecell_delay 1.62ms\n");
}
{
std::ostringstream oss;
caller.call("storagecell_delay", {}, -1, GET, oss);
REQUIRE(oss.str() == "storagecell_delay 1.62ms\n");
}
{
std::ostringstream oss;
caller.call("storagecell_delay", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "storagecell_delay 0\n");
}
REQUIRE_THROWS(
caller.call("storagecell_delay", {"1638376ns"}, -1, PUT));
for (int i = 0; i != det.size(); ++i) {
det.setStorageCellDelay(prev_val[i], {i});
}
}
// chip version 1.1
else {
// cannot set storage cell delay
REQUIRE_THROWS(
caller.call("storagecell_delay", {"1.62ms"}, -1, PUT));
}
} else {
REQUIRE_THROWS(caller.call("storagecell_delay", {}, -1, GET));
REQUIRE_THROWS(caller.call("storagecell_delay", {"0"}, -1, PUT));
}
}
TEST_CASE("gainmode", "[.detectorintegration]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
auto prev_val = det.getGainMode();
{
std::ostringstream oss;
caller.call("gainmode", {"forceswitchg1"}, -1, PUT, oss);
REQUIRE(oss.str() == "gainmode forceswitchg1\n");
}
{
std::ostringstream oss;
caller.call("gainmode", {}, -1, GET, oss);
REQUIRE(oss.str() == "gainmode forceswitchg1\n");
}
{
std::ostringstream oss;
caller.call("gainmode", {"dynamic"}, -1, PUT, oss);
REQUIRE(oss.str() == "gainmode dynamic\n");
}
{
std::ostringstream oss;
caller.call("gainmode", {"forceswitchg2"}, -1, PUT, oss);
REQUIRE(oss.str() == "gainmode forceswitchg2\n");
}
{
std::ostringstream oss;
caller.call("gainmode", {"fixg1"}, -1, PUT, oss);
REQUIRE(oss.str() == "gainmode fixg1\n");
}
{
std::ostringstream oss;
caller.call("gainmode", {"fixg2"}, -1, PUT, oss);
REQUIRE(oss.str() == "gainmode fixg2\n");
}
{
std::ostringstream oss;
caller.call("gainmode", {"fixg0"}, -1, PUT, oss);
REQUIRE(oss.str() == "gainmode fixg0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setGainMode(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("gainmode", {}, -1, GET));
}
}
TEST_CASE("filtercells", "[.detectorintegration]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
// chip version 1.1
if (det.getChipVersion().squash() * 10 == 11) {
auto prev_val = det.getNumberOfFilterCells();
{
std::ostringstream oss;
caller.call("filtercells", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "filtercells 1\n");
}
{
std::ostringstream oss;
caller.call("filtercells", {"12"}, -1, PUT, oss);
REQUIRE(oss.str() == "filtercells 12\n");
}
{
std::ostringstream oss;
caller.call("filtercells", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "filtercells 0\n");
}
{
std::ostringstream oss;
caller.call("filtercells", {}, -1, GET, oss);
REQUIRE(oss.str() == "filtercells 0\n");
}
REQUIRE_THROWS(caller.call("filtercells", {"13"}, -1, PUT));
for (int i = 0; i != det.size(); ++i) {
det.setNumberOfFilterCells(prev_val[i], {i});
}
}
// chip version 1.0
else {
// cannot set/get filter cell
REQUIRE_THROWS(caller.call("filtercells", {"1"}, -1, PUT));
REQUIRE_THROWS(caller.call("filtercells", {}, -1, GET));
}
} else {
REQUIRE_THROWS(caller.call("filtercells", {}, -1, GET));
REQUIRE_THROWS(caller.call("filtercells", {"0"}, -1, PUT));
}
}
TEST_CASE("pedestalmode", "[.detectorintegration]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
auto prev_val = det.getPedestalMode();
auto prev_frames = det.getNumberOfFrames().tsquash(
"Inconsistent number of frames to test");
auto prev_triggers = det.getNumberOfTriggers().tsquash(
"Inconsistent number of triggers to test");
auto prev_timingmode =
det.getTimingMode().tsquash("Inconsistent timing mode to test");
REQUIRE_NOTHROW(caller.call("pedestalmode", {}, 0, GET));
REQUIRE_NOTHROW(caller.call("pedestalmode", {}, -1, GET));
REQUIRE_THROWS(caller.call("pedestalmode", {"0"}, -1, GET));
REQUIRE_THROWS(caller.call("pedestalmode", {"256", "10"}, -1, PUT));
REQUIRE_THROWS(caller.call("pedestalmode", {"-1", "10"}, 0, PUT));
REQUIRE_THROWS(caller.call("pedestalmode", {"20", "1000"}, 0, PUT));
REQUIRE_THROWS(caller.call("pedestalmode", {"2000", "100"}, 0, PUT));
REQUIRE_THROWS(caller.call("pedestalmode", {"20", "-1"}, 0, PUT));
{
std::ostringstream oss;
caller.call("pedestalmode", {"30", "100"}, -1, PUT, oss);
REQUIRE(oss.str() == "pedestalmode [30, 100]\n");
}
// cannot change any of these in pedestal mode
REQUIRE_THROWS_WITH(caller.call("frames", {"200"}, -1, PUT),
"Detector returned: Cannot set frames in pedestal "
"mode. It is overwritten anyway.\n");
REQUIRE_THROWS_WITH(caller.call("triggers", {"200"}, -1, PUT),
"Detector returned: Cannot set triggers in "
"pedestal mode. It is overwritten anyway.\n");
REQUIRE_THROWS_WITH(
caller.call("timing", {"auto"}, -1, PUT),
"Detector returned: Cannot set timing mode in pedestal mode. "
"Switch off pedestal mode to change timing mode.\n");
REQUIRE_THROWS_WITH(
caller.call("scan", {"vb_comp", "500", "1500", "10"}, -1, PUT),
"Detector returned: Cannot set scan when in pedestal mode.\n");
REQUIRE_THROWS_WITH(
caller.call("scan", {"0"}, -1, PUT),
"Detector returned: Cannot set scan when in pedestal mode.\n");
// should not throw to get these values though
REQUIRE_NOTHROW(caller.call("frames", {}, -1, GET));
REQUIRE_NOTHROW(caller.call("triggers", {}, -1, GET));
REQUIRE_NOTHROW(caller.call("timing", {}, -1, GET));
REQUIRE_NOTHROW(caller.call("scan", {}, -1, GET));
{
std::ostringstream oss;
caller.call("pedestalmode", {"50", "100"}, -1, PUT, oss);
REQUIRE(oss.str() == "pedestalmode [50, 100]\n");
}
{
std::ostringstream oss;
caller.call("pedestalmode", {}, -1, GET, oss);
REQUIRE(oss.str() == "pedestalmode [enabled, 50, 100]\n");
}
{
auto pedemode = det.getPedestalMode().tsquash(
"Inconsistent pedestal mode to test");
REQUIRE(pedemode.enable == true);
REQUIRE(pedemode.frames == 50);
REQUIRE(pedemode.loops == 100);
}
{
std::ostringstream oss;
caller.call("pedestalmode", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "pedestalmode [0]\n");
}
{
std::ostringstream oss;
caller.call("pedestalmode", {}, -1, GET, oss);
REQUIRE(oss.str() == "pedestalmode [disabled]\n");
}
uint8_t pedestalFrames = 50;
uint16_t pedestalLoops = 100;
int64_t expNumFrames = pedestalFrames * pedestalLoops * 2;
auto origFrames = det.getNumberOfFrames().squash(-1);
auto origTriggers = det.getNumberOfTriggers().squash(-1);
// auto mode
det.setTimingMode(defs::AUTO_TIMING);
REQUIRE_NOTHROW(caller.call(
"pedestalmode",
{std::to_string(pedestalFrames), std::to_string(pedestalLoops)}, -1,
PUT));
auto numTriggers = det.getNumberOfTriggers().squash(-1);
auto numFrames = det.getNumberOfFrames().squash(-1);
REQUIRE(numFrames == expNumFrames);
REQUIRE(numTriggers == 1);
// pedestal mode off
REQUIRE_NOTHROW(caller.call("pedestalmode", {"0"}, -1, PUT));
numTriggers = det.getNumberOfTriggers().squash(-1);
numFrames = det.getNumberOfFrames().squash(-1);
REQUIRE(numFrames == origFrames);
REQUIRE(numTriggers == origTriggers);
// trigger mode (frames > 1)
REQUIRE_NOTHROW(det.setTimingMode(defs::TRIGGER_EXPOSURE));
origFrames = 5;
REQUIRE_NOTHROW(det.setNumberOfFrames(origFrames));
REQUIRE_NOTHROW(caller.call(
"pedestalmode",
{std::to_string(pedestalFrames), std::to_string(pedestalLoops)}, -1,
PUT));
numTriggers = det.getNumberOfTriggers().squash(-1);
numFrames = det.getNumberOfFrames().squash(-1);
REQUIRE(numFrames == expNumFrames);
REQUIRE(numTriggers == 1);
// pedestal mode off
REQUIRE_NOTHROW(caller.call("pedestalmode", {"0"}, -1, PUT));
numTriggers = det.getNumberOfTriggers().squash(-1);
numFrames = det.getNumberOfFrames().squash(-1);
REQUIRE(numFrames == origFrames);
REQUIRE(numTriggers == origTriggers);
// trigger mode (frames = 1)
origFrames = 1;
REQUIRE_NOTHROW(det.setNumberOfFrames(origFrames));
origTriggers = 10;
REQUIRE_NOTHROW(det.setNumberOfTriggers(origTriggers));
REQUIRE_NOTHROW(caller.call(
"pedestalmode",
{std::to_string(pedestalFrames), std::to_string(pedestalLoops)}, -1,
PUT));
numTriggers = det.getNumberOfTriggers().squash(-1);
numFrames = det.getNumberOfFrames().squash(-1);
REQUIRE(numFrames == 1);
REQUIRE(numTriggers == expNumFrames);
// pedestal mode off
REQUIRE_NOTHROW(caller.call("pedestalmode", {"0"}, -1, PUT));
numTriggers = det.getNumberOfTriggers().squash(-1);
numFrames = det.getNumberOfFrames().squash(-1);
REQUIRE(numFrames == origFrames);
REQUIRE(numTriggers == origTriggers);
det.setNumberOfFrames(prev_frames);
det.setNumberOfTriggers(prev_triggers);
det.setTimingMode(prev_timingmode);
for (int i = 0; i != det.size(); ++i) {
det.setPedestalMode(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("pedestalmode", {}, -1, GET));
REQUIRE_THROWS(caller.call("pedestalmode", {"0"}, -1, PUT));
}
}
TEST_CASE("timing_info_decoder", "[.detectorintegration]") {
Detector det;
Caller caller(&det);
if (det.getDetectorType().squash() == defs::JUNGFRAU &&
det.getHardwareVersion().squash() == "2.0") {
auto prev_val = det.getTimingInfoDecoder();
/*{
std::ostringstream oss;
caller.call("timing_info_decoder", {"shine"}, -1, PUT, oss);
REQUIRE(oss.str() == "timing_info_decoder shine\n");
}*/
{
std::ostringstream oss;
caller.call("timing_info_decoder", {"swissfel"}, -1, PUT, oss);
REQUIRE(oss.str() == "timing_info_decoder swissfel\n");
}
{
std::ostringstream oss;
caller.call("timing_info_decoder", {}, -1, GET, oss);
REQUIRE(oss.str() == "timing_info_decoder swissfel\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setTimingInfoDecoder(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("timing_info_decoder", {}, -1, GET));
}
}
TEST_CASE("collectionmode", "[.detectorintegration]") {
Detector det;
Caller caller(&det);
if (det.getDetectorType().squash() == defs::JUNGFRAU) {
auto prev_val = det.getCollectionMode();
{
std::ostringstream oss;
caller.call("collectionmode", {"electron"}, -1, PUT, oss);
REQUIRE(oss.str() == "collectionmode electron\n");
}
{
std::ostringstream oss;
caller.call("collectionmode", {"hole"}, -1, PUT, oss);
REQUIRE(oss.str() == "collectionmode hole\n");
}
{
std::ostringstream oss;
caller.call("collectionmode", {}, -1, GET, oss);
REQUIRE(oss.str() == "collectionmode hole\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setCollectionMode(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(caller.call("collectionmode", {}, -1, GET));
}
}
TEST_CASE("sync", "[.detectorintegration]") {
Detector det;
Caller caller(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU || det_type == defs::MOENCH) {
auto prev_val = det.getSynchronization().tsquash(
"inconsistent synchronization to test");
{
std::ostringstream oss;
caller.call("sync", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "sync 0\n");
}
{
std::ostringstream oss;
caller.call("sync", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "sync 1\n");
}
// setting to master or slave when synced
{
// get previous master
int prevMaster = 0;
auto previous = det.getMaster();
for (int i = 0; i != det.size(); ++i) {
if (previous[i] == 1) {
prevMaster = i;
break;
}
}
caller.call("master", {"1"}, 0, PUT);
caller.call("master", {"0"}, 0, PUT);
std::ostringstream oss;
caller.call("status", {}, -1, GET, oss);
REQUIRE(oss.str() != "status running\n");
// set all to slaves, and then master
for (int i = 0; i != det.size(); ++i) {
det.setMaster(0, {i});
}
det.setMaster(1, prevMaster);
}
{
std::ostringstream oss;
caller.call("sync", {}, -1, GET, oss);
REQUIRE(oss.str() == "sync 1\n");
}
// setting sync when running
{
auto prev_timing =
det.getTimingMode().tsquash("inconsistent timing mode in test");
auto prev_frames =
det.getNumberOfFrames().tsquash("inconsistent #frames in test");
auto prev_exptime =
det.getExptime().tsquash("inconsistent exptime in test");
auto prev_period =
det.getPeriod().tsquash("inconsistent period in test");
det.setTimingMode(defs::AUTO_TIMING);
det.setNumberOfFrames(10000);
det.setExptime(std::chrono::microseconds(200));
det.setPeriod(std::chrono::milliseconds(1000));
det.setSynchronization(1);
det.startDetector();
REQUIRE_THROWS(caller.call("sync", {"0"}, -1, PUT));
{
std::ostringstream oss;
caller.call("sync", {}, -1, GET, oss);
REQUIRE(oss.str() == "sync 1\n");
}
det.stopDetector();
det.setTimingMode(prev_timing);
det.setNumberOfFrames(prev_frames);
det.setExptime(prev_exptime);
det.setPeriod(prev_period);
}
det.setSynchronization(prev_val);
} else {
REQUIRE_THROWS(caller.call("sync", {}, -1, GET));
REQUIRE_THROWS(caller.call("sync", {"0"}, -1, PUT));
}
}
} // namespace sls