From 7a00732fa81026a8f32f1c2964299214c952cbb8 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Thu, 16 Jan 2020 11:39:35 +0100 Subject: [PATCH] various minor things from clang-tidy --- slsDetectorSoftware/include/Detector.h | 2 +- slsDetectorSoftware/src/Detector.cpp | 3 +- slsDetectorSoftware/src/multiSlsDetector.cpp | 2 +- slsDetectorSoftware/src/slsDetector.cpp | 62 ++++++++++---------- slsDetectorSoftware/src/slsDetector.h | 4 +- slsSupportLib/include/sls_detector_defs.h | 4 +- 6 files changed, 39 insertions(+), 38 deletions(-) diff --git a/slsDetectorSoftware/include/Detector.h b/slsDetectorSoftware/include/Detector.h index da6863319..4ee1e2dc2 100644 --- a/slsDetectorSoftware/include/Detector.h +++ b/slsDetectorSoftware/include/Detector.h @@ -1054,7 +1054,7 @@ class Detector { Result> getRxDbitList(Positions pos = {}) const; /** [CTB] list contains the set of bits (0-63) to save */ - void setRxDbitList(std::vector list, Positions pos = {}); + void setRxDbitList(const std::vector& list, Positions pos = {}); /** [CTB] */ Result getRxDbitOffset(Positions pos = {}) const; diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index ef292712c..fd0b6241d 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -1414,7 +1414,7 @@ Result> Detector::getRxDbitList(Positions pos) const { return pimpl->Parallel(&slsDetector::getReceiverDbitList, pos); } -void Detector::setRxDbitList(std::vector list, Positions pos) { +void Detector::setRxDbitList(const std::vector& list, Positions pos) { pimpl->Parallel(&slsDetector::setReceiverDbitList, pos, list); } @@ -1776,6 +1776,7 @@ std::vector Detector::getPortNumbers(int start_port) { break; } std::vector res; + res.reserve(size()); for (int idet = 0; idet < size(); ++idet) { res.push_back(start_port + (idet * num_sockets_per_detector)); } diff --git a/slsDetectorSoftware/src/multiSlsDetector.cpp b/slsDetectorSoftware/src/multiSlsDetector.cpp index 0ba72c2bf..6154122b0 100755 --- a/slsDetectorSoftware/src/multiSlsDetector.cpp +++ b/slsDetectorSoftware/src/multiSlsDetector.cpp @@ -643,7 +643,7 @@ void multiSlsDetector::readFrameFromReceiver() { << "\n\tsingledetrowoffset: " << singledetrowoffset << "\n\trowoffset: " << rowoffset; - if (eiger && (flippedDataX != 0u)) { + if (eiger && (flippedDataX != 0U)) { for (uint32_t i = 0; i < nPixelsY; ++i) { memcpy(((char *)multiframe) + ((yoffset + (nPixelsY - 1 - i)) * diff --git a/slsDetectorSoftware/src/slsDetector.cpp b/slsDetectorSoftware/src/slsDetector.cpp index fcaacdfbf..c3f75ad2c 100755 --- a/slsDetectorSoftware/src/slsDetector.cpp +++ b/slsDetectorSoftware/src/slsDetector.cpp @@ -343,9 +343,9 @@ void slsDetector::initializeDetectorStructure(detectorType type) { (detId * ((shm()->myDetectorType == EIGER) ? 2 : 1)); shm()->rxUpstream = false; shm()->rxReadFreq = 1; - shm()->zmqip = 0u; - shm()->rxZmqip = 0u; - shm()->gappixels = 0u; + shm()->zmqip = 0U; + shm()->rxZmqip = 0U; + shm()->gappixels = 0U; memset(shm()->rxAdditionalJsonHeader, 0, MAX_STR_LENGTH); shm()->rxFrameDiscardMode = NO_DISCARD; shm()->rxFramePadding = true; @@ -558,7 +558,7 @@ void slsDetector::updateNumberOfChannels() { nachans = 32; } else { for (int ich = 0; ich < 32; ++ich) { - if ((mask & (1 << ich)) != 0u) + if ((mask & (1 << ich)) != 0U) ++nachans; } } @@ -578,7 +578,7 @@ void slsDetector::updateNumberOfChannels() { } slsDetectorDefs::xy slsDetector::getNumberOfChannels() const { - slsDetectorDefs::xy coord; + slsDetectorDefs::xy coord{}; coord.x = (shm()->nChan.x * shm()->nChip.x + shm()->gappixels * shm()->nGappixels.x); coord.y = (shm()->nChan.y * shm()->nChip.y + @@ -591,7 +591,7 @@ bool slsDetector::getQuad() { FILE_LOG(logDEBUG1) << "Getting Quad Type"; sendToDetector(F_GET_QUAD, nullptr, retval); FILE_LOG(logDEBUG1) << "Quad Type :" << retval; - return (retval == 0 ? false : true); + return retval != 0; } void slsDetector::setQuad(const bool enable) { @@ -686,11 +686,11 @@ bool slsDetector::lockServer(int lock) { FILE_LOG(logDEBUG1) << "Setting detector server lock to " << lock; sendToDetector(F_LOCK_SERVER, lock, retval); FILE_LOG(logDEBUG1) << "Lock: " << retval; - return (retval == 1 ? true : false); + return retval == 1; } sls::IpAddr slsDetector::getLastClientIP() { - sls::IpAddr retval = 0u; + sls::IpAddr retval = 0U; FILE_LOG(logDEBUG1) << "Getting last client ip to detector server"; sendToDetector(F_GET_LAST_CLIENT_IP, nullptr, retval); FILE_LOG(logDEBUG1) << "Last client IP to detector: " << retval; @@ -709,7 +709,7 @@ void slsDetector::execCommand(const std::string &cmd) { sls::strcpy_safe(arg, cmd.c_str()); FILE_LOG(logDEBUG1) << "Sending command to detector " << arg; sendToDetector(F_EXEC_COMMAND, arg, retval); - if (strlen(retval) != 0u) { + if (strlen(retval) != 0U) { FILE_LOG(logINFO) << "Detector " << detId << " returned:\n" << retval; } } @@ -722,7 +722,7 @@ void slsDetector::updateCachedDetectorVariables() { FORCE_UPDATE) { int n = 0, i32 = 0; int64_t i64 = 0; - sls::IpAddr lastClientIP = 0u; + sls::IpAddr lastClientIP = 0U; n += client.Receive(&lastClientIP, sizeof(lastClientIP)); FILE_LOG(logDEBUG1) << "Updating detector last modified by " << lastClientIP; @@ -1612,7 +1612,7 @@ bool slsDetector::getStoreInRamMode() { } void slsDetector::setReadoutMode(const slsDetectorDefs::readoutMode mode) { - uint32_t arg = static_cast(mode); + auto arg = static_cast(mode); FILE_LOG(logDEBUG1) << "Setting readout mode to " << arg; sendToDetector(F_SET_READOUT_MODE, arg, nullptr); shm()->roMode = mode; @@ -1825,7 +1825,7 @@ void slsDetector::setSourceUDPMAC(const sls::MacAddr mac) { } sls::MacAddr slsDetector::getSourceUDPMAC() { - sls::MacAddr retval(0lu); + sls::MacAddr retval(0LU); FILE_LOG(logDEBUG1) << "Getting source udp mac"; sendToDetector(F_GET_SOURCE_UDP_MAC, nullptr, retval); FILE_LOG(logDEBUG1) << "Source udp mac: " << retval; @@ -1841,7 +1841,7 @@ void slsDetector::setSourceUDPMAC2(const sls::MacAddr mac) { } sls::MacAddr slsDetector::getSourceUDPMAC2() { - sls::MacAddr retval(0lu); + sls::MacAddr retval(0LU); FILE_LOG(logDEBUG1) << "Getting source udp mac2"; sendToDetector(F_GET_SOURCE_UDP_MAC2, nullptr, retval); FILE_LOG(logDEBUG1) << "Source udp mac2: " << retval; @@ -1858,7 +1858,7 @@ void slsDetector::setSourceUDPIP(const IpAddr ip) { } sls::IpAddr slsDetector::getSourceUDPIP() { - sls::IpAddr retval(0u); + sls::IpAddr retval(0U); FILE_LOG(logDEBUG1) << "Getting source udp ip"; sendToDetector(F_GET_SOURCE_UDP_IP, nullptr, retval); FILE_LOG(logDEBUG1) << "Source udp ip: " << retval; @@ -1875,7 +1875,7 @@ void slsDetector::setSourceUDPIP2(const IpAddr ip) { } sls::IpAddr slsDetector::getSourceUDPIP2() { - sls::IpAddr retval(0u); + sls::IpAddr retval(0U); FILE_LOG(logDEBUG1) << "Getting source udp ip2"; sendToDetector(F_GET_SOURCE_UDP_IP2, nullptr, retval); FILE_LOG(logDEBUG1) << "Source udp ip2: " << retval; @@ -1889,7 +1889,7 @@ void slsDetector::setDestinationUDPIP(const IpAddr ip) { } sendToDetector(F_SET_DEST_UDP_IP, ip, nullptr); if (shm()->useReceiverFlag) { - sls::MacAddr retval(0lu); + sls::MacAddr retval(0LU); sendToReceiver(F_SET_RECEIVER_UDP_IP, ip, retval); FILE_LOG(logINFO) << "Setting destination udp mac to " << retval; sendToDetector(F_SET_DEST_UDP_MAC, retval, nullptr); @@ -1897,7 +1897,7 @@ void slsDetector::setDestinationUDPIP(const IpAddr ip) { } sls::IpAddr slsDetector::getDestinationUDPIP() { - sls::IpAddr retval(0u); + sls::IpAddr retval(0U); FILE_LOG(logDEBUG1) << "Getting destination udp ip"; sendToDetector(F_GET_DEST_UDP_IP, nullptr, retval); FILE_LOG(logDEBUG1) << "Destination udp ip: " << retval; @@ -1925,7 +1925,7 @@ void slsDetector::setDestinationUDPIP2(const IpAddr ip) { sendToDetector(F_SET_DEST_UDP_IP2, ip, nullptr); if (shm()->useReceiverFlag) { - sls::MacAddr retval(0lu); + sls::MacAddr retval(0LU); sendToReceiver(F_SET_RECEIVER_UDP_IP2, ip, retval); FILE_LOG(logINFO) << "Setting destination udp mac2 to " << retval; sendToDetector(F_SET_DEST_UDP_MAC2, retval, nullptr); @@ -1933,7 +1933,7 @@ void slsDetector::setDestinationUDPIP2(const IpAddr ip) { } sls::IpAddr slsDetector::getDestinationUDPIP2() { - sls::IpAddr retval(0u); + sls::IpAddr retval(0U); FILE_LOG(logDEBUG1) << "Getting destination udp ip2"; sendToDetector(F_GET_DEST_UDP_IP2, nullptr, retval); FILE_LOG(logDEBUG1) << "Destination udp ip2: " << retval; @@ -1963,7 +1963,7 @@ void slsDetector::setDestinationUDPMAC(const MacAddr mac) { } sls::MacAddr slsDetector::getDestinationUDPMAC() { - sls::MacAddr retval(0lu); + sls::MacAddr retval(0LU); FILE_LOG(logDEBUG1) << "Getting destination udp mac"; sendToDetector(F_GET_DEST_UDP_MAC, nullptr, retval); FILE_LOG(logDEBUG1) << "Destination udp mac: " << retval; @@ -1980,7 +1980,7 @@ void slsDetector::setDestinationUDPMAC2(const MacAddr mac) { } sls::MacAddr slsDetector::getDestinationUDPMAC2() { - sls::MacAddr retval(0lu); + sls::MacAddr retval(0LU); FILE_LOG(logDEBUG1) << "Getting destination udp mac2"; sendToDetector(F_GET_DEST_UDP_MAC2, nullptr, retval); FILE_LOG(logDEBUG1) << "Destination udp mac2: " << retval; @@ -2130,7 +2130,7 @@ bool slsDetector::getTenGigaFlowControl() { int retval = -1; sendToDetector(F_GET_TEN_GIGA_FLOW_CONTROL, nullptr, retval); FILE_LOG(logDEBUG1) << "ten giga flow control :" << retval; - return retval == 1 ? true : false; + return retval == 1; } void slsDetector::setTenGigaFlowControl(bool enable) { @@ -2252,7 +2252,7 @@ std::string slsDetector::setAdditionalJsonParameter(const std::string &key, // key not found, append key value pair else { - if (header.length() != 0u) { + if (header.length() != 0U) { header.append(","); } header.append(keyLiteral + valueLiteral); @@ -2265,7 +2265,7 @@ std::string slsDetector::setAdditionalJsonParameter(const std::string &key, std::string slsDetector::getAdditionalJsonParameter(const std::string &key) { // additional json header is empty - if (strlen(shm()->rxAdditionalJsonHeader) == 0u) + if (strlen(shm()->rxAdditionalJsonHeader) == 0U) return std::string(); // add quotations before and after the key value @@ -2585,7 +2585,7 @@ void slsDetector::setADCEnableMask(uint32_t mask) { updateNumberOfChannels(); // send to processor - if (shm()->myDetectorType == MOENCH && shm()->tenGigaEnable == 0) + if (shm()->myDetectorType == MOENCH && !shm()->tenGigaEnable) setAdditionalJsonParameter("adcmask", std::to_string(shm()->adcEnableMaskOneGiga)); @@ -2620,7 +2620,7 @@ void slsDetector::setTenGigaADCEnableMask(uint32_t mask) { updateNumberOfChannels(); // send to processor - if (shm()->myDetectorType == MOENCH && shm()->tenGigaEnable == 1) + if (shm()->myDetectorType == MOENCH && shm()->tenGigaEnable) setAdditionalJsonParameter("adcmask", std::to_string(shm()->adcEnableMaskTenGiga)); @@ -2682,7 +2682,7 @@ int slsDetector::setExternalSampling(int value) { int slsDetector::getExternalSampling() { return setExternalSampling(-1); } -void slsDetector::setReceiverDbitList(std::vector list) { +void slsDetector::setReceiverDbitList(const std::vector& list) { FILE_LOG(logDEBUG1) << "Setting Receiver Dbit List"; if (list.size() > 64) { @@ -2811,7 +2811,7 @@ int slsDetector::enableGapPixels(int val) { return shm()->gappixels; } -int slsDetector::setTrimEn(std::vector energies) { +int slsDetector::setTrimEn(const std::vector& energies) { if (shm()->myDetectorType != EIGER) { throw RuntimeError("Not implemented for this detector."); } @@ -3152,7 +3152,7 @@ int slsDetector::lockReceiver(int lock) { } sls::IpAddr slsDetector::getReceiverLastClientIP() const { - sls::IpAddr retval = 0u; + sls::IpAddr retval = 0U; FILE_LOG(logDEBUG1) << "Getting last client ip to receiver server"; if (shm()->useReceiverFlag) { sendToReceiver(F_GET_LAST_RECEIVER_CLIENT_IP, nullptr, retval); @@ -3190,7 +3190,7 @@ void slsDetector::updateCachedReceiverVariables() const { int n = 0, i32 = 0; int64_t i64 = 0; char cstring[MAX_STR_LENGTH]{}; - IpAddr ip = 0u; + IpAddr ip = 0U; n += receiver.Receive(&ip, sizeof(ip)); FILE_LOG(logDEBUG1) @@ -3673,7 +3673,7 @@ void slsDetector::setPattern(const std::string &fname) { uint64_t addr = 0; FILE *fd = fopen(fname.c_str(), "r"); if (fd != nullptr) { - while (fread(&word, sizeof(word), 1, fd) != 0u) { + while (fread(&word, sizeof(word), 1, fd) != 0U) { setPatternWord(addr, word); // TODO! (Erik) do we need to send // pattern in 64bit chunks? ++addr; diff --git a/slsDetectorSoftware/src/slsDetector.h b/slsDetectorSoftware/src/slsDetector.h index 5edcdae2e..df2edad33 100755 --- a/slsDetectorSoftware/src/slsDetector.h +++ b/slsDetectorSoftware/src/slsDetector.h @@ -1236,7 +1236,7 @@ class slsDetector : public virtual slsDetectorDefs { * @param list external sampling source (Option: 0-63) * @param detPos -1 for all detectors in list or specific detector position */ - void setReceiverDbitList(std::vector list); + void setReceiverDbitList(const std::vector& list); /** * Get external sampling source (CTB only) @@ -1317,7 +1317,7 @@ class slsDetector : public virtual slsDetectorDefs { * @param vector os trimmed energies * @returns number of trim energies */ - int setTrimEn(std::vector energies = {}); + int setTrimEn(const std::vector& energies = {}); /** * Returns a vector with the trimmed energies (Eiger) diff --git a/slsSupportLib/include/sls_detector_defs.h b/slsSupportLib/include/sls_detector_defs.h index 12e2ae757..f1675e89e 100755 --- a/slsSupportLib/include/sls_detector_defs.h +++ b/slsSupportLib/include/sls_detector_defs.h @@ -214,8 +214,8 @@ format #ifdef __cplusplus struct xy { - int x; - int y; + int x=0; + int y=0; }; #endif