mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 10:07:59 +02:00
Get trimbits (#462)
* added the possibility to save settings file for m3 and eiger * added save trimbits to gui * update release notes * python wip * moved location of trimbits save option in gui * python works * updating getModule with all its parameters in the server side * updating binaries
This commit is contained in:
@ -159,6 +159,10 @@ class Detector {
|
||||
* is attached. */
|
||||
void loadTrimbits(const std::string &fname, Positions pos = {});
|
||||
|
||||
/** [Eiger][Mythen3] If no extension specified, serial number of each module
|
||||
* is attached. */
|
||||
void saveTrimbits(const std::string &fname, Positions pos = {});
|
||||
|
||||
/** [Eiger][Mythen3] -1 if they are all different */
|
||||
Result<int> getAllTrimbits(Positions pos = {}) const;
|
||||
|
||||
|
@ -452,6 +452,31 @@ std::string CmdProxy::Threshold(int action) {
|
||||
return os.str();
|
||||
}
|
||||
|
||||
std::string CmdProxy::Trimbits(int action) {
|
||||
std::ostringstream os;
|
||||
os << cmd << ' ';
|
||||
if (action == defs::HELP_ACTION) {
|
||||
os << "[fname]\n\t[Eiger][Mythen3] Put will load the trimbit file to detector. If no extension specified, serial number of each module is attached. Get will save the trimbits from the detector to file with serial number added to file name."
|
||||
<< '\n';
|
||||
} else if (action == defs::GET_ACTION) {
|
||||
if (args.size() != 1) {
|
||||
WrongNumberOfParameters(1);
|
||||
}
|
||||
det->saveTrimbits(args[0], std::vector<int>{det_id});
|
||||
os << args << '\n';
|
||||
} else if (action == defs::PUT_ACTION) {
|
||||
if (args.size() != 1) {
|
||||
WrongNumberOfParameters(1);
|
||||
}
|
||||
det->loadTrimbits(args[0], std::vector<int>{det_id});
|
||||
os << args << '\n';
|
||||
} else {
|
||||
throw RuntimeError("Unknown action");
|
||||
}
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
||||
std::string CmdProxy::TrimEnergies(int action) {
|
||||
std::ostringstream os;
|
||||
os << cmd << ' ';
|
||||
|
@ -782,7 +782,7 @@ class CmdProxy {
|
||||
{"threshold", &CmdProxy::Threshold},
|
||||
{"thresholdnotb", &CmdProxy::Threshold},
|
||||
{"settingspath", &CmdProxy::settingspath},
|
||||
{"trimbits", &CmdProxy::trimbits},
|
||||
{"trimbits", &CmdProxy::Trimbits},
|
||||
{"trimval", &CmdProxy::trimval},
|
||||
{"trimen", &CmdProxy::TrimEnergies},
|
||||
{"gappixels", &CmdProxy::GapPixels},
|
||||
@ -1115,6 +1115,7 @@ class CmdProxy {
|
||||
std::string ClientVersion(int action);
|
||||
std::string DetectorSize(int action);
|
||||
std::string Threshold(int action);
|
||||
std::string Trimbits(int action);
|
||||
std::string TrimEnergies(int action);
|
||||
std::string GapPixels(int action);
|
||||
/* acquisition parameters */
|
||||
@ -1273,11 +1274,6 @@ class CmdProxy {
|
||||
"[path]\n\t[Eiger][Mythen3] Directory where settings files "
|
||||
"are loaded from/to.");
|
||||
|
||||
EXECUTE_SET_COMMAND_1ARG(
|
||||
trimbits, loadTrimbits,
|
||||
"[fname]\n\t[Eiger][Mythen3] Loads the trimbit file to detector. If no "
|
||||
"extension specified, serial number of each module is attached.");
|
||||
|
||||
INTEGER_COMMAND_VEC_ID(
|
||||
trimval, getAllTrimbits, setAllTrimbits, StringTo<int>,
|
||||
"[n_trimval]\n\t[Eiger][Mythen3] All trimbits set to this "
|
||||
|
@ -273,6 +273,10 @@ void Detector::loadTrimbits(const std::string &fname, Positions pos) {
|
||||
pimpl->Parallel(&Module::loadTrimbits, pos, fname);
|
||||
}
|
||||
|
||||
void Detector::saveTrimbits(const std::string &fname, Positions pos) {
|
||||
pimpl->Parallel(&Module::saveTrimbits, pos, fname);
|
||||
}
|
||||
|
||||
Result<int> Detector::getAllTrimbits(Positions pos) const {
|
||||
return pimpl->Parallel(&Module::getAllTrimbits, pos);
|
||||
}
|
||||
|
@ -468,6 +468,27 @@ void Module::loadTrimbits(const std::string &fname) {
|
||||
}
|
||||
}
|
||||
|
||||
void Module::saveTrimbits(const std::string &fname) {
|
||||
// find specific file if it has detid in file name (.snxxx)
|
||||
if (shm()->detType == EIGER || shm()->detType == MYTHEN3) {
|
||||
std::ostringstream ostfn;
|
||||
ostfn << fname;
|
||||
int moduleIdWidth = 3;
|
||||
if (shm()->detType == MYTHEN3) {
|
||||
moduleIdWidth = 4;
|
||||
}
|
||||
if ((fname.find(".sn") == std::string::npos) &&
|
||||
(fname.find(".trim") == std::string::npos)) {
|
||||
ostfn << ".sn" << std::setfill('0') << std::setw(moduleIdWidth)
|
||||
<< std::dec << getModuleId();
|
||||
}
|
||||
auto myMod = getModule();
|
||||
saveSettingsFile(myMod, ostfn.str());
|
||||
} else {
|
||||
throw RuntimeError("not implemented for this detector");
|
||||
}
|
||||
}
|
||||
|
||||
int Module::getAllTrimbits() const {
|
||||
return sendToDetector<int>(F_SET_ALL_TRIMBITS, GET_FLAG);
|
||||
}
|
||||
@ -3310,7 +3331,36 @@ void Module::checkReceiverVersionCompatibility() {
|
||||
sendToReceiver(F_RECEIVER_CHECK_VERSION, int64_t(APIRECEIVER), nullptr);
|
||||
}
|
||||
|
||||
int Module::sendModule(sls_detector_module *myMod, ClientSocket &client) {
|
||||
void Module::setModule(sls_detector_module &module, bool trimbits) {
|
||||
LOG(logDEBUG1) << "Setting module with trimbits:" << trimbits;
|
||||
// to exclude trimbits
|
||||
if (!trimbits) {
|
||||
module.nchan = 0;
|
||||
module.nchip = 0;
|
||||
}
|
||||
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
|
||||
client.Send(F_SET_MODULE);
|
||||
sendModule(&module, client);
|
||||
if (client.Receive<int>() == FAIL) {
|
||||
throw DetectorError("Module " + std::to_string(moduleIndex) +
|
||||
" returned error: " + client.readErrorMessage());
|
||||
}
|
||||
}
|
||||
|
||||
sls_detector_module Module::getModule() {
|
||||
LOG(logDEBUG1) << "Getting module";
|
||||
sls_detector_module module(shm()->detType);
|
||||
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
|
||||
client.Send(F_GET_MODULE);
|
||||
if (client.Receive<int>() == FAIL) {
|
||||
throw DetectorError("Module " + std::to_string(moduleIndex) +
|
||||
" returned error: " + client.readErrorMessage());
|
||||
}
|
||||
receiveModule(&module, client);
|
||||
return module;
|
||||
}
|
||||
|
||||
void Module::sendModule(sls_detector_module *myMod, ClientSocket &client) {
|
||||
constexpr TLogLevel level = logDEBUG1;
|
||||
LOG(level) << "Sending Module";
|
||||
int ts = 0;
|
||||
@ -3353,28 +3403,41 @@ int Module::sendModule(sls_detector_module *myMod, ClientSocket &client) {
|
||||
ts += n;
|
||||
LOG(level) << "dacs sent. " << n << " bytes";
|
||||
|
||||
if (shm()->detType == EIGER || shm()->detType == MYTHEN3) {
|
||||
n = client.Send(myMod->chanregs, sizeof(int) * (myMod->nchan));
|
||||
ts += n;
|
||||
LOG(level) << "channels sent. " << n << " bytes";
|
||||
n = client.Send(myMod->chanregs, sizeof(int) * (myMod->nchan));
|
||||
ts += n;
|
||||
LOG(level) << "channels sent. " << n << " bytes";
|
||||
|
||||
int expectedBytesSent = sizeof(sls_detector_module) - sizeof(myMod->dacs) - sizeof(myMod->chanregs) + (myMod->ndac * sizeof(int)) + (myMod->nchan * sizeof(int));
|
||||
|
||||
if (expectedBytesSent != ts) {
|
||||
throw RuntimeError("Module size " + std::to_string(ts) + " sent does not match expected size to be sent " + std::to_string(expectedBytesSent));
|
||||
}
|
||||
return ts;
|
||||
}
|
||||
|
||||
void Module::setModule(sls_detector_module &module, bool trimbits) {
|
||||
LOG(logDEBUG1) << "Setting module with trimbits:" << trimbits;
|
||||
// to exclude trimbits
|
||||
if (!trimbits) {
|
||||
module.nchan = 0;
|
||||
module.nchip = 0;
|
||||
}
|
||||
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
|
||||
client.Send(F_SET_MODULE);
|
||||
sendModule(&module, client);
|
||||
if (client.Receive<int>() == FAIL) {
|
||||
throw DetectorError("Module " + std::to_string(moduleIndex) +
|
||||
" returned error: " + client.readErrorMessage());
|
||||
}
|
||||
|
||||
void Module::receiveModule(sls_detector_module *myMod, ClientSocket &client) {
|
||||
constexpr TLogLevel level = logDEBUG1;
|
||||
LOG(level) << "Receiving Module";
|
||||
myMod->serialnumber = client.Receive<int>();
|
||||
LOG(level) << "serialno: " << myMod->serialnumber;
|
||||
myMod->nchan = client.Receive<int>();
|
||||
LOG(level) << "nchan: " << myMod->nchan;
|
||||
myMod->nchip = client.Receive<int>();
|
||||
LOG(level) << "nchip: " << myMod->nchip;
|
||||
myMod->ndac = client.Receive<int>();
|
||||
LOG(level) << "ndac: " << myMod->ndac;
|
||||
myMod->reg = client.Receive<int>();
|
||||
LOG(level) << "reg: " << myMod->reg;
|
||||
myMod->iodelay = client.Receive<int>();
|
||||
LOG(level) << "iodelay: " << myMod->iodelay;
|
||||
myMod->tau = client.Receive<int>();
|
||||
LOG(level) << "tau: " << myMod->tau;
|
||||
client.Receive(myMod->eV);
|
||||
LOG(level) << "eV: " << ToString(myMod->eV);
|
||||
client.Receive(myMod->dacs, sizeof(int) * (myMod->ndac));
|
||||
LOG(level) << myMod->ndac << " dacs received";
|
||||
client.Receive(myMod->chanregs, sizeof(int) * (myMod->nchan));
|
||||
LOG(level) << myMod->nchan << " chans received";
|
||||
}
|
||||
|
||||
void Module::updateReceiverStreamingIP() {
|
||||
@ -3615,10 +3678,39 @@ sls_detector_module Module::readSettingsFile(const std::string &fname,
|
||||
else {
|
||||
throw RuntimeError("Not implemented for this detector");
|
||||
}
|
||||
LOG(logINFO) << "Settings file loaded: " << fname.c_str();
|
||||
LOG(logINFO) << "Settings file loaded: " << fname;
|
||||
return myMod;
|
||||
}
|
||||
|
||||
void Module::saveSettingsFile(sls_detector_module &myMod, const std::string &fname) {
|
||||
LOG(logDEBUG1) << moduleIndex << ": Saving settings to " << fname;
|
||||
std::ofstream outfile(fname);
|
||||
if (!outfile) {
|
||||
throw RuntimeError("Could not write settings file: " + fname);
|
||||
}
|
||||
switch (shm()->detType) {
|
||||
case MYTHEN3:
|
||||
outfile.write(reinterpret_cast<char *>(&myMod.reg), sizeof(myMod.reg));
|
||||
outfile.write(reinterpret_cast<char *>(myMod.dacs),
|
||||
sizeof(int) * (myMod.ndac));
|
||||
outfile.write(reinterpret_cast<char *>(myMod.chanregs),
|
||||
sizeof(int) * (myMod.nchan));
|
||||
break;
|
||||
case EIGER:
|
||||
outfile.write(reinterpret_cast<char *>(myMod.dacs),
|
||||
sizeof(int) * (myMod.ndac));
|
||||
outfile.write(reinterpret_cast<char *>(&myMod.iodelay),
|
||||
sizeof(myMod.iodelay));
|
||||
outfile.write(reinterpret_cast<char *>(&myMod.tau), sizeof(myMod.tau));
|
||||
outfile.write(reinterpret_cast<char *>(myMod.chanregs),
|
||||
sizeof(int) * (myMod.nchan));
|
||||
break;
|
||||
default:
|
||||
throw RuntimeError("Saving settings file is not implemented for this detector.");
|
||||
}
|
||||
LOG(logINFO) << "Settings for " << shm()->hostname << " written to " << fname;
|
||||
}
|
||||
|
||||
void Module::sendProgram(bool blackfin, std::vector<char> buffer,
|
||||
const int functionEnum,
|
||||
const std::string &functionType,
|
||||
|
@ -114,6 +114,7 @@ class Module : public virtual slsDetectorDefs {
|
||||
std::string getSettingsDir() const;
|
||||
std::string setSettingsDir(const std::string &dir);
|
||||
void loadTrimbits(const std::string &fname);
|
||||
void saveTrimbits(const std::string &fname);
|
||||
int getAllTrimbits() const;
|
||||
void setAllTrimbits(int val);
|
||||
std::vector<int> getTrimEn() const;
|
||||
@ -736,7 +737,9 @@ class Module : public virtual slsDetectorDefs {
|
||||
void checkDetectorVersionCompatibility();
|
||||
void checkReceiverVersionCompatibility();
|
||||
void setModule(sls_detector_module &module, bool trimbits = true);
|
||||
int sendModule(sls_detector_module *myMod, ClientSocket &client);
|
||||
sls_detector_module getModule();
|
||||
void sendModule(sls_detector_module *myMod, ClientSocket &client);
|
||||
void receiveModule(sls_detector_module *myMod, ClientSocket &client);
|
||||
void updateReceiverStreamingIP();
|
||||
|
||||
void updateRateCorrection();
|
||||
@ -770,6 +773,7 @@ class Module : public virtual slsDetectorDefs {
|
||||
std::string getTrimbitFilename(detectorSettings settings, int e_eV);
|
||||
sls_detector_module readSettingsFile(const std::string &fname,
|
||||
bool trimbits = true);
|
||||
void saveSettingsFile(sls_detector_module &myMod, const std::string &fname);
|
||||
void sendProgram(bool blackfin, std::vector<char> buffer,
|
||||
const int functionEnum, const std::string &functionType,
|
||||
const std::string serverName = "",
|
||||
|
Reference in New Issue
Block a user