mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-04 00:50:42 +02:00
added patfname command to save the file the last pttern was loaded from (#770)
* added patfname command to save the file the last pttern was loaded from
This commit is contained in:
parent
e18c191247
commit
58cdb5bd20
@ -3412,6 +3412,13 @@ class Detector(CppDetectorApi):
|
||||
fname = ut.make_string_path(fname)
|
||||
ut.set_using_dict(self.setPattern, fname)
|
||||
|
||||
@property
|
||||
def patfname(self):
|
||||
"""
|
||||
[Ctb][Mythen3] Gets the pattern file name including path of the last pattern uploaded. Returns an empty if nothing was uploaded or via a server default
|
||||
file
|
||||
"""
|
||||
return self.getPatterFileName()
|
||||
|
||||
@property
|
||||
@element
|
||||
|
@ -1737,6 +1737,11 @@ void init_det(py::module &m) {
|
||||
(std::string(Detector::*)(const defs::dacIndex) const) &
|
||||
Detector::getSlowAdcName,
|
||||
py::arg());
|
||||
CppDetectorApi.def(
|
||||
"getPatterFileName",
|
||||
(Result<std::string>(Detector::*)(sls::Positions) const) &
|
||||
Detector::getPatterFileName,
|
||||
py::arg() = Positions{});
|
||||
CppDetectorApi.def(
|
||||
"setPattern",
|
||||
(void (Detector::*)(const std::string &, sls::Positions)) &
|
||||
|
Binary file not shown.
Binary file not shown.
@ -1375,7 +1375,7 @@ int setTrimbits(int *trimbits) {
|
||||
error = 1;
|
||||
} else {
|
||||
memset(cmess, 0, MAX_STR_LENGTH);
|
||||
error |= loadPattern(cmess, logDEBUG5, pat);
|
||||
error |= loadPattern(cmess, logDEBUG5, pat, "");
|
||||
if (!error)
|
||||
startPattern();
|
||||
free(pat);
|
||||
@ -2827,7 +2827,7 @@ int setChipStatusRegister(int csr) {
|
||||
iret = FAIL;
|
||||
} else {
|
||||
memset(cmess, 0, MAX_STR_LENGTH);
|
||||
iret = loadPattern(cmess, logDEBUG5, pat);
|
||||
iret = loadPattern(cmess, logDEBUG5, pat, "");
|
||||
if (iret == OK) {
|
||||
startPattern();
|
||||
LOG(logINFO, ("CSR is now: 0x%x\n", csr));
|
||||
|
@ -54,8 +54,9 @@ uint64_t getPatternBitMask();
|
||||
#ifdef MYTHEN3D
|
||||
void startPattern();
|
||||
#endif
|
||||
|
||||
int loadPattern(char *mess, enum TLogLevel printLevel, patternParameters *pat);
|
||||
char *getPatternFileName();
|
||||
int loadPattern(char *mess, enum TLogLevel printLevel, patternParameters *pat,
|
||||
char *patfname);
|
||||
int getPattern(char *mess, patternParameters *pat);
|
||||
int loadPatternFile(char *patFname, char *errMessage);
|
||||
|
||||
|
@ -226,6 +226,7 @@ int get_gate_delay_all_gates(int);
|
||||
int get_veto(int);
|
||||
int set_veto(int);
|
||||
int set_pattern(int);
|
||||
int get_pattern_file(int);
|
||||
int get_scan(int);
|
||||
int set_scan(int);
|
||||
int get_scan_error_message(int);
|
||||
|
@ -32,6 +32,8 @@ extern void setU64BitReg(uint64_t value, int aLSB, int aMSB);
|
||||
#define MAX_LEVELS MAX_PATTERN_LEVELS
|
||||
#endif
|
||||
|
||||
char clientPatternfile[MAX_STR_LENGTH];
|
||||
|
||||
void initializePatternAddresses() {
|
||||
LOG(logDEBUG1, ("Setting default Loop and Wait Addresses(0x%x)\n",
|
||||
MAX_PATTERN_LENGTH - 1));
|
||||
@ -747,10 +749,15 @@ void startPattern() {
|
||||
}
|
||||
#endif
|
||||
|
||||
char *getPatternFileName() { return clientPatternfile; }
|
||||
|
||||
int loadPattern(char *message, enum TLogLevel printLevel,
|
||||
patternParameters *pat) {
|
||||
patternParameters *pat, char *patfname) {
|
||||
LOG(logINFOBLUE, ("Loading Pattern from structure\n"));
|
||||
int ret = OK;
|
||||
memset(clientPatternfile, 0, MAX_STR_LENGTH);
|
||||
memcpy(clientPatternfile, patfname, MAX_STR_LENGTH);
|
||||
printf("Client Pattern File:%s\n", clientPatternfile);
|
||||
#ifdef MYTHEN3D
|
||||
trimmingPrint = printLevel;
|
||||
#endif
|
||||
|
@ -397,6 +397,7 @@ void function_table() {
|
||||
flist[F_GET_VETO] = &get_veto;
|
||||
flist[F_SET_VETO] = &set_veto;
|
||||
flist[F_SET_PATTERN] = &set_pattern;
|
||||
flist[F_GET_PATTERN_FILE_NAME] = &get_pattern_file;
|
||||
flist[F_GET_SCAN] = &get_scan;
|
||||
flist[F_SET_SCAN] = &set_scan;
|
||||
flist[F_GET_SCAN_ERROR_MESSAGE] = &get_scan_error_message;
|
||||
@ -7604,6 +7605,8 @@ int set_veto(int file_des) {
|
||||
int set_pattern(int file_des) {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
char args[MAX_STR_LENGTH];
|
||||
memset(args, 0, MAX_STR_LENGTH);
|
||||
|
||||
#if !defined(CHIPTESTBOARDD) && !defined(MYTHEN3D)
|
||||
functionNotImplemented();
|
||||
@ -7617,10 +7620,15 @@ int set_pattern(int file_des) {
|
||||
free(pat);
|
||||
return printSocketReadError();
|
||||
}
|
||||
if (receiveData(file_des, args, MAX_STR_LENGTH, OTHER) < 0) {
|
||||
if (pat != NULL)
|
||||
free(pat);
|
||||
return printSocketReadError();
|
||||
}
|
||||
|
||||
if (Server_VerifyLock() == OK) {
|
||||
LOG(logINFO, ("Setting Pattern from structure\n"));
|
||||
ret = loadPattern(mess, logINFO, pat);
|
||||
LOG(logDEBUG1, ("Setting Pattern from structure\n"));
|
||||
ret = loadPattern(mess, logINFO, pat, args);
|
||||
}
|
||||
if (pat != NULL)
|
||||
free(pat);
|
||||
@ -7629,6 +7637,24 @@ int set_pattern(int file_des) {
|
||||
return Server_SendResult(file_des, INT32, NULL, 0);
|
||||
}
|
||||
|
||||
int get_pattern_file(int file_des) {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
char retvals[MAX_STR_LENGTH];
|
||||
memset(retvals, 0, MAX_STR_LENGTH);
|
||||
|
||||
LOG(logDEBUG1, ("Getting pattern file name\n"));
|
||||
|
||||
#if !defined(CHIPTESTBOARDD) && !defined(MYTHEN3D)
|
||||
functionNotImplemented();
|
||||
#else
|
||||
// get only
|
||||
strcpy(retvals, getPatternFileName());
|
||||
LOG(logDEBUG1, ("pattern file name retval: %s\n", retvals));
|
||||
#endif
|
||||
return Server_SendResult(file_des, OTHER, retvals, sizeof(retvals));
|
||||
}
|
||||
|
||||
int get_pattern(int file_des) {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
|
@ -1803,6 +1803,10 @@ class Detector {
|
||||
* Pattern *
|
||||
* *
|
||||
* ************************************************/
|
||||
/** [CTB][Mythen3] Gets the pattern file name including path of the last
|
||||
* pattern uploaded. \n Returns an empty if nothing was uploaded or via a
|
||||
* server default file*/
|
||||
Result<std::string> getPatterFileName(Positions pos = {}) const;
|
||||
|
||||
/** [CTB][Mythen3] Loads ASCII pattern file directly to server
|
||||
* (instead of executing line by line)*/
|
||||
|
@ -1224,6 +1224,7 @@ class CmdProxy {
|
||||
|
||||
/* Pattern */
|
||||
{"pattern", &CmdProxy::Pattern},
|
||||
{"patfname", &CmdProxy::patfname},
|
||||
{"savepattern", &CmdProxy::savepattern},
|
||||
{"defaultpattern", &CmdProxy::defaultpattern},
|
||||
{"patioctrl", &CmdProxy::patioctrl},
|
||||
@ -1721,7 +1722,8 @@ class CmdProxy {
|
||||
"[voltagename1 voltagename2 .. voltagename4] \n\t\t[ChipTestBoard] Set "
|
||||
"the list of voltage names for this board.");
|
||||
|
||||
CTB_SINGLE_DACNAME(voltagename, getVoltageName, setVoltageName, defs::V_POWER_A,
|
||||
CTB_SINGLE_DACNAME(voltagename, getVoltageName, setVoltageName,
|
||||
defs::V_POWER_A,
|
||||
"[0-4][name] \n\t\t[ChipTestBoard] Set "
|
||||
"the voltage at the given position to the given name.");
|
||||
|
||||
@ -1734,7 +1736,8 @@ class CmdProxy {
|
||||
"[slowadcname1 slowadcname2 .. slowadcname7] \n\t\t[ChipTestBoard] Set "
|
||||
"the list of slowadc names for this board.");
|
||||
|
||||
CTB_SINGLE_DACNAME(slowadcname, getSlowAdcName, setSlowAdcName, defs::SLOW_ADC0,
|
||||
CTB_SINGLE_DACNAME(slowadcname, getSlowAdcName, setSlowAdcName,
|
||||
defs::SLOW_ADC0,
|
||||
"[0-7][name] \n\t\t[ChipTestBoard] Set "
|
||||
"the slowadc at the given position to the given name.");
|
||||
|
||||
@ -2473,6 +2476,11 @@ class CmdProxy {
|
||||
|
||||
/* Pattern */
|
||||
|
||||
GET_COMMAND(patfname, getPatterFileName,
|
||||
"\n\t[Ctb][Mythen3] Gets the pattern file name including "
|
||||
"path of the last pattern uploaded. Returns an empty if "
|
||||
"nothing was uploaded or via a server default file");
|
||||
|
||||
EXECUTE_SET_COMMAND_NOID_1ARG(
|
||||
savepattern, savePattern,
|
||||
"[fname]\n\t[Ctb][Mythen3] Saves pattern to file (ascii). "
|
||||
|
@ -2335,7 +2335,7 @@ defs::dacIndex Detector::getVoltageIndex(const std::string &name) const {
|
||||
}
|
||||
|
||||
void Detector::setVoltageName(const defs::dacIndex index,
|
||||
const std::string &name) {
|
||||
const std::string &name) {
|
||||
if (getDetectorType().squash() != defs::CHIPTESTBOARD)
|
||||
throw RuntimeError("Named powers only for CTB");
|
||||
pimpl->setCtbVoltageName(index, name);
|
||||
@ -2370,7 +2370,7 @@ defs::dacIndex Detector::getSlowAdcIndex(const std::string &name) const {
|
||||
}
|
||||
|
||||
void Detector::setSlowAdcName(const defs::dacIndex index,
|
||||
const std::string &name) {
|
||||
const std::string &name) {
|
||||
if (getDetectorType().squash() != defs::CHIPTESTBOARD)
|
||||
throw RuntimeError("Named SlowAdcs only for CTB");
|
||||
pimpl->setCtbSlowAdcName(index, name);
|
||||
@ -2384,16 +2384,20 @@ std::string Detector::getSlowAdcName(const defs::dacIndex i) const {
|
||||
|
||||
// Pattern
|
||||
|
||||
Result<std::string> Detector::getPatterFileName(Positions pos) const {
|
||||
return pimpl->Parallel(&Module::getPatterFileName, pos);
|
||||
}
|
||||
|
||||
void Detector::setPattern(const std::string &fname, Positions pos) {
|
||||
Pattern pat;
|
||||
pat.load(fname);
|
||||
pat.validate();
|
||||
setPattern(pat, pos);
|
||||
pimpl->Parallel(&Module::setPattern, pos, pat, fname);
|
||||
}
|
||||
|
||||
void Detector::setPattern(const Pattern &pat, Positions pos) {
|
||||
pat.validate();
|
||||
pimpl->Parallel(&Module::setPattern, pos, pat);
|
||||
pimpl->Parallel(&Module::setPattern, pos, pat, "");
|
||||
}
|
||||
|
||||
void Detector::savePattern(const std::string &fname) {
|
||||
|
@ -2051,7 +2051,7 @@ std::string DetectorImpl::getCtbVoltageName(const defs::dacIndex i) const {
|
||||
}
|
||||
|
||||
void DetectorImpl::setCtbVoltageName(const defs::dacIndex index,
|
||||
const std::string &name) {
|
||||
const std::string &name) {
|
||||
ctb_shm()->setVoltageName(static_cast<int>(index - defs::V_POWER_A), name);
|
||||
}
|
||||
|
||||
@ -2068,7 +2068,7 @@ std::string DetectorImpl::getCtbSlowAdcName(const defs::dacIndex i) const {
|
||||
}
|
||||
|
||||
void DetectorImpl::setCtbSlowAdcName(const defs::dacIndex index,
|
||||
const std::string &name) {
|
||||
const std::string &name) {
|
||||
ctb_shm()->setSlowAdcName(static_cast<int>(index - defs::SLOW_ADC0), name);
|
||||
}
|
||||
|
||||
|
@ -2478,9 +2478,23 @@ void Module::setLEDEnable(bool enable) {
|
||||
}
|
||||
|
||||
// Pattern
|
||||
std::string Module::getPatterFileName() const {
|
||||
char retval[MAX_STR_LENGTH]{};
|
||||
sendToDetector(F_GET_PATTERN_FILE_NAME, nullptr, retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
void Module::setPattern(const Pattern &pat) {
|
||||
sendToDetector(F_SET_PATTERN, pat.data(), pat.size(), nullptr, 0);
|
||||
void Module::setPattern(const Pattern &pat, const std::string &fname) {
|
||||
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
|
||||
client.Send(F_SET_PATTERN);
|
||||
client.Send(pat.data(), pat.size());
|
||||
char args[MAX_STR_LENGTH]{};
|
||||
strcpy_safe(args, fname.c_str());
|
||||
client.Send(args);
|
||||
if (client.Receive<int>() == FAIL) {
|
||||
throw DetectorError("Detector " + std::to_string(moduleIndex) +
|
||||
" returned error: " + client.readErrorMessage());
|
||||
}
|
||||
}
|
||||
|
||||
Pattern Module::getPattern() {
|
||||
|
@ -525,7 +525,8 @@ class Module : public virtual slsDetectorDefs {
|
||||
* Pattern *
|
||||
* *
|
||||
* ************************************************/
|
||||
void setPattern(const Pattern &pat);
|
||||
std::string getPatterFileName() const;
|
||||
void setPattern(const Pattern &pat, const std::string &fname);
|
||||
Pattern getPattern();
|
||||
void loadDefaultPattern();
|
||||
uint64_t getPatternIOControl() const;
|
||||
|
@ -309,15 +309,15 @@ TEST_CASE("voltagename", "[.cmd]") {
|
||||
REQUIRE_THROWS(proxy.Call("voltagename", {"5", "bname"}, -1, PUT));
|
||||
{
|
||||
std::ostringstream oss;
|
||||
REQUIRE_NOTHROW(proxy.Call("voltagename", {str_voltage_index, "bname"},
|
||||
-1, PUT, oss));
|
||||
REQUIRE_NOTHROW(proxy.Call(
|
||||
"voltagename", {str_voltage_index, "bname"}, -1, PUT, oss));
|
||||
}
|
||||
{
|
||||
std::ostringstream oss;
|
||||
REQUIRE_NOTHROW(
|
||||
proxy.Call("voltagename", {str_voltage_index}, -1, GET, oss));
|
||||
REQUIRE(oss.str() ==
|
||||
std::string("voltagename ") + str_voltage_index + " bname\n");
|
||||
REQUIRE(oss.str() == std::string("voltagename ") +
|
||||
str_voltage_index + " bname\n");
|
||||
}
|
||||
det.setVoltageName(ind, prev);
|
||||
|
||||
@ -401,15 +401,15 @@ TEST_CASE("slowadcname", "[.cmd]") {
|
||||
REQUIRE_THROWS(proxy.Call("slowadcname", {"8", "bname"}, -1, PUT));
|
||||
{
|
||||
std::ostringstream oss;
|
||||
REQUIRE_NOTHROW(proxy.Call("slowadcname", {str_slowadc_index, "bname"},
|
||||
-1, PUT, oss));
|
||||
REQUIRE_NOTHROW(proxy.Call(
|
||||
"slowadcname", {str_slowadc_index, "bname"}, -1, PUT, oss));
|
||||
}
|
||||
{
|
||||
std::ostringstream oss;
|
||||
REQUIRE_NOTHROW(
|
||||
proxy.Call("slowadcname", {str_slowadc_index}, -1, GET, oss));
|
||||
REQUIRE(oss.str() ==
|
||||
std::string("slowadcname ") + str_slowadc_index + " bname\n");
|
||||
REQUIRE(oss.str() == std::string("slowadcname ") +
|
||||
str_slowadc_index + " bname\n");
|
||||
}
|
||||
det.setSlowAdcName(ind, prev);
|
||||
|
||||
|
@ -19,6 +19,18 @@ using test::PUT;
|
||||
|
||||
/* Pattern */
|
||||
|
||||
TEST_CASE("patfname", "[.cmd]") {
|
||||
Detector det;
|
||||
CmdProxy proxy(&det);
|
||||
auto det_type = det.getDetectorType().squash();
|
||||
if (det_type == defs::CHIPTESTBOARD || det_type == defs::MYTHEN3) {
|
||||
REQUIRE_THROWS(proxy.Call("patfname", {}, -1, PUT));
|
||||
REQUIRE_NOTHROW(proxy.Call("patfname", {}, -1, GET));
|
||||
} else {
|
||||
REQUIRE_THROWS(proxy.Call("patfname", {}, -1, GET));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("pattern", "[.cmd]") {
|
||||
Detector det;
|
||||
CmdProxy proxy(&det);
|
||||
|
@ -281,6 +281,7 @@ enum detFuncs {
|
||||
F_SET_BIT,
|
||||
F_CLEAR_BIT,
|
||||
F_GET_PATTERN_IO_CONTROL,
|
||||
F_GET_PATTERN_FILE_NAME,
|
||||
|
||||
NUM_DET_FUNCTIONS,
|
||||
RECEIVER_ENUM_START = 512, /**< detector function should not exceed this
|
||||
@ -665,6 +666,7 @@ const char* getFunctionNameFromEnum(enum detFuncs func) {
|
||||
case F_SET_BIT: return "F_SET_BIT";
|
||||
case F_CLEAR_BIT: return "F_CLEAR_BIT";
|
||||
case F_GET_PATTERN_IO_CONTROL: return "F_GET_PATTERN_IO_CONTROL";
|
||||
case F_GET_PATTERN_FILE_NAME: return "F_GET_PATTERN_FILE_NAME";
|
||||
|
||||
|
||||
case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS";
|
||||
|
@ -5,9 +5,9 @@
|
||||
#define APILIB "developer 0x230224"
|
||||
#define APIRECEIVER "developer 0x230224"
|
||||
#define APIEIGER "developer 0x230525"
|
||||
#define APICTB "developer 0x230615"
|
||||
#define APIGOTTHARD "developer 0x230615"
|
||||
#define APIGOTTHARD2 "developer 0x230615"
|
||||
#define APIJUNGFRAU "developer 0x230615"
|
||||
#define APIMYTHEN3 "developer 0x230615"
|
||||
#define APIMOENCH "developer 0x230615"
|
||||
#define APICTB "developer 0x230621"
|
||||
#define APIMYTHEN3 "developer 0x230621"
|
||||
|
Loading…
x
Reference in New Issue
Block a user