mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-13 05:17:13 +02:00
Merge branch 'developer' into testing
This commit is contained in:
@ -33,6 +33,7 @@ target_compile_definitions(ctbDetectorServer_virtual
|
||||
|
||||
target_link_libraries(ctbDetectorServer_virtual
|
||||
PUBLIC pthread rt slsProjectCWarnings
|
||||
m
|
||||
)
|
||||
|
||||
set_target_properties(ctbDetectorServer_virtual PROPERTIES
|
||||
|
Binary file not shown.
Binary file not shown.
@ -67,6 +67,7 @@ int eiger_extgating = 0;
|
||||
int eiger_extgatingpolarity = 0;
|
||||
int eiger_nexposures = 1;
|
||||
int eiger_ntriggers = 1;
|
||||
int eiger_tau_ns = 0;
|
||||
|
||||
|
||||
#ifdef VIRTUAL
|
||||
@ -477,6 +478,7 @@ void setupDetector() {
|
||||
getSubExpTime(DEFAULT_SUBFRAME_DEADTIME);
|
||||
setPeriod(DEFAULT_PERIOD);
|
||||
setNumTriggers(DEFAULT_NUM_CYCLES);
|
||||
eiger_dynamicrange = DEFAULT_DYNAMIC_RANGE;
|
||||
setDynamicRange(DEFAULT_DYNAMIC_RANGE);
|
||||
eiger_photonenergy = DEFAULT_PHOTON_ENERGY;
|
||||
setParallelMode(DEFAULT_PARALLEL_MODE);
|
||||
@ -488,6 +490,7 @@ void setupDetector() {
|
||||
setStartingFrameNumber(DEFAULT_STARTING_FRAME_NUMBER);
|
||||
setReadNLines(MAX_ROWS_PER_READOUT);
|
||||
//SetPhotonEnergyCalibrationParameters(-5.8381e-5,1.838515,5.09948e-7,-4.32390e-11,1.32527e-15);
|
||||
eiger_tau_ns = DEFAULT_RATE_CORRECTION;
|
||||
setRateCorrection(DEFAULT_RATE_CORRECTION);
|
||||
int enable[2] = {DEFAULT_EXT_GATING_ENABLE, DEFAULT_EXT_GATING_POLARITY};
|
||||
setExternalGating(enable);//disable external gating
|
||||
@ -532,31 +535,27 @@ int readRegister(uint32_t offset, uint32_t* retval) {
|
||||
|
||||
|
||||
int setDynamicRange(int dr) {
|
||||
#ifdef VIRTUAL
|
||||
if (dr > 0) {
|
||||
LOG(logINFO, ("Setting dynamic range: %d\n", dr));
|
||||
eiger_dynamicrange = dr;
|
||||
}
|
||||
return eiger_dynamicrange;
|
||||
#else
|
||||
// setting dr
|
||||
if (dr > 0) {
|
||||
LOG(logDEBUG1, ("Setting dynamic range: %d\n", dr));
|
||||
#ifndef VIRTUAL
|
||||
if (Feb_Control_SetDynamicRange(dr)) {
|
||||
|
||||
//EigerSetBitMode(dr);
|
||||
on_dst = 0;
|
||||
int i;
|
||||
for(i=0;i<32;i++) dst_requested[i] = 0; //clear dst requested
|
||||
if (Beb_SetUpTransferParameters(dr))
|
||||
eiger_dynamicrange = dr;
|
||||
else LOG(logERROR, ("Could not set bit mode in the back end\n"));
|
||||
if (!Beb_SetUpTransferParameters(dr)) {
|
||||
LOG(logERROR, ("Could not set bit mode in the back end\n"));
|
||||
return eiger_dynamicrange;
|
||||
}
|
||||
}
|
||||
}
|
||||
//make sure back end and front end have the same bit mode
|
||||
dr= Feb_Control_GetDynamicRange();
|
||||
|
||||
return dr;
|
||||
#endif
|
||||
eiger_dynamicrange = dr;
|
||||
}
|
||||
// getting dr
|
||||
#ifndef VIRTUAL
|
||||
eiger_dynamicrange = Feb_Control_GetDynamicRange();
|
||||
#endif
|
||||
return eiger_dynamicrange;
|
||||
}
|
||||
|
||||
|
||||
@ -842,8 +841,9 @@ int setModule(sls_detector_module myMod, char* mess) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// trimbits
|
||||
|
||||
#ifndef VIRTUAL
|
||||
// trimbits
|
||||
if (myMod.nchan == 0) {
|
||||
LOG(logINFO, ("Setting module without trimbits\n"));
|
||||
} else {
|
||||
@ -872,6 +872,7 @@ int setModule(sls_detector_module myMod, char* mess) {
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//rate correction
|
||||
@ -891,17 +892,24 @@ int setModule(sls_detector_module myMod, char* mess) {
|
||||
else {
|
||||
setDefaultSettingsTau_in_nsec(myMod.tau);
|
||||
if (getRateCorrectionEnable()) {
|
||||
int64_t retvalTau = setRateCorrection(myMod.tau);
|
||||
if (myMod.tau != retvalTau) {
|
||||
sprintf(mess, "Cannot set module. Could not set rate correction\n");
|
||||
if (setRateCorrection(myMod.tau) == FAIL) {
|
||||
sprintf(mess, "Cannot set module. Rate correction failed.\n");
|
||||
LOG(logERROR, (mess));
|
||||
setSettings(UNDEFINED);
|
||||
LOG(logERROR, ("Settings has been changed to undefined (random trim file)\n"));
|
||||
return FAIL;
|
||||
return FAIL;
|
||||
} else {
|
||||
int64_t retvalTau = getCurrentTau();
|
||||
if (myMod.tau != retvalTau) {
|
||||
sprintf(mess, "Cannot set module. Could not set rate correction\n");
|
||||
LOG(logERROR, (mess));
|
||||
setSettings(UNDEFINED);
|
||||
LOG(logERROR, ("Settings has been changed to undefined (random trim file)\n"));
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return OK;
|
||||
}
|
||||
|
||||
@ -1449,12 +1457,59 @@ int pulseChip(int n) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
int64_t setRateCorrection(int64_t custom_tau_in_nsec) {//in nanosec (will never be -1)
|
||||
int updateRateCorrection(char* mess) {
|
||||
int ret = OK;
|
||||
// recalculates rate correction table, or switches off in wrong bit mode
|
||||
if (eiger_tau_ns != 0) {
|
||||
switch (eiger_dynamicrange) {
|
||||
case 16:
|
||||
case 32:
|
||||
ret = setRateCorrection(eiger_tau_ns);
|
||||
break;
|
||||
default:
|
||||
setRateCorrection(0);
|
||||
strcpy(mess, "Rate correction Deactivated, must be in 32 or 16 bit mode");
|
||||
ret = FAIL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
getCurrentTau(); // update eiger_tau_ns
|
||||
return ret;
|
||||
}
|
||||
|
||||
int validateAndSetRateCorrection(int64_t tau_ns, char* mess) {
|
||||
// switching on in wrong bit mode
|
||||
if ((tau_ns != 0) &&
|
||||
(eiger_dynamicrange != 32) && (eiger_dynamicrange != 16)) {
|
||||
strcpy(mess,"Rate correction Deactivated, must be in 32 or 16 bit mode\n");
|
||||
LOG(logERROR,(mess));
|
||||
return FAIL;
|
||||
}
|
||||
// default tau (-1, get proper value)
|
||||
if (tau_ns < 0) {
|
||||
tau_ns = getDefaultSettingsTau_in_nsec();
|
||||
if (tau_ns < 0) {
|
||||
strcpy(mess,"Default settings file not loaded. No default tau yet\n");
|
||||
LOG(logERROR,(mess));
|
||||
return FAIL;
|
||||
}
|
||||
eiger_tau_ns = -1;
|
||||
}
|
||||
// user defined value (settings become undefined)
|
||||
else if (tau_ns > 0) {
|
||||
setSettings(UNDEFINED);
|
||||
LOG(logERROR, ("Settings has been changed to undefined (tau changed)\n"));
|
||||
eiger_tau_ns = tau_ns;
|
||||
}
|
||||
return setRateCorrection(tau_ns);
|
||||
}
|
||||
|
||||
int setRateCorrection(int64_t custom_tau_in_nsec) {//in nanosec (will never be -1)
|
||||
#ifdef VIRTUAL
|
||||
//deactivating rate correction
|
||||
if (custom_tau_in_nsec==0) {
|
||||
eiger_virtual_ratecorrection_variable = 0;
|
||||
return 0;
|
||||
return OK;
|
||||
}
|
||||
|
||||
//when dynamic range changes, use old tau
|
||||
@ -1484,22 +1539,21 @@ int64_t setRateCorrection(int64_t custom_tau_in_nsec) {//in nanosec (will never
|
||||
//different setting, calculate table
|
||||
else {
|
||||
eiger_virtual_ratetable_tau_in_ns = custom_tau_in_nsec;
|
||||
double period_in_sec = (double)(eiger_virtual_subexptime*10)/(double)1e9;
|
||||
eiger_virtual_ratetable_period_in_ns = eiger_virtual_subexptime*10;
|
||||
if (eiger_dynamicrange == 16)
|
||||
period_in_sec = eiger_virtual_exptime;
|
||||
eiger_virtual_ratetable_period_in_ns = period_in_sec*1e9;
|
||||
eiger_virtual_ratetable_period_in_ns = eiger_virtual_exptime;
|
||||
}
|
||||
//activating rate correction
|
||||
eiger_virtual_ratecorrection_variable = 1;
|
||||
LOG(logINFO, ("Rate Correction Value set to %lld ns\n",(long long int)eiger_virtual_ratetable_tau_in_ns));
|
||||
|
||||
return eiger_virtual_ratetable_tau_in_ns;
|
||||
return OK;
|
||||
#else
|
||||
|
||||
//deactivating rate correction
|
||||
if (custom_tau_in_nsec==0) {
|
||||
Feb_Control_SetRateCorrectionVariable(0);
|
||||
return 0;
|
||||
return OK;
|
||||
}
|
||||
|
||||
//when dynamic range changes, use old tau
|
||||
@ -1533,7 +1587,7 @@ int64_t setRateCorrection(int64_t custom_tau_in_nsec) {//in nanosec (will never
|
||||
if (ret<=0) {
|
||||
LOG(logERROR, ("Rate correction failed. Deactivating rate correction\n"));
|
||||
Feb_Control_SetRateCorrectionVariable(0);
|
||||
return ret;
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
//activating rate correction
|
||||
@ -1541,7 +1595,7 @@ int64_t setRateCorrection(int64_t custom_tau_in_nsec) {//in nanosec (will never
|
||||
LOG(logINFO, ("Rate Correction Value set to %lld ns\n", (long long int)Feb_Control_Get_RateTable_Tau_in_nsec()));
|
||||
Feb_Control_PrintCorrectedValues();
|
||||
|
||||
return Feb_Control_Get_RateTable_Tau_in_nsec();
|
||||
return OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -1559,18 +1613,22 @@ int getDefaultSettingsTau_in_nsec() {
|
||||
|
||||
void setDefaultSettingsTau_in_nsec(int t) {
|
||||
default_tau_from_file = t;
|
||||
LOG(logINFO, ("Default tau set to %d\n", default_tau_from_file));
|
||||
LOG(logINFOBLUE, ("Default tau set to %d\n", default_tau_from_file));
|
||||
}
|
||||
|
||||
int64_t getCurrentTau() {
|
||||
if (!getRateCorrectionEnable())
|
||||
if (!getRateCorrectionEnable()) {
|
||||
eiger_tau_ns = 0;
|
||||
return 0;
|
||||
else
|
||||
}
|
||||
else {
|
||||
#ifndef VIRTUAL
|
||||
return Feb_Control_Get_RateTable_Tau_in_nsec();
|
||||
eiger_tau_ns = Feb_Control_Get_RateTable_Tau_in_nsec();
|
||||
#else
|
||||
return eiger_virtual_ratetable_tau_in_ns;
|
||||
eiger_tau_ns = eiger_virtual_ratetable_tau_in_ns;
|
||||
#endif
|
||||
return eiger_tau_ns;
|
||||
}
|
||||
}
|
||||
|
||||
void setExternalGating(int enable[]) {
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -31,6 +31,7 @@ target_compile_definitions(moenchDetectorServer_virtual
|
||||
|
||||
target_link_libraries(moenchDetectorServer_virtual
|
||||
PUBLIC pthread rt slsProjectCWarnings
|
||||
m
|
||||
)
|
||||
|
||||
set_target_properties(moenchDetectorServer_virtual PROPERTIES
|
||||
|
Binary file not shown.
Binary file not shown.
@ -413,7 +413,9 @@ int setCounterBit(int val);
|
||||
int pulsePixel(int n, int x, int y);
|
||||
int pulsePixelNMove(int n, int x, int y);
|
||||
int pulseChip(int n);
|
||||
int64_t setRateCorrection(int64_t custom_tau_in_nsec);
|
||||
int updateRateCorrection(char* mess);
|
||||
int validateAndSetRateCorrection(int64_t tau_ns, char* mess);
|
||||
int setRateCorrection(int64_t custom_tau_in_nsec);
|
||||
int getRateCorrectionEnable();
|
||||
int getDefaultSettingsTau_in_nsec();
|
||||
void setDefaultSettingsTau_in_nsec(int t);
|
||||
|
@ -217,3 +217,5 @@ int set_current_source(int);
|
||||
int get_timing_source(int);
|
||||
int set_timing_source(int);
|
||||
int get_num_channels(int);
|
||||
int update_rate_correction(int);
|
||||
|
||||
|
@ -317,6 +317,7 @@ const char* getFunctionName(enum detFuncs func) {
|
||||
case F_GET_TIMING_SOURCE: return "F_GET_TIMING_SOURCE";
|
||||
case F_SET_TIMING_SOURCE: return "F_SET_TIMING_SOURCE";
|
||||
case F_GET_NUM_CHANNELS: return "F_GET_NUM_CHANNELS";
|
||||
case F_UPDATE_RATE_CORRECTION: return "F_UPDATE_RATE_CORRECTION";
|
||||
|
||||
default: return "Unknown Function";
|
||||
}
|
||||
@ -510,6 +511,7 @@ void function_table() {
|
||||
flist[F_GET_TIMING_SOURCE] = &get_timing_source;
|
||||
flist[F_SET_TIMING_SOURCE] = &set_timing_source;
|
||||
flist[F_GET_NUM_CHANNELS] = &get_num_channels;
|
||||
flist[F_UPDATE_RATE_CORRECTION] = &update_rate_correction;
|
||||
|
||||
// check
|
||||
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
|
||||
@ -2844,61 +2846,12 @@ int send_update(int file_des) {
|
||||
ret = OK;
|
||||
int n = 0;
|
||||
int i32 = -1;
|
||||
int64_t i64 = -1;
|
||||
|
||||
i32 = lastClientIP;
|
||||
i32 = __builtin_bswap32(i32);
|
||||
n = sendData(file_des, &i32,sizeof(i32),INT32);
|
||||
if (n < 0) return printSocketReadError();
|
||||
|
||||
// dr
|
||||
i32 = setDynamicRange(GET_FLAG);
|
||||
n = sendData(file_des,&i32,sizeof(i32),INT32);
|
||||
if (n < 0) return printSocketReadError();
|
||||
|
||||
// settings
|
||||
#if defined(EIGERD) || defined(JUNGFRAUD) || defined(GOTTHARDD) || defined(GOTTHARD2D)|| defined(MOENCHD)
|
||||
i32 = (int)getSettings();
|
||||
n = sendData(file_des,&i32,sizeof(i32),INT32);
|
||||
if (n < 0) return printSocketReadError();
|
||||
#endif
|
||||
|
||||
// #frames
|
||||
i64 = getNumFrames();
|
||||
n = sendData(file_des,&i64,sizeof(i64),INT64);
|
||||
if (n < 0) return printSocketReadError();
|
||||
|
||||
// #storage cell
|
||||
#ifdef JUNGFRAUD
|
||||
i64 = getNumAdditionalStorageCells();
|
||||
n = sendData(file_des,&i64,sizeof(i64),INT64);
|
||||
if (n < 0) return printSocketReadError();
|
||||
#endif
|
||||
|
||||
// #triggers
|
||||
i64 = getNumTriggers();
|
||||
n = sendData(file_des,&i64,sizeof(i64),INT64);
|
||||
if (n < 0) return printSocketReadError();
|
||||
|
||||
// #bursts
|
||||
#ifdef GOTTHARD2D
|
||||
i64 = getNumBursts();
|
||||
n = sendData(file_des,&i64,sizeof(i64),INT64);
|
||||
if (n < 0) return printSocketReadError();
|
||||
#endif
|
||||
|
||||
// timing mode
|
||||
i32 = (int)getTiming();
|
||||
n = sendData(file_des,&i32,sizeof(i32),INT32);
|
||||
if (n < 0) return printSocketReadError();
|
||||
|
||||
// burst mode
|
||||
#ifdef GOTTHARD2D
|
||||
i32 = (int)getBurstMode();
|
||||
n = sendData(file_des,&i32,sizeof(i32),INT32);
|
||||
if (n < 0) return printSocketReadError();
|
||||
#endif
|
||||
|
||||
// number of channels
|
||||
#if defined(MOENCHD) || defined(CHIPTESTBOARDD)
|
||||
{
|
||||
@ -3498,35 +3451,13 @@ int set_rate_correct(int file_des) {
|
||||
#else
|
||||
// only set
|
||||
if (Server_VerifyLock() == OK) {
|
||||
|
||||
int dr = setDynamicRange(-1);
|
||||
|
||||
// switching on in wrong bit mode
|
||||
if ((tau_ns != 0) && (dr != 32) && (dr != 16)) {
|
||||
ret = FAIL;
|
||||
strcpy(mess,"Rate correction Deactivated, must be in 32 or 16 bit mode\n");
|
||||
LOG(logERROR,(mess));
|
||||
}
|
||||
|
||||
// switching on in right mode
|
||||
else {
|
||||
if (tau_ns < 0) {
|
||||
tau_ns = getDefaultSettingsTau_in_nsec();
|
||||
if (tau_ns < 0) {
|
||||
ret = FAIL;
|
||||
strcpy(mess,"Default settings file not loaded. No default tau yet\n");
|
||||
LOG(logERROR,(mess));
|
||||
}
|
||||
}
|
||||
else if (tau_ns > 0) {
|
||||
//changing tau to a user defined value changes settings to undefined
|
||||
setSettings(UNDEFINED);
|
||||
LOG(logERROR, ("Settings has been changed to undefined (tau changed)\n"));
|
||||
}
|
||||
if (ret == OK) {
|
||||
int64_t retval = setRateCorrection(tau_ns);
|
||||
validate64(tau_ns, retval, "set rate correction", DEC);
|
||||
}
|
||||
ret = validateAndSetRateCorrection(tau_ns, mess);
|
||||
int64_t retval = getCurrentTau(); // to update eiger_tau_ns (for update rate correction)
|
||||
if (ret == FAIL) {
|
||||
strcpy(mess, "Rate correction failed\n");
|
||||
LOG(logERROR, (mess));
|
||||
} else {
|
||||
validate64(tau_ns, retval, "set rate correction", DEC);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -6930,4 +6861,22 @@ int get_num_channels(int file_des) {
|
||||
LOG(logDEBUG1, ("Get number of channels sretval:[%d, %d]\n", retvals[0], retvals[1]));
|
||||
#endif
|
||||
return Server_SendResult(file_des, INT32, UPDATE, retvals, sizeof(retvals));
|
||||
}
|
||||
|
||||
|
||||
|
||||
int update_rate_correction(int file_des) {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
|
||||
#ifndef EIGERD
|
||||
functionNotImplemented();
|
||||
#else
|
||||
LOG(logINFO, ("Update Rate Correction\n"));
|
||||
// only set
|
||||
if (Server_VerifyLock() == OK) {
|
||||
ret = updateRateCorrection(mess);
|
||||
}
|
||||
#endif
|
||||
return Server_SendResult(file_des, INT32, UPDATE, NULL, 0);
|
||||
}
|
Reference in New Issue
Block a user