eiger server and client: cleaning up setting of dynamic range for eiger, where multi client takes care of checking rate correction in a separate call, tests included

This commit is contained in:
maliakal_d 2019-04-12 19:20:20 +02:00
parent 721f80a493
commit 79c6f5310b
9 changed files with 127 additions and 58 deletions

1
.gitignore vendored
View File

@ -11,6 +11,7 @@ bin/
build
docs/
RELEASE.txt
Testing/
*.pyc

View File

@ -3,7 +3,7 @@
struct SingleDetectorConfig {
slsDetectorDefs::detectorType type_enum =
slsDetectorDefs::detectorType::EIGER;
const std::string hostname = "beb083";
const std::string hostname = "beb031+beb032+";
const std::string type_string = "Eiger";
const std::string my_ip = "129.129.205.242";
const std::string my_ip = "129.129.205.171";
};

View File

@ -3,6 +3,7 @@
#include "ClientSocket.h"
#include "logger.h"
#include "multiSlsDetector.h"
#include "slsDetector.h"
#include "sls_detector_defs.h"
@ -222,3 +223,56 @@ TEST_CASE("Excersise all possible set timer functions", "[.integration]") {
// d.freeSharedMemory();
// }
TEST_CASE("Eiger Dynamic Range with effect on rate correction and clock divider", "[.integration]") {
SingleDetectorConfig c;
int ratecorr = 125;
// pick up multi detector from shm id 0
multiSlsDetector m(0);
// ensure eiger detector type, hostname and online
REQUIRE(m.getDetectorTypeAsEnum()==c.type_enum);
REQUIRE(m.getHostname()==c.hostname);
REQUIRE(m.setOnline(true)==slsDetectorDefs::ONLINE_FLAG);
// starting state with rate correction off
CHECK(m.setRateCorrection(0) == 0);
// dr 16: clk divider, no change for ratecorr
CHECK(m.setDynamicRange(16) == 16);
CHECK(m.setSpeed(slsDetectorDefs::CLOCK_DIVIDER) == 1);
CHECK(m.getRateCorrection() == 0);
// dr 32: clk divider, no change for ratecorr
CHECK(m.setDynamicRange(32) == 32);
CHECK(m.setSpeed(slsDetectorDefs::CLOCK_DIVIDER) == 2);
CHECK(m.getRateCorrection() == 0);
// other drs: no change for clk divider, no change for ratecorr
CHECK(m.setDynamicRange(8) == 8);
CHECK(m.setSpeed(slsDetectorDefs::CLOCK_DIVIDER) == 2);
CHECK(m.getRateCorrection() == 0);
CHECK(m.setDynamicRange(4) == 4);
CHECK(m.setSpeed(slsDetectorDefs::CLOCK_DIVIDER) == 2);
CHECK(m.getRateCorrection() == 0);
// switching on rate correction with dr 16, 32
m.setDynamicRange(16);
m.setRateCorrection(ratecorr);
CHECK(m.getRateCorrection() == ratecorr);
m.setDynamicRange(32);
CHECK(m.getRateCorrection() == ratecorr);
// ratecorr fail with dr 4 or 8
CHECK_THROWS_AS(m.setDynamicRange(8), sls::NonCriticalError);
CHECK(m.getRateCorrection()==0);
m.setDynamicRange(16);
m.setDynamicRange(16);
m.setRateCorrection(ratecorr);
m.setDynamicRange(16);
m.setRateCorrection(ratecorr);
CHECK_THROWS_AS(m.setDynamicRange(4), sls::NonCriticalError);
CHECK(m.getRateCorrection()==0);
}

View File

@ -1766,10 +1766,6 @@ int set_dynamic_range(int file_des) {
// set & get
if ((dr == -1) || (Server_VerifyLock() == OK)) {
#ifdef EIGERD
int old_dr = setDynamicRange(-1);
#endif
// check dr
switch(dr) {
case -1:
@ -1785,29 +1781,6 @@ int set_dynamic_range(int file_des) {
modeNotImplemented("Dynamic range", dr);
break;
}
#ifdef EIGERD
if (dr != -1 && getRateCorrectionEnable()) {
// 4 or 8 bit, switch off rate corr (only if dr worked)
if ((dr != 32) && (dr != 16) && (ret == OK)) {
setRateCorrection(0);
ret = FAIL;
strcpy(mess,"Switching off Rate Correction. Must be in 32 or 16 bit mode\n");
FILE_LOG(logERROR,(mess));
}
// 16, 32 (diff from old value), set new tau in rate table(-1), if it didnt work, give error
else if ((dr == 16 || dr == 32) && (old_dr != dr)) {
setRateCorrection(-1); //tau_ns will not be -1 here
// it didnt work
if (!getRateCorrectionEnable()) {
ret = FAIL;
strcpy(mess,"Deactivating Rate Correction. Could not set it.\n");
FILE_LOG(logERROR,(mess));
}
}
}
#endif
}
return Server_SendResult(file_des, INT32, UPDATE, &retval, sizeof(retval));
}

View File

@ -15,7 +15,7 @@ class multiSlsDetector;
class ServerInterface;
class MySocketTCP;
#define SLS_SHMVERSION 0x181005
#define SLS_SHMVERSION 0x190412
#define NCHIPSMAX 10
#define NCHANSMAX 65536
#define NDACSMAX 16
@ -120,6 +120,9 @@ struct sharedSlsDetector {
/** timer values */
int64_t timerValue[slsDetectorDefs::timerIndex::MAX_TIMERS];
/** rate correction in ns */
int64_t deadTime;
/** ip address/hostname of the receiver for client control via TCP */
char receiver_hostname[MAX_STR_LENGTH];
@ -1339,7 +1342,7 @@ class slsDetector : public virtual slsDetectorDefs{
sls_detector_module *getModule();
/**
* Set Rate correction (Mythen, Eiger)
* Set Rate correction (Eiger)
* @param t dead time in ns - if 0 disable correction,
* if >0 set dead time to t, if < 0 set deadtime to default dead time
* for current settings
@ -1348,11 +1351,18 @@ class slsDetector : public virtual slsDetectorDefs{
int setRateCorrection(int64_t t = 0);
/**
* Get rate correction Eiger)
* Get rate correction (Eiger)
* @returns 0 if rate correction disabled, > 0 otherwise
*/
int64_t getRateCorrection();
/**
* Update rate correction according to dynamic range (Eiger)
* If rate correction enabled and dr is 8 or 16, it will throw
* Otherwise update ratecorrection if enabled
*/
void updateRateCorrection();
/**
* Prints receiver configuration
* @param level print level

View File

@ -1264,36 +1264,46 @@ int multiSlsDetector::setDynamicRange(int dr, int detPos) {
int prevGValue = multi_shm()->dataBytesInclGapPixels;
multi_shm()->dataBytes = 0;
multi_shm()->dataBytesInclGapPixels = 0;
multi_shm()->numberOfChannels = 0;
for (auto &d : detectors) {
multi_shm()->dataBytes += d->getDataBytes();
multi_shm()->dataBytesInclGapPixels += d->getDataBytesInclGapPixels();
multi_shm()->numberOfChannels += d->getTotalNumberOfChannels();
}
// for usability
if (getDetectorTypeAsEnum() == EIGER) {
switch (dr) {
case 32:
FILE_LOG(logINFO) << "Setting Clock to Quarter Speed to cope with "
"Dynamic Range of 32";
setSpeed(CLOCK_DIVIDER, 2);
break;
case 16:
FILE_LOG(logINFO) << "Setting Clock to Half Speed for Dynamic Range of 16";
setSpeed(CLOCK_DIVIDER, 1);
break;
default:
break;
// if there was a change FIXME:add dr to sls shm and check that instead
if ((prevValue != multi_shm()->dataBytes) ||
(prevGValue != multi_shm()->dataBytesInclGapPixels)) {
updateOffsets();
// update speed, check ratecorrection
if (getDetectorTypeAsEnum() == EIGER) {
// rate correction before speed for consistency
// (else exception at speed makes ratecorr inconsistent)
parallelCall(&slsDetector::updateRateCorrection);
// speed(usability)
switch (dr) {
case 32:
FILE_LOG(logINFO)
<< "Setting Clock to Quarter Speed to cope with "
"Dynamic Range of 32";
setSpeed(CLOCK_DIVIDER, 2);
break;
case 16:
FILE_LOG(logINFO)
<< "Setting Clock to Half Speed for Dynamic Range of 16";
setSpeed(CLOCK_DIVIDER, 1);
break;
default:
break;
}
}
}
// update offsets if there was a change FIXME:add dr to sls shm and check
// that instead
if ((prevValue != multi_shm()->dataBytes) ||
(prevGValue != multi_shm()->dataBytesInclGapPixels)) {
updateOffsets();
}
return ret;
}

View File

@ -322,6 +322,7 @@ void slsDetector::initializeDetectorStructure(detectorType type) {
detector_shm()->timerValue[SUBFRAME_ACQUISITION_TIME] = 0;
detector_shm()->timerValue[STORAGE_CELL_NUMBER] = 0;
detector_shm()->timerValue[SUBFRAME_DEADTIME] = 0;
detector_shm()->deadTime = 0;
sls::strcpy_safe(detector_shm()->receiver_hostname, "none");
detector_shm()->receiverTCPPort = DEFAULT_PORTNO + 2;
detector_shm()->receiverUDPPort = DEFAULT_UDP_PORTNO;
@ -3810,6 +3811,7 @@ int slsDetector::setRateCorrection(int64_t t) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, &arg, sizeof(arg), nullptr, 0);
detector_shm()->deadTime = t;
}
if (ret == FORCE_UPDATE) {
ret = updateDetector();
@ -3828,6 +3830,7 @@ int64_t slsDetector::getRateCorrection() {
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, nullptr, 0, &retval,
sizeof(retval));
detector_shm()->deadTime = retval;
FILE_LOG(logDEBUG1) << "Rate correction: " << retval;
}
if (ret == FORCE_UPDATE) {
@ -3836,6 +3839,24 @@ int64_t slsDetector::getRateCorrection() {
return retval;
}
void slsDetector::updateRateCorrection() {
// rate correction is enabled
if (detector_shm()->deadTime != 0) {
switch (detector_shm()->dynamicRange) {
// rate correction is allowed
case 16:
case 32:
setRateCorrection(detector_shm()->deadTime);
break;
// not allowed
default:
setRateCorrection(0);
throw sls::NonCriticalError(
"Rate correction Deactivated, must be in 32 or 16 bit mode");
}
}
}
void slsDetector::printReceiverConfiguration(TLogLevel level) {
FILE_LOG(level) << "#Detector " << detId << ":\n Receiver Hostname:\t"
<< getReceiverHostname()

View File

@ -2,9 +2,9 @@
#define GITBRANCH "refgui"
#define APIGOTTHARD 0x190108
#define APIMOENCH 0x181108
#define APIEIGER 0x190405
#define APIJUNGFRAU 0x190405
#define APILIB 0x190405
#define APIRECEIVER 0x190405
#define APIGUI 0x190405
#define APICTB 0x190405
#define APICTB 0x190412
#define APIEIGER 0x190412