works in file. still needs refactoring

This commit is contained in:
2026-05-13 13:44:11 +02:00
parent 794c9f506a
commit fa263d1d21
14 changed files with 130 additions and 113 deletions
+10
View File
@@ -30,7 +30,17 @@ def extract_enums(lines):
line_iter = iter(lines)
enums = {}
inside_defs = False
for line in line_iter:
# only pick up what is inside slsDetectorDefs
if "class slsDetectorDefs" in line:
inside_defs = True
if not inside_defs:
continue
#Hack away class enum defs
if "class" in line:
line = line.replace("class", "")
+15 -12
View File
@@ -653,9 +653,9 @@ void init_det(py::module &m) {
Detector::getNumberofUDPInterfaces,
py::arg() = Positions{});
CppDetectorApi.def("setNumberofUDPInterfaces",
(void (Detector::*)(int, sls::Positions)) &
(void (Detector::*)(int)) &
Detector::setNumberofUDPInterfaces,
py::arg(), py::arg() = Positions{});
py::arg());
CppDetectorApi.def("getSelectedUDPInterface",
(Result<int>(Detector::*)(sls::Positions) const) &
Detector::getSelectedUDPInterface,
@@ -841,6 +841,19 @@ void init_det(py::module &m) {
CppDetectorApi.def(
"setTransmissionDelay",
(void (Detector::*)(int)) & Detector::setTransmissionDelay, py::arg());
CppDetectorApi.def("getDataStream",
(Result<bool>(Detector::*)(const defs::portPosition,
sls::Positions) const) &
Detector::getDataStream,
py::arg(), py::arg() = Positions{});
CppDetectorApi.def("setDataStream",
(void (Detector::*)(const defs::portPosition, const bool,
sls::Positions)) &
Detector::setDataStream,
py::arg(), py::arg(), py::arg() = Positions{});
CppDetectorApi.def("getPortPositionList",
(std::vector<defs::portPosition>(Detector::*)() const) &
Detector::getPortPositionList);
CppDetectorApi.def("getUseReceiverFlag",
(Result<bool>(Detector::*)(sls::Positions) const) &
Detector::getUseReceiverFlag,
@@ -1170,16 +1183,6 @@ void init_det(py::module &m) {
CppDetectorApi.def("setQuad",
(void (Detector::*)(const bool)) & Detector::setQuad,
py::arg());
CppDetectorApi.def("getDataStream",
(Result<bool>(Detector::*)(const defs::portPosition,
sls::Positions) const) &
Detector::getDataStream,
py::arg(), py::arg() = Positions{});
CppDetectorApi.def("setDataStream",
(void (Detector::*)(const defs::portPosition, const bool,
sls::Positions)) &
Detector::setDataStream,
py::arg(), py::arg(), py::arg() = Positions{});
CppDetectorApi.def("getTop",
(Result<bool>(Detector::*)(sls::Positions) const) &
Detector::getTop,
+7
View File
@@ -27,6 +27,7 @@ void init_enums(py::module &m) {
.value("GOTTHARD2", slsDetectorDefs::detectorType::GOTTHARD2)
.value("XILINX_CHIPTESTBOARD",
slsDetectorDefs::detectorType::XILINX_CHIPTESTBOARD)
.value("MATTERHORN", slsDetectorDefs::detectorType::MATTERHORN)
.export_values();
py::enum_<slsDetectorDefs::boolFormat>(Defs, "boolFormat")
@@ -50,6 +51,12 @@ void init_enums(py::module &m) {
.value("Y", slsDetectorDefs::dimension::Y)
.export_values();
py::enum_<slsDetectorDefs::FrequencyUnit>(Defs, "FrequencyUnit")
.value("Hz", slsDetectorDefs::FrequencyUnit::Hz)
.value("kHz", slsDetectorDefs::FrequencyUnit::kHz)
.value("MHz", slsDetectorDefs::FrequencyUnit::MHz)
.export_values();
py::enum_<slsDetectorDefs::frameDiscardPolicy>(Defs, "frameDiscardPolicy")
.value("NO_DISCARD", slsDetectorDefs::frameDiscardPolicy::NO_DISCARD)
.value("DISCARD_EMPTY_FRAMES",
+9 -9
View File
@@ -826,15 +826,6 @@ nextframenumber:
function: setNextFrameNumber
input_types: [ uint64_t ]
numinterfaces:
help: "[1, 2]\n\t[Jungfrau][Moench] Number of udp interfaces to stream data from detector. Default: 1.\n\tAlso enables second interface in receiver for listening (Writes a file per interface if writing enabled).\n\tAlso restarts client and receiver zmq sockets if zmq streaming enabled.\n\t[Eiger] Only gets with result 2."
inherit_actions: INTEGER_COMMAND_VEC_ID
actions:
GET:
function: getNumberofUDPInterfaces
PUT:
function: setNumberofUDPInterfaces
selinterface:
help: "[0, 1]\n\t[Jungfrau][Moench] The udp interface to stream data from detector. Effective only when number of interfaces is 1. Default: 0 (outer)"
inherit_actions: INTEGER_COMMAND_VEC_ID
@@ -1521,6 +1512,15 @@ zmqport:
function: setClientZmqPort
################# INTEGER_COMMAND_SET_NOID_GET_ID ############
numinterfaces:
help: "[1, 2]\n\t[Jungfrau][Moench] Number of udp interfaces to stream data from detector. Default: 1.\n\tAlso enables second interface in receiver for listening (Writes a file per interface if writing enabled).\n\tAlso restarts client and receiver zmq sockets if zmq streaming enabled.\n\t[Eiger] Only gets with result 2."
inherit_actions: INTEGER_COMMAND_SET_NOID_GET_ID
actions:
GET:
function: getNumberofUDPInterfaces
PUT:
function: setNumberofUDPInterfaces
sync:
inherit_actions: INTEGER_COMMAND_SET_NOID_GET_ID
help: "[0, 1]\n\t[Jungfrau][Moench] Enables or disables synchronization between modules. Sync mode requires at least one master configured. Also requires flatband cabling between master and slave with termination board."
@@ -5674,7 +5674,7 @@ numinterfaces:
argc: 1
cast_input:
- true
check_det_id: false
check_det_id: true
convert_det_id: true
function: setNumberofUDPInterfaces
input:
@@ -5683,7 +5683,7 @@ numinterfaces:
- int
output:
- args.front()
require_det_id: true
require_det_id: false
store_result_in_t: false
command_name: numinterfaces
function_alias: numinterfaces
+4 -3
View File
@@ -719,8 +719,9 @@ class Detector {
* restarts client and receiver zmq sockets if zmq streaming enabled. \n
* [Gotthard2] second interface enabled to send veto information via 10Gbps
* for debugging. By default, if veto enabled, it is sent via 2.5 gbps
* interface. \nSetting this resets the receiver roi */
void setNumberofUDPInterfaces(int n, Positions pos = {});
* interface. \nSetting this resets the receiver roi and any udp datastream
* disables */
void setNumberofUDPInterfaces(int n);
/** [Jungfrau][Moench] */
Result<int> getSelectedUDPInterface(Positions pos = {}) const;
@@ -2279,7 +2280,7 @@ class Detector {
private:
std::vector<uint16_t> getValidPortNumbers(uint16_t start_port);
void updateRxRateCorrections();
void setNumberofUDPInterfaces_(int n, Positions pos);
void setNumberofUDPInterfaces_(int n);
};
} // namespace sls
+5 -1
View File
@@ -7053,8 +7053,12 @@ std::string Caller::numinterfaces(int action) {
if (action == slsDetectorDefs::PUT_ACTION) {
if (args.size() == 1) {
if (det_id != -1) {
throw RuntimeError(
"Cannot execute numinterfaces at module level");
}
auto arg0 = StringTo<int>(args[0]);
det->setNumberofUDPInterfaces(arg0, std::vector<int>{det_id});
det->setNumberofUDPInterfaces(arg0);
os << args.front() << '\n';
}
}
+17 -9
View File
@@ -1082,18 +1082,17 @@ Result<int> Detector::getNumberofUDPInterfaces(Positions pos) const {
return pimpl->Parallel(&Module::getNumberofUDPInterfacesFromShm, pos);
}
void Detector::setNumberofUDPInterfaces(int n, Positions pos) {
void Detector::setNumberofUDPInterfaces(int n) {
auto detType = getDetectorType().squash();
if (detType != defs::JUNGFRAU && detType != defs::MOENCH) {
throw RuntimeError(
"Cannot set number of udp interfaces for this detector.");
}
// also called by vetostream (for gotthard2)
setNumberofUDPInterfaces_(n, pos);
pimpl->updateRxUDPDatastreamMetadata();
setNumberofUDPInterfaces_(n);
}
void Detector::setNumberofUDPInterfaces_(int n, Positions pos) {
void Detector::setNumberofUDPInterfaces_(int n) {
if (!size()) {
throw RuntimeError("No modules added.");
}
@@ -1103,10 +1102,10 @@ void Detector::setNumberofUDPInterfaces_(int n, Positions pos) {
bool previouslyReceiverStreaming = false;
uint16_t rxStartingPort = 0;
if (useReceiver) {
previouslyReceiverStreaming = getRxZmqDataStream(pos).squash(true);
previouslyReceiverStreaming = getRxZmqDataStream().squash(true);
rxStartingPort = getRxZmqPort({0}).squash(0);
}
pimpl->Parallel(&Module::setNumberofUDPInterfaces, pos, n);
pimpl->Parallel(&Module::setNumberofUDPInterfaces, {}, n);
// ensure receiver zmq socket ports are multiplied by 2 (2 interfaces)
setClientZmqPort(clientStartingPort, -1);
if (getUseReceiverFlag().squash(false)) {
@@ -1118,8 +1117,8 @@ void Detector::setNumberofUDPInterfaces_(int n, Positions pos) {
pimpl->setDataStreamingToClient(true);
}
if (previouslyReceiverStreaming) {
setRxZmqDataStream(false, pos);
setRxZmqDataStream(true, pos);
setRxZmqDataStream(false);
setRxZmqDataStream(true);
}
}
@@ -1325,6 +1324,15 @@ Result<bool> Detector::getDataStream(const defs::portPosition port,
void Detector::setDataStream(const defs::portPosition port, const bool enable,
Positions pos) {
// check num interfaces
auto numInterfaces =
pimpl->Parallel(&Module::getNumberofUDPInterfacesFromShm, {})
.tsquash("Inconsistent number of UDP interfaces among modules");
if (numInterfaces != 2) {
throw RuntimeError(
"Cannot enable/disable individual udp ports. Change number of udp "
"interfaces to 2 (cmd = numinterfaces).");
}
pimpl->Parallel(&Module::setDataStream, pos, port, enable);
pimpl->updateRxUDPDatastreamMetadata();
}
@@ -2014,7 +2022,7 @@ void Detector::setVetoStream(defs::streamingInterface interface,
? 2
: 1);
if (numinterfaces != old_numinterfaces) {
setNumberofUDPInterfaces_(numinterfaces, pos);
setNumberofUDPInterfaces_(numinterfaces);
}
}
+16 -26
View File
@@ -1657,12 +1657,6 @@ std::vector<defs::portPosition> DetectorImpl::getPortPositionList() const {
}
void DetectorImpl::updateRxUDPDatastreamMetadata() {
auto detType = shm()->detType;
if (detType != defs::EIGER && detType != defs::JUNGFRAU &&
detType != defs::MOENCH)
throw RuntimeError(
"Datastream enable not implemented for this detector");
// check num interfaces
auto numInterfaces =
Parallel(&Module::getNumberofUDPInterfacesFromShm, {})
@@ -1672,27 +1666,23 @@ void DetectorImpl::updateRxUDPDatastreamMetadata() {
}
std::vector<int> disable;
// 1 interface: empty vector (disable none)
// 2 interface: check each enable
if (numInterfaces == 2) {
auto portList = getPortPositionList();
if (portList.size() != 2) {
throw RuntimeError("Invalid port size. Expected 2.");
}
// bottom and left is port 0
auto port0 = Parallel(&Module::getDataStream, {}, portList[0]);
auto port1 = Parallel(&Module::getDataStream, {}, portList[1]);
auto portList = getPortPositionList();
if (portList.size() != 2) {
throw RuntimeError("Invalid port size. Expected 2.");
}
// bottom and left is port 0
auto port0 = Parallel(&Module::getDataStream, {}, portList[0]);
auto port1 = Parallel(&Module::getDataStream, {}, portList[1]);
// if any of them are disabled
if (port0.any(false) || port1.any(false)) {
// for each module: if disabled, push port index
for (size_t i = 0; i != port0.size(); ++i) {
if (!port0[i]) {
disable.push_back(i * 2);
}
if (!port1[i]) {
disable.push_back(i * 2 + 1);
}
// if any of them are disabled
if (port0.any(false) || port1.any(false)) {
// for each module: if disabled, push port index
for (size_t i = 0; i != port0.size(); ++i) {
if (!port0[i]) {
disable.push_back(i * 2);
}
if (!port1[i]) {
disable.push_back(i * 2 + 1);
}
}
}
+4
View File
@@ -193,6 +193,8 @@ class GeneralData {
slsDetectorDefs::NO_DISCARD};
/* actual image size after ctboffset and ctbreorder */
uint32_t actualImageSize{0};
/* bottom & top or left & right for 2 interfaces */
std::array<defs::portPosition, 2> udpPortTypes{defs::LEFT, defs::RIGHT};
GeneralData(){};
virtual ~GeneralData(){};
@@ -344,6 +346,7 @@ class JungfrauData : public GeneralData {
fifoDepth = 2500;
standardheader = true;
maxRowsPerReadout = 512;
udpPortTypes = {defs::BOTTOM, defs::TOP};
UpdateImageSize();
};
@@ -376,6 +379,7 @@ class MoenchData : public GeneralData {
standardheader = true;
maxRowsPerReadout = 400;
frameDiscardMode = slsDetectorDefs::DISCARD_PARTIAL_FRAMES;
udpPortTypes = {defs::BOTTOM, defs::TOP};
UpdateImageSize();
};
+10 -9
View File
@@ -747,8 +747,8 @@ void Implementation::stopReceiver() {
if (!activated) {
summary = "\n\tDeactivated Receiver";
} else if (!udpDataStream[i]) {
summary = "\n\tDeactivated " + ToString(udpDataStreamType[i]) +
" Port";
summary = "\n\tDeactivated " +
ToString(generalData->udpPortTypes[i]) + " Port";
} else if (portRois[i].noRoi()) {
summary = "\n\tNo Roi on Port[" + std::to_string(i) + ']';
} else {
@@ -994,9 +994,10 @@ void Implementation::StartMasterWriter() {
masterAttributes.gates = numberOfGates;
masterAttributes.additionalJsonHeader = additionalJsonHeader;
masterAttributes.readoutSpeed = readoutSpeed;
masterAttributes.udpPortEnables = udpPortEnables;
masterAttributes.udpPortType[0] = ToString(udpDataStreamType[0]);
masterAttributes.udpPortType[1] = ToString(udpDataStreamType[1]);
masterAttributes.udpPortTypes = {
ToString(generalData->udpPortTypes[0]),
ToString(generalData->udpPortTypes[1])};
masterAttributes.udpPortsDisabled = udpPortsDisabledMetadata;
// create master file
masterFileName = dataProcessor[0]->CreateMasterFile(
@@ -1101,6 +1102,7 @@ void Implementation::setNumberofUDPInterfaces(const int n) {
// reset udp data stream
udpDataStream[0] = true;
udpDataStream[1] = true;
udpPortsDisabledMetadata.clear();
// create threads
for (int i = 0; i < generalData->numUDPInterfaces; ++i) {
@@ -1691,7 +1693,6 @@ void Implementation::setUDPDataStream(const portPosition port,
// top goes to udp port 2 (jungfrau & moench)
if (port == TOP || port == RIGHT)
index = 1;
udpDataStreamType[index] = port;
// jungfrau and moench: straightforward
if (generalData->detType != EIGER) {
udpDataStream[index] = enable;
@@ -1714,9 +1715,9 @@ void Implementation::setUDPDataStream(const portPosition port,
listener[i]->SetUDPDatastream(udpDataStream[i]);
}
void Implementation::updateUDPDatastreamMetadata(
const std::array<std::vector<int>, 2> &portEnables) {
udpPortEnables = portEnables;
void Implementation::updateUDPPortsDisabledMetadata(
const std::vector<int> &portsDisabled) {
udpPortsDisabledMetadata = portsDisabled;
}
int Implementation::getReadNRows() const { return readNRows; }
-2
View File
@@ -368,8 +368,6 @@ class Implementation : private virtual slsDetectorDefs {
bool activated{true};
std::array<bool, 2> udpDataStream = {{true, true}};
std::vector<int> udpPortsDisabledMetadata;
std::vector<bool> udpPort2Enable;
std::array<portPosition, 2> udpDataStreamType = {{LEFT, RIGHT}};
// only for Eiger to remember (10Gbe selectable)
std::array<bool, 2> udpDataStream10GbE = {{true, true}};
int readNRows{0};
+20 -34
View File
@@ -55,8 +55,6 @@ void MasterAttributes::GetJungfrauBinaryAttributes(writer *w) {
WriteBinaryNumberOfUDPInterfaces(w);
WriteBinaryNumberOfRows(w);
WriteBinaryReadoutSpeed(w);
if (numUDPInterfaces == 2)
WriteBinaryUDPPortEnables(w);
}
#ifdef HDF5C
@@ -67,8 +65,6 @@ void MasterAttributes::WriteJungfrauHDF5Attributes(H5::Group *group) {
WriteHDF5NumberOfUDPInterfaces(group);
WriteHDF5NumberOfRows(group);
WriteHDF5ReadoutSpeed(group);
if (numUDPInterfaces == 2)
WriteHDF5UDPPortEnables(group);
}
#endif
@@ -79,8 +75,6 @@ void MasterAttributes::GetMoenchBinaryAttributes(writer *w) {
WriteBinaryNumberOfUDPInterfaces(w);
WriteBinaryNumberOfRows(w);
WriteBinaryReadoutSpeed(w);
if (numUDPInterfaces == 2)
WriteBinaryUDPPortEnables(w);
}
#ifdef HDF5C
@@ -91,8 +85,6 @@ void MasterAttributes::WriteMoenchHDF5Attributes(H5::Group *group) {
WriteHDF5NumberOfUDPInterfaces(group);
WriteHDF5NumberOfRows(group);
WriteHDF5ReadoutSpeed(group);
if (numUDPInterfaces == 2)
WriteHDF5UDPPortEnables(group);
}
#endif
@@ -109,7 +101,6 @@ void MasterAttributes::GetEigerBinaryAttributes(writer *w) {
WriteBinaryNumberOfRows(w);
WriteBinaryRateCorrections(w);
WriteBinaryReadoutSpeed(w);
WriteBinaryUDPPortEnables(w);
}
#ifdef HDF5C
@@ -126,7 +117,6 @@ void MasterAttributes::WriteEigerHDF5Attributes(H5::Group *group) {
WriteHDF5NumberOfRows(group);
WriteHDF5RateCorrections(group);
WriteHDF5ReadoutSpeed(group);
WriteHDF5UDPPortEnables(group);
}
#endif
@@ -423,11 +413,19 @@ void MasterAttributes::WriteHDF5AcquisitionPeriod(H5::Group *group) {
void MasterAttributes::WriteBinaryNumberOfUDPInterfaces(writer *w) {
WriteBinary(w, N_NUM_UDP_INTERFACES.data(), numUDPInterfaces);
if (numUDPInterfaces == 2 && detType != defs::GOTTHARD2) {
WriteBinaryUDPPortsType(w);
WriteBinaryUDPPortsDisabled(w);
}
}
#ifdef HDF5C
void MasterAttributes::WriteHDF5NumberOfUDPInterfaces(H5::Group *group) {
WriteHDF5Int(group, N_NUM_UDP_INTERFACES.data(), numUDPInterfaces);
if (numUDPInterfaces == 2 && detType != defs::GOTTHARD2) {
WriteHDF5UDPPortsType(group);
WriteHDF5UDPPortsDisabled(group);
}
}
#endif
@@ -700,35 +698,23 @@ void MasterAttributes::WriteHDF5TransceiverSamples(H5::Group *group) {
}
#endif
void MasterAttributes::WriteBinaryUDPPortEnables(writer *w) {
for (size_t i = 0; i != udpPortType.size(); ++i) {
std::string key = udpPortType[i] + std::string(N_UDP_PORT_ENABLES);
w->Key(key.c_str());
w->StartArray();
for (const int u : udpPortEnables[i]) {
w->Int(u);
}
w->EndArray();
}
void MasterAttributes::WriteBinaryUDPPortsType(writer *w) {
WriteBinary(w, N_UDP_PORTS_TYPE.data(), udpPortTypes);
}
#ifdef HDF5C
void MasterAttributes::WriteHDF5UDPPortEnables(H5::Group *group) {
for (size_t i = 0; i != udpPortType.size(); ++i) {
// convert vector<bool> -> vector<uint8_t>
std::vector<int> vals(udpPortEnables[i].begin(),
udpPortEnables[i].end());
void MasterAttributes::WriteHDF5UDPPortsType(H5::Group *group) {
WriteHDF5StringArray(group, N_UDP_PORTS_TYPE.data(), udpPortTypes);
}
#endif
hsize_t dims[1] = {vals.size()};
H5::DataSpace dataspace(1, dims);
void MasterAttributes::WriteBinaryUDPPortsDisabled(writer *w) {
WriteBinary(w, N_UDP_PORTS_DISBLED.data(), udpPortsDisabled);
}
std::string key = udpPortType[i] + std::string(N_UDP_PORT_ENABLES);
H5::DataSet dataset =
group->createDataSet(key, H5::PredType::NATIVE_UINT32, dataspace);
dataset.write(vals.data(), H5::PredType::NATIVE_UINT32);
}
#ifdef HDF5C
void MasterAttributes::WriteHDF5UDPPortsDisabled(H5::Group *group) {
WriteHDF5Int(group, N_UDP_PORTS_DISBLED.data(), udpPortsDisabled);
}
#endif
+11 -6
View File
@@ -68,8 +68,8 @@ class MasterAttributes {
std::map<std::string, std::string> additionalJsonHeader;
uint64_t framesInFile{0};
slsDetectorDefs::speedLevel readoutSpeed{slsDetectorDefs::FULL_SPEED};
std::array<std::vector<int>, 2> udpPortEnables;
std::array<std::string, 2> udpPortType;
std::vector<std::string> udpPortTypes;
std::vector<int> udpPortsDisabled;
inline static const std::string_view N_DETECTOR_TYPE = "Detector Type";
inline static const std::string_view N_TIMING_MODE = "Timing Mode";
@@ -127,8 +127,9 @@ class MasterAttributes {
inline static const std::string_view N_SCAN_PARAMETERS = "Scan Parameters";
inline static const std::string_view N_ADDITIONAL_JSON_HEADER =
"Additional JSON Header";
inline static const std::string_view N_UDP_PORT_ENABLES =
" UDP Port Enables";
inline static const std::string_view N_UDP_PORTS_DISBLED =
"UDP Ports Disabled";
inline static const std::string_view N_UDP_PORTS_TYPE = "UDP Ports Type";
MasterAttributes() = default;
~MasterAttributes() = default;
@@ -338,9 +339,13 @@ class MasterAttributes {
#ifdef HDF5C
void WriteHDF5TransceiverSamples(H5::Group *group);
#endif
void WriteBinaryUDPPortEnables(writer *w);
void WriteBinaryUDPPortsType(writer *w);
#ifdef HDF5C
void WriteHDF5UDPPortEnables(H5::Group *group);
void WriteHDF5UDPPortsType(H5::Group *group);
#endif
void WriteBinaryUDPPortsDisabled(writer *w);
#ifdef HDF5C
void WriteHDF5UDPPortsDisabled(H5::Group *group);
#endif
/** writes according to type */
template <typename T> void WriteBinaryValue(writer *w, const T &value) {