This commit is contained in:
Erik Frojdh 2020-05-11 18:28:06 +02:00
parent 1ed1b5da86
commit eff664e790
4 changed files with 125 additions and 367 deletions

View File

@ -15,6 +15,7 @@
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <sstream>
namespace sls {
@ -138,7 +139,8 @@ void Module::sendToDetector(int fnum, std::nullptr_t, Ret &retval) {
void Module::sendToDetector(int fnum) {
LOG(logDEBUG1) << "Sending: ["
<< getFunctionNameFromEnum(
static_cast<slsDetectorDefs::detFuncs>(fnum)) << "]";
static_cast<slsDetectorDefs::detFuncs>(fnum))
<< "]";
sendToDetector(fnum, nullptr, 0, nullptr, 0);
}
@ -214,7 +216,8 @@ void Module::sendToDetectorStop(int fnum, std::nullptr_t, Ret &retval) const {
void Module::sendToDetectorStop(int fnum) {
LOG(logDEBUG1) << "Sending to detector stop: ["
<< getFunctionNameFromEnum(
static_cast<slsDetectorDefs::detFuncs>(fnum)) << "]";
static_cast<slsDetectorDefs::detFuncs>(fnum))
<< "]";
sendToDetectorStop(fnum, nullptr, 0, nullptr, 0);
}
@ -230,6 +233,13 @@ void Module::sendToReceiver(int fnum, const void *args, size_t args_size,
void Module::sendToReceiver(int fnum, const void *args, size_t args_size,
void *retval, size_t retval_size) const {
if (!shm()->useReceiverFlag) {
std::ostringstream oss;
oss << "Set rx_hostname first to use receiver parameters, ";
oss << getFunctionNameFromEnum(
static_cast<slsDetectorDefs::detFuncs>(fnum));
throw RuntimeError(oss.str());
}
auto receiver = ReceiverSocket(shm()->rxHostname, shm()->rxTCPPort);
receiver.sendCommandThenRead(fnum, args, args_size, retval, retval_size);
receiver.close();
@ -533,9 +543,7 @@ slsDetectorDefs::xy Module::getNumberOfChannels() const {
return coord;
}
bool Module::getQuad() {
return sendToDetector<int>(F_GET_QUAD) != 0;
}
bool Module::getQuad() { return sendToDetector<int>(F_GET_QUAD) != 0; }
void Module::setQuad(const bool enable) {
int value = enable ? 1 : 0;
@ -556,9 +564,7 @@ void Module::setReadNLines(const int value) {
}
}
int Module::getReadNLines() {
return sendToDetector<int>(F_GET_READ_N_LINES);
}
int Module::getReadNLines() { return sendToDetector<int>(F_GET_READ_N_LINES); }
void Module::updateMultiSize(slsDetectorDefs::xy det) {
shm()->multiSize = det;
@ -630,9 +636,7 @@ sls::IpAddr Module::getLastClientIP() {
return sendToDetector<sls::IpAddr>(F_GET_LAST_CLIENT_IP);
}
void Module::exitServer() {
sendToDetector(F_EXIT_SERVER);
}
void Module::exitServer() { sendToDetector(F_EXIT_SERVER); }
void Module::execCommand(const std::string &cmd) {
char arg[MAX_STR_LENGTH]{};
@ -918,9 +922,7 @@ slsDetectorDefs::runStatus Module::getRunStatus() const {
return retval;
}
void Module::prepareAcquisition() {
sendToDetector(F_PREPARE_ACQUISITION);
}
void Module::prepareAcquisition() { sendToDetector(F_PREPARE_ACQUISITION); }
void Module::startAcquisition() {
shm()->stoppedFlag = false;
@ -946,22 +948,16 @@ void Module::stopAcquisition() {
}
}
void Module::sendSoftwareTrigger() {
sendToDetectorStop(F_SOFTWARE_TRIGGER);
}
void Module::sendSoftwareTrigger() { sendToDetectorStop(F_SOFTWARE_TRIGGER); }
void Module::startAndReadAll() {
shm()->stoppedFlag = false;
sendToDetector(F_START_AND_READ_ALL);
}
void Module::startReadOut() {
sendToDetector(F_START_READOUT);
}
void Module::startReadOut() { sendToDetector(F_START_READOUT); }
void Module::readAll() {
sendToDetector(F_READ_ALL);
}
void Module::readAll() { sendToDetector(F_READ_ALL); }
void Module::setStartingFrameNumber(uint64_t value) {
LOG(logDEBUG1) << "Setting starting frame number to " << value;
@ -969,18 +965,11 @@ void Module::setStartingFrameNumber(uint64_t value) {
}
uint64_t Module::getStartingFrameNumber() {
uint64_t retval = -1;
LOG(logDEBUG1) << "Getting starting frame number";
sendToDetector(F_GET_STARTING_FRAME_NUMBER, nullptr, retval);
LOG(logDEBUG1) << "Starting frame number :" << retval;
return retval;
return sendToDetector<uint64_t>(F_GET_STARTING_FRAME_NUMBER);
}
int64_t Module::getNumberOfFrames() {
int64_t retval = -1;
sendToDetector(F_GET_NUM_FRAMES, nullptr, retval);
LOG(logDEBUG1) << "number of frames :" << retval;
return retval;
return sendToDetector<int64_t>(F_GET_NUM_FRAMES);
}
void Module::setNumberOfFrames(int64_t value) {
@ -993,10 +982,7 @@ void Module::setNumberOfFrames(int64_t value) {
}
int64_t Module::getNumberOfTriggers() {
int64_t retval = -1;
sendToDetector(F_GET_NUM_TRIGGERS, nullptr, retval);
LOG(logDEBUG1) << "number of triggers :" << retval;
return retval;
return sendToDetector<int64_t>(F_GET_NUM_TRIGGERS);
}
void Module::setNumberOfTriggers(int64_t value) {
@ -1009,10 +995,7 @@ void Module::setNumberOfTriggers(int64_t value) {
}
int64_t Module::getNumberOfBursts() {
int64_t retval = -1;
sendToDetector(F_GET_NUM_BURSTS, nullptr, retval);
LOG(logDEBUG1) << "number of bursts :" << retval;
return retval;
return sendToDetector<int64_t>(F_GET_NUM_BURSTS);
}
void Module::setNumberOfBursts(int64_t value) {
@ -1025,10 +1008,7 @@ void Module::setNumberOfBursts(int64_t value) {
}
int Module::getNumberOfAdditionalStorageCells() {
int retval = -1;
sendToDetector(F_GET_NUM_ADDITIONAL_STORAGE_CELLS, nullptr, retval);
LOG(logDEBUG1) << "number of storage cells :" << retval;
return retval;
return sendToDetector<int>(F_GET_NUM_ADDITIONAL_STORAGE_CELLS);
}
void Module::setNumberOfAdditionalStorageCells(int value) {
@ -1037,10 +1017,7 @@ void Module::setNumberOfAdditionalStorageCells(int value) {
}
int Module::getNumberOfAnalogSamples() {
int retval = -1;
sendToDetector(F_GET_NUM_ANALOG_SAMPLES, nullptr, retval);
LOG(logDEBUG1) << "number of analog samples :" << retval;
return retval;
return sendToDetector<int>(F_GET_NUM_ANALOG_SAMPLES);
}
void Module::setNumberOfAnalogSamples(int value) {
@ -1056,10 +1033,7 @@ void Module::setNumberOfAnalogSamples(int value) {
}
int Module::getNumberOfDigitalSamples() {
int retval = -1;
sendToDetector(F_GET_NUM_DIGITAL_SAMPLES, nullptr, retval);
LOG(logDEBUG1) << "number of digital samples :" << retval;
return retval;
return sendToDetector<int>(F_GET_NUM_DIGITAL_SAMPLES);
}
void Module::setNumberOfDigitalSamples(int value) {
@ -1155,10 +1129,7 @@ void Module::setSubDeadTime(int64_t value) {
}
int64_t Module::getStorageCellDelay() {
int64_t retval = -1;
sendToDetector(F_GET_STORAGE_CELL_DELAY, nullptr, retval);
LOG(logDEBUG1) << "storage cell delay :" << retval;
return retval;
return sendToDetector<int64_t>(F_GET_STORAGE_CELL_DELAY);
}
void Module::setStorageCellDelay(int64_t value) {
@ -1322,11 +1293,7 @@ void Module::setOnChipDAC(slsDetectorDefs::dacIndex index, int chipIndex,
}
int Module::getADC(dacIndex index) {
int retval = -1;
LOG(logDEBUG1) << "Getting ADC " << index;
sendToDetector(F_GET_ADC, static_cast<int>(index), retval);
LOG(logDEBUG1) << "ADC (" << index << "): " << retval;
return retval;
return sendToDetector<int>(F_GET_ADC, static_cast<int>(index));
}
slsDetectorDefs::externalSignalFlag
@ -1708,18 +1675,10 @@ void Module::setClientStreamingPort(int port) { shm()->zmqport = port; }
int Module::getClientStreamingPort() { return shm()->zmqport; }
void Module::setReceiverStreamingPort(int port) {
if (!shm()->useReceiverFlag) {
throw RuntimeError(
"Set rx_hostname first to use receiver parameters (zmq port)");
}
sendToReceiver(F_SET_RECEIVER_STREAMING_PORT, port, nullptr);
}
int Module::getReceiverStreamingPort() {
if (!shm()->useReceiverFlag) {
throw RuntimeError(
"Set rx_hostname first to get receiver parameters (zmq port)");
}
return sendToReceiver<int>(F_GET_RECEIVER_STREAMING_PORT);
}
@ -1734,14 +1693,9 @@ void Module::setClientStreamingIP(const sls::IpAddr ip) {
sls::IpAddr Module::getClientStreamingIP() { return shm()->zmqip; }
void Module::setReceiverStreamingIP(const sls::IpAddr ip) {
if (!shm()->useReceiverFlag) {
throw RuntimeError(
"Set rx_hostname first to use receiver parameters (streaming ip)");
}
if (ip == 0) {
throw RuntimeError("Invalid receiver zmq ip address");
}
// if client zmqip is empty, update it
if (shm()->zmqip == 0) {
shm()->zmqip = ip;
@ -1750,10 +1704,6 @@ void Module::setReceiverStreamingIP(const sls::IpAddr ip) {
}
sls::IpAddr Module::getReceiverStreamingIP() {
if (!shm()->useReceiverFlag) {
throw RuntimeError(
"Set rx_hostname first to use receiver parameters (streaming ip)");
}
return sendToReceiver<sls::IpAddr>(F_GET_RECEIVER_STREAMING_SRC_IP);
}
@ -1888,10 +1838,6 @@ std::map<std::string, std::string> Module::getAdditionalJsonHeader() {
void Module::setAdditionalJsonParameter(const std::string &key,
const std::string &value) {
if (!shm()->useReceiverFlag) {
throw RuntimeError("Set rx_hostname first to use receiver parameters "
"(zmq json parameter)");
}
if (key.empty() || key.length() > SHORT_STR_LENGTH ||
value.length() > SHORT_STR_LENGTH) {
throw RuntimeError(
@ -1906,10 +1852,6 @@ void Module::setAdditionalJsonParameter(const std::string &key,
}
std::string Module::getAdditionalJsonParameter(const std::string &key) {
if (!shm()->useReceiverFlag) {
throw RuntimeError("Set rx_hostname first to use receiver parameters "
"(zmq json parameter)");
}
char arg[SHORT_STR_LENGTH]{};
sls::strcpy_safe(arg, key.c_str());
char retval[SHORT_STR_LENGTH]{};
@ -1947,10 +1889,7 @@ void Module::executeBusTest() {
}
int Module::getImageTestMode() {
int retval = -1;
sendToDetector(F_GET_IMAGE_TEST_MODE, nullptr, retval);
LOG(logDEBUG1) << "image test mode: " << retval;
return retval;
return sendToDetector<int>(F_GET_IMAGE_TEST_MODE);
}
void Module::setImageTestMode(const int value) {
@ -2153,19 +2092,12 @@ void Module::setTimingSource(slsDetectorDefs::timingSourceType value) {
}
int Module::setCounterBit(int cb) {
int retval = -1;
LOG(logDEBUG1) << "Sending counter bit " << cb;
sendToDetector(F_SET_COUNTER_BIT, cb, retval);
LOG(logDEBUG1) << "Counter bit: " << retval;
return retval;
return sendToDetector<int>(F_SET_COUNTER_BIT, cb);
}
void Module::clearROI() {
LOG(logDEBUG1) << "Clearing ROI";
slsDetectorDefs::ROI arg;
arg.xmin = -1;
arg.xmax = -1;
setROI(arg);
setROI(slsDetectorDefs::ROI{});
}
void Module::setROI(slsDetectorDefs::ROI arg) {
@ -2184,13 +2116,12 @@ void Module::setROI(slsDetectorDefs::ROI arg) {
}
slsDetectorDefs::ROI Module::getROI() {
std::array<int, 2> retvals{};
sendToDetector(F_GET_ROI, nullptr, retvals);
LOG(logDEBUG1) << "ROI retval [" << retvals[0] << "," << retvals[1] << "]";
slsDetectorDefs::ROI retval;
retval.xmin = retvals[0];
retval.xmax = retvals[1];
return retval;
// std::array<int, 2> retvals{};
// sendToDetector(F_GET_ROI, nullptr, retvals);
// LOG(logDEBUG1) << "ROI retval [" << retvals[0] << "," << retvals[1] <<
// "]"; slsDetectorDefs::ROI retval; retval.xmin = retvals[0]; retval.xmax =
// retvals[1]; return retval;
return sendToDetector<slsDetectorDefs::ROI>(F_GET_ROI);
}
void Module::setADCEnableMask(uint32_t mask) {
@ -2292,13 +2223,7 @@ int Module::setExternalSampling(int value) {
int Module::getExternalSampling() { return setExternalSampling(-1); }
void Module::setReceiverDbitList(const std::vector<int> &list) {
if (!shm()->useReceiverFlag) {
throw RuntimeError(
"Set rx_hostname first to use receiver parameters (dbit list)");
}
LOG(logDEBUG1) << "Setting Receiver Dbit List";
if (list.size() > 64) {
throw sls::RuntimeError("Dbit list size cannot be greater than 64\n");
}
@ -2313,28 +2238,15 @@ void Module::setReceiverDbitList(const std::vector<int> &list) {
}
std::vector<int> Module::getReceiverDbitList() const {
if (!shm()->useReceiverFlag) {
throw RuntimeError(
"Set rx_hostname first to use receiver parameters (dbit list)");
}
sls::FixedCapacityContainer<int, MAX_RX_DBIT> retval;
sendToReceiver(F_GET_RECEIVER_DBIT_LIST, nullptr, retval);
return retval;
return sendToReceiver<sls::FixedCapacityContainer<int, MAX_RX_DBIT>>(
F_GET_RECEIVER_DBIT_LIST);
}
void Module::setReceiverDbitOffset(int value) {
if (!shm()->useReceiverFlag) {
throw RuntimeError(
"Set rx_hostname first to use receiver parameters (dbit offset)");
}
sendToReceiver(F_SET_RECEIVER_DBIT_OFFSET, value, nullptr);
}
int Module::getReceiverDbitOffset() {
if (!shm()->useReceiverFlag) {
throw RuntimeError(
"Set rx_hostname first to use receiver parameters (dbit offset)");
}
return sendToReceiver<int>(F_GET_RECEIVER_DBIT_OFFSET);
}
@ -2358,58 +2270,27 @@ int Module::activate(int enable) {
}
bool Module::getDeactivatedRxrPaddingMode() {
if (!shm()->useReceiverFlag) {
throw RuntimeError("Set rx_hostname first to use receiver parameters "
"(deactivated padding)");
}
return sendToReceiver<int>(F_GET_RECEIVER_DEACTIVATED_PADDING);
}
void Module::setDeactivatedRxrPaddingMode(bool padding) {
if (!shm()->useReceiverFlag) {
throw RuntimeError("Set rx_hostname first to use receiver parameters "
"(deactivated padding)");
}
int arg = static_cast<int>(padding);
sendToReceiver(F_SET_RECEIVER_DEACTIVATED_PADDING, arg, nullptr);
sendToReceiver(F_SET_RECEIVER_DEACTIVATED_PADDING, static_cast<int>(padding), nullptr);
}
bool Module::getFlippedDataX() {
if (!shm()->useReceiverFlag) {
throw RuntimeError("Set rx_hostname first to use receiver parameters "
"(flipped data x)");
}
int retval = -1;
int arg = -1;
sendToReceiver(F_SET_FLIPPED_DATA_RECEIVER, arg, retval);
LOG(logDEBUG1) << "Flipped data:" << retval;
return retval;
return sendToReceiver<int>(F_SET_FLIPPED_DATA_RECEIVER, -1);
}
void Module::setFlippedDataX(bool value) {
if (!shm()->useReceiverFlag) {
throw RuntimeError("Set rx_hostname first to use receiver parameters "
"(flipped data x)");
}
int retval = -1;
int arg = static_cast<int>(value);
LOG(logDEBUG1) << "Setting flipped data across x axis with value: "
<< value;
sendToReceiver(F_SET_FLIPPED_DATA_RECEIVER, arg, retval);
sendToReceiver<int>(F_SET_FLIPPED_DATA_RECEIVER, static_cast<int>(value));
}
int Module::getAllTrimbits() {
int retval = -1;
int val = -1;
sendToDetector(F_SET_ALL_TRIMBITS, val, retval);
LOG(logDEBUG1) << "All trimbit value: " << retval;
return retval;
return sendToDetector<int>(F_SET_ALL_TRIMBITS, -1);
}
void Module::setAllTrimbits(int val) {
int retval = -1;
LOG(logDEBUG1) << "Setting all trimbits to " << val;
sendToDetector(F_SET_ALL_TRIMBITS, val, retval);
sendToDetector<int>(F_SET_ALL_TRIMBITS, val);
}
int Module::setTrimEn(const std::vector<int> &energies) {
@ -2621,9 +2502,7 @@ void Module::programFPGAviaNios(std::vector<char> buffer) {
rebootController();
}
void Module::resetFPGA() {
return sendToDetector(F_RESET_FPGA);
}
void Module::resetFPGA() { return sendToDetector(F_RESET_FPGA); }
void Module::copyDetectorServer(const std::string &fname,
const std::string &hostname) {
@ -2646,11 +2525,7 @@ int Module::powerChip(int ival) {
}
int Module::setAutoComparatorDisableMode(int ival) {
int retval = -1;
LOG(logDEBUG1) << "Setting auto comp disable mode to " << ival;
sendToDetector(F_AUTO_COMP_DISABLE, ival, retval);
LOG(logDEBUG1) << "Auto comp disable: " << retval;
return retval;
return sendToDetector<int>(F_AUTO_COMP_DISABLE, ival);
}
void Module::setModule(sls_detector_module &module, int tb) {
@ -2696,14 +2571,10 @@ void Module::setRateCorrection(int64_t t) {
}
int64_t Module::getRateCorrection() {
int64_t retval = -1;
sendToDetector(F_GET_RATE_CORRECT, nullptr, retval);
LOG(logDEBUG1) << "Rate correction: " << retval;
return retval;
return sendToDetector<int64_t>(F_GET_RATE_CORRECT);
}
void Module::updateRateCorrection() {
LOG(logDEBUG1) << "Updating rate correction";
sendToDetector(F_UPDATE_RATE_CORRECTION);
}
@ -2776,20 +2647,12 @@ void Module::execReceiverCommand(const std::string &cmd) {
}
std::string Module::getFilePath() {
if (!shm()->useReceiverFlag) {
throw RuntimeError(
"Set rx_hostname first to use receiver parameters (file path)");
}
char retvals[MAX_STR_LENGTH]{};
sendToReceiver(F_GET_RECEIVER_FILE_PATH, nullptr, retvals);
return std::string(retvals);
char ret[MAX_STR_LENGTH]{};
sendToReceiver(F_GET_RECEIVER_FILE_PATH, nullptr, ret);
return ret;
}
void Module::setFilePath(const std::string &path) {
if (!shm()->useReceiverFlag) {
throw RuntimeError(
"Set rx_hostname first to use receiver parameters (file path)");
}
if (path.empty()) {
throw RuntimeError("Cannot set empty file path");
}
@ -2799,20 +2662,12 @@ void Module::setFilePath(const std::string &path) {
}
std::string Module::getFileName() {
if (!shm()->useReceiverFlag) {
throw RuntimeError("Set rx_hostname first to use receiver parameters "
"(file name prefix)");
}
char retvals[MAX_STR_LENGTH]{};
sendToReceiver(F_GET_RECEIVER_FILE_NAME, nullptr, retvals);
return std::string(retvals);
}
void Module::setFileName(const std::string &fname) {
if (!shm()->useReceiverFlag) {
throw RuntimeError("Set rx_hostname first to use receiver parameters "
"(file name prefix)");
}
if (fname.empty()) {
throw RuntimeError("Cannot set empty file name prefix");
}
@ -2822,96 +2677,49 @@ void Module::setFileName(const std::string &fname) {
}
int64_t Module::getFileIndex() {
if (!shm()->useReceiverFlag) {
throw RuntimeError(
"Set rx_hostname first to use receiver parameters (file index)");
}
return sendToReceiver<int64_t>(F_GET_RECEIVER_FILE_INDEX);
}
void Module::setFileIndex(int64_t file_index) {
if (!shm()->useReceiverFlag) {
throw RuntimeError(
"Set rx_hostname first to use receiver parameters (file index)");
}
sendToReceiver(F_SET_RECEIVER_FILE_INDEX, file_index, nullptr);
}
void Module::incrementFileIndex() {
if (!shm()->useReceiverFlag) {
throw RuntimeError("Set rx_hostname first to use receiver parameters "
"(increment file index)");
}
sendToReceiver(F_INCREMENT_FILE_INDEX, nullptr, nullptr);
}
slsDetectorDefs::fileFormat Module::getFileFormat() {
if (!shm()->useReceiverFlag) {
throw RuntimeError(
"Set rx_hostname first to use receiver parameters (file format)");
}
return static_cast<fileFormat>(
sendToReceiver<int>(F_GET_RECEIVER_FILE_FORMAT));
}
void Module::setFileFormat(fileFormat f) {
if (!shm()->useReceiverFlag) {
throw RuntimeError(
"Set rx_hostname first to use receiver parameters (file format)");
}
int arg = static_cast<int>(f);
sendToReceiver(F_SET_RECEIVER_FILE_FORMAT, arg, nullptr);
sendToReceiver(F_SET_RECEIVER_FILE_FORMAT, static_cast<int>(f), nullptr);
}
int Module::getFramesPerFile() {
if (!shm()->useReceiverFlag) {
throw RuntimeError("Set rx_hostname first to use receiver parameters "
"(frames per file)");
}
return sendToReceiver<int>(F_GET_RECEIVER_FRAMES_PER_FILE);
}
void Module::setFramesPerFile(int n_frames) {
if (!shm()->useReceiverFlag) {
throw RuntimeError("Set rx_hostname first to use receiver parameters "
"(frames per file)");
}
sendToReceiver(F_SET_RECEIVER_FRAMES_PER_FILE, n_frames, nullptr);
}
slsDetectorDefs::frameDiscardPolicy Module::getReceiverFramesDiscardPolicy() {
if (!shm()->useReceiverFlag) {
throw RuntimeError("Set rx_hostname first to use receiver parameters "
"(frame discard policy)");
}
return static_cast<frameDiscardPolicy>(
sendToReceiver<int>(F_GET_RECEIVER_DISCARD_POLICY));
}
void Module::setReceiverFramesDiscardPolicy(frameDiscardPolicy f) {
if (!shm()->useReceiverFlag) {
throw RuntimeError("Set rx_hostname first to use receiver parameters "
"(frame discard policy)");
}
int arg = static_cast<int>(f);
sendToReceiver(F_SET_RECEIVER_DISCARD_POLICY, arg, nullptr);
sendToReceiver(F_SET_RECEIVER_DISCARD_POLICY, static_cast<int>(f), nullptr);
}
bool Module::getPartialFramesPadding() {
if (!shm()->useReceiverFlag) {
throw RuntimeError(
"Set rx_hostname first to use receiver parameters (frame padding)");
}
return sendToReceiver<int>(F_GET_RECEIVER_PADDING);
}
void Module::setPartialFramesPadding(bool padding) {
if (!shm()->useReceiverFlag) {
throw RuntimeError(
"Set rx_hostname first to use receiver parameters (frame padding)");
}
int arg = static_cast<int>(padding);
sendToReceiver(F_SET_RECEIVER_PADDING, arg, nullptr);
sendToReceiver(F_SET_RECEIVER_PADDING, static_cast<int>(padding), nullptr);
}
void Module::startReceiver() {
@ -2998,69 +2806,34 @@ int Module::getReceiverProgress() const {
}
void Module::setFileWrite(bool value) {
if (!shm()->useReceiverFlag) {
throw RuntimeError("Set rx_hostname first to use receiver parameters "
"(file write enable)");
}
int arg = static_cast<int>(value);
sendToReceiver(F_SET_RECEIVER_FILE_WRITE, arg, nullptr);
sendToReceiver(F_SET_RECEIVER_FILE_WRITE, static_cast<int>(value), nullptr);
}
bool Module::getFileWrite() {
if (!shm()->useReceiverFlag) {
throw RuntimeError("Set rx_hostname first to use receiver parameters "
"(file_write enable)");
}
return sendToReceiver<int>(F_GET_RECEIVER_FILE_WRITE);
}
void Module::setMasterFileWrite(bool value) {
if (!shm()->useReceiverFlag) {
throw RuntimeError("Set rx_hostname first to use receiver parameters "
"(master file write enable)");
}
int arg = static_cast<int>(value);
sendToReceiver(F_SET_RECEIVER_MASTER_FILE_WRITE, arg, nullptr);
sendToReceiver(F_SET_RECEIVER_MASTER_FILE_WRITE, static_cast<int>(value), nullptr);
}
bool Module::getMasterFileWrite() {
if (!shm()->useReceiverFlag) {
throw RuntimeError("Set rx_hostname first to use receiver parameters "
"(master file write enable)");
}
return sendToReceiver<int>(F_GET_RECEIVER_MASTER_FILE_WRITE);
}
void Module::setFileOverWrite(bool value) {
if (!shm()->useReceiverFlag) {
throw RuntimeError("Set rx_hostname first to use receiver parameters "
"(file overwrite enable)");
}
int arg = static_cast<int>(value);
sendToReceiver(F_SET_RECEIVER_OVERWRITE, arg, nullptr);
sendToReceiver(F_SET_RECEIVER_OVERWRITE, static_cast<int>(value), nullptr);
}
bool Module::getFileOverWrite() {
if (!shm()->useReceiverFlag) {
throw RuntimeError("Set rx_hostname first to use receiver parameters "
"(file overwrite enable)");
}
return sendToReceiver<int>(F_GET_RECEIVER_OVERWRITE);
}
int Module::getReceiverStreamingFrequency() {
if (!shm()->useReceiverFlag) {
throw RuntimeError("Set rx_hostname first to use receiver parameters "
"(streaming/read frequency)");
}
return sendToReceiver<int>(F_GET_RECEIVER_STREAMING_FREQUENCY);
}
void Module::setReceiverStreamingFrequency(int freq) {
if (!shm()->useReceiverFlag) {
throw RuntimeError("Set rx_hostname first to use receiver parameters "
"(streaming/read frequency)");
}
if (freq < 0) {
throw RuntimeError("Invalid streaming frequency " +
std::to_string(freq));
@ -3079,20 +2852,11 @@ int Module::setReceiverStreamingTimer(int time_in_ms) {
}
bool Module::getReceiverStreaming() {
if (!shm()->useReceiverFlag) {
throw RuntimeError(
"Set rx_hostname first to get receiver parameters (zmq enable)");
}
return sendToReceiver<int>(F_GET_RECEIVER_STREAMING);
}
void Module::setReceiverStreaming(bool enable) {
if (!shm()->useReceiverFlag) {
throw RuntimeError(
"Set rx_hostname first to use receiver parameters (zmq enable)");
}
int arg = static_cast<int>(enable);
sendToReceiver(F_SET_RECEIVER_STREAMING, arg, nullptr);
sendToReceiver(F_SET_RECEIVER_STREAMING, static_cast<int>(enable), nullptr);
}
bool Module::enableTenGigabitEthernet(int value) {
@ -3125,20 +2889,12 @@ int Module::setReceiverFifoDepth(int n_frames) {
}
bool Module::getReceiverSilentMode() {
if (!shm()->useReceiverFlag) {
throw RuntimeError(
"Set rx_hostname first to use receiver parameters (silent mode)");
}
return sendToReceiver<int>(F_GET_RECEIVER_SILENT_MODE);
}
void Module::setReceiverSilentMode(bool enable) {
if (!shm()->useReceiverFlag) {
throw RuntimeError(
"Set rx_hostname first to use receiver parameters (silent mode)");
}
int arg = static_cast<int>(enable);
sendToReceiver(F_SET_RECEIVER_SILENT_MODE, arg, nullptr);
sendToReceiver(F_SET_RECEIVER_SILENT_MODE, static_cast<int>(enable),
nullptr);
}
void Module::restreamStopFromReceiver() {
@ -3165,31 +2921,23 @@ void Module::setPattern(const std::string &fname) {
}
uint64_t Module::setPatternIOControl(uint64_t word) {
uint64_t retval = -1;
LOG(logDEBUG1) << "Setting Pattern IO Control, word: 0x" << std::hex << word
<< std::dec;
sendToDetector(F_SET_PATTERN_IO_CONTROL, word, retval);
LOG(logDEBUG1) << "Set Pattern IO Control: " << retval;
return retval;
return sendToDetector<uint64_t>(F_SET_PATTERN_IO_CONTROL, word);
}
uint64_t Module::setPatternClockControl(uint64_t word) {
uint64_t retval = -1;
LOG(logDEBUG1) << "Setting Pattern Clock Control, word: 0x" << std::hex
<< word << std::dec;
sendToDetector(F_SET_PATTERN_CLOCK_CONTROL, word, retval);
LOG(logDEBUG1) << "Set Pattern Clock Control: " << retval;
return retval;
return sendToDetector<uint64_t>(F_SET_PATTERN_CLOCK_CONTROL, word);
}
uint64_t Module::setPatternWord(int addr, uint64_t word) {
uint64_t args[]{static_cast<uint64_t>(addr), word};
uint64_t retval = -1;
LOG(logDEBUG1) << "Setting Pattern word, addr: 0x" << std::hex << addr
<< ", word: 0x" << word << std::dec;
sendToDetector(F_SET_PATTERN_WORD, args, retval);
LOG(logDEBUG1) << "Set Pattern word: " << retval;
return retval;
return sendToDetector<uint64_t>(F_SET_PATTERN_WORD, args);
}
std::array<int, 2> Module::setPatternLoopAddresses(int level, int start,
@ -3208,41 +2956,28 @@ int Module::setPatternLoopCycles(int level, int n) {
int args[]{level, n};
LOG(logDEBUG1) << "Setting Pat Loop cycles, level: " << level
<< ",nloops: " << n;
auto retval = sendToDetector<int>(F_SET_PATTERN_LOOP_CYCLES, args);
LOG(logDEBUG1) << "Set Pat Loop Cycles: " << retval;
return retval;
return sendToDetector<int>(F_SET_PATTERN_LOOP_CYCLES, args);
}
int Module::setPatternWaitAddr(int level, int addr) {
int args[]{level, addr};
LOG(logDEBUG1) << "Setting Pat Wait Addr, level: " << level << ", addr: 0x"
<< std::hex << addr << std::dec;
auto retval = sendToDetector<int>(F_SET_PATTERN_WAIT_ADDR, args);
LOG(logDEBUG1) << "Set Pat Wait Addr: " << retval;
return retval;
return sendToDetector<int>(F_SET_PATTERN_WAIT_ADDR, args);
}
uint64_t Module::setPatternWaitTime(int level, uint64_t t) {
uint64_t args[]{static_cast<uint64_t>(level), t};
LOG(logDEBUG1) << "Setting Pat Wait Time, level: " << level << ", t: " << t;
auto retval = sendToDetector<uint64_t>(F_SET_PATTERN_WAIT_TIME, args);
LOG(logDEBUG1) << "Set Pat Wait Time: " << retval;
return retval;
return sendToDetector<uint64_t>(F_SET_PATTERN_WAIT_TIME, args);
}
void Module::setPatternMask(uint64_t mask) {
LOG(logDEBUG1) << "Setting Pattern Mask " << std::hex << mask << std::dec;
sendToDetector(F_SET_PATTERN_MASK, mask, nullptr);
LOG(logDEBUG1) << "Pattern Mask successful";
}
uint64_t Module::getPatternMask() {
uint64_t retval = -1;
LOG(logDEBUG1) << "Getting Pattern Mask ";
sendToDetector(F_GET_PATTERN_MASK, nullptr, retval);
LOG(logDEBUG1) << "Pattern Mask:" << retval;
return retval;
return sendToDetector<uint64_t>(F_GET_PATTERN_MASK);
}
void Module::setPatternBitMask(uint64_t mask) {
@ -3253,19 +2988,11 @@ void Module::setPatternBitMask(uint64_t mask) {
}
uint64_t Module::getPatternBitMask() {
uint64_t retval = -1;
LOG(logDEBUG1) << "Getting Pattern Bit Mask ";
sendToDetector(F_GET_PATTERN_BIT_MASK, nullptr, retval);
LOG(logDEBUG1) << "Pattern Bit Mask:" << retval;
return retval;
return sendToDetector<uint64_t>(F_GET_PATTERN_BIT_MASK);
}
int Module::setLEDEnable(int enable) {
int retval = -1;
LOG(logDEBUG1) << "Sending LED Enable: " << enable;
sendToDetector(F_LED, enable, retval);
LOG(logDEBUG1) << "LED Enable: " << retval;
return retval;
return sendToDetector<int>(F_LED, enable);
}
void Module::setDigitalIODelay(uint64_t pinMask, int delay) {
@ -3277,11 +3004,7 @@ void Module::setDigitalIODelay(uint64_t pinMask, int delay) {
}
int Module::getClockFrequency(int clkIndex) {
int retval = -1;
LOG(logDEBUG1) << "Getting Clock " << clkIndex << " frequency";
sendToDetector(F_GET_CLOCK_FREQUENCY, clkIndex, retval);
LOG(logDEBUG1) << "Clock " << clkIndex << " frequency: " << retval;
return retval;
return sendToDetector<int>(F_GET_CLOCK_FREQUENCY, clkIndex);
}
void Module::setClockFrequency(int clkIndex, int value) {
@ -3309,20 +3032,11 @@ void Module::setClockPhase(int clkIndex, int value, bool inDegrees) {
}
int Module::getMaxClockPhaseShift(int clkIndex) {
int retval = -1;
LOG(logDEBUG1) << "Getting Max Phase Shift for Clock " << clkIndex;
sendToDetector(F_GET_MAX_CLOCK_PHASE_SHIFT, clkIndex, retval);
LOG(logDEBUG1) << "Max Phase Shift for Clock " << clkIndex << ": "
<< retval;
return retval;
return sendToDetector<int>(F_GET_MAX_CLOCK_PHASE_SHIFT, clkIndex);
}
int Module::getClockDivider(int clkIndex) {
int retval = -1;
LOG(logDEBUG1) << "Getting Clock " << clkIndex << " divider";
sendToDetector(F_GET_CLOCK_DIVIDER, clkIndex, retval);
LOG(logDEBUG1) << "Clock " << clkIndex << " divider: " << retval;
return retval;
return sendToDetector<int>(F_GET_CLOCK_DIVIDER, clkIndex);
}
void Module::setClockDivider(int clkIndex, int value) {
@ -3332,11 +3046,7 @@ void Module::setClockDivider(int clkIndex, int value) {
}
int Module::getPipeline(int clkIndex) {
int retval = -1;
LOG(logDEBUG1) << "Getting Clock " << clkIndex << " pipeline";
sendToDetector(F_GET_PIPELINE, clkIndex, retval);
LOG(logDEBUG1) << "Clock " << clkIndex << " pipeline: " << retval;
return retval;
return sendToDetector<int>(F_GET_PIPELINE, clkIndex);
}
void Module::setPipeline(int clkIndex, int value) {
@ -3356,10 +3066,7 @@ void Module::setCounterMask(uint32_t countermask) {
}
uint32_t Module::getCounterMask() {
uint32_t retval = 0;
sendToDetector(F_GET_COUNTER_MASK, nullptr, retval);
LOG(logDEBUG1) << "Received counter mask: " << retval;
return retval;
return sendToDetector<uint32_t>(F_GET_COUNTER_MASK);
}
sls_detector_module Module::interpolateTrim(sls_detector_module *a,

View File

@ -12,6 +12,7 @@
#include "sls_detector_defs.h"
#include "sls_detector_exceptions.h"
#include "string_utils.h"
#include "FixedCapacityContainer.h"
#include <chrono>
#include <iomanip>
#include <map>
@ -36,6 +37,14 @@ std::string ToString(const defs::detectorModeType s);
std::string ToString(const defs::burstMode s);
std::string ToString(const defs::timingSourceType s);
std::string ToString(const slsDetectorDefs::ROI &roi);
std::ostream &operator<<(std::ostream &os, const slsDetectorDefs::ROI &roi);
template<typename T, size_t Capacity>
std::ostream &operator<<(std::ostream &os, const sls::FixedCapacityContainer<T, Capacity>& c){
return os << ToString(c);
}
const std::string &ToString(const std::string &s);
/** Convert std::chrono::duration with specified output unit */

View File

@ -2,6 +2,16 @@
namespace sls {
std::string ToString(const slsDetectorDefs::ROI& roi){
std::ostringstream oss;
oss << '[' << roi.xmin << ", " << roi.xmax << ']';
return oss.str();
}
std::ostream&operator<<(std::ostream &os, const slsDetectorDefs::ROI& roi){
return os << ToString(roi);
}
std::string ToString(const defs::runStatus s) {
switch (s) {
case defs::ERROR:

View File

@ -6,6 +6,7 @@
#include <array>
#include <map>
#include <vector>
#include <sstream>
// using namespace sls;
using sls::defs;
@ -216,4 +217,35 @@ TEST_CASE("Detector type") {
auto dt = defs::detectorType::EIGER;
REQUIRE(ToString(dt) == "Eiger");
REQUIRE(StringTo<defs::detectorType>("Eiger") == dt);
}
TEST_CASE("Formatting slsDetectorDefs::ROI"){
slsDetectorDefs::ROI roi{5,159};
REQUIRE(ToString(roi) == "[5, 159]");
}
TEST_CASE("Streaming of slsDetectorDefs::ROI"){
using namespace sls;
slsDetectorDefs::ROI roi{-10,1};
std::ostringstream oss;
oss << roi;
REQUIRE(oss.str() == "[-10, 1]");
}
TEST_CASE("sls::FixedCapacityContainer"){
sls::FixedCapacityContainer<int, 5> vec;
vec.push_back(3);
vec.push_back(8);
REQUIRE(ToString(vec) == "[3, 8]");
}
TEST_CASE("sls::FixedCapacityContainer stream"){
sls::FixedCapacityContainer<int, 5> vec;
vec.push_back(33);
vec.push_back(85667);
vec.push_back(2);
std::ostringstream oss;
oss << vec;
REQUIRE(oss.str() == "[33, 85667, 2]");
}