From 248306d570c2f8fa9b7cf3d6d4748dff77950501 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Mon, 15 Apr 2019 17:22:31 +0200 Subject: [PATCH 01/12] minor --- python/scripts/basic.py | 10 +++++++++- python/src/main.cpp | 2 +- python/src/mythenFileIO.h | 6 +++--- slsDetectorSoftware/tests/test-multiSlsDetector.cpp | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/python/scripts/basic.py b/python/scripts/basic.py index 8f199146c..b4808fb66 100755 --- a/python/scripts/basic.py +++ b/python/scripts/basic.py @@ -5,11 +5,19 @@ sys.path.append(os.path.join(os.getcwd(), 'bin')) from sls_detector import Eiger from sls_detector import ExperimentalDetector -from _sls_detector.io import read_ctb_file +from _sls_detector.io import read_my302_file d = Eiger() e = ExperimentalDetector() + +# for i in range(200): +# a = read_my302_file('/home/l_frojdh/Downloads/run_d0_5.raw', i, 24) +# print(f'{i}: {(a==5).sum()}') + + + +a = read_my302_file('/home/l_frojdh/Downloads/run_d0_5.raw', 104, 24) # ncols = 192 # start = 600 # end = 1800 diff --git a/python/src/main.cpp b/python/src/main.cpp index 094ab8e48..f2a591c5e 100755 --- a/python/src/main.cpp +++ b/python/src/main.cpp @@ -286,7 +286,7 @@ py::class_ multiDetectorApi(m, "multiDetectorApi"); ; py::module io = m.def_submodule("io", "Submodule for io"); - io.def("read_ctb_file", &read_ctb_file, "some"); + io.def("read_my302_file", &read_my302_file, "some"); #ifdef VERSION_INFO diff --git a/python/src/mythenFileIO.h b/python/src/mythenFileIO.h index c0660c9bc..1a89b18c3 100644 --- a/python/src/mythenFileIO.h +++ b/python/src/mythenFileIO.h @@ -55,10 +55,10 @@ std::vector ExtractBits(const std::vector &data, int dr = 24) { return result; } -std::vector ReadFile(const std::string &fname, int offset = 8, +std::vector ReadFile(const std::string &fname, int byte_offset = 8, int dr = 24) { const int element_size = static_cast(sizeof(uint64_t)); - const int byte_offset = element_size * offset; + // const int byte_offset = element_size * offset; const int expected_size = dr * element_size * 32 * 3; std::ifstream fs(fname, std::ios::binary | std::ios::ate); if (!fs.is_open()) { @@ -78,7 +78,7 @@ std::vector ReadFile(const std::string &fname, int offset = 8, return data; } -py::array_t read_ctb_file(const std::string &fname, int offset = 8, +py::array_t read_my302_file(const std::string &fname, int offset = 8, int dr = 24) { auto data = ExtractBits<17, 6>(ReadFile(fname, offset, dr)); return py::array(data.size(), data.data()); diff --git a/slsDetectorSoftware/tests/test-multiSlsDetector.cpp b/slsDetectorSoftware/tests/test-multiSlsDetector.cpp index f4e40e726..c6d24da9d 100755 --- a/slsDetectorSoftware/tests/test-multiSlsDetector.cpp +++ b/slsDetectorSoftware/tests/test-multiSlsDetector.cpp @@ -62,7 +62,7 @@ SCENARIO("Multi detector operation", "[detector]") { } } -TEST_CASE("Set and get partialFramesPadding", "[detector]"){ +TEST_CASE("Set and get partialFramesPadding", "[detector][somenewtag]"){ multiSlsDetector::freeSharedMemory(20, -1); multiSlsDetector m(20); From d31446ce0793ccb7c69ba06130611ac2cbe3bc0a Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Mon, 15 Apr 2019 18:14:58 +0200 Subject: [PATCH 02/12] unused values and comments --- slsDetectorSoftware/include/slsDetectorCommand.h | 1 - slsDetectorSoftware/src/slsDetector.cpp | 16 ++++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/slsDetectorSoftware/include/slsDetectorCommand.h b/slsDetectorSoftware/include/slsDetectorCommand.h index 2a4117d9c..39fb02d5c 100755 --- a/slsDetectorSoftware/include/slsDetectorCommand.h +++ b/slsDetectorSoftware/include/slsDetectorCommand.h @@ -113,7 +113,6 @@ class slsDetectorCommand : public virtual slsDetectorDefs { std::string cmdFileName(int narg, char *args[], int action, int detPos = -1); std::string cmdFileIndex(int narg, char *args[], int action, int detPos = -1); std::string cmdRateCorr(int narg, char *args[], int action, int detPos = -1); - // std::string cmdThreaded(int narg, char *args[], int action, int detPos = -1); std::string cmdNetworkParameter(int narg, char *args[], int action, int detPos = -1); std::string cmdPort(int narg, char *args[], int action, int detPos = -1); std::string cmdLock(int narg, char *args[], int action, int detPos = -1); diff --git a/slsDetectorSoftware/src/slsDetector.cpp b/slsDetectorSoftware/src/slsDetector.cpp index ee5dd3a23..6e66fc7e4 100755 --- a/slsDetectorSoftware/src/slsDetector.cpp +++ b/slsDetectorSoftware/src/slsDetector.cpp @@ -2584,7 +2584,7 @@ void slsDetector::setReceiverStreamingIP(std::string sourceIP) { // if empty, give rx_hostname if (sourceIP.empty()) { - if (!strcmp(detector_shm()->receiver_hostname, "none")) { + if (strcmp(detector_shm()->receiver_hostname, "none") == 0) { throw RuntimeError("Receiver hostname not set yet. Cannot create " "rx_zmqip from none"); } @@ -2624,7 +2624,7 @@ void slsDetector::setReceiverStreamingIP(std::string sourceIP) { sls::strcpy_safe(detector_shm()->receiver_zmqip, retvals); if (ret == FORCE_UPDATE) { receiver.close(); - ret = updateCachedReceiverVariables(); + updateCachedReceiverVariables(); } } } @@ -2680,7 +2680,7 @@ slsDetector::setAdditionalJsonHeader(const std::string &jsonheader) { retvals); } if (ret == FORCE_UPDATE) { - ret = updateCachedReceiverVariables(); + updateCachedReceiverVariables(); } return std::string(detector_shm()->receiver_additionalJsonHeader); } @@ -2703,7 +2703,7 @@ std::string slsDetector::getAdditionalJsonHeader() { retvals); } if (ret == FORCE_UPDATE) { - ret = updateCachedReceiverVariables(); + updateCachedReceiverVariables(); } return std::string(detector_shm()->receiver_additionalJsonHeader); } @@ -3279,7 +3279,7 @@ int slsDetector::setDeactivatedRxrPaddingMode(int padding) { detector_shm()->receiver_deactivatedPaddingEnable = retval; } if (ret == FORCE_UPDATE) { - ret = updateCachedReceiverVariables(); + updateCachedReceiverVariables(); } return detector_shm()->receiver_deactivatedPaddingEnable; } @@ -3315,7 +3315,7 @@ int slsDetector::setFlippedData(dimension d, int value) { FILE_LOG(logDEBUG1) << "Flipped data:" << retval << " ret: " << ret; } if (ret == FORCE_UPDATE) { - ret = updateCachedReceiverVariables(); + updateCachedReceiverVariables(); } return detector_shm()->flippedData[d]; } @@ -3370,7 +3370,7 @@ int slsDetector::enableGapPixels(int val) { } } if (ret == FORCE_UPDATE) { - ret = updateCachedReceiverVariables(); + updateCachedReceiverVariables(); } } return detector_shm()->gappixels; @@ -3521,7 +3521,7 @@ int slsDetector::setStoragecellStart(int pos) { FILE_LOG(logDEBUG1) << "Storage cell start: " << retval; } if (ret == FORCE_UPDATE) { - ret = updateDetector(); + updateDetector(); } return retval; } From 0527880747a09cabf85c1f02af0c0380e0b9d442 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Tue, 16 Apr 2019 09:15:17 +0200 Subject: [PATCH 03/12] slsDetector implicit conversion --- slsDetectorSoftware/include/multiSlsDetector.h | 2 +- slsDetectorSoftware/include/slsDetector.h | 2 +- slsDetectorSoftware/src/multiSlsDetector.cpp | 2 +- slsDetectorSoftware/src/slsDetector.cpp | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/slsDetectorSoftware/include/multiSlsDetector.h b/slsDetectorSoftware/include/multiSlsDetector.h index 57af13111..9130e7497 100755 --- a/slsDetectorSoftware/include/multiSlsDetector.h +++ b/slsDetectorSoftware/include/multiSlsDetector.h @@ -1299,7 +1299,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns return value (mostly -1 as it can't read adc register) */ - int writeAdcRegister(int addr, int val, int detPos = -1); + int writeAdcRegister(uint32_t addr, uint32_t val, int detPos = -1); /** * Activates/Deactivates the detector (Eiger only) diff --git a/slsDetectorSoftware/include/slsDetector.h b/slsDetectorSoftware/include/slsDetector.h index 9e95e539a..31f74f2d0 100755 --- a/slsDetectorSoftware/include/slsDetector.h +++ b/slsDetectorSoftware/include/slsDetector.h @@ -1160,7 +1160,7 @@ class slsDetector : public virtual slsDetectorDefs{ * @param val value * @returns return value (mostly -1 as it can't read adc register) */ - int writeAdcRegister(int addr, int val); + int writeAdcRegister(uint32_t addr, uint32_t val); /** * Activates/Deactivates the detector (Eiger only) diff --git a/slsDetectorSoftware/src/multiSlsDetector.cpp b/slsDetectorSoftware/src/multiSlsDetector.cpp index 6eb43c94a..df53fe95b 100755 --- a/slsDetectorSoftware/src/multiSlsDetector.cpp +++ b/slsDetectorSoftware/src/multiSlsDetector.cpp @@ -2448,7 +2448,7 @@ const slsDetectorDefs::ROI *multiSlsDetector::getROI(int &n, int detPos) { return retval; } -int multiSlsDetector::writeAdcRegister(int addr, int val, int detPos) { +int multiSlsDetector::writeAdcRegister(uint32_t addr, uint32_t val, int detPos) { // single if (detPos >= 0) { return detectors[detPos]->writeAdcRegister(addr, val); diff --git a/slsDetectorSoftware/src/slsDetector.cpp b/slsDetectorSoftware/src/slsDetector.cpp index 6e66fc7e4..1f146b8fb 100755 --- a/slsDetectorSoftware/src/slsDetector.cpp +++ b/slsDetectorSoftware/src/slsDetector.cpp @@ -3204,10 +3204,10 @@ int slsDetector::sendROI(int n, ROI roiLimits[]) { return ret; } -int slsDetector::writeAdcRegister(int addr, int val) { +int slsDetector::writeAdcRegister(uint32_t addr, uint32_t val) { int fnum = F_WRITE_ADC_REG; int ret = FAIL; - uint32_t args[2] = {(uint32_t)addr, (uint32_t)val}; + uint32_t args[]{addr, val}; FILE_LOG(logDEBUG1) << "Writing to ADC register 0x" << std::hex << addr << "data: 0x" << std::hex << val << std::dec; @@ -3236,7 +3236,7 @@ int slsDetector::activate(int enable) { ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); FILE_LOG(logDEBUG1) << "Activate: " << retval; - detector_shm()->activated = retval; + detector_shm()->activated = static_cast(retval); } if (ret == FORCE_UPDATE) { ret = updateDetector(); @@ -3260,7 +3260,7 @@ int slsDetector::activate(int enable) { updateCachedReceiverVariables(); } } - return detector_shm()->activated; + return static_cast(detector_shm()->activated); } int slsDetector::setDeactivatedRxrPaddingMode(int padding) { From 001ce4a93e435f9cff21f9870ae488a3dd2f685c Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Tue, 16 Apr 2019 09:28:29 +0200 Subject: [PATCH 04/12] clang-tidy warnings --- slsDetectorSoftware/include/slsDetector.h | 4 +-- slsDetectorSoftware/src/slsDetector.cpp | 33 +++++++++++------------ 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/slsDetectorSoftware/include/slsDetector.h b/slsDetectorSoftware/include/slsDetector.h index 31f74f2d0..d827e02d8 100755 --- a/slsDetectorSoftware/include/slsDetector.h +++ b/slsDetectorSoftware/include/slsDetector.h @@ -225,7 +225,7 @@ struct sharedSlsDetector { bool activated; /** padding enable in deactivated receiver */ - bool receiver_deactivatedPaddingEnable; + bool rxPadDeactivatedModules; /** silent receiver */ bool receiver_silentMode; @@ -1174,7 +1174,7 @@ class slsDetector : public virtual slsDetectorDefs{ * @param padding padding option for deactivated receiver. Can be 1 (padding), 0 (no padding), -1 (gets) * @returns 1 (padding), 0 (no padding), -1 (inconsistent values) for padding option */ - int setDeactivatedRxrPaddingMode(int padding = -1); + bool setDeactivatedRxrPaddingMode(int padding = -1); /** * Returns the enable if data will be flipped across x or y axis (Eiger) diff --git a/slsDetectorSoftware/src/slsDetector.cpp b/slsDetectorSoftware/src/slsDetector.cpp index 1f146b8fb..07c167ea9 100755 --- a/slsDetectorSoftware/src/slsDetector.cpp +++ b/slsDetectorSoftware/src/slsDetector.cpp @@ -362,7 +362,7 @@ void slsDetector::initializeDetectorStructure(detectorType type) { detector_shm()->receiver_frameDiscardMode = NO_DISCARD; detector_shm()->rxFramePadding = true; detector_shm()->activated = true; - detector_shm()->receiver_deactivatedPaddingEnable = true; + detector_shm()->rxPadDeactivatedModules = true; detector_shm()->receiver_silentMode = false; sls::strcpy_safe(detector_shm()->receiver_filePath, "/"); sls::strcpy_safe(detector_shm()->receiver_fileName, "run"); @@ -2307,7 +2307,7 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) { << "\nflippeddatax:" << (detector_shm()->flippedData[X]) << "\nactivated: " << detector_shm()->activated << "\nreceiver deactivated padding: " - << detector_shm()->receiver_deactivatedPaddingEnable + << detector_shm()->rxPadDeactivatedModules << "\nsilent Mode:" << detector_shm()->receiver_silentMode << "\n10GbE:" << detector_shm()->tenGigaEnable << "\nGap pixels: " << detector_shm()->gappixels @@ -2352,7 +2352,7 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) { setFlippedData(X, -1); activate(-1); setDeactivatedRxrPaddingMode( - detector_shm()->receiver_deactivatedPaddingEnable); + detector_shm()->rxPadDeactivatedModules); enableGapPixels(detector_shm()->gappixels); enableTenGigabitEthernet(detector_shm()->tenGigaEnable); setReadOutFlags(GET_READOUT_FLAGS); @@ -2844,7 +2844,7 @@ int slsDetector::setUDPConnection() { FILE_LOG(logDEBUG1) << "Setting UDP Connection"; // called before set up - if (!strcmp(detector_shm()->receiver_hostname, "none")) { + if (strcmp(detector_shm()->receiver_hostname, "none") == 0) { FILE_LOG(logDEBUG1) << "Receiver hostname not set yet."; return FAIL; } @@ -2892,11 +2892,11 @@ int slsDetector::setUDPConnection() { detector_shm()->receiverTCPPort); ret = receiver.sendCommandThenRead(fnum, args, sizeof(args), retvals, sizeof(retvals)); - if (strlen(retvals[0])) { + if (strlen(retvals[0]) != 0u) { FILE_LOG(logDEBUG1) << "Receiver UDP MAC returned : " << retvals[0]; detector_shm()->receiverUDPMAC = retvals[0]; } - if (strlen(retvals[1])) { + if (strlen(retvals[1]) != 0u) { FILE_LOG(logDEBUG1) << "Receiver UDP MAC2 returned : " << retvals[1]; detector_shm()->receiverUDPMAC2 = retvals[1]; @@ -2942,10 +2942,10 @@ int slsDetector::loadImageToDetector(imageType index, const std::string &fname) { int nChan = getTotalNumberOfChannels(); int16_t args[nChan]; - FILE_LOG(logDEBUG1) << "Loading " << (!index ? "Dark" : "Gain") + FILE_LOG(logDEBUG1) << "Loading " << (index == 0u ? "Dark" : "Gain") << "image from file " << fname; - if (readDataFile(fname, args, nChan)) { + if (readDataFile(fname, args, nChan) != 0) { return sendImageToDetector(index, args); } else { throw RuntimeError( @@ -2957,7 +2957,7 @@ int slsDetector::sendImageToDetector(imageType index, int16_t imageVals[]) { int fnum = F_LOAD_IMAGE; int ret = FAIL; int nChan = getTotalNumberOfChannels(); - int args[2] = {(int)index, nChan}; + int args[]{static_cast(index), nChan}; FILE_LOG(logDEBUG1) << "Sending image to detector"; if (detector_shm()->onlineFlag == ONLINE_FLAG) { @@ -2983,7 +2983,7 @@ int slsDetector::sendImageToDetector(imageType index, int16_t imageVals[]) { int slsDetector::writeCounterBlockFile(const std::string &fname, int startACQ) { int ret = FAIL; int nChan = getTotalNumberOfChannels(); - short int retvals[nChan]; + int16_t retvals[nChan]; FILE_LOG(logDEBUG1) << "Reading Counter to " << fname << (startACQ ? " and Restarting Acquisition" : "\n"); @@ -3047,7 +3047,7 @@ int slsDetector::setCounterBit(int i) { FILE_LOG(logDEBUG1) << "Counter bit: " << retval; } if (ret == FORCE_UPDATE) { - ret = updateDetector(); + updateDetector(); } return retval; } @@ -3245,8 +3245,7 @@ int slsDetector::activate(int enable) { // receiver if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG && ret == OK) { fnum = F_RECEIVER_ACTIVATE; - ret = FAIL; - arg = detector_shm()->activated; + arg = static_cast(detector_shm()->activated); retval = -1; FILE_LOG(logDEBUG1) << "Setting activate flag " << arg << " to receiver"; @@ -3263,7 +3262,7 @@ int slsDetector::activate(int enable) { return static_cast(detector_shm()->activated); } -int slsDetector::setDeactivatedRxrPaddingMode(int padding) { +bool slsDetector::setDeactivatedRxrPaddingMode(int padding) { int fnum = F_RECEIVER_DEACTIVATED_PADDING_ENABLE; int ret = OK; int arg = padding; @@ -3276,12 +3275,12 @@ int slsDetector::setDeactivatedRxrPaddingMode(int padding) { ret = receiver.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); FILE_LOG(logDEBUG1) << "Deactivated Receiver Padding Enable:" << retval; - detector_shm()->receiver_deactivatedPaddingEnable = retval; + detector_shm()->rxPadDeactivatedModules = retval; } if (ret == FORCE_UPDATE) { updateCachedReceiverVariables(); } - return detector_shm()->receiver_deactivatedPaddingEnable; + return detector_shm()->rxPadDeactivatedModules; } int slsDetector::getFlippedData(dimension d) const { @@ -4075,7 +4074,7 @@ int slsDetector::updateCachedReceiverVariables() const { // deactivated padding enable n += receiver.receiveData(&i32, sizeof(i32)); - detector_shm()->receiver_deactivatedPaddingEnable = + detector_shm()->rxPadDeactivatedModules = static_cast(i32); // silent mode From bad8b99b2571ab440d6122759ae1b4e172e3e73d Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Tue, 16 Apr 2019 10:21:35 +0200 Subject: [PATCH 05/12] clang-tidy fix --- slsDetectorSoftware/include/slsDetector.h | 2 +- slsDetectorSoftware/src/slsDetector.cpp | 86 +++++++++++------------ 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/slsDetectorSoftware/include/slsDetector.h b/slsDetectorSoftware/include/slsDetector.h index d827e02d8..03b7e7690 100755 --- a/slsDetectorSoftware/include/slsDetector.h +++ b/slsDetectorSoftware/include/slsDetector.h @@ -204,7 +204,7 @@ struct sharedSlsDetector { int dataBytesInclGapPixels; /** additional json header */ - char receiver_additionalJsonHeader[MAX_STR_LENGTH]; + char rxAdditionalJsonHeader[MAX_STR_LENGTH]; /** detector control server software API version */ int64_t detectorControlAPIVersion; diff --git a/slsDetectorSoftware/src/slsDetector.cpp b/slsDetectorSoftware/src/slsDetector.cpp index 07c167ea9..80d3c61f5 100755 --- a/slsDetectorSoftware/src/slsDetector.cpp +++ b/slsDetectorSoftware/src/slsDetector.cpp @@ -355,7 +355,7 @@ void slsDetector::initializeDetectorStructure(detectorType type) { memset(detector_shm()->zmqip, 0, MAX_STR_LENGTH); memset(detector_shm()->receiver_zmqip, 0, MAX_STR_LENGTH); detector_shm()->gappixels = 0; - memset(detector_shm()->receiver_additionalJsonHeader, 0, MAX_STR_LENGTH); + memset(detector_shm()->rxAdditionalJsonHeader, 0, MAX_STR_LENGTH); detector_shm()->detectorControlAPIVersion = 0; detector_shm()->detectorStopAPIVersion = 0; detector_shm()->receiverAPIVersion = 0; @@ -656,8 +656,8 @@ void slsDetector::updateTotalNumberOfChannels() { // add digital signals depending on readout flags if (detector_shm()->myDetectorType == CHIPTESTBOARD && - (detector_shm()->roFlags & DIGITAL_ONLY || - detector_shm()->roFlags & ANALOG_AND_DIGITAL)) { + (((detector_shm()->roFlags & DIGITAL_ONLY) != 0) || + ((detector_shm()->roFlags & ANALOG_AND_DIGITAL) != 0))) { detector_shm()->nChan[X] += 4; } @@ -1329,7 +1329,7 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, } // verify e_eV exists in trimEneregies[] - if (!detector_shm()->nTrimEn || (e_eV < detector_shm()->trimEnergies[0]) || + if ((detector_shm()->nTrimEn == 0) || (e_eV < detector_shm()->trimEnergies[0]) || (e_eV > detector_shm()->trimEnergies[detector_shm()->nTrimEn - 1])) { throw RuntimeError("This energy " + std::to_string(e_eV) + " not defined for this module!"); @@ -1361,7 +1361,7 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, // myMod = createModule(); // readSettings also checks if create module // is null if (nullptr == readSettingsFile(settingsfname, myMod, tb)) { - if (myMod) { + if (myMod != nullptr) { deleteModule(myMod); } return FAIL; @@ -1830,7 +1830,7 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t) { if ((dr == 32 && index == SUBFRAME_ACQUISITION_TIME) || (dr == 16 && index == ACQUISITION_TIME)) { int r = getRateCorrection(); - if (r) { + if (r != 0) { setRateCorrection(r); } } @@ -2003,7 +2003,7 @@ int slsDetector::setDAC(int val, dacIndex index, int mV) { int args[3]{static_cast(index), mV, val}; int retval = -1; FILE_LOG(logDEBUG1) << "Setting DAC " << index << " to " << val - << (mV ? "mV" : "dac units"); + << (mV != 0 ? "mV" : "dac units"); if (detector_shm()->onlineFlag == ONLINE_FLAG) { auto client = DetectorSocket(detector_shm()->hostname, @@ -2011,7 +2011,7 @@ int slsDetector::setDAC(int val, dacIndex index, int mV) { ret = client.sendCommandThenRead(fnum, args, sizeof(args), &retval, sizeof(retval)); FILE_LOG(logDEBUG1) << "Dac index " << index << ": " << retval - << (mV ? "mV" : "dac units"); + << (mV != 0 ? "mV" : "dac units"); } if (ret == FORCE_UPDATE) { updateDetector(); @@ -2315,7 +2315,7 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) { << "\nrx streaming port:" << detector_shm()->receiver_zmqport << "\nrx streaming source ip:" << detector_shm()->receiver_zmqip << "\nrx additional json header:" - << detector_shm()->receiver_additionalJsonHeader + << detector_shm()->rxAdditionalJsonHeader << "\nrx_datastream:" << enableDataStreamingFromReceiver(-1) << std::endl; @@ -2352,7 +2352,7 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) { setFlippedData(X, -1); activate(-1); setDeactivatedRxrPaddingMode( - detector_shm()->rxPadDeactivatedModules); + static_cast(detector_shm()->rxPadDeactivatedModules)); enableGapPixels(detector_shm()->gappixels); enableTenGigabitEthernet(detector_shm()->tenGigaEnable); setReadOutFlags(GET_READOUT_FLAGS); @@ -2373,15 +2373,15 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) { break; } - setReceiverSilentMode(detector_shm()->receiver_silentMode); + setReceiverSilentMode(static_cast(detector_shm()->receiver_silentMode)); // data streaming setReceiverStreamingFrequency(detector_shm()->receiver_read_freq); setReceiverStreamingPort(getReceiverStreamingPort()); setReceiverStreamingIP(getReceiverStreamingIP()); setAdditionalJsonHeader( - detector_shm()->receiver_additionalJsonHeader); + detector_shm()->rxAdditionalJsonHeader); enableDataStreamingFromReceiver( - enableDataStreamingFromReceiver(-1)); + static_cast(enableDataStreamingFromReceiver(-1))); if (detector_shm()->myDetectorType == GOTTHARD || detector_shm()->myDetectorType == CHIPTESTBOARD || detector_shm()->myDetectorType == MOENCH) { @@ -2403,7 +2403,7 @@ std::string slsDetector::setReceiverUDPIP(const std::string &udpip) { "VALID and in xxx.xxx.xxx.xxx format"); } detector_shm()->receiverUDPIP = ip; - if (!strcmp(detector_shm()->receiver_hostname, "none")) { + if (strcmp(detector_shm()->receiver_hostname, "none") == 0) { FILE_LOG(logDEBUG1) << "Receiver hostname not set yet"; } else if (setUDPConnection() == FAIL) { FILE_LOG(logWARNING) << "UDP connection set up failed"; @@ -2422,7 +2422,7 @@ std::string slsDetector::setReceiverUDPIP2(const std::string &udpip) { "VALID and in xxx.xxx.xxx.xxx format"); } detector_shm()->receiverUDPIP2 = ip; - if (!strcmp(detector_shm()->receiver_hostname, "none")) { + if (strcmp(detector_shm()->receiver_hostname, "none") == 0) { FILE_LOG(logDEBUG1) << "Receiver hostname not set yet"; } else if (setUDPConnection() == FAIL) { FILE_LOG(logWARNING) << "UDP connection set up failed"; @@ -2462,7 +2462,7 @@ MacAddr slsDetector::getReceiverUDPMAC2() const { int slsDetector::setReceiverUDPPort(int udpport) { detector_shm()->receiverUDPPort = udpport; - if (!strcmp(detector_shm()->receiver_hostname, "none")) { + if (strcmp(detector_shm()->receiver_hostname, "none") == 0) { FILE_LOG(logDEBUG1) << "Receiver hostname not set yet"; } else if (setUDPConnection() == FAIL) { FILE_LOG(logWARNING) << "UDP connection set up failed"; @@ -2476,7 +2476,7 @@ int slsDetector::getReceiverUDPPort() const { int slsDetector::setReceiverUDPPort2(int udpport) { detector_shm()->receiverUDPPort2 = udpport; - if (!strcmp(detector_shm()->receiver_hostname, "none")) { + if (strcmp(detector_shm()->receiver_hostname, "none") == 0) { FILE_LOG(logDEBUG1) << "Receiver hostname not set yet"; } else if (setUDPConnection() == FAIL) { FILE_LOG(logWARNING) << "UDP connection set up failed"; @@ -2494,7 +2494,7 @@ int slsDetector::setNumberofUDPInterfaces(int n) { "Cannot choose number of interfaces for this detector"); } detector_shm()->numUDPInterfaces = (n > 1 ? 2 : 1); - if (!strcmp(detector_shm()->receiver_hostname, "none")) { + if (strcmp(detector_shm()->receiver_hostname, "none") == 0) { FILE_LOG(logDEBUG1) << "Receiver hostname not set yet"; } else if (setUDPConnection() == FAIL) { FILE_LOG(logWARNING) << "UDP connection set up failed"; @@ -2511,7 +2511,7 @@ int slsDetector::selectUDPInterface(int n) { throw RuntimeError("Cannot select an interface for this detector"); } detector_shm()->selectedUDPInterface = (n > 1 ? 2 : 1); - if (!strcmp(detector_shm()->receiver_hostname, "none")) { + if (strcmp(detector_shm()->receiver_hostname, "none") == 0) { FILE_LOG(logDEBUG1) << "Receiver hostname not set yet"; } else if (setUDPConnection() == FAIL) { FILE_LOG(logWARNING) << "UDP connection set up failed"; @@ -2560,7 +2560,7 @@ int slsDetector::getReceiverStreamingPort() { void slsDetector::setClientStreamingIP(const std::string &sourceIP) { struct addrinfo *result; // on failure to convert to a valid ip - if (sls::ConvertHostnameToInternetAddress(sourceIP.c_str(), &result)) { + if (sls::ConvertHostnameToInternetAddress(sourceIP.c_str(), &result) != 0) { throw RuntimeError("Could not convert zmqip into a valid IP" + sourceIP); } @@ -2595,7 +2595,7 @@ void slsDetector::setReceiverStreamingIP(std::string sourceIP) { { struct addrinfo *result; // on failure to convert to a valid ip - if (sls::ConvertHostnameToInternetAddress(sourceIP.c_str(), &result)) { + if (sls::ConvertHostnameToInternetAddress(sourceIP.c_str(), &result) != 0) { throw RuntimeError("Could not convert rx_zmqip into a valid IP" + sourceIP); } @@ -2607,7 +2607,7 @@ void slsDetector::setReceiverStreamingIP(std::string sourceIP) { memset(detector_shm()->receiver_zmqip, 0, MAX_STR_LENGTH); sls::strcpy_safe(detector_shm()->receiver_zmqip, args); // if zmqip is empty, update it - if (!strlen(detector_shm()->zmqip)) { + if (strlen(detector_shm()->zmqip) != 0u) { sls::strcpy_safe(detector_shm()->zmqip, args); } FILE_LOG(logDEBUG1) << "Sending receiver streaming IP to receiver: " @@ -2666,7 +2666,7 @@ slsDetector::setAdditionalJsonHeader(const std::string &jsonheader) { FILE_LOG(logDEBUG1) << "Sending additional json header " << args; if (detector_shm()->receiverOnlineFlag != ONLINE_FLAG) { - sls::strcpy_safe(detector_shm()->receiver_additionalJsonHeader, + sls::strcpy_safe(detector_shm()->rxAdditionalJsonHeader, jsonheader.c_str()); } else { auto receiver = ReceiverSocket(detector_shm()->receiver_hostname, @@ -2674,15 +2674,15 @@ slsDetector::setAdditionalJsonHeader(const std::string &jsonheader) { ret = receiver.sendCommandThenRead(fnum, args, sizeof(args), retvals, sizeof(retvals)); FILE_LOG(logDEBUG1) << "Additional json header: " << retvals; - memset(detector_shm()->receiver_additionalJsonHeader, 0, + memset(detector_shm()->rxAdditionalJsonHeader, 0, MAX_STR_LENGTH); - sls::strcpy_safe(detector_shm()->receiver_additionalJsonHeader, + sls::strcpy_safe(detector_shm()->rxAdditionalJsonHeader, retvals); } if (ret == FORCE_UPDATE) { updateCachedReceiverVariables(); } - return std::string(detector_shm()->receiver_additionalJsonHeader); + return std::string(detector_shm()->rxAdditionalJsonHeader); } std::string slsDetector::getAdditionalJsonHeader() { @@ -2697,21 +2697,21 @@ std::string slsDetector::getAdditionalJsonHeader() { ret = receiver.sendCommandThenRead(fnum, nullptr, 0, retvals, sizeof(retvals)); FILE_LOG(logDEBUG1) << "Additional json header: " << retvals; - memset(detector_shm()->receiver_additionalJsonHeader, 0, + memset(detector_shm()->rxAdditionalJsonHeader, 0, MAX_STR_LENGTH); - sls::strcpy_safe(detector_shm()->receiver_additionalJsonHeader, + sls::strcpy_safe(detector_shm()->rxAdditionalJsonHeader, retvals); } if (ret == FORCE_UPDATE) { updateCachedReceiverVariables(); } - return std::string(detector_shm()->receiver_additionalJsonHeader); + return std::string(detector_shm()->rxAdditionalJsonHeader); } std::string slsDetector::setAdditionalJsonParameter(const std::string &key, const std::string &value) { if (key.empty() || value.empty()) { - throw("Could not set additional json header parameter as the key or " + throw RuntimeError("Could not set additional json header parameter as the key or " "value is empty"); } @@ -2736,7 +2736,7 @@ std::string slsDetector::setAdditionalJsonParameter(const std::string &key, valueLiteral.append("\""); } - std::string header(detector_shm()->receiver_additionalJsonHeader); + std::string header(detector_shm()->rxAdditionalJsonHeader); size_t keyPos = header.find(keyLiteral); // if key found, replace value @@ -2751,7 +2751,7 @@ std::string slsDetector::setAdditionalJsonParameter(const std::string &key, // key not found, append key value pair else { - if (header.length()) { + if (header.length() != 0u) { header.append(","); } header.append(keyLiteral + valueLiteral); @@ -2764,7 +2764,7 @@ std::string slsDetector::setAdditionalJsonParameter(const std::string &key, std::string slsDetector::getAdditionalJsonParameter(const std::string &key) { // additional json header is empty - if (!strlen(detector_shm()->receiver_additionalJsonHeader)) + if (strlen(detector_shm()->rxAdditionalJsonHeader) == 0u) return std::string(); // add quotations before and after the key value @@ -2774,7 +2774,7 @@ std::string slsDetector::getAdditionalJsonParameter(const std::string &key) { // loop through the parameters for (const auto ¶meter : - sls::split(detector_shm()->receiver_additionalJsonHeader, ',')) { + sls::split(detector_shm()->rxAdditionalJsonHeader, ',')) { // get a vector of key value pair for each parameter const auto &pairs = sls::split(parameter, ':'); // match for key @@ -2807,7 +2807,7 @@ int64_t slsDetector::setReceiverUDPSocketBufferSize(int64_t udpsockbufsize) { FILE_LOG(logDEBUG1) << "Receiver UDP Socket Buffer size: " << retval; } if (ret == FORCE_UPDATE) { - ret = updateCachedReceiverVariables(); + updateCachedReceiverVariables(); } return retval; } @@ -2831,7 +2831,7 @@ int64_t slsDetector::getReceiverRealUDPSocketBufferSize() { << "Real Receiver UDP Socket Buffer size: " << retval; } if (ret == FORCE_UPDATE) { - ret = updateCachedReceiverVariables(); + updateCachedReceiverVariables(); } return retval; } @@ -2839,8 +2839,8 @@ int64_t slsDetector::getReceiverRealUDPSocketBufferSize() { int slsDetector::setUDPConnection() { int fnum = F_SETUP_RECEIVER_UDP; int ret = FAIL; - char args[6][MAX_STR_LENGTH] = {{}, {}, {}, {}, {}, {}}; - char retvals[2][MAX_STR_LENGTH] = {{}, {}}; + char args[6][MAX_STR_LENGTH]{}; + char retvals[2][MAX_STR_LENGTH]{}; FILE_LOG(logDEBUG1) << "Setting UDP Connection"; // called before set up @@ -2985,7 +2985,7 @@ int slsDetector::writeCounterBlockFile(const std::string &fname, int startACQ) { int nChan = getTotalNumberOfChannels(); int16_t retvals[nChan]; FILE_LOG(logDEBUG1) << "Reading Counter to " << fname - << (startACQ ? " and Restarting Acquisition" : "\n"); + << (startACQ !=0 ? " and Restarting Acquisition" : "\n"); ret = getCounterBlock(retvals, startACQ); if (ret != FAIL) { @@ -3275,7 +3275,7 @@ bool slsDetector::setDeactivatedRxrPaddingMode(int padding) { ret = receiver.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); FILE_LOG(logDEBUG1) << "Deactivated Receiver Padding Enable:" << retval; - detector_shm()->rxPadDeactivatedModules = retval; + detector_shm()->rxPadDeactivatedModules = static_cast(retval); } if (ret == FORCE_UPDATE) { updateCachedReceiverVariables(); @@ -3290,7 +3290,7 @@ int slsDetector::getFlippedData(dimension d) const { int slsDetector::setFlippedData(dimension d, int value) { int fnum = F_SET_FLIPPED_DATA_RECEIVER; int ret = OK; - int args[2] = {(int)d, value}; + int args[]{static_cast(d), value}; int retval = -1; // flipped across y @@ -3334,7 +3334,7 @@ int slsDetector::setAllTrimbits(int val) { FILE_LOG(logDEBUG1) << "All trimbit value: " << retval; } if (ret == FORCE_UPDATE) { - ret = updateDetector(); + updateDetector(); } return retval; } @@ -4061,7 +4061,7 @@ int slsDetector::updateCachedReceiverVariables() const { // additional json header n += receiver.receiveData(cstring, sizeof(cstring)); - sls::strcpy_safe(detector_shm()->receiver_additionalJsonHeader, + sls::strcpy_safe(detector_shm()->rxAdditionalJsonHeader, cstring); // receiver streaming enable From dd6bb852306eef59463a3af5ccc01926ccb2717b Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Tue, 16 Apr 2019 10:31:04 +0200 Subject: [PATCH 06/12] clang-tidy fix --- slsDetectorSoftware/src/slsDetector.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/slsDetectorSoftware/src/slsDetector.cpp b/slsDetectorSoftware/src/slsDetector.cpp index 80d3c61f5..55470e3de 100755 --- a/slsDetectorSoftware/src/slsDetector.cpp +++ b/slsDetectorSoftware/src/slsDetector.cpp @@ -1164,7 +1164,7 @@ int slsDetector::writeConfigurationFile(std::ofstream &outfile, auto cmd = slsDetectorCommand(m); for (auto &name : names) { - char *args[] = {(char *)name.c_str()}; + char *args[] = {const_cast(name.c_str())}; outfile << detId << ":"; outfile << name << " " << cmd.executeLine(1, args, GET_ACTION) << std::endl; @@ -1211,7 +1211,7 @@ slsDetectorDefs::detectorSettings slsDetector::sendSettingsOnly(detectorSettings isettings) { int fnum = F_SET_SETTINGS; int ret = FAIL; - int arg = (int)isettings; + int arg = static_cast(isettings); int retval = -1; FILE_LOG(logDEBUG1) << "Setting settings to " << arg; @@ -1221,7 +1221,7 @@ slsDetector::sendSettingsOnly(detectorSettings isettings) { client.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); FILE_LOG(logDEBUG1) << "Settings: " << retval; - detector_shm()->currentSettings = (detectorSettings)retval; + detector_shm()->currentSettings = static_cast(retval); } if (ret == FORCE_UPDATE) { updateDetector(); @@ -1785,7 +1785,7 @@ int slsDetector::configureMAC() { int64_t slsDetector::setTimer(timerIndex index, int64_t t) { int fnum = F_SET_TIMER; int ret = FAIL; - int64_t args[2] = {(int64_t)index, t}; + int64_t args[2] = {static_cast(index), t}; int64_t retval = -1; FILE_LOG(logDEBUG1) << "Setting " << getTimerType(index) << " to " << t << " ns/value"; @@ -1881,7 +1881,7 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t) { &retval, sizeof(retval)); if (ret == FORCE_UPDATE) { receiver.close(); - ret = updateCachedReceiverVariables(); + updateCachedReceiverVariables(); } break; default: @@ -1904,7 +1904,7 @@ int64_t slsDetector::getTimeLeft(timerIndex index) { sizeof(retval)); FILE_LOG(logDEBUG1) << getTimerType(index) << " left: " << retval; if (ret == FORCE_UPDATE) { - ret = updateDetector(); + updateDetector(); } } return retval; @@ -1913,7 +1913,7 @@ int64_t slsDetector::getTimeLeft(timerIndex index) { int slsDetector::setSpeed(speedVariable sp, int value, int mode) { int fnum = F_SET_SPEED; int ret = FAIL; - int args[3] = {(int)sp, value, mode}; + int args[]{static_cast(sp), value, mode}; int retval = -1; FILE_LOG(logDEBUG1) << "Setting speed index " << sp << " to " << value << " mode: " << mode; @@ -1974,7 +1974,6 @@ int slsDetector::setDynamicRange(int n) { // send to receiver if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG && ret == OK) { fnum = F_SET_RECEIVER_DYNAMIC_RANGE; - ret = FAIL; n = detector_shm()->dynamicRange; retval = -1; FILE_LOG(logDEBUG1) << "Sending dynamic range to receiver: " << n; @@ -1985,7 +1984,7 @@ int slsDetector::setDynamicRange(int n) { FILE_LOG(logDEBUG1) << "Receiver Dynamic range: " << retval; if (ret == FORCE_UPDATE) { receiver.close(); - ret = updateCachedReceiverVariables(); + updateCachedReceiverVariables(); } } return detector_shm()->dynamicRange; @@ -2091,7 +2090,7 @@ int slsDetector::setReadOutFlags(readOutFlags flag) { ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), &retval, sizeof(retval)); FILE_LOG(logDEBUG1) << "Readout flag: " << retval; - detector_shm()->roFlags = (readOutFlags)retval; + detector_shm()->roFlags = retval; // update #nchans and databytes, as it depends on #samples, roi, // readoutflags (ctb only) if (detector_shm()->myDetectorType == CHIPTESTBOARD) { @@ -3576,7 +3575,7 @@ int slsDetector::programFPGA(std::vector buffer) { --count; printf( "%d%%\r", - (int)(((double)(ERASE_TIME - count) / ERASE_TIME) * 100)); + static_cast((static_cast(ERASE_TIME - count) / ERASE_TIME) * 100)); std::cout << std::flush; } printf("\n"); @@ -3608,7 +3607,7 @@ int slsDetector::programFPGA(std::vector buffer) { // print progress printf( "%d%%\r", - (int)(((double)(totalsize - filesize) / totalsize) * 100)); + static_cast((static_cast(totalsize - filesize) / totalsize) * 100)); std::cout << std::flush; } else { printf("\n"); @@ -3728,7 +3727,7 @@ int slsDetector::getChanRegs(double *retval) { // the original array has 0 initialized if (myMod->chanregs != nullptr) { for (int i = 0; i < n; ++i) { - retval[i] = (double)(myMod->chanregs[i] & TRIMBITMASK); + retval[i] = static_cast(myMod->chanregs[i] & TRIMBITMASK); } } deleteModule(myMod); From c7169f3c36bdde3f5f8cd5fce6c05975d0d9cb0f Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Tue, 16 Apr 2019 12:15:31 +0200 Subject: [PATCH 07/12] moved setDetectorSpecific parameters to constructor of detectorParameters --- slsDetectorSoftware/include/slsDetector.h | 82 +++++++-- slsDetectorSoftware/src/slsDetector.cpp | 156 +++++------------- .../tests/test-slsDetector.cpp | 28 +++- 3 files changed, 139 insertions(+), 127 deletions(-) diff --git a/slsDetectorSoftware/include/slsDetector.h b/slsDetectorSoftware/include/slsDetector.h index 03b7e7690..8caee7b71 100755 --- a/slsDetectorSoftware/include/slsDetector.h +++ b/slsDetectorSoftware/include/slsDetector.h @@ -23,14 +23,73 @@ class MySocketTCP; * parameter list that has to be initialized depending on the detector type */ struct detParameters { - int nChanX; - int nChanY; - int nChipX; - int nChipY; - int nDacs; - int dynamicRange; - int nGappixelsX; - int nGappixelsY; + int nChanX{0}; + int nChanY{0}; + int nChipX{0}; + int nChipY{0}; + int nDacs{0}; + int dynamicRange{0}; + int nGappixelsX{0}; + int nGappixelsY{0}; + + detParameters(){} + detParameters(slsDetectorDefs::detectorType type){ + switch (type) { + case slsDetectorDefs::detectorType::GOTTHARD: + nChanX = 128; + nChanY = 1; + nChipX = 10; + nChipY = 1; + nDacs = 8; + dynamicRange = 16; + nGappixelsX = 0; + nGappixelsY = 0; + break; + case slsDetectorDefs::detectorType::JUNGFRAU: + nChanX = 256; + nChanY = 256; + nChipX = 4; + nChipY = 2; + nDacs = 8; + dynamicRange = 16; + nGappixelsX = 0; + nGappixelsY = 0; + break; + case slsDetectorDefs::detectorType::CHIPTESTBOARD: + nChanX = 36; + nChanY = 1; + nChipX = 1; + nChipY = 1; + nDacs = 24; + dynamicRange = 16; + nGappixelsX = 0; + nGappixelsY = 0; + break; + case slsDetectorDefs::detectorType::MOENCH: + nChanX = 32; + nChanY = 1; + nChipX = 1; + nChipY = 1; + nDacs = 8; + dynamicRange = 16; + nGappixelsX = 0; + nGappixelsY = 0; + break; + case slsDetectorDefs::detectorType::EIGER: + nChanX = 256; + nChanY = 256; + nChipX = 4; + nChipY = 1; + nDacs = 16; + dynamicRange = 16; + nGappixelsX = 6; + nGappixelsY = 1; + break; + default: + throw sls::RuntimeError("Unknown detector type! " + + slsDetectorDefs::detectorTypeToString(type)); + } + } }; /** @@ -1747,13 +1806,6 @@ class slsDetector : public virtual slsDetectorDefs{ */ void initSharedMemory(detectorType type, int multi_id, bool verify = true); - /** - * Sets detector parameters depending detector type - * @param type detector type - * @param list structure of parameters to initialize depending on detector type - */ - void setDetectorSpecificParameters(detectorType type, detParameters &list); - /** * Initialize detector structure to defaults * Called when new shared memory is created diff --git a/slsDetectorSoftware/src/slsDetector.cpp b/slsDetectorSoftware/src/slsDetector.cpp index 55470e3de..ab0e1ebe5 100755 --- a/slsDetectorSoftware/src/slsDetector.cpp +++ b/slsDetectorSoftware/src/slsDetector.cpp @@ -98,7 +98,7 @@ int slsDetector::checkDetectorVersionCompatibility() { auto client = DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort); - ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), nullptr, 0); + client.sendCommandThenRead(fnum, &arg, sizeof(arg), nullptr, 0); auto stop = DetectorSocket(detector_shm()->hostname, detector_shm()->stopPort); @@ -225,64 +225,6 @@ void slsDetector::initSharedMemory(detectorType type, int multi_id, } } -void slsDetector::setDetectorSpecificParameters(detectorType type, - detParameters &list) { - switch (type) { - case GOTTHARD: - list.nChanX = 128; - list.nChanY = 1; - list.nChipX = 10; - list.nChipY = 1; - list.nDacs = 8; - list.dynamicRange = 16; - list.nGappixelsX = 0; - list.nGappixelsY = 0; - break; - case JUNGFRAU: - list.nChanX = 256; - list.nChanY = 256; - list.nChipX = 4; - list.nChipY = 2; - list.nDacs = 8; - list.dynamicRange = 16; - list.nGappixelsX = 0; - list.nGappixelsY = 0; - break; - case CHIPTESTBOARD: - list.nChanX = 36; - list.nChanY = 1; - list.nChipX = 1; - list.nChipY = 1; - list.nDacs = 24; - list.dynamicRange = 16; - list.nGappixelsX = 0; - list.nGappixelsY = 0; - break; - case MOENCH: - list.nChanX = 32; - list.nChanY = 1; - list.nChipX = 1; - list.nChipY = 1; - list.nDacs = 8; - list.dynamicRange = 16; - list.nGappixelsX = 0; - list.nGappixelsY = 0; - break; - case EIGER: - list.nChanX = 256; - list.nChanY = 256; - list.nChipX = 4; - list.nChipY = 1; - list.nDacs = 16; - list.dynamicRange = 16; - list.nGappixelsX = 6; - list.nGappixelsY = 1; - break; - default: - throw RuntimeError("Unknown detector type! " + - slsDetectorDefs::detectorTypeToString(type)); - } -} void slsDetector::initializeDetectorStructure(detectorType type) { detector_shm()->shmversion = SLS_SHMVERSION; @@ -391,8 +333,7 @@ void slsDetector::initializeDetectorStructure(detectorType type) { detector_shm()->rxFileOverWrite = true; // get the detector parameters based on type - detParameters parameters{}; - setDetectorSpecificParameters(type, parameters); + detParameters parameters{type}; detector_shm()->nChan[X] = parameters.nChanX; detector_shm()->nChan[Y] = parameters.nChanY; detector_shm()->nChip[X] = parameters.nChipX; @@ -434,16 +375,11 @@ slsDetectorDefs::sls_detector_module *slsDetector::createModule() { slsDetectorDefs::sls_detector_module * slsDetector::createModule(detectorType type) { // get the detector parameters based on type - detParameters parameters{}; - int nch = 0, nc = 0, nd = 0; - try { - setDetectorSpecificParameters(type, parameters); - nch = parameters.nChanX * parameters.nChanY; - nc = parameters.nChipX * parameters.nChipY; - nd = parameters.nDacs; - } catch (...) { - return nullptr; - } + detParameters parameters{type}; + int nch = parameters.nChanX * parameters.nChanY; + int nc = parameters.nChipX * parameters.nChipY; + int nd = parameters.nDacs; + int *dacs = new int[nd]; int *chanregs = new int[nch * nc]; @@ -1262,7 +1198,7 @@ int slsDetector::getThresholdEnergy() { detector_shm()->currentThresholdEV = retval; } if (ret == FORCE_UPDATE) { - ret = updateDetector(); + updateDetector(); } return detector_shm()->currentThresholdEV; } @@ -1329,7 +1265,8 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, } // verify e_eV exists in trimEneregies[] - if ((detector_shm()->nTrimEn == 0) || (e_eV < detector_shm()->trimEnergies[0]) || + if ((detector_shm()->nTrimEn == 0) || + (e_eV < detector_shm()->trimEnergies[0]) || (e_eV > detector_shm()->trimEnergies[detector_shm()->nTrimEn - 1])) { throw RuntimeError("This energy " + std::to_string(e_eV) + " not defined for this module!"); @@ -1348,7 +1285,7 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, sls_detector_module *myMod = nullptr; // normal - if (!interpolate) { + if (interpolate == false) { // find their directory names std::ostringstream ostfn; ostfn << detector_shm()->settingsDir << ssettings << "/" << e_eV << "eV" @@ -1360,16 +1297,13 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, // read the files // myMod = createModule(); // readSettings also checks if create module // is null - if (nullptr == readSettingsFile(settingsfname, myMod, tb)) { + if (readSettingsFile(settingsfname, myMod, tb) == nullptr) { if (myMod != nullptr) { deleteModule(myMod); } return FAIL; } - } - - // interpolate - else { + }else{ // find the trim values int trim1 = -1, trim2 = -1; for (int i = 0; i < detector_shm()->nTrimEn; ++i) { @@ -1853,7 +1787,6 @@ int64_t slsDetector::setTimer(timerIndex index, int64_t t) { case STORAGE_CELL_NUMBER: // send fnum = F_SET_RECEIVER_TIMER; - ret = FAIL; args[1] = detector_shm() ->timerValue[index]; // to the value given by detector retval = -1; @@ -1926,7 +1859,7 @@ int slsDetector::setSpeed(speedVariable sp, int value, int mode) { FILE_LOG(logDEBUG1) << "Speed index " << sp << ": " << retval; } if (ret == FORCE_UPDATE) { - ret = updateDetector(); + updateDetector(); } return retval; } @@ -1952,7 +1885,7 @@ int slsDetector::setDynamicRange(int n) { client.close(); ret = updateDetector(); } - } + } // only for eiger // setting dr consequences on databytes shm @@ -2140,7 +2073,7 @@ uint32_t slsDetector::writeRegister(uint32_t addr, uint32_t val) { << std::hex << retval << std::dec; } if (ret == FORCE_UPDATE) { - ret = updateDetector(); + updateDetector(); } return retval; } @@ -2372,13 +2305,13 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) { break; } - setReceiverSilentMode(static_cast(detector_shm()->receiver_silentMode)); + setReceiverSilentMode( + static_cast(detector_shm()->receiver_silentMode)); // data streaming setReceiverStreamingFrequency(detector_shm()->receiver_read_freq); setReceiverStreamingPort(getReceiverStreamingPort()); setReceiverStreamingIP(getReceiverStreamingIP()); - setAdditionalJsonHeader( - detector_shm()->rxAdditionalJsonHeader); + setAdditionalJsonHeader(detector_shm()->rxAdditionalJsonHeader); enableDataStreamingFromReceiver( static_cast(enableDataStreamingFromReceiver(-1))); if (detector_shm()->myDetectorType == GOTTHARD || @@ -2594,7 +2527,8 @@ void slsDetector::setReceiverStreamingIP(std::string sourceIP) { { struct addrinfo *result; // on failure to convert to a valid ip - if (sls::ConvertHostnameToInternetAddress(sourceIP.c_str(), &result) != 0) { + if (sls::ConvertHostnameToInternetAddress(sourceIP.c_str(), &result) != + 0) { throw RuntimeError("Could not convert rx_zmqip into a valid IP" + sourceIP); } @@ -2673,10 +2607,8 @@ slsDetector::setAdditionalJsonHeader(const std::string &jsonheader) { ret = receiver.sendCommandThenRead(fnum, args, sizeof(args), retvals, sizeof(retvals)); FILE_LOG(logDEBUG1) << "Additional json header: " << retvals; - memset(detector_shm()->rxAdditionalJsonHeader, 0, - MAX_STR_LENGTH); - sls::strcpy_safe(detector_shm()->rxAdditionalJsonHeader, - retvals); + memset(detector_shm()->rxAdditionalJsonHeader, 0, MAX_STR_LENGTH); + sls::strcpy_safe(detector_shm()->rxAdditionalJsonHeader, retvals); } if (ret == FORCE_UPDATE) { updateCachedReceiverVariables(); @@ -2696,10 +2628,8 @@ std::string slsDetector::getAdditionalJsonHeader() { ret = receiver.sendCommandThenRead(fnum, nullptr, 0, retvals, sizeof(retvals)); FILE_LOG(logDEBUG1) << "Additional json header: " << retvals; - memset(detector_shm()->rxAdditionalJsonHeader, 0, - MAX_STR_LENGTH); - sls::strcpy_safe(detector_shm()->rxAdditionalJsonHeader, - retvals); + memset(detector_shm()->rxAdditionalJsonHeader, 0, MAX_STR_LENGTH); + sls::strcpy_safe(detector_shm()->rxAdditionalJsonHeader, retvals); } if (ret == FORCE_UPDATE) { updateCachedReceiverVariables(); @@ -2710,8 +2640,9 @@ std::string slsDetector::getAdditionalJsonHeader() { std::string slsDetector::setAdditionalJsonParameter(const std::string &key, const std::string &value) { if (key.empty() || value.empty()) { - throw RuntimeError("Could not set additional json header parameter as the key or " - "value is empty"); + throw RuntimeError( + "Could not set additional json header parameter as the key or " + "value is empty"); } // validation (ignore if key or value has , : ") @@ -2984,7 +2915,8 @@ int slsDetector::writeCounterBlockFile(const std::string &fname, int startACQ) { int nChan = getTotalNumberOfChannels(); int16_t retvals[nChan]; FILE_LOG(logDEBUG1) << "Reading Counter to " << fname - << (startACQ !=0 ? " and Restarting Acquisition" : "\n"); + << (startACQ != 0 ? " and Restarting Acquisition" + : "\n"); ret = getCounterBlock(retvals, startACQ); if (ret != FAIL) { @@ -3573,9 +3505,10 @@ int slsDetector::programFPGA(std::vector buffer) { while (count > 0) { usleep(1 * 1000 * 1000); --count; - printf( - "%d%%\r", - static_cast((static_cast(ERASE_TIME - count) / ERASE_TIME) * 100)); + printf("%d%%\r", static_cast( + (static_cast(ERASE_TIME - count) / + ERASE_TIME) * + 100)); std::cout << std::flush; } printf("\n"); @@ -3605,9 +3538,10 @@ int slsDetector::programFPGA(std::vector buffer) { currentPointer += unitprogramsize; // print progress - printf( - "%d%%\r", - static_cast((static_cast(totalsize - filesize) / totalsize) * 100)); + printf("%d%%\r", static_cast((static_cast( + totalsize - filesize) / + totalsize) * + 100)); std::cout << std::flush; } else { printf("\n"); @@ -3727,7 +3661,8 @@ int slsDetector::getChanRegs(double *retval) { // the original array has 0 initialized if (myMod->chanregs != nullptr) { for (int i = 0; i < n; ++i) { - retval[i] = static_cast(myMod->chanregs[i] & TRIMBITMASK); + retval[i] = + static_cast(myMod->chanregs[i] & TRIMBITMASK); } } deleteModule(myMod); @@ -3989,8 +3924,9 @@ int slsDetector::updateCachedReceiverVariables() const { FILE_LOG(logDEBUG1) << "Sending update client to receiver server"; if (detector_shm()->receiverOnlineFlag == ONLINE_FLAG) { - auto receiver = sls::ClientSocket("Receiver", detector_shm()->receiver_hostname, - detector_shm()->receiverTCPPort); + auto receiver = + sls::ClientSocket("Receiver", detector_shm()->receiver_hostname, + detector_shm()->receiverTCPPort); ret = receiver.sendCommandThenRead(fnum, nullptr, 0, nullptr, 0); if (ret == FAIL) { std::string msg = "Could not update receiver: " + @@ -4060,8 +3996,7 @@ int slsDetector::updateCachedReceiverVariables() const { // additional json header n += receiver.receiveData(cstring, sizeof(cstring)); - sls::strcpy_safe(detector_shm()->rxAdditionalJsonHeader, - cstring); + sls::strcpy_safe(detector_shm()->rxAdditionalJsonHeader, cstring); // receiver streaming enable n += receiver.receiveData(&i32, sizeof(i32)); @@ -4073,8 +4008,7 @@ int slsDetector::updateCachedReceiverVariables() const { // deactivated padding enable n += receiver.receiveData(&i32, sizeof(i32)); - detector_shm()->rxPadDeactivatedModules = - static_cast(i32); + detector_shm()->rxPadDeactivatedModules = static_cast(i32); // silent mode n += receiver.receiveData(&i32, sizeof(i32)); diff --git a/slsDetectorSoftware/tests/test-slsDetector.cpp b/slsDetectorSoftware/tests/test-slsDetector.cpp index 8a3d44ed0..b6fb6ce39 100755 --- a/slsDetectorSoftware/tests/test-slsDetector.cpp +++ b/slsDetectorSoftware/tests/test-slsDetector.cpp @@ -7,7 +7,7 @@ #include #include -using namespace sls; + TEST_CASE("Set and get trimen", "[detector]") { // Free shared memory to be sure that we start in a clean state @@ -191,4 +191,30 @@ TEST_CASE("Padding and discard policy", "[detector][new]"){ d.freeSharedMemory(); +} + + +TEST_CASE("create detParamets struct", "[detector][new]"){ + detParameters par; + CHECK(sizeof(par) == 32); + CHECK(par.nChanX == 0); + CHECK(par.nChanY == 0); + CHECK(par.nChipX == 0); + CHECK(par.nChipY == 0); + CHECK(par.nDacs == 0); + CHECK(par.dynamicRange == 0); + CHECK(par.nGappixelsX == 0); + CHECK(par.nGappixelsY == 0); + + + detParameters par2{slsDetectorDefs::detectorType::EIGER}; + CHECK(sizeof(par2) == 32); + CHECK(par2.nChanX == 256); + CHECK(par2.nChanY == 256); + CHECK(par2.nChipX == 4); + CHECK(par2.nChipY == 1); + CHECK(par2.nDacs == 16); + CHECK(par2.dynamicRange == 16); + CHECK(par2.nGappixelsX == 6); + CHECK(par2.nGappixelsY == 1); } \ No newline at end of file From cedde395a0c4487299e8d682abd12bcccf7ce9c2 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Wed, 17 Apr 2019 09:05:21 +0200 Subject: [PATCH 08/12] conda meta --- .travis.yml | 2 +- conda-recepie/meta.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index a3774de07..0bbc8d6bf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -45,5 +45,5 @@ deploy: provider: script script: find $HOME/miniconda/conda-bld/${TRAVIS_OS_NAME}-64 -name "*.tar.bz2" -exec anaconda -t $CONDA_TOKEN upload --force {} \; on: - branch: refactor + branch: developer diff --git a/conda-recepie/meta.yaml b/conda-recepie/meta.yaml index b60529d28..f8fe035c4 100755 --- a/conda-recepie/meta.yaml +++ b/conda-recepie/meta.yaml @@ -1,7 +1,7 @@ package: name: sls_detector_software - version: "refactor" + version: "developer" source: - path: .. @@ -76,7 +76,7 @@ outputs: run: - python - numpy - - sls_detector_lib=refactor + - sls_detector_lib=developer - pyzmq - libstdcxx-ng - libgcc-ng From 91813a2c6830eabb0fb94008373511b1aa90d4a7 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Wed, 17 Apr 2019 09:27:45 +0200 Subject: [PATCH 09/12] moved sls_detector_module outside slsDetectorDefs class --- slsDetectorSoftware/src/slsDetector.cpp | 10 ++--- slsSupportLib/include/sls_detector_defs.h | 52 +++++++++++------------ 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/slsDetectorSoftware/src/slsDetector.cpp b/slsDetectorSoftware/src/slsDetector.cpp index ab0e1ebe5..e9e1a234a 100755 --- a/slsDetectorSoftware/src/slsDetector.cpp +++ b/slsDetectorSoftware/src/slsDetector.cpp @@ -368,11 +368,11 @@ void slsDetector::initializeDetectorStructure(detectorType type) { } } -slsDetectorDefs::sls_detector_module *slsDetector::createModule() { +sls_detector_module *slsDetector::createModule() { return createModule(detector_shm()->myDetectorType); } -slsDetectorDefs::sls_detector_module * +sls_detector_module * slsDetector::createModule(detectorType type) { // get the detector parameters based on type detParameters parameters{type}; @@ -3709,7 +3709,7 @@ int slsDetector::setModule(sls_detector_module module, int tb) { return ret; } -slsDetectorDefs::sls_detector_module *slsDetector::getModule() { +sls_detector_module *slsDetector::getModule() { int fnum = F_GET_MODULE; int ret = FAIL; FILE_LOG(logDEBUG1) << "Getting module"; @@ -4810,7 +4810,7 @@ int slsDetector::setDigitalIODelay(uint64_t pinMask, int delay) { return ret; } -slsDetectorDefs::sls_detector_module * +sls_detector_module * slsDetector::interpolateTrim(sls_detector_module *a, sls_detector_module *b, const int energy, const int e1, const int e2, int tb) { @@ -4887,7 +4887,7 @@ slsDetector::interpolateTrim(sls_detector_module *a, sls_detector_module *b, return myMod; } -slsDetectorDefs::sls_detector_module * +sls_detector_module * slsDetector::readSettingsFile(const std::string &fname, sls_detector_module *myMod, int tb) { diff --git a/slsSupportLib/include/sls_detector_defs.h b/slsSupportLib/include/sls_detector_defs.h index 4db2091ff..8a25de884 100755 --- a/slsSupportLib/include/sls_detector_defs.h +++ b/slsSupportLib/include/sls_detector_defs.h @@ -62,7 +62,33 @@ #define DEFAULT_STREAMING_TIMER_IN_MS 200 +/** + @short structure for a detector module + should not be used by unexperienced users + + \see :: moduleRegisterBit ::chipRegisterBit :channelRegisterBit + + @li reg is the module register (e.g. dynamic range? see moduleRegisterBit) + @li dacs is the pointer to the array of dac values (in V) + @li adcs is the pointer to the array of adc values (in V) + @li chipregs is the pointer to the array of chip registers + @li chanregs is the pointer to the array of channel registers + @li gain is the module gain + @li offset is the module offset +*/ +typedef struct { + int serialnumber; /**< is the module serial number */ + int nchan; /**< is the number of channels on the module*/ + int nchip; /**< is the number of chips on the module */ + int ndac; /**< is the number of dacs on the module */ + int reg; /**< is the module register settings (gain level) */ + int iodelay; /**< iodelay */ + int tau; /**< tau */ + int eV; /**< threshold energy */ + int *dacs; /**< is the pointer to the array of the dac values (in V) */ + int *chanregs; /**< is the pointer to the array of the channel registers */ +} sls_detector_module; typedef char mystring[MAX_STR_LENGTH]; @@ -220,33 +246,7 @@ public: int ymax; /**< is the roi ymax (in channel number)*/ } ROI ; - /** - @short structure for a detector module - should not be used by unexperienced users - - \see :: moduleRegisterBit ::chipRegisterBit :channelRegisterBit - - @li reg is the module register (e.g. dynamic range? see moduleRegisterBit) - @li dacs is the pointer to the array of dac values (in V) - @li adcs is the pointer to the array of adc values (in V) - @li chipregs is the pointer to the array of chip registers - @li chanregs is the pointer to the array of channel registers - @li gain is the module gain - @li offset is the module offset - */ - typedef struct { - int serialnumber; /**< is the module serial number */ - int nchan; /**< is the number of channels on the module*/ - int nchip; /**< is the number of chips on the module */ - int ndac; /**< is the number of dacs on the module */ - int reg; /**< is the module register settings (gain level) */ - int iodelay; /**< iodelay */ - int tau; /**< tau */ - int eV; /**< threshold energy */ - int *dacs; /**< is the pointer to the array of the dac values (in V) */ - int *chanregs; /**< is the pointer to the array of the channel registers */ - } sls_detector_module; /** From b46e107f35e807033b7eb121ca4c87793773cfc9 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Wed, 17 Apr 2019 14:28:53 +0200 Subject: [PATCH 10/12] moved detParameters to sls_detector_defs --- slsDetectorSoftware/include/slsDetector.h | 71 -------- slsSupportLib/include/sls_detector_defs.h | 158 +++++++++++++++--- slsSupportLib/tests/CMakeLists.txt | 1 + .../tests/test-sls_detector_defs.cpp | 33 ++++ 4 files changed, 165 insertions(+), 98 deletions(-) create mode 100644 slsSupportLib/tests/test-sls_detector_defs.cpp diff --git a/slsDetectorSoftware/include/slsDetector.h b/slsDetectorSoftware/include/slsDetector.h index 8caee7b71..82335f29f 100755 --- a/slsDetectorSoftware/include/slsDetector.h +++ b/slsDetectorSoftware/include/slsDetector.h @@ -19,78 +19,7 @@ class MySocketTCP; #define NCHIPSMAX 10 #define NCHANSMAX 65536 #define NDACSMAX 16 -/** - * parameter list that has to be initialized depending on the detector type - */ -struct detParameters { - int nChanX{0}; - int nChanY{0}; - int nChipX{0}; - int nChipY{0}; - int nDacs{0}; - int dynamicRange{0}; - int nGappixelsX{0}; - int nGappixelsY{0}; - detParameters(){} - detParameters(slsDetectorDefs::detectorType type){ - switch (type) { - case slsDetectorDefs::detectorType::GOTTHARD: - nChanX = 128; - nChanY = 1; - nChipX = 10; - nChipY = 1; - nDacs = 8; - dynamicRange = 16; - nGappixelsX = 0; - nGappixelsY = 0; - break; - case slsDetectorDefs::detectorType::JUNGFRAU: - nChanX = 256; - nChanY = 256; - nChipX = 4; - nChipY = 2; - nDacs = 8; - dynamicRange = 16; - nGappixelsX = 0; - nGappixelsY = 0; - break; - case slsDetectorDefs::detectorType::CHIPTESTBOARD: - nChanX = 36; - nChanY = 1; - nChipX = 1; - nChipY = 1; - nDacs = 24; - dynamicRange = 16; - nGappixelsX = 0; - nGappixelsY = 0; - break; - case slsDetectorDefs::detectorType::MOENCH: - nChanX = 32; - nChanY = 1; - nChipX = 1; - nChipY = 1; - nDacs = 8; - dynamicRange = 16; - nGappixelsX = 0; - nGappixelsY = 0; - break; - case slsDetectorDefs::detectorType::EIGER: - nChanX = 256; - nChanY = 256; - nChipX = 4; - nChipY = 1; - nDacs = 16; - dynamicRange = 16; - nGappixelsX = 6; - nGappixelsY = 1; - break; - default: - throw sls::RuntimeError("Unknown detector type! " + - slsDetectorDefs::detectorTypeToString(type)); - } - } -}; /** * @short structure allocated in shared memory to store detector settings for IPC and cache diff --git a/slsSupportLib/include/sls_detector_defs.h b/slsSupportLib/include/sls_detector_defs.h index 8a25de884..2062e9451 100755 --- a/slsSupportLib/include/sls_detector_defs.h +++ b/slsSupportLib/include/sls_detector_defs.h @@ -15,6 +15,7 @@ #include #ifdef __cplusplus +#include "sls_detector_exceptions.h" #include #include #endif @@ -62,33 +63,6 @@ #define DEFAULT_STREAMING_TIMER_IN_MS 200 -/** - @short structure for a detector module - - should not be used by unexperienced users - - \see :: moduleRegisterBit ::chipRegisterBit :channelRegisterBit - - @li reg is the module register (e.g. dynamic range? see moduleRegisterBit) - @li dacs is the pointer to the array of dac values (in V) - @li adcs is the pointer to the array of adc values (in V) - @li chipregs is the pointer to the array of chip registers - @li chanregs is the pointer to the array of channel registers - @li gain is the module gain - @li offset is the module offset -*/ -typedef struct { - int serialnumber; /**< is the module serial number */ - int nchan; /**< is the number of channels on the module*/ - int nchip; /**< is the number of chips on the module */ - int ndac; /**< is the number of dacs on the module */ - int reg; /**< is the module register settings (gain level) */ - int iodelay; /**< iodelay */ - int tau; /**< tau */ - int eV; /**< threshold energy */ - int *dacs; /**< is the pointer to the array of the dac values (in V) */ - int *chanregs; /**< is the pointer to the array of the channel registers */ -} sls_detector_module; typedef char mystring[MAX_STR_LENGTH]; @@ -959,3 +933,133 @@ protected: }; #endif ; + +#ifdef __cplusplus +struct detParameters { + int nChanX{0}; + int nChanY{0}; + int nChipX{0}; + int nChipY{0}; + int nDacs{0}; + int dynamicRange{0}; + int nGappixelsX{0}; + int nGappixelsY{0}; + + detParameters() {} + detParameters(slsDetectorDefs::detectorType type) { + switch (type) { + case slsDetectorDefs::detectorType::GOTTHARD: + nChanX = 128; + nChanY = 1; + nChipX = 10; + nChipY = 1; + nDacs = 8; + dynamicRange = 16; + nGappixelsX = 0; + nGappixelsY = 0; + break; + case slsDetectorDefs::detectorType::JUNGFRAU: + nChanX = 256; + nChanY = 256; + nChipX = 4; + nChipY = 2; + nDacs = 8; + dynamicRange = 16; + nGappixelsX = 0; + nGappixelsY = 0; + break; + case slsDetectorDefs::detectorType::CHIPTESTBOARD: + nChanX = 36; + nChanY = 1; + nChipX = 1; + nChipY = 1; + nDacs = 24; + dynamicRange = 16; + nGappixelsX = 0; + nGappixelsY = 0; + break; + case slsDetectorDefs::detectorType::MOENCH: + nChanX = 32; + nChanY = 1; + nChipX = 1; + nChipY = 1; + nDacs = 8; + dynamicRange = 16; + nGappixelsX = 0; + nGappixelsY = 0; + break; + case slsDetectorDefs::detectorType::EIGER: + nChanX = 256; + nChanY = 256; + nChipX = 4; + nChipY = 1; + nDacs = 16; + dynamicRange = 16; + nGappixelsX = 6; + nGappixelsY = 1; + break; + default: + throw sls::RuntimeError( + "Unknown detector type! " + + slsDetectorDefs::detectorTypeToString(type)); + } + } +}; +#endif + +/** + @short structure for a detector module + + should not be used by unexperienced users + + \see :: moduleRegisterBit ::chipRegisterBit :channelRegisterBit + + @li reg is the module register (e.g. dynamic range? see moduleRegisterBit) + @li dacs is the pointer to the array of dac values (in V) + @li adcs is the pointer to the array of adc values (in V) + @li chipregs is the pointer to the array of chip registers + @li chanregs is the pointer to the array of channel registers + @li gain is the module gain + @li offset is the module offset +*/ +#ifdef __cplusplus +struct sls_detector_module { +#else +typedef struct { +#endif + int serialnumber; /**< is the module serial number */ + int nchan; /**< is the number of channels on the module*/ + int nchip; /**< is the number of chips on the module */ + int ndac; /**< is the number of dacs on the module */ + int reg; /**< is the module register settings (gain level) */ + int iodelay; /**< iodelay */ + int tau; /**< tau */ + int eV; /**< threshold energy */ + int *dacs; /**< is the pointer to the array of the dac values (in V) */ + int *chanregs; /**< is the pointer to the array of the channel registers */ + +#ifdef __cplusplus + + sls_detector_module() + : serialnumber(0), nchan(0), nchip(0), ndac(0), reg(0), iodelay(0), + tau(0), eV(0), dacs(nullptr), chanregs(nullptr) {} + sls_detector_module(slsDetectorDefs::detectorType type) { + detParameters parameters{type}; + int nch = parameters.nChanX * parameters.nChanY; + int nc = parameters.nChipX * parameters.nChipY; + int nd = parameters.nDacs; + + ndac = nd; + nchip = nc; + nchan = nch * nc; + dacs = new int[nd]; + chanregs = new int[nch * nc]; + } + ~sls_detector_module(){ + delete[] dacs; + delete[] chanregs; + } +}; +#else +} sls_detector_module; +#endif diff --git a/slsSupportLib/tests/CMakeLists.txt b/slsSupportLib/tests/CMakeLists.txt index 6164cc13d..dad82546a 100755 --- a/slsSupportLib/tests/CMakeLists.txt +++ b/slsSupportLib/tests/CMakeLists.txt @@ -5,4 +5,5 @@ target_sources(tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test-network_utils.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-string_utils.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-Timer.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test-sls_detector_defs.cpp ) \ No newline at end of file diff --git a/slsSupportLib/tests/test-sls_detector_defs.cpp b/slsSupportLib/tests/test-sls_detector_defs.cpp new file mode 100644 index 000000000..4d9ba20c9 --- /dev/null +++ b/slsSupportLib/tests/test-sls_detector_defs.cpp @@ -0,0 +1,33 @@ +#include "catch.hpp" +#include "sls_detector_defs.h" +#include "slsDetector.h" + +using dt = slsDetectorDefs::detectorType; + +TEST_CASE("sls_detector_module default construction", "[support][new]") { + sls_detector_module m; + CHECK(m.serialnumber == 0); + CHECK(m.nchan == 0); + CHECK(m.nchip == 0); + CHECK(m.ndac == 0); + CHECK(m.reg == 0); + CHECK(m.iodelay == 0); + CHECK(m.tau == 0); + CHECK(m.eV == 0); + CHECK(m.dacs == nullptr); + CHECK(m.chanregs == nullptr); +} + +TEST_CASE("sls_detector_module from type", "[support][new]") { + sls_detector_module m(dt::EIGER); + CHECK(m.serialnumber == 0); + CHECK(m.nchan == 256*256*4); + CHECK(m.nchip == 4); + CHECK(m.ndac == 16); + CHECK(m.reg == 0); + CHECK(m.iodelay == 0); + CHECK(m.tau == 0); + CHECK(m.eV == 0); + CHECK(m.dacs != nullptr); + CHECK(m.chanregs != nullptr); +} \ No newline at end of file From ee20cfab1e92bc45a708ff26d0de2cc1b15c92be Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Wed, 17 Apr 2019 16:19:18 +0200 Subject: [PATCH 11/12] removed pointers added constructor --- slsDetectorSoftware/include/slsDetector.h | 4 +- slsDetectorSoftware/src/slsDetector.cpp | 79 ++++++------------- slsSupportLib/include/sls_detector_defs.h | 42 ++++++++-- .../tests/test-sls_detector_defs.cpp | 26 +++++- 4 files changed, 83 insertions(+), 68 deletions(-) diff --git a/slsDetectorSoftware/include/slsDetector.h b/slsDetectorSoftware/include/slsDetector.h index 82335f29f..fc9c42b7a 100755 --- a/slsDetectorSoftware/include/slsDetector.h +++ b/slsDetectorSoftware/include/slsDetector.h @@ -1321,7 +1321,7 @@ class slsDetector : public virtual slsDetectorDefs{ * @returns ok or fail * \sa ::sls_detector_module */ - int setModule(sls_detector_module module, int tb = 1); + int setModule(sls_detector_module& module, int tb = 1); /** * Get module structure from detector (all detectors) @@ -1805,7 +1805,7 @@ class slsDetector : public virtual slsDetectorDefs{ * @param tb 1 to include trimbits, 0 to exclude (used for eiger) * @returns the pointer to the module structure with interpolated values or NULL if error */ - sls_detector_module *interpolateTrim( + sls_detector_module interpolateTrim( sls_detector_module *a, sls_detector_module *b, const int energy, const int e1, const int e2, int tb = 1); diff --git a/slsDetectorSoftware/src/slsDetector.cpp b/slsDetectorSoftware/src/slsDetector.cpp index e9e1a234a..213508a46 100755 --- a/slsDetectorSoftware/src/slsDetector.cpp +++ b/slsDetectorSoftware/src/slsDetector.cpp @@ -1280,10 +1280,7 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, break; } } - - // fill detector module structure - sls_detector_module *myMod = nullptr; - + sls_detector_module myMod{detector_shm()->myDetectorType}; // normal if (interpolate == false) { // find their directory names @@ -1294,13 +1291,7 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, std::string settingsfname = ostfn.str(); FILE_LOG(logDEBUG1) << "Settings File is " << settingsfname; - // read the files - // myMod = createModule(); // readSettings also checks if create module - // is null - if (readSettingsFile(settingsfname, myMod, tb) == nullptr) { - if (myMod != nullptr) { - deleteModule(myMod); - } + if (readSettingsFile(settingsfname, &myMod, tb) == nullptr) { return FAIL; } }else{ @@ -1330,51 +1321,33 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, // read the files FILE_LOG(logDEBUG1) << "Settings Files are " << settingsfname1 << " and " << settingsfname2; - sls_detector_module *myMod1 = createModule(); - sls_detector_module *myMod2 = createModule(); - if (nullptr == readSettingsFile(settingsfname1, myMod1, tb)) { - - deleteModule(myMod1); - deleteModule(myMod2); + sls_detector_module myMod1{detector_shm()->myDetectorType}; + sls_detector_module myMod2{detector_shm()->myDetectorType}; + if (readSettingsFile(settingsfname1, &myMod1, tb) == nullptr) { throw RuntimeError( "setThresholdEnergyAndSettings: Could not open settings file"); } - if (nullptr == readSettingsFile(settingsfname2, myMod2, tb)) { - deleteModule(myMod1); - deleteModule(myMod2); + if (readSettingsFile(settingsfname2, &myMod2, tb) == nullptr) { throw RuntimeError( "setThresholdEnergyAndSettings: Could not open settings file"); } - if (myMod1->iodelay != myMod2->iodelay) { - deleteModule(myMod1); - deleteModule(myMod2); + if (myMod1.iodelay != myMod2.iodelay) { throw RuntimeError("setThresholdEnergyAndSettings: Iodelays do not " "match between files"); } // interpolate module - myMod = interpolateTrim(myMod1, myMod2, e_eV, trim1, trim2, tb); - if (myMod == nullptr) { - deleteModule(myMod1); - deleteModule(myMod2); - throw RuntimeError("setThresholdEnergyAndSettings: Could not " - "interpolate, different " - "dac values in files"); - } - // interpolate tau - myMod->iodelay = myMod1->iodelay; - myMod->tau = - linearInterpolation(e_eV, trim1, trim2, myMod1->tau, myMod2->tau); - // printf("new tau:%d\n",tau); + myMod = interpolateTrim(&myMod1, &myMod2, e_eV, trim1, trim2, tb); - deleteModule(myMod1); - deleteModule(myMod2); + // // interpolate tau + myMod.iodelay = myMod1.iodelay; + myMod.tau = + linearInterpolation(e_eV, trim1, trim2, myMod1.tau, myMod2.tau); } - myMod->reg = detector_shm()->currentSettings; - myMod->eV = e_eV; - setModule(*myMod, tb); - deleteModule(myMod); + myMod.reg = detector_shm()->currentSettings; + myMod.eV = e_eV; + setModule(myMod, tb); if (getSettings() != is) { throw RuntimeError("setThresholdEnergyAndSettings: Could not set " "settings in detector"); @@ -3670,7 +3643,7 @@ int slsDetector::getChanRegs(double *retval) { return n; } -int slsDetector::setModule(sls_detector_module module, int tb) { +int slsDetector::setModule(sls_detector_module& module, int tb) { int fnum = F_SET_MODULE; int ret = FAIL; int retval = -1; @@ -4810,7 +4783,7 @@ int slsDetector::setDigitalIODelay(uint64_t pinMask, int delay) { return ret; } -sls_detector_module * +sls_detector_module slsDetector::interpolateTrim(sls_detector_module *a, sls_detector_module *b, const int energy, const int e1, const int e2, int tb) { @@ -4821,10 +4794,7 @@ slsDetector::interpolateTrim(sls_detector_module *a, sls_detector_module *b, "Interpolation of Trim values not implemented for this detector!"); } - sls_detector_module *myMod = createModule(detector_shm()->myDetectorType); - if (myMod == nullptr) { - throw RuntimeError("Could not create module"); - } + sls_detector_module myMod{detector_shm()->myDetectorType}; enum eiger_DacIndex { SVP, VTR, @@ -4849,10 +4819,9 @@ slsDetector::interpolateTrim(sls_detector_module *a, sls_detector_module *b, int num_dacs_to_copy = sizeof(dacs_to_copy) / sizeof(dacs_to_copy[0]); for (int i = 0; i < num_dacs_to_copy; ++i) { if (a->dacs[dacs_to_copy[i]] != b->dacs[dacs_to_copy[i]]) { - deleteModule(myMod); - return nullptr; + throw RuntimeError("Interpolate module: dacs different"); } - myMod->dacs[dacs_to_copy[i]] = a->dacs[dacs_to_copy[i]]; + myMod.dacs[dacs_to_copy[i]] = a->dacs[dacs_to_copy[i]]; } // Copy irrelevant dacs (without failing): CAL @@ -4864,7 +4833,7 @@ slsDetector::interpolateTrim(sls_detector_module *a, sls_detector_module *b, "Taking first: " << a->dacs[CAL]; } - myMod->dacs[CAL] = a->dacs[CAL]; + myMod.dacs[CAL] = a->dacs[CAL]; // Interpolate vrf, vcmp, vcp int dacs_to_interpolate[] = {VRF, VCMP_LL, VCMP_LR, VCMP_RL, @@ -4872,15 +4841,15 @@ slsDetector::interpolateTrim(sls_detector_module *a, sls_detector_module *b, int num_dacs_to_interpolate = sizeof(dacs_to_interpolate) / sizeof(dacs_to_interpolate[0]); for (int i = 0; i < num_dacs_to_interpolate; ++i) { - myMod->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]]); } // Interpolate all trimbits if (tb != 0) { - for (int i = 0; i < myMod->nchan; ++i) { - myMod->chanregs[i] = linearInterpolation( + for (int i = 0; i < myMod.nchan; ++i) { + myMod.chanregs[i] = linearInterpolation( energy, e1, e2, a->chanregs[i], b->chanregs[i]); } } diff --git a/slsSupportLib/include/sls_detector_defs.h b/slsSupportLib/include/sls_detector_defs.h index 2062e9451..88ed58e23 100755 --- a/slsSupportLib/include/sls_detector_defs.h +++ b/slsSupportLib/include/sls_detector_defs.h @@ -16,6 +16,7 @@ #include #ifdef __cplusplus #include "sls_detector_exceptions.h" +#include #include #include #endif @@ -1043,22 +1044,47 @@ typedef struct { sls_detector_module() : serialnumber(0), nchan(0), nchip(0), ndac(0), reg(0), iodelay(0), tau(0), eV(0), dacs(nullptr), chanregs(nullptr) {} + sls_detector_module(slsDetectorDefs::detectorType type) { detParameters parameters{type}; int nch = parameters.nChanX * parameters.nChanY; int nc = parameters.nChipX * parameters.nChipY; - int nd = parameters.nDacs; + // int nd = parameters.nDacs; - ndac = nd; + ndac = parameters.nDacs; nchip = nc; nchan = nch * nc; - dacs = new int[nd]; - chanregs = new int[nch * nc]; + dacs = new int[ndac]; + chanregs = new int[nchan]; + } + + sls_detector_module(const sls_detector_module &other) + : dacs(nullptr), chanregs(nullptr) { + *this = other; + } + + sls_detector_module &operator=(const sls_detector_module &other) { + delete[] dacs; + delete[] chanregs; + serialnumber = other.serialnumber; + nchan = other.nchan; + nchip = other.nchip; + ndac = other.ndac; + reg = other.reg; + iodelay = other.iodelay; + tau = other.tau; + eV = other.eV; + dacs = new int[ndac]; + std::copy(other.dacs, other.dacs + ndac, dacs); + chanregs = new int[nchan]; + std::copy(other.chanregs, other.chanregs + nchan, chanregs); + return *this; + } + + ~sls_detector_module() { + delete[] dacs; + delete[] chanregs; } - ~sls_detector_module(){ - delete[] dacs; - delete[] chanregs; - } }; #else } sls_detector_module; diff --git a/slsSupportLib/tests/test-sls_detector_defs.cpp b/slsSupportLib/tests/test-sls_detector_defs.cpp index 4d9ba20c9..9b745a29e 100644 --- a/slsSupportLib/tests/test-sls_detector_defs.cpp +++ b/slsSupportLib/tests/test-sls_detector_defs.cpp @@ -1,6 +1,6 @@ #include "catch.hpp" -#include "sls_detector_defs.h" #include "slsDetector.h" +#include "sls_detector_defs.h" using dt = slsDetectorDefs::detectorType; @@ -18,10 +18,10 @@ TEST_CASE("sls_detector_module default construction", "[support][new]") { CHECK(m.chanregs == nullptr); } -TEST_CASE("sls_detector_module from type", "[support][new]") { +TEST_CASE("sls_detector_module from type", "[support]") { sls_detector_module m(dt::EIGER); CHECK(m.serialnumber == 0); - CHECK(m.nchan == 256*256*4); + CHECK(m.nchan == 256 * 256 * 4); CHECK(m.nchip == 4); CHECK(m.ndac == 16); CHECK(m.reg == 0); @@ -30,4 +30,24 @@ TEST_CASE("sls_detector_module from type", "[support][new]") { CHECK(m.eV == 0); CHECK(m.dacs != nullptr); CHECK(m.chanregs != nullptr); +} + +TEST_CASE("assign module", "[support]") { + sls_detector_module m0; + sls_detector_module m1(dt::EIGER); + m1.serialnumber = 14; + m1.reg = 500; + m1.iodelay = 750; + + m0 = m1; // Assignment operator + CHECK(m0.serialnumber == 14); + CHECK(m0.reg == 500); + CHECK(m0.iodelay == 750); + CHECK(m0.nchan == 256 * 256 * 4); + + auto m3 = m1; // Copy constructor + CHECK(m3.serialnumber == 14); + CHECK(m3.reg == 500); + CHECK(m3.iodelay == 750); + CHECK(m3.nchan == 256 * 256 * 4); } \ No newline at end of file From 849d3ba0497ca60348d23249f4849c77cf7a5c8c Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Wed, 17 Apr 2019 17:17:59 +0200 Subject: [PATCH 12/12] removed create and delete module --- .../include/multiSlsDetector.h | 7 - slsDetectorSoftware/include/slsDetector.h | 35 +-- slsDetectorSoftware/src/multiSlsDetector.cpp | 12 - slsDetectorSoftware/src/slsDetector.cpp | 269 +++++------------- 4 files changed, 79 insertions(+), 244 deletions(-) diff --git a/slsDetectorSoftware/include/multiSlsDetector.h b/slsDetectorSoftware/include/multiSlsDetector.h index 9130e7497..227d47b56 100755 --- a/slsDetectorSoftware/include/multiSlsDetector.h +++ b/slsDetectorSoftware/include/multiSlsDetector.h @@ -1488,13 +1488,6 @@ class multiSlsDetector : public virtual slsDetectorDefs { */ int setAutoComparatorDisableMode(int ival = -1, int detPos = -1); - /** - * Returns the trimbits from the detector's shared memmory (Mythen, Eiger) - * @param retval is the array with the trimbits - * @param detPos -1 for all detectors in list or specific detector position - * @returns total number of channels for the detector - */ - int getChanRegs(double *retval, int detPos = -1); /** * Set Rate correction ( Eiger) diff --git a/slsDetectorSoftware/include/slsDetector.h b/slsDetectorSoftware/include/slsDetector.h index fc9c42b7a..2d9f54289 100755 --- a/slsDetectorSoftware/include/slsDetector.h +++ b/slsDetectorSoftware/include/slsDetector.h @@ -1305,12 +1305,12 @@ class slsDetector : public virtual slsDetectorDefs{ */ int setAutoComparatorDisableMode(int ival = -1); - /** - * Returns the trimbits from the detector's shared memmory (Eiger) - * @param retval is the array with the trimbits - * @returns total number of channels for the detector + + /** + * Get trimbit filename with path for settings and energy + * */ - int getChanRegs(double *retval); + std::string getTrimbitFilename(detectorSettings settings, int e_eV); /** * Configure Module (Eiger) @@ -1327,7 +1327,7 @@ class slsDetector : public virtual slsDetectorDefs{ * Get module structure from detector (all detectors) * @returns pointer to module structure (which has been created and must then be deleted) */ - sls_detector_module *getModule(); + sls_detector_module getModule(); /** * Set Rate correction (Eiger) @@ -1742,27 +1742,6 @@ class slsDetector : public virtual slsDetectorDefs{ */ void initializeDetectorStructure(detectorType type); - /** - * Allocates the memory for a sls_detector_module structure and initializes it - * Uses current detector type - * @returns myMod the pointer to the allocate memory location - */ - sls_detector_module *createModule(); - - /** - * Allocates the memory for a sls_detector_module structure and initializes it - * Has detector type - * @param type detector type - * @returns myMod the pointer to the allocate dmemory location - */ - sls_detector_module *createModule(detectorType type); - - /** - * Frees the memory for a sls_detector_module structure - * @param myMod the pointer to the memory to be freed - */ - void deleteModule(sls_detector_module *myMod); - /** * Send a sls_detector_module structure over socket * @param myMod module structure to send @@ -1818,7 +1797,7 @@ class slsDetector : public virtual slsDetectorDefs{ * @returns the pointer to myMod or NULL if reading the file failed */ - sls_detector_module *readSettingsFile(const std::string &fname, sls_detector_module *myMod = nullptr, int tb = 1); + sls_detector_module readSettingsFile(const std::string &fname, int tb = 1); /** * writes a trim/settings file diff --git a/slsDetectorSoftware/src/multiSlsDetector.cpp b/slsDetectorSoftware/src/multiSlsDetector.cpp index df53fe95b..b4fcfefe5 100755 --- a/slsDetectorSoftware/src/multiSlsDetector.cpp +++ b/slsDetectorSoftware/src/multiSlsDetector.cpp @@ -2729,18 +2729,6 @@ int multiSlsDetector::setAutoComparatorDisableMode(int ival, int detPos) { return sls::minusOneIfDifferent(r); } -int multiSlsDetector::getChanRegs(double *retval, int detPos) { - - int offset = 0; - std::vector r; - for (auto &d : detectors) { - int nch = d->getTotalNumberOfChannels(); - double result[nch]; - r.push_back(d->getChanRegs(result)); - memcpy(retval + offset, result, nch * sizeof(double)); - } - return sls::minusOneIfDifferent(r); -} int multiSlsDetector::setRateCorrection(int64_t t, int detPos) { // single diff --git a/slsDetectorSoftware/src/slsDetector.cpp b/slsDetectorSoftware/src/slsDetector.cpp index 213508a46..70e253ef3 100755 --- a/slsDetectorSoftware/src/slsDetector.cpp +++ b/slsDetectorSoftware/src/slsDetector.cpp @@ -368,37 +368,6 @@ void slsDetector::initializeDetectorStructure(detectorType type) { } } -sls_detector_module *slsDetector::createModule() { - return createModule(detector_shm()->myDetectorType); -} - -sls_detector_module * -slsDetector::createModule(detectorType type) { - // get the detector parameters based on type - detParameters parameters{type}; - int nch = parameters.nChanX * parameters.nChanY; - int nc = parameters.nChipX * parameters.nChipY; - int nd = parameters.nDacs; - - int *dacs = new int[nd]; - int *chanregs = new int[nch * nc]; - - auto *myMod = new sls_detector_module; - myMod->ndac = nd; - myMod->nchip = nc; - myMod->nchan = nch * nc; - myMod->dacs = dacs; - myMod->chanregs = chanregs; - return myMod; -} - -void slsDetector::deleteModule(sls_detector_module *myMod) { - if (myMod != nullptr) { - delete[] myMod->dacs; - delete[] myMod->chanregs; - delete myMod; - } -} int slsDetector::sendModule(sls_detector_module *myMod, sls::ClientSocket &client) { @@ -1235,34 +1204,6 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, detectorSettings is = ((isettings != GET_SETTINGS) ? isettings : detector_shm()->currentSettings); - std::string ssettings; - switch (is) { - case STANDARD: - ssettings = "/standard"; - detector_shm()->currentSettings = STANDARD; - break; - case HIGHGAIN: - ssettings = "/highgain"; - detector_shm()->currentSettings = HIGHGAIN; - break; - case LOWGAIN: - ssettings = "/lowgain"; - detector_shm()->currentSettings = LOWGAIN; - break; - case VERYHIGHGAIN: - ssettings = "/veryhighgain"; - detector_shm()->currentSettings = VERYHIGHGAIN; - break; - case VERYLOWGAIN: - ssettings = "/verylowgain"; - detector_shm()->currentSettings = VERYLOWGAIN; - break; - default: - std::ostringstream ss; - ss << "Unknown settings " << getDetectorSettings(is) - << " for this detector!"; - throw RuntimeError(ss.str()); - } // verify e_eV exists in trimEneregies[] if ((detector_shm()->nTrimEn == 0) || @@ -1272,28 +1213,18 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, " not defined for this module!"); } - // find if interpolation required - bool interpolate = true; - for (int i = 0; i < detector_shm()->nTrimEn; ++i) { - if (detector_shm()->trimEnergies[i] == e_eV) { - interpolate = false; - break; - } - } - sls_detector_module myMod{detector_shm()->myDetectorType}; - // normal - if (interpolate == false) { - // find their directory names - std::ostringstream ostfn; - ostfn << detector_shm()->settingsDir << ssettings << "/" << e_eV << "eV" - << "/noise.sn" << std::setfill('0') << std::setw(3) << std::dec - << getId(DETECTOR_SERIAL_NUMBER) << std::setbase(10); - std::string settingsfname = ostfn.str(); - FILE_LOG(logDEBUG1) << "Settings File is " << settingsfname; - if (readSettingsFile(settingsfname, &myMod, tb) == nullptr) { - return FAIL; - } + bool interpolate = + std::all_of(detector_shm()->trimEnergies, + detector_shm()->trimEnergies + detector_shm()->nTrimEn, + [e_eV](const int &e) { return e != e_eV; }); + + sls_detector_module myMod{detector_shm()->myDetectorType}; + + if (!interpolate) { + std::string settingsfname = getTrimbitFilename(is, e_eV); + FILE_LOG(logDEBUG1) << "Settings File is " << settingsfname; + myMod = readSettingsFile(settingsfname, tb); }else{ // find the trim values int trim1 = -1, trim2 = -1; @@ -1304,47 +1235,23 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, break; } } - // find their directory names - std::ostringstream ostfn; - ostfn << detector_shm()->settingsDir << ssettings << "/" << trim1 - << "eV" - << "/noise.sn" << std::setfill('0') << std::setw(3) << std::dec - << getId(DETECTOR_SERIAL_NUMBER) << std::setbase(10); - std::string settingsfname1 = ostfn.str(); - ostfn.str(""); - ostfn.clear(); - ostfn << detector_shm()->settingsDir << ssettings << "/" << trim2 - << "eV" - << "/noise.sn" << std::setfill('0') << std::setw(3) << std::dec - << getId(DETECTOR_SERIAL_NUMBER) << std::setbase(10); - std::string settingsfname2 = ostfn.str(); - // read the files + std::string settingsfname1 = getTrimbitFilename(is, trim1); + std::string settingsfname2 = getTrimbitFilename(is, trim2); FILE_LOG(logDEBUG1) << "Settings Files are " << settingsfname1 << " and " << settingsfname2; - sls_detector_module myMod1{detector_shm()->myDetectorType}; - sls_detector_module myMod2{detector_shm()->myDetectorType}; - if (readSettingsFile(settingsfname1, &myMod1, tb) == nullptr) { - throw RuntimeError( - "setThresholdEnergyAndSettings: Could not open settings file"); - } - if (readSettingsFile(settingsfname2, &myMod2, tb) == nullptr) { - throw RuntimeError( - "setThresholdEnergyAndSettings: Could not open settings file"); - } + auto myMod1 = readSettingsFile(settingsfname1, tb); + auto myMod2 = readSettingsFile(settingsfname2, tb); if (myMod1.iodelay != myMod2.iodelay) { throw RuntimeError("setThresholdEnergyAndSettings: Iodelays do not " "match between files"); } - - // interpolate module myMod = interpolateTrim(&myMod1, &myMod2, e_eV, trim1, trim2, tb); - - // // interpolate tau myMod.iodelay = myMod1.iodelay; myMod.tau = linearInterpolation(e_eV, trim1, trim2, myMod1.tau, myMod2.tau); } + detector_shm()->currentSettings = is; myMod.reg = detector_shm()->currentSettings; myMod.eV = e_eV; setModule(myMod, tb); @@ -1355,6 +1262,37 @@ int slsDetector::setThresholdEnergyAndSettings(int e_eV, return OK; } +std::string slsDetector::getTrimbitFilename(detectorSettings s, int e_eV){ + std::string ssettings; + switch (s) { + case STANDARD: + ssettings = "/standard"; + break; + case HIGHGAIN: + ssettings = "/highgain"; + break; + case LOWGAIN: + ssettings = "/lowgain"; + break; + case VERYHIGHGAIN: + ssettings = "/veryhighgain"; + break; + case VERYLOWGAIN: + ssettings = "/verylowgain"; + break; + default: + std::ostringstream ss; + ss << "Unknown settings " << getDetectorSettings(s) + << " for this detector!"; + throw RuntimeError(ss.str()); + } + std::ostringstream ostfn; + ostfn << detector_shm()->settingsDir << ssettings << "/" << e_eV << "eV" + << "/noise.sn" << std::setfill('0') << std::setw(3) << std::dec + << getId(DETECTOR_SERIAL_NUMBER) << std::setbase(10); + return ostfn.str(); +} + std::string slsDetector::getSettingsDir() { return std::string(detector_shm()->settingsDir); } @@ -1379,19 +1317,8 @@ int slsDetector::loadSettingsFile(const std::string &fname) { } } fn = ostfn.str(); - - // read settings file - sls_detector_module *myMod = nullptr; - myMod = readSettingsFile(fn, myMod); - - // set module - int ret = FAIL; - if (myMod != nullptr) { - myMod->reg = -1; - myMod->eV = -1; - ret = setModule(*myMod); - deleteModule(myMod); - } + auto myMod = readSettingsFile(fn); + int ret = setModule(myMod); return ret; } @@ -1406,14 +1333,8 @@ int slsDetector::saveSettingsFile(const std::string &fname) { << getId(DETECTOR_SERIAL_NUMBER); } fn = ostfn.str(); - - // get module - int ret = FAIL; - sls_detector_module *myMod = getModule(); - if (myMod != nullptr) { - ret = writeSettingsFile(fn, *myMod); - deleteModule(myMod); - } + sls_detector_module myMod = getModule(); + int ret = writeSettingsFile(fn, myMod); return ret; } @@ -3625,23 +3546,6 @@ int slsDetector::setAutoComparatorDisableMode(int ival) { return retval; } -int slsDetector::getChanRegs(double *retval) { - int n = getTotalNumberOfChannels(); - // update chanregs - sls_detector_module *myMod = getModule(); - - if (myMod != nullptr) { - // the original array has 0 initialized - if (myMod->chanregs != nullptr) { - for (int i = 0; i < n; ++i) { - retval[i] = - static_cast(myMod->chanregs[i] & TRIMBITMASK); - } - } - deleteModule(myMod); - } - return n; -} int slsDetector::setModule(sls_detector_module& module, int tb) { int fnum = F_SET_MODULE; @@ -3682,27 +3586,24 @@ int slsDetector::setModule(sls_detector_module& module, int tb) { return ret; } -sls_detector_module *slsDetector::getModule() { +sls_detector_module slsDetector::getModule() { int fnum = F_GET_MODULE; int ret = FAIL; FILE_LOG(logDEBUG1) << "Getting module"; - sls_detector_module *myMod = createModule(); - if (myMod == nullptr) { - throw RuntimeError("Could not create module"); - } + sls_detector_module myMod{detector_shm()->myDetectorType}; if (detector_shm()->onlineFlag == ONLINE_FLAG) { auto client = DetectorSocket(detector_shm()->hostname, detector_shm()->controlPort); ret = client.sendCommandThenRead(fnum, nullptr, 0, nullptr, 0); - receiveModule(myMod, client); + receiveModule(&myMod, client); } if (ret == FORCE_UPDATE) { ret = updateDetector(); } if (ret == OK) { - if (myMod->eV != -1) { - detector_shm()->currentThresholdEV = myMod->eV; + if (myMod.eV != -1) { + detector_shm()->currentThresholdEV = myMod.eV; } } return myMod; @@ -4856,20 +4757,11 @@ slsDetector::interpolateTrim(sls_detector_module *a, sls_detector_module *b, return myMod; } -sls_detector_module * -slsDetector::readSettingsFile(const std::string &fname, - sls_detector_module *myMod, int tb) { +sls_detector_module +slsDetector::readSettingsFile(const std::string &fname, int tb) { FILE_LOG(logDEBUG1) << "Read settings file " << fname; - bool modCreated = - false; // If we create a module it must be deleted, TODO! usre RAII - if (myMod == nullptr) { - myMod = createModule(detector_shm()->myDetectorType); - if (myMod == nullptr) { - throw RuntimeError("Could not create module"); - } - modCreated = true; - } + sls_detector_module myMod(detector_shm()->myDetectorType); std::vector names; switch (detector_shm()->myDetectorType) { @@ -4896,11 +4788,6 @@ slsDetector::readSettingsFile(const std::string &fname, names.emplace_back("VDAC7"); break; default: - if (modCreated) { - if (myMod != nullptr) { - deleteModule(myMod); - } - } throw RuntimeError( "Unknown detector type - unknown format for settings file"); } @@ -4913,9 +4800,6 @@ slsDetector::readSettingsFile(const std::string &fname, infile.open(fname.c_str(), std::ios_base::in); } if (!infile.is_open()) { - if (modCreated) { - deleteModule(myMod); - } throw RuntimeError("Could not open settings file for reading: " + fname); } @@ -4923,18 +4807,18 @@ slsDetector::readSettingsFile(const std::string &fname, // eiger if (detector_shm()->myDetectorType == EIGER) { bool allread = false; - infile.read(reinterpret_cast(myMod->dacs), - sizeof(int) * (myMod->ndac)); + infile.read(reinterpret_cast(myMod.dacs), + sizeof(int) * (myMod.ndac)); if (infile.good()) { - infile.read(reinterpret_cast(&myMod->iodelay), - sizeof(myMod->iodelay)); + infile.read(reinterpret_cast(&myMod.iodelay), + sizeof(myMod.iodelay)); if (infile.good()) { - infile.read(reinterpret_cast(&myMod->tau), - sizeof(myMod->tau)); + infile.read(reinterpret_cast(&myMod.tau), + sizeof(myMod.tau)); if (tb != 0) { if (infile.good()) { - infile.read(reinterpret_cast(myMod->chanregs), - sizeof(int) * (myMod->nchan)); + infile.read(reinterpret_cast(myMod.chanregs), + sizeof(int) * (myMod.nchan)); if (infile) { allread = true; } @@ -4945,19 +4829,16 @@ slsDetector::readSettingsFile(const std::string &fname, } } if (!allread) { - if (modCreated) { - deleteModule(myMod); - } infile.close(); throw RuntimeError("readSettingsFile: Could not load all values " "for settings for " + fname); } - for (int i = 0; i < myMod->ndac; ++i) { - FILE_LOG(logDEBUG1) << "dac " << i << ":" << myMod->dacs[i]; + for (int i = 0; i < myMod.ndac; ++i) { + FILE_LOG(logDEBUG1) << "dac " << i << ":" << myMod.dacs[i]; } - FILE_LOG(logDEBUG1) << "iodelay:" << myMod->iodelay; - FILE_LOG(logDEBUG1) << "tau:" << myMod->tau; + FILE_LOG(logDEBUG1) << "iodelay:" << myMod.iodelay; + FILE_LOG(logDEBUG1) << "tau:" << myMod.tau; } // gotthard, jungfrau @@ -4977,7 +4858,7 @@ slsDetector::readSettingsFile(const std::string &fname, bool found = false; for (size_t i = 0; i < names.size(); ++i) { if (sargname == names[i]) { - myMod->dacs[i] = ival; + myMod.dacs[i] = ival; found = true; FILE_LOG(logDEBUG1) << names[i] << "(" << i << "): " << ival; @@ -4987,17 +4868,11 @@ slsDetector::readSettingsFile(const std::string &fname, if (!found) { throw RuntimeError("readSettingsFile: Unknown dac: " + sargname); - if (modCreated) { - deleteModule(myMod); - } infile.close(); } } // not all read if (idac != names.size()) { - if (modCreated) { - deleteModule(myMod); - } infile.close(); throw RuntimeError("Could read only " + std::to_string(idac) + " dacs. Expected " +