jungfrau: comp disable time

This commit is contained in:
maliakal_d 2021-08-03 13:12:58 +02:00
parent 15f4dd97b5
commit 9c4ecf0506
14 changed files with 211 additions and 41 deletions

View File

@ -2013,7 +2013,7 @@ class Detector(CppDetectorApi):
Note
-----
By default, the on-chip gain switching is active during the entire exposure. This mode disables the on-chip gain switching comparator automatically after 93.75% of exposure time (only for longer than 100us).\n
By default, the on-chip gain switching is active during the entire exposure. This mode disables the on-chip gain switching comparator automatically after 93.75% of exposure time (only for longer than 100us). The % is only for chipv1.0, the duration can be set for chipv1.1.\n
Default is 0 or this mode disabled (comparator enabled throughout). 1 enables mode. 0 disables mode.
"""
return self.getAutoCompDisable()
@ -2022,6 +2022,31 @@ class Detector(CppDetectorApi):
def auto_comp_disable(self, value):
ut.set_using_dict(self.setAutoCompDisable, value)
@property
@element
def comp_disable_time(self):
"""[Jungfrau] Time before end of exposure when comparator is disabled.
Note
-----
It is only possible for chipv1.1.
:getter: always returns in seconds. To get in datetime.delta, use getComparatorDisableTime
Example
-----------
>>> d.comp_disable_time = 1.05
>>> d.comp_disable_time = datetime.timedelta(minutes = 3, seconds = 1.23)
>>> d.comp_disable_time
181.23
>>> d.getComparatorDisableTime()
[datetime.timedelta(seconds=181, microseconds=230000)]
"""
return ut.reduce_time(self.getComparatorDisableTime())
@comp_disable_time.setter
def comp_disable_time(self, value):
ut.set_time_using_dict(self.setComparatorDisableTime, value)
@property
@element

View File

@ -978,6 +978,14 @@ void init_det(py::module &m) {
(void (Detector::*)(bool, sls::Positions)) &
Detector::setAutoCompDisable,
py::arg(), py::arg() = Positions{})
.def("getComparatorDisableTime",
(Result<sls::ns>(Detector::*)(sls::Positions) const) &
Detector::getComparatorDisableTime,
py::arg() = Positions{})
.def("setComparatorDisableTime",
(void (Detector::*)(sls::ns, sls::Positions)) &
Detector::setComparatorDisableTime,
py::arg(), py::arg() = Positions{})
.def("getNumberOfAdditionalStorageCells",
(Result<int>(Detector::*)(sls::Positions) const) &
Detector::getNumberOfAdditionalStorageCells,

View File

@ -1662,6 +1662,32 @@ int autoCompDisable(int on) {
EXT_DAQ_CTRL_CMP_LGC_ENBL_OFST);
}
int setComparatorDisableTime(int64_t val) {
if (getChipVersion() != 11) {
return FAIL;
}
if (val < 0) {
LOG(logERROR,
("Invalid comp disable time: %lld ns\n", (long long int)val));
return FAIL;
}
LOG(logINFO, ("Setting comp disable time %lld ns\n", (long long int)val));
val *= (1E-3 * CLK_RUN);
bus_w(COMP_DSBLE_TIME_REG, val);
// validate for tolerance
int64_t retval = getComparatorDisableTime();
val /= (1E-3 * CLK_RUN);
if (val != retval) {
return FAIL;
}
return OK;
}
int64_t getComparatorDisableTime() {
return bus_r(COMP_DSBLE_TIME_REG) / (1E-3 * CLK_RUN);
}
void configureASICTimer() {
LOG(logINFO, ("Configuring ASIC Timer\n"));
bus_w(ASIC_CTRL_REG, (bus_r(ASIC_CTRL_REG) & ~ASIC_CTRL_PRCHRG_TMR_MSK) |

View File

@ -450,6 +450,8 @@ int powerChip(int on);
int isChipConfigured();
void configureChip();
int autoCompDisable(int on);
int setComparatorDisableTime(int64_t val);
int64_t getComparatorDisableTime();
void configureASICTimer();
int setClockDivider(enum CLKINDEX ind, int val);
int getClockDivider(enum CLKINDEX ind);

View File

@ -258,4 +258,6 @@ int get_chip_version(int);
int get_default_dac(int);
int set_default_dac(int);
int get_gain_mode(int);
int set_gain_mode(int);
int set_gain_mode(int);
int get_comp_disable_time(int);
int set_comp_disable_time(int);

View File

@ -384,6 +384,8 @@ void function_table() {
flist[F_SET_DEFAULT_DAC] = &set_default_dac;
flist[F_GET_GAIN_MODE] = &get_gain_mode;
flist[F_SET_GAIN_MODE] = &set_gain_mode;
flist[F_GET_COMP_DISABLE_TIME] = &get_comp_disable_time;
flist[F_SET_COMP_DISABLE_TIME] = &set_comp_disable_time;
// check
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
@ -8613,3 +8615,61 @@ int set_gain_mode(int file_des) {
#endif
return Server_SendResult(file_des, INT32, NULL, 0);
}
int get_comp_disable_time(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int64_t retval = -1;
#ifndef JUNGFRAUD
functionNotImplemented();
#else
// get only
if (getChipVersion() != 11) {
ret = FAIL;
strcpy(mess,
"Cannot get comparator disable time. Only valid for chipv1.1\n");
LOG(logERROR, (mess));
} else {
retval = getComparatorDisableTime();
LOG(logDEBUG1,
("retval comp disable time %lld ns\n", (long long int)retval));
}
#endif
return Server_SendResult(file_des, INT64, &retval, sizeof(retval));
}
int set_comp_disable_time(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
int64_t arg = -1;
if (receiveData(file_des, &arg, sizeof(arg), INT64) < 0)
return printSocketReadError();
LOG(logDEBUG1, ("Setting comp disable time %lld ns\n", (long long int)arg));
#ifndef JUNGFRAUD
functionNotImplemented();
#else
// only set
if (Server_VerifyLock() == OK) {
if (getChipVersion() != 11) {
ret = FAIL;
strcpy(mess, "Cannot get comparator disable time. Only valid for "
"chipv1.1\n");
LOG(logERROR, (mess));
} else {
ret = setComparatorDisableTime(arg);
int64_t retval = getComparatorDisableTime();
LOG(logDEBUG1, ("retval get comp disable time %lld ns\n",
(long long int)retval));
if (ret == FAIL) {
sprintf(mess,
"Could not set comp disable time. Set %lld ns, read "
"%lld ns.\n",
(long long int)arg, (long long int)retval);
LOG(logERROR, (mess));
}
}
}
#endif
return Server_SendResult(file_des, INT64, NULL, 0);
}

View File

@ -1131,15 +1131,23 @@ class Detector {
/** [Jungfrau] Advanced
* //TODO naming
* By default, the on-chip gain switching is active during the entire
* exposure. This mode disables the on-chip gain switching comparator
* automatically after 93.75% of exposure time (only for longer than
* 100us).\n
* Default is false or this mode disabled(comparator enabled throughout).
* true enables mode. 0 disables mode.
* By default, the on-chip gain switching is active during the
* entire exposure. This mode disables the on-chip gain switching comparator
* automatically after 93.75% of exposure time (only for longer than 100us).
* The % is for chipv1.0. One can set the duration for chipv1.1 using
* setComparatorDisableTime\n Default is false or this mode
* disabled(comparator enabled throughout). true enables mode. 0 disables
* mode.
*/
void setAutoCompDisable(bool value, Positions pos = {});
/** [Jungfrau] */
Result<ns> getComparatorDisableTime(Positions pos = {}) const;
/** [Jungfrau] Time before end of exposure when comparator is disabled. It
* is only possible for chipv1.1.*/
void setComparatorDisableTime(ns t, Positions pos = {});
/** [Jungfrau] Advanced TODO naming */
Result<int> getNumberOfAdditionalStorageCells(Positions pos = {}) const;

View File

@ -1729,37 +1729,6 @@ std::string CmdProxy::TemperatureEvent(int action) {
return os.str();
}
std::string AutoComparatorDisable(const int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == slsDetectorDefs::HELP_ACTION)
os << "[0, 1]\n\t[Jungfrau] Auto comparator disable mode. By default, "
"the on-chip gain switching is active during the entire "
"exposure.This mode disables the on - chip gain switching "
"comparator automatically after 93.75% of exposure time (only "
"for longer than 100us). \n\tDefault is 0 or this mode "
"disabled(comparator enabled throughout). 1 enables mode. 0 "
"disables mode."
<< '\n';
else if (action == slsDetectorDefs::GET_ACTION) {
if (!args.empty()) {
WrongNumberOfParameters(0);
}
auto t = det->GETFCN(std::vector<int>{det_id});
os << OutString(t) << '\n';
} else if (action == slsDetectorDefs::PUT_ACTION) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
auto val = CONV(args[0]);
det->SETFCN(val, std::vector<int>{det_id});
os << args.front() << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
/* Gotthard Specific */
std::string CmdProxy::ROI(int action) {

View File

@ -925,7 +925,8 @@ class CmdProxy {
{"temp_threshold", &CmdProxy::temp_threshold},
{"temp_control", &CmdProxy::temp_control},
{"temp_event", &CmdProxy::TemperatureEvent},
{"auto_comp_disable", &CmdProxy::AutoComparatorDisable},
{"auto_comp_disable", &CmdProxy::auto_comp_disable},
{"comp_disable_time", &CmdProxy::comp_disable_time},
{"storagecells", &CmdProxy::storagecells},
{"storagecell_start", &CmdProxy::storagecell_start},
{"storagecell_delay", &CmdProxy::storagecell_delay},
@ -1123,7 +1124,6 @@ class CmdProxy {
std::string DataStream(int action);
/* Jungfrau Specific */
std::string TemperatureEvent(int action);
std::string AutoComparatorDisable(int action);
/* Gotthard Specific */
std::string ROI(int action);
std::string ClearROI(int action);
@ -1837,6 +1837,24 @@ class CmdProxy {
"to be less than threshold temperature and temperature event has to be "
"cleared.");
INTEGER_COMMAND_VEC_ID(
auto_comp_disable, getAutoCompDisable, setAutoCompDisable,
StringTo<int>,
"[0, 1]\n\t[Jungfrau] Auto comparator disable mode. By default, the "
"on-chip gain switching is active during the entire exposure.This mode "
"disables the on - chip gain switching comparator automatically after "
"93.75% (only for chipv1.0) of exposure time (only for longer than "
"100us). It is possible to set the duration for chipv1.1 using "
"comp_disable_time command.\n\tDefault is 0 or this mode "
"disabled(comparator enabled throughout). 1 enables mode. 0 disables "
"mode. ");
TIME_COMMAND(comp_disable_time, getComparatorDisableTime,
setComparatorDisableTime,
"[duration] [(optional unit) ns|us|ms|s]\n\t[Jungfrau] Time "
"before end of exposure when comparator is disabled. It is "
"only possible for chipv1.1.");
INTEGER_COMMAND_SET_NOID_GET_ID(
storagecells, getNumberOfAdditionalStorageCells,
setNumberOfAdditionalStorageCells, StringTo<int>,

View File

@ -1459,6 +1459,14 @@ void Detector::setAutoCompDisable(bool value, Positions pos) {
pimpl->Parallel(&Module::setAutoComparatorDisableMode, pos, value);
}
Result<ns> Detector::getComparatorDisableTime(Positions pos) const {
return pimpl->Parallel(&Module::getComparatorDisableTime, pos);
}
void Detector::setComparatorDisableTime(ns t, Positions pos) {
pimpl->Parallel(&Module::setComparatorDisableTime, pos, t.count());
}
Result<int> Detector::getNumberOfAdditionalStorageCells(Positions pos) const {
return pimpl->Parallel(&Module::getNumberOfAdditionalStorageCells, pos);
}

View File

@ -1577,6 +1577,14 @@ void Module::setAutoComparatorDisableMode(bool val) {
sendToDetector<int>(F_AUTO_COMP_DISABLE, static_cast<int>(val));
}
int64_t Module::getComparatorDisableTime() const {
return sendToDetector<int64_t>(F_GET_COMP_DISABLE_TIME);
}
void Module::setComparatorDisableTime(int64_t value) {
sendToDetector(F_SET_COMP_DISABLE_TIME, value, nullptr);
}
int Module::getNumberOfAdditionalStorageCells() const {
return sendToDetector<int>(F_GET_NUM_ADDITIONAL_STORAGE_CELLS);
}

View File

@ -363,6 +363,8 @@ class Module : public virtual slsDetectorDefs {
void resetTemperatureEvent();
bool getAutoComparatorDisableMode() const;
void setAutoComparatorDisableMode(bool val);
int64_t getComparatorDisableTime() const;
void setComparatorDisableTime(int64_t value);
int getNumberOfAdditionalStorageCells() const;
void setNumberOfAdditionalStorageCells(int value);
int getStorageCellStart() const;

View File

@ -283,6 +283,36 @@ TEST_CASE("auto_comp_disable", "[.cmd]") {
}
}
TEST_CASE("comp_disable_time", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) {
auto prev_val = det.getComparatorDisableTime();
{
std::ostringstream oss;
proxy.Call("comp_disable_time", {"125ns"}, -1, PUT, oss);
REQUIRE(oss.str() == "comp_disable_time 125ns\n");
}
{
std::ostringstream oss;
proxy.Call("comp_disable_time", {}, -1, GET, oss);
REQUIRE(oss.str() == "comp_disable_time 125ns\n");
}
{
std::ostringstream oss;
proxy.Call("comp_disable_time", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "comp_disable_time 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setComparatorDisableTime(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(proxy.Call("comp_disable_time", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("comp_disable_time", {"0"}, -1, PUT));
}
}
TEST_CASE("storagecells", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);

View File

@ -235,6 +235,8 @@ enum detFuncs {
F_SET_DEFAULT_DAC,
F_GET_GAIN_MODE,
F_SET_GAIN_MODE,
F_GET_COMP_DISABLE_TIME,
F_SET_COMP_DISABLE_TIME,
NUM_DET_FUNCTIONS,
RECEIVER_ENUM_START = 256, /**< detector function should not exceed this
@ -576,6 +578,8 @@ const char* getFunctionNameFromEnum(enum detFuncs func) {
case F_SET_DEFAULT_DAC: return "F_SET_DEFAULT_DAC";
case F_GET_GAIN_MODE: return "F_GET_GAIN_MODE";
case F_SET_GAIN_MODE: return "F_SET_GAIN_MODE";
case F_GET_COMP_DISABLE_TIME: return "F_GET_COMP_DISABLE_TIME";
case F_SET_COMP_DISABLE_TIME: return "F_SET_COMP_DISABLE_TIME";
case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS";
case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START";