From 9ee2d389fb1dae83f7aab7b46aa3185a1168be7b Mon Sep 17 00:00:00 2001 From: Dhanya Thattil Date: Wed, 22 Apr 2020 13:43:10 +0200 Subject: [PATCH] WIP --- slsDetectorSoftware/src/Detector.cpp | 41 +++- slsDetectorSoftware/src/Module.cpp | 48 ----- slsDetectorSoftware/src/Receiver.cpp | 89 +++++---- slsDetectorSoftware/src/Receiver.h | 267 +++++++++++++-------------- 4 files changed, 228 insertions(+), 217 deletions(-) diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 3b299bf88..b132cdf72 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -234,12 +234,13 @@ Result Detector::getExptime(Positions pos) const { void Detector::setExptime(ns t, Positions pos) { bool change = false; if (getDetectorType().squash() == defs::EIGER) { - ns prevVal = getPeriod(pos).squash(); - if (prevVal != t) { + ns prevVal = getExptime(pos).squash(); + if (getExptime(pos).squash() != t) { change = true; } } pimpl->Parallel(&Module::setExptime, pos, t.count()); + pimpl->Parallel3(&Receiver::setExptime, t.count()); if (change) { pimpl->Parallel(&Module::updateRateCorrection, pos); } @@ -283,6 +284,7 @@ Result Detector::getTimingMode(Positions pos) const { void Detector::setTimingMode(defs::timingMode value, Positions pos) { pimpl->Parallel(&Module::setTimingMode, pos, value); + pimpl->Parallel3(&Receiver::setTimingMode, value); } Result Detector::getSpeed(Positions pos) const { @@ -1028,7 +1030,29 @@ Result Detector::getDynamicRange(Positions pos) const { } void Detector::setDynamicRange(int value) { + bool change = false; + int prevVal = value; + if (getDetectorType().squash() == defs::EIGER) { + prevVal = getDynamicRange().squash(); + if (prevVal != value) { + change = true; + } + } pimpl->Parallel(&Module::setDynamicRange, {}, value); + pimpl->Parallel3(&Receiver::setDynamicRange, value); + if (change) { + // update speed for usability + if (value == 32) { + LOG(logINFO) << "Setting Clock to Quarter Speed to cope with " + "Dynamic Range of 32"; + setSpeed(defs::QUARTER_SPEED); + } else if (prevVal == 32) { + LOG(logINFO) << "Setting Clock to Full Speed for Dynamic Range " + "of " << value; + setSpeed(defs::FULL_SPEED); + } + pimpl->Parallel(&Module::updateRateCorrection, {}); + } } Result Detector::getSubExptime(Positions pos) const { @@ -1036,7 +1060,18 @@ Result Detector::getSubExptime(Positions pos) const { } void Detector::setSubExptime(ns t, Positions pos) { + bool change = false; + if (getDetectorType().squash() == defs::EIGER) { + ns prevVal = getSubExptime(pos).squash(); + if (prevVal != t) { + change = true; + } + } pimpl->Parallel(&Module::setSubExptime, pos, t.count()); + pimpl->Parallel3(&Receiver::setSubExptime, t.count()); + if (change) { + pimpl->Parallel(&Module::updateRateCorrection, pos); + } } Result Detector::getSubDeadTime(Positions pos) const { @@ -1045,6 +1080,7 @@ Result Detector::getSubDeadTime(Positions pos) const { void Detector::setSubDeadTime(ns value, Positions pos) { pimpl->Parallel(&Module::setSubDeadTime, pos, value.count()); + pimpl->Parallel3(&Receiver::setSubDeadTime, value.count()); } Result Detector::getThresholdEnergy(Positions pos) const { @@ -1494,6 +1530,7 @@ Result Detector::getReadoutMode(Positions pos) const { void Detector::setReadoutMode(defs::readoutMode value, Positions pos) { pimpl->Parallel(&Module::setReadoutMode, pos, value); + pimpl->Parallel3(&Receiver::setReadoutMode, value); } Result Detector::getDBITClock(Positions pos) const { diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index 5b934e007..ae26e0a4c 100755 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -1106,19 +1106,8 @@ int64_t Module::getSubExptime() { } void Module::setSubExptime(int64_t value) { - int64_t prevVal = value; - if (shm()->myDetectorType == EIGER) { - prevVal = getSubExptime(); - } LOG(logDEBUG1) << "Setting sub exptime to " << value << "ns"; sendToDetector(F_SET_SUB_EXPTIME, value, nullptr); - if (shm()->useReceiver) { - LOG(logDEBUG1) << "Sending sub exptime to Receiver: " << value; - sendToReceiver(F_RECEIVER_SET_SUB_EXPTIME, value, nullptr); - } - if (prevVal != value) { - updateRateCorrection(); - } } int64_t Module::getSubDeadTime() { @@ -1128,10 +1117,6 @@ int64_t Module::getSubDeadTime() { void Module::setSubDeadTime(int64_t value) { LOG(logDEBUG1) << "Setting sub deadtime to " << value << "ns"; sendToDetector(F_SET_SUB_DEADTIME, value, nullptr); - if (shm()->useReceiver) { - LOG(logDEBUG1) << "Sending sub deadtime to Receiver: " << value; - sendToReceiver(F_RECEIVER_SET_SUB_DEADTIME, value, nullptr); - } } int64_t Module::getStorageCellDelay() { @@ -1228,10 +1213,6 @@ void Module::setTimingMode(timingMode value) { timingMode retval = GET_TIMING_MODE; LOG(logDEBUG1) << "Setting timing mode to " << value; sendToDetector(F_SET_TIMING_MODE, static_cast(value), retval); - if (shm()->useReceiver) { - LOG(logDEBUG1) << "Sending timing mode to Receiver: " << value; - sendToReceiver(F_SET_RECEIVER_TIMING_MODE, value, nullptr); - } } int Module::getDynamicRange() { @@ -1243,36 +1224,10 @@ int Module::getDynamicRange() { } void Module::setDynamicRange(int n) { - int prev_val = n; - if (shm()->myDetectorType == EIGER) { - prev_val = getDynamicRange(); - } - int retval = -1; LOG(logDEBUG1) << "Setting dynamic range to " << n; sendToDetector(F_SET_DYNAMIC_RANGE, n, retval); LOG(logDEBUG1) << "Dynamic Range: " << retval; - - if (shm()->useReceiver) { - int arg = retval; - retval = -1; - LOG(logDEBUG1) << "Sending dynamic range to receiver: " << arg; - sendToReceiver(F_SET_RECEIVER_DYNAMIC_RANGE, arg, retval); - LOG(logDEBUG1) << "Receiver Dynamic range: " << retval; - } - - // changes in dr - if (n != prev_val) { - // update speed for usability - if (n == 32) { - LOG(logINFO) << "Setting Clock to Quarter Speed to cope with Dynamic Range of 32"; - setClockDivider(RUN_CLOCK, 2); - } else if (prev_val == 32) { - LOG(logINFO) << "Setting Clock to Full Speed for Dynamic Range of " << n; - setClockDivider(RUN_CLOCK, 0); - } - updateRateCorrection(); - } } int Module::setDAC(int val, dacIndex index, int mV) { @@ -1368,9 +1323,6 @@ void Module::setReadoutMode(const slsDetectorDefs::readoutMode mode) { if (shm()->myDetectorType == CHIPTESTBOARD) { updateNumberOfChannels(); } - if (shm()->useReceiver) { - sendToReceiver(F_RECEIVER_SET_READOUT_MODE, mode, nullptr); - } } slsDetectorDefs::readoutMode Module::getReadoutMode() { diff --git a/slsDetectorSoftware/src/Receiver.cpp b/slsDetectorSoftware/src/Receiver.cpp index 50923c9a3..d0ce4cfa4 100755 --- a/slsDetectorSoftware/src/Receiver.cpp +++ b/slsDetectorSoftware/src/Receiver.cpp @@ -322,7 +322,48 @@ int64_t Receiver::getSoftwareVersion() const { return sendToReceiver(F_GET_RECEIVER_VERSION); } -/** Acquisition Parameters */ +/** Acquisition */ + +void Receiver::start() { + LOG(logDEBUG1) << "Starting Receiver"; + shm()->stoppedFlag = false; + sendToReceiver(F_START_RECEIVER, nullptr, nullptr); +} + +void Receiver::stop() { + LOG(logDEBUG1) << "Stopping Receiver"; + int arg = static_cast(shm()->stoppedFlag); + sendToReceiver(F_STOP_RECEIVER, arg, nullptr); +} + +slsDetectorDefs::runStatus Receiver::getStatus() const { + runStatus retval = ERROR; + LOG(logDEBUG1) << "Getting Receiver Status"; + sendToReceiver(F_GET_RECEIVER_STATUS, nullptr, retval); + LOG(logDEBUG1) << "Receiver Status: " << ToString(retval); + return retval; +} + +int Receiver::getProgress() const { + int retval = -1; + sendToReceiver(F_GET_RECEIVER_PROGRESS, nullptr, retval); + LOG(logDEBUG1) << "Current Progress of Receiver: " << retval; + return retval; +} + +void Receiver::setStoppedFlag() { + shm()->stoppedFlag = true; +} + +void Receiver::restreamStop() { + LOG(logDEBUG1) << "Restream stop dummy from Receiver via zmq"; + sendToReceiver(F_RESTREAM_STOP_FROM_RECEIVER, nullptr, nullptr); +} + +/** Network Configuration (Detector<->Receiver) */ + + +/** Detector Parameters */ void Receiver::setNumberOfFrames(int64_t value) { LOG(logDEBUG1) << "Sending number of frames to Receiver: " << value; sendToReceiver(F_RECEIVER_SET_NUM_FRAMES, value, nullptr); @@ -353,47 +394,31 @@ void Receiver::setExptime(int64_t value) { sendToReceiver(F_RECEIVER_SET_EXPTIME, value, nullptr); } -/** Acquisition */ - -void Receiver::start() { - LOG(logDEBUG1) << "Starting Receiver"; - shm()->stoppedFlag = false; - sendToReceiver(F_START_RECEIVER, nullptr, nullptr); +void Receiver::setSubExptime(int64_t value) { + LOG(logDEBUG1) << "Sending sub exptime to Receiver: " << value; + sendToReceiver(F_RECEIVER_SET_SUB_EXPTIME, value, nullptr); } -void Receiver::stop() { - LOG(logDEBUG1) << "Stopping Receiver"; - int arg = static_cast(shm()->stoppedFlag); - sendToReceiver(F_STOP_RECEIVER, arg, nullptr); +void Receiver::setSubDeadTime(int64_t value) { + LOG(logDEBUG1) << "Sending sub deadtime to Receiver: " << value; + sendToReceiver(F_RECEIVER_SET_SUB_DEADTIME, value, nullptr); } -slsDetectorDefs::runStatus Receiver::getStatus() const { - runStatus retval = ERROR; - LOG(logDEBUG1) << "Getting Receiver Status"; - sendToReceiver(F_GET_RECEIVER_STATUS, nullptr, retval); - LOG(logDEBUG1) << "Receiver Status: " << ToString(retval); - return retval; +void Receiver::setTimingMode(timingMode value) { + LOG(logDEBUG1) << "Sending timing mode to Receiver: " << value; + sendToReceiver(F_SET_RECEIVER_TIMING_MODE, value, nullptr); } - -int Receiver::getProgress() const { +void Receiver::setDynamicRange(int n) { int retval = -1; - sendToReceiver(F_GET_RECEIVER_PROGRESS, nullptr, retval); - LOG(logDEBUG1) << "Current Progress of Receiver: " << retval; - return retval; + LOG(logDEBUG1) << "Sending dynamic range to receiver: " << n; + sendToReceiver(F_SET_RECEIVER_DYNAMIC_RANGE, n, retval); } -void Receiver::setStoppedFlag() { - shm()->stoppedFlag = true; +void Receiver::setReadoutMode(const slsDetectorDefs::readoutMode mode) { + sendToReceiver(F_RECEIVER_SET_READOUT_MODE, mode, nullptr); } -void Receiver::restreamStop() { - LOG(logDEBUG1) << "Restream stop dummy from Receiver via zmq"; - sendToReceiver(F_RESTREAM_STOP_FROM_RECEIVER, nullptr, nullptr); -} - -/** Detector Specific */ -// Eiger void Receiver::setQuad(const bool enable) { int value = enable ? 1 : 0; LOG(logDEBUG1) << "Setting Quad type to " << value << " in Receiver"; @@ -406,8 +431,6 @@ void Receiver::setReadNLines(const int value) { sendToReceiver(F_SET_RECEIVER_READ_N_LINES, value, nullptr); } -// Moench - void Receiver::setAdditionalJsonHeader(const std::map &jsonHeader) { for (auto &it : jsonHeader) { if (it.first.empty() || it.first.length() > SHORT_STR_LENGTH || diff --git a/slsDetectorSoftware/src/Receiver.h b/slsDetectorSoftware/src/Receiver.h index 623094f38..89900cccc 100755 --- a/slsDetectorSoftware/src/Receiver.h +++ b/slsDetectorSoftware/src/Receiver.h @@ -9,162 +9,161 @@ #define RECEIVER_SHMVERSION 0x200421 namespace sls { - struct sharedReceiver { +struct sharedReceiver { - /* FIXED PATTERN FOR STATIC FUNCTIONS. DO NOT CHANGE, ONLY APPEND ------*/ - int shmversion; - char hostname[MAX_STR_LENGTH]; - int tcpPort; - /** END OF FIXED PATTERN -----------------------------------------------*/ +/* FIXED PATTERN FOR STATIC FUNCTIONS. DO NOT CHANGE, ONLY APPEND ------*/ +int shmversion; +char hostname[MAX_STR_LENGTH]; +int tcpPort; +/** END OF FIXED PATTERN -----------------------------------------------*/ - int stoppedFlag; - int zmqPort; - sls::IpAddr zmqIp; +int stoppedFlag; +int zmqPort; +sls::IpAddr zmqIp; - }; +}; - class Receiver : public virtual slsDetectorDefs { - public: - static size_t getNumReceivers(); - // create shm - explicit Receiver(int detector_id, int module_id, int interface_id, - int receiver_id, int tcp_port = 0, std::string hostname = "", - int zmq_port = 0); - // open shm - explicit Receiver(int detector_id, int module_id, int interface_id, - int receiver_id, bool verify); +class Receiver : public virtual slsDetectorDefs { + public: + static size_t getNumReceivers(); + // create shm + explicit Receiver(int detector_id, int module_id, int interface_id, + int receiver_id, int tcp_port = 0, std::string hostname = "", + int zmq_port = 0); + // open shm + explicit Receiver(int detector_id, int module_id, int interface_id, + int receiver_id, bool verify); - virtual ~Receiver(); + virtual ~Receiver(); - void createIndexString(); + void createIndexString(); - /************************************************** - * * - * Configuration * - * * - * ************************************************/ - /** - * Free shared memory and delete shared memory structure - * occupied by the sharedReceiver structure - * Is only safe to call if one deletes the Receiver object afterward - * and frees multi shared memory/updates - * thisMultiDetector->numberOfReceivers - */ - void freeSharedMemory(); - std::string getHostname() const; - void setHostname(const std::string &hostname); - sls::MacAddr configure(slsDetectorDefs::rxParameters arg); - int getTCPPort() const; - void setTCPPort(const int port); - std::string printConfiguration(); - int64_t getSoftwareVersion() const; + /************************************************** + * * + * Configuration * + * * + * ************************************************/ + /** + * Free shared memory and delete shared memory structure + * occupied by the sharedReceiver structure + * Is only safe to call if one deletes the Receiver object afterward + * and frees multi shared memory/updates + * thisMultiDetector->numberOfReceivers + */ + void freeSharedMemory(); + std::string getHostname() const; + void setHostname(const std::string &hostname); + sls::MacAddr configure(slsDetectorDefs::rxParameters arg); + int getTCPPort() const; + void setTCPPort(const int port); + std::string printConfiguration(); + int64_t getSoftwareVersion() const; + + /************************************************** + * * + * Acquisition * + * * + * ************************************************/ + void start(); + void stop(); + slsDetectorDefs::runStatus getStatus() const; + int getProgress() const; + void setStoppedFlag(); + void restreamStop(); + + /************************************************** + * * + * Network Configuration (Detector<->Receiver) * + * * + * ************************************************/ + + /************************************************** + * * + * Detector Parameters * + * * + * ************************************************/ + void setNumberOfFrames(int64_t value); + void setNumberOfTriggers(int64_t value); + void setNumberOfBursts(int64_t value); + void setNumberOfAnalogSamples(int value); + void setNumberOfDigitalSamples(int value); + void setExptime(int64_t value); + void setSubExptime(int64_t value); + void setSubDeadTime(int64_t value); + void setTimingMode(timingMode value); + void setDynamicRange(int n); + void setReadoutMode(const readoutMode mode); + void setQuad(const bool enable); + void setReadNLines(const int value); + /** empty vector deletes entire additional json header */ + void setAdditionalJsonHeader(const std::map &jsonHeader); + std::map getAdditionalJsonHeader(); + /** Sets the value for the additional json header parameter key if found, + else append it. If value empty, then deletes parameter */ + void setAdditionalJsonParameter(const std::string &key, const std::string &value); + std::string getAdditionalJsonParameter(const std::string &key); - /************************************************** - * * - * Acquisition Parameters * - * * - * ************************************************/ - void setNumberOfFrames(int64_t value); - void setNumberOfTriggers(int64_t value); - void setNumberOfBursts(int64_t value); - void setNumberOfAnalogSamples(int value); - void setNumberOfDigitalSamples(int value); - void setExptime(int64_t value); + /************************************************** + * * + * Receiver Parameters * + * * + * ************************************************/ + /************************************************** + * * + * File * + * * + * ************************************************/ + /************************************************** + * * + * ZMQ Streaming Parameters (Receiver<->Client)* + * * + * ************************************************/ - /************************************************** - * * - * Acquisition * - * * - * ************************************************/ - void start(); - void stop(); - slsDetectorDefs::runStatus getStatus() const; - int getProgress() const; - void setStoppedFlag(); - void restreamStop(); + private: + void sendToReceiver(int fnum, const void *args, size_t args_size, + void *retval, size_t retval_size); - /************************************************** - * * - * Network Configuration (Detector<->Receiver) * - * * - * ************************************************/ + void sendToReceiver(int fnum, const void *args, size_t args_size, + void *retval, size_t retval_size) const; - /************************************************** - * * - * File * - * * - * ************************************************/ - /************************************************** - * * - * ZMQ Streaming Parameters (Receiver<->Client)* - * * - * ************************************************/ - - /************************************************** - * * - * Detector Specific * - * * - * ************************************************/ - // Eiger - void setQuad(const bool enable); - void setReadNLines(const int value); + template + void sendToReceiver(int fnum, const Arg &args, Ret &retval); - // Moench - /** empty vector deletes entire additional json header */ - void setAdditionalJsonHeader(const std::map &jsonHeader); - std::map getAdditionalJsonHeader(); + template + void sendToReceiver(int fnum, const Arg &args, Ret &retval) const; - /** Sets the value for the additional json header parameter key if found, - else append it. If value empty, then deletes parameter */ - void setAdditionalJsonParameter(const std::string &key, const std::string &value); - std::string getAdditionalJsonParameter(const std::string &key); + template + void sendToReceiver(int fnum, const Arg &args, std::nullptr_t); + template + void sendToReceiver(int fnum, const Arg &args, std::nullptr_t) const; - private: - void sendToReceiver(int fnum, const void *args, size_t args_size, - void *retval, size_t retval_size); + template + void sendToReceiver(int fnum, std::nullptr_t, Ret &retval); - void sendToReceiver(int fnum, const void *args, size_t args_size, - void *retval, size_t retval_size) const; + template + void sendToReceiver(int fnum, std::nullptr_t, Ret &retval) const; - template - void sendToReceiver(int fnum, const Arg &args, Ret &retval); + template + Ret sendToReceiver(int fnum); - template - void sendToReceiver(int fnum, const Arg &args, Ret &retval) const; + template + Ret sendToReceiver(int fnum) const; - template - void sendToReceiver(int fnum, const Arg &args, std::nullptr_t); + template + Ret sendToReceiver(int fnum, const Arg &args); - template - void sendToReceiver(int fnum, const Arg &args, std::nullptr_t) const; + template + Ret sendToReceiver(int fnum, const Arg &args) const; - template - void sendToReceiver(int fnum, std::nullptr_t, Ret &retval); - - template - void sendToReceiver(int fnum, std::nullptr_t, Ret &retval) const; - - template - Ret sendToReceiver(int fnum); - - template - Ret sendToReceiver(int fnum) const; - - template - Ret sendToReceiver(int fnum, const Arg &args); - - template - Ret sendToReceiver(int fnum, const Arg &args) const; - - void checkVersionCompatibility(); - const int receiverId{0}; - const int interfaceId{0}; - const int moduleId{0}; - std::string indexString; - mutable sls::SharedMemory shm{0, 0, 0, 0}; - }; + void checkVersionCompatibility(); + const int receiverId{0}; + const int interfaceId{0}; + const int moduleId{0}; + std::string indexString; + mutable sls::SharedMemory shm{0, 0, 0, 0}; +}; } // sls \ No newline at end of file