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:
2023-05-31 21:07:07 +02:00
committed by GitHub
parent 225e5490d2
commit b9a346a396
12 changed files with 564 additions and 50 deletions

View File

@ -1127,6 +1127,187 @@ std::string CmdProxy::TemperatureValues(int action) {
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 */
std::string CmdProxy::Dac(int action) {
std::ostringstream os;
@ -1205,41 +1386,6 @@ std::string CmdProxy::Dac(int action) {
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::ostringstream os;
os << cmd << ' ';

View File

@ -842,9 +842,16 @@ class CmdProxy {
{"temp_fpgafr", &CmdProxy::temp_fpgafr},
{"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 */
{"dac", &CmdProxy::Dac},
{"daclist", &CmdProxy::DacList},
{"dacvalues", &CmdProxy::DacValues},
{"resetdacs", &CmdProxy::ResetDacs},
{"defaultdac", &CmdProxy::DefaultDac},
@ -1142,9 +1149,15 @@ class CmdProxy {
std::string CurrentSource(int action);
/** temperature */
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 */
std::string Dac(int action);
std::string DacList(int action);
std::string DacValues(int action);
std::string ResetDacs(int action);
std::string DefaultDac(int action);

View File

@ -14,12 +14,23 @@ CtbConfig::CtbConfig() {
for (size_t i = 0; i != num_dacs; ++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)) {
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());
}
}
@ -29,7 +40,7 @@ void CtbConfig::check_size(const std::string &name) const {
if (name.empty())
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))) {
std::ostringstream oss;
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) {
check_index(index);
check_dac_index(index);
check_size(name);
char *dst = &dacnames[index * name_length];
memset(dst, '\0', name_length);
memcpy(dst, &name[0], name.size());
}
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) {
setDacName(i, names[i]);
}
}
std::string CtbConfig::getDacName(size_t index) const {
check_dac_index(index);
return dacnames + index * name_length;
}
@ -65,6 +79,36 @@ std::vector<std::string> CtbConfig::getDacNames() const {
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_; }
} // namespace sls

View File

@ -6,10 +6,13 @@ namespace sls {
class CtbConfig {
static constexpr size_t name_length = 20;
static constexpr size_t num_dacs = 18;
static constexpr size_t num_adcs = 32;
static constexpr const char *shm_tag_ = "ctbdacs";
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;
public:
@ -23,6 +26,12 @@ class CtbConfig {
void setDacName(size_t index, const std::string &name);
std::string getDacName(size_t index) 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();
};

View File

@ -2231,6 +2231,12 @@ defs::dacIndex Detector::getDacIndex(const std::string &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) {
auto type = getDetectorType().squash();
if (type == defs::CHIPTESTBOARD)
@ -2238,6 +2244,40 @@ std::string Detector::getDacName(defs::dacIndex 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
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));
}
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

View File

@ -328,6 +328,12 @@ class DetectorImpl : public virtual slsDetectorDefs {
std::vector<std::string> getCtbDacNames() const;
std::string getCtbDacName(defs::dacIndex i) const;
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:
/**