formatting
Some checks failed
Build on RHEL9 / build (push) Failing after 3m0s
Build on RHEL8 / build (push) Failing after 5m14s

This commit is contained in:
2025-10-10 17:22:15 +02:00
parent 5d4a0055e1
commit 137365642d
11 changed files with 225 additions and 160 deletions

View File

@@ -73,7 +73,7 @@ class Caller {
static void EmptyDataCallBack(detectorData *data, uint64_t frameIndex,
uint32_t subFrameIndex, void *this_pointer);
uint32_t parseValueFromBitNames(const std::string& input) const;
uint32_t parseValueFromBitNames(const std::string &input) const;
std::string bitoperations(int action);

View File

@@ -1839,31 +1839,32 @@ class Detector {
/** [CTB][Xilinx CTB] */
int getRegisterDefinitionsCount() const;
/** [CTB][Xilinx CTB] */
void setRegisterDefinition(const std::string &name, const int value);
/** [CTB][Xilinx CTB] */
bool hasRegisterDefinition(const std::string &name) const;
/** [CTB][Xilinx CTB] */
int getRegisterDefinitionByName(const std::string &name) const;
/** [CTB][Xilinx CTB] */
std::string getRegisterDefinitionByValue(const int value) const;
/** [CTB][Xilinx CTB] */
void clearRegisterDefinitions();
/** [CTB][Xilinx CTB] */
void setRegisterDefinitions(const std::vector<std::pair<std::string, int>> &list);
void setRegisterDefinitions(
const std::vector<std::pair<std::string, int>> &list);
/** [CTB][Xilinx CTB] */
std::vector<std::pair<std::string, int>> getRegisterDefinitions() const;
/** [CTB][Xilinx CTB] */
int getBitDefinitionsCount() const;
/** [CTB][Xilinx CTB] */
void setBitDefinition(const std::string &name, const int value);
@@ -1872,16 +1873,17 @@ class Detector {
/** [CTB][Xilinx CTB] */
int getBitDefinitionByName(const std::string &name) const;
/** [CTB][Xilinx CTB] */
void clearBitDefinitions();
/** [CTB][Xilinx CTB] */
void setBitDefinitions(const std::vector<std::pair<std::string, int>> &list);
void
setBitDefinitions(const std::vector<std::pair<std::string, int>> &list);
/** [CTB][Xilinx CTB] */
std::vector<std::pair<std::string, int>> getBitDefinitions() const;
///@}
/** @name Xilinx CTB Specific */

View File

@@ -1439,22 +1439,31 @@ std::string Caller::sleep(int action) {
std::string Caller::define(int action) {
std::ostringstream os;
if (action == defs::HELP_ACTION) {
os << "[reg/bit] [name] [address or bit position]\n\tSets a user defined register or bit name in shared memory. One can retrieve the address or bit position using the name. One can also retrieve the name using the address, but only for registers. One can then use this user-defined name in other commands instead of hard coding the address or bit position such as for reg, setbit, clearbit and getbit commands. The name can be upto 32 characters long."
os << "[reg/bit] [name] [address or bit position]\n\tSets a user "
"defined register or bit name in shared memory. One can retrieve "
"the address or bit position using the name. One can also "
"retrieve the name using the address, but only for registers. "
"One can then use this user-defined name in other commands "
"instead of hard coding the address or bit position such as for "
"reg, setbit, clearbit and getbit commands. The name can be upto "
"32 characters long."
<< '\n';
return os.str();
}
return os.str();
}
if (action != defs::GET_ACTION && action != defs::PUT_ACTION) {
throw RuntimeError("Unknown action");
}
}
auto det_type = det->getDetectorType().squash();
if (det_type != defs::XILINX_CHIPTESTBOARD && det_type != defs::CHIPTESTBOARD) {
throw RuntimeError("define command only supported for ctb and xilinx_ctb");
if (det_type != defs::XILINX_CHIPTESTBOARD &&
det_type != defs::CHIPTESTBOARD) {
throw RuntimeError(
"define command only supported for ctb and xilinx_ctb");
}
if (det_id != -1) {
throw RuntimeError(
"Cannot use define at module level. Use the default multi-module level");
throw RuntimeError("Cannot use define at module level. Use the default "
"multi-module level");
}
if (args.size() < 1) {
@@ -1463,7 +1472,7 @@ std::string Caller::define(int action) {
if (args[0] != "reg" && args[0] != "bit") {
throw RuntimeError("Unknown argument " + args[0] +
". Did you mean reg or bit?");
". Did you mean reg or bit?");
}
if (action == defs::GET_ACTION) {
@@ -1507,15 +1516,18 @@ std::string Caller::define(int action) {
std::string Caller::definelist(int action) {
std::ostringstream os;
if (action == defs::HELP_ACTION) {
os << "[reg/bit] \n\tList of user-defined register or bit definitions in shared memory."
os << "[reg/bit] \n\tList of user-defined register or bit definitions "
"in shared memory."
<< '\n';
} else if (action == defs::PUT_ACTION) {
throw RuntimeError("cannot put");
} else if (action == defs::GET_ACTION) {
auto det_type = det->getDetectorType().squash();
if (det_type != defs::XILINX_CHIPTESTBOARD && det_type != defs::CHIPTESTBOARD) {
throw RuntimeError("define command only supported for ctb and xilinx_ctb");
if (det_type != defs::XILINX_CHIPTESTBOARD &&
det_type != defs::CHIPTESTBOARD) {
throw RuntimeError(
"define command only supported for ctb and xilinx_ctb");
}
if (args.size() != 1) {
@@ -1530,7 +1542,7 @@ std::string Caller::definelist(int action) {
os << ToString(t) << '\n';
} else {
throw RuntimeError("Unknown argument " + args[0] +
". Did you mean register or bit?");
". Did you mean register or bit?");
}
} else {
throw RuntimeError("Unknown action");
@@ -1538,7 +1550,7 @@ std::string Caller::definelist(int action) {
return os.str();
}
uint32_t Caller::parseValueFromBitNames(const std::string& input) const{
uint32_t Caller::parseValueFromBitNames(const std::string &input) const {
uint32_t value = 0;
std::stringstream ss(input);
std::string token;
@@ -1546,7 +1558,7 @@ uint32_t Caller::parseValueFromBitNames(const std::string& input) const{
while (std::getline(ss, token, '|')) {
if (token.empty())
continue;
int bit_pos = det->getBitDefinitionByName(token);
value |= (1u << bit_pos);
}
@@ -1556,7 +1568,16 @@ uint32_t Caller::parseValueFromBitNames(const std::string& input) const{
std::string Caller::reg(int action) {
std::ostringstream os;
if (action == defs::HELP_ACTION) {
os << "[address] [32 bit value][(optional)--validate]\n\t[Mythen3][Gotthard2] Reads/writes to a 32 bit register in hex. Advanced Function!\n\tGoes to stop server. Hence, can be called while calling blocking acquire().\n\t\t Use --validate to force validation when writing to it.\n\t[Eiger] +0x100 for only left, +0x200 for only right.\n\t\t[Ctb][Xilinx_Ctb] Address can also be a user-defined name set previously using the define command. Value can be a user-defined bit name as well or combined with '|'."
os << "[address] [32 bit "
"value][(optional)--validate]\n\t[Mythen3][Gotthard2] "
"Reads/writes to a 32 bit register in hex. Advanced "
"Function!\n\tGoes to stop server. Hence, can be called while "
"calling blocking acquire().\n\t\t Use --validate to force "
"validation when writing to it.\n\t[Eiger] +0x100 for only left, "
"+0x200 for only right.\n\t\t[Ctb][Xilinx_Ctb] Address can also "
"be a user-defined name set previously using the define command. "
"Value can be a user-defined bit name as well or combined with "
"'|'."
<< '\n';
} else {
if (args.size() < 1) {
@@ -1568,11 +1589,15 @@ std::string Caller::reg(int action) {
addr = StringTo<uint32_t>(args[0]);
} catch (...) {
auto det_type = det->getDetectorType().squash();
if (det_type != defs::XILINX_CHIPTESTBOARD && det_type != defs::CHIPTESTBOARD) {
throw RuntimeError("User defined register definitions only supported for ctb and xilinx_ctb. Use an actual hard coded address for this detector.");
if (det_type != defs::XILINX_CHIPTESTBOARD &&
det_type != defs::CHIPTESTBOARD) {
throw RuntimeError(
"User defined register definitions only supported for ctb "
"and xilinx_ctb. Use an actual hard coded address for this "
"detector.");
}
addr = det->getRegisterDefinitionByName(args[0]);
}
}
if (action == defs::PUT_ACTION) {
if (args.size() != 2 && args.size() != 3) {
WrongNumberOfParameters(2);
@@ -1584,9 +1609,8 @@ std::string Caller::reg(int action) {
validate = true;
} else {
throw RuntimeError("Unknown argument " + args[2] +
". Did you mean --validate?");
". Did you mean --validate?");
}
}
// get value from int or name
uint32_t val = 0;
@@ -1594,18 +1618,22 @@ std::string Caller::reg(int action) {
val = StringTo<uint32_t>(args[1]);
} catch (...) {
auto det_type = det->getDetectorType().squash();
if (det_type != defs::XILINX_CHIPTESTBOARD && det_type != defs::CHIPTESTBOARD) {
throw RuntimeError("User defined bit definitions only supported for ctb and xilinx_ctb. Use an actual hard coded value for this detector.");
if (det_type != defs::XILINX_CHIPTESTBOARD &&
det_type != defs::CHIPTESTBOARD) {
throw RuntimeError(
"User defined bit definitions only supported for ctb "
"and xilinx_ctb. Use an actual hard coded value for "
"this detector.");
}
val = parseValueFromBitNames(args[1]);
std::cout << "value:"<< val << std::endl;
}
std::cout << "value:" << val << std::endl;
}
det->writeRegister(addr, val, validate, std::vector<int>{det_id});
os << '[' << args[0] << ", " << args[1] << "]\n";
} else if (action == defs::GET_ACTION) {
auto t = det->readRegister(addr, std::vector<int>{det_id});
os << OutStringHex(t) << '\n';
auto t = det->readRegister(addr, std::vector<int>{det_id});
os << OutStringHex(t) << '\n';
} else {
throw RuntimeError("Unknown action");
}
@@ -1613,35 +1641,32 @@ std::string Caller::reg(int action) {
return os.str();
}
std::string Caller::getbit(int action) {
return bitoperations(action);
}
std::string Caller::getbit(int action) { return bitoperations(action); }
std::string Caller::setbit(int action) {
return bitoperations(action);
}
std::string Caller::setbit(int action) { return bitoperations(action); }
std::string Caller::clearbit(int action) {
return bitoperations(action);
}
std::string Caller::clearbit(int action) { return bitoperations(action); }
std::string Caller::bitoperations(int action) {
std::ostringstream os;
if (action == defs::HELP_ACTION) {
if (cmd == "getbit") {
os << "[reg address in hex] [bit index]\n\tGets bit in address."
<< '\n';
<< '\n';
} else if (cmd == "setbit") {
os << "[reg address in hex] [bit index]\n\tSets bit in address.\n\tUse --validate to force validation."
<< '\n';
os << "[reg address in hex] [bit index]\n\tSets bit in "
"address.\n\tUse --validate to force validation."
<< '\n';
} else if (cmd == "clearbit") {
os << "[reg address in hex] [bit index]\n\tClears bit in address.\n\tUse --validate to force validation."
<< '\n';
os << "[reg address in hex] [bit index]\n\tClears bit in "
"address.\n\tUse --validate to force validation."
<< '\n';
} else {
throw RuntimeError("Unknown command");
}
os << "\n\t\t[Ctb][Xilinx_Ctb] Address or bit position can also be a user-defined name set previously using the define command.";
os << '\n';
os << "\n\t\t[Ctb][Xilinx_Ctb] Address or bit position can also be a "
"user-defined name set previously using the define command.";
os << '\n';
} else {
if (action != defs::GET_ACTION && action != defs::PUT_ACTION) {
throw RuntimeError("Unknown action");
@@ -1658,11 +1683,15 @@ std::string Caller::bitoperations(int action) {
addr = StringTo<uint32_t>(args[0]);
} catch (...) {
auto det_type = det->getDetectorType().squash();
if (det_type != defs::XILINX_CHIPTESTBOARD && det_type != defs::CHIPTESTBOARD) {
throw RuntimeError("User defined register definitions only supported for ctb and xilinx_ctb. Use an actual hard coded address for this detector.");
if (det_type != defs::XILINX_CHIPTESTBOARD &&
det_type != defs::CHIPTESTBOARD) {
throw RuntimeError(
"User defined register definitions only supported for ctb "
"and xilinx_ctb. Use an actual hard coded address for this "
"detector.");
}
addr = det->getRegisterDefinitionByName(args[0]);
}
}
// get bit postition from int or name
int bit = 0;
@@ -1670,25 +1699,29 @@ std::string Caller::bitoperations(int action) {
bit = StringTo<int>(args[1]);
} catch (...) {
auto det_type = det->getDetectorType().squash();
if (det_type != defs::XILINX_CHIPTESTBOARD && det_type != defs::CHIPTESTBOARD) {
throw RuntimeError("User defined bit definitions only supported for ctb and xilinx_ctb. Use an actual hard coded bit positions for this detector.");
if (det_type != defs::XILINX_CHIPTESTBOARD &&
det_type != defs::CHIPTESTBOARD) {
throw RuntimeError(
"User defined bit definitions only supported for ctb and "
"xilinx_ctb. Use an actual hard coded bit positions for "
"this detector.");
}
bit = det->getBitDefinitionByName(args[1]);
}
}
if (action == defs::GET_ACTION) {
if (cmd == "setbit" || cmd == "clearbit")
if (cmd == "setbit" || cmd == "clearbit")
throw RuntimeError("Cannot get");
auto t = det->getBit(addr, bit, std::vector<int>{det_id});
os << OutString(t) << '\n';
os << OutString(t) << '\n';
} else {
if (cmd == "getbit")
throw RuntimeError("Cannot put");
if (args.size() > 3)
WrongNumberOfParameters(2);
// third arg: flag
bool validate = false;
if (args.size() == 3) {
@@ -1696,18 +1729,17 @@ std::string Caller::bitoperations(int action) {
validate = true;
} else {
throw RuntimeError("Unknown argument " + args[2] +
". Did you mean --validate?");
". Did you mean --validate?");
}
}
if (cmd == "setbit")
if (cmd == "setbit")
det->setBit(addr, bit, validate, std::vector<int>{det_id});
else if (cmd == "clearbit")
det->clearBit(addr, bit, validate, std::vector<int>{det_id});
else
throw RuntimeError("Unknown command");
os << '[' << args[0] << ", " << args[1] << "]\n";
}
}
return os.str();

View File

@@ -238,47 +238,54 @@ std::vector<std::string> CtbConfig::getSlowADCNames() const {
const char *CtbConfig::shm_tag() { return shm_tag_; }
std::optional<Entry*> CtbConfig::findEntryByName(const std::string &name, const bool is_register) {
Entry* begin = is_register ? registernames : bitnames;
Entry* end = begin + (is_register ? num_regs : num_bits);
std::optional<Entry *> CtbConfig::findEntryByName(const std::string &name,
const bool is_register) {
Entry *begin = is_register ? registernames : bitnames;
Entry *end = begin + (is_register ? num_regs : num_bits);
auto it = std::find_if(begin, end, [&name](const Entry &e) {
return std::strncmp(e.key, name.c_str(), CTB_NAME_LENGTH) == 0;
});
if (it != end) return it;
if (it != end)
return it;
return std::nullopt;
}
// const overload
std::optional<const Entry*> CtbConfig::findEntryByName(const std::string &name, const bool is_register) const {
const Entry* begin = is_register ? registernames : bitnames;
const Entry* end = begin + (is_register ? num_regs : num_bits);
std::optional<const Entry *>
CtbConfig::findEntryByName(const std::string &name,
const bool is_register) const {
const Entry *begin = is_register ? registernames : bitnames;
const Entry *end = begin + (is_register ? num_regs : num_bits);
auto it = std::find_if(begin, end, [&name](const Entry &e) {
return std::strncmp(e.key, name.c_str(), CTB_NAME_LENGTH) == 0;
});
if (it != end) return it;
if (it != end)
return it;
return std::nullopt;
}
std::optional<const Entry*> CtbConfig::findEntryByValue(const int value, const bool is_register) const {
const Entry* begin = is_register ? registernames : bitnames;
const Entry* end = begin + (is_register ? num_regs : num_bits);
auto it = std::find_if(begin, end, [&value](const Entry &e) {
return e.value == value;
});
std::optional<const Entry *>
CtbConfig::findEntryByValue(const int value, const bool is_register) const {
const Entry *begin = is_register ? registernames : bitnames;
const Entry *end = begin + (is_register ? num_regs : num_bits);
auto it = std::find_if(
begin, end, [&value](const Entry &e) { return e.value == value; });
if (it != end) return it;
if (it != end)
return it;
return std::nullopt;
}
std::optional<int> CtbConfig::lookupEntryByName(const char* name, const bool is_register) const {
std::optional<int> CtbConfig::lookupEntryByName(const char *name,
const bool is_register) const {
auto entry = findEntryByName(name, is_register);
return (entry ? std::optional<int>((*entry)->value) : std::nullopt);
}
std::optional<std::string> CtbConfig::lookupEntryByValue(const int value, const bool is_register) const {
std::optional<std::string>
CtbConfig::lookupEntryByValue(const int value, const bool is_register) const {
if (!is_register) {
throw RuntimeError("Lookup by value only valid for registers");
}
@@ -286,28 +293,35 @@ std::optional<std::string> CtbConfig::lookupEntryByValue(const int value, const
return (entry ? std::optional<std::string>((*entry)->key) : std::nullopt);
}
void CtbConfig::addEntry(const char* name, const int value, const bool is_register) {
void CtbConfig::addEntry(const char *name, const int value,
const bool is_register) {
check_size(name);
Entry* begin = is_register ? registernames : bitnames;
size_t* size_ptr = is_register ? &num_regs : &num_bits;
Entry *begin = is_register ? registernames : bitnames;
size_t *size_ptr = is_register ? &num_regs : &num_bits;
size_t max_size = is_register ? max_regs : max_bits;
// exists: overwrite value
if (auto entry = findEntryByName(name, is_register)) {
(*entry)->value = value;
(*entry)->value = value;
return;
}
}
// check size
if (*size_ptr >= max_size) {
throw RuntimeError("Maximum number of " + std::string(is_register ? "registers" : "bits") + " reached. Clear shared memory and try again.");
throw RuntimeError("Maximum number of " +
std::string(is_register ? "registers" : "bits") +
" reached. Clear shared memory and try again.");
}
// check value exists
if (is_register) {
if (auto addr_entry = findEntryByValue(value, is_register)) {
throw RuntimeError("Address " + std::to_string(value) + " already assigned to " + std::string(is_register ? "register" : "bit") + " '" + std::string((*addr_entry)->key) + "'. Cannot assign to '" + name + "'");
throw RuntimeError("Address " + std::to_string(value) +
" already assigned to " +
std::string(is_register ? "register" : "bit") +
" '" + std::string((*addr_entry)->key) +
"'. Cannot assign to '" + name + "'");
}
}
@@ -318,15 +332,14 @@ void CtbConfig::addEntry(const char* name, const int value, const bool is_regist
++(*size_ptr);
}
int CtbConfig::getRegisterNamesCount() const {
return num_regs;
}
int CtbConfig::getRegisterNamesCount() const { return num_regs; }
void CtbConfig::setRegisterName(const std::string &name, const int value) {
addEntry(name.c_str(), value, true);
}
std::optional<int> CtbConfig::getRegisterAddress(const std::string &name) const {
std::optional<int>
CtbConfig::getRegisterAddress(const std::string &name) const {
return lookupEntryByName(name.c_str(), true);
}
@@ -339,13 +352,14 @@ void CtbConfig::clearRegisterNames() {
num_regs = 0;
}
void CtbConfig::setRegisterNames(const std::vector<std::pair<std::string, int>> &list) {
void CtbConfig::setRegisterNames(
const std::vector<std::pair<std::string, int>> &list) {
if (list.size() > max_regs) {
throw RuntimeError("Register names need to be of size less than " +
std::to_string(max_regs));
}
clearRegisterNames();
for (const auto& [name, value] : list) {
for (const auto &[name, value] : list) {
setRegisterName(name, value);
}
}
@@ -353,17 +367,17 @@ void CtbConfig::setRegisterNames(const std::vector<std::pair<std::string, int>>
std::vector<std::pair<std::string, int>> CtbConfig::getRegisterNames() const {
std::vector<std::pair<std::string, int>> names;
for (size_t i = 0; i != num_regs; ++i)
names.push_back({std::string(registernames[i].key), registernames[i].value});
names.push_back(
{std::string(registernames[i].key), registernames[i].value});
return names;
}
int CtbConfig::getBitNamesCount() const {
return num_bits;
}
int CtbConfig::getBitNamesCount() const { return num_bits; }
void CtbConfig::setBitName(const std::string &name, const int value) {
if (value < 0 || value > 31) {
throw RuntimeError("Bit position defined for " + name + " must be between 0 and 31");
throw RuntimeError("Bit position defined for " + name +
" must be between 0 and 31");
}
addEntry(name.c_str(), value, false);
}
@@ -377,13 +391,14 @@ void CtbConfig::clearBitNames() {
num_bits = 0;
}
void CtbConfig::setBitNames(const std::vector<std::pair<std::string, int>> &list) {
void CtbConfig::setBitNames(
const std::vector<std::pair<std::string, int>> &list) {
if (list.size() > max_bits) {
throw RuntimeError("Bit names need to be of size less than " +
std::to_string(max_bits));
}
clearBitNames();
for (const auto& [name, value] : list) {
for (const auto &[name, value] : list) {
setBitName(name, value);
}
}
@@ -395,5 +410,4 @@ std::vector<std::pair<std::string, int>> CtbConfig::getBitNames() const {
return names;
}
} // namespace sls

View File

@@ -1,8 +1,8 @@
#pragma once
#include <string>
#include <vector>
#include <optional>
#include <string>
#include <variant>
#include <vector>
namespace sls {
@@ -12,8 +12,8 @@ namespace sls {
#define CTB_NAME_LENGTH 32
struct Entry {
char key[CTB_NAME_LENGTH]{};
int value{0};
char key[CTB_NAME_LENGTH]{};
int value{0};
};
class CtbConfig {
@@ -51,12 +51,17 @@ class CtbConfig {
void check_slow_adc_index(size_t i) const;
void check_size(const std::string &name) const;
std::optional<Entry*> findEntryByName(const std::string &name, const bool is_register);
std::optional<const Entry*> findEntryByName(const std::string &name, const bool is_register) const;
std::optional<const Entry*> findEntryByValue(const int value, const bool is_register) const;
std::optional<int> lookupEntryByName(const char* name, const bool is_register) const;
std::optional<std::string> lookupEntryByValue(const int value, const bool is_register) const;
void addEntry(const char* name, const int value, const bool is_register);
std::optional<Entry *> findEntryByName(const std::string &name,
const bool is_register);
std::optional<const Entry *> findEntryByName(const std::string &name,
const bool is_register) const;
std::optional<const Entry *> findEntryByValue(const int value,
const bool is_register) const;
std::optional<int> lookupEntryByName(const char *name,
const bool is_register) const;
std::optional<std::string> lookupEntryByValue(const int value,
const bool is_register) const;
void addEntry(const char *name, const int value, const bool is_register);
public:
CtbConfig();
@@ -99,7 +104,6 @@ class CtbConfig {
void setRegisterNames(const std::vector<std::pair<std::string, int>> &list);
std::vector<std::pair<std::string, int>> getRegisterNames() const;
int getBitNamesCount() const;
void setBitName(const std::string &name, const int value);
std::optional<int> getBitPosition(const std::string &name) const;

View File

@@ -2533,11 +2533,13 @@ void Detector::clearRegisterDefinitions() {
pimpl->setRegisterDefinitions(std::vector<std::pair<std::string, int>>{});
}
void Detector::setRegisterDefinitions(const std::vector<std::pair<std::string, int>> &list) {
void Detector::setRegisterDefinitions(
const std::vector<std::pair<std::string, int>> &list) {
pimpl->setRegisterDefinitions(list);
}
std::vector<std::pair<std::string, int>> Detector::getRegisterDefinitions() const {
std::vector<std::pair<std::string, int>>
Detector::getRegisterDefinitions() const {
return pimpl->getRegisterDefinitions();
}
@@ -2561,7 +2563,8 @@ void Detector::clearBitDefinitions() {
pimpl->setBitDefinitions(std::vector<std::pair<std::string, int>>{});
}
void Detector::setBitDefinitions(const std::vector<std::pair<std::string, int>> &list) {
void Detector::setBitDefinitions(
const std::vector<std::pair<std::string, int>> &list) {
pimpl->setBitDefinitions(list);
}
@@ -2569,7 +2572,6 @@ std::vector<std::pair<std::string, int>> Detector::getBitDefinitions() const {
return pimpl->getBitDefinitions();
}
// Xilinx Ctb Specific
void Detector::configureTransceiver(Positions pos) {

View File

@@ -1936,7 +1936,7 @@ void DetectorImpl::setBadChannels(const std::vector<int> list, Positions pos) {
std::vector<std::string> DetectorImpl::getCtbDacNames() const {
if (!isChipTestBoard())
throw RuntimeError("Named DACs only for CTB");
throw RuntimeError("Named DACs only for CTB");
return ctb_shm()->getDacNames();
}
@@ -2053,7 +2053,7 @@ std::string DetectorImpl::getCtbSlowADCName(const defs::dacIndex i) const {
void DetectorImpl::setCtbSlowADCName(const defs::dacIndex index,
const std::string &name) {
if (!isChipTestBoard())
throw RuntimeError("Named Slow ADCs only for CTB");
throw RuntimeError("Named Slow ADCs only for CTB");
ctb_shm()->setSlowADCName(static_cast<int>(index - defs::SLOW_ADC0), name);
}
@@ -2063,7 +2063,8 @@ int DetectorImpl::getRegisterDefinitionsCount() const {
return ctb_shm()->getRegisterNamesCount();
}
void DetectorImpl::setRegisterDefinition(const std::string &name, const int value) {
void DetectorImpl::setRegisterDefinition(const std::string &name,
const int value) {
if (!isChipTestBoard())
throw RuntimeError("Register Definitions only for CTB");
ctb_shm()->setRegisterName(name, value);
@@ -2090,7 +2091,8 @@ std::string DetectorImpl::getRegisterDefinitionByValue(const int value) const {
throw RuntimeError("Register Definitions only for CTB");
auto val = ctb_shm()->getRegisterName(value);
if (!val.has_value()) {
throw RuntimeError("No register definition found for address: " + value);
throw RuntimeError("No register definition found for address: " +
value);
}
return val.value();
}
@@ -2101,15 +2103,17 @@ void DetectorImpl::clearRegisterDefinitions() {
ctb_shm()->clearRegisterNames();
}
void DetectorImpl::setRegisterDefinitions(const std::vector<std::pair<std::string, int>> &list){
void DetectorImpl::setRegisterDefinitions(
const std::vector<std::pair<std::string, int>> &list) {
if (!isChipTestBoard())
throw RuntimeError("Register Definitions only for CTB");
throw RuntimeError("Register Definitions only for CTB");
ctb_shm()->setRegisterNames(list);
}
std::vector<std::pair<std::string, int>> DetectorImpl::getRegisterDefinitions() const {
std::vector<std::pair<std::string, int>>
DetectorImpl::getRegisterDefinitions() const {
if (!isChipTestBoard())
throw RuntimeError("Register Definitions only for CTB");
throw RuntimeError("Register Definitions only for CTB");
return ctb_shm()->getRegisterNames();
}
@@ -2147,17 +2151,18 @@ void DetectorImpl::clearBitDefinitions() {
ctb_shm()->clearBitNames();
}
void DetectorImpl::setBitDefinitions(const std::vector<std::pair<std::string, int>> &list) {
void DetectorImpl::setBitDefinitions(
const std::vector<std::pair<std::string, int>> &list) {
if (!isChipTestBoard())
throw RuntimeError("Bit Definitions only for CTB");
ctb_shm()->setBitNames(list);
}
std::vector<std::pair<std::string, int>> DetectorImpl::getBitDefinitions() const {
std::vector<std::pair<std::string, int>>
DetectorImpl::getBitDefinitions() const {
if (!isChipTestBoard())
throw RuntimeError("Bit Definitions only for CTB");
return ctb_shm()->getBitNames();
}
} // namespace sls

View File

@@ -339,16 +339,18 @@ class DetectorImpl : public virtual slsDetectorDefs {
int getRegisterDefinitionByName(const std::string &name) const;
std::string getRegisterDefinitionByValue(const int value) const;
void clearRegisterDefinitions();
void setRegisterDefinitions(const std::vector<std::pair<std::string, int>> &list);
void setRegisterDefinitions(
const std::vector<std::pair<std::string, int>> &list);
std::vector<std::pair<std::string, int>> getRegisterDefinitions() const;
int getBitDefinitionsCount() const;
void setBitDefinition(const std::string &name, const int value);
bool hasBitDefinition(const std::string &name) const;
int getBitDefinitionByName(const std::string &name) const;
void clearBitDefinitions();
void setBitDefinitions(const std::vector<std::pair<std::string, int>> &list);
void
setBitDefinitions(const std::vector<std::pair<std::string, int>> &list);
std::vector<std::pair<std::string, int>> getBitDefinitions() const;
private:
/**
* Creates/open shared memory, initializes detector structure and members

View File

@@ -1389,13 +1389,16 @@ TEST_CASE("define", "[.cmdcall]") {
auto prev_reg_defines = det.getRegisterDefinitions();
auto prev_bit_defines = det.getBitDefinitions();
REQUIRE_THROWS(caller.call("define", {}, -1, GET)); // no mode or args
REQUIRE_THROWS(caller.call("define", {"TEST_MACRO"}, -1, GET)); // no name or pos
REQUIRE_THROWS(caller.call("define", {"TEST_MACRO", "2"}, -1, PUT));// skipped mode
REQUIRE_THROWS(caller.call("define", {"addr", "TEST_MACRO", "0x200"}, -1, PUT)); // invalid mode
REQUIRE_THROWS(caller.call("define", {"reg", "TEST_MACRO", "0x200"}, 0, PUT)); // invalid module id
REQUIRE_THROWS(
caller.call("define", {"TEST_MACRO"}, -1, GET)); // no name or pos
REQUIRE_THROWS(caller.call("define", {"TEST_MACRO", "2"}, -1,
PUT)); // skipped mode
REQUIRE_THROWS(caller.call("define", {"addr", "TEST_MACRO", "0x200"},
-1, PUT)); // invalid mode
REQUIRE_THROWS(caller.call("define", {"reg", "TEST_MACRO", "0x200"}, 0,
PUT)); // invalid module id
{
REQUIRE_NOTHROW(
caller.call("define", {"reg", "REG_MACRO", "0x202"}, -1, PUT));
@@ -1415,8 +1418,8 @@ TEST_CASE("define", "[.cmdcall]") {
int reg_addr = 0x205;
std::string s_reg_addr = "0x205";
{
REQUIRE_NOTHROW(
caller.call("define", {"reg", "REG_MACRO", s_reg_addr}, -1, PUT));
REQUIRE_NOTHROW(caller.call(
"define", {"reg", "REG_MACRO", s_reg_addr}, -1, PUT));
std::ostringstream oss;
caller.call("define", {"reg", "REG_MACRO"}, -1, GET, oss);
REQUIRE(oss.str() == "define " + s_reg_addr + "\n");
@@ -1428,7 +1431,7 @@ TEST_CASE("define", "[.cmdcall]") {
auto prev_val = det.readRegister(reg_addr);
{
std::ostringstream oss;
//det.writeRegister(reg_addr, 0x0);
// det.writeRegister(reg_addr, 0x0);
REQUIRE_NOTHROW(
caller.call("reg", {"REG_MACRO", "0x0"}, -1, PUT));
REQUIRE_NOTHROW(
@@ -1472,7 +1475,8 @@ TEST_CASE("define", "[.cmdcall]") {
} else {
REQUIRE_THROWS(caller.call("define", {"TEST_MACRO", "reg"}, -1, GET));
REQUIRE_THROWS(caller.call("define", {"TEST_MACRO", "reg", "0x200"}, -1, PUT));
REQUIRE_THROWS(
caller.call("define", {"TEST_MACRO", "reg", "0x200"}, -1, PUT));
}
}
@@ -1486,9 +1490,10 @@ TEST_CASE("definelist", "[.cmdcall]") {
auto prev_reg_defines = det.getRegisterDefinitions();
auto prev_bit_defines = det.getBitDefinitions();
REQUIRE_THROWS(caller.call("definelist", {}, -1, GET));
REQUIRE_THROWS(caller.call("definelist", {"reg", "TEST_MACRO"}, -1, GET));
REQUIRE_THROWS(
caller.call("definelist", {"reg", "TEST_MACRO"}, -1, GET));
REQUIRE_NOTHROW(caller.call("definelist", {"reg"}, -1, GET));
REQUIRE_NOTHROW(caller.call("definelist", {"bit"}, -1, GET));

View File

@@ -11,8 +11,8 @@ namespace sls {
TEST_CASE("Default construction") {
static_assert(sizeof(CtbConfig) ==
(2 * sizeof(int) + (18 + 32 + 64 + 5 + 8) * 32) + (16 +
(64 + 64) * (32 + 4)),
(2 * sizeof(int) + (18 + 32 + 64 + 5 + 8) * 32) +
(16 + (64 + 64) * (32 + 4)),
"Size of CtbConfig does not match ");
CtbConfig c;
@@ -51,7 +51,6 @@ TEST_CASE("Default construction") {
REQUIRE(regisernames.size() == 0);
auto bitnames = c.getBitNames();
REQUIRE(bitnames.size() == 0);
}
TEST_CASE("Set and get a single dac name") {
@@ -95,7 +94,8 @@ TEST_CASE("Add or modify a register name", "[.reg]") {
CtbConfig c;
REQUIRE(c.getRegisterNamesCount() == 0);
REQUIRE_THROWS(c.setRegisterName("reg1_with_a_really_long_name_to_crash", 100));
REQUIRE_THROWS(
c.setRegisterName("reg1_with_a_really_long_name_to_crash", 100));
// add an entry
REQUIRE_NOTHROW(c.setRegisterName("reg1", 100));
@@ -125,7 +125,7 @@ TEST_CASE("Add a register list", "[.reg]") {
REQUIRE(names[0].second == 0x100);
REQUIRE(names[1].first == "reg2");
REQUIRE(names[1].second == 0x200);
REQUIRE(names[2].first == "reg3");
REQUIRE(names[2].first == "reg3");
REQUIRE(names[2].second == 0x300);
// clear all entries
@@ -139,7 +139,7 @@ TEST_CASE("Finding a regiser name or address", "[.reg]") {
// find nothing
REQUIRE(c.getRegisterNamesCount() == 0);
REQUIRE(c.getRegisterName(100) == std::nullopt);
REQUIRE(c.getRegisterAddress("reg1") == std::nullopt);
REQUIRE(c.getRegisterAddress("reg1") == std::nullopt);
std::vector<std::pair<std::string, int>> list = {
{"reg1", 0x100}, {"reg2", 0x200}, {"reg3", 0x300}};
@@ -186,7 +186,7 @@ TEST_CASE("Add a bit list", "[.reg]") {
REQUIRE(names[0].second == 2);
REQUIRE(names[1].first == "reg2");
REQUIRE(names[1].second == 21);
REQUIRE(names[2].first == "reg3");
REQUIRE(names[2].first == "reg3");
REQUIRE(names[2].second == 31);
// clear all entries
@@ -199,7 +199,7 @@ TEST_CASE("Finding a bit value", "[.reg]") {
// find nothing
REQUIRE(c.getBitNamesCount() == 0);
REQUIRE(c.getBitPosition("bit1") == std::nullopt);
REQUIRE(c.getBitPosition("bit1") == std::nullopt);
std::vector<std::pair<std::string, int>> list = {
{"bit1", 2}, {"reg2", 21}, {"reg3", 31}};

View File

@@ -127,7 +127,6 @@ std::string ToString(const std::pair<T1, T2> &p) {
return os.str();
}
/** Conversion of integer types, do not remove trailing zeros */
template <typename T>
typename std::enable_if<std::is_integral<T>::value, std::string>::type