This commit is contained in:
maliakal_d 2020-04-22 13:43:10 +02:00
parent 8d0146949c
commit 9ee2d389fb
4 changed files with 228 additions and 217 deletions

View File

@ -234,12 +234,13 @@ Result<ns> 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<defs::timingMode> 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<defs::speedLevel> Detector::getSpeed(Positions pos) const {
@ -1028,7 +1030,29 @@ Result<int> 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<ns> Detector::getSubExptime(Positions pos) const {
@ -1036,7 +1060,18 @@ Result<ns> 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<ns> Detector::getSubDeadTime(Positions pos) const {
@ -1045,6 +1080,7 @@ Result<ns> 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<int> Detector::getThresholdEnergy(Positions pos) const {
@ -1494,6 +1530,7 @@ Result<defs::readoutMode> 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<int> Detector::getDBITClock(Positions pos) const {

View File

@ -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<int>(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() {

View File

@ -322,7 +322,48 @@ int64_t Receiver::getSoftwareVersion() const {
return sendToReceiver<int64_t>(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<int>(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<int>(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<std::string, std::string> &jsonHeader) {
for (auto &it : jsonHeader) {
if (it.first.empty() || it.first.length() > SHORT_STR_LENGTH ||

View File

@ -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<std::string, std::string> &jsonHeader);
std::map<std::string, std::string> 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)*
* *
* ************************************************/
template <typename Arg, typename Ret>
void sendToReceiver(int fnum, const Arg &args, Ret &retval);
/**************************************************
* *
* Detector Specific *
* *
* ************************************************/
// Eiger
void setQuad(const bool enable);
void setReadNLines(const int value);
template <typename Arg, typename Ret>
void sendToReceiver(int fnum, const Arg &args, Ret &retval) const;
// Moench
/** empty vector deletes entire additional json header */
void setAdditionalJsonHeader(const std::map<std::string, std::string> &jsonHeader);
std::map<std::string, std::string> getAdditionalJsonHeader();
template <typename Arg>
void sendToReceiver(int fnum, const Arg &args, std::nullptr_t);
/** 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 <typename Arg>
void sendToReceiver(int fnum, const Arg &args, std::nullptr_t) const;
template <typename Ret>
void sendToReceiver(int fnum, std::nullptr_t, Ret &retval);
private:
void sendToReceiver(int fnum, const void *args, size_t args_size,
void *retval, size_t retval_size);
template <typename Ret>
void sendToReceiver(int fnum, std::nullptr_t, Ret &retval) const;
void sendToReceiver(int fnum, const void *args, size_t args_size,
void *retval, size_t retval_size) const;
template <typename Ret>
Ret sendToReceiver(int fnum);
template <typename Arg, typename Ret>
void sendToReceiver(int fnum, const Arg &args, Ret &retval);
template <typename Ret>
Ret sendToReceiver(int fnum) const;
template <typename Arg, typename Ret>
void sendToReceiver(int fnum, const Arg &args, Ret &retval) const;
template <typename Ret, typename Arg>
Ret sendToReceiver(int fnum, const Arg &args);
template <typename Arg>
void sendToReceiver(int fnum, const Arg &args, std::nullptr_t);
template <typename Ret, typename Arg>
Ret sendToReceiver(int fnum, const Arg &args) const;
template <typename Arg>
void sendToReceiver(int fnum, const Arg &args, std::nullptr_t) const;
template <typename Ret>
void sendToReceiver(int fnum, std::nullptr_t, Ret &retval);
template <typename Ret>
void sendToReceiver(int fnum, std::nullptr_t, Ret &retval) const;
template <typename Ret>
Ret sendToReceiver(int fnum);
template <typename Ret>
Ret sendToReceiver(int fnum) const;
template <typename Ret, typename Arg>
Ret sendToReceiver(int fnum, const Arg &args);
template <typename Ret, typename Arg>
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<sharedReceiver> 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<sharedReceiver> shm{0, 0, 0, 0};
};
} // sls