From d904f7b32ea8025d8dd1803a9f7d1e425395e9d6 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 23 Sep 2016 14:28:20 +0200 Subject: [PATCH] adding 16 bit rate correction in eiger --- slsDetectorSoftware/commonFiles/error_defs.h | 6 ++-- .../eigerDetectorServer/FebControl.c | 31 ++++++++++++++++--- .../eigerDetectorServer/FebControl.h | 2 ++ .../slsDetectorFunctionList.c | 23 ++++++++++++-- .../slsDetector/slsDetector.cpp | 20 +++++++++--- .../slsDetectorServer_funcs.c | 21 ++++++++++--- 6 files changed, 84 insertions(+), 19 deletions(-) diff --git a/slsDetectorSoftware/commonFiles/error_defs.h b/slsDetectorSoftware/commonFiles/error_defs.h index 89798faef..530c8c9c5 100644 --- a/slsDetectorSoftware/commonFiles/error_defs.h +++ b/slsDetectorSoftware/commonFiles/error_defs.h @@ -59,7 +59,7 @@ using namespace std; #define COULD_NOT_PULSE_CHIP 0x0000000000100000ULL #define COULD_NOT_SET_RATE_CORRECTION 0x0000000000200000ULL #define DETECTOR_NETWORK_PARAMETER 0x0000000000400000ULL -#define RATE_CORRECTION_NOT_32BIT 0x0000000000800000ULL +#define RATE_CORRECTION_NOT_32or16BIT 0x0000000000800000ULL #define RATE_CORRECTION_NO_TAU_PROVIDED 0x0000000001000000ULL // 0x00000000FFFFFFFFULL @@ -192,8 +192,8 @@ public: if(slsErrorMask&DETECTOR_NETWORK_PARAMETER) retval.append("Could not set/get detector network parameter\n"); - if(slsErrorMask&RATE_CORRECTION_NOT_32BIT) - retval.append("Rate correction Deactivated, must be in 32 bit mode\n"); + if(slsErrorMask&RATE_CORRECTION_NOT_32or16BIT) + retval.append("Rate correction Deactivated, must be in 32 or 16 bit mode\n"); if(slsErrorMask&RATE_CORRECTION_NO_TAU_PROVIDED) retval.append("Rate correction Deactivated. No default tau provided in file\n"); diff --git a/slsDetectorSoftware/eigerDetectorServer/FebControl.c b/slsDetectorSoftware/eigerDetectorServer/FebControl.c index a07d6b2fb..fe63977af 100644 --- a/slsDetectorSoftware/eigerDetectorServer/FebControl.c +++ b/slsDetectorSoftware/eigerDetectorServer/FebControl.c @@ -51,6 +51,7 @@ double Feb_Control_exposure_period_in_sec; int64_t Feb_Control_RateTable_Tau_in_nsec = -1; int64_t Feb_Control_RateTable_Subexptime_in_nsec = -1; +int64_t Feb_Control_RateTable_Exptime_in_nsec = -1; unsigned int Feb_Control_trimbit_size; unsigned int* Feb_Control_last_downloaded_trimbits; @@ -1371,6 +1372,7 @@ int Feb_Control_SetExposureTime(double the_exposure_time_in_sec){ return 1; } double Feb_Control_GetExposureTime(){return Feb_Control_exposure_time_in_sec;} +int64_t Feb_Control_GetExposureTime_in_nsec(){return (int64_t)(Feb_Control_exposure_time_in_sec*(1E9));} int Feb_Control_SetSubFrameExposureTime(int64_t the_subframe_exposure_time_in_10nsec){ Feb_Control_subframe_exposure_time_in_10nsec = the_subframe_exposure_time_in_10nsec; @@ -1790,25 +1792,39 @@ int Feb_Control_PulseChip(int npulses){ int64_t Feb_Control_Get_RateTable_Tau_in_nsec(){ return Feb_Control_RateTable_Tau_in_nsec;} int64_t Feb_Control_Get_RateTable_Subexptime_in_nsec(){ return Feb_Control_RateTable_Subexptime_in_nsec;} +int64_t Feb_Control_Get_RateTable_Exptime_in_nsec(){ return Feb_Control_RateTable_Exptime_in_nsec;} //returns -1 if slope is too high int Feb_Control_SetRateCorrectionTau(int64_t tau_in_Nsec){ + double exptime_in_sec = Feb_Control_GetExposureTime(); double sub_expure_time_in_sec = (double)(Feb_Control_GetSubFrameExposureTime())/(double)1e9; + + + int dr = Feb_Control_GetDynamicRange(); + double period_in_sec = sub_expure_time_in_sec; + if(dr == 16) + period_in_sec = exptime_in_sec; + double tau_in_sec = (double)tau_in_Nsec/(double)1e9; unsigned int np = 16384; //max slope 16 * 1024 double b0[1024]; double m[1024]; - if(tau_in_sec<0||sub_expure_time_in_sec<0){ - printf("Error tau %f and sub_expure_time %f must be greater than 0.\n", tau_in_sec, sub_expure_time_in_sec); + + if(tau_in_sec<0||period_in_sec<0){ + if(dr == 32) + printf("Error tau %f and sub_exposure_time %f must be greater than 0.\n", tau_in_sec, sub_expure_time_in_sec); + else + printf("Error tau %f and exposure_time %f must be greater than 0.\n", tau_in_sec, exptime_in_sec); return 0; } printf("\tCalculating table for tau of %lld ns.\n", tau_in_Nsec); int i; for(i=0;imyDetectorType == EIGER) && (t>=0) && getRateCorrection(r)){ + if( (thisDetector->myDetectorType == EIGER) && + getRateCorrection(r) && + (t>=0) && + + (((index == SUBFRAME_ACQUISITION_TIME) && (thisDetector->dynamicRange == 32))|| + ((index == ACQUISITION_TIME) && (thisDetector->dynamicRange == 16))) + + && (t>=0) && getRateCorrection(r)){ setRateCorrection(r); } @@ -4515,8 +4523,12 @@ int slsDetector::setDynamicRange(int n){ if (rateret==FAIL) { controlSocket->ReceiveDataOnly(mess,sizeof(mess)); std::cout<< "Detector returned error: " << mess << std::endl; - if(strstr(mess,"Rate Correction")!=NULL) - setErrorMask((getErrorMask())|(RATE_CORRECTION_NOT_32BIT)); + if(strstr(mess,"Rate Correction")!=NULL){ + if(strstr(mess,"32")!=NULL) + setErrorMask((getErrorMask())|(RATE_CORRECTION_NOT_32or16BIT)); + else + setErrorMask((getErrorMask())|(COULD_NOT_SET_RATE_CORRECTION)); + } } } controlSocket->ReceiveDataOnly(&ret,sizeof(ret)); @@ -5090,7 +5102,7 @@ int slsDetector::setRateCorrection(double t){ if(strstr(mess,"default tau")!=NULL) setErrorMask((getErrorMask())|(RATE_CORRECTION_NO_TAU_PROVIDED)); if(strstr(mess,"32")!=NULL) - setErrorMask((getErrorMask())|(RATE_CORRECTION_NOT_32BIT)); + setErrorMask((getErrorMask())|(RATE_CORRECTION_NOT_32or16BIT)); else setErrorMask((getErrorMask())|(COULD_NOT_SET_RATE_CORRECTION)); } diff --git a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c index bbba27be6..63b95f90f 100755 --- a/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c +++ b/slsDetectorSoftware/slsDetectorServer/slsDetectorServer_funcs.c @@ -2788,15 +2788,26 @@ int set_dynamic_range(int file_des) { #endif } if(ret == OK){ + int old_dr = setDynamicRange(-1); retval=setDynamicRange(dr); if (dr>=0 && retval!=dr) ret=FAIL; //look at rate correction only if dr change worked - if((ret==OK) && (dr!=32) && (dr!=-1) && (getRateCorrectionEnable())){ + if((ret==OK) && (dr!=32) && (dr!=16) && (dr!=-1) && (getRateCorrectionEnable())){ setRateCorrection(0); - strcpy(mess,"Switching off Rate Correction. Must be in 32 bit mode\n"); + strcpy(mess,"Switching off Rate Correction. Must be in 32 or 16 bit mode\n"); cprintf(RED,"%s",mess); rateret = FAIL; + }else{ + //setting it if dr changed from 16 to 32 or vice versa with tau value as in rate table + if((dr!=-1) && (old_dr != dr) && getRateCorrectionEnable() && (dr == 16 || dr == 32)){ + setRateCorrection(-1); //tau_ns will not be -1 here + if(!getRateCorrectionEnable()){ + strcpy(mess,"Deactivating Rate Correction. Could not set it.\n"); + cprintf(RED,"%s",mess); + ret=FAIL; + } + } } } #endif @@ -3978,9 +3989,9 @@ int set_rate_correct(int file_des) { //set rate else{ - //not 32 bit mode - if((setDynamicRange(-1)!=32) && (tau_ns!=0)){ - strcpy(mess,"Rate correction Deactivated, must be in 32 bit mode\n"); + //not 32 or 16 bit mode + if((setDynamicRange(-1)!=32) && (setDynamicRange(-1)!=16) && (tau_ns!=0)){ + strcpy(mess,"Rate correction Deactivated, must be in 32 or 16 bit mode\n"); cprintf(RED,"%s",mess); ret=FAIL; }