This commit is contained in:
2021-08-10 17:26:26 +02:00
parent c716a87935
commit fce35e35a1
17 changed files with 486 additions and 78 deletions

View File

@ -488,6 +488,14 @@ class Detector {
* 0.\n[Jungfrau] Options: [0|1]. Default is 1.*/
void setFilterResistor(int value, Positions pos = {});
/** [Gotthard2][Jungfrau] */
Result<defs::currentSrcParameters>
getCurrentSource(Positions pos = {}) const;
/** [Gotthard2][Jungfrau] Please refer documentation on currentSrcParameters
* (sls_detector_defs.h) on the structure and its members */
void setCurrentSource(defs::currentSrcParameters par, Positions pos = {});
///@{
/** @name Acquisition */
@ -1300,12 +1308,6 @@ class Detector {
/** default disabled */
void setCDSGain(bool value, Positions pos = {});
/** [Gotthard2] */
Result<bool> getCurrentSource(Positions pos = {}) const;
/** default disabled */
void setCurrentSource(bool value, Positions pos = {});
/** [Gotthard2] */
Result<defs::timingSourceType> getTimingSource(Positions pos = {}) const;

View File

@ -959,6 +959,69 @@ std::string CmdProxy::ExternalSignal(int action) {
return os.str();
}
std::string CmdProxy::CurrentSource(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[0|1]\n\t[Gotthard2] Enable or disable current source. Default "
"is disabled.\n[0|1] [fix|nofix] [select source] "
"[normal|low]\n\t[Jungfrau] Disable or enable current source "
"with some parameters. The select source is 0-63 for chipv1.0 "
"and a 64 bit mask for chipv1.1. To disable, one needs only one "
"argument '0'."
<< '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 0) {
WrongNumberOfParameters(0);
}
auto t = det->getCurrentSource(std::vector<int>{det_id});
os << OutString(t) << '\n';
} else if (action == defs::PUT_ACTION) {
if (args.size() == 1) {
det->setCurrentsource(
defs::currentSrcParameters(StringTo<bool>(args[0])));
} else if (args.size() >= 3) {
// scan fix
bool fix = false;
if (args[1] == "fix") {
fix = true;
} else if (args[1] == "nofix") {
fix = false;
} else {
throw sls::RuntimeError("Invalid argument: " + args[1] +
". Did you mean fix or nofix?");
}
if (args.size() == 3) {
det->setCurrentsource(defs::currentSrcParameters(
StringTo<bool>(args[0]), fix, StringTo<int64_t>(args[2])));
} else if (args.size() == 4) {
bool normalCurrent = false;
if (args[3] == "normal") {
normalCurrent = true;
} else if (args[3] == "low") {
normalCurrent = false;
} else {
throw sls::RuntimeError("Invalid argument: " + args[3] +
". Did you mean normal or low?");
}
det->setCurrentsource(defs::currentSrcParameters(
StringTo<bool>(args[0]), fix, StringTo<int64_t>(args[2]),
normalCurrent));
} else {
throw sls::RuntimeError(
"Invalid number of parareters for this command.");
}
} else {
throw sls::RuntimeError(
"Invalid number of parareters for this command.");
}
os << ToString(args) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
/** temperature */
std::string CmdProxy::TemperatureValues(int action) {
std::ostringstream os;

View File

@ -803,6 +803,7 @@ class CmdProxy {
{"extsig", &CmdProxy::ExternalSignal},
{"parallel", &CmdProxy::parallel},
{"filterresistor", &CmdProxy::filterresistor},
{"currentsource", &CmdProxy::CurrentSource},
/** temperature */
{"templist", &CmdProxy::templist},
@ -951,7 +952,6 @@ class CmdProxy {
{"vetofile", &CmdProxy::VetoFile},
{"burstmode", &CmdProxy::BurstMode},
{"cdsgain", &CmdProxy::cdsgain},
{"currentsource", &CmdProxy::currentsource},
{"timingsource", &CmdProxy::timingsource},
{"veto", &CmdProxy::veto},
{"vetostream", &CmdProxy::VetoStreaming},
@ -1097,6 +1097,7 @@ class CmdProxy {
std::string MaxClockPhaseShift(int action);
std::string ClockDivider(int action);
std::string ExternalSignal(int action);
std::string CurrentSource(int action);
/** temperature */
std::string TemperatureValues(int action);
/* dacs */
@ -1921,11 +1922,6 @@ class CmdProxy {
"[0, 1]\n\t[Gotthard2] Enable or disable CDS gain. Default "
"is disabled.");
INTEGER_COMMAND_VEC_ID(
currentsource, getCurrentSource, setCurrentSource, StringTo<int>,
"[0, 1]\n\t[Gotthard2] Enable or disable current source. "
"Default is disabled.");
INTEGER_COMMAND_VEC_ID(
timingsource, getTimingSource, setTimingSource,
sls::StringTo<slsDetectorDefs::timingSourceType>,

View File

@ -707,6 +707,14 @@ void Detector::setFilterResistor(int value, Positions pos) {
pimpl->Parallel(&Module::setFilterResistor, pos, value);
}
Result<defs::currentSrcParameters>
Detector::getCurrentSource(Positions pos) const {
return pimpl->Parallel(&Module::getCurrentSource, pos);
}
void Detector::setCurrentSource(defs::currentSrcParameters par, Positions pos) {
pimpl->Parallel(&Module::setCurrentSource, pos, par);
}
// Acquisition
void Detector::acquire() { pimpl->acquire(); }
@ -1620,14 +1628,6 @@ void Detector::setCDSGain(bool value, Positions pos) {
pimpl->Parallel(&Module::setCDSGain, pos, value);
}
Result<bool> Detector::getCurrentSource(Positions pos) const {
return pimpl->Parallel(&Module::getCurrentSource, pos);
}
void Detector::setCurrentSource(bool value, Positions pos) {
pimpl->Parallel(&Module::setCurrentSource, pos, value);
}
Result<defs::timingSourceType> Detector::getTimingSource(Positions pos) const {
return pimpl->Parallel(&Module::getTimingSource, pos);
}

View File

@ -712,6 +712,14 @@ void Module::setFilterResistor(int value) {
sendToDetector(F_SET_FILTER_RESISTOR, value, nullptr);
}
defs::currentSrcParameters Module::getCurrentSource() const {
return sendToDetector<defs::currentSrcParameters>(F_GET_CURRENT_SOURCE);
}
void Module::setCurrentSource(defs::currentSrcParameters par) {
sendToDetector(F_SET_CURRENT_SOURCE, par, nullptr);
}
// Acquisition
void Module::startReceiver() {
@ -1914,14 +1922,6 @@ void Module::setCDSGain(bool value) {
sendToDetector(F_SET_CDS_GAIN, static_cast<int>(value), nullptr);
}
bool Module::getCurrentSource() const {
return sendToDetector<int>(F_GET_CURRENT_SOURCE);
}
void Module::setCurrentSource(bool value) {
sendToDetector(F_SET_CURRENT_SOURCE, static_cast<int>(value), nullptr);
}
slsDetectorDefs::timingSourceType Module::getTimingSource() const {
return sendToDetector<timingSourceType>(F_GET_TIMING_SOURCE);
}

View File

@ -172,7 +172,8 @@ class Module : public virtual slsDetectorDefs {
void setParallelMode(const bool enable);
int getFilterResistor() const;
void setFilterResistor(int value);
defs::currentSrcParameters getCurrentSource() const;
void setCurrentSource(defs::currentSrcParameters par);
/**************************************************
* *
* Acquisition *
@ -412,8 +413,6 @@ class Module : public virtual slsDetectorDefs {
void setBurstMode(burstMode value);
bool getCDSGain() const;
void setCDSGain(bool value);
bool getCurrentSource() const;
void setCurrentSource(bool value);
slsDetectorDefs::timingSourceType getTimingSource() const;
void setTimingSource(slsDetectorDefs::timingSourceType value);
bool getVeto() const;

View File

@ -519,36 +519,6 @@ TEST_CASE("cdsgain", "[.cmd]") {
}
}
TEST_CASE("currentsource", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2) {
auto prev_val = det.getCurrentSource();
{
std::ostringstream oss;
proxy.Call("currentsource", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "currentsource 1\n");
}
{
std::ostringstream oss;
proxy.Call("currentsource", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "currentsource 0\n");
}
{
std::ostringstream oss;
proxy.Call("currentsource", {}, -1, GET, oss);
REQUIRE(oss.str() == "currentsource 0\n");
}
for (int i = 0; i != det.size(); ++i) {
det.setCurrentSource(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(proxy.Call("currentsource", {}, -1, GET));
}
}
TEST_CASE("timingsource", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);

View File

@ -1423,6 +1423,134 @@ TEST_CASE("filterresistor", "[.cmd]") {
}
}
TEST_CASE("currentsource", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::GOTTHARD2 || detType == defs::Jungfrau) {
auto prev_val = det.getCurrentSource();
if (det_type == defs::GOTTHARD2) {
{
std::ostringstream oss;
proxy.Call("currentsource", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "currentsource 1\n");
}
{
std::ostringstream oss;
proxy.Call("currentsource", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "currentsource 0\n");
}
{
std::ostringstream oss;
proxy.Call("currentsource", {}, -1, GET, oss);
REQUIRE(oss.str() == "currentsource 0\n");
}
REQUIRE_THROWS(
proxy.Call("currentsource", {"1", "fix", "42"}, -1, PUT));
REQUIRE_THROWS(proxy.Call("currentsource",
{"1", "fix", "42", "normal"}, -1, PUT));
}
// jungfrau
else {
auto chipVersion = det.getChipVersion().tsquash(
"inconsistent chip versions to test");
if (chipVersion == 10) {
REQUIRE_THROWS(proxy.Call("currentsource", {"1"}, -1, PUT));
REQUIRE_THROWS(
proxy.Call("currentsource", {"1", "fix"}, -1, PUT));
REQUIRE_THROWS(
proxy.Call("currentsource", {"1", "fix", 64}, -1, PUT));
REQUIRE_THROWS(
proxy.Call("currentsource", {"1", "dfg", 64}, -1, PUT));
REQUIRE_THROWS(proxy.Call("currentsource",
{"1", "fix", 63, "normal"}, -1, PUT));
{
std::ostringstream oss;
proxy.Call("currentsource", {"1", "fix", "63"}, -1, PUT,
oss);
REQUIRE(oss.str() == "currentsource [1, fix, 63]\n");
}
{
std::ostringstream oss;
proxy.Call("currentsource", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "currentsource 0\n");
}
{
std::ostringstream oss;
proxy.Call("currentsource", {}, -1, GET, oss);
REQUIRE(oss.str() == "currentsource [disabled]\n");
}
{
std::ostringstream oss;
proxy.Call("currentsource", {"1", "nofix", "63"}, -1, PUT,
oss);
REQUIRE(oss.str() == "currentsource [1, nofix, 63]\n");
}
{
std::ostringstream oss;
proxy.Call("currentsource", {}, -1, GET, oss);
REQUIRE(oss.str() ==
"currentsource [enabled, nofix, 63]\n");
}
}
// chipv1.1
else {
REQUIRE_THROWS(proxy.Call("currentsource", {"1"}, -1, PUT));
REQUIRE_THROWS(
proxy.Call("currentsource", {"1", "fix"}, -1, PUT));
REQUIRE_THROWS(proxy.Call("currentsource",
{"1", "ffgdfgix", 65}, -1, PUT));
REQUIRE_THROWS(proxy.Call(
"currentsource", {"1", "fix", 65, "normaldgf"}, -1, PUT));
{
std::ostringstream oss;
proxy.Call("currentsource", {"1", "fix", "65", "normal"},
-1, PUT, oss);
REQUIRE(oss.str() ==
"currentsource [1, fix, 65, normal]\n");
}
{
std::ostringstream oss;
proxy.Call("currentsource", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "currentsource 0\n");
}
{
std::ostringstream oss;
proxy.Call("currentsource", {}, -1, GET, oss);
REQUIRE(oss.str() == "currentsource [disabled]\n");
}
{
std::ostringstream oss;
proxy.Call("currentsource", {"1", "nofix", "65", "normal"},
-1, PUT, oss);
REQUIRE(oss.str() ==
"currentsource [1, nofix, 65, normal]\n");
}
{
std::ostringstream oss;
proxy.Call("currentsource", {}, -1, GET, oss);
REQUIRE(oss.str() ==
"currentsource [enabled, nofix, 65, normal]\n");
}
{
std::ostringstream oss;
proxy.Call("currentsource", {"1", "nofix", "65", "low"}, -1,
PUT, oss);
REQUIRE(oss.str() == "currentsource [1, nofix, 65, low]\n");
}
}
}
for (int i = 0; i != det.size(); ++i) {
det.setCurrentSource(prev_val[i], {i});
}
} else {
REQUIRE_THROWS(proxy.Call("currentsource", {}, -1, GET));
}
}
/** temperature */
TEST_CASE("templist", "[.cmd]") {