diff --git a/python/scripts/test_virtual.py b/python/scripts/test_virtual.py index f5dc302cd..eec0da90b 100644 --- a/python/scripts/test_virtual.py +++ b/python/scripts/test_virtual.py @@ -101,11 +101,11 @@ def test_module_size(virtual_jf_detectors): def test_settings(virtual_jf_detectors): d = ExperimentalDetector() - assert d.settings == detectorSettings.DYNAMICGAIN + assert d.settings == detectorSettings.GAIN0 gain_list = [ - detectorSettings.DYNAMICHG0, - detectorSettings.DYNAMICGAIN, + detectorSettings.GAIN0, + detectorSettings.HIGHGAIN0, ] # Set all viable gain for Jungfrau to make sure nothing is crashing @@ -113,14 +113,14 @@ def test_settings(virtual_jf_detectors): d.settings = gain assert d.settings == gain - d.setSettings(detectorSettings.DYNAMICGAIN, [1]) + d.setSettings(detectorSettings.GAIN0, [1]) assert d.settings == [ - detectorSettings.DYNAMICHG0, - detectorSettings.DYNAMICGAIN, + detectorSettings.GAIN0, + detectorSettings.HIGHGAIN0, ] - d.settings = detectorSettings.DYNAMICGAIN - assert d.settings == detectorSettings.DYNAMICGAIN + d.settings = detectorSettings.GAIN0 + assert d.settings == detectorSettings.GAIN0 def test_frames(virtual_jf_detectors): d = ExperimentalDetector() @@ -161,9 +161,12 @@ def test_gainmode(virtual_jf_detectors): assert d.gainMode == gainMode.NORMAL_GAIN_MODE gain_list = [ - gainMode.NORMAL_GAIN_MODE, + gainMode.DYNAMIC_GAIN_MODE, gainMode.FORCE_SWITCH_G1, gainMode.FORCE_SWITCH_G2, + gainMode.FIX_G1, + gainMode.FIX_G2, + gainMode.FIX_G0 ] # Set all viable gain for Jungfrau to make sure nothing is crashing @@ -173,9 +176,12 @@ def test_gainmode(virtual_jf_detectors): d.setGainMode(gainMode.FORCE_SWITCH_G1, [1]) assert d.gainMode == [ - gainMode.NORMAL_GAIN_MODE, + gainMode.DYNAMIC_GAIN_MODE, gainMode.FORCE_SWITCH_G1, gainMode.FORCE_SWITCH_G2, + gainMode.FIX_G1, + gainMode.FIX_G2, + gainMode.FIX_G0 ] d.gainMode = gainMode.FORCE_SWITCH_G1 diff --git a/python/slsdet/detector.py b/python/slsdet/detector.py index b47699d11..383c2265c 100755 --- a/python/slsdet/detector.py +++ b/python/slsdet/detector.py @@ -311,7 +311,7 @@ class Detector(CppDetectorApi): ----- [Eiger] Use threshold command to load settings - [Jungfrau] DYNAMICGAIN, DYNAMICHG0 \n + [Jungfrau] GAIN0, HIGHGAIN0 \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 @@ -2201,8 +2201,8 @@ class Detector(CppDetectorApi): [Jungfrau] Detector gain mode. Enum: gainMode Note ----- - - [Jungfrau] NORMAL_GAIN_MODE, FORCE_SWITCH_G1, FORCE_SWITCH_G2 + [Jungfrau] DYNAMIC_GAIN_MODE, FORCE_SWITCH_G1, FORCE_SWITCH_G2, FIX_G1, FIX_G2, FIX_G0 \n + CAUTION: Do not use FIX_G0 without caution, you can damage the detector!!! """ return element_if_equal(self.getGainMode()) diff --git a/python/src/enums.cpp b/python/src/enums.cpp index 851779b13..f3d381a51 100644 --- a/python/src/enums.cpp +++ b/python/src/enums.cpp @@ -210,7 +210,7 @@ void init_enums(py::module &m) { .value("LOWGAIN", slsDetectorDefs::detectorSettings::LOWGAIN) .value("MEDIUMGAIN", slsDetectorDefs::detectorSettings::MEDIUMGAIN) .value("VERYHIGHGAIN", slsDetectorDefs::detectorSettings::VERYHIGHGAIN) - .value("DYNAMICHG0", slsDetectorDefs::detectorSettings::DYNAMICHG0) + .value("HIGHGAIN0", slsDetectorDefs::detectorSettings::HIGHGAIN0) .value("FIXGAIN1", slsDetectorDefs::detectorSettings::FIXGAIN1) .value("FIXGAIN2", slsDetectorDefs::detectorSettings::FIXGAIN2) .value("VERYLOWGAIN", slsDetectorDefs::detectorSettings::VERYLOWGAIN) @@ -226,6 +226,7 @@ void init_enums(py::module &m) { slsDetectorDefs::detectorSettings::G2_LOWCAP_LOWGAIN) .value("G4_HIGHGAIN", slsDetectorDefs::detectorSettings::G4_HIGHGAIN) .value("G4_LOWGAIN", slsDetectorDefs::detectorSettings::G4_LOWGAIN) + .value("GAIN0", slsDetectorDefs::detectorSettings::GAIN0) .value("UNDEFINED", slsDetectorDefs::detectorSettings::UNDEFINED) .value("UNINITIALIZED", slsDetectorDefs::detectorSettings::UNINITIALIZED) @@ -307,8 +308,11 @@ void init_enums(py::module &m) { .export_values(); py::enum_(Defs, "gainMode") - .value("NORMAL_GAIN_MODE", slsDetectorDefs::gainMode::NORMAL_GAIN_MODE) + .value("DYNAMIC_GAIN_MODE", slsDetectorDefs::gainMode::DYNAMIC_GAIN_MODE) .value("FORCE_SWITCH_G1", slsDetectorDefs::gainMode::FORCE_SWITCH_G1) .value("FORCE_SWITCH_G2", slsDetectorDefs::gainMode::FORCE_SWITCH_G2) + .value("FIX_G1", slsDetectorDefs::gainMode::FIX_G1) + .value("FIX_G2", slsDetectorDefs::gainMode::FIX_G2) + .value("FIX_G0", slsDetectorDefs::gainMode::FIX_G0) .export_values(); } diff --git a/slsDetectorGui/forms/form_tab_settings.ui b/slsDetectorGui/forms/form_tab_settings.ui index a466a1ffb..32890e2d0 100755 --- a/slsDetectorGui/forms/form_tab_settings.ui +++ b/slsDetectorGui/forms/form_tab_settings.ui @@ -7,7 +7,7 @@ 0 0 775 - 345 + 380 @@ -32,7 +32,7 @@ Form - + false @@ -51,7 +51,7 @@ - + false @@ -70,7 +70,7 @@ - + false @@ -109,7 +109,7 @@ - + false @@ -146,7 +146,7 @@ - + false @@ -183,7 +183,7 @@ - + false @@ -205,7 +205,7 @@ - + Qt::Vertical @@ -221,7 +221,7 @@ - + true @@ -334,7 +334,7 @@ - + false @@ -356,7 +356,7 @@ - + false @@ -393,7 +393,7 @@ - + Qt::Horizontal @@ -409,7 +409,7 @@ - + false @@ -431,7 +431,7 @@ - + false @@ -514,7 +514,7 @@ - Dynamic HG0 + High Gain 0 @@ -572,6 +572,11 @@ G4_LG + + + Gain 0 + + Undefined @@ -584,6 +589,86 @@ + + + + false + + + + 110 + 0 + + + + + 110 + 16777215 + + + + Gain Mode: + + + + + + + false + + + + 0 + 0 + + + + + 140 + 25 + + + + + 140 + 16777215 + + + + <html><head/><body><p>Gain Mode of the detector</p><p> #gainmode#</p><p><br/></p><p>Fix G0 is to be used with utmost caution. Can damage the detector!</p></body></html> + + + + Dynamic Gain + + + + + Force Switch G1 + + + + + Force Switch G2 + + + + + Fix G1 + + + + + Fix G2 + + + + + Fix G0 + + + + diff --git a/slsDetectorGui/include/qTabSettings.h b/slsDetectorGui/include/qTabSettings.h index 988da3eeb..927cd8436 100644 --- a/slsDetectorGui/include/qTabSettings.h +++ b/slsDetectorGui/include/qTabSettings.h @@ -10,9 +10,12 @@ class qTabSettings : public QWidget, private Ui::TabSettingsObject { qTabSettings(QWidget *parent, sls::Detector *detector); ~qTabSettings(); void Refresh(); + public slots: + void SetExportMode(bool exportMode); private slots: void SetSettings(int index); + void SetGainMode(int index); void SetDynamicRange(int index); void SetThresholdEnergy(int index); void SetThresholdEnergies(); @@ -21,9 +24,12 @@ class qTabSettings : public QWidget, private Ui::TabSettingsObject { private: void SetupWidgetWindow(); void SetupDetectorSettings(); + void SetupGainMode(); + void ShowFixG0(bool expertMode); void Initialization(); void GetSettings(); + void GetGainMode(); void GetDynamicRange(); void GetThresholdEnergy(); void GetThresholdEnergies(); @@ -40,7 +46,7 @@ class qTabSettings : public QWidget, private Ui::TabSettingsObject { LOWGAIN, MEDIUMGAIN, VERYHIGHGAIN, - DYNAMICHG0, + HIGHGAIN0, FIXGAIN1, FIXGAIN2, VERLOWGAIN, @@ -52,9 +58,21 @@ class qTabSettings : public QWidget, private Ui::TabSettingsObject { G2_LOWCAP_LOWGAIN, G4_HIGHGAIN, G4_LOWGAIN, + GAIN0, UNDEFINED, UNINITIALIZED, NUMSETTINGS }; + + enum { + DYNAMIC_GAIN_MODE, + FORCE_SWITCH_G1, + FORCE_SWITCH_G2, + FIX_G1, + FIX_G2, + FIX_G0 + }; + bool isVisibleFixG0{false}; + enum { DYNAMICRANGE_32, DYNAMICRANGE_16, DYNAMICRANGE_8, DYNAMICRANGE_4 }; }; diff --git a/slsDetectorGui/src/qDetectorMain.cpp b/slsDetectorGui/src/qDetectorMain.cpp index 2ca2c1291..634def39e 100644 --- a/slsDetectorGui/src/qDetectorMain.cpp +++ b/slsDetectorGui/src/qDetectorMain.cpp @@ -340,6 +340,7 @@ void qDetectorMain::EnableModes(QAction *action) { actionLoadTrimbits->setVisible(enable && (detType == slsDetectorDefs::EIGER || detType == slsDetectorDefs::MYTHEN3)); + tabSettings->SetExportMode(enable); LOG(logINFO) << "Expert Mode: " << qDefs::stringEnable(enable); } diff --git a/slsDetectorGui/src/qTabSettings.cpp b/slsDetectorGui/src/qTabSettings.cpp index 33234fe96..0181667b7 100644 --- a/slsDetectorGui/src/qTabSettings.cpp +++ b/slsDetectorGui/src/qTabSettings.cpp @@ -71,6 +71,9 @@ void qTabSettings::SetupWidgetWindow() { comboDynamicRange->setEnabled(true); lblThreshold->setEnabled(true); spinThreshold->setEnabled(true); + } else if (detType == slsDetectorDefs::JUNGFRAU) { + lblGainMode->setEnabled(true); + comboGainMode->setEnabled(true); } // default settings for the disabled @@ -83,19 +86,35 @@ void qTabSettings::SetupWidgetWindow() { spinThreshold2->setValue(-1); spinThreshold3->setValue(-1); } + + // default for gain mode + if (comboGainMode->isEnabled()) { + SetupGainMode(); + } + Initialization(); // default for the disabled GetDynamicRange(); Refresh(); } +void qTabSettings::SetExportMode(bool exportMode) { + if (comboGainMode->isVisible()) { + ShowFixG0(exportMode); + } +} + void qTabSettings::SetupDetectorSettings() { + comboSettings->setCurrentIndex(UNINITIALIZED); + + // enable only those available to detector QStandardItemModel *model = qobject_cast(comboSettings->model()); + const int numSettings = comboSettings->count(); if (model) { - QModelIndex index[NUMSETTINGS]; - QStandardItem *item[NUMSETTINGS]; - for (int i = 0; i < NUMSETTINGS; ++i) { + std::vector index(numSettings); + std::vector item(numSettings); + for (size_t i = 0; i < index.size(); ++i) { index[i] = model->index(i, comboSettings->modelColumn(), comboSettings->rootModelIndex()); item[i] = model->itemFromIndex(index[i]); @@ -112,11 +131,38 @@ void qTabSettings::SetupDetectorSettings() { } } +void qTabSettings::SetupGainMode() { + comboGainMode->setCurrentIndex(DYNAMIC_GAIN_MODE); + ShowFixG0(false); +} + +void qTabSettings::ShowFixG0(bool expertMode) { + LOG(logINFO) << (expertMode ? "Showing" : "Hiding") << " FIX_G0"; + + // enable.disable Fix G0 + QStandardItemModel *model = + qobject_cast(comboGainMode->model()); + const int numSettings = comboGainMode->count(); + if (model) { + std::vector index(numSettings); + std::vector item(numSettings); + index[FIX_G0] = model->index(FIX_G0, comboGainMode->modelColumn(), + comboGainMode->rootModelIndex()); + item[FIX_G0] = model->itemFromIndex(index[FIX_G0]); + item[FIX_G0]->setEnabled(expertMode); + } + isVisibleFixG0 = expertMode; +} + void qTabSettings::Initialization() { // Settings if (comboSettings->isEnabled()) connect(comboSettings, SIGNAL(currentIndexChanged(int)), this, SLOT(SetSettings(int))); + // Gain mode + if (comboGainMode->isEnabled()) + connect(comboGainMode, SIGNAL(currentIndexChanged(int)), this, + SLOT(SetGainMode(int))); // Dynamic Range if (comboDynamicRange->isEnabled()) @@ -160,7 +206,7 @@ void qTabSettings::GetSettings() { comboSettings->setCurrentIndex(UNINITIALIZED); break; default: - if ((int)retval < -1 || (int)retval >= NUMSETTINGS) { + if ((int)retval < -1 || (int)retval >= comboSettings->count()) { throw sls::RuntimeError(std::string("Unknown settings: ") + std::to_string(retval)); } @@ -188,6 +234,60 @@ void qTabSettings::SetSettings(int index) { } } +void qTabSettings::GetGainMode() { + LOG(logDEBUG) << "Getting gain mode"; + disconnect(comboGainMode, SIGNAL(currentIndexChanged(int)), this, + SLOT(SetGainMode(int))); + try { + auto retval = det->getGainMode().tsquash( + "Inconsistent gain mode for all detectors."); + if ((int)retval < 0 || (int)retval >= comboGainMode->count()) { + throw sls::RuntimeError(std::string("Unknown gain mode: ") + + std::to_string(retval)); + } + // warning when using fix_g0 and not in export mode + if ((int)retval == FIX_G0 && !isVisibleFixG0) { + std::string message = + "You are not in Expert Mode and Gain Mode is in FIX_G0. " + "
Could damage the detector when used without " + "caution! "; + qDefs::Message(qDefs::WARNING, message, + "qTabSettings::GetGainMode"); + LOG(logWARNING) << message; + } + comboGainMode->setCurrentIndex((int)retval); + } + CATCH_DISPLAY("Could not get gain mode.", "qTabSettings::GetGainMode") + connect(comboGainMode, SIGNAL(currentIndexChanged(int)), this, + SLOT(SetGainMode(int))); +} + +void qTabSettings::SetGainMode(int index) { + // warning for fix_G0 even in export mode + if (index == FIX_G0) { + if (qDefs::Message( + qDefs::QUESTION, + "You are in Export mode, " + "
but setting Gain Mode to FIX_G0 could " + "damage the detector!
Proceed and set " + "gainmode to FIX_G0 anyway?", + "qTabSettings::SetGainMode") == slsDetectorDefs::FAIL) { + GetGainMode(); + return; + } + } + + LOG(logINFO) << "Setting Gain Mode to " + << comboGainMode->currentText().toAscii().data(); + auto val = static_cast(index); + try { + + det->setGainMode(val); + } + CATCH_HANDLE("Could not set gain mode.", "qTabSettings::SetGainMode", this, + &qTabSettings::GetGainMode) +} + void qTabSettings::GetDynamicRange() { LOG(logDEBUG) << "Getting dynamic range"; disconnect(comboDynamicRange, SIGNAL(activated(int)), this, @@ -360,6 +460,10 @@ void qTabSettings::Refresh() { GetSettings(); } + if (comboGainMode->isEnabled()) { + GetGainMode(); + } + if (comboDynamicRange->isEnabled()) { GetDynamicRange(); } diff --git a/slsDetectorServers/jungfrauDetectorServer/RegisterDefs.h b/slsDetectorServers/jungfrauDetectorServer/RegisterDefs.h index 2eff513e6..5ea830d1b 100644 --- a/slsDetectorServers/jungfrauDetectorServer/RegisterDefs.h +++ b/slsDetectorServers/jungfrauDetectorServer/RegisterDefs.h @@ -351,6 +351,7 @@ #define DAQ_CRRNT_SRC_CLMN_FIX_MSK (0x00000001 << DAQ_CRRNT_SRC_CLMN_FIX_OFST) #define DAQ_CRRNT_SRC_CLMN_SLCT_OFST (20) #define DAQ_CRRNT_SRC_CLMN_SLCT_MSK (0x0000003F << DAQ_CRRNT_SRC_CLMN_SLCT_OFST) +#define DAQ_GAIN_MODE_MASK (DAQ_FRCE_SWTCH_GAIN_MSK | DAQ_FIX_GAIN_MSK | DAQ_CMP_RST_MSK) /** Chip Power Register */ #define CHIP_POWER_REG (0x5E << MEM_MAP_SHIFT) diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c index d03e8a9f5..0665f053e 100644 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorFunctionList.c @@ -451,6 +451,7 @@ void setupDetector() { // Initialization of acquistion parameters setSettings(DEFAULT_SETTINGS); + setGainMode(DEFAULT_GAINMODE); setNumFrames(DEFAULT_NUM_FRAMES); setNumTriggers(DEFAULT_NUM_CYCLES); @@ -507,10 +508,10 @@ int resetToDefaultDacs(int hardReset) { // special dac: replace default value if (specialDacs[j] == i) { switch (oldSettings) { - case DYNAMICGAIN: + case GAIN0: value = defaultDacValue_G0[j]; break; - case DYNAMICHG0: + case HIGHGAIN0: value = defaultDacValue_HG0[j]; break; default: @@ -541,10 +542,10 @@ int getDefaultDac(enum DACINDEX index, enum detectorSettings sett, for (int i = 0; i < NSPECIALDACS; ++i) { if ((int)index == specialDacs[i]) { switch (sett) { - case DYNAMICGAIN: + case GAIN0: *retval = defaultDacValue_G0[i]; return OK; - case DYNAMICHG0: + case HIGHGAIN0: *retval = defaultDacValue_HG0[i]; return OK; // unknown settings @@ -573,15 +574,14 @@ int setDefaultDac(enum DACINDEX index, enum detectorSettings sett, int value) { for (int i = 0; i < NSPECIALDACS; ++i) { if ((int)index == specialDacs[i]) { switch (sett) { - case DYNAMICGAIN: - LOG(logINFO, - ("Setting Default Dac [%d - %s, dynamicgain]: %d\n", - (int)index, dac_names[index], value)); + case GAIN0: + LOG(logINFO, ("Setting Default Dac [%d - %s, gain0]: %d\n", + (int)index, dac_names[index], value)); defaultDacValue_G0[i] = value; return OK; - case DYNAMICHG0: + case HIGHGAIN0: LOG(logINFO, - ("Setting Default Dac [%d - %s, dynamichg0]: %d\n", + ("Setting Default Dac [%d - %s, highgain0]: %d\n", (int)index, dac_names[index], value)); defaultDacValue_HG0[i] = value; return OK; @@ -793,6 +793,11 @@ int selectStoragecellStart(int pos) { LOG(logINFO, ("Setting storage cell start: %d\n", pos)); bus_w(addr, bus_r(addr) & ~mask); bus_w(addr, bus_r(addr) | ((value << offset) & mask)); + // should not do a get to verify (status register does not update + // immediately during acquisition) + if (getChipVersion() == 11) { + return pos; + } } // read value back @@ -1045,16 +1050,16 @@ enum detectorSettings setSettings(enum detectorSettings sett) { int *dacVals = NULL; // set settings switch (sett) { - case DYNAMICGAIN: + case GAIN0: bus_w(DAQ_REG, bus_r(DAQ_REG) & ~DAQ_HIGH_GAIN_MSK); LOG(logINFO, - ("Set settings - Dyanmic Gain [DAQ Reg:0x%x]\n", bus_r(DAQ_REG))); + ("Set settings - Gain 0 [DAQ Reg:0x%x]\n", bus_r(DAQ_REG))); dacVals = defaultDacValue_G0; break; - case DYNAMICHG0: + case HIGHGAIN0: bus_w(DAQ_REG, bus_r(DAQ_REG) | DAQ_HIGH_GAIN_MSK); - LOG(logINFO, ("Set settings - Dyanmic High Gain 0 [DAQ Reg:0x%x]\n", - bus_r(DAQ_REG))); + LOG(logINFO, + ("Set settings - High Gain 0 [DAQ Reg:0x%x]\n", bus_r(DAQ_REG))); dacVals = defaultDacValue_HG0; break; default: @@ -1075,61 +1080,56 @@ enum detectorSettings setSettings(enum detectorSettings sett) { configureChip(); } - return thisSettings; + return getSettings(); } -void validateSettings() { - // if any special dac value is changed individually => undefined - const int specialDacs[NSPECIALDACS] = SPECIALDACINDEX; - int *specialDacValues[] = {defaultDacValue_G0, defaultDacValue_HG0}; - int settList[] = {DYNAMICGAIN, DYNAMICHG0}; - enum detectorSettings sett = UNDEFINED; - for (int isett = 0; isett != NUMSETTINGS; ++isett) { - - // assume it matches current setting in list - sett = settList[isett]; - // if one value does not match, = undefined - for (int i = 0; i < NSPECIALDACS; ++i) { - if (getDAC(specialDacs[i], 0) != specialDacValues[isett][i]) { - sett = UNDEFINED; - break; - } - } - - // all values matchd a setting - if (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() { + if (bus_r(DAQ_REG) & DAQ_HIGH_GAIN_MSK) + return HIGHGAIN0; + return GAIN0; } -enum detectorSettings getSettings() { return thisSettings; } - enum gainMode getGainMode() { - uint32_t retval = bus_r(DAQ_REG) & DAQ_FRCE_SWTCH_GAIN_MSK; + uint32_t regval = bus_r(DAQ_REG); + uint32_t retval_force = regval & DAQ_FRCE_SWTCH_GAIN_MSK; + uint32_t retval_fix = regval & DAQ_FIX_GAIN_MSK; + uint32_t retval_cmp_rst = regval & DAQ_CMP_RST_MSK; - switch (retval) { - case DAQ_FRCE_GAIN_STG_0_VAL: - return NORMAL_GAIN_MODE; + // only one set should be valid + if ((retval_force && retval_fix) || (retval_fix && retval_cmp_rst) || + (retval_force && retval_cmp_rst)) { + LOG(logERROR, ("undefined gain mode. DAQ reg: 0x%x\n", regval)); + } + + // dynamic gain, when nothing is set + if (retval_force == 0 && retval_fix == 0 && retval_cmp_rst == 0) { + return DYNAMIC_GAIN_MODE; + } + + switch (retval_force) { case DAQ_FRCE_GAIN_STG_1_VAL: return FORCE_SWITCH_G1; case DAQ_FRCE_GAIN_STG_2_VAL: return FORCE_SWITCH_G2; default: - LOG(logERROR, ("This gain mode %d is not defined [DAQ reg: %d]\n", - (retval << DAQ_FRCE_SWTCH_GAIN_OFST), retval)); - return -1; + break; } + + switch (retval_fix) { + case DAQ_FIX_GAIN_STG_1_VAL: + return FIX_G1; + case DAQ_FIX_GAIN_STG_2_VAL: + return FIX_G2; + default: + break; + } + + if (retval_cmp_rst) { + return FIX_G0; + } + + LOG(logERROR, ("This gain mode is undefined [DAQ reg: %d]\n", regval)); + return -1; } void setGainMode(enum gainMode mode) { @@ -1137,26 +1137,47 @@ void setGainMode(enum gainMode mode) { uint32_t value = bus_r(addr); switch (mode) { - case NORMAL_GAIN_MODE: - value &= ~(DAQ_FRCE_SWTCH_GAIN_MSK); + case DYNAMIC_GAIN_MODE: + value &= ~(DAQ_GAIN_MODE_MASK); bus_w(addr, value); - LOG(logINFO, ("Set gain mode - Normal Gain Mode [DAQ Reg:0x%x]\n", - bus_r(DAQ_REG))); + LOG(logINFO, + ("Set gain mode - Dynamic Gain [DAQ Reg:0x%x]\n", bus_r(DAQ_REG))); break; case FORCE_SWITCH_G1: - value &= ~(DAQ_FRCE_SWTCH_GAIN_MSK); + value &= ~(DAQ_GAIN_MODE_MASK); value |= DAQ_FRCE_GAIN_STG_1_VAL; bus_w(addr, value); LOG(logINFO, ("Set gain mode - Force Switch G1 [DAQ Reg:0x%x]\n", bus_r(DAQ_REG))); break; case FORCE_SWITCH_G2: - value &= ~(DAQ_FRCE_SWTCH_GAIN_MSK); + value &= ~(DAQ_GAIN_MODE_MASK); value |= DAQ_FRCE_GAIN_STG_2_VAL; bus_w(addr, value); LOG(logINFO, ("Set gain mode - Force Switch G2 [DAQ Reg:0x%x]\n", bus_r(DAQ_REG))); break; + case FIX_G1: + value &= ~(DAQ_GAIN_MODE_MASK); + value |= DAQ_FIX_GAIN_STG_1_VAL; + bus_w(addr, value); + LOG(logINFO, + ("Set gain mode - Fix G1 [DAQ Reg:0x%x]\n", bus_r(DAQ_REG))); + break; + case FIX_G2: + value &= ~(DAQ_GAIN_MODE_MASK); + value |= DAQ_FIX_GAIN_STG_2_VAL; + bus_w(addr, value); + LOG(logINFO, + ("Set gain mode - Fix G2 [DAQ Reg:0x%x]\n", bus_r(DAQ_REG))); + break; + case FIX_G0: + value &= ~(DAQ_GAIN_MODE_MASK); + value |= DAQ_CMP_RST_MSK; + bus_w(addr, value); + LOG(logINFO, + ("Set gain mode - Fix G0 [DAQ Reg:0x%x]\n", bus_r(DAQ_REG))); + break; default: LOG(logERROR, ("This gain mode %d is not defined\n", (int)mode)); } @@ -1193,12 +1214,6 @@ 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) { diff --git a/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer_defs.h b/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer_defs.h index 9182ef65d..6f222b746 100644 --- a/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer_defs.h +++ b/slsDetectorServers/jungfrauDetectorServer/slsDetectorServer_defs.h @@ -97,7 +97,8 @@ enum CLKINDEX { RUN_CLK, ADC_CLK, DBIT_CLK, NUM_CLOCKS }; #define DEFAULT_DELAY (0) #define DEFAULT_HIGH_VOLTAGE (0) #define DEFAULT_TIMING_MODE (AUTO_TIMING) -#define DEFAULT_SETTINGS (DYNAMICGAIN) +#define DEFAULT_SETTINGS (GAIN0) +#define DEFAULT_GAINMODE (DYNAMIC_GAIN_MODE) #define DEFAULT_TX_UDP_PORT (0x7e9a) #define DEFAULT_TMP_THRSHLD (65 * 1000) // milli degree Celsius #define DEFAULT_NUM_STRG_CLLS (0) diff --git a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h index de06ff9ff..95a1c2249 100644 --- a/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h +++ b/slsDetectorServers/slsDetectorServer/include/slsDetectorFunctionList.h @@ -297,9 +297,6 @@ int getAllTrimbits(); #ifndef CHIPTESTBOARDD enum detectorSettings setSettings(enum detectorSettings sett); #endif -#if defined(MYTHEN3D) || defined(JUNGFRAUD) -void validateSettings(); -#endif enum detectorSettings getSettings(); #ifdef JUNGFRAUD enum gainMode getGainMode(); diff --git a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c index eb3887bfb..faa4b0ff4 100644 --- a/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c +++ b/slsDetectorServers/slsDetectorServer/src/slsDetectorServer_funcs.c @@ -1561,8 +1561,8 @@ void validate_settings(enum detectorSettings sett) { #ifdef EIGERD case STANDARD: #elif JUNGFRAUD - case DYNAMICGAIN: - case DYNAMICHG0: + case GAIN0: + case HIGHGAIN0: #elif GOTTHARDD case DYNAMICGAIN: case HIGHGAIN: @@ -8560,7 +8560,7 @@ int set_default_dac(int file_des) { int get_gain_mode(int file_des) { ret = OK; memset(mess, 0, sizeof(mess)); - enum gainMode retval = NORMAL_GAIN_MODE; + enum gainMode retval = DYNAMIC_GAIN_MODE; LOG(logDEBUG1, ("Getting gain mode\n")); #ifndef JUNGFRAUD @@ -8593,9 +8593,12 @@ int set_gain_mode(int file_des) { // only set if (Server_VerifyLock() == OK) { switch (gainmode) { - case NORMAL_GAIN_MODE: + case DYNAMIC_GAIN_MODE: case FORCE_SWITCH_G1: case FORCE_SWITCH_G2: + case FIX_G1: + case FIX_G2: + case FIX_G0: break; default: modeNotImplemented("Gain Mode Index", (int)gainmode); diff --git a/slsDetectorSoftware/include/sls/Detector.h b/slsDetectorSoftware/include/sls/Detector.h index 988f8b174..8ad4c5338 100644 --- a/slsDetectorSoftware/include/sls/Detector.h +++ b/slsDetectorSoftware/include/sls/Detector.h @@ -113,7 +113,7 @@ class Detector { /** [Jungfrau][Gotthard][Gotthard2][Mythen3] */ Result getSettings(Positions pos = {}) const; - /** [Jungfrau] DYNAMICGAIN, DYNAMICHG0 \n [Gotthard] DYNAMICGAIN, HIGHGAIN, + /** [Jungfrau] GAIN0, HIGHGAIN0 \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, @@ -1179,7 +1179,9 @@ class Detector { /** [Jungfrau]*/ Result getGainMode(Positions pos = {}) const; - /** [Jungfrau] Options: NORMAL_GAIN_MODE, FORCE_SWITCH_G1, FORCE_SWITCH_G2\n + /** [Jungfrau] Options: DYNAMIC_GAIN_MODE, FORCE_SWITCH_G1, FORCE_SWITCH_G2, + * FIX_G1, FIX_G2, FIX_G0 \n\CAUTION: Do not use FIX_G0 without caution, you + * can damage the detector!!!\n */ void setGainMode(const defs::gainMode mode, Positions pos = {}); diff --git a/slsDetectorSoftware/src/CmdProxy.h b/slsDetectorSoftware/src/CmdProxy.h index 106897719..f501a6f99 100644 --- a/slsDetectorSoftware/src/CmdProxy.h +++ b/slsDetectorSoftware/src/CmdProxy.h @@ -1203,12 +1203,12 @@ class CmdProxy { settings, getSettings, setSettings, sls::StringTo, "[standard, fast, highgain, dynamicgain, lowgain, " - "mediumgain, veryhighgain, dynamichg0, " + "mediumgain, veryhighgain, highgain0, " "fixgain1, fixgain2, forceswitchg1, forceswitchg2, " "verylowgain, g1_hg, g1_lg, g2_hc_hg, g2_hc_lg, " - "g2_lc_hg, g2_lc_lg, g4_hg, g4_lg]" + "g2_lc_hg, g2_lc_lg, g4_hg, g4_lg, gain0]" "\n\t Detector Settings" - "\n\t[Jungfrau] - [dynamicgain | dynamichg0]" + "\n\t[Jungfrau] - [ gain0 | highgain0]" "\n\t[Gotthard] - [dynamicgain | highgain | lowgain | " "mediumgain | veryhighgain]" "\n\t[Gotthard2] - [dynamicgain | fixgain1 | fixgain2]" @@ -1877,7 +1877,10 @@ class CmdProxy { INTEGER_COMMAND_VEC_ID( gainmode, getGainMode, setGainMode, sls::StringTo, - "[forceswitchg1, forceswitchg2]\n\t[Jungfrau] Gain mode."); + "[dynamicgain|forceswitchg1|forceswitchg2|fixg1|fixg2|fixg0]\n\t[" + "Jungfrau] Gain mode.\n\tCAUTION: Do not use fixg0 without caution, " + "you can " + "damage the detector!!!"); /* Gotthard Specific */ TIME_GET_COMMAND(exptimel, getExptimeLeft, diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index ddd7253f2..427950689 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -158,12 +158,11 @@ std::vector Detector::getSettingsList() const { defs::HIGHGAIN, defs::DYNAMICGAIN, defs::LOWGAIN, defs::MEDIUMGAIN, defs::VERYHIGHGAIN}; case defs::JUNGFRAU: - return std::vector{defs::DYNAMICGAIN, - defs::DYNAMICHG0}; + return std::vector{defs::GAIN0, + defs::HIGHGAIN0}; case defs::GOTTHARD2: return std::vector{ - defs::DYNAMICGAIN, defs::DYNAMICHG0, defs::FIXGAIN1, - defs::FIXGAIN2}; + defs::DYNAMICGAIN, defs::FIXGAIN1, defs::FIXGAIN2}; case defs::MOENCH: return std::vector{ defs::G1_HIGHGAIN, defs::G1_LOWGAIN, @@ -1494,9 +1493,12 @@ void Detector::setStorageCellDelay(ns value, Positions pos) { std::vector Detector::getGainModeList() const { switch (getDetectorType().squash()) { case defs::JUNGFRAU: - return std::vector{defs::NORMAL_GAIN_MODE, + return std::vector{defs::DYNAMIC_GAIN_MODE, defs::FORCE_SWITCH_G1, - defs::FORCE_SWITCH_G2}; + defs::FORCE_SWITCH_G2, + defs::FIX_G1, + defs::FIX_G2, + defs::FIX_G0}; break; default: throw RuntimeError("Gain mode is not implemented for this detector."); diff --git a/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp b/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp index 521b0faee..3fddd6f26 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy-jungfrau.cpp @@ -456,6 +456,11 @@ TEST_CASE("gainmode", "[.cmd]") { proxy.Call("gainmode", {}, -1, GET, oss); REQUIRE(oss.str() == "gainmode forceswitchg1\n"); } + { + std::ostringstream oss; + proxy.Call("gainmode", {"dynamicgain"}, -1, PUT, oss); + REQUIRE(oss.str() == "gainmode dynamicgain\n"); + } { std::ostringstream oss; proxy.Call("gainmode", {"forceswitchg2"}, -1, PUT, oss); @@ -463,8 +468,18 @@ TEST_CASE("gainmode", "[.cmd]") { } { std::ostringstream oss; - proxy.Call("gainmode", {"normal"}, -1, PUT, oss); - REQUIRE(oss.str() == "gainmode normal\n"); + proxy.Call("gainmode", {"fixg1"}, -1, PUT, oss); + REQUIRE(oss.str() == "gainmode fixg1\n"); + } + { + std::ostringstream oss; + proxy.Call("gainmode", {"fixg2"}, -1, PUT, oss); + REQUIRE(oss.str() == "gainmode fixg2\n"); + } + { + std::ostringstream oss; + proxy.Call("gainmode", {"fixg0"}, -1, PUT, oss); + REQUIRE(oss.str() == "gainmode fixg0\n"); } for (int i = 0; i != det.size(); ++i) { det.setGainMode(prev_val[i], {i}); diff --git a/slsDetectorSoftware/tests/test-CmdProxy.cpp b/slsDetectorSoftware/tests/test-CmdProxy.cpp index 9219b26b3..77b70a795 100644 --- a/slsDetectorSoftware/tests/test-CmdProxy.cpp +++ b/slsDetectorSoftware/tests/test-CmdProxy.cpp @@ -150,7 +150,7 @@ TEST_CASE("settings", "[.cmd]") { allSett.push_back("lowgain"); allSett.push_back("mediumgain"); allSett.push_back("veryhighgain"); - allSett.push_back("dynamichg0"); + allSett.push_back("highgain0"); allSett.push_back("fixgain1"); allSett.push_back("fixgain2"); allSett.push_back("verylowgain"); @@ -164,12 +164,13 @@ TEST_CASE("settings", "[.cmd]") { allSett.push_back("g4_lg"); allSett.push_back("forceswitchg1"); allSett.push_back("forceswitchg2"); + allSett.push_back("gain0"); std::vector sett; switch (det_type) { case defs::JUNGFRAU: - sett.push_back("dynamicgain"); - sett.push_back("dynamichg0"); + sett.push_back("gain0"); + sett.push_back("highgain0"); break; case defs::GOTTHARD: sett.push_back("highgain"); diff --git a/slsSupportLib/include/sls/sls_detector_defs.h b/slsSupportLib/include/sls/sls_detector_defs.h index b4ce1bf87..348b36648 100644 --- a/slsSupportLib/include/sls/sls_detector_defs.h +++ b/slsSupportLib/include/sls/sls_detector_defs.h @@ -345,7 +345,7 @@ typedef struct { LOWGAIN, MEDIUMGAIN, VERYHIGHGAIN, - DYNAMICHG0, + HIGHGAIN0, FIXGAIN1, FIXGAIN2, VERYLOWGAIN, @@ -357,6 +357,7 @@ typedef struct { G2_LOWCAP_LOWGAIN, G4_HIGHGAIN, G4_LOWGAIN, + GAIN0, UNDEFINED = 200, UNINITIALIZED }; @@ -414,7 +415,14 @@ typedef struct { enum vetoAlgorithm { DEFAULT_ALGORITHM }; - enum gainMode { NORMAL_GAIN_MODE, FORCE_SWITCH_G1, FORCE_SWITCH_G2 }; + enum gainMode { + DYNAMIC_GAIN_MODE, + FORCE_SWITCH_G1, + FORCE_SWITCH_G2, + FIX_G1, + FIX_G2, + FIX_G0 + }; #ifdef __cplusplus diff --git a/slsSupportLib/src/ToString.cpp b/slsSupportLib/src/ToString.cpp index 23882768a..2755f320d 100644 --- a/slsSupportLib/src/ToString.cpp +++ b/slsSupportLib/src/ToString.cpp @@ -170,8 +170,8 @@ std::string ToString(const defs::detectorSettings s) { return std::string("mediumgain"); case defs::VERYHIGHGAIN: return std::string("veryhighgain"); - case defs::DYNAMICHG0: - return std::string("dynamichg0"); + case defs::HIGHGAIN0: + return std::string("highgain0"); case defs::FIXGAIN1: return std::string("fixgain1"); case defs::FIXGAIN2: @@ -194,6 +194,8 @@ std::string ToString(const defs::detectorSettings s) { return std::string("g4_hg"); case defs::G4_LOWGAIN: return std::string("g4_lg"); + case defs::GAIN0: + return std::string("gain0"); case defs::UNDEFINED: return std::string("undefined"); case defs::UNINITIALIZED: @@ -581,12 +583,18 @@ std::string ToString(const defs::vetoAlgorithm s) { std::string ToString(const defs::gainMode s) { switch (s) { - case defs::NORMAL_GAIN_MODE: - return std::string("normal"); + case defs::DYNAMIC_GAIN_MODE: + return std::string("dynamicgain"); case defs::FORCE_SWITCH_G1: return std::string("forceswitchg1"); case defs::FORCE_SWITCH_G2: return std::string("forceswitchg2"); + case defs::FIX_G1: + return std::string("fixg1"); + case defs::FIX_G2: + return std::string("fixg2"); + case defs::FIX_G0: + return std::string("fixg0"); default: return std::string("Unknown"); } @@ -627,8 +635,8 @@ template <> defs::detectorSettings StringTo(const std::string &s) { return defs::MEDIUMGAIN; if (s == "veryhighgain") return defs::VERYHIGHGAIN; - if (s == "dynamichg0") - return defs::DYNAMICHG0; + if (s == "highgain0") + return defs::HIGHGAIN0; if (s == "fixgain1") return defs::FIXGAIN1; if (s == "fixgain2") @@ -649,6 +657,8 @@ template <> defs::detectorSettings StringTo(const std::string &s) { return defs::G2_LOWCAP_LOWGAIN; if (s == "g4_hg") return defs::G4_HIGHGAIN; + if (s == "gain0") + return defs::GAIN0; if (s == "g4_lg") return defs::G4_LOWGAIN; throw sls::RuntimeError("Unknown setting " + s); @@ -976,12 +986,18 @@ template <> defs::vetoAlgorithm StringTo(const std::string &s) { } template <> defs::gainMode StringTo(const std::string &s) { - if (s == "normal") - return defs::NORMAL_GAIN_MODE; + if (s == "dynamicgain") + return defs::DYNAMIC_GAIN_MODE; if (s == "forceswitchg1") return defs::FORCE_SWITCH_G1; if (s == "forceswitchg2") return defs::FORCE_SWITCH_G2; + if (s == "fixg1") + return defs::FIX_G1; + if (s == "fixg2") + return defs::FIX_G2; + if (s == "fixg0") + return defs::FIX_G0; throw sls::RuntimeError("Unknown gain mode " + s); }