From 78fdf5b60adba54464d76290bbff3af2f13749be Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Thu, 6 Aug 2020 12:33:43 +0200 Subject: [PATCH] removed casts --- slsDetectorSoftware/src/Module.cpp | 94 +++++++++++------------------- slsDetectorSoftware/src/Module.h | 4 +- slsSupportLib/include/TimeHelper.h | 2 + 3 files changed, 39 insertions(+), 61 deletions(-) diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index ae5f03f8a..a61c05d91 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -390,8 +390,8 @@ void Module::startReceiver() { } void Module::stopReceiver() { - int arg = static_cast(shm()->stoppedFlag); - sendToReceiver(F_STOP_RECEIVER, arg, nullptr); + sendToReceiver(F_STOP_RECEIVER, static_cast(shm()->stoppedFlag), + nullptr); } void Module::startAcquisition() { @@ -676,7 +676,7 @@ bool Module::getTenGiga() const { } void Module::setTenGiga(bool value) { - int arg = static_cast(value); + auto arg = static_cast(value); auto retval = sendToDetector(F_ENABLE_TEN_GIGA, arg); sendToDetectorStop(F_ENABLE_TEN_GIGA, arg); arg = retval; @@ -690,8 +690,8 @@ bool Module::getTenGigaFlowControl() const { } void Module::setTenGigaFlowControl(bool enable) { - int arg = static_cast(enable); - sendToDetector(F_SET_TEN_GIGA_FLOW_CONTROL, arg, nullptr); + sendToDetector(F_SET_TEN_GIGA_FLOW_CONTROL, static_cast(enable), + nullptr); } int Module::getTransmissionDelayFrame() const { @@ -825,8 +825,7 @@ void Module::setReceiverSilentMode(bool enable) { slsDetectorDefs::frameDiscardPolicy Module::getReceiverFramesDiscardPolicy() const { - return static_cast( - sendToReceiver(F_GET_RECEIVER_DISCARD_POLICY)); + return sendToReceiver(F_GET_RECEIVER_DISCARD_POLICY); } void Module::setReceiverFramesDiscardPolicy(frameDiscardPolicy f) { @@ -1118,8 +1117,7 @@ bool Module::getOverFlowMode() const { } void Module::setOverFlowMode(const bool enable) { - int arg = static_cast(enable); - sendToDetector(F_SET_OVERFLOW_MODE, arg, nullptr); + sendToDetector(F_SET_OVERFLOW_MODE, static_cast(enable), nullptr); } bool Module::getFlippedDataX() const { @@ -1196,8 +1194,7 @@ bool Module::getInterruptSubframe() const { } void Module::setInterruptSubframe(const bool enable) { - int arg = static_cast(enable); - sendToDetector(F_SET_INTERRUPT_SUBFRAME, arg, nullptr); + sendToDetector(F_SET_INTERRUPT_SUBFRAME, static_cast(enable), nullptr); } int64_t Module::getMeasuredPeriod() const { @@ -1248,12 +1245,12 @@ void Module::setCounterBit(bool cb) { } void Module::pulsePixel(int n, int x, int y) { - int args[]{n, x, y}; + const int args[]{n, x, y}; sendToDetector(F_PULSE_PIXEL, args, nullptr); } void Module::pulsePixelNMove(int n, int x, int y) { - int args[]{n, x, y}; + const int args[]{n, x, y}; sendToDetector(F_PULSE_PIXEL_AND_MOVE, args, nullptr); } @@ -1288,7 +1285,7 @@ void Module::setThresholdTemperature(int val) { } bool Module::getTemperatureControl() const { - return static_cast(sendToDetectorStop(F_TEMP_CONTROL, GET_FLAG)); + return sendToDetectorStop(F_TEMP_CONTROL, GET_FLAG); } void Module::setTemperatureControl(bool val) { @@ -1304,8 +1301,7 @@ void Module::resetTemperatureEvent() { } bool Module::getAutoComparatorDisableMode() const { - return static_cast( - sendToDetector(F_AUTO_COMP_DISABLE, GET_FLAG)); + return sendToDetector(F_AUTO_COMP_DISABLE, GET_FLAG); } void Module::setAutoComparatorDisableMode(bool val) { @@ -1439,7 +1435,6 @@ void Module::getVetoPhoton(const int chipIndex, // save to file std::ofstream outfile(fname); - if (!outfile) { throw RuntimeError("Could not create file to save veto photon"); } @@ -1527,7 +1522,7 @@ void Module::setVetoPhoton(const int chipIndex, const int numPhotons, } void Module::setVetoReference(const int gainIndex, const int value) { - int args[]{gainIndex, value}; + const int args[]{gainIndex, value}; sendToDetector(F_SET_VETO_REFERENCE, args, nullptr); } @@ -1591,13 +1586,11 @@ void Module::setVetoFile(const int chipIndex, const std::string &fname) { } slsDetectorDefs::burstMode Module::getBurstMode() const { - auto r = sendToDetector(F_GET_BURST_MODE); - return static_cast(r); + return sendToDetector(F_GET_BURST_MODE); } void Module::setBurstMode(slsDetectorDefs::burstMode value) { - int arg = static_cast(value); - sendToDetector(F_SET_BURST_MODE, arg, nullptr); + sendToDetector(F_SET_BURST_MODE, value, nullptr); if (shm()->useReceiverFlag) { sendToReceiver(F_SET_RECEIVER_BURST_MODE, value, nullptr); } @@ -1624,8 +1617,7 @@ void Module::setCurrentSource(bool value) { } slsDetectorDefs::timingSourceType Module::getTimingSource() const { - auto r = sendToDetector(F_GET_TIMING_SOURCE); - return static_cast(r); + return sendToDetector(F_GET_TIMING_SOURCE); } void Module::setTimingSource(slsDetectorDefs::timingSourceType value) { @@ -1743,7 +1735,6 @@ void Module::setNumberOfGates(int value) { } std::array Module::getExptimeForAllGates() const { - static_assert(sizeof(time::ns) == 8, "ns needs to be 64bit"); return sendToDetector>(F_GET_EXPTIME_ALL_GATES); } @@ -1760,12 +1751,10 @@ void Module::setGateDelay(int gateIndex, int64_t value) { } std::array Module::getGateDelayForAllGates() const { - static_assert(sizeof(time::ns) == 8, "ns needs to be 64bit"); return sendToDetector>(F_GET_GATE_DELAY_ALL_GATES); } // CTB / Moench Specific - int Module::getNumberOfAnalogSamples() const { return sendToDetector(F_GET_NUM_ANALOG_SAMPLES); } @@ -1841,13 +1830,11 @@ void Module::setNumberOfDigitalSamples(int value) { } slsDetectorDefs::readoutMode Module::getReadoutMode() const { - auto r = sendToDetector(F_GET_READOUT_MODE); - return static_cast(r); + return sendToDetector(F_GET_READOUT_MODE); } void Module::setReadoutMode(const slsDetectorDefs::readoutMode mode) { - auto arg = static_cast(mode); - LOG(logDEBUG1) << "Setting readout mode to " << arg; + auto arg = static_cast(mode); // TODO! unit? sendToDetector(F_SET_READOUT_MODE, arg, nullptr); // update #nchan, as it depends on #samples, adcmask, if (shm()->myDetectorType == CHIPTESTBOARD) { @@ -1908,7 +1895,7 @@ void Module::setDigitalIODelay(uint64_t pinMask, int delay) { } bool Module::getLEDEnable() const { - return static_cast(sendToDetector(F_LED, GET_FLAG)); + return sendToDetector(F_LED, GET_FLAG); } void Module::setLEDEnable(bool enable) { @@ -2020,8 +2007,8 @@ void Module::setPattern(const std::string &fname) { } uint64_t Module::getPatternIOControl() const { - int64_t arg = GET_FLAG; - return sendToDetector(F_SET_PATTERN_IO_CONTROL, arg); + return sendToDetector(F_SET_PATTERN_IO_CONTROL, + int64_t(GET_FLAG)); } void Module::setPatternIOControl(uint64_t word) { @@ -2191,7 +2178,6 @@ void Module::setAdditionalJsonParameter(const std::string &key, } // Advanced - void Module::programFPGA(std::vector buffer) { switch (shm()->myDetectorType) { case JUNGFRAU: @@ -2270,31 +2256,24 @@ void Module::setADCInvert(uint32_t value) { } // Insignificant - int Module::getControlPort() const { return shm()->controlPort; } -int Module::setControlPort(int port_number) { - if (port_number >= 0 && port_number != shm()->controlPort) { - if (strlen(shm()->hostname) > 0) { - shm()->controlPort = sendToDetector(F_SET_PORT, port_number); - } else { - shm()->controlPort = port_number; - } +void Module::setControlPort(int port_number) { + if (strlen(shm()->hostname) > 0) { + shm()->controlPort = sendToDetector(F_SET_PORT, port_number); + } else { + shm()->controlPort = port_number; } - return shm()->controlPort; } int Module::getStopPort() const { return shm()->stopPort; } -int Module::setStopPort(int port_number) { - if (port_number >= 0 && port_number != shm()->stopPort) { - if (strlen(shm()->hostname) > 0) { - shm()->stopPort = sendToDetectorStop(F_SET_PORT, port_number); - } else { - shm()->stopPort = port_number; - } +void Module::setStopPort(int port_number) { + if (strlen(shm()->hostname) > 0) { + shm()->stopPort = sendToDetectorStop(F_SET_PORT, port_number); + } else { + shm()->stopPort = port_number; } - return shm()->stopPort; } bool Module::getLockDetector() const { @@ -2314,7 +2293,7 @@ std::string Module::execCommand(const std::string &cmd) { char retval[MAX_STR_LENGTH]{}; sls::strcpy_safe(arg, cmd.c_str()); sendToDetector(F_EXEC_COMMAND, arg, retval); - return std::string(retval); + return retval; } int64_t Module::getNumberOfFramesFromStart() const { @@ -2612,7 +2591,7 @@ void Module::sendToReceiver(int fnum, const void *args, size_t args_size, } template -void Module::sendToReceiver(int fnum, const Arg &args, Ret &retval) const{ +void Module::sendToReceiver(int fnum, const Arg &args, Ret &retval) const { LOG(logDEBUG1) << "Sending to Receiver: [" << getFunctionNameFromEnum(static_cast(fnum)) << ", " << args << ", " << sizeof(args) << ", " @@ -2723,8 +2702,7 @@ slsDetectorDefs::detectorType Module::getDetectorTypeFromShm(int det_id, shm.UnmapSharedMemory(); throw SharedMemoryError(ss.str()); } - auto type = shm()->myDetectorType; - return type; + return shm()->myDetectorType; } void Module::initSharedMemory(detectorType type, int det_id, bool verify) { @@ -2806,8 +2784,7 @@ void Module::checkDetectorVersionCompatibility() { void Module::checkReceiverVersionCompatibility() { // TODO! Verify that this works as intended when version don't match - int64_t arg = APIRECEIVER; - sendToReceiver(F_RECEIVER_CHECK_VERSION, arg, nullptr); + sendToReceiver(F_RECEIVER_CHECK_VERSION, int64_t(APIRECEIVER), nullptr); } void Module::restreamStopFromReceiver() { @@ -3217,5 +3194,4 @@ void Module::programFPGAviaNios(std::vector buffer) { LOG(logINFO) << "FPGA programmed successfully"; rebootController(); } - } // namespace sls diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index 79e1b4936..f3dcbbb2a 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -511,9 +511,9 @@ class Module : public virtual slsDetectorDefs { * * * ************************************************/ int getControlPort() const; - int setControlPort(int port_number); + void setControlPort(int port_number); int getStopPort() const; - int setStopPort(int port_number); + void setStopPort(int port_number); bool getLockDetector() const; void setLockDetector(bool lock); sls::IpAddr getLastClientIP() const; diff --git a/slsSupportLib/include/TimeHelper.h b/slsSupportLib/include/TimeHelper.h index daefc1eef..99730b50e 100644 --- a/slsSupportLib/include/TimeHelper.h +++ b/slsSupportLib/include/TimeHelper.h @@ -16,5 +16,7 @@ abs(std::chrono::duration d) { return d >= d.zero() ? d : -d; } +static_assert(sizeof(ns) == 8, "ns needs to be 64bit"); + } // namespace time } // namespace sls \ No newline at end of file