merge fix

This commit is contained in:
maliakal_d 2022-03-21 11:08:02 +01:00
parent f2b8aa9dbd
commit 5508f0135d
2 changed files with 2731 additions and 2793 deletions

View File

@ -211,7 +211,8 @@
}
/** int or enum */
#define INTEGER_COMMAND_VEC_ID_PUT_SINGLE_ID(CMDNAME, GETFCN, SETFCN, CONV, HLPSTR) \
#define INTEGER_COMMAND_VEC_ID_PUT_SINGLE_ID(CMDNAME, GETFCN, SETFCN, CONV, \
HLPSTR) \
std::string CMDNAME(const int action) { \
std::ostringstream os; \
os << cmd << ' '; \
@ -236,7 +237,8 @@
return os.str(); \
}
#define INTEGER_COMMAND_VEC_ID_P_RX_SINGLE_ID(CMDNAME, GETFCN, SETFCN, CONV, HLPSTR) \
#define INTEGER_COMMAND_VEC_ID_P_RX_SINGLE_ID(CMDNAME, GETFCN, SETFCN, CONV, \
HLPSTR) \
std::string CMDNAME(const int action) { \
std::ostringstream os; \
os << cmd << ' '; \
@ -1352,7 +1354,7 @@ class CmdProxy {
"interfaces must be set to 2. slsReceiver and slsDetectorGui "
"does not handle.");
INTEGER_COMMAND_VEC_ID_GET(
INTEGER_COMMAND_VEC_ID_PUT_SINGLE_ID(
master, getMaster, setMaster, StringTo<int>,
"[0, 1]\n\t[Eiger] Sets half module to master and "
"others to slaves.\n\t[Gotthard][Gotthard2][Mythen3][Eiger] "

View File

@ -1115,6 +1115,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
}
}
}
}
sls::IpAddr Module::getDestinationUDPIP2(const int rxIndex) const {
if (rxIndex < 0 || rxIndex >= MAX_UDP_DESTINATION) {
@ -1135,8 +1136,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
}
if (ip.str() == LOCALHOST_IP && !isVirtualDetectorServer()) {
throw RuntimeError(
"Invalid destination udp ip2. Change rx_hostname "
throw RuntimeError("Invalid destination udp ip2. Change rx_hostname "
"from localhost or change udp_dstip from auto?");
}
@ -1152,11 +1152,10 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
if (shm()->useReceiverFlag) {
sls::MacAddr retval(0LU);
sendToReceiver(entries[iEntry], F_SET_RECEIVER_UDP_IP2, ip,
retval);
LOG(logINFO)
<< "Setting destination udp mac2 of Module " << moduleIndex
<< ", " << entries[iEntry] << "] to " << retval;
sendToReceiver(entries[iEntry], F_SET_RECEIVER_UDP_IP2, ip, retval);
LOG(logINFO) << "Setting destination udp mac2 of Module "
<< moduleIndex << ", " << entries[iEntry] << "] to "
<< retval;
if (entries[iEntry] == 0) {
sendToDetector(F_SET_DEST_UDP_MAC2, retval, nullptr);
} else {
@ -1280,9 +1279,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
}
}
void Module::reconfigureUDPDestination() {
sendToDetector(F_RECONFIGURE_UDP);
}
void Module::reconfigureUDPDestination() { sendToDetector(F_RECONFIGURE_UDP); }
void Module::validateUDPConfiguration() {
sendToDetector(F_VALIDATE_UDP_CONFIG);
@ -1292,9 +1289,8 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
std::ostringstream os;
std::vector<int> entries = getEntryList(rxIndex);
for (int iEntry = 0; iEntry != (int)entries.size(); ++iEntry) {
os << "\n\nModule " << moduleIndex << "\nReceiver ["
<< entries[iEntry] << "] Hostname:\t"
<< getReceiverHostname(entries[iEntry]);
os << "\n\nModule " << moduleIndex << "\nReceiver [" << entries[iEntry]
<< "] Hostname:\t" << getReceiverHostname(entries[iEntry]);
if (shm()->detType == JUNGFRAU) {
os << "\nNumber of Interfaces:\t" << getNumberofUDPInterfaces()
@ -1302,9 +1298,8 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
}
auto t = getDestinationUDPList(entries[iEntry]);
os << "\nSource UDP IP:\t" << getSourceUDPIP()
<< "\nSource UDP MAC:\t" << getSourceUDPMAC()
<< "\nDestination UDP IP:\t" << t.ip
os << "\nSource UDP IP:\t" << getSourceUDPIP() << "\nSource UDP MAC:\t"
<< getSourceUDPMAC() << "\nDestination UDP IP:\t" << t.ip
<< "\nDestination UDP MAC:\t" << t.mac;
if (shm()->detType == JUNGFRAU) {
@ -1378,8 +1373,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
return std::string(shm()->receivers[rxIndex].hostname);
}
void Module::setAllReceiverHostnames(
const std::vector<std::string> &receiver) {
void Module::setAllReceiverHostnames(const std::vector<std::string> &receiver) {
if (receiver.size() == 1) {
setReceiverHostname(receiver[0], 0);
} else {
@ -1494,8 +1488,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
int Module::getReceiverFifoDepth() const {
const int rxIndex = 0;
return sendToReceiver<int>(rxIndex, F_SET_RECEIVER_FIFO_DEPTH,
GET_FLAG);
return sendToReceiver<int>(rxIndex, F_SET_RECEIVER_FIFO_DEPTH, GET_FLAG);
}
void Module::setReceiverFifoDepth(int n_frames) {
@ -1514,17 +1507,17 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
static_cast<int>(enable), nullptr);
}
slsDetectorDefs::frameDiscardPolicy Module::getReceiverFramesDiscardPolicy()
const {
slsDetectorDefs::frameDiscardPolicy
Module::getReceiverFramesDiscardPolicy() const {
const int rxIndex = 0;
return sendToReceiver<frameDiscardPolicy>(
rxIndex, F_GET_RECEIVER_DISCARD_POLICY);
return sendToReceiver<frameDiscardPolicy>(rxIndex,
F_GET_RECEIVER_DISCARD_POLICY);
}
void Module::setReceiverFramesDiscardPolicy(frameDiscardPolicy f) {
const int rxIndex = -1;
sendToReceiver(rxIndex, F_SET_RECEIVER_DISCARD_POLICY,
static_cast<int>(f), nullptr);
sendToReceiver(rxIndex, F_SET_RECEIVER_DISCARD_POLICY, static_cast<int>(f),
nullptr);
}
bool Module::getPartialFramesPadding() const {
@ -1534,8 +1527,8 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
void Module::setPartialFramesPadding(bool padding) {
const int rxIndex = -1;
sendToReceiver(rxIndex, F_SET_RECEIVER_PADDING,
static_cast<int>(padding), nullptr);
sendToReceiver(rxIndex, F_SET_RECEIVER_PADDING, static_cast<int>(padding),
nullptr);
}
int Module::getReceiverUDPSocketBufferSize() const {
@ -1551,8 +1544,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
void Module::setReceiverUDPSocketBufferSize(int udpsockbufsize) {
const int rxIndex = -1;
sendToReceiver<int>(rxIndex, F_RECEIVER_UDP_SOCK_BUF_SIZE,
udpsockbufsize);
sendToReceiver<int>(rxIndex, F_RECEIVER_UDP_SOCK_BUF_SIZE, udpsockbufsize);
}
bool Module::getReceiverLock() const {
@ -1567,8 +1559,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
sls::IpAddr Module::getReceiverLastClientIP() const {
const int rxIndex = 0;
return sendToReceiver<sls::IpAddr>(rxIndex,
F_GET_LAST_RECEIVER_CLIENT_IP);
return sendToReceiver<sls::IpAddr>(rxIndex, F_GET_LAST_RECEIVER_CLIENT_IP);
}
std::array<pid_t, NUM_RX_THREAD_IDS> Module::getReceiverThreadIds() const {
@ -1578,11 +1569,13 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
}
bool Module::getRxArping() const {
return sendToReceiver<int>(F_GET_RECEIVER_ARPING);
const int rxIndex = 0;
return sendToReceiver<int>(rxIndex, F_GET_RECEIVER_ARPING);
}
void Module::setRxArping(bool enable) {
sendToReceiver(F_SET_RECEIVER_ARPING, static_cast<int>(enable),
const int rxIndex = -1;
sendToReceiver(rxIndex, F_SET_RECEIVER_ARPING, static_cast<int>(enable),
nullptr);
}
@ -1653,8 +1646,8 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
void Module::setFileWrite(bool value) {
const int rxIndex = -1;
sendToReceiver(rxIndex, F_SET_RECEIVER_FILE_WRITE,
static_cast<int>(value), nullptr);
sendToReceiver(rxIndex, F_SET_RECEIVER_FILE_WRITE, static_cast<int>(value),
nullptr);
}
bool Module::getMasterFileWrite() const {
@ -1675,8 +1668,8 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
void Module::setFileOverWrite(bool value) {
const int rxIndex = -1;
sendToReceiver(rxIndex, F_SET_RECEIVER_OVERWRITE,
static_cast<int>(value), nullptr);
sendToReceiver(rxIndex, F_SET_RECEIVER_OVERWRITE, static_cast<int>(value),
nullptr);
}
int Module::getFramesPerFile() const {
@ -1686,8 +1679,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
void Module::setFramesPerFile(int n_frames) {
const int rxIndex = -1;
sendToReceiver(rxIndex, F_SET_RECEIVER_FRAMES_PER_FILE, n_frames,
nullptr);
sendToReceiver(rxIndex, F_SET_RECEIVER_FRAMES_PER_FILE, n_frames, nullptr);
}
// ZMQ Streaming Parameters (Receiver<->Client)
@ -1699,8 +1691,8 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
void Module::setReceiverStreaming(bool enable) {
const int rxIndex = -1;
sendToReceiver(rxIndex, F_SET_RECEIVER_STREAMING,
static_cast<int>(enable), nullptr);
sendToReceiver(rxIndex, F_SET_RECEIVER_STREAMING, static_cast<int>(enable),
nullptr);
}
int Module::getReceiverStreamingFrequency() const {
@ -1714,14 +1706,12 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
std::to_string(freq));
}
const int rxIndex = -1;
sendToReceiver(rxIndex, F_SET_RECEIVER_STREAMING_FREQUENCY, freq,
nullptr);
sendToReceiver(rxIndex, F_SET_RECEIVER_STREAMING_FREQUENCY, freq, nullptr);
}
int Module::getReceiverStreamingTimer() const {
const int rxIndex = 0;
return sendToReceiver<int>(rxIndex, F_RECEIVER_STREAMING_TIMER,
GET_FLAG);
return sendToReceiver<int>(rxIndex, F_RECEIVER_STREAMING_TIMER, GET_FLAG);
}
void Module::setReceiverStreamingTimer(int time_in_ms) {
@ -1731,8 +1721,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
int Module::getReceiverStreamingStartingFrame() const {
const int rxIndex = 0;
return sendToReceiver<int>(rxIndex,
F_GET_RECEIVER_STREAMING_START_FNUM);
return sendToReceiver<int>(rxIndex, F_GET_RECEIVER_STREAMING_START_FNUM);
}
void Module::setReceiverStreamingStartingFrame(int fnum) {
@ -1741,8 +1730,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
std::to_string(fnum));
}
const int rxIndex = -1;
sendToReceiver(rxIndex, F_SET_RECEIVER_STREAMING_START_FNUM, fnum,
nullptr);
sendToReceiver(rxIndex, F_SET_RECEIVER_STREAMING_START_FNUM, fnum, nullptr);
}
int Module::getReceiverStreamingPort() const {
@ -1763,8 +1751,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
F_GET_RECEIVER_STREAMING_SRC_IP);
}
void Module::setReceiverStreamingIP(const sls::IpAddr ip,
const int rxIndex) {
void Module::setReceiverStreamingIP(const sls::IpAddr ip, const int rxIndex) {
if (ip == 0) {
throw RuntimeError("Invalid receiver zmq ip address");
}
@ -1831,8 +1818,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
sendToDetector(F_SET_SUB_DEADTIME, value, nullptr);
if (shm()->useReceiverFlag) {
const int rxIndex = -1;
sendToReceiver(rxIndex, F_RECEIVER_SET_SUB_DEADTIME, value,
nullptr);
sendToReceiver(rxIndex, F_RECEIVER_SET_SUB_DEADTIME, value, nullptr);
}
}
@ -1858,8 +1844,8 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
}
void Module::sendReceiverRateCorrections(const std::vector<int64_t> &t) {
LOG(logDEBUG) << "Sending to receiver 0 [rate corrections: "
<< ToString(t) << ']';
LOG(logDEBUG) << "Sending to receiver 0 [rate corrections: " << ToString(t)
<< ']';
// only to master receiver
auto receiver = ReceiverSocket(shm()->receivers[0].hostname,
shm()->receivers[0].tcpPort);
@ -1867,8 +1853,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
receiver.Send(static_cast<int>(t.size()));
receiver.Send(t);
if (receiver.Receive<int>() == FAIL) {
throw RuntimeError(
"Receiver " + std::to_string(moduleIndex) +
throw RuntimeError("Receiver " + std::to_string(moduleIndex) +
" returned error: " + receiver.readErrorMessage());
}
}
@ -1878,8 +1863,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
}
void Module::setInterruptSubframe(const bool enable) {
sendToDetector(F_SET_INTERRUPT_SUBFRAME, static_cast<int>(enable),
nullptr);
sendToDetector(F_SET_INTERRUPT_SUBFRAME, static_cast<int>(enable), nullptr);
}
int64_t Module::getMeasuredPeriod() const {
@ -1913,8 +1897,8 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
}
bool Module::getCounterBit() const {
return (!static_cast<bool>(
sendToDetector<int>(F_SET_COUNTER_BIT, GET_FLAG)));
return (
!static_cast<bool>(sendToDetector<int>(F_SET_COUNTER_BIT, GET_FLAG)));
}
void Module::setCounterBit(bool cb) {
@ -1935,9 +1919,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
sendToDetector(F_PULSE_CHIP, n_pulses, nullptr);
}
bool Module::getQuad() const {
return sendToDetector<int>(F_GET_QUAD) != 0;
}
bool Module::getQuad() const { return sendToDetector<int>(F_GET_QUAD) != 0; }
void Module::setQuad(const bool enable) {
int value = enable ? 1 : 0;
@ -2125,14 +2107,13 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
const std::vector<int> &values) {
const int nch = gainIndices.size();
if (gainIndices.size() != values.size()) {
throw RuntimeError(
"Number of Gain Indices and values do not match! "
throw RuntimeError("Number of Gain Indices and values do not match! "
"Gain Indices size: " +
std::to_string(gainIndices.size()) +
", values size: " + std::to_string(values.size()));
}
LOG(logDEBUG1) << "Sending veto photon/file to detector [chip:"
<< chipIndex << ", nch:" << nch << "]";
LOG(logDEBUG1) << "Sending veto photon/file to detector [chip:" << chipIndex
<< ", nch:" << nch << "]";
const int args[]{chipIndex, nch};
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
@ -2141,29 +2122,27 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
client.Send(gainIndices);
client.Send(values);
if (client.Receive<int>() == FAIL) {
throw DetectorError(
"Detector " + std::to_string(moduleIndex) +
throw DetectorError("Detector " + std::to_string(moduleIndex) +
" returned error: " + client.readErrorMessage());
}
}
void Module::getVetoPhoton(const int chipIndex, const std::string &fname)
const {
void Module::getVetoPhoton(const int chipIndex,
const std::string &fname) const {
LOG(logDEBUG1) << "Getting veto photon [" << chipIndex << "]\n";
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.Send(F_GET_VETO_PHOTON);
client.Send(chipIndex);
if (client.Receive<int>() == FAIL) {
throw DetectorError(
"Detector " + std::to_string(moduleIndex) +
throw DetectorError("Detector " + std::to_string(moduleIndex) +
" returned error: " + client.readErrorMessage());
}
auto nch = client.Receive<int>();
if (nch != shm()->nChan.x) {
throw DetectorError("Could not get veto photon. Expected " +
std::to_string(shm()->nChan.x) +
" channels, got " + std::to_string(nch));
std::to_string(shm()->nChan.x) + " channels, got " +
std::to_string(nch));
}
std::vector<int> gainIndices(nch);
std::vector<int> values(nch);
@ -2188,8 +2167,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
"Set Veto reference is not implemented for this detector");
}
if (chipIndex < -1 || chipIndex >= shm()->nChip.x) {
throw RuntimeError(
"Could not set veto photon. Invalid chip index: " +
throw RuntimeError("Could not set veto photon. Invalid chip index: " +
std::to_string(chipIndex));
}
if (numPhotons < 1) {
@ -2203,8 +2181,8 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
}
std::ifstream infile(fname.c_str());
if (!infile) {
throw RuntimeError(
"Could not set veto photon. Could not open file: " + fname);
throw RuntimeError("Could not set veto photon. Could not open file: " +
fname);
}
LOG(logDEBUG1) << "Setting veto photon. Reading Gain values from file";
@ -2228,11 +2206,10 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
double gainValue[3] = {-1, -1, -1};
int gainThreshold[2] = {-1, -1};
ss >> gainPedestal[0] >> gainPedestal[1] >> gainPedestal[2] >>
gainValue[0] >> gainValue[1] >> gainValue[2] >>
gainThreshold[0] >> gainThreshold[1];
gainValue[0] >> gainValue[1] >> gainValue[2] >> gainThreshold[0] >>
gainThreshold[1];
if (ss.fail()) {
throw RuntimeError(
"Could not set veto photon. Invalid pedestals, "
throw RuntimeError("Could not set veto photon. Invalid pedestals, "
"gain values or gain thresholds for channel " +
std::to_string(gainIndices.size()));
}
@ -2305,9 +2282,9 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
try {
value = StringTo<int>(val);
} catch (...) {
throw RuntimeError(
"Could not set veto file. Invalid value " + val +
" for channel " + std::to_string(gainIndices.size()));
throw RuntimeError("Could not set veto file. Invalid value " +
val + " for channel " +
std::to_string(gainIndices.size()));
}
gainIndices.push_back(gainIndex);
values.push_back(value);
@ -2336,9 +2313,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
}
}
bool Module::getCDSGain() const {
return sendToDetector<int>(F_GET_CDS_GAIN);
}
bool Module::getCDSGain() const { return sendToDetector<int>(F_GET_CDS_GAIN); }
void Module::setCDSGain(bool value) {
sendToDetector(F_SET_CDS_GAIN, static_cast<int>(value), nullptr);
@ -2379,8 +2354,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
sendToDetector(F_SET_VETO_ALGORITHM, args, nullptr);
}
int Module::getADCConfiguration(const int chipIndex, const int adcIndex)
const {
int Module::getADCConfiguration(const int chipIndex, const int adcIndex) const {
int args[]{chipIndex, adcIndex};
return sendToDetector<int>(F_GET_ADC_CONFIGURATION, args);
}
@ -2396,8 +2370,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.Send(F_GET_BAD_CHANNELS);
if (client.Receive<int>() == FAIL) {
throw DetectorError(
"Detector " + std::to_string(moduleIndex) +
throw DetectorError("Detector " + std::to_string(moduleIndex) +
" returned error: " + client.readErrorMessage());
}
// receive badchannels
@ -2436,8 +2409,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
int ival = 0;
iss >> ival;
if (iss.fail()) {
throw RuntimeError(
"Could not load bad channels file. Invalid "
throw RuntimeError("Could not load bad channels file. Invalid "
"channel number at position " +
std::to_string(badchannels.size()));
}
@ -2455,8 +2427,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
client.Send(badchannels);
}
if (client.Receive<int>() == FAIL) {
throw DetectorError(
"Detector " + std::to_string(moduleIndex) +
throw DetectorError("Detector " + std::to_string(moduleIndex) +
" returned error: " + client.readErrorMessage());
}
}
@ -2508,8 +2479,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
}
std::array<time::ns, 3> Module::getGateDelayForAllGates() const {
return sendToDetector<std::array<time::ns, 3>>(
F_GET_GATE_DELAY_ALL_GATES);
return sendToDetector<std::array<time::ns, 3>>(F_GET_GATE_DELAY_ALL_GATES);
}
int Module::getChipStatusRegister() const {
@ -2636,8 +2606,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
void Module::setReceiverDbitList(std::vector<int> list) {
LOG(logDEBUG1) << "Setting Receiver Dbit List";
if (list.size() > 64) {
throw sls::RuntimeError(
"Dbit list size cannot be greater than 64\n");
throw sls::RuntimeError("Dbit list size cannot be greater than 64\n");
}
for (auto &it : list) {
if (it < 0 || it > 63) {
@ -2689,9 +2658,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
return pat;
}
void Module::loadDefaultPattern() {
sendToDetector(F_LOAD_DEFAULT_PATTERN);
}
void Module::loadDefaultPattern() { sendToDetector(F_LOAD_DEFAULT_PATTERN); }
uint64_t Module::getPatternIOControl() const {
return sendToDetector<uint64_t>(F_SET_PATTERN_IO_CONTROL,
@ -2781,8 +2748,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
// TODO, refactor this function with a more robust sending.
// Now assuming whitespace separated key value
if (!shm()->useReceiverFlag) {
throw RuntimeError(
"Set rx_hostname first to use receiver parameters "
throw RuntimeError("Set rx_hostname first to use receiver parameters "
"(zmq json header)");
}
const int rxIndex = 0;
@ -2790,8 +2756,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
shm()->receivers[rxIndex].tcpPort);
client.Send(F_GET_ADDITIONAL_JSON_HEADER);
if (client.Receive<int>() == FAIL) {
throw ReceiverError(
"Receiver " + std::to_string(moduleIndex) +
throw ReceiverError("Receiver " + std::to_string(moduleIndex) +
" returned error: " + client.readErrorMessage());
} else {
auto size = client.Receive<int>();
@ -2806,8 +2771,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
retval[key] = value;
}
}
LOG(logDEBUG) << "Getting additional json header "
<< ToString(retval);
LOG(logDEBUG) << "Getting additional json header " << ToString(retval);
return retval;
}
}
@ -2815,8 +2779,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
void Module::setAdditionalJsonHeader(
const std::map<std::string, std::string> &jsonHeader) {
if (!shm()->useReceiverFlag) {
throw RuntimeError(
"Set rx_hostname first to use receiver parameters "
throw RuntimeError("Set rx_hostname first to use receiver parameters "
"(zmq json header)");
}
for (auto &it : jsonHeader) {
@ -2844,14 +2807,12 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
client.Send(&buff[0], buff.size());
if (client.Receive<int>() == FAIL) {
throw ReceiverError(
"Receiver " + std::to_string(moduleIndex) +
throw ReceiverError("Receiver " + std::to_string(moduleIndex) +
" returned error: " + client.readErrorMessage());
}
}
std::string Module::getAdditionalJsonParameter(const std::string &key)
const {
std::string Module::getAdditionalJsonParameter(const std::string &key) const {
char arg[SHORT_STR_LENGTH]{};
sls::strcpy_safe(arg, key.c_str());
char retval[SHORT_STR_LENGTH]{};
@ -2902,8 +2863,8 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
sls::strcpy_safe(args[0], fname.c_str());
sls::strcpy_safe(args[1], hostname.c_str());
LOG(logINFO) << "Module " << moduleIndex << " (" << shm()->hostname
<< "): Sending detector server " << args[0]
<< " from host " << args[1];
<< "): Sending detector server " << args[0] << " from host "
<< args[1];
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
client.Send(F_COPY_DET_SERVER);
client.Send(args);
@ -2952,8 +2913,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
sendProgram(false, buffer, F_UPDATE_KERNEL, "Update Kernel");
break;
default:
throw RuntimeError(
"Updating Kernel via the package is not implemented "
throw RuntimeError("Updating Kernel via the package is not implemented "
"for this detector");
}
}
@ -2969,8 +2929,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
}
void Module::setUpdateMode(const bool updatemode) {
sendToDetector(F_SET_UPDATE_MODE, static_cast<int>(updatemode),
nullptr);
sendToDetector(F_SET_UPDATE_MODE, static_cast<int>(updatemode), nullptr);
LOG(logINFO) << "Module " << moduleIndex << " (" << shm()->hostname
<< "): Update Mode set to " << updatemode << "!";
}
@ -2986,8 +2945,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
void Module::setBit(uint32_t addr, int n) {
if (n < 0 || n > 31) {
throw RuntimeError("Bit number " + std::to_string(n) +
" out of Range");
throw RuntimeError("Bit number " + std::to_string(n) + " out of Range");
} else {
uint32_t val = readRegister(addr);
writeRegister(addr, val | 1 << n);
@ -2996,8 +2954,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
void Module::clearBit(uint32_t addr, int n) {
if (n < 0 || n > 31) {
throw RuntimeError("Bit number " + std::to_string(n) +
" out of Range");
throw RuntimeError("Bit number " + std::to_string(n) + " out of Range");
} else {
uint32_t val = readRegister(addr);
writeRegister(addr, val & ~(1 << n));
@ -3006,8 +2963,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
int Module::getBit(uint32_t addr, int n) {
if (n < 0 || n > 31) {
throw RuntimeError("Bit number " + std::to_string(n) +
" out of Range");
throw RuntimeError("Bit number " + std::to_string(n) + " out of Range");
} else {
return ((readRegister(addr) >> n) & 0x1);
}
@ -3153,8 +3109,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
}
template <typename Arg>
void Module::sendToDetector(int fnum, const Arg &args, std::nullptr_t)
const {
void Module::sendToDetector(int fnum, const Arg &args, std::nullptr_t) const {
LOG(logDEBUG1) << "Sending: ["
<< getFunctionNameFromEnum(static_cast<detFuncs>(fnum))
<< ", " << typeid(Arg).name() << ", " << sizeof(Arg)
@ -3181,8 +3136,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
template <typename Ret>
void Module::sendToDetector(int fnum, std::nullptr_t, Ret &retval) {
static_cast<const Module &>(*this).sendToDetector(fnum, nullptr,
retval);
static_cast<const Module &>(*this).sendToDetector(fnum, nullptr, retval);
}
void Module::sendToDetector(int fnum) const {
@ -3228,16 +3182,14 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
template <typename Ret, typename Arg>
Ret Module::sendToDetector(int fnum, const Arg &args) {
return static_cast<const Module &>(*this).sendToDetector<Ret>(fnum,
args);
return static_cast<const Module &>(*this).sendToDetector<Ret>(fnum, args);
}
//----------------------------------------------------------
// sendToDetectorStop
void Module::sendToDetectorStop(int fnum, const void *args,
size_t args_size, void *retval,
size_t retval_size) const {
void Module::sendToDetectorStop(int fnum, const void *args, size_t args_size,
void *retval, size_t retval_size) const {
// This is the only function that actually sends data to the detector
// stop the other versions use templates to deduce sizes and create the
// return type
@ -3247,16 +3199,14 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
stop.close();
}
void Module::sendToDetectorStop(int fnum, const void *args,
size_t args_size, void *retval,
size_t retval_size) {
static_cast<const Module &>(*this).sendToDetectorStop(
fnum, args, args_size, retval, retval_size);
void Module::sendToDetectorStop(int fnum, const void *args, size_t args_size,
void *retval, size_t retval_size) {
static_cast<const Module &>(*this).sendToDetectorStop(fnum, args, args_size,
retval, retval_size);
}
template <typename Arg, typename Ret>
void Module::sendToDetectorStop(int fnum, const Arg &args, Ret &retval)
const {
void Module::sendToDetectorStop(int fnum, const Arg &args, Ret &retval) const {
LOG(logDEBUG1) << "Sending to Stop: ["
<< getFunctionNameFromEnum(static_cast<detFuncs>(fnum))
<< ", " << args << ", " << sizeof(args) << ", "
@ -3269,13 +3219,12 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
template <typename Arg, typename Ret>
void Module::sendToDetectorStop(int fnum, const Arg &args, Ret &retval) {
static_cast<const Module &>(*this).sendToDetectorStop(fnum, args,
retval);
static_cast<const Module &>(*this).sendToDetectorStop(fnum, args, retval);
}
template <typename Arg>
void Module::sendToDetectorStop(int fnum, const Arg &args, std::nullptr_t)
const {
void Module::sendToDetectorStop(int fnum, const Arg &args,
std::nullptr_t) const {
LOG(logDEBUG1) << "Sending to Stop: ["
<< getFunctionNameFromEnum(static_cast<detFuncs>(fnum))
<< ", " << typeid(Arg).name() << ", " << sizeof(Arg)
@ -3286,13 +3235,11 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
template <typename Arg>
void Module::sendToDetectorStop(int fnum, const Arg &args, std::nullptr_t) {
static_cast<const Module &>(*this).sendToDetectorStop(fnum, args,
nullptr);
static_cast<const Module &>(*this).sendToDetectorStop(fnum, args, nullptr);
}
template <typename Ret>
void Module::sendToDetectorStop(int fnum, std::nullptr_t, Ret &retval)
const {
void Module::sendToDetectorStop(int fnum, std::nullptr_t, Ret &retval) const {
LOG(logDEBUG1) << "Sending to Stop: ["
<< getFunctionNameFromEnum(static_cast<detFuncs>(fnum))
<< ", nullptr, 0, " << typeid(Ret).name() << ", "
@ -3397,9 +3344,8 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
if (!strcmp(shm()->receivers[entries[i]].hostname, "none")) {
continue;
}
LOG(logDEBUG1) << "Receiver ["
<< shm()->receivers[entries[i]].hostname << ", "
<< shm()->receivers[entries[i]].tcpPort << ']';
LOG(logDEBUG1) << "Receiver [" << shm()->receivers[entries[i]].hostname
<< ", " << shm()->receivers[entries[i]].tcpPort << ']';
try {
auto receiver =
ReceiverSocket(shm()->receivers[entries[i]].hostname,
@ -3432,8 +3378,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
<< typeid(Ret).name() << ", " << sizeof(Ret) << "]";
STATIC_ASSERT_ARG(Arg, "sendToReceiver")
STATIC_ASSERT_ARG(Ret, "sendToReceiver")
sendToReceiver(rxIndex, fnum, &args, sizeof(args), &retval,
sizeof(retval));
sendToReceiver(rxIndex, fnum, &args, sizeof(args), &retval, sizeof(retval));
LOG(logDEBUG1) << "Got back: " << retval;
}
@ -3477,8 +3422,8 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
template <typename Ret>
void Module::sendToReceiver(const int rxIndex, int fnum, std::nullptr_t,
Ret &retval) {
static_cast<const Module &>(*this).sendToReceiver(rxIndex, fnum,
nullptr, retval);
static_cast<const Module &>(*this).sendToReceiver(rxIndex, fnum, nullptr,
retval);
}
template <typename Ret>
@ -3512,8 +3457,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
}
template <typename Ret, typename Arg>
Ret Module::sendToReceiver(const int rxIndex, int fnum, const Arg &args)
const {
Ret Module::sendToReceiver(const int rxIndex, int fnum, const Arg &args) const {
LOG(logDEBUG1) << "Sending to Receiver " << rxIndex << ": ["
<< getFunctionNameFromEnum(static_cast<detFuncs>(fnum))
<< ", " << args << ", " << sizeof(args) << ", "
@ -3521,16 +3465,15 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
STATIC_ASSERT_ARG(Arg, "sendToReceiver")
STATIC_ASSERT_ARG(Ret, "sendToReceiver")
Ret retval{};
sendToReceiver(rxIndex, fnum, &args, sizeof(args), &retval,
sizeof(retval));
sendToReceiver(rxIndex, fnum, &args, sizeof(args), &retval, sizeof(retval));
LOG(logDEBUG1) << "Got back: " << retval;
return retval;
}
template <typename Ret, typename Arg>
Ret Module::sendToReceiver(const int rxIndex, int fnum, const Arg &args) {
return static_cast<const Module &>(*this).sendToReceiver<Ret>(
rxIndex, fnum, args);
return static_cast<const Module &>(*this).sendToReceiver<Ret>(rxIndex, fnum,
args);
}
slsDetectorDefs::detectorType Module::getDetectorTypeFromShm(int det_id,
@ -3545,9 +3488,9 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
if (verify && shm()->shmversion != MODULE_SHMVERSION) {
std::ostringstream ss;
ss << "Single shared memory (" << det_id << "-" << moduleIndex
<< ":)version mismatch (expected 0x" << std::hex
<< MODULE_SHMVERSION << " but got 0x" << shm()->shmversion << ")"
<< std::dec << ". Clear Shared memory to continue.";
<< ":)version mismatch (expected 0x" << std::hex << MODULE_SHMVERSION
<< " but got 0x" << shm()->shmversion << ")" << std::dec
<< ". Clear Shared memory to continue.";
shm.UnmapSharedMemory();
throw SharedMemoryError(ss.str());
}
@ -3565,8 +3508,8 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
std::ostringstream ss;
ss << "Single shared memory (" << det_id << "-" << moduleIndex
<< ":) version mismatch (expected 0x" << std::hex
<< MODULE_SHMVERSION << " but got 0x" << shm()->shmversion
<< ")" << std::dec << ". Clear Shared memory to continue.";
<< MODULE_SHMVERSION << " but got 0x" << shm()->shmversion << ")"
<< std::dec << ". Clear Shared memory to continue.";
throw SharedMemoryError(ss.str());
}
}
@ -3641,8 +3584,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
nullptr);
}
int Module::sendModule(sls_detector_module * myMod,
sls::ClientSocket & client) {
int Module::sendModule(sls_detector_module *myMod, sls::ClientSocket &client) {
constexpr TLogLevel level = logDEBUG1;
LOG(level) << "Sending Module";
int ts = 0;
@ -3704,8 +3646,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
client.Send(F_SET_MODULE);
sendModule(&module, client);
if (client.Receive<int>() == FAIL) {
throw DetectorError(
"Module " + std::to_string(moduleIndex) +
throw DetectorError("Module " + std::to_string(moduleIndex) +
" returned error: " + client.readErrorMessage());
}
}
@ -3729,9 +3670,10 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
sendToDetector(F_UPDATE_RATE_CORRECTION);
}
sls_detector_module Module::interpolateTrim(
sls_detector_module * a, sls_detector_module * b, const int energy,
const int e1, const int e2, bool trimbits) {
sls_detector_module Module::interpolateTrim(sls_detector_module *a,
sls_detector_module *b,
const int energy, const int e1,
const int e2, bool trimbits) {
// dacs specified only for eiger and mythen3
if (shm()->detType != EIGER && shm()->detType != MYTHEN3) {
throw NotImplementedError("Interpolation of Trim values not "
@ -3788,10 +3730,9 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
E_VCMP_RL, E_VCMP_RR, E_VCP, E_VRS});
} else {
dacs_to_copy.insert(dacs_to_copy.end(),
{M_VCASSH, M_VRSHAPER, M_VRSHAPER_N,
M_VIPRE_OUT, M_VICIN, M_VCAS, M_VRPREAMP,
M_VCAL_N, M_VIPRE, M_VISHAPER, M_VCAL_P,
M_VDCSH});
{M_VCASSH, M_VRSHAPER, M_VRSHAPER_N, M_VIPRE_OUT,
M_VICIN, M_VCAS, M_VRPREAMP, M_VCAL_N, M_VIPRE,
M_VISHAPER, M_VCAL_P, M_VDCSH});
// interpolate vtrim, vth1, vth2, vth3
dacs_to_interpolate.insert(dacs_to_interpolate.end(),
{M_VTH1, M_VTH2, M_VTH3, M_VTRIM});
@ -3800,16 +3741,16 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
// Copy Dacs
for (size_t i = 0; i < dacs_to_copy.size(); ++i) {
if (a->dacs[dacs_to_copy[i]] != b->dacs[dacs_to_copy[i]]) {
throw RuntimeError("Interpolate module: dacs " +
std::to_string(i) + " different");
throw RuntimeError("Interpolate module: dacs " + std::to_string(i) +
" different");
}
myMod.dacs[dacs_to_copy[i]] = a->dacs[dacs_to_copy[i]];
}
// Interpolate Dacs
for (size_t i = 0; i < dacs_to_interpolate.size(); ++i) {
myMod.dacs[dacs_to_interpolate[i]] = linearInterpolation(
energy, e1, e2, a->dacs[dacs_to_interpolate[i]],
myMod.dacs[dacs_to_interpolate[i]] =
linearInterpolation(energy, e1, e2, a->dacs[dacs_to_interpolate[i]],
b->dacs[dacs_to_interpolate[i]]);
}
@ -3817,9 +3758,9 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
if (shm()->detType == EIGER) {
// CAL
if (a->dacs[E_CAL] != b->dacs[E_CAL]) {
LOG(logWARNING) << "DAC CAL differs in both energies ("
<< a->dacs[E_CAL] << "," << b->dacs[E_CAL]
<< ")!\nTaking first: " << a->dacs[E_CAL];
LOG(logWARNING)
<< "DAC CAL differs in both energies (" << a->dacs[E_CAL] << ","
<< b->dacs[E_CAL] << ")!\nTaking first: " << a->dacs[E_CAL];
}
myMod.dacs[E_CAL] = a->dacs[E_CAL];
}
@ -3902,8 +3843,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
sizeof(int) * (myMod.ndac));
infile.read(reinterpret_cast<char *>(&myMod.iodelay),
sizeof(myMod.iodelay));
infile.read(reinterpret_cast<char *>(&myMod.tau),
sizeof(myMod.tau));
infile.read(reinterpret_cast<char *>(&myMod.tau), sizeof(myMod.tau));
for (int i = 0; i < myMod.ndac; ++i) {
LOG(logDEBUG1) << "dac " << i << ":" << myMod.dacs[i];
}
@ -3914,8 +3854,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
sizeof(int) * (myMod.nchan));
}
if (!infile) {
throw RuntimeError(
"readSettingsFile: Could not load all values "
throw RuntimeError("readSettingsFile: Could not load all values "
"for settings for " +
fname);
}
@ -3931,8 +3870,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
std::to_string(file_size) + " instead of " +
std::to_string(expected_size) + " bytes");
}
infile.read(reinterpret_cast<char *>(&myMod.reg),
sizeof(myMod.reg));
infile.read(reinterpret_cast<char *>(&myMod.reg), sizeof(myMod.reg));
infile.read(reinterpret_cast<char *>(myMod.dacs),
sizeof(int) * (myMod.ndac));
for (int i = 0; i < myMod.ndac; ++i) {
@ -3943,8 +3881,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
sizeof(int) * (myMod.nchan));
}
if (!infile) {
throw RuntimeError(
"readSettingsFile: Could not load all values "
throw RuntimeError("readSettingsFile: Could not load all values "
"for settings for " +
fname);
}
@ -3957,9 +3894,10 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
return myMod;
}
void Module::sendProgram(
bool blackfin, std::vector<char> buffer, const int functionEnum,
const std::string &functionType, const std::string serverName) {
void Module::sendProgram(bool blackfin, std::vector<char> buffer,
const int functionEnum,
const std::string &functionType,
const std::string serverName) {
LOG(logINFO) << "Module " << moduleIndex << " (" << shm()->hostname
<< "): Sending " << functionType;
@ -3970,8 +3908,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
client.Send(filesize);
// send checksum
std::string checksum =
sls::md5_calculate_checksum(buffer.data(), filesize);
std::string checksum = sls::md5_calculate_checksum(buffer.data(), filesize);
LOG(logDEBUG1) << "Checksum:" << checksum;
char cChecksum[MAX_STR_LENGTH] = {0};
strcpy(cChecksum, checksum.c_str());
@ -4008,8 +3945,7 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
if (client.Receive<int>() == FAIL) {
std::cout << '\n';
std::ostringstream os;
os << "Module " << moduleIndex << " (" << shm()->hostname
<< ")"
os << "Module " << moduleIndex << " (" << shm()->hostname << ")"
<< " returned error: " << client.readErrorMessage();
throw DetectorError(os.str());
}
@ -4074,10 +4010,10 @@ void Module::setDestinationUDPIP(const IpAddr ip, const int rxIndex) {
while (count > 0) {
std::this_thread::sleep_for(std::chrono::seconds(1));
--count;
printf("%d%%\r",
printf(
"%d%%\r",
static_cast<int>(
(static_cast<double>(ERASE_TIME - count) / ERASE_TIME) *
100));
(static_cast<double>(ERASE_TIME - count) / ERASE_TIME) * 100));
std::cout << std::flush;
}
printf("\n");