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
+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);
}
}
}