in python, but need to change the default to Hz again for clean code and intuition
Run Simulator Tests on local RHEL9 / build (push) Failing after 59s
Run Simulator Tests on local RHEL8 / build (push) Failing after 2m28s
Build on RHEL9 docker image / build (push) Failing after 2m34s
Build on RHEL8 docker image / build (push) Failing after 3m56s

This commit is contained in:
2026-04-15 17:27:55 +02:00
parent f253296c23
commit 97ed713d4d
7 changed files with 68 additions and 7 deletions
+1
View File
@@ -13,6 +13,7 @@ pybind11_add_module(_slsdet
src/DurationWrapper.cpp
src/pedestal.cpp
src/bit.cpp
src/frequency.cpp
)
target_link_libraries(_slsdet PUBLIC
+1
View File
@@ -34,6 +34,7 @@ scanParameters = _slsdet.scanParameters
currentSrcParameters = _slsdet.currentSrcParameters
DurationWrapper = _slsdet.DurationWrapper
pedestalParameters = _slsdet.pedestalParameters
Hz = _slsdet.Hz
import os
def read_version():
+20 -3
View File
@@ -13,11 +13,12 @@ dacIndex = slsDetectorDefs.dacIndex
detectorType = slsDetectorDefs.detectorType
streamingInterface = slsDetectorDefs.streamingInterface
defs = slsDetectorDefs
from .utils import element_if_equal, all_equal, get_set_bits, list_to_bitmask
from .utils import Geometry, to_geo, element, reduce_time, is_iterable, hostname_list
from ._slsdet import xy, freeSharedMemory, getUserDetails
from ._slsdet import xy, Hz, freeSharedMemory, getUserDetails
from .gaincaps import Mythen3GainCapsWrapper
from . import utils as ut
from .proxy import JsonProxy, SlowAdcProxy, ClkDivProxy, MaxPhaseProxy, ClkFreqProxy, PatLoopProxy, PatNLoopProxy, PatWaitProxy, PatWaitTimeProxy
@@ -3524,18 +3525,23 @@ class Detector(CppDetectorApi):
Accepts decimal inputs
"""
return self.getRUNClock()
'''
freq_hz = element_if_equal(self.getRUNClock())
if isinstance(freq_hz, list):
return [value / 1e6 for value in freq_hz]
return freq_hz / 1e6
'''
@runclk.setter
def runclk(self, freq):
'''
if isinstance(freq, dict):
freq_hz = {key: int(round(value * 1e6)) for key, value in freq.items()}
else:
freq_hz = int(round(freq * 1e6))
ut.set_using_dict(self.setRUNClock, freq_hz)
'''
ut.set_using_dict(self.setRUNClock, freq)
@property
@element
@@ -3615,18 +3621,24 @@ class Detector(CppDetectorApi):
[Ctb][Xilinx Ctb] Sets clock for latching the digital bits in MHz. \n
Accepts decimal inputs
"""
'''
freq_hz = element_if_equal(self.getDBITClock())
if isinstance(freq_hz, list):
return [value / 1e6 for value in freq_hz]
return freq_hz / 1e6
'''
return self.getDBITClock()
@dbitclk.setter
def dbitclk(self, value):
'''
if isinstance(value, dict):
value_hz = {key: int(round(item * 1e6)) for key, item in value.items()}
else:
value_hz = int(round(value * 1e6))
ut.set_using_dict(self.setDBITClock, value_hz)
'''
ut.set_using_dict(self.setDBITClock, value)
@property
@element
@@ -3752,19 +3764,24 @@ class Detector(CppDetectorApi):
[Ctb][Xilinx Ctb] Sets ADC clock frequency in MHz. \n
Accepts decimal inputs
"""
'''
freq_hz = element_if_equal(self.getADCClock())
if isinstance(freq_hz, list):
return [value / 1e6 for value in freq_hz]
return freq_hz / 1e6
'''
return self.getADCClock()
@adcclk.setter
def adcclk(self, value):
'''
if isinstance(value, dict):
value_hz = {key: int(round(item * 1e6)) for key, item in value.items()}
else:
value_hz = int(round(value * 1e6))
ut.set_using_dict(self.setADCClock, value_hz)
'''
ut.set_using_dict(self.setADCClock, value)
@property
@element
+26
View File
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
/*
This file contains Python bindings for the Hz and for conversion to other units from and to string.
*/
#include "py_headers.h"
#include "sls/ToString.h"
#include "sls/sls_detector_defs.h"
namespace py = pybind11;
void init_freq(py::module &m) {
py::class_<slsDetectorDefs::Hz> Hz(m, "Hz");
Hz.def(py::init<int v) {
return slsDetectorDefs::Hz(v * 1000000);
}));
Hz.def(py::init([](const std::string &s) {
return sls::StringTo<slsDetectorDefs::Hz>(s);
}));
Hz.def_readwrite("value", &slsDetectorDefs::Hz::value);
Hz.def("__repr__", [](const slsDetectorDefs::Hz &f) { return sls::ToString(f); });
Hz.def("__str__", [](const slsDetectorDefs::Hz &f) { return sls::ToString(f); });
Hz.def(py::self == py::self);
py::implicitly_convertible<std::string, slsDetectorDefs::Hz>();
}
+2
View File
@@ -21,6 +21,7 @@ void init_source(py::module &);
void init_duration(py::module &);
void init_pedestal(py::module &);
void init_bit(py::module &);
void init_freq(py::module &);
PYBIND11_MODULE(_slsdet, m) {
m.doc() = R"pbdoc(
@@ -42,6 +43,7 @@ PYBIND11_MODULE(_slsdet, m) {
init_duration(m);
init_pedestal(m);
init_bit(m);
init_freq(m);
// init_experimental(m);
py::module io = m.def_submodule("io", "Submodule for io");
+14
View File
@@ -0,0 +1,14 @@
from slsdet import Hz
'''
def test_Hz():
f = Hz(1)
assert f.value() == 1e6
f = Hz('1MHz')
assert f.value() == 1e6
f = Hz('5000kHz')
assert f.value() == 5e6
assert Hz(1) == 1
assert Hz(1e6) == 1e6
assert Hz(1, 'MHz') == 1e6
assert Hz(0.5, 'GHz') == 0.5e9
'''