mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-26 16:20:03 +02:00
Hacky implementation
This commit is contained in:
parent
74d55db3f0
commit
2823451c9d
@ -59,6 +59,9 @@ class DetectorDacs:
|
||||
def __getattr__(self, name):
|
||||
return self.__getattribute__('_' + name)
|
||||
|
||||
@property
|
||||
def dacnames(self):
|
||||
return [_d[0] for _d in _dacs]
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
if name in self._dacnames:
|
||||
|
@ -1427,6 +1427,20 @@ void init_det(py::module &m) {
|
||||
(void (Detector::*)(bool, sls::Positions)) &
|
||||
Detector::setLEDEnable,
|
||||
py::arg(), py::arg() = Positions{})
|
||||
.def("setDacNames",
|
||||
(void (Detector::*)(const std::vector<std::string>)) &
|
||||
Detector::setDacNames,
|
||||
py::arg())
|
||||
.def("getDacNames", (std::vector<std::string>(Detector::*)() const) &
|
||||
Detector::getDacNames)
|
||||
.def("decodeNamedDac",
|
||||
(defs::dacIndex(Detector::*)(const std::string &)) &
|
||||
Detector::decodeNamedDac,
|
||||
py::arg())
|
||||
.def("decodeNamedDac",
|
||||
(std::string(Detector::*)(defs::dacIndex)) &
|
||||
Detector::decodeNamedDac,
|
||||
py::arg())
|
||||
.def("setPattern",
|
||||
(void (Detector::*)(const std::string &, sls::Positions)) &
|
||||
Detector::setPattern,
|
||||
|
@ -1613,6 +1613,14 @@ class Detector {
|
||||
|
||||
/** [CTB] Default is enabled. */
|
||||
void setLEDEnable(bool enable, Positions pos = {});
|
||||
|
||||
|
||||
void setDacNames(const std::vector<std::string> names);
|
||||
|
||||
std::vector<std::string> getDacNames() const;
|
||||
|
||||
defs::dacIndex decodeNamedDac(const std::string& name);
|
||||
std::string decodeNamedDac(defs::dacIndex i);
|
||||
///@}
|
||||
|
||||
/** @name Pattern */
|
||||
|
@ -1056,11 +1056,11 @@ std::string CmdProxy::TemperatureValues(int action) {
|
||||
std::string CmdProxy::Dac(int action) {
|
||||
std::ostringstream os;
|
||||
os << cmd << ' ';
|
||||
|
||||
auto type = det->getDetectorType().squash();
|
||||
// dac indices only for ctb
|
||||
if (args.size() > 0 && action != defs::HELP_ACTION) {
|
||||
if (is_int(args[0]) &&
|
||||
det->getDetectorType().squash() != defs::CHIPTESTBOARD) {
|
||||
type != defs::CHIPTESTBOARD) {
|
||||
throw sls::RuntimeError(
|
||||
"Dac indices can only be used for chip test board. Use daclist "
|
||||
"to get list of dac names for current detector.");
|
||||
@ -1077,7 +1077,13 @@ std::string CmdProxy::Dac(int action) {
|
||||
if (args.empty())
|
||||
WrongNumberOfParameters(1); // This prints slightly wrong
|
||||
|
||||
defs::dacIndex dacIndex = StringTo<defs::dacIndex>(args[0]);
|
||||
defs::dacIndex dacIndex{};
|
||||
if (type == defs::CHIPTESTBOARD && !is_int(args[0])){
|
||||
dacIndex = det->decodeNamedDac(args[0]);
|
||||
}else{
|
||||
dacIndex = StringTo<defs::dacIndex>(args[0]);
|
||||
}
|
||||
|
||||
bool mV = false;
|
||||
|
||||
if (args.size() == 2) {
|
||||
@ -1095,7 +1101,11 @@ std::string CmdProxy::Dac(int action) {
|
||||
if (args.empty())
|
||||
WrongNumberOfParameters(1); // This prints slightly wrong
|
||||
|
||||
defs::dacIndex dacIndex = StringTo<defs::dacIndex>(args[0]);
|
||||
defs::dacIndex dacIndex{};
|
||||
if (type == defs::CHIPTESTBOARD && !is_int(args[0]))
|
||||
dacIndex = det->decodeNamedDac(args[0]);
|
||||
else
|
||||
dacIndex = StringTo<defs::dacIndex>(args[0]);
|
||||
bool mV = false;
|
||||
if (args.size() == 3) {
|
||||
if ((args[2] != "mv") && (args[2] != "mV")) {
|
||||
@ -1134,13 +1144,15 @@ std::string CmdProxy::DacValues(int action) {
|
||||
WrongNumberOfParameters(1);
|
||||
}
|
||||
auto t = det->getDacList();
|
||||
auto names = det->getDacNames();
|
||||
auto name_it = names.begin();
|
||||
os << '[';
|
||||
auto it = t.cbegin();
|
||||
os << ToString(*it) << ' ';
|
||||
os << ToString(*name_it++) << ' ';
|
||||
os << OutString(det->getDAC(*it++, mv, std::vector<int>{det_id}))
|
||||
<< (!args.empty() ? " mV" : "");
|
||||
while (it != t.cend()) {
|
||||
os << ", " << ToString(*it) << ' ';
|
||||
os << ", " << ToString(*name_it++) << ' ';
|
||||
os << OutString(det->getDAC(*it++, mv, std::vector<int>{det_id}))
|
||||
<< (!args.empty() ? " mV" : "");
|
||||
}
|
||||
|
@ -1466,7 +1466,7 @@ class CmdProxy {
|
||||
/* dacs */
|
||||
|
||||
GET_COMMAND_NOID(
|
||||
daclist, getDacList,
|
||||
daclist, getDacNames,
|
||||
"\n\tGets the list of commands for every dac for this detector.");
|
||||
|
||||
/* on chip dacs */
|
||||
|
@ -2067,6 +2067,69 @@ void Detector::setLEDEnable(bool enable, Positions pos) {
|
||||
pimpl->Parallel(&Module::setLEDEnable, pos, enable);
|
||||
}
|
||||
|
||||
void Detector::setDacNames(const std::vector<std::string> names) {
|
||||
if (getDetectorType().squash() != defs::CHIPTESTBOARD)
|
||||
throw RuntimeError("Named dacs only for CTB");
|
||||
if (names.size() != 18)
|
||||
throw RuntimeError("Need to set all 18 dacs when naming dacs");
|
||||
|
||||
std::ofstream ofs("/dev/shm/slsDetectorPackage_ctbdacnames");
|
||||
if (!ofs)
|
||||
throw RuntimeError("Failed to open dacnames file in shared memory");
|
||||
|
||||
std::string s = sls::ToString(names);
|
||||
ofs.write(&s[0], s.size());
|
||||
}
|
||||
|
||||
std::vector<std::string> Detector::getDacNames() const {
|
||||
|
||||
auto type = getDetectorType().squash();
|
||||
if (type == defs::CHIPTESTBOARD) {
|
||||
try {
|
||||
std::ifstream ifs("/dev/shm/slsDetectorPackage_ctbdacnames");
|
||||
if (!ifs)
|
||||
throw RuntimeError("Could not read dacnames form shm");
|
||||
std::string dacnames;
|
||||
ifs.seekg(0, std::ios::end);
|
||||
dacnames.resize(ifs.tellg());
|
||||
ifs.seekg(0, std::ios::beg);
|
||||
ifs.read(&dacnames[0], dacnames.size());
|
||||
|
||||
std::string chars = "[] ";
|
||||
|
||||
dacnames.erase(std::remove_if(dacnames.begin(), dacnames.end(),
|
||||
[&chars](const char &c) {
|
||||
return chars.find(c) !=
|
||||
std::string::npos;
|
||||
}),
|
||||
dacnames.end());
|
||||
auto names = sls::split(dacnames, ',');
|
||||
return names;
|
||||
} catch (...) {
|
||||
}
|
||||
}
|
||||
std::vector<std::string> names;
|
||||
for (const auto& index : getDacList())
|
||||
names.push_back(ToString(index));
|
||||
return names;
|
||||
}
|
||||
|
||||
defs::dacIndex Detector::decodeNamedDac(const std::string &name) {
|
||||
auto names = getDacNames();
|
||||
auto it = std::find(names.begin(), names.end(), name);
|
||||
if (it == names.end())
|
||||
throw RuntimeError("Dacname not found");
|
||||
return static_cast<defs::dacIndex>(it - names.begin());
|
||||
}
|
||||
|
||||
std::string Detector::decodeNamedDac(defs::dacIndex i) {
|
||||
auto names = getDacNames();
|
||||
auto index = static_cast<size_t>(i);
|
||||
if (index > names.size())
|
||||
throw RuntimeError("Dac index out of range");
|
||||
return names[index];
|
||||
}
|
||||
|
||||
// Pattern
|
||||
|
||||
void Detector::setPattern(const std::string &fname, Positions pos) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user