Files
slsDetectorPackage/slsDetectorSoftware/tests/Caller/test-Caller-master-attributes.cpp
Dhanya Thattil 54e4c46f02
Some checks failed
Build on RHEL9 / build (push) Failing after 4m23s
Build on RHEL8 / build (push) Failing after 4m58s
10.0.0.rc (#1260)
* alignedData now uses std::align_alloc

* imagedata is now allocated on the heap

* m3 server fix for trimbits and badchannels that are shifted by 1

* formatting

* binary in

* added check for proper memory allocation

* commenting out the example in receiver data call back changing size as it affects users using debugging mode to print out headers

* fixed warnings

* commenting out the example in receiver data call back changing size as it affects users using debugging mode to print out headers

* got rid of cast to uint64

* got rid of Reorder function

* added sanity check to only enable for chipttestboard and xilinx

* removed Gotthard stuff

* update the comment about how to modify data on a data call back from the receiver

* autogenerated commands and make format

* changed font size in GUI

* clang-format with clang-format version 17

* updated update_image_size in xilinx

* version number automated for python build

* mistakenly set version back to 0.0.0

* updated github workflow scripts to support automatic version numbering with environment variable

* managed to load VERSION file in yaml file - simplifies things

* saving changes in git workflow failed

* got typo in github workflow

* updatet regex pattern to support postfix

* normalized version to PEP 440 specification in update_version.py

* bug did not support version 0.0.0

* upgrading to c++17 from c++11 and patch command has to be found before applying patch on libzmq (#1195)

* Dev/allow localhost for virtual tests (#1190)

* remove the check for localhost being used in rx_hostname for python test for simulators, run rx_arping test only if hostname is not 'localhost'

* fix tests for fpath: cannot set back to empty anymore (empty is default)

* default rx_hostname arg = localhost, and default settings path =../../settingsdir

* changed virtual tests script for better printout on exceptions

* fix for catching generaltests exceptions and exiting instead of continuing

* fix minor

* fixed shared memeory tests to include current env and fixed prints for errors

---------

Co-authored-by: Erik Fröjdh <erik.frojdh@gmail.com>

* added regex pattern matching to version in toml file

* Dev/gitea docker (#1194)

* gitea workflows for RH8 and RH9
* using our docker images

* version now supports . before postfix

* rough draft of test acquire of all detectors for frames caught and file size. ctb not included yet

* moved dbitoffset, dbitreorder and dbitlist to GeneralData

* added error message on receiver side, throw error

* removed log as error already printed

* added tests to check file size and frames caught with an acquire (virtual) for every detector

* minor printout removed

* typo fixed

* removed minor printout

* incorrect counter mask tested

* fix 10g adc enable mask, switched with 1g

* fixed hardcoded values of nchip nchan etc from detPArameters

* fixed ctb tests, need to fix in develoepr (if digital modfe not enabled, should not take into accoutn dbitlist or dbitoffset or dbitreorder

* only reorder bits if some sort of digital readout mode enabled

* trying to fix acquire for xilinx

* fix for xilinx ctb virtual

* alloweing all tests

* typo

* fix for slsreceiver killed but complaining for virtual tests with script

* fixed bug found by @AliceMazzoleni99 that for ctb server is still shown in pgrep -f if xilinx server running, so now the pid is killed and looking for any DetectorServer_virtual instead. also reset color coding after Log

* check if process running for kill -9 slsReceiver fail

* removed -9 to kill with cleanup

* frame synchonrizer fixes: typo of iterator for loop and zmg_msg_t list cleaned up before sending multi part zmq; test written for the frame synchronizer, test_simulator.py rewritten for more robustness and refactoring commonality between both scripts

* better error messageS

* minor

* typo

* moving the erasure of the fnum to after sending the zmg packets and also deleteing all old frames when end of acquisition

* fix bug in blackfin read access to firmware registers

* updates api version based on version file & converted shell script files to python

* updated all makefiles

* refactoring code and compiling binary

* formatting

* rewrote end() for StaticVector

* rearranged receiver topics, differentiated btween receiver variants and added info about slsFrameSynchronizer

* typo

* minor aesthetics

* minor

* added extra fs link and fixed execute_program warning

* and now with link

* updating pmods

* adresses review comments

* dummy commit for versionAPI

* formatted and updated versionAPI.h

* added expat to host section

* updated documentation for pip installation as well

* Dev/add numpy  (#1227)

* added numpy dependency
* added build specifications for python version and platform

* updates files/variants for pmods for 9.2.0 (#1233)

* tests for bool in ToString/StringTo (#1230)

- Added tests for ToString/StringTo<bool>
- Added overload for ToString of bool (previously went through int)

* added docs for SLSDETNAME (#1228)

* added docs for SLSDETNAME

* clarification on hostname

* added examples on module index

* fixes

* fixed typo

* Dev/update test framesynchronizer (#1221)

* raise an exception if the pull socket python script had errors at startup (for eg if pyzmq was not installed)

* minor changes that got lost in the merge of automate_version_part 2 PR

---------

Co-authored-by: Erik Fröjdh <erik.frojdh@gmail.com>

* added workflow for python wheels

* wip

* formatting

* wip

* wip to parse vector of rois at command line

* wip

* first level test

* can get individual rois, but not connected to command yet

* rois shoudl work. left to implement tests for individual rois, create multiple datasets (1 for each roi) in the virutal data file. currently virutal dataset with roi is not implemented and a warning is given instead. wonder why since the inviduviaual roi files are clipped

* all tests pased

* minor

* fixed rx_roi for multi modules jungfrau , tests for eiger, multi modules jungfrau in x and 2 interfaces

* works for eiger as well

* switched to vector instead of std::array<ROI, 2>>, which prints extra [-1, -1] when theres only 1 udp interface

* wip

* fix for empty roi vectors (which shouldnt be) as you cant know if its all or not in roi

* wip: to map roi to virutal

* fix for eiger, added python test for testig roi in different module and detector type configurations

* wip, fails with master and virtual

* works for complete roi

* wip, works for a single roi

* works for all rois

* wip to fix tests

* 1d fixes

* rois test work on 1d as well

* check master file creation as well in rx_roi tests

* get rx_roi from metadata from rxr, cant reconstruct. fixed clear roi should give 1 roi min

* gui shows roi now

* format

* updated python bindings

* updated master file versions

* cmd generation and formatting

* minor fixes in command line and help

* minor

* doesnt happen anymore

* comment

* minor

* redundant getRxROI in Detector class for multi level and module level

* refactor cmd parsing (detid can be parsed directly)

* refactor cmd line

* refactor command line parsing of roi

* modified comments about ctb and xilinx not using roi

* refactoring

* refactorign

* refactoring wip

* wip refactoring

* formattin

* to avoid confusion, moved default initialized, single sized declared vector of roi to be created at setDetectorType

* pybind only 1 function for getRxROI

* command line help

* specified number of receiver error message

* minor comment

* refactored to take out repetitive code, need to adjust for slsMulti and slsFrameSync

* wip

* works, need to add tests

* made Commadnlineoptions into a class

* wip test

* fixed tests

* cleaning up properly , semaphore leaks, child process/thread throwing handled

* getuid issue on github workflow

* constexpr and checking if options object type is same

* unnecessary capture

* remove testing code, minor

* fixed help, -t for multi should not be supported as it never had it

* Formatting

* hdf5 definitions in test when not compiled with hdf5

* typo

* moved optstring and long options to the constructor

* raising a SIGINT when the child thread has an exception so that the parent thread can exit all the threads and clean up gracefully

* minor test typo

* check status of child exiting and use that to send sigint to all the child processes from the parent

* fixed validation in network_utils, added a tests to throw for port 65535 in test mode (option on for sls_use_tests), multi:parent process checks child process exit status to send sigint to others

* moving set signal handler to network utils

* readoutspeed in rx master file and  other master file inconsistencies (#1245)

readout speed added to json and h5 master files.
Also fixed master file inconsistencies

Sserver binaries
- update server binaries because readoutspeed needs to be sent to receiver with rx_hostname command

API
- added const to Detector class set/getburstmode

Python
- updated python bindings (burstmode const and roi arguments)

Cmd generation
- added pragma once in Caller.in.h as Caller is included in test files

m3: num channels due to #counters < 3
* workaround for m3 for messed up num channels (client always assumes all counters enabled and adds them to num channels), fix for hdf5

g2: exptime master file inconsistency
- exptime didnt match because of round of when setting burst mode (sets to a different clk divider)
- so updating actual time for all timers (exptime, period, subexptime etc, )  in Module class, get timer values from detector when setting it and then send to receiver to write in master file

ctb image size incorrect:
-  write actual size into master file and not the reserved size (digital reduces depending on dbit list and dbit offset)
- added a calculate ctb image size free function in generalData.h that is used there as well as for the tests.


master file inconsistencies
- refactored master attributes writing using templates
-    names changed to keep it consistent between json and hdf5 master file (Version, Pixels, Exposure Times, GateDelays, Acquisition Period, etc.)
-  datatypes changed to keep it simple where possible: imageSize, dynamicRange, tengiga, quad, readnrows, analog, analogsamples, digital, digitalsamples, dbitreorder, dbitoffset, transceivermask, transeiver, transceiversamples, countermask, gates =>int
- replacing "toString" with arrays, objects etc for eg for scan, rois, etc.
- json header always written (empty dataset or empty brackets)
- hdf5 needs const char* so have to convert strings to it, but taking care that strings exist prior to push_back
- master attributes (redundant string literals->error prone

tests for master file
- suppressed deprecated functions in rapidjson warnings just for the tests
- added slsREceiverSoftware/src to allow access to receiver_defs.h to test binary/hdf5 version
- refactored acquire tests by moving all the acquire tests from individual detector type files to a single one=test-Caller-acquire.cpp
- set some default settings (loadBasicSettings) for a basic acquire at load config part for the test_simulator python scripts. so minimum number of settings for detector to be set for any acquire tests.
- added tests to test master files for json and hdf5= test-Caller-master-attributes.cpp
- added option to add '-m' markers for tests using test_simulator python script

* doc: added inst on how to set persistentn NIC changes after reboot for each ethernet interface such as rx 4096, rx-usecs, adaptive-rx and gro etc.

* added permanent ethtool settings also for fedora or modern rhel

* troubleshooting doc: permanent changes for 10g pc tuning (#1247)

* doc: added inst on how to set persistentn NIC changes after reboot for each ethernet interface such as rx 4096, rx-usecs, adaptive-rx and gro etc.

* added permanent ethtool settings also for fedora or modern rhel

* ifcfg scripts still work on rhel8, just not preferred

* added dataformat for jungfrau

* eiger basic mod

* eiger doc done

* added moench

* done

* free shm exposed in python as free function and detector function

* minimum change

* added quad and updated about 1gbe/10gbe

* more info

* remove arguments info

* replacing commands with links

* minor

* detail explanation of eiger

* fixed imagesize ctb issue (out values not transferred, setting any dbit values was not recalculatign image size in generaldata)

* fixed ctb dbit clock changing period in tests as it was setting run clock instead

* python accessing freed shared memory object (#1253)

* added a 'isValid' member in shared memory (also updated shm version) with default true, any access to shared memory() checks also for validity. any free will set this to false and then unmap shm. Any access to shm will then check validity in python.

* fixed tests for shm

* added tests in python as well

---------

Co-authored-by: Alice <alice.mazzoleni@psi.ch>

* updated error message

* made markers argument in ParseArguments a boolean instead of an int

* removed relative path compared to where executable run in test script for settingsdir

* fix roi test

* updating versions (#1258)

* updating package version, client version, server versions. Renaming server versions, using hardlinks in serverBin. Removing ctb servers in serverBin. (#1259)

* fixed no interpolation mode for moench (#1262)

Co-authored-by: Anna Bergamaschi <anna.bergamaschi@psi.ch>

* fixed multi receiver and frames sync help throw of bad variant access (#1265)

* 1000/doc c standard (#1267)

* updated c++11 to c++17

* more about c++11 and updating readme

* updated documentation for receiver arguments and also making receiver constructor explicit

* minor fix for rxr err message

* fixed doc about gcc version

* 1000/release notes (#1269)

* updated firmware and server version in release notes

* release notes wip

* updated notes(prs done)

* updated release notes. wip

* Release notes

* minor

* minor fix

* 1000/doc architecture commands (#1271)

* sw architecture and setup commands

* 1000/shm free obsolete (#1273)

* freeing obsolete shm withoua a 'isValid' should access raw pointers. Need to move this all into the shm class

* fixed obsolete shm free issue

* minor

* ensuring the test works platform independent for size of int

* removed verify, update, fixed getUser to be a free function, generated commands, python bindings yet to do

* python bindings

* fixed tests

* minor

* minor

* format

* userdetails refinedg

* fixed caller test

* updated client api version (#1277)

* one doesnt need to open shared memory to call removesharedmemory, and calling hasMemoryvalid without opening will cause segfault (not used now, but could in the future)

* fix test on shm

* minor

* added image source files from draw.io to create the images (#1280)

* 1000/fix_actual_tests (#1282)

- fix acquire fail in tests (adcreg test)
- roi tests fail after overlapping invalid test and acquire after
- print udp dest mac in server properly
- fixed udp dst list get (server was not sending entry proper size to match proper struct size in client)
- updated server binaries and updated hard links in serverBin
- added documentation regarding gui:  zmqport and zmqip in terms of gui, rx_zmqstream
- removed print - probably ended there for debuggung

---------

Co-authored-by: Alice <alice.mazzoleni@psi.ch>

* 1000/fix_m3_tests (#1286)

* testing clkdiv one must ensure the exptime delay etc all are reset to the exact values for tests

* change dac max values for vth values for m3 in client side (set module

* 1000/doc_cmake (#1289)

* more detail documentation in installation

* more detail documentation in installation

* added links to api examples

* reverted back that vthreshold dacs in m3 have min and max as 200 and 2400 (#1294)

* update release notes and date (#1298)

---------

Co-authored-by: Mazzoleni Alice Francesca <mazzol_a@pc17378.psi.ch>
Co-authored-by: Erik Fröjdh <erik.frojdh@gmail.com>
Co-authored-by: AliceMazzoleni99 <alice.mazzoleni@psi.ch>
Co-authored-by: Martin Mueller <martin.mueller@psi.ch>
Co-authored-by: froejdh_e <erik.frojdh@psi.ch>
Co-authored-by: Anna Bergamaschi <anna.bergamaschi@psi.ch>
2025-09-10 11:13:36 +02:00

1085 lines
40 KiB
C++

// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#include "Caller.h"
#include "MasterAttributes.h"
#include "catch.hpp"
#include "receiver_defs.h"
#include "sls/Detector.h"
#include "sls/ToString.h"
#include "sls/logger.h"
#include "sls/sls_detector_defs.h"
#include "test-Caller-global.h"
#include "tests/globals.h"
#include <filesystem>
#include <fstream>
#include <rapidjson/document.h>
#include <rapidjson/error/en.h>
#include <sstream>
#include <string>
#ifdef HDF5C
#include "H5Cpp.h"
const std::string HDF5_GROUP = "/entry/instrument/detector/";
#endif
namespace sls {
using test::GET;
using test::PUT;
using namespace rapidjson;
inline bool operator==(sls::ns lhs, sls::ns rhs) {
return lhs.count() == rhs.count();
}
#ifdef HDF5C
std::optional<H5::H5File> h5File{};
#endif
/** std::string */
void read_from_json(const Document &doc, const std::string &name,
std::string &retval) {
retval = doc[name.c_str()].GetString();
}
#ifdef HDF5C
void read_from_h5_dataset(const H5::DataSet &dataset, const std::string &name,
std::string &retval) {
dataset.read(retval, dataset.getStrType());
}
#endif
/** int */
void read_from_json(const Document &doc, const std::string &name, int &retval) {
retval = doc[name.c_str()].GetInt();
}
#ifdef HDF5C
void read_from_h5_dataset(const H5::DataSet &dataset, const std::string &name,
int &retval) {
dataset.read(&retval, H5::PredType::NATIVE_INT);
}
#endif
/** uint64_t */
void read_from_json(const Document &doc, const std::string &name,
uint64_t &retval) {
retval = doc[name.c_str()].GetUint64();
}
#ifdef HDF5C
void read_from_h5_dataset(const H5::DataSet &dataset, const std::string &name,
uint64_t &retval) {
dataset.read(&retval, H5::PredType::STD_U64LE);
}
#endif
/** uint32_t */
void read_from_json(const Document &doc, const std::string &name,
uint32_t &retval) {
retval = doc[name.c_str()].GetUint();
}
#ifdef HDF5C
void read_from_h5_dataset(const H5::DataSet &dataset, const std::string &name,
uint32_t &retval) {
dataset.read(&retval, H5::PredType::STD_U32LE);
}
#endif
/** double */
void read_from_json(const Document &doc, const std::string &name,
double &retval) {
retval = doc[name.c_str()].GetDouble();
}
#ifdef HDF5C
void read_from_h5_dataset(const H5::DataSet &dataset, const std::string &name,
double &retval) {
dataset.read(&retval, H5::PredType::NATIVE_DOUBLE);
}
#endif
/** std::vector<int64_t> */
void read_from_json(const Document &doc, const std::string &name,
std::vector<int64_t> &retval) {
for (const auto &item : doc[name.c_str()].GetArray()) {
retval.push_back(item.GetInt64());
}
}
#ifdef HDF5C
void read_from_h5_dataset(const H5::DataSet &dataset, const std::string &name,
std::vector<int64_t> &retval) {
H5::DataSpace dataspace = dataset.getSpace();
hsize_t dims[1];
dataspace.getSimpleExtentDims(dims);
retval.resize(dims[0]);
dataset.read(retval.data(), H5::PredType::STD_I64LE);
}
#endif
/** std::vector<defs::ROI> */
void read_from_json(const Document &doc, const std::string &name,
std::vector<defs::ROI> &retval) {
for (const auto &item : doc[name.c_str()].GetArray()) {
defs::ROI r{};
r.xmin = item["xmin"].GetInt();
r.xmax = item["xmax"].GetInt();
r.ymin = item["ymin"].GetInt();
r.ymax = item["ymax"].GetInt();
retval.push_back(r);
}
}
#ifdef HDF5C
void read_from_h5_dataset(const H5::DataSet &dataset, const std::string &name,
std::vector<defs::ROI> &retval) {
H5::DataSpace dataspace = dataset.getSpace();
hsize_t dims[1];
dataspace.getSimpleExtentDims(dims);
H5::CompType cType(sizeof(defs::ROI));
cType.insertMember("xmin", HOFFSET(defs::ROI, xmin),
H5::PredType::NATIVE_INT);
cType.insertMember("xmax", HOFFSET(defs::ROI, xmax),
H5::PredType::NATIVE_INT);
cType.insertMember("ymin", HOFFSET(defs::ROI, ymin),
H5::PredType::NATIVE_INT);
cType.insertMember("ymax", HOFFSET(defs::ROI, ymax),
H5::PredType::NATIVE_INT);
retval.resize(dims[0]);
dataset.read(retval.data(), cType);
}
#endif
/** std::array<int, 3UL> */
void read_from_json(const Document &doc, const std::string &name,
std::array<int, 3UL> &retval) {
const auto &json_values = doc[name.c_str()].GetArray();
if (json_values.Size() != retval.size()) {
throw sls::RuntimeError("JSON array " + name +
" does not have num elements as expected");
}
int index = 0;
for (const auto &item : json_values) {
retval[index++] = item.GetInt();
}
}
#ifdef HDF5C
void read_from_h5_dataset(const H5::DataSet &dataset, const std::string &name,
std::array<int, 3UL> &retval) {
H5::DataSpace dataspace = dataset.getSpace();
hsize_t dims[1];
dataspace.getSimpleExtentDims(dims);
if (dims[0] != retval.size()) {
throw sls::RuntimeError("HDF5 dataset " + name +
" does not have num elements as expected");
}
dataset.read(retval.data(), H5::PredType::NATIVE_INT);
}
#endif
/* std::array<sls::ns, 3UL> */
void read_from_json(const Document &doc, const std::string &name,
std::array<sls::ns, 3UL> &retval) {
const auto &json_values = doc[name.c_str()].GetArray();
if (json_values.Size() != retval.size()) {
throw sls::RuntimeError("JSON array " + name +
" does not have num elements as expected");
}
int index = 0;
for (const auto &item : json_values) {
std::string sval = item.GetString();
retval[index++] = StringTo<sls::ns>(sval);
}
}
#ifdef HDF5C
void read_from_h5_dataset(const H5::DataSet &dataset, const std::string &name,
std::array<sls::ns, 3UL> &retval) {
H5::DataSpace dataspace = dataset.getSpace();
hsize_t dims[1];
dataspace.getSimpleExtentDims(dims);
if (dims[0] != retval.size()) {
throw sls::RuntimeError("HDF5 dataset " + name +
" does not have num elements as expected");
}
std::vector<const char *> strValues(dims[0]);
dataset.read(strValues.data(), dataset.getStrType());
for (size_t i = 0; i < dims[0]; ++i) {
retval[i] = StringTo<sls::ns>(strValues[i]);
}
}
#endif
/** defs::xy */
void read_from_json(const Document &doc, const std::string &name,
defs::xy &retval) {
retval.x = doc[name.c_str()]["x"].GetInt();
retval.y = doc[name.c_str()]["y"].GetInt();
}
#ifdef HDF5C
void read_from_h5_dataset(const H5::DataSet &dataset, const std::string &name,
defs::xy &retval) {
H5::CompType cType(sizeof(defs::xy));
cType.insertMember("x", HOFFSET(defs::xy, x), H5::PredType::NATIVE_INT);
cType.insertMember("y", HOFFSET(defs::xy, y), H5::PredType::NATIVE_INT);
dataset.read(&retval, cType);
}
#endif
/** defs::scanParameters */
void read_from_json(const Document &doc, const std::string &name,
defs::scanParameters &retval) {
const auto &s = doc[name.c_str()].GetObject();
retval.enable = s["enable"].GetInt();
retval.dacInd = static_cast<defs::dacIndex>(s["dacInd"].GetInt());
retval.startOffset = s["start offset"].GetInt();
retval.stopOffset = s["stop offset"].GetInt();
retval.stepSize = s["step size"].GetInt();
retval.dacSettleTime_ns = s["dac settle time ns"].GetInt64();
}
#ifdef HDF5C
void read_from_h5_dataset(const H5::DataSet &dataset, const std::string &name,
defs::scanParameters &retval) {
H5::CompType cType(sizeof(defs::scanParameters));
cType.insertMember("enable", HOFFSET(defs::scanParameters, enable),
H5::PredType::NATIVE_INT);
cType.insertMember("dacInd", HOFFSET(defs::scanParameters, dacInd),
H5::PredType::NATIVE_INT);
cType.insertMember("startOffset",
HOFFSET(defs::scanParameters, startOffset),
H5::PredType::NATIVE_INT);
cType.insertMember("stopOffset", HOFFSET(defs::scanParameters, stopOffset),
H5::PredType::NATIVE_INT);
cType.insertMember("stepSize", HOFFSET(defs::scanParameters, stepSize),
H5::PredType::NATIVE_INT);
cType.insertMember("dacSettleTime_ns",
HOFFSET(defs::scanParameters, dacSettleTime_ns),
H5::PredType::STD_I64LE);
dataset.read(&retval, cType);
}
#endif
/** std::map<std::string, std::string> */
void read_from_json(const Document &doc, const std::string &name,
std::map<std::string, std::string> &retval) {
for (const auto &m : doc[name.c_str()].GetObject()) {
retval[m.name.GetString()] = m.value.GetString();
}
}
#ifdef HDF5C
void read_from_h5_dataset(const H5::DataSet &dataset, const std::string &name,
std::map<std::string, std::string> &retval) {
H5::DataSpace dataspace = dataset.getSpace();
hsize_t dims[1];
dataspace.getSimpleExtentDims(dims);
if (dims[0] == 0) {
return; // empty dataset
}
auto strType = dataset.getStrType();
H5::CompType mapType(sizeof(char *) * 2);
mapType.insertMember("key", 0, strType);
mapType.insertMember("value", sizeof(char *), strType);
struct KeyValue {
const char *key;
const char *value;
};
std::vector<KeyValue> kv_vector(dims[0]);
dataset.read(kv_vector.data(), mapType);
for (const auto &kv : kv_vector) {
retval[kv.key] = kv.value;
}
}
#endif
/** test parameter in file */
template <typename T>
void test_json_parameter(const Document &doc, const std::string &name,
const T &expected) {
REQUIRE(doc.HasMember(name.c_str()));
T retval{};
read_from_json(doc, name, retval);
REQUIRE(retval == expected);
}
#ifdef HDF5C
template <typename T>
void test_h5_dataset(const std::string &name, const T &expected) {
auto dataset = h5File->openDataSet(HDF5_GROUP + name);
T retval{};
read_from_h5_dataset(dataset, name, retval);
REQUIRE(retval == expected);
}
#endif
template <typename T>
void check_master_file(const std::optional<Document> &doc,
const std::string &name, const T &expected) {
if (doc.has_value()) {
const auto &d = *doc;
test_json_parameter(d, name, expected);
} else {
#ifdef HDF5C
if (!h5File.has_value()) {
throw sls::RuntimeError("HDF5 file is not opened for testing " +
name);
}
test_h5_dataset(name, expected);
#else
throw sls::RuntimeError("Document is not available for testing " +
name);
#endif
}
}
void test_master_file_version(const Detector &det,
const std::optional<Document> &doc) {
// different values for json and hdf5
// hdf5 version in atttribute and not dataset
double retval{};
std::string name = MasterAttributes::N_VERSION.data();
if (doc.has_value()) {
const auto &d = *doc;
REQUIRE(d.HasMember(MasterAttributes::N_VERSION.data()));
read_from_json(d, name, retval);
REQUIRE(retval == BINARY_WRITER_VERSION);
} else {
#ifdef HDF5C
if (!h5File.has_value()) {
throw sls::RuntimeError(
"HDF5 file is not opened for testing Version");
}
auto attr = h5File->openAttribute(MasterAttributes::N_VERSION.data());
attr.read(attr.getDataType(), &retval);
REQUIRE(retval == HDF5_WRITER_VERSION);
#else
throw sls::RuntimeError(
"Document is not available for testing Version");
#endif
}
}
void test_master_file_type(const Detector &det,
const std::optional<Document> &doc) {
auto det_type = det.getDetectorType().tsquash("Inconsistent detector type");
REQUIRE_NOTHROW(check_master_file<std::string>(
doc, MasterAttributes::N_DETECTOR_TYPE.data(), ToString(det_type)));
}
void test_master_file_timing_mode(const Detector &det,
const std::optional<Document> &doc) {
auto timing_mode = det.getTimingMode().tsquash("Inconsistent timing mode");
REQUIRE_NOTHROW(check_master_file<std::string>(
doc, MasterAttributes::N_TIMING_MODE.data(), ToString(timing_mode)));
}
void test_master_file_geometry(const Detector &det,
const std::optional<Document> &doc) {
auto modGeometry = det.getModuleGeometry();
auto portperModGeometry = det.getPortPerModuleGeometry();
auto geometry = defs::xy{modGeometry.x * portperModGeometry.x,
modGeometry.y * portperModGeometry.y};
REQUIRE_NOTHROW(check_master_file<defs::xy>(
doc, MasterAttributes::N_GEOMETRY.data(), geometry));
}
void test_master_file_image_size(const Detector &det,
const std::optional<Document> &doc) {
auto det_type =
det.getDetectorType().tsquash("Inconsistent detector types to test");
int bytes_per_pixel = det.getDynamicRange().squash() / 8;
detParameters par(det_type);
int image_size = 0;
switch (det_type) {
case defs::EIGER: {
int num_chips = (par.nChipX / 2);
image_size = par.nChanX * par.nChanY * num_chips * bytes_per_pixel;
} break;
case defs::JUNGFRAU:
case defs::MOENCH: {
auto num_udp_interfaces = det.getNumberofUDPInterfaces().tsquash(
"inconsistent number of udp interfaces");
image_size = (par.nChanX * par.nChanY * par.nChipX * par.nChipY *
bytes_per_pixel) /
num_udp_interfaces;
} break;
case defs::MYTHEN3: {
int counter_mask = det.getCounterMask().squash();
int num_counters = __builtin_popcount(counter_mask);
int num_channels_per_counter = par.nChanX / MAX_NUM_COUNTERS;
image_size = num_channels_per_counter * num_counters * par.nChipX *
bytes_per_pixel;
} break;
case defs::GOTTHARD2: {
image_size = par.nChanX * par.nChipX * bytes_per_pixel;
} break;
case defs::CHIPTESTBOARD:
case defs::XILINX_CHIPTESTBOARD: {
testCtbAcquireInfo test_info{};
image_size = calculate_ctb_image_size(
test_info, (det_type == defs::XILINX_CHIPTESTBOARD))
.first;
} break;
default:
throw sls::RuntimeError("Unsupported detector type for this test");
}
REQUIRE_NOTHROW(check_master_file<int>(
doc, MasterAttributes::N_IMAGE_SIZE.data(), image_size));
}
void test_master_file_det_size(const Detector &det,
const std::optional<Document> &doc) {
auto det_type =
det.getDetectorType().tsquash("Inconsistent detector types to test");
auto portSize = det.getPortSize()[0];
// m3 assumes all counters enabled when getting num channels from client
// TODO: in future, remove assumption
if (det_type == defs::MYTHEN3) {
int nchan = portSize.x / MAX_NUM_COUNTERS;
auto counter_mask = det.getCounterMask().tsquash(
"Inconsistent counter mask for Mythen3 detector");
int num_counters = __builtin_popcount(counter_mask);
portSize.x = nchan * num_counters;
} else if (det_type == defs::CHIPTESTBOARD ||
det_type == defs::XILINX_CHIPTESTBOARD) {
testCtbAcquireInfo test_info{};
portSize.x = calculate_ctb_image_size(
test_info, det_type == defs::XILINX_CHIPTESTBOARD)
.second;
portSize.y = 1;
}
REQUIRE_NOTHROW(check_master_file<defs::xy>(
doc, MasterAttributes::N_PIXELS.data(), portSize));
}
void test_master_file_max_frames_per_file(const Detector &det,
const std::optional<Document> &doc) {
auto max_frames_per_file =
det.getFramesPerFile().tsquash("Inconsistent max frames per file");
REQUIRE_NOTHROW(check_master_file<int>(
doc, MasterAttributes::N_MAX_FRAMES_PER_FILE.data(),
max_frames_per_file));
}
void test_master_file_frame_discard_policy(const Detector &det,
const std::optional<Document> &doc) {
auto policy = det.getRxFrameDiscardPolicy().tsquash(
"Inconsistent frame discard policy");
REQUIRE_NOTHROW(check_master_file<std::string>(
doc, MasterAttributes::N_FRAME_DISCARD_POLICY.data(),
ToString(policy)));
}
void test_master_file_frame_padding(const Detector &det,
const std::optional<Document> &doc) {
auto padding = static_cast<int>(
det.getPartialFramesPadding().tsquash("Inconsistent frame padding"));
REQUIRE_NOTHROW(check_master_file<int>(
doc, MasterAttributes::N_FRAME_PADDING.data(), padding));
}
void test_master_file_scan_parameters(const Detector &det,
const std::optional<Document> &doc) {
auto scan_params = det.getScan().tsquash("Inconsistent scan parameters");
REQUIRE_NOTHROW(check_master_file<defs::scanParameters>(
doc, MasterAttributes::N_SCAN_PARAMETERS.data(), scan_params));
}
void test_master_file_total_frames(const Detector &det,
const std::optional<Document> &doc) {
uint64_t repeats =
det.getNumberOfTriggers().tsquash("Inconsistent number of triggers");
uint64_t numFrames =
det.getNumberOfFrames().tsquash("Inconsistent number of frames");
int numAdditionalStorageCells = 0;
auto det_type =
det.getDetectorType().tsquash("Inconsistent detector types");
if (det_type == defs::GOTTHARD2) {
auto timing_mode =
det.getTimingMode().tsquash("Inconsistent timing mode");
auto burst_mode = det.getBurstMode().tsquash("Inconsistent burst mode");
auto numBursts =
det.getNumberOfBursts().tsquash("Inconsistent number of bursts");
// auto
if (timing_mode == defs::AUTO_TIMING) {
// burst mode, repeats = #bursts
if (burst_mode == defs::BURST_INTERNAL ||
burst_mode == defs::BURST_EXTERNAL) {
repeats = numBursts;
}
// continuous, repeats = 1 (no trigger as well)
else {
repeats = 1;
}
}
// trigger
else {
// continuous, numFrames is limited
if (burst_mode == defs::CONTINUOUS_INTERNAL ||
burst_mode == defs::CONTINUOUS_EXTERNAL) {
numFrames = 1;
}
}
} else if (det_type == defs::JUNGFRAU) {
numAdditionalStorageCells =
det.getNumberOfAdditionalStorageCells().tsquash(
"Inconsistent number of additional storage cells");
}
uint64_t total_frames =
numFrames * repeats * (int64_t)(numAdditionalStorageCells + 1);
REQUIRE_NOTHROW(check_master_file<uint64_t>(
doc, MasterAttributes::N_TOTAL_FRAMES.data(), total_frames));
}
void test_master_file_rois(const Detector &det,
const std::optional<Document> &doc) {
auto rois = det.getRxROI();
auto detsize = det.getDetectorSize();
auto det_type =
det.getDetectorType().tsquash("Inconsistent detector types to test");
// compensate for m3 channel size and counter mask mess
if (det_type == defs::MYTHEN3) {
int nchan = detsize.x / MAX_NUM_COUNTERS;
auto counter_mask = det.getCounterMask().tsquash(
"Inconsistent counter mask for Mythen3 detector");
int num_counters = __builtin_popcount(counter_mask);
detsize.x = nchan * num_counters;
}
// replace -1 for complete ROI
bool is2D = (detsize.y > 1);
for (auto &roi : rois) {
if (roi.completeRoi()) {
roi.xmin = 0;
roi.xmax = detsize.x - 1;
if (is2D) {
roi.ymin = 0;
roi.ymax = detsize.y - 1;
}
}
}
REQUIRE_NOTHROW(check_master_file<std::vector<defs::ROI>>(
doc, MasterAttributes::N_RECEIVER_ROIS.data(), rois));
}
void test_master_file_exptime(const Detector &det,
const std::optional<Document> &doc) {
auto exptime = det.getExptime().tsquash("Inconsistent exposure time");
REQUIRE_NOTHROW(check_master_file<std::string>(
doc, MasterAttributes::N_EXPOSURE_TIME.data(), ToString(exptime)));
}
void test_master_file_period(const Detector &det,
const std::optional<Document> &doc) {
auto period = det.getPeriod().tsquash("Inconsistent period");
REQUIRE_NOTHROW(check_master_file<std::string>(
doc, MasterAttributes::N_ACQUISITION_PERIOD.data(), ToString(period)));
}
void test_master_file_num_udp_interfaces(const Detector &det,
const std::optional<Document> &doc) {
auto num_udp_interfaces = det.getNumberofUDPInterfaces().tsquash(
"Inconsistent number of UDP interfaces");
REQUIRE_NOTHROW(check_master_file<int>(
doc, MasterAttributes::N_NUM_UDP_INTERFACES.data(),
num_udp_interfaces));
}
void test_master_file_read_n_rows(const Detector &det,
const std::optional<Document> &doc) {
auto readnrows = det.getReadNRows().tsquash("Inconsistent number of rows");
REQUIRE_NOTHROW(check_master_file<int>(
doc, MasterAttributes::N_NUMBER_OF_ROWS.data(), readnrows));
}
void test_master_file_readout_speed(const Detector &det,
const std::optional<Document> &doc) {
auto readout_speed =
det.getReadoutSpeed().tsquash("Inconsistent readout speed");
REQUIRE_NOTHROW(check_master_file<std::string>(
doc, MasterAttributes::N_READOUT_SPEED.data(),
ToString(readout_speed)));
}
void test_master_file_frames_in_file(const std::optional<Document> &doc,
const int frames_in_file) {
REQUIRE_NOTHROW(check_master_file<int>(
doc, MasterAttributes::N_FRAMES_IN_FILE.data(), frames_in_file));
}
void test_master_file_json_header(const Detector &det,
const std::optional<Document> &doc) {
auto json_header =
det.getAdditionalJsonHeader().tsquash("Inconsistent JSON header");
REQUIRE_NOTHROW(check_master_file<std::map<std::string, std::string>>(
doc, MasterAttributes::N_ADDITIONAL_JSON_HEADER.data(), json_header));
}
void test_master_file_dynamic_range(const Detector &det,
const std::optional<Document> &doc) {
auto dr = det.getDynamicRange().tsquash("Inconsistent dynamic range");
REQUIRE_NOTHROW(check_master_file<int>(
doc, MasterAttributes::N_DYNAMIC_RANGE.data(), dr));
}
void test_master_file_ten_giga(const Detector &det,
const std::optional<Document> &doc) {
auto ten_giga =
static_cast<int>(det.getTenGiga().tsquash("Inconsistent ten giga"));
REQUIRE_NOTHROW(check_master_file<int>(
doc, MasterAttributes::N_TEN_GIGA.data(), ten_giga));
}
void test_master_file_threshold_energy(const Detector &det,
const std::optional<Document> &doc) {
auto threshold =
det.getThresholdEnergy().tsquash("Inconsistent threshold energy");
REQUIRE_NOTHROW(check_master_file<int>(
doc, MasterAttributes::N_THRESHOLD_ENERGY.data(), threshold));
}
void test_master_file_sub_exptime(const Detector &det,
const std::optional<Document> &doc) {
auto sub_exptime =
det.getSubExptime().tsquash("Inconsistent sub exposure time");
REQUIRE_NOTHROW(check_master_file<std::string>(
doc, MasterAttributes::N_SUB_EXPOSURE_TIME.data(),
ToString(sub_exptime)));
}
void test_master_file_sub_period(const Detector &det,
const std::optional<Document> &doc) {
auto exptime = det.getSubExptime().tsquash("Inconsistent sub exptime");
auto deadtime = det.getSubDeadTime().tsquash("Inconsistent sub deadtime");
auto sub_period = exptime + deadtime;
REQUIRE_NOTHROW(check_master_file<std::string>(
doc, MasterAttributes::N_SUB_ACQUISITION_PERIOD.data(),
ToString(sub_period)));
}
void test_master_file_quad(const Detector &det,
const std::optional<Document> &doc) {
auto quad = static_cast<int>(det.getQuad().tsquash("Inconsistent quad"));
REQUIRE_NOTHROW(
check_master_file<int>(doc, MasterAttributes::N_QUAD.data(), quad));
}
void test_master_file_rate_corrections(const Detector &det,
const std::optional<Document> &doc) {
std::vector<int64_t> dead_times;
for (auto item : det.getRateCorrection())
dead_times.push_back(item.count());
REQUIRE_NOTHROW(check_master_file<std::vector<int64_t>>(
doc, MasterAttributes::N_RATE_CORRECTIONS.data(), dead_times));
}
void test_master_file_counter_mask(const Detector &det,
const std::optional<Document> &doc) {
auto counter_mask = static_cast<int>(
det.getCounterMask().tsquash("Inconsistent counter mask"));
REQUIRE_NOTHROW(check_master_file<int>(
doc, MasterAttributes::N_COUNTER_MASK.data(), counter_mask));
}
void test_master_file_exptimes(const Detector &det,
const std::optional<Document> &doc) {
auto exptimes =
det.getExptimeForAllGates().tsquash("Inconsistent exposure times");
REQUIRE_NOTHROW(check_master_file<std::array<sls::ns, 3UL>>(
doc, MasterAttributes::N_EXPOSURE_TIMES.data(), exptimes));
}
void test_master_file_gate_delays(const Detector &det,
const std::optional<Document> &doc) {
auto gate_delays =
det.getGateDelayForAllGates().tsquash("Inconsistent GateDelay");
REQUIRE_NOTHROW(check_master_file<std::array<sls::ns, 3UL>>(
doc, MasterAttributes::N_GATE_DELAYS.data(), gate_delays));
}
void test_master_file_gates(const Detector &det,
const std::optional<Document> &doc) {
auto gates = det.getNumberOfGates().tsquash("Inconsistent number of gates");
REQUIRE_NOTHROW(
check_master_file<int>(doc, MasterAttributes::N_GATES.data(), gates));
}
void test_master_file_threadhold_energies(const Detector &det,
const std::optional<Document> &doc) {
auto threshold_energies =
det.getAllThresholdEnergy().tsquash("Inconsistent threshold energies");
REQUIRE_NOTHROW(check_master_file<std::array<int, 3UL>>(
doc, MasterAttributes::N_THRESHOLD_ENERGIES.data(),
threshold_energies));
}
void test_master_file_burst_mode(const Detector &det,
const std::optional<Document> &doc) {
auto burst_mode = det.getBurstMode().tsquash("Inconsistent burst mode");
REQUIRE_NOTHROW(check_master_file<std::string>(
doc, MasterAttributes::N_BURST_MODE.data(), ToString(burst_mode)));
}
void test_master_file_adc_mask(const Detector &det,
const std::optional<Document> &doc) {
testCtbAcquireInfo test_ctb_config{};
auto adc_mask = test_ctb_config.adc_enable_10g;
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD) {
auto tengiga = test_ctb_config.ten_giga;
if (!tengiga)
adc_mask = test_ctb_config.adc_enable_1g;
}
REQUIRE_NOTHROW(check_master_file<uint32_t>(
doc, MasterAttributes::N_ADC_MASK.data(), adc_mask));
}
void test_master_file_analog_flag(const Detector &det,
const std::optional<Document> &doc) {
testCtbAcquireInfo test_info{};
auto romode = test_info.readout_mode;
auto analog = static_cast<int>(
(romode == defs::ANALOG_ONLY || romode == defs::ANALOG_AND_DIGITAL));
REQUIRE_NOTHROW(
check_master_file<int>(doc, MasterAttributes::N_ANALOG.data(), analog));
}
void test_master_file_analog_samples(const Detector &det,
const std::optional<Document> &doc) {
testCtbAcquireInfo test_info{};
auto analog_samples = test_info.num_adc_samples;
REQUIRE_NOTHROW(check_master_file<int>(
doc, MasterAttributes::N_ANALOG_SAMPLES.data(), analog_samples));
}
void test_master_file_digital_flag(const Detector &det,
const std::optional<Document> &doc) {
testCtbAcquireInfo test_info{};
auto romode = test_info.readout_mode;
auto digital = static_cast<int>(romode == defs::DIGITAL_ONLY ||
romode == defs::ANALOG_AND_DIGITAL ||
romode == defs::DIGITAL_AND_TRANSCEIVER);
REQUIRE_NOTHROW(check_master_file<int>(
doc, MasterAttributes::N_DIGITAL.data(), digital));
}
void test_master_file_digital_samples(const Detector &det,
const std::optional<Document> &doc) {
testCtbAcquireInfo test_info{};
auto digital_samples = test_info.num_dbit_samples;
REQUIRE_NOTHROW(check_master_file<int>(
doc, MasterAttributes::N_DIGITAL_SAMPLES.data(), digital_samples));
}
void test_master_file_dbit_offset(const Detector &det,
const std::optional<Document> &doc) {
testCtbAcquireInfo test_info{};
auto dbit_offset = test_info.dbit_offset;
REQUIRE_NOTHROW(check_master_file<int>(
doc, MasterAttributes::N_DBIT_OFFSET.data(), dbit_offset));
}
void test_master_file_dbit_reorder(const Detector &det,
const std::optional<Document> &doc) {
testCtbAcquireInfo test_info{};
auto dbit_reorder = test_info.dbit_reorder;
REQUIRE_NOTHROW(check_master_file<int>(
doc, MasterAttributes::N_DBIT_REORDER.data(), dbit_reorder));
}
void test_master_file_dbit_bitset(const Detector &det,
const std::optional<Document> &doc) {
testCtbAcquireInfo test_info{};
uint64_t dbit_bitset = 0;
for (auto &i : test_info.dbit_list) {
dbit_bitset |= (static_cast<uint64_t>(1) << i);
}
REQUIRE_NOTHROW(check_master_file<uint64_t>(
doc, MasterAttributes::N_DBIT_BITSET.data(), dbit_bitset));
}
void test_master_file_transceiver_mask(const Detector &det,
const std::optional<Document> &doc) {
testCtbAcquireInfo test_info{};
auto trans_mask = test_info.transceiver_mask;
REQUIRE_NOTHROW(check_master_file<int>(
doc, MasterAttributes::N_TRANSCEIVER_MASK.data(), trans_mask));
}
void test_master_file_transceiver_flag(const Detector &det,
const std::optional<Document> &doc) {
testCtbAcquireInfo test_info{};
auto romode = test_info.readout_mode;
auto trans = static_cast<int>(romode == defs::DIGITAL_AND_TRANSCEIVER ||
romode == defs::TRANSCEIVER_ONLY);
REQUIRE_NOTHROW(check_master_file<int>(
doc, MasterAttributes::N_TRANSCEIVER.data(), trans));
}
void test_master_file_transceiver_samples(const Detector &det,
const std::optional<Document> &doc) {
testCtbAcquireInfo test_info{};
auto trans_samples = test_info.num_trans_samples;
REQUIRE_NOTHROW(check_master_file<int>(
doc, MasterAttributes::N_TRANSCEIVER_SAMPLES.data(), trans_samples));
}
void test_master_file_common_metadata(const Detector &det,
const std::optional<Document> &doc) {
test_master_file_version(det, doc);
test_master_file_type(det, doc);
test_master_file_timing_mode(det, doc);
test_master_file_geometry(det, doc);
test_master_file_image_size(det, doc);
test_master_file_det_size(det, doc);
test_master_file_max_frames_per_file(det, doc);
test_master_file_frame_discard_policy(det, doc);
test_master_file_frame_padding(det, doc);
test_master_file_scan_parameters(det, doc);
test_master_file_total_frames(det, doc);
test_master_file_json_header(det, doc);
// TODO: test frame header format?
}
void test_master_file_jungfrau_metadata(const Detector &det,
const std::optional<Document> &doc) {
REQUIRE_NOTHROW(test_master_file_common_metadata(det, doc));
// Jungfrau specific metadata
REQUIRE_NOTHROW(test_master_file_rois(det, doc));
REQUIRE_NOTHROW(test_master_file_exptime(det, doc));
REQUIRE_NOTHROW(test_master_file_period(det, doc));
REQUIRE_NOTHROW(test_master_file_num_udp_interfaces(det, doc));
REQUIRE_NOTHROW(test_master_file_read_n_rows(det, doc));
REQUIRE_NOTHROW(test_master_file_readout_speed(det, doc));
}
void test_master_file_eiger_metadata(const Detector &det,
const std::optional<Document> &doc) {
REQUIRE_NOTHROW(test_master_file_common_metadata(det, doc));
// Eiger specific metadata
REQUIRE_NOTHROW(test_master_file_rois(det, doc));
REQUIRE_NOTHROW(test_master_file_dynamic_range(det, doc));
REQUIRE_NOTHROW(test_master_file_ten_giga(det, doc));
REQUIRE_NOTHROW(test_master_file_exptime(det, doc));
REQUIRE_NOTHROW(test_master_file_period(det, doc));
REQUIRE_NOTHROW(test_master_file_threshold_energy(det, doc));
REQUIRE_NOTHROW(test_master_file_sub_exptime(det, doc));
REQUIRE_NOTHROW(test_master_file_sub_period(det, doc));
REQUIRE_NOTHROW(test_master_file_quad(det, doc));
REQUIRE_NOTHROW(test_master_file_read_n_rows(det, doc));
REQUIRE_NOTHROW(test_master_file_rate_corrections(det, doc));
REQUIRE_NOTHROW(test_master_file_readout_speed(det, doc));
}
void test_master_file_moench_metadata(const Detector &det,
const std::optional<Document> &doc) {
REQUIRE_NOTHROW(test_master_file_common_metadata(det, doc));
// Moench specific metadata
REQUIRE_NOTHROW(test_master_file_rois(det, doc));
REQUIRE_NOTHROW(test_master_file_exptime(det, doc));
REQUIRE_NOTHROW(test_master_file_period(det, doc));
REQUIRE_NOTHROW(test_master_file_num_udp_interfaces(det, doc));
REQUIRE_NOTHROW(test_master_file_read_n_rows(det, doc));
REQUIRE_NOTHROW(test_master_file_readout_speed(det, doc));
}
void test_master_file_mythen3_metadata(const Detector &det,
const std::optional<Document> &doc) {
REQUIRE_NOTHROW(test_master_file_common_metadata(det, doc));
// Mythen3 specific metadata
REQUIRE_NOTHROW(test_master_file_rois(det, doc));
REQUIRE_NOTHROW(test_master_file_dynamic_range(det, doc));
REQUIRE_NOTHROW(test_master_file_ten_giga(det, doc));
REQUIRE_NOTHROW(test_master_file_period(det, doc));
REQUIRE_NOTHROW(test_master_file_counter_mask(det, doc));
REQUIRE_NOTHROW(test_master_file_exptimes(det, doc));
REQUIRE_NOTHROW(test_master_file_gate_delays(det, doc));
REQUIRE_NOTHROW(test_master_file_gates(det, doc));
REQUIRE_NOTHROW(test_master_file_threadhold_energies(det, doc));
REQUIRE_NOTHROW(test_master_file_readout_speed(det, doc));
}
void test_master_file_gotthard2_metadata(const Detector &det,
const std::optional<Document> &doc) {
REQUIRE_NOTHROW(test_master_file_common_metadata(det, doc));
// Gotthard2 specific metadata
REQUIRE_NOTHROW(test_master_file_exptime(det, doc));
REQUIRE_NOTHROW(test_master_file_period(det, doc));
REQUIRE_NOTHROW(test_master_file_burst_mode(det, doc));
REQUIRE_NOTHROW(test_master_file_readout_speed(det, doc));
}
void test_master_file_ctb_metadata(const Detector &det,
const std::optional<Document> &doc) {
auto det_type = det.getDetectorType().squash();
REQUIRE_NOTHROW(test_master_file_common_metadata(det, doc));
// Ctb specific metadata
REQUIRE_NOTHROW(test_master_file_exptime(det, doc));
REQUIRE_NOTHROW(test_master_file_period(det, doc));
if (det_type == defs::CHIPTESTBOARD)
REQUIRE_NOTHROW(test_master_file_ten_giga(det, doc));
REQUIRE_NOTHROW(test_master_file_adc_mask(det, doc));
REQUIRE_NOTHROW(test_master_file_analog_flag(det, doc));
REQUIRE_NOTHROW(test_master_file_analog_samples(det, doc));
REQUIRE_NOTHROW(test_master_file_digital_flag(det, doc));
REQUIRE_NOTHROW(test_master_file_digital_samples(det, doc));
REQUIRE_NOTHROW(test_master_file_dbit_offset(det, doc));
REQUIRE_NOTHROW(test_master_file_dbit_reorder(det, doc));
REQUIRE_NOTHROW(test_master_file_dbit_bitset(det, doc));
REQUIRE_NOTHROW(test_master_file_transceiver_mask(det, doc));
REQUIRE_NOTHROW(test_master_file_transceiver_flag(det, doc));
REQUIRE_NOTHROW(test_master_file_transceiver_samples(det, doc));
}
void test_master_file_metadata(const Detector &det,
const std::optional<Document> &doc) {
auto det_type =
det.getDetectorType().tsquash("Inconsistent detector types");
switch (det_type) {
case defs::JUNGFRAU:
test_master_file_jungfrau_metadata(det, doc);
break;
case defs::EIGER:
test_master_file_eiger_metadata(det, doc);
break;
case defs::MOENCH:
test_master_file_moench_metadata(det, doc);
break;
case defs::MYTHEN3:
test_master_file_mythen3_metadata(det, doc);
break;
case defs::GOTTHARD2:
test_master_file_gotthard2_metadata(det, doc);
break;
case defs::CHIPTESTBOARD:
case defs::XILINX_CHIPTESTBOARD:
test_master_file_ctb_metadata(det, doc);
break;
default:
break;
}
}
Document parse_binary_master_attributes(std::string file_path) {
REQUIRE(std::filesystem::exists(file_path) == true);
std::ifstream file(file_path);
REQUIRE(file.is_open());
std::stringstream buffer;
buffer << file.rdbuf();
std::string json_str = buffer.str();
Document doc;
ParseResult result = doc.Parse(json_str.c_str());
if (result == 0) {
std::cout << "JSON parse error: " << GetParseError_En(result.Code())
<< " (at offset " << result.Offset() << ")" << std::endl;
// Optional: Show problematic snippet
size_t offset = result.Offset();
std::string context =
json_str.substr(std::max(0, (int)offset - 20), 40);
std::cout << "Context around error: \"" << context << "\"" << std::endl;
}
REQUIRE(result != 0);
return doc;
}
#ifdef HDF5C
void open_hdf5_file(const std::string &file_path) {
REQUIRE(std::filesystem::exists(file_path) == true);
h5File = std::make_optional<H5::H5File>(file_path, H5F_ACC_RDONLY);
REQUIRE(H5Lexists(h5File->getId(), HDF5_GROUP.c_str(), H5P_DEFAULT) ==
true);
}
#endif
TEST_CASE("check_master_file_attributes", "[.cmdcall][.cmdacquire][.cmdattr]") {
Detector det;
Caller caller(&det);
auto det_type =
det.getDetectorType().tsquash("Inconsistent detector types to test");
int64_t num_frames = 1;
switch (det_type) {
case defs::EIGER:
case defs::JUNGFRAU:
case defs::MOENCH:
case defs::MYTHEN3:
case defs::GOTTHARD2:
create_files_for_acquire(det, caller, num_frames);
break;
case defs::CHIPTESTBOARD:
case defs::XILINX_CHIPTESTBOARD: {
testCtbAcquireInfo test_ctb_config{};
create_files_for_acquire(det, caller, num_frames, test_ctb_config);
} break;
default:
throw sls::RuntimeError("Unsupported detector type for this test");
}
testFileInfo file_info;
std::string master_file_prefix = file_info.getMasterFileNamePrefix();
// binary
std::string fname =
master_file_prefix + ".json"; // /tmp/sls_test_master_0.json
auto doc = std::make_optional(parse_binary_master_attributes(fname));
test_master_file_metadata(det, doc);
test_master_file_frames_in_file(doc, num_frames);
// hdf5
#ifdef HDF5C
fname = master_file_prefix + ".h5"; // /tmp/sls_test_master_0.h5
try {
open_hdf5_file(fname);
test_master_file_metadata(det, std::nullopt);
test_master_file_frames_in_file(std::nullopt, num_frames);
} catch (H5::Exception &e) {
LOG(logERROR) << "HDF5 error: " << e.getDetailMsg();
throw;
}
#endif
}
} // namespace sls