merge fix

This commit is contained in:
2022-03-28 09:11:32 +02:00
27 changed files with 349 additions and 343 deletions

View File

@ -1274,40 +1274,6 @@ std::string CmdProxy::DetectorStatus(int action) {
return os.str();
}
std::string CmdProxy::RxMissingPackets(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "Number of missing packets for each port in receiver. If "
"negative, they are packets in excess. "
<< '\n';
} else if (action == defs::GET_ACTION) {
if (!args.empty()) {
WrongNumberOfParameters(0);
}
auto mp = det->getNumMissingPackets(std::vector<int>{det_id});
/*
auto tmp = det->getNumMissingPackets(std::vector<int>{det_id});
// convert to signed missing packets (to get excess)
Result<std::vector<int64_t>> mp(tmp.size());
for (unsigned int i = 0; i < mp.size(); ++i) {
mp[i] = static_cast<int64_t>(tmp[i]);
}
OR
Result<std::vector<int64_t>> tmp;
for (auto val : tmp) {
mp.push_back(static_cast<int64_t>(val));
}
*/
os << OutString(mp) << '\n';
} else if (action == defs::PUT_ACTION) {
throw sls::RuntimeError("Cannot put");
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::Scan(int action) {
std::ostringstream os;
os << cmd << ' ';

View File

@ -860,7 +860,8 @@ class CmdProxy {
{"rx_status", &CmdProxy::ReceiverStatus},
{"status", &CmdProxy::DetectorStatus},
{"rx_framescaught", &CmdProxy::rx_framescaught},
{"rx_missingpackets", &CmdProxy::RxMissingPackets},
{"rx_missingpackets", &CmdProxy::rx_missingpackets},
{"rx_frameindex", &CmdProxy::rx_frameindex},
{"nextframenumber", &CmdProxy::nextframenumber},
{"trigger", &CmdProxy::Trigger},
{"scan", &CmdProxy::Scan},
@ -1086,8 +1087,7 @@ class CmdProxy {
{"framecounter", &CmdProxy::framecounter},
{"runtime", &CmdProxy::runtime},
{"frametime", &CmdProxy::frametime},
{"user", &CmdProxy::UserDetails},
{"rx_frameindex", &CmdProxy::rx_frameindex}
{"user", &CmdProxy::UserDetails}
};
@ -1540,11 +1540,15 @@ class CmdProxy {
"to IDLE or STOPPED. Goes to stop server.");
GET_COMMAND(rx_framescaught, getFramesCaught,
"\n\tNumber of frames caught by receiver.");
"\n\tNumber of frames caught by each port in receiver.");
GET_COMMAND(rx_missingpackets, getNumMissingPackets,
"\n\tNumber of missing packets for each port in receiver. "
"Negative number denotes extra packets.");
"\n\tNumber of missing packets for each port in receiver. If "
"negative, they are packets in excess. ");
GET_COMMAND(rx_frameindex, getRxCurrentFrameIndex,
"\n\tCurrent frame index received for each port in receiver "
"during acquisition.");
INTEGER_COMMAND_VEC_ID(
nextframenumber, getNextFrameNumber, setNextFrameNumber,
@ -2262,10 +2266,6 @@ class CmdProxy {
"ns|us|ms|s]\n\t[Jungfrau][Mythen3][Gotthard2][Moench]["
"CTB] Timestamp at a frame start."
"\n\t[Gotthard2] not in burst and auto mode.");
GET_COMMAND(
rx_frameindex, getRxCurrentFrameIndex,
"\n\tCurrent frame index received in receiver during acquisition.");
};
} // namespace sls

View File

@ -829,7 +829,7 @@ Result<defs::runStatus> Detector::getReceiverStatus(Positions pos) const {
return pimpl->Parallel(&Module::getReceiverStatus, pos);
}
Result<int64_t> Detector::getFramesCaught(Positions pos) const {
Result<std::vector<int64_t>> Detector::getFramesCaught(Positions pos) const {
return pimpl->Parallel(&Module::getFramesCaughtByReceiver, pos);
}
@ -838,6 +838,11 @@ Detector::getNumMissingPackets(Positions pos) const {
return pimpl->Parallel(&Module::getNumMissingPackets, pos);
}
Result<std::vector<int64_t>>
Detector::getRxCurrentFrameIndex(Positions pos) const {
return pimpl->Parallel(&Module::getReceiverCurrentFrameIndex, pos);
}
Result<uint64_t> Detector::getNextFrameNumber(Positions pos) const {
return pimpl->Parallel(&Module::getNextFrameNumber, pos);
}
@ -871,7 +876,7 @@ Result<std::string> Detector::getScanErrorMessage(Positions pos) const {
Result<int> Detector::getNumberofUDPInterfaces(Positions pos) const {
// also called by vetostream (for gotthard2)
return pimpl->getNumberofUDPInterfaces(pos);
return pimpl->Parallel(&Module::getNumberofUDPInterfacesFromShm, pos);
}
void Detector::setNumberofUDPInterfaces(int n, Positions pos) {
@ -1739,7 +1744,7 @@ Result<defs::streamingInterface> Detector::getVetoStream(Positions pos) const {
// 3gbe
auto r3 = pimpl->Parallel(&Module::getVetoStream, pos);
// 10gbe (debugging interface) opens 2nd udp interface in receiver
auto r10 = pimpl->getNumberofUDPInterfaces(pos);
auto r10 = getNumberofUDPInterfaces(pos);
Result<defs::streamingInterface> res(r3.size());
for (unsigned int i = 0; i < res.size(); ++i) {
@ -1761,7 +1766,7 @@ void Detector::setVetoStream(defs::streamingInterface interface,
pimpl->Parallel(&Module::setVetoStream, pos, LOW_LATENCY_LINK);
// 10gbe (debugging interface) opens 2nd udp interface in receiver
int old_numinterfaces = pimpl->getNumberofUDPInterfaces(pos).tsquash(
int old_numinterfaces = getNumberofUDPInterfaces(pos).tsquash(
"retrieved inconsistent number of udp interfaces");
int numinterfaces =
(((interface & defs::streamingInterface::ETHERNET_10GB) ==
@ -2351,12 +2356,8 @@ Result<ns> Detector::getMeasurementTime(Positions pos) const {
std::string Detector::getUserDetails() const { return pimpl->getUserDetails(); }
Result<uint64_t> Detector::getRxCurrentFrameIndex(Positions pos) const {
return pimpl->Parallel(&Module::getReceiverCurrentFrameIndex, pos);
}
std::vector<int> Detector::getPortNumbers(int start_port) {
int num_sockets_per_detector = pimpl->getNumberofUDPInterfaces({}).tsquash(
int num_sockets_per_detector = getNumberofUDPInterfaces({}).tsquash(
"Number of UDP Interfaces is not consistent among modules");
std::vector<int> res;
res.reserve(size());

View File

@ -245,15 +245,6 @@ void DetectorImpl::setHostname(const std::vector<std::string> &name) {
addModule(hostname);
}
updateDetectorSize();
// update zmq port (especially for eiger)
int numInterfaces = modules[0]->getNumberofUDPInterfaces();
if (numInterfaces == 2) {
for (size_t i = 0; i < modules.size(); ++i) {
modules[i]->setClientStreamingPort(DEFAULT_ZMQ_CL_PORTNO +
i * numInterfaces);
}
}
}
void DetectorImpl::addModule(const std::string &hostname) {
@ -281,6 +272,13 @@ void DetectorImpl::addModule(const std::string &hostname) {
// get type by connecting
detectorType type = Module::getTypeFromDetector(host, port);
// gotthard cannot have more than 2 modules (50um=1, 25um=2
if ((type == GOTTHARD || type == GOTTHARD2) && modules.size() > 2) {
freeSharedMemory();
throw sls::RuntimeError("Gotthard cannot have more than 2 modules");
}
auto pos = modules.size();
modules.emplace_back(
sls::make_unique<Module>(type, detectorIndex, pos, false));
@ -288,11 +286,20 @@ void DetectorImpl::addModule(const std::string &hostname) {
modules[pos]->setControlPort(port);
modules[pos]->setStopPort(port + 1);
modules[pos]->setHostname(host, shm()->initialChecks);
// module type updated by now
shm()->detType = Parallel(&Module::getDetectorType, {})
.tsquash("Inconsistent detector types.");
// for moench and ctb
modules[pos]->updateNumberOfChannels();
// for eiger, jungfrau, gotthard2
modules[pos]->updateNumberofUDPInterfaces();
// update zmq port in case numudpinterfaces changed
int numInterfaces = modules[pos]->getNumberofUDPInterfacesFromShm();
modules[pos]->setClientStreamingPort(DEFAULT_ZMQ_CL_PORTNO +
pos * numInterfaces);
}
void DetectorImpl::updateDetectorSize() {
@ -1142,7 +1149,7 @@ int DetectorImpl::acquire() {
if (acquisition_finished != nullptr) {
int status = Parallel(&Module::getRunStatus, {}).squash(ERROR);
auto a = Parallel(&Module::getReceiverProgress, {});
double progress = (*std::min_element(a.begin(), a.end()));
double progress = (*std::max_element(a.begin(), a.end()));
acquisition_finished(progress, status, acqFinished_p);
}
@ -1361,10 +1368,6 @@ std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
return buffer;
}
sls::Result<int> DetectorImpl::getNumberofUDPInterfaces(Positions pos) const {
return Parallel(&Module::getNumberofUDPInterfaces, pos);
}
sls::Result<int> DetectorImpl::getDefaultDac(defs::dacIndex index,
defs::detectorSettings sett,
Positions pos) {

View File

@ -291,7 +291,6 @@ class DetectorImpl : public virtual slsDetectorDefs {
*/
std::vector<char> readProgrammingFile(const std::string &fname);
sls::Result<int> getNumberofUDPInterfaces(Positions pos) const;
void setNumberofUDPInterfaces(int n, Positions pos);
sls::Result<int> getDefaultDac(defs::dacIndex index,
defs::detectorSettings sett,

View File

@ -873,8 +873,26 @@ double Module::getReceiverProgress() const {
return sendToReceiver<double>(F_GET_RECEIVER_PROGRESS);
}
int64_t Module::getFramesCaughtByReceiver() const {
return sendToReceiver<int64_t>(F_GET_RECEIVER_FRAMES_CAUGHT);
std::vector<int64_t> Module::getFramesCaughtByReceiver() const {
// TODO!(Erik) Refactor
LOG(logDEBUG1) << "Getting frames caught";
if (shm()->useReceiverFlag) {
auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort);
client.Send(F_GET_RECEIVER_FRAMES_CAUGHT);
if (client.Receive<int>() == FAIL) {
throw ReceiverError(
"Receiver " + std::to_string(moduleIndex) +
" returned error: " + client.readErrorMessage());
} else {
auto nports = client.Receive<int>();
std::vector<int64_t> retval(nports);
client.Receive(retval);
LOG(logDEBUG1) << "Frames caught of Receiver" << moduleIndex << ": "
<< sls::ToString(retval);
return retval;
}
}
throw RuntimeError("No receiver to get frames caught.");
}
std::vector<int64_t> Module::getNumMissingPackets() const {
@ -899,6 +917,28 @@ std::vector<int64_t> Module::getNumMissingPackets() const {
throw RuntimeError("No receiver to get missing packets.");
}
std::vector<int64_t> Module::getReceiverCurrentFrameIndex() const {
// TODO!(Erik) Refactor
LOG(logDEBUG1) << "Getting frame index";
if (shm()->useReceiverFlag) {
auto client = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort);
client.Send(F_GET_RECEIVER_FRAME_INDEX);
if (client.Receive<int>() == FAIL) {
throw ReceiverError(
"Receiver " + std::to_string(moduleIndex) +
" returned error: " + client.readErrorMessage());
} else {
auto nports = client.Receive<int>();
std::vector<int64_t> retval(nports);
client.Receive(retval);
LOG(logDEBUG1) << "Frame index of Receiver" << moduleIndex << ": "
<< sls::ToString(retval);
return retval;
}
}
throw RuntimeError("No receiver to get frame index.");
}
uint64_t Module::getNextFrameNumber() const {
return sendToDetector<uint64_t>(F_GET_NEXT_FRAME_NUMBER);
}
@ -936,9 +976,8 @@ int Module::getNumberofUDPInterfacesFromShm() const {
return shm()->numUDPInterfaces;
}
int Module::getNumberofUDPInterfaces() const {
void Module::updateNumberofUDPInterfaces() {
shm()->numUDPInterfaces = sendToDetector<int>(F_GET_NUM_INTERFACES);
return shm()->numUDPInterfaces;
}
void Module::setNumberofUDPInterfaces(int n) {
@ -1146,7 +1185,7 @@ std::string Module::printReceiverConfiguration() {
<< getReceiverHostname();
if (shm()->detType == JUNGFRAU) {
os << "\nNumber of Interfaces:\t" << getNumberofUDPInterfaces()
os << "\nNumber of Interfaces:\t" << getNumberofUDPInterfacesFromShm()
<< "\nSelected Interface:\t" << getSelectedUDPInterface();
}
@ -2758,10 +2797,6 @@ int64_t Module::getMeasurementTime() const {
return sendToDetectorStop<int64_t>(F_GET_MEASUREMENT_TIME);
}
uint64_t Module::getReceiverCurrentFrameIndex() const {
return sendToReceiver<uint64_t>(F_GET_RECEIVER_FRAME_INDEX);
}
// private
void Module::checkArgs(const void *args, size_t args_size, void *retval,
@ -3185,10 +3220,10 @@ void Module::initializeModuleStructure(detectorType type) {
sls::strcpy_safe(shm()->rxHostname, "none");
shm()->rxTCPPort = DEFAULT_PORTNO + 2;
shm()->useReceiverFlag = false;
shm()->numUDPInterfaces = 1;
shm()->zmqport =
DEFAULT_ZMQ_CL_PORTNO + moduleIndex * shm()->numUDPInterfaces;
shm()->zmqip = IpAddr{};
shm()->numUDPInterfaces = 1;
shm()->stoppedFlag = false;
// get the Module parameters based on type

View File

@ -203,8 +203,9 @@ class Module : public virtual slsDetectorDefs {
runStatus getRunStatus() const;
runStatus getReceiverStatus() const;
double getReceiverProgress() const;
int64_t getFramesCaughtByReceiver() const;
std::vector<int64_t> getFramesCaughtByReceiver() const;
std::vector<int64_t> getNumMissingPackets() const;
std::vector<int64_t> getReceiverCurrentFrameIndex() const;
uint64_t getNextFrameNumber() const;
void setNextFrameNumber(uint64_t value);
void sendSoftwareTrigger(const bool block);
@ -218,7 +219,7 @@ class Module : public virtual slsDetectorDefs {
* *
* ************************************************/
int getNumberofUDPInterfacesFromShm() const;
int getNumberofUDPInterfaces() const;
void updateNumberofUDPInterfaces();
void setNumberofUDPInterfaces(int n);
int getSelectedUDPInterface() const;
void selectUDPInterface(int n);
@ -582,7 +583,6 @@ class Module : public virtual slsDetectorDefs {
int64_t getNumberOfFramesFromStart() const;
int64_t getActualTime() const;
int64_t getMeasurementTime() const;
uint64_t getReceiverCurrentFrameIndex() const;
private:
void checkArgs(const void *args, size_t args_size, void *retval,