wip acquire ctb state

This commit is contained in:
2026-05-21 17:40:26 +02:00
parent c4c7d80070
commit b45349998b
4 changed files with 240 additions and 0 deletions
@@ -0,0 +1,69 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#include "Acquire.h"
#include "catch.hpp"
#include <thread>
namespace sls::test::acquire {
void wait_until_idle(const Detector &det) {
bool idle = false;
while (!idle) {
auto statusList = det.getDetectorStatus();
if (statusList.any(defs::ERROR)) {
throw std::runtime_error("error status during acquisition");
}
if (statusList.contains_only(defs::IDLE, defs::STOPPED)) {
idle = true;
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
void acquire(Detector &det) {
det.startReceiver();
det.startDetector();
wait_until_idle(det);
det.stopReceiver();
}
void run(Detector &det, int64_t num_frames, const FileState& file_state, const std::optional<CTBState>& ctb_state) {
FileStateGuard file_guard(det);
CTBStateGuard ctb_guard(det);
if (ctb_state) {
set_ctb_state(det, ctb_state.value());
}
// frames
auto prev_frames = det.getNumberOfFrames().tsquash(
"Inconsistent number of frames to acquire");
det.setNumberOfFrames(num_frames);
// binary
auto bin_state = file_state;
bin_state.file_format = defs::BINARY;
set_file_state(det, bin_state);
acquire(det);
{
auto frames_caught = det.getFramesCaught()[0][0];
REQUIRE(frames_caught == num_frames);
}
// hdf5
#ifdef HDF5C
auto h5_state = file_state;
h5_state.file_format = defs::HDF5;
set_file_state(det, h5_state);
acquire(det);
{
auto frames_caught = det.getFramesCaught()[0][0];
REQUIRE(frames_caught == num_frames);
}
#endif
// restore previous state
det.setNumberOfFrames(prev_frames);
}
} // namespace sls::test::acquire
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#pragma once
#include "FileState.h"
#include "CTBState.h"
#include "sls/Detector.h"
#include <optional>
namespace sls::test::acquire {
void wait_until_idle(const Detector &det);
void acquire(Detector &det);
void run(Detector &det, int64_t num_frames = 1, const FileState& file_state = default_file_state(), const std::optional<CTBState>& ctb_state = std::nullopt);
} // namespace sls::test::acquire
@@ -0,0 +1,91 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#pragma once
#include "sls/Detector.h"
namespace sls::test::acquire {
struct CTBState {
defs::readoutMode readout_mode;
bool ten_giga;
int num_adc_samples;
int num_dbit_samples;
int num_trans_samples;
uint32_t adc_enable_1g;
uint32_t adc_enable_10g;
int dbit_offset;
std::vector<int> dbit_list;
bool dbit_reorder;
uint32_t transceiver_mask;
};
inline CTBState default_ctb_state() {
return {
defs::ANALOG_AND_DIGITAL,
false,
5000,
6000,
288,
0xFFFFFF00,
0xFF00FFFF,
0,
{0, 12, 2, 43},
false,
0x3
};
}
inline CTBState get_ctb_state(const Detector& det) {
return CTBState{
det.getReadoutMode().tsquash("Inconsistent readout mode"),
true, // always true for xilinx, det.getTenGiga() for ctb
det.getNumberOfAnalogSamples().tsquash("Inconsistent number of analog samples"),
det.getNumberOfDigitalSamples().tsquash("Inconsistent number of digital samples"),
det.getNumberOfTransceiverSamples().tsquash("Inconsistent number of transceiver samples"),
0, // always 0 for xilinx, det.getTenGigaADCEnableMask() for ctb
det.getTenGigaADCEnableMask().tsquash("Inconsistent ten giga adc enable mask"),
det.getRxDbitOffset().tsquash("Inconsistent rx dbit offset"),
det.getRxDbitList().tsquash("Inconsistent rx dbit list"),
det.getRxDbitReorder().tsquash("Inconsistent rx dbit reorder"),
det.getTransceiverEnableMask().tsquash("Inconsistent transceiver mask")
};
}
inline void set_ctb_state(Detector& det, const CTBState& s) {
det.setReadoutMode(s.readout_mode);
if (det.getDetectorType().tsquash("inconsistent detector type") ==
slsDetectorDefs::CHIPTESTBOARD) {
det.setTenGiga(s.ten_giga);
det.setADCEnableMask(s.adc_enable_1g);
}
det.setNumberOfAnalogSamples(s.num_adc_samples);
det.setNumberOfDigitalSamples(s.num_dbit_samples);
det.setNumberOfTransceiverSamples(s.num_trans_samples);
det.setTenGigaADCEnableMask(s.adc_enable_10g);
det.setRxDbitOffset(s.dbit_offset);
det.setRxDbitList(s.dbit_list);
det.setRxDbitReorder(s.dbit_reorder);
det.setTransceiverEnableMask(s.transceiver_mask);
}
class CTBStateGuard {
public:
explicit CTBStateGuard(Detector& det) : det(det), saved_(get_ctb_state(det)) {}
~CTBStateGuard() {
set_ctb_state(det, saved_);
}
private:
Detector& det;
CTBState saved_;
static bool is_ctb(const Detector& det) {
auto type = det.getDetectorType().tsquash("");
return type == defs::CHIPTESTBOARD ||
type == defs::XILINX_CHIPTESTBOARD;
}
};
} // namespace sls::test::acquire
@@ -0,0 +1,62 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
#pragma once
#include "sls/Detector.h"
namespace sls::test::acquire {
struct FileState {
std::string file_path;
std::string file_prefix;
int64_t file_acq_index;
bool file_write;
bool file_overwrite;
slsDetectorDefs::fileFormat file_format;
};
inline FileState default_file_state() {
return {
"/tmp",
"sls_test",
0,
true,
true,
slsDetectorDefs::BINARY
};
}
inline FileState get_file_state(const Detector& det) {
return FileState{
det.getFilePath().tsquash("Inconsistent file path"),
det.getFileNamePrefix().tsquash("Inconsistent file prefix"),
det.getAcquisitionIndex().tsquash("Inconsistent file acquisition index"),
det.getFileWrite().tsquash("Inconsistent file write"),
det.getFileOverWrite().tsquash("Inconsistent file overwrite"),
det.getFileFormat().tsquash("Inconsistent file format")
};
}
inline void set_file_state(Detector& det, const FileState& s) {
det.setFilePath(s.file_path);
det.setFileNamePrefix(s.file_prefix);
det.setAcquisitionIndex(s.file_acq_index);
det.setFileWrite(s.file_write);
det.setFileOverWrite(s.file_overwrite);
det.setFileFormat(s.file_format);
}
class FileStateGuard {
public:
explicit FileStateGuard(Detector& det) : det(det), saved_(get_file_state(det)) {}
~FileStateGuard() {
set_file_state(det, saved_);
}
private:
Detector& det;
FileState saved_;
};
} // namespace sls::test::acquire