Merge pull request #269 from slsdetectorgroup/j3settings

Jungfrau features: 3. settings
This commit is contained in:
Dhanya Thattil 2021-07-29 12:55:26 +02:00 committed by GitHub
commit ffc3d4ddd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 119 additions and 190 deletions

View File

@ -104,10 +104,6 @@ def test_settings(virtual_jf_detectors):
assert d.settings == detectorSettings.DYNAMICGAIN
gain_list = [
detectorSettings.FIXGAIN1,
detectorSettings.FIXGAIN2,
detectorSettings.FORCESWITCHG1,
detectorSettings.FORCESWITCHG2,
detectorSettings.DYNAMICHG0,
detectorSettings.DYNAMICGAIN,
]
@ -117,10 +113,9 @@ def test_settings(virtual_jf_detectors):
d.settings = gain
assert d.settings == gain
d.setSettings(detectorSettings.FORCESWITCHG1, [1])
d.setSettings(detectorSettings.DYNAMICGAIN, [1])
assert d.settings == [
detectorSettings.DYNAMICGAIN,
detectorSettings.FORCESWITCHG1,
detectorSettings.DYNAMICHG0,
detectorSettings.DYNAMICGAIN,
]

View File

@ -311,7 +311,7 @@ class Detector(CppDetectorApi):
-----
[Eiger] Use threshold command to load settings
[Jungfrau] DYNAMICGAIN, DYNAMICHG0, FIXGAIN1, FIXGAIN2, FORCESWITCHG1, FORCESWITCHG2 \n
[Jungfrau] DYNAMICGAIN, DYNAMICHG0 \n
[Gotthard] DYNAMICGAIN, HIGHGAIN, LOWGAIN, MEDIUMGAIN, VERYHIGHGAIN \n
[Gotthard2] DYNAMICGAIN, FIXGAIN1, FIXGAIN2 \n
[Moench] G1_HIGHGAIN, G1_LOWGAIN, G2_HIGHCAP_HIGHGAIN, G2_HIGHCAP_LOWGAIN, G2_LOWCAP_HIGHGAIN, G2_LOWCAP_LOWGAIN, G4_HIGHGAIN, G4_LOWGAIN \n

View File

@ -213,10 +213,6 @@ void init_enums(py::module &m) {
.value("DYNAMICHG0", slsDetectorDefs::detectorSettings::DYNAMICHG0)
.value("FIXGAIN1", slsDetectorDefs::detectorSettings::FIXGAIN1)
.value("FIXGAIN2", slsDetectorDefs::detectorSettings::FIXGAIN2)
.value("FORCESWITCHG1",
slsDetectorDefs::detectorSettings::FORCESWITCHG1)
.value("FORCESWITCHG2",
slsDetectorDefs::detectorSettings::FORCESWITCHG2)
.value("VERYLOWGAIN", slsDetectorDefs::detectorSettings::VERYLOWGAIN)
.value("G1_HIGHGAIN", slsDetectorDefs::detectorSettings::G1_HIGHGAIN)
.value("G1_LOWGAIN", slsDetectorDefs::detectorSettings::G1_LOWGAIN)

View File

@ -527,16 +527,6 @@
<string>Fix Gain 2</string>
</property>
</item>
<item>
<property name="text">
<string>Force Switch G1</string>
</property>
</item>
<item>
<property name="text">
<string>Force Switch G2</string>
</property>
</item>
<item>
<property name="text">
<string>Very Low Gain</string>

View File

@ -43,8 +43,6 @@ class qTabSettings : public QWidget, private Ui::TabSettingsObject {
DYNAMICHG0,
FIXGAIN1,
FIXGAIN2,
FORCESWITCHG1,
FORCESWITCHG2,
VERLOWGAIN,
G1_HIGHGAIN,
G1_LOWGAIN,

View File

@ -213,23 +213,16 @@ void qTabMeasurement::SetupTimingMode() {
index[i] = model->index(i, comboTimingMode->modelColumn(),
comboTimingMode->rootModelIndex());
item[i] = model->itemFromIndex(index[i]);
item[i]->setEnabled(false);
}
item[(int)GATED]->setEnabled(false);
item[(int)BURST_TRIGGER]->setEnabled(false);
item[(int)TRIGGER_GATED]->setEnabled(false);
switch (det->getDetectorType().squash()) {
case slsDetectorDefs::EIGER:
item[(int)GATED]->setEnabled(true);
item[(int)BURST_TRIGGER]->setEnabled(true);
break;
case slsDetectorDefs::MYTHEN3:
item[(int)GATED]->setEnabled(true);
item[(int)TRIGGER_GATED]->setEnabled(true);
break;
default:
break;
try {
auto res = det->getTimingModeList();
for (auto it : res) {
item[(int)it]->setEnabled(true);
}
}
CATCH_DISPLAY(std::string("Could not setup timing mode"),
"qTabMeasurement::SetupTimingMode")
}
}

View File

@ -101,56 +101,14 @@ void qTabSettings::SetupDetectorSettings() {
item[i] = model->itemFromIndex(index[i]);
item[i]->setEnabled(false);
}
switch (det->getDetectorType().squash()) {
case slsDetectorDefs::EIGER:
item[(int)STANDARD]->setEnabled(true);
item[(int)HIGHGAIN]->setEnabled(true);
item[(int)LOWGAIN]->setEnabled(true);
item[(int)VERYHIGHGAIN]->setEnabled(true);
item[(int)VERLOWGAIN]->setEnabled(true);
break;
case slsDetectorDefs::GOTTHARD:
item[(int)HIGHGAIN]->setEnabled(true);
item[(int)DYNAMICGAIN]->setEnabled(true);
item[(int)LOWGAIN]->setEnabled(true);
item[(int)MEDIUMGAIN]->setEnabled(true);
item[(int)VERYHIGHGAIN]->setEnabled(true);
break;
case slsDetectorDefs::JUNGFRAU:
item[(int)DYNAMICGAIN]->setEnabled(true);
item[(int)DYNAMICHG0]->setEnabled(true);
item[(int)FIXGAIN1]->setEnabled(true);
item[(int)FIXGAIN2]->setEnabled(true);
item[(int)FORCESWITCHG1]->setEnabled(true);
item[(int)FORCESWITCHG2]->setEnabled(true);
break;
case slsDetectorDefs::GOTTHARD2:
item[(int)DYNAMICGAIN]->setEnabled(true);
item[(int)FIXGAIN1]->setEnabled(true);
item[(int)FIXGAIN2]->setEnabled(true);
break;
case slsDetectorDefs::MOENCH:
item[(int)G1_HIGHGAIN]->setEnabled(true);
item[(int)G1_LOWGAIN]->setEnabled(true);
item[(int)G2_HIGHCAP_HIGHGAIN]->setEnabled(true);
item[(int)G2_HIGHCAP_LOWGAIN]->setEnabled(true);
item[(int)G2_LOWCAP_HIGHGAIN]->setEnabled(true);
item[(int)G2_LOWCAP_LOWGAIN]->setEnabled(true);
item[(int)G4_HIGHGAIN]->setEnabled(true);
item[(int)G4_LOWGAIN]->setEnabled(true);
break;
case slsDetectorDefs::MYTHEN3:
item[(int)STANDARD]->setEnabled(true);
item[(int)FAST]->setEnabled(true);
item[(int)HIGHGAIN]->setEnabled(true);
break;
default:
LOG(logDEBUG) << "Unknown detector type. Exiting GUI.";
qDefs::Message(qDefs::CRITICAL,
"Unknown detector type. Exiting GUI.",
"qTabSettings::SetupDetectorSettings");
exit(-1);
try {
auto res = det->getSettingsList();
for (auto it : res) {
item[(int)it]->setEnabled(true);
}
}
CATCH_DISPLAY(std::string("Could not setup settings"),
"qTabSettings::SetupDetectorSettings")
}
}

View File

@ -884,42 +884,23 @@ enum detectorSettings setSettings(enum detectorSettings sett) {
if (sett == UNINITIALIZED)
return thisSettings;
int G0DacVals[] = SPECIAL_DEFAULT_DYNAMIC_GAIN_VALS;
int HG0DacVals[] = SPECIAL_DEFAULT_DYNAMICHG0_GAIN_VALS;
int *dacVals = NULL;
// set settings
switch (sett) {
case DYNAMICGAIN:
bus_w(DAQ_REG, bus_r(DAQ_REG) & ~DAQ_SETTINGS_MSK);
LOG(logINFO,
("Set settings - Dyanmic Gain, DAQ Reg: 0x%x\n", bus_r(DAQ_REG)));
dacVals = G0DacVals;
break;
case DYNAMICHG0:
bus_w(DAQ_REG, bus_r(DAQ_REG) & ~DAQ_SETTINGS_MSK);
bus_w(DAQ_REG, bus_r(DAQ_REG) | DAQ_FIX_GAIN_HIGHGAIN_VAL);
LOG(logINFO, ("Set settings - Dyanmic High Gain 0, DAQ Reg: 0x%x\n",
bus_r(DAQ_REG)));
break;
case FIXGAIN1:
bus_w(DAQ_REG, bus_r(DAQ_REG) & ~DAQ_SETTINGS_MSK);
bus_w(DAQ_REG, bus_r(DAQ_REG) | DAQ_FIX_GAIN_STG_1_VAL);
LOG(logINFO,
("Set settings - Fix Gain 1, DAQ Reg: 0x%x\n", bus_r(DAQ_REG)));
break;
case FIXGAIN2:
bus_w(DAQ_REG, bus_r(DAQ_REG) & ~DAQ_SETTINGS_MSK);
bus_w(DAQ_REG, bus_r(DAQ_REG) | DAQ_FIX_GAIN_STG_2_VAL);
LOG(logINFO,
("Set settings - Fix Gain 2, DAQ Reg: 0x%x\n", bus_r(DAQ_REG)));
break;
case FORCESWITCHG1:
bus_w(DAQ_REG, bus_r(DAQ_REG) & ~DAQ_SETTINGS_MSK);
bus_w(DAQ_REG, bus_r(DAQ_REG) | DAQ_FRCE_GAIN_STG_1_VAL);
LOG(logINFO, ("Set settings - Force Switch Gain 1, DAQ Reg: 0x%x\n",
bus_r(DAQ_REG)));
break;
case FORCESWITCHG2:
bus_w(DAQ_REG, bus_r(DAQ_REG) & ~DAQ_SETTINGS_MSK);
bus_w(DAQ_REG, bus_r(DAQ_REG) | DAQ_FRCE_GAIN_STG_2_VAL);
LOG(logINFO, ("Set settings - Force Switch Gain 2, DAQ Reg: 0x%x\n",
bus_r(DAQ_REG)));
dacVals = HG0DacVals;
break;
default:
LOG(logERROR,
@ -929,63 +910,68 @@ enum detectorSettings setSettings(enum detectorSettings sett) {
thisSettings = sett;
return getSettings();
}
// set special dacs
const int specialDacs[] = SPECIALDACINDEX;
for (int i = 0; i < NSPECIALDACS; ++i) {
setDAC(specialDacs[i], dacVals[i], 0);
}
enum detectorSettings getSettings() {
uint32_t regval = bus_r(DAQ_REG);
uint32_t val = regval & DAQ_SETTINGS_MSK;
LOG(logDEBUG1, ("Getting Settings\n Reading DAQ Register :0x%x\n", val));
switch (val) {
case DAQ_FIX_GAIN_DYNMC_VAL:
thisSettings = DYNAMICGAIN;
LOG(logDEBUG1,
("Settings read: Dynamic Gain. DAQ Reg: 0x%x\n", regval));
break;
case DAQ_FIX_GAIN_HIGHGAIN_VAL:
thisSettings = DYNAMICHG0;
LOG(logDEBUG1,
("Settings read: Dynamig High Gain. DAQ Reg: 0x%x\n", regval));
break;
case DAQ_FIX_GAIN_STG_1_VAL:
thisSettings = FIXGAIN1;
LOG(logDEBUG1, ("Settings read: Fix Gain 1. DAQ Reg: 0x%x\n", regval));
break;
case DAQ_FIX_GAIN_STG_2_VAL:
thisSettings = FIXGAIN2;
LOG(logDEBUG1, ("Settings read: Fix Gain 2. DAQ Reg: 0x%x\n", regval));
break;
case DAQ_FRCE_GAIN_STG_1_VAL:
thisSettings = FORCESWITCHG1;
LOG(logDEBUG1,
("Settings read: Force Switch Gain 1. DAQ Reg: 0x%x\n", regval));
break;
case DAQ_FRCE_GAIN_STG_2_VAL:
thisSettings = FORCESWITCHG2;
LOG(logDEBUG1,
("Settings read: Force Switch Gain 2. DAQ Reg: 0x%x\n", regval));
break;
default:
thisSettings = UNDEFINED;
LOG(logERROR, ("Settings read: Undefined. DAQ Reg: 0x%x\n", regval));
// if chip 1.1, and power chip on, configure chip
if (getChipVersion() == 11 && powerChip(-1)) {
configureChip();
}
return thisSettings;
}
void validateSettings() {
// if any special dac value is changed individually => undefined
const int specialDacs[NSPECIALDACS] = SPECIALDACINDEX;
int specialDacValues[NUMSETTINGS][NSPECIALDACS] = {
SPECIAL_DEFAULT_DYNAMIC_GAIN_VALS,
SPECIAL_DEFAULT_DYNAMICHG0_GAIN_VALS};
int settList[NUMSETTINGS] = {DYNAMICGAIN, DYNAMICHG0};
enum detectorSettings sett = UNDEFINED;
for (int isett = 0; isett != NUMSETTINGS; ++isett) {
// dont overwrite if settings is correct
if (sett != UNDEFINED) {
break;
}
// assume it matches current setting in list
sett = settList[isett];
for (int ival = 0; ival < NSPECIALDACS; ++ival) {
// if one value does not match, undefined
if (getDAC(specialDacs[ival], 0) != specialDacValues[isett][ival]) {
sett = UNDEFINED;
break;
}
}
}
// update settings
if (thisSettings != sett) {
LOG(logINFOBLUE,
("Validated settings to %s (%d)\n",
(sett == DYNAMICGAIN
? "dynamicgain"
: (sett == DYNAMICHG0 ? "dynamichg0" : "undefined")),
sett));
thisSettings = sett;
}
}
enum detectorSettings getSettings() { return thisSettings; }
/* parameters - dac, adc, hv */
void setDAC(enum DACINDEX ind, int val, int mV) {
if (val < 0)
return;
char *dac_names[] = {DAC_NAMES};
LOG(logINFO, ("Setting DAC %s\n", dac_names[ind]));
LOG(logDEBUG1, ("Setting dac[%d - %s]: %d %s \n", (int)ind, dac_names[ind],
val, (mV ? "mV" : "dac units")));
int dacval = val;
#ifdef VIRTUAL
LOG(logINFO, ("Setting dac[%d - %s]: %d %s \n", (int)ind, dac_names[ind],
val, (mV ? "mV" : "dac units")));
if (!mV) {
dacValues[ind] = val;
}
@ -994,6 +980,7 @@ void setDAC(enum DACINDEX ind, int val, int mV) {
dacValues[ind] = dacval;
}
#else
LOG(logINFO, ("Setting DAC %s\n", dac_names[ind]));
if (LTC2620_SetDACValue((int)ind, val, mV, &dacval) == OK) {
dacValues[ind] = dacval;
if (ind == J_VREF_COMP &&
@ -1006,6 +993,12 @@ void setDAC(enum DACINDEX ind, int val, int mV) {
}
}
#endif
const int specialDacs[NSPECIALDACS] = SPECIALDACINDEX;
for (int i = 0; i < NSPECIALDACS; ++i) {
if ((int)ind == specialDacs[i]) {
validateSettings();
}
}
}
int getDAC(enum DACINDEX ind, int mV) {

View File

@ -62,6 +62,15 @@ enum DACINDEX {
480, /* J_VREF_DS */ \
420 /* J_VREF_COMP */ \
};
#define NUMSETTINGS (2)
#define NSPECIALDACS (3)
#define SPECIALDACINDEX {J_VB_COMP, J_VREF_DS, J_VREF_COMP};
#define SPECIAL_DEFAULT_DYNAMIC_GAIN_VALS \
{ 1000, 500, 400 }
#define SPECIAL_DEFAULT_DYNAMICHG0_GAIN_VALS \
{ 1500, 550, 450 }
enum NETWORKINDEX { TXN_FRAME, FLOWCTRL_10G };
enum CLKINDEX { RUN_CLK, ADC_CLK, DBIT_CLK, NUM_CLOCKS };
#define CLK_NAMES "run", "adc", "dbit"

View File

@ -294,7 +294,7 @@ int getAllTrimbits();
#ifndef CHIPTESTBOARDD
enum detectorSettings setSettings(enum detectorSettings sett);
#endif
#ifdef MYTHEN3D
#if defined(MYTHEN3D) || defined(JUNGFRAUD)
void validateSettings();
#endif
enum detectorSettings getSettings();

View File

@ -1537,10 +1537,6 @@ int set_module(int file_des) {
#ifdef JUNGFRAUD
case DYNAMICGAIN:
case DYNAMICHG0:
case FIXGAIN1:
case FIXGAIN2:
case FORCESWITCHG1:
case FORCESWITCHG2:
#elif GOTTHARDD
case DYNAMICGAIN:
case HIGHGAIN:
@ -1592,10 +1588,6 @@ int set_settings(int file_des) {
#ifdef JUNGFRAUD
case DYNAMICGAIN:
case DYNAMICHG0:
case FIXGAIN1:
case FIXGAIN2:
case FORCESWITCHG1:
case FORCESWITCHG2:
#elif GOTTHARDD
case DYNAMICGAIN:
case HIGHGAIN:

View File

@ -113,8 +113,7 @@ class Detector {
/** [Jungfrau][Gotthard][Gotthard2][Mythen3] */
Result<defs::detectorSettings> getSettings(Positions pos = {}) const;
/** [Jungfrau] DYNAMICGAIN, DYNAMICHG0, FIXGAIN1, FIXGAIN2,
* FORCESWITCHG1, FORCESWITCHG2 \n [Gotthard] DYNAMICGAIN, HIGHGAIN,
/** [Jungfrau] DYNAMICGAIN, DYNAMICHG0 \n [Gotthard] DYNAMICGAIN, HIGHGAIN,
* LOWGAIN, MEDIUMGAIN, VERYHIGHGAIN \n [Gotthard2] DYNAMICGAIN,
* FIXGAIN1, FIXGAIN2 \n [Moench] G1_HIGHGAIN, G1_LOWGAIN,
* G2_HIGHCAP_HIGHGAIN, G2_HIGHCAP_LOWGAIN, G2_LOWCAP_HIGHGAIN,

View File

@ -1201,8 +1201,7 @@ class CmdProxy {
"verylowgain, g1_hg, g1_lg, g2_hc_hg, g2_hc_lg, "
"g2_lc_hg, g2_lc_lg, g4_hg, g4_lg]"
"\n\t Detector Settings"
"\n\t[Jungfrau] - [dynamicgain | dynamichg0 | fixgain1 | "
"fixgain2 | forceswitchg1 | forceswitchg2]"
"\n\t[Jungfrau] - [dynamicgain | dynamichg0]"
"\n\t[Gotthard] - [dynamicgain | highgain | lowgain | "
"mediumgain | veryhighgain]"
"\n\t[Gotthard2] - [dynamicgain | fixgain1 | fixgain2]"

View File

@ -158,9 +158,8 @@ std::vector<defs::detectorSettings> Detector::getSettingsList() const {
defs::HIGHGAIN, defs::DYNAMICGAIN, defs::LOWGAIN, defs::MEDIUMGAIN,
defs::VERYHIGHGAIN};
case defs::JUNGFRAU:
return std::vector<defs::detectorSettings>{
defs::DYNAMICGAIN, defs::DYNAMICHG0, defs::FIXGAIN1,
defs::FIXGAIN2, defs::FORCESWITCHG1, defs::FORCESWITCHG2};
return std::vector<defs::detectorSettings>{defs::DYNAMICGAIN,
defs::DYNAMICHG0};
case defs::GOTTHARD2:
return std::vector<defs::detectorSettings>{
defs::DYNAMICGAIN, defs::DYNAMICHG0, defs::FIXGAIN1,

View File

@ -142,15 +142,34 @@ TEST_CASE("settings", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
std::vector<std::string> allSett;
allSett.push_back("standard");
allSett.push_back("fast");
allSett.push_back("highgain");
allSett.push_back("dynamicgain");
allSett.push_back("lowgain");
allSett.push_back("mediumgain");
allSett.push_back("veryhighgain");
allSett.push_back("dynamichg0");
allSett.push_back("fixgain1");
allSett.push_back("fixgain2");
allSett.push_back("verylowgain");
allSett.push_back("g1_hg");
allSett.push_back("g1_lg");
allSett.push_back("g2_hc_hg");
allSett.push_back("g2_hc_lg");
allSett.push_back("g2_lc_hg");
allSett.push_back("g2_lc_lg");
allSett.push_back("g4_hg");
allSett.push_back("g4_lg");
allSett.push_back("forceswitchg1");
allSett.push_back("forceswitchg2");
std::vector<std::string> sett;
switch (det_type) {
case defs::JUNGFRAU:
sett.push_back("dynamicgain");
sett.push_back("dynamichg0");
sett.push_back("fixgain1");
sett.push_back("fixgain2");
sett.push_back("forceswitchg1");
sett.push_back("forceswitchg2");
break;
case defs::GOTTHARD:
sett.push_back("highgain");
@ -203,10 +222,9 @@ TEST_CASE("settings", "[.cmd]") {
REQUIRE(oss.str() == "settings " + it + "\n");
}
}
for (int i = 0; i != det.size(); ++i) {
if (prev_val[i] != defs::UNDEFINED &&
prev_val[i] != defs::UNINITIALIZED) {
det.setSettings(prev_val[i], {i});
for (auto &it : allSett) {
if (std::find(sett.begin(), sett.end(), it) == sett.end()) {
REQUIRE_THROWS(proxy.Call("settings", {it}, -1, PUT));
}
}
}

View File

@ -348,8 +348,6 @@ typedef struct {
DYNAMICHG0,
FIXGAIN1,
FIXGAIN2,
FORCESWITCHG1,
FORCESWITCHG2,
VERYLOWGAIN,
G1_HIGHGAIN,
G1_LOWGAIN,

View File

@ -9,4 +9,4 @@
#define APIMYTHEN3 0x210727
#define APIMOENCH 0x210727
#define APIEIGER 0x210727
#define APIJUNGFRAU 0x210727
#define APIJUNGFRAU 0x210729

View File

@ -176,10 +176,6 @@ std::string ToString(const defs::detectorSettings s) {
return std::string("fixgain1");
case defs::FIXGAIN2:
return std::string("fixgain2");
case defs::FORCESWITCHG1:
return std::string("forceswitchg1");
case defs::FORCESWITCHG2:
return std::string("forceswitchg2");
case defs::VERYLOWGAIN:
return std::string("verylowgain");
case defs::G1_HIGHGAIN:
@ -624,10 +620,6 @@ template <> defs::detectorSettings StringTo(const std::string &s) {
return defs::FIXGAIN1;
if (s == "fixgain2")
return defs::FIXGAIN2;
if (s == "forceswitchg1")
return defs::FORCESWITCHG1;
if (s == "forceswitchg2")
return defs::FORCESWITCHG2;
if (s == "verylowgain")
return defs::VERYLOWGAIN;
if (s == "g1_hg")