1. Ctb powerindices (#767)

* power and sense returning dac indices instead of int in Detector class
This commit is contained in:
2023-06-19 15:19:50 +02:00
committed by GitHub
parent 3f9ec695db
commit d3d98db7e9
10 changed files with 205 additions and 174 deletions

View File

@ -1158,66 +1158,6 @@ std::string CmdProxy::DacList(const int 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();
}
/* dacs */
std::string CmdProxy::Dac(int action) {
std::ostringstream os;

View File

@ -554,6 +554,73 @@ namespace sls {
return os.str(); \
}
#define CTB_SINGLE_DACNAME(CMDNAME, GETFCN, SETFCN, STARTINDEX, HLPSTR) \
std::string CMDNAME(const int action) { \
std::ostringstream os; \
os << cmd << ' '; \
if (action == slsDetectorDefs::HELP_ACTION) { \
os << HLPSTR << '\n'; \
return os.str(); \
} \
if (det->getDetectorType().squash() != defs::CHIPTESTBOARD) { \
throw RuntimeError(cmd + " only allowed for CTB."); \
} \
if (det_id != -1) { \
throw RuntimeError("Cannot configure " + cmd + \
" at module level"); \
} \
defs::dacIndex index = defs::DAC_0; \
if (args.size() > 0) { \
index = static_cast<defs::dacIndex>(StringTo<int>(args[0]) + \
STARTINDEX); \
} \
if (action == slsDetectorDefs::GET_ACTION) { \
if (args.size() != 1) { \
WrongNumberOfParameters(1); \
} \
auto t = det->GETFCN(index); \
os << args[0] << ' ' << t << '\n'; \
} else if (action == slsDetectorDefs::PUT_ACTION) { \
if (args.size() != 2) { \
WrongNumberOfParameters(2); \
} \
det->SETFCN(index, args[1]); \
os << ToString(args) << '\n'; \
} else { \
throw RuntimeError("Unknown action"); \
} \
return os.str(); \
}
#define CTB_GET_DACINDEX(CMDNAME, GETFCN, STARTINDEX, HLPSTR) \
std::string CMDNAME(const int action) { \
std::ostringstream os; \
os << cmd << ' '; \
if (action == slsDetectorDefs::HELP_ACTION) { \
os << HLPSTR << '\n'; \
return os.str(); \
} \
if (det->getDetectorType().squash() != defs::CHIPTESTBOARD) { \
throw RuntimeError(cmd + " only allowed for CTB."); \
} \
if (det_id != -1) { \
throw RuntimeError("Cannot configure " + cmd + \
" at module level"); \
} \
if (action == slsDetectorDefs::GET_ACTION) { \
if (args.size() != 1) { \
WrongNumberOfParameters(1); \
} \
auto t = det->GETFCN(args[0]); \
os << ToString(static_cast<int>(t) - STARTINDEX) << '\n'; \
} else if (action == slsDetectorDefs::PUT_ACTION) { \
throw RuntimeError("Cannot put"); \
} else { \
throw RuntimeError("Unknown action"); \
} \
return os.str(); \
}
#define CTB_SINGLE_NAME(CMDNAME, GETFCN, SETFCN, HLPSTR) \
std::string CMDNAME(const int action) { \
std::ostringstream os; \
@ -574,7 +641,7 @@ namespace sls {
WrongNumberOfParameters(1); \
} \
auto t = det->GETFCN(StringTo<int>(args[0])); \
os << args[0] << ' ' << ToString(t) << '\n'; \
os << args[0] << ' ' << t << '\n'; \
} else if (action == slsDetectorDefs::PUT_ACTION) { \
if (args.size() != 2) { \
WrongNumberOfParameters(2); \
@ -607,7 +674,7 @@ namespace sls {
WrongNumberOfParameters(1); \
} \
auto t = det->GETFCN(args[0]); \
os << ToString(t) << '\n'; \
os << ToString(static_cast<int>(t)) << '\n'; \
} else if (action == slsDetectorDefs::PUT_ACTION) { \
throw RuntimeError("Cannot put"); \
} else { \
@ -936,8 +1003,8 @@ class CmdProxy {
/* lists */
{"daclist", &CmdProxy::DacList},
{"dacname", &CmdProxy::DacName},
{"dacindex", &CmdProxy::DacIndex},
{"dacname", &CmdProxy::dacname},
{"dacindex", &CmdProxy::dacindex},
{"adclist", &CmdProxy::adclist},
{"adcname", &CmdProxy::adcname},
{"adcindex", &CmdProxy::adcindex},
@ -1252,8 +1319,6 @@ class CmdProxy {
std::string TemperatureValues(int action);
/* list */
std::string DacList(int action);
std::string DacName(int action);
std::string DacIndex(int action);
/* dacs */
std::string Dac(int action);
std::string DacValues(int action);
@ -1617,6 +1682,15 @@ class CmdProxy {
"[n_value]\n\t[Ctb]Temperature of the slow adc");
/* lists */
CTB_SINGLE_DACNAME(dacname, getDacName, setDacName, defs::DAC_0,
"\n\t[0-18][name] \n\t\t[ChipTestBoard] Set "
"the dac at the given position to the given name.");
CTB_GET_DACINDEX(dacindex, getDacIndex, defs::DAC_0,
"\n\t[name] \n\t\t[ChipTestBoard] Get "
"the dac index for the given name.");
CTB_NAMED_LIST(adclist, getAdcNames, setAdcNames,
"[adcname1 adcname2 .. adcname32] \n\t\t[ChipTestBoard] Set "
"the list of adc names for this board.");
@ -1647,26 +1721,26 @@ class CmdProxy {
"[powername1 powername2 .. powername4] \n\t\t[ChipTestBoard] Set "
"the list of power names for this board.");
CTB_SINGLE_NAME(powername, getPowerName, setPowerName,
"[0-31][name] \n\t\t[ChipTestBoard] Set "
"the power at the given position to the given name.");
CTB_SINGLE_DACNAME(powername, getPowerName, setPowerName, defs::V_POWER_A,
"[0-31][name] \n\t\t[ChipTestBoard] Set "
"the power at the given position to the given name.");
CTB_GET_INDEX(powerindex, getPowerIndex,
"[name] \n\t\t[ChipTestBoard] Get "
"the power index for the given name.");
CTB_GET_DACINDEX(powerindex, getPowerIndex, defs::V_POWER_A,
"[name] \n\t\t[ChipTestBoard] Get "
"the power index for the given name.");
CTB_NAMED_LIST(
senselist, getSenseNames, setSenseNames,
"[sensename1 sensename2 .. sensename7] \n\t\t[ChipTestBoard] Set "
"the list of sense names for this board.");
CTB_SINGLE_NAME(sensename, getSenseName, setSenseName,
"[0-31][name] \n\t\t[ChipTestBoard] Set "
"the sense at the given position to the given name.");
CTB_SINGLE_DACNAME(sensename, getSenseName, setSenseName, defs::SLOW_ADC0,
"[0-31][name] \n\t\t[ChipTestBoard] Set "
"the sense at the given position to the given name.");
CTB_GET_INDEX(senseindex, getSenseIndex,
"[name] \n\t\t[ChipTestBoard] Get "
"the sense index for the given name.");
CTB_GET_DACINDEX(senseindex, getSenseIndex, defs::SLOW_ADC0,
"[name] \n\t\t[ChipTestBoard] Get "
"the sense index for the given name.");
/* dacs */

View File

@ -31,41 +31,43 @@ CtbConfig::CtbConfig() {
}
void CtbConfig::check_dac_index(size_t i) const {
if (!(i < num_dacs)) {
if (i >= num_dacs) {
std::ostringstream oss;
oss << "DAC index is too large. Needs to be below " << num_dacs;
oss << "Invalid DAC index. Options: 0 - " << num_dacs;
throw RuntimeError(oss.str());
}
}
void CtbConfig::check_adc_index(size_t i) const {
if (!(i < num_adcs)) {
if (i >= num_adcs) {
std::ostringstream oss;
oss << "ADC index is too large.Needs to be below " << num_adcs;
oss << "Invalid ADC index. Options: 0 - " << num_adcs;
throw RuntimeError(oss.str());
}
}
void CtbConfig::check_signal_index(size_t i) const {
if (!(i < num_signals)) {
if (i >= num_signals) {
std::ostringstream oss;
oss << "Signal index is too large.Needs to be below " << num_signals;
oss << "Invalid Signal index. Options: 0 - " << num_signals;
throw RuntimeError(oss.str());
}
}
void CtbConfig::check_power_index(size_t i) const {
if (!(i < num_powers)) {
if (i >= num_powers) {
std::ostringstream oss;
oss << "Power index is too large.Needs to be below " << num_powers;
oss << "Invalid Power index. Options: 0 - " << num_signals
<< " or V_POWER_A - V_POWER_IO";
throw RuntimeError(oss.str());
}
}
void CtbConfig::check_sense_index(size_t i) const {
if (!(i < num_senses)) {
if (i >= num_senses) {
std::ostringstream oss;
oss << "Sense index is too large.Needs to be below " << num_senses;
oss << "Invalid Sense index. Options: 0 - " << num_senses
<< " or SLOW_ADC0 - SLOW_ADC7";
throw RuntimeError(oss.str());
}
}

View File

@ -2219,7 +2219,7 @@ std::vector<std::string> Detector::getDacNames() const {
return names;
}
defs::dacIndex Detector::getDacIndex(const std::string &name) {
defs::dacIndex Detector::getDacIndex(const std::string &name) const {
auto type = getDetectorType().squash();
if (type == defs::CHIPTESTBOARD) {
auto names = getDacNames();
@ -2231,13 +2231,13 @@ defs::dacIndex Detector::getDacIndex(const std::string &name) {
return StringTo<defs::dacIndex>(name);
}
void Detector::setDacName(defs::dacIndex i, const std::string &name) {
void Detector::setDacName(const 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(const defs::dacIndex i) const {
auto type = getDetectorType().squash();
if (type == defs::CHIPTESTBOARD)
return pimpl->getCtbDacName(i);
@ -2256,7 +2256,7 @@ std::vector<std::string> Detector::getAdcNames() const {
return pimpl->getCtbAdcNames();
}
int Detector::getAdcIndex(const std::string &name) {
int Detector::getAdcIndex(const std::string &name) const {
if (getDetectorType().squash() != defs::CHIPTESTBOARD)
throw RuntimeError("Named adcs only for CTB");
auto names = getAdcNames();
@ -2272,7 +2272,7 @@ void Detector::setAdcName(const int index, const std::string &name) {
pimpl->setCtbAdcName(index, name);
}
std::string Detector::getAdcName(int i) {
std::string Detector::getAdcName(const int i) const {
if (getDetectorType().squash() != defs::CHIPTESTBOARD)
throw RuntimeError("Named adcs only for CTB");
return pimpl->getCtbAdcName(i);
@ -2290,7 +2290,7 @@ std::vector<std::string> Detector::getSignalNames() const {
return pimpl->getCtbSignalNames();
}
int Detector::getSignalIndex(const std::string &name) {
int Detector::getSignalIndex(const std::string &name) const {
if (getDetectorType().squash() != defs::CHIPTESTBOARD)
throw RuntimeError("Named signals only for CTB");
auto names = getSignalNames();
@ -2306,7 +2306,7 @@ void Detector::setSignalName(const int index, const std::string &name) {
pimpl->setCtbSignalName(index, name);
}
std::string Detector::getSignalName(int i) {
std::string Detector::getSignalName(const int i) const {
if (getDetectorType().squash() != defs::CHIPTESTBOARD)
throw RuntimeError("Named signals only for CTB");
return pimpl->getCtbSignalName(i);
@ -2324,23 +2324,24 @@ std::vector<std::string> Detector::getPowerNames() const {
return pimpl->getCtbPowerNames();
}
int Detector::getPowerIndex(const std::string &name) {
defs::dacIndex Detector::getPowerIndex(const std::string &name) const {
if (getDetectorType().squash() != defs::CHIPTESTBOARD)
throw RuntimeError("Named powers only for CTB");
auto names = getPowerNames();
auto it = std::find(names.begin(), names.end(), name);
if (it == names.end())
throw RuntimeError("Power name not found");
return (it - names.begin());
return static_cast<defs::dacIndex>(it - names.begin() + defs::V_POWER_A);
}
void Detector::setPowerName(const int index, const std::string &name) {
void Detector::setPowerName(const defs::dacIndex index,
const std::string &name) {
if (getDetectorType().squash() != defs::CHIPTESTBOARD)
throw RuntimeError("Named powers only for CTB");
pimpl->setCtbPowerName(index, name);
}
std::string Detector::getPowerName(int i) {
std::string Detector::getPowerName(const defs::dacIndex i) const {
if (getDetectorType().squash() != defs::CHIPTESTBOARD)
throw RuntimeError("Named powers only for CTB");
return pimpl->getCtbPowerName(i);
@ -2358,23 +2359,24 @@ std::vector<std::string> Detector::getSenseNames() const {
return pimpl->getCtbSenseNames();
}
int Detector::getSenseIndex(const std::string &name) {
defs::dacIndex Detector::getSenseIndex(const std::string &name) const {
if (getDetectorType().squash() != defs::CHIPTESTBOARD)
throw RuntimeError("Named senses only for CTB");
auto names = getSenseNames();
auto it = std::find(names.begin(), names.end(), name);
if (it == names.end())
throw RuntimeError("Sense name not found");
return (it - names.begin());
return static_cast<defs::dacIndex>(it - names.begin() + defs::SLOW_ADC0);
}
void Detector::setSenseName(const int index, const std::string &name) {
void Detector::setSenseName(const defs::dacIndex index,
const std::string &name) {
if (getDetectorType().squash() != defs::CHIPTESTBOARD)
throw RuntimeError("Named senses only for CTB");
pimpl->setCtbSenseName(index, name);
}
std::string Detector::getSenseName(int i) {
std::string Detector::getSenseName(const defs::dacIndex i) const {
if (getDetectorType().squash() != defs::CHIPTESTBOARD)
throw RuntimeError("Named senses only for CTB");
return pimpl->getCtbSenseName(i);

View File

@ -2001,7 +2001,8 @@ 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) {
void DetectorImpl::setCtbDacName(const defs::dacIndex index,
const std::string &name) {
ctb_shm()->setDacName(index, name);
}
@ -2013,7 +2014,7 @@ void DetectorImpl::setCtbAdcNames(const std::vector<std::string> &names) {
ctb_shm()->setAdcNames(names);
}
std::string DetectorImpl::getCtbAdcName(int i) const {
std::string DetectorImpl::getCtbAdcName(const int i) const {
return ctb_shm()->getAdcName(i);
}
@ -2029,7 +2030,7 @@ void DetectorImpl::setCtbSignalNames(const std::vector<std::string> &names) {
ctb_shm()->setSignalNames(names);
}
std::string DetectorImpl::getCtbSignalName(int i) const {
std::string DetectorImpl::getCtbSignalName(const int i) const {
return ctb_shm()->getSignalName(i);
}
@ -2045,12 +2046,13 @@ void DetectorImpl::setCtbPowerNames(const std::vector<std::string> &names) {
ctb_shm()->setPowerNames(names);
}
std::string DetectorImpl::getCtbPowerName(int i) const {
return ctb_shm()->getPowerName(i);
std::string DetectorImpl::getCtbPowerName(const defs::dacIndex i) const {
return ctb_shm()->getPowerName(static_cast<int>(i - defs::V_POWER_A));
}
void DetectorImpl::setCtbPowerName(const int index, const std::string &name) {
ctb_shm()->setPowerName(index, name);
void DetectorImpl::setCtbPowerName(const defs::dacIndex index,
const std::string &name) {
ctb_shm()->setPowerName(static_cast<int>(index - defs::V_POWER_A), name);
}
std::vector<std::string> DetectorImpl::getCtbSenseNames() const {
@ -2061,12 +2063,13 @@ void DetectorImpl::setCtbSenseNames(const std::vector<std::string> &names) {
ctb_shm()->setSenseNames(names);
}
std::string DetectorImpl::getCtbSenseName(int i) const {
return ctb_shm()->getSenseName(i);
std::string DetectorImpl::getCtbSenseName(const defs::dacIndex i) const {
return ctb_shm()->getSenseName(static_cast<int>(i - defs::SLOW_ADC0));
}
void DetectorImpl::setCtbSenseName(const int index, const std::string &name) {
ctb_shm()->setSenseName(index, name);
void DetectorImpl::setCtbSenseName(const defs::dacIndex index,
const std::string &name) {
ctb_shm()->setSenseName(static_cast<int>(index - defs::SLOW_ADC0), name);
}
} // namespace sls

View File

@ -326,29 +326,29 @@ class DetectorImpl : public virtual slsDetectorDefs {
void setBadChannels(const std::vector<int> list, Positions pos);
std::vector<std::string> getCtbDacNames() const;
std::string getCtbDacName(defs::dacIndex i) const;
std::string getCtbDacName(const defs::dacIndex i) const;
void setCtbDacNames(const std::vector<std::string> &names);
void setCtbDacName(const int index, const std::string &name);
void setCtbDacName(const defs::dacIndex index, const std::string &name);
std::vector<std::string> getCtbAdcNames() const;
std::string getCtbAdcName(int i) const;
std::string getCtbAdcName(const int i) const;
void setCtbAdcNames(const std::vector<std::string> &names);
void setCtbAdcName(const int index, const std::string &name);
std::vector<std::string> getCtbSignalNames() const;
std::string getCtbSignalName(int i) const;
std::string getCtbSignalName(const int i) const;
void setCtbSignalNames(const std::vector<std::string> &names);
void setCtbSignalName(const int index, const std::string &name);
std::vector<std::string> getCtbPowerNames() const;
std::string getCtbPowerName(int i) const;
std::string getCtbPowerName(const defs::dacIndex i) const;
void setCtbPowerNames(const std::vector<std::string> &names);
void setCtbPowerName(const int index, const std::string &name);
void setCtbPowerName(const defs::dacIndex index, const std::string &name);
std::vector<std::string> getCtbSenseNames() const;
std::string getCtbSenseName(int i) const;
std::string getCtbSenseName(const defs::dacIndex i) const;
void setCtbSenseNames(const std::vector<std::string> &names);
void setCtbSenseName(const int index, const std::string &name);
void setCtbSenseName(const defs::dacIndex index, const std::string &name);
private:
/**