diff --git a/.gitignore b/.gitignore index fb8df8cb6..efbd9ce60 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ bin/ build docs/ RELEASE.txt +Testing/ *.pyc diff --git a/integrationTests/config.h b/integrationTests/config.h index 37ebd8189..32fd25ea9 100644 --- a/integrationTests/config.h +++ b/integrationTests/config.h @@ -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"; }; diff --git a/integrationTests/test-integrationDectector.cpp b/integrationTests/test-integrationDectector.cpp index 27c1f29e2..0e138f384 100755 --- a/integrationTests/test-integrationDectector.cpp +++ b/integrationTests/test-integrationDectector.cpp @@ -3,6 +3,7 @@ #include "ClientSocket.h" #include "logger.h" +#include "multiSlsDetector.h" #include "slsDetector.h" #include "sls_detector_defs.h" @@ -221,4 +222,57 @@ TEST_CASE("Excersise all possible set timer functions", "[.integration]") { // CHECK(rperiod == 0.1); // d.freeSharedMemory(); -// } \ No newline at end of file +// } + +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); +} diff --git a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_refactor b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer similarity index 56% rename from slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_refactor rename to slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer index bba1d168c..9e81bfd77 100755 Binary files a/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_refactor and b/slsDetectorServers/eigerDetectorServer/bin/eigerDetectorServer_developer differ diff --git a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c index f8d3e10bf..a61bf5f6a 100755 --- a/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/slsDetectorServer_funcs.c @@ -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)); } diff --git a/slsDetectorSoftware/include/slsDetector.h b/slsDetectorSoftware/include/slsDetector.h index b778372b1..9e95e539a 100755 --- a/slsDetectorSoftware/include/slsDetector.h +++ b/slsDetectorSoftware/include/slsDetector.h @@ -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 diff --git a/slsDetectorSoftware/src/multiSlsDetector.cpp b/slsDetectorSoftware/src/multiSlsDetector.cpp index 277ab1c0d..6eb43c94a 100755 --- a/slsDetectorSoftware/src/multiSlsDetector.cpp +++ b/slsDetectorSoftware/src/multiSlsDetector.cpp @@ -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; } diff --git a/slsDetectorSoftware/src/slsDetector.cpp b/slsDetectorSoftware/src/slsDetector.cpp index 8b4cfcc1e..ee5dd3a23 100755 --- a/slsDetectorSoftware/src/slsDetector.cpp +++ b/slsDetectorSoftware/src/slsDetector.cpp @@ -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; @@ -1951,7 +1952,7 @@ int slsDetector::setDynamicRange(int n) { client.close(); ret = updateDetector(); } - } + } // only for eiger // setting dr consequences on databytes shm @@ -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() diff --git a/slsSupportLib/include/versionAPI.h b/slsSupportLib/include/versionAPI.h index 0a3be3b92..b9644b57a 100644 --- a/slsSupportLib/include/versionAPI.h +++ b/slsSupportLib/include/versionAPI.h @@ -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 0x190412 +#define APIEIGER 0x190412