ctb adc names (#757)

* first draft of adc names

* fixed tests

* formatting

* added python functions in src

---------

Co-authored-by: Erik Fröjdh <erik.frojdh@gmail.com>
This commit is contained in:
maliakal_d 2023-05-31 21:07:07 +02:00 committed by GitHub
parent 225e5490d2
commit b9a346a396
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 564 additions and 50 deletions

View File

@ -1766,7 +1766,7 @@ class Detector(CppDetectorApi):
@property @property
def daclist(self): def daclist(self):
""" """
List of enums for every dac for this detector. List of enums/names for every dac for this detector.
:setter: Only implemented for Chiptestboard :setter: Only implemented for Chiptestboard
""" """
@ -1776,6 +1776,20 @@ class Detector(CppDetectorApi):
def daclist(self, value): def daclist(self, value):
self.setDacNames(value) self.setDacNames(value)
@property
def adclist(self):
"""
List of names for every adc for this detector.
:setter: Only implemented for Chiptestboard
"""
return self.getAdcNames()
@adclist.setter
def adclist(self, value):
self.setAdcNames(value)
@property @property
def dacvalues(self): def dacvalues(self):
"""Gets the dac values for every dac for this detector.""" """Gets the dac values for every dac for this detector."""

View File

@ -1647,10 +1647,33 @@ void init_det(py::module &m) {
(defs::dacIndex(Detector::*)(const std::string &)) & (defs::dacIndex(Detector::*)(const std::string &)) &
Detector::getDacIndex, Detector::getDacIndex,
py::arg()); py::arg());
CppDetectorApi.def(
"setDacName",
(void (Detector::*)(defs::dacIndex, const std::string &)) &
Detector::setDacName,
py::arg(), py::arg());
CppDetectorApi.def("getDacName", CppDetectorApi.def("getDacName",
(std::string(Detector::*)(defs::dacIndex)) & (std::string(Detector::*)(defs::dacIndex)) &
Detector::getDacName, Detector::getDacName,
py::arg()); py::arg());
CppDetectorApi.def("setAdcNames",
(void (Detector::*)(const std::vector<std::string>)) &
Detector::setAdcNames,
py::arg());
CppDetectorApi.def("getAdcNames",
(std::vector<std::string>(Detector::*)() const) &
Detector::getAdcNames);
CppDetectorApi.def("getAdcIndex",
(int (Detector::*)(const std::string &)) &
Detector::getAdcIndex,
py::arg());
CppDetectorApi.def("setAdcName",
(void (Detector::*)(const int, const std::string &)) &
Detector::setAdcName,
py::arg(), py::arg());
CppDetectorApi.def("getAdcName",
(std::string(Detector::*)(int)) & Detector::getAdcName,
py::arg());
CppDetectorApi.def( CppDetectorApi.def(
"setPattern", "setPattern",
(void (Detector::*)(const std::string &, sls::Positions)) & (void (Detector::*)(const std::string &, sls::Positions)) &

View File

@ -1721,12 +1721,33 @@ class Detector {
/** [CTB] Default is enabled. */ /** [CTB] Default is enabled. */
void setLEDEnable(bool enable, Positions pos = {}); void setLEDEnable(bool enable, Positions pos = {});
/** [CTB] */
void setDacNames(const std::vector<std::string> names); void setDacNames(const std::vector<std::string> names);
std::vector<std::string> getDacNames() const; std::vector<std::string> getDacNames() const;
defs::dacIndex getDacIndex(const std::string &name); defs::dacIndex getDacIndex(const std::string &name);
/** [CTB] */
void setDacName(defs::dacIndex i, const std::string &name);
std::string getDacName(defs::dacIndex i); std::string getDacName(defs::dacIndex i);
/** [CTB] */
void setAdcNames(const std::vector<std::string> names);
/** [CTB] */
std::vector<std::string> getAdcNames() const;
/** [CTB] */
int getAdcIndex(const std::string &name);
/** [CTB] */
void setAdcName(const int i, const std::string &name);
/** [CTB] */
std::string getAdcName(int i);
///@} ///@}
/** @name Pattern */ /** @name Pattern */

View File

@ -1127,6 +1127,187 @@ std::string CmdProxy::TemperatureValues(int action) {
return os.str(); return os.str();
} }
/* list */
std::string CmdProxy::DacList(const int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == slsDetectorDefs::HELP_ACTION) {
os << "\n\t[dacname1 dacname2 .. dacname18] \n\t\t[ChipTestBoard] Set "
"the list of dac names for this detector.\n\t\t[All] Gets the "
"list of dac names for every dac for this detector."
<< '\n';
} else if (action == slsDetectorDefs::GET_ACTION) {
if (!args.empty()) {
WrongNumberOfParameters(0);
}
auto t = det->getDacNames();
os << ToString(t) << '\n';
} else if (action == slsDetectorDefs::PUT_ACTION) {
if (det->getDetectorType().squash() != defs::CHIPTESTBOARD) {
throw RuntimeError("This detector already has fixed dac "
"names. Cannot change them.");
}
if (det_id != -1) {
throw RuntimeError("Cannot configure dacnames at module level");
}
det->setDacNames(args);
os << ToString(args) << '\n';
} else {
throw RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::DacName(const int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == slsDetectorDefs::HELP_ACTION) {
os << "\n\t[0-18][name] \n\t\t[ChipTestBoard] Set "
"the dac at the given position to the given name."
<< '\n';
return os.str();
}
if (det->getDetectorType().squash() != defs::CHIPTESTBOARD) {
throw RuntimeError("Named Dacs only allowed for CTB.");
}
defs::dacIndex index = static_cast<defs::dacIndex>(StringTo<int>(args[0]));
if (action == slsDetectorDefs::GET_ACTION) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
auto t = det->getDacName(index);
os << args[0] << ' ' << ToString(t) << '\n';
} else if (action == slsDetectorDefs::PUT_ACTION) {
if (det_id != -1) {
throw RuntimeError("Cannot configure dacnames at module level");
}
if (args.size() != 2) {
WrongNumberOfParameters(2);
}
det->setDacName(index, args[1]);
os << ToString(args) << '\n';
} else {
throw RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::DacIndex(const int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == slsDetectorDefs::HELP_ACTION) {
os << "\n\t[name] \n\t\t[ChipTestBoard] Get "
"the dac index for the given name."
<< '\n';
return os.str();
}
if (det->getDetectorType().squash() != defs::CHIPTESTBOARD) {
throw RuntimeError("Named Dacs only allowed for CTB.");
}
if (action == slsDetectorDefs::GET_ACTION) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
auto t = det->getDacIndex(args[0]);
os << ToString(static_cast<int>(t)) << '\n';
} else if (action == slsDetectorDefs::PUT_ACTION) {
throw RuntimeError("Cannot set dac index");
} else {
throw RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::AdcList(const int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == slsDetectorDefs::HELP_ACTION) {
os << "\n\t[adcname1 adcname2 .. adcname32] \n\t\t[ChipTestBoard] Set "
"the list of adc names for this board."
<< '\n';
return os.str();
}
if (det->getDetectorType().squash() != defs::CHIPTESTBOARD) {
throw RuntimeError("Named Adcs only allowed for CTB.");
}
if (action == slsDetectorDefs::GET_ACTION) {
if (!args.empty()) {
WrongNumberOfParameters(0);
}
auto t = det->getAdcNames();
os << ToString(t) << '\n';
} else if (action == slsDetectorDefs::PUT_ACTION) {
if (det_id != -1) {
throw RuntimeError("Cannot configure adcnames at module level");
}
det->setAdcNames(args);
os << ToString(args) << '\n';
} else {
throw RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::AdcName(const int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == slsDetectorDefs::HELP_ACTION) {
os << "\n\t[0-31][name] \n\t\t[ChipTestBoard] Set "
"the adc at the given position to the given name."
<< '\n';
return os.str();
}
if (det->getDetectorType().squash() != defs::CHIPTESTBOARD) {
throw RuntimeError("Named Adcs only allowed for CTB.");
}
int index = StringTo<int>(args[0]);
if (action == slsDetectorDefs::GET_ACTION) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
auto t = det->getAdcName(index);
os << args[0] << ' ' << ToString(t) << '\n';
} else if (action == slsDetectorDefs::PUT_ACTION) {
if (det_id != -1) {
throw RuntimeError("Cannot configure adcnames at module level");
}
if (args.size() != 2) {
WrongNumberOfParameters(2);
}
det->setAdcName(index, args[1]);
os << ToString(args) << '\n';
} else {
throw RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::AdcIndex(const int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == slsDetectorDefs::HELP_ACTION) {
os << "\n\t[name] \n\t\t[ChipTestBoard] Get "
"the adc index for the given name."
<< '\n';
return os.str();
}
if (det->getDetectorType().squash() != defs::CHIPTESTBOARD) {
throw RuntimeError("Named Adcs only allowed for CTB.");
}
if (action == slsDetectorDefs::GET_ACTION) {
if (args.size() != 1) {
WrongNumberOfParameters(1);
}
auto t = det->getAdcIndex(args[0]);
os << ToString(t) << '\n';
} else if (action == slsDetectorDefs::PUT_ACTION) {
throw RuntimeError("Cannot set adc index");
} else {
throw RuntimeError("Unknown action");
}
return os.str();
}
/* dacs */ /* dacs */
std::string CmdProxy::Dac(int action) { std::string CmdProxy::Dac(int action) {
std::ostringstream os; std::ostringstream os;
@ -1205,41 +1386,6 @@ std::string CmdProxy::Dac(int action) {
return os.str(); return os.str();
} }
std::string CmdProxy::DacList(const int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == slsDetectorDefs::HELP_ACTION) {
os << "\n\t[dacname1 dacname2 .. dacname18] \n\t\t[ChipTestBoard] Set "
"the list of dac names for this detector.\n\t\t[All] Gets the "
"list "
"of "
"dac names for every dac for this detector."
<< '\n';
} else if (action == slsDetectorDefs::GET_ACTION) {
if (!args.empty()) {
WrongNumberOfParameters(0);
}
auto t = det->getDacNames();
os << ToString(t) << '\n';
} else if (action == slsDetectorDefs::PUT_ACTION) {
if (det->getDetectorType().squash() != defs::CHIPTESTBOARD) {
throw RuntimeError("This detector already has fixed dac "
"names. Cannot change them.");
}
if (det_id != -1) {
throw RuntimeError("Cannot configure dacnames at module level");
}
if (args.size() != 18) {
WrongNumberOfParameters(18);
}
det->setDacNames(args);
os << ToString(args) << '\n';
} else {
throw RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::DacValues(int action) { std::string CmdProxy::DacValues(int action) {
std::ostringstream os; std::ostringstream os;
os << cmd << ' '; os << cmd << ' ';

View File

@ -842,9 +842,16 @@ class CmdProxy {
{"temp_fpgafr", &CmdProxy::temp_fpgafr}, {"temp_fpgafr", &CmdProxy::temp_fpgafr},
{"temp_slowadc", &CmdProxy::temp_slowadc}, {"temp_slowadc", &CmdProxy::temp_slowadc},
/* lists */
{"daclist", &CmdProxy::DacList},
{"dacname", &CmdProxy::DacName},
{"dacindex", &CmdProxy::DacIndex},
{"adclist", &CmdProxy::AdcList},
{"adcname", &CmdProxy::AdcName},
{"adcindex", &CmdProxy::AdcIndex},
/* dacs */ /* dacs */
{"dac", &CmdProxy::Dac}, {"dac", &CmdProxy::Dac},
{"daclist", &CmdProxy::DacList},
{"dacvalues", &CmdProxy::DacValues}, {"dacvalues", &CmdProxy::DacValues},
{"resetdacs", &CmdProxy::ResetDacs}, {"resetdacs", &CmdProxy::ResetDacs},
{"defaultdac", &CmdProxy::DefaultDac}, {"defaultdac", &CmdProxy::DefaultDac},
@ -1142,9 +1149,15 @@ class CmdProxy {
std::string CurrentSource(int action); std::string CurrentSource(int action);
/** temperature */ /** temperature */
std::string TemperatureValues(int action); std::string TemperatureValues(int action);
/* list */
std::string DacList(int action);
std::string DacName(int action);
std::string DacIndex(int action);
std::string AdcList(int action);
std::string AdcName(int action);
std::string AdcIndex(int action);
/* dacs */ /* dacs */
std::string Dac(int action); std::string Dac(int action);
std::string DacList(int action);
std::string DacValues(int action); std::string DacValues(int action);
std::string ResetDacs(int action); std::string ResetDacs(int action);
std::string DefaultDac(int action); std::string DefaultDac(int action);

View File

@ -14,12 +14,23 @@ CtbConfig::CtbConfig() {
for (size_t i = 0; i != num_dacs; ++i) { for (size_t i = 0; i != num_dacs; ++i) {
setDacName(i, "dac" + ToString(i)); setDacName(i, "dac" + ToString(i));
} }
for (size_t i = 0; i != num_adcs; ++i) {
setAdcName(i, "adc" + ToString(i));
}
} }
void CtbConfig::check_index(size_t i) const { void CtbConfig::check_dac_index(size_t i) const {
if (!(i < num_dacs)) { if (!(i < num_dacs)) {
std::ostringstream oss; std::ostringstream oss;
oss << "DAC index is too large needs to be below " << num_dacs; oss << "DAC index is too large. Needs to be below " << num_dacs;
throw RuntimeError(oss.str());
}
}
void CtbConfig::check_adc_index(size_t i) const {
if (!(i < num_adcs)) {
std::ostringstream oss;
oss << "ADC index is too large.Needs to be below " << num_adcs;
throw RuntimeError(oss.str()); throw RuntimeError(oss.str());
} }
} }
@ -29,7 +40,7 @@ void CtbConfig::check_size(const std::string &name) const {
if (name.empty()) if (name.empty())
throw RuntimeError("Name needs to be at least one character"); throw RuntimeError("Name needs to be at least one character");
// dacname_length -1 to account for \0 termination // dac/adc name_length -1 to account for \0 termination
if (!(name.size() < (name_length - 1))) { if (!(name.size() < (name_length - 1))) {
std::ostringstream oss; std::ostringstream oss;
oss << "Length of name needs to be less than " << name_length - 1 oss << "Length of name needs to be less than " << name_length - 1
@ -39,22 +50,25 @@ void CtbConfig::check_size(const std::string &name) const {
} }
void CtbConfig::setDacName(size_t index, const std::string &name) { void CtbConfig::setDacName(size_t index, const std::string &name) {
check_dac_index(index);
check_index(index);
check_size(name); check_size(name);
char *dst = &dacnames[index * name_length]; char *dst = &dacnames[index * name_length];
memset(dst, '\0', name_length); memset(dst, '\0', name_length);
memcpy(dst, &name[0], name.size()); memcpy(dst, &name[0], name.size());
} }
void CtbConfig::setDacNames(const std::vector<std::string> &names) { void CtbConfig::setDacNames(const std::vector<std::string> &names) {
if (names.size() != num_dacs) {
throw RuntimeError("Dac names need to be of size " +
std::to_string(num_dacs));
}
for (size_t i = 0; i != num_dacs; ++i) { for (size_t i = 0; i != num_dacs; ++i) {
setDacName(i, names[i]); setDacName(i, names[i]);
} }
} }
std::string CtbConfig::getDacName(size_t index) const { std::string CtbConfig::getDacName(size_t index) const {
check_dac_index(index);
return dacnames + index * name_length; return dacnames + index * name_length;
} }
@ -65,6 +79,36 @@ std::vector<std::string> CtbConfig::getDacNames() const {
return names; return names;
} }
void CtbConfig::setAdcName(size_t index, const std::string &name) {
check_adc_index(index);
check_size(name);
char *dst = &adcnames[index * name_length];
memset(dst, '\0', name_length);
memcpy(dst, &name[0], name.size());
}
void CtbConfig::setAdcNames(const std::vector<std::string> &names) {
if (names.size() != num_adcs) {
throw RuntimeError("Adc names need to be of size " +
std::to_string(num_adcs));
}
for (size_t i = 0; i != num_adcs; ++i) {
setAdcName(i, names[i]);
}
}
std::string CtbConfig::getAdcName(size_t index) const {
check_adc_index(index);
return adcnames + index * name_length;
}
std::vector<std::string> CtbConfig::getAdcNames() const {
std::vector<std::string> names;
for (size_t i = 0; i != num_adcs; ++i)
names.push_back(getAdcName(i));
return names;
}
const char *CtbConfig::shm_tag() { return shm_tag_; } const char *CtbConfig::shm_tag() { return shm_tag_; }
} // namespace sls } // namespace sls

View File

@ -6,10 +6,13 @@ namespace sls {
class CtbConfig { class CtbConfig {
static constexpr size_t name_length = 20; static constexpr size_t name_length = 20;
static constexpr size_t num_dacs = 18; static constexpr size_t num_dacs = 18;
static constexpr size_t num_adcs = 32;
static constexpr const char *shm_tag_ = "ctbdacs"; static constexpr const char *shm_tag_ = "ctbdacs";
char dacnames[name_length * num_dacs]{}; char dacnames[name_length * num_dacs]{};
char adcnames[name_length * num_adcs]{};
void check_index(size_t i) const; void check_dac_index(size_t i) const;
void check_adc_index(size_t i) const;
void check_size(const std::string &name) const; void check_size(const std::string &name) const;
public: public:
@ -23,6 +26,12 @@ class CtbConfig {
void setDacName(size_t index, const std::string &name); void setDacName(size_t index, const std::string &name);
std::string getDacName(size_t index) const; std::string getDacName(size_t index) const;
std::vector<std::string> getDacNames() const; std::vector<std::string> getDacNames() const;
void setAdcNames(const std::vector<std::string> &names);
void setAdcName(size_t index, const std::string &name);
std::string getAdcName(size_t index) const;
std::vector<std::string> getAdcNames() const;
static const char *shm_tag(); static const char *shm_tag();
}; };

View File

@ -2231,6 +2231,12 @@ defs::dacIndex Detector::getDacIndex(const std::string &name) {
return StringTo<defs::dacIndex>(name); return StringTo<defs::dacIndex>(name);
} }
void Detector::setDacName(defs::dacIndex i, const std::string &name) {
if (getDetectorType().squash() != defs::CHIPTESTBOARD)
throw RuntimeError("Named dacs only for CTB");
pimpl->setCtbDacName(i, name);
}
std::string Detector::getDacName(defs::dacIndex i) { std::string Detector::getDacName(defs::dacIndex i) {
auto type = getDetectorType().squash(); auto type = getDetectorType().squash();
if (type == defs::CHIPTESTBOARD) if (type == defs::CHIPTESTBOARD)
@ -2238,6 +2244,40 @@ std::string Detector::getDacName(defs::dacIndex i) {
return ToString(i); return ToString(i);
} }
void Detector::setAdcNames(const std::vector<std::string> names) {
if (getDetectorType().squash() != defs::CHIPTESTBOARD)
throw RuntimeError("Named adcs only for CTB");
pimpl->setCtbAdcNames(names);
}
std::vector<std::string> Detector::getAdcNames() const {
if (getDetectorType().squash() != defs::CHIPTESTBOARD)
throw RuntimeError("Named adcs only for CTB");
return pimpl->getCtbAdcNames();
}
int Detector::getAdcIndex(const std::string &name) {
if (getDetectorType().squash() != defs::CHIPTESTBOARD)
throw RuntimeError("Named adcs only for CTB");
auto names = getAdcNames();
auto it = std::find(names.begin(), names.end(), name);
if (it == names.end())
throw RuntimeError("Adcname not found");
return (it - names.begin());
}
void Detector::setAdcName(const int index, const std::string &name) {
if (getDetectorType().squash() != defs::CHIPTESTBOARD)
throw RuntimeError("Named adcs only for CTB");
pimpl->setCtbAdcName(index, name);
}
std::string Detector::getAdcName(int i) {
if (getDetectorType().squash() != defs::CHIPTESTBOARD)
throw RuntimeError("Named adcs only for CTB");
return pimpl->getCtbAdcName(i);
}
// Pattern // Pattern
void Detector::setPattern(const std::string &fname, Positions pos) { void Detector::setPattern(const std::string &fname, Positions pos) {

View File

@ -2001,4 +2001,24 @@ std::string DetectorImpl::getCtbDacName(defs::dacIndex i) const {
return ctb_shm()->getDacName(static_cast<int>(i)); return ctb_shm()->getDacName(static_cast<int>(i));
} }
void DetectorImpl::setCtbDacName(const int index, const std::string &name) {
ctb_shm()->setDacName(index, name);
}
std::vector<std::string> DetectorImpl::getCtbAdcNames() const {
return ctb_shm()->getAdcNames();
}
void DetectorImpl::setCtbAdcNames(const std::vector<std::string> &names) {
ctb_shm()->setAdcNames(names);
}
std::string DetectorImpl::getCtbAdcName(int i) const {
return ctb_shm()->getAdcName(i);
}
void DetectorImpl::setCtbAdcName(const int index, const std::string &name) {
ctb_shm()->setAdcName(index, name);
}
} // namespace sls } // namespace sls

View File

@ -328,6 +328,12 @@ class DetectorImpl : public virtual slsDetectorDefs {
std::vector<std::string> getCtbDacNames() const; std::vector<std::string> getCtbDacNames() const;
std::string getCtbDacName(defs::dacIndex i) const; std::string getCtbDacName(defs::dacIndex i) const;
void setCtbDacNames(const std::vector<std::string> &names); void setCtbDacNames(const std::vector<std::string> &names);
void setCtbDacName(const int index, const std::string &name);
std::vector<std::string> getCtbAdcNames() const;
std::string getCtbAdcName(int i) const;
void setCtbAdcNames(const std::vector<std::string> &names);
void setCtbAdcName(const int index, const std::string &name);
private: private:
/** /**

View File

@ -1929,15 +1929,193 @@ TEST_CASE("temp_fpga", "[.cmd]") {
} }
} }
/* dacs */ /* list */
TEST_CASE("daclist", "[.cmd]") { TEST_CASE("daclist", "[.cmd]") {
Detector det; Detector det;
CmdProxy proxy(&det); CmdProxy proxy(&det);
REQUIRE_NOTHROW(proxy.Call("daclist", {}, -1, GET)); auto det_type = det.getDetectorType().squash();
REQUIRE_THROWS(proxy.Call("daclist", {}, -1, PUT));
if (det_type == defs::CHIPTESTBOARD) {
REQUIRE_NOTHROW(proxy.Call("daclist", {}, -1, GET));
auto prev = det.getDacNames();
REQUIRE_THROWS(proxy.Call("daclist", {"a", "s", "d"}, -1, PUT));
std::vector<std::string> names;
for (int iarg = 0; iarg != 18; ++iarg) {
names.push_back("a");
}
{
std::ostringstream oss;
REQUIRE_NOTHROW(proxy.Call("daclist", names, -1, PUT, oss));
}
{
std::ostringstream oss;
REQUIRE_NOTHROW(proxy.Call("daclist", {}, -1, GET, oss));
REQUIRE(oss.str() ==
std::string("daclist ") + ToString(names) + '\n');
}
det.setDacNames(prev);
} else {
REQUIRE_THROWS(proxy.Call("daclist", {"a", "b"}, -1, PUT));
REQUIRE_NOTHROW(proxy.Call("daclist", {}, -1, GET));
}
} }
TEST_CASE("adclist", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD) {
auto prev = det.getAdcNames();
REQUIRE_THROWS(proxy.Call("adclist", {"a", "s", "d"}, -1, PUT));
std::vector<std::string> names;
for (int iarg = 0; iarg != 32; ++iarg) {
names.push_back("a");
}
{
std::ostringstream oss;
REQUIRE_NOTHROW(proxy.Call("adclist", names, -1, PUT, oss));
}
{
std::ostringstream oss;
REQUIRE_NOTHROW(proxy.Call("adclist", {}, -1, GET, oss));
REQUIRE(oss.str() ==
std::string("adclist ") + ToString(names) + '\n');
}
det.setAdcNames(prev);
} else {
REQUIRE_THROWS(proxy.Call("adclist", {"a", "b"}, -1, PUT));
REQUIRE_THROWS(proxy.Call("adclist", {}, -1, GET));
}
}
TEST_CASE("dacname", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD) {
defs::dacIndex ind = static_cast<defs::dacIndex>(2);
std::string str_dac_index = "2";
auto prev = det.getDacName(ind);
// 1 arg throw
REQUIRE_THROWS(proxy.Call("dacname", {"2", "3", "bname"}, -1, PUT));
// invalid index
REQUIRE_THROWS(proxy.Call("dacname", {"18", "bname"}, -1, PUT));
{
std::ostringstream oss;
REQUIRE_NOTHROW(
proxy.Call("dacname", {str_dac_index, "bname"}, -1, PUT, oss));
}
{
std::ostringstream oss;
REQUIRE_NOTHROW(
proxy.Call("dacname", {str_dac_index}, -1, GET, oss));
REQUIRE(oss.str() ==
std::string("dacname ") + str_dac_index + " bname\n");
}
det.setDacName(ind, prev);
} else {
REQUIRE_THROWS(proxy.Call("dacname", {"2", "b"}, -1, PUT));
REQUIRE_THROWS(proxy.Call("dacname", {"2"}, -1, GET));
}
}
TEST_CASE("adcname", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD) {
int ind = 2;
std::string str_adc_index = "2";
auto prev = det.getAdcName(ind);
// 1 arg throw
REQUIRE_THROWS(proxy.Call("adcname", {"2", "3", "bname"}, -1, PUT));
// invalid index
REQUIRE_THROWS(proxy.Call("adcname", {"32", "bname"}, -1, PUT));
{
std::ostringstream oss;
REQUIRE_NOTHROW(
proxy.Call("adcname", {str_adc_index, "bname"}, -1, PUT, oss));
}
{
std::ostringstream oss;
REQUIRE_NOTHROW(
proxy.Call("adcname", {str_adc_index}, -1, GET, oss));
REQUIRE(oss.str() ==
std::string("adcname ") + str_adc_index + " bname\n");
}
det.setAdcName(ind, prev);
} else {
REQUIRE_THROWS(proxy.Call("adcname", {"2", "b"}, -1, PUT));
REQUIRE_THROWS(proxy.Call("adcname", {"2"}, -1, GET));
}
}
TEST_CASE("dacindex", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD) {
defs::dacIndex ind = static_cast<defs::dacIndex>(2);
std::string str_dac_index = "2";
// 1 arg throw
REQUIRE_THROWS(proxy.Call("dacindex", {"2", "2"}, -1, PUT));
// invalid index
REQUIRE_THROWS(proxy.Call("dacindex", {"18"}, -1, PUT));
auto dacname = det.getDacName(ind);
{
std::ostringstream oss;
REQUIRE_NOTHROW(proxy.Call("dacindex", {dacname}, -1, GET, oss));
REQUIRE(oss.str() ==
std::string("dacindex ") + str_dac_index + '\n');
}
} else {
REQUIRE_THROWS(proxy.Call("dacindex", {"2"}, -1, GET));
}
}
TEST_CASE("adcindex", "[.cmd]") {
Detector det;
CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash();
if (det_type == defs::CHIPTESTBOARD) {
int ind = 2;
std::string str_adc_index = "2";
// 1 arg throw
REQUIRE_THROWS(proxy.Call("adcindex", {"2", "2"}, -1, PUT));
// invalid index
REQUIRE_THROWS(proxy.Call("adcindex", {"32"}, -1, PUT));
auto adcname = det.getAdcName(ind);
{
std::ostringstream oss;
REQUIRE_NOTHROW(proxy.Call("adcindex", {adcname}, -1, GET, oss));
REQUIRE(oss.str() ==
std::string("adcindex ") + str_adc_index + '\n');
}
} else {
REQUIRE_THROWS(proxy.Call("adcindex", {"2"}, -1, GET));
}
}
/* dacs */
TEST_CASE("dacvalues", "[.cmd]") { TEST_CASE("dacvalues", "[.cmd]") {
Detector det; Detector det;
CmdProxy proxy(&det); CmdProxy proxy(&det);

View File

@ -10,8 +10,8 @@
namespace sls { namespace sls {
TEST_CASE("Default construction") { TEST_CASE("Default construction") {
static_assert(sizeof(CtbConfig) == 360, static_assert(sizeof(CtbConfig) == ((18 + 32) * 20),
"Size of CtbConfig does not match"); // 18*20 "Size of CtbConfig does not match");
CtbConfig c; CtbConfig c;
auto names = c.getDacNames(); auto names = c.getDacNames();