Formatted package
This commit is contained in:
Dhanya Thattil
2022-08-05 15:39:34 +02:00
committed by GitHub
parent 7173785b29
commit 6bf9dbf6d3
89 changed files with 1366 additions and 1210 deletions

View File

@ -68,7 +68,7 @@ int main(int argc, char *argv[]) {
// prevent mem size check
if (parser.command() == "config" && action == slsDetectorDefs::PUT_ACTION) {
sls::freeSharedMemory(parser.multi_id());
}
}
try {
sls::Detector det(parser.multi_id());

View File

@ -48,8 +48,8 @@ void CmdProxy::Call(const std::string &command,
if (it != functions.end()) {
os << ((*this).*(it->second))(action);
} else {
throw RuntimeError(
cmd + " Unknown command, use list to list all commands");
throw RuntimeError(cmd +
" Unknown command, use list to list all commands");
}
}
@ -219,12 +219,10 @@ std::string CmdProxy::Acquire(int action) {
<< '\n';
} else {
if (det->empty()) {
throw RuntimeError(
"This shared memory has no detectors added.");
throw RuntimeError("This shared memory has no detectors added.");
}
if (det_id >= 0) {
throw RuntimeError(
"Individual detectors not allowed for readout.");
throw RuntimeError("Individual detectors not allowed for readout.");
}
det->acquire();
@ -456,27 +454,29 @@ 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."
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';
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';
os << args << '\n';
} else {
throw RuntimeError("Unknown action");
}
return os.str();
}
std::string CmdProxy::TrimEnergies(int action) {
std::ostringstream os;
os << cmd << ' ';
@ -553,8 +553,7 @@ std::string CmdProxy::Exptime(int action) {
} else if (cmd == "exptime3") {
gateIndex = 2;
} else {
throw RuntimeError(
"Unknown command, use list to list all commands");
throw RuntimeError("Unknown command, use list to list all commands");
}
std::ostringstream os;
@ -699,8 +698,7 @@ std::string CmdProxy::Adcphase(int action) {
auto det_type = det->getDetectorType().squash(defs::GENERIC);
if (det_type == defs::EIGER || det_type == defs::MYTHEN3 ||
det_type == defs::GOTTHARD2) {
throw RuntimeError(
"adcphase not implemented for this detector");
throw RuntimeError("adcphase not implemented for this detector");
}
if (action == defs::GET_ACTION) {
Result<int> t;
@ -710,8 +708,7 @@ std::string CmdProxy::Adcphase(int action) {
} else if (args.size() == 1) {
if (args[0] != "deg") {
throw RuntimeError("Unknown adcphase argument " +
args[0] +
". Did you mean deg? ");
args[0] + ". Did you mean deg? ");
}
t = det->getADCPhaseInDegrees(std::vector<int>{det_id});
os << OutString(t) << " deg\n";
@ -726,7 +723,7 @@ std::string CmdProxy::Adcphase(int action) {
} else if (args.size() == 2) {
if (args[1] != "deg") {
throw RuntimeError("Unknown adcphase 2nd argument " +
args[1] + ". Did you mean deg?");
args[1] + ". Did you mean deg?");
}
det->setADCPhaseInDegrees(StringTo<int>(args[0]),
std::vector<int>{det_id});
@ -754,8 +751,7 @@ std::string CmdProxy::Dbitphase(int action) {
auto det_type = det->getDetectorType().squash(defs::GENERIC);
if (det_type == defs::EIGER || det_type == defs::MYTHEN3 ||
det_type == defs::GOTTHARD2) {
throw RuntimeError(
"dbitphase not implemented for this detector");
throw RuntimeError("dbitphase not implemented for this detector");
}
if (action == defs::GET_ACTION) {
Result<int> t;
@ -764,8 +760,8 @@ std::string CmdProxy::Dbitphase(int action) {
os << OutString(t) << '\n';
} else if (args.size() == 1) {
if (args[0] != "deg") {
throw RuntimeError("Unknown dbitphase argument " +
args[0] + ". Did you mean deg? ");
throw RuntimeError("Unknown dbitphase argument " + args[0] +
". Did you mean deg? ");
}
t = det->getDBITPhaseInDegrees(std::vector<int>{det_id});
os << OutString(t) << " deg\n";
@ -780,7 +776,7 @@ std::string CmdProxy::Dbitphase(int action) {
} else if (args.size() == 2) {
if (args[1] != "deg") {
throw RuntimeError("Unknown dbitphase 2nd argument " +
args[1] + ". Did you mean deg? ");
args[1] + ". Did you mean deg? ");
}
det->setDBITPhaseInDegrees(StringTo<int>(args[0]),
std::vector<int>{det_id});
@ -805,8 +801,7 @@ std::string CmdProxy::ClockFrequency(int action) {
} else {
defs::detectorType type = det->getDetectorType().squash(defs::GENERIC);
if (type != defs::GOTTHARD2 && type != defs::MYTHEN3) {
throw RuntimeError(
"clkfreq not implemented for this detector.");
throw RuntimeError("clkfreq not implemented for this detector.");
}
if (action == defs::GET_ACTION) {
if (args.size() != 1) {
@ -836,8 +831,7 @@ std::string CmdProxy::ClockPhase(int action) {
} else {
defs::detectorType type = det->getDetectorType().squash(defs::GENERIC);
if (type != defs::GOTTHARD2 && type != defs::MYTHEN3) {
throw RuntimeError(
"clkphase not implemented for this detector.");
throw RuntimeError("clkphase not implemented for this detector.");
}
if (action == defs::GET_ACTION) {
if (args.size() == 1) {
@ -847,7 +841,7 @@ std::string CmdProxy::ClockPhase(int action) {
} else if (args.size() == 2) {
if (args[1] != "deg") {
throw RuntimeError("Cannot scan argument" + args[1] +
". Did you mean deg?");
". Did you mean deg?");
}
auto t = det->getClockPhaseinDegrees(StringTo<int>(args[0]),
{det_id});
@ -864,7 +858,7 @@ std::string CmdProxy::ClockPhase(int action) {
} else if (args.size() == 3) {
if (args[2] != "deg") {
throw RuntimeError("Cannot scan argument" + args[2] +
". Did you mean deg?");
". Did you mean deg?");
}
det->setClockPhaseinDegrees(StringTo<int>(args[0]),
StringTo<int>(args[1]),
@ -919,8 +913,7 @@ std::string CmdProxy::ClockDivider(int action) {
} else {
defs::detectorType type = det->getDetectorType().squash(defs::GENERIC);
if (type != defs::GOTTHARD2 && type != defs::MYTHEN3) {
throw RuntimeError(
"clkdiv not implemented for this detector.");
throw RuntimeError("clkdiv not implemented for this detector.");
}
if (action == defs::GET_ACTION) {
if (args.size() != 1) {
@ -1010,7 +1003,7 @@ std::string CmdProxy::CurrentSource(int action) {
fix = false;
} else {
throw RuntimeError("Invalid argument: " + args[1] +
". Did you mean fix or nofix?");
". Did you mean fix or nofix?");
}
if (args.size() == 3) {
det->setCurrentSource(defs::currentSrcParameters(
@ -1023,7 +1016,7 @@ std::string CmdProxy::CurrentSource(int action) {
normalCurrent = false;
} else {
throw RuntimeError("Invalid argument: " + args[3] +
". Did you mean normal or low?");
". Did you mean normal or low?");
}
det->setCurrentSource(defs::currentSrcParameters(
fix, StringTo<uint64_t>(args[2]), normalCurrent));
@ -1119,7 +1112,7 @@ std::string CmdProxy::Dac(int action) {
if (args.size() == 2) {
if ((args[1] != "mv") && (args[1] != "mV")) {
throw RuntimeError("Unknown argument " + args[1] +
". Did you mean mV?");
". Did you mean mV?");
}
mV = true;
} else if (args.size() > 2) {
@ -1140,7 +1133,7 @@ std::string CmdProxy::Dac(int action) {
if (args.size() == 3) {
if ((args[2] != "mv") && (args[2] != "mV")) {
throw RuntimeError("Unknown argument " + args[2] +
". Did you mean mV?");
". Did you mean mV?");
}
mV = true;
} else if (args.size() > 3 || args.size() < 2) {
@ -1174,11 +1167,10 @@ std::string CmdProxy::DacList(const int action) {
} else if (action == slsDetectorDefs::PUT_ACTION) {
if (det->getDetectorType().squash() != defs::CHIPTESTBOARD) {
throw RuntimeError("This detector already has fixed dac "
"names. Cannot change them.");
"names. Cannot change them.");
}
if (det_id != -1) {
throw RuntimeError(
"Cannot configure dacnames at module level");
throw RuntimeError("Cannot configure dacnames at module level");
}
if (args.size() != 18) {
WrongNumberOfParameters(18);
@ -1203,7 +1195,7 @@ std::string CmdProxy::DacValues(int action) {
if (args.size() == 1) {
if ((args[0] != "mv") && (args[0] != "mV")) {
throw RuntimeError("Unknown argument " + args[0] +
". Did you mean mV?");
". Did you mean mV?");
}
mv = true;
} else if (args.size() > 1) {
@ -1248,7 +1240,7 @@ std::string CmdProxy::ResetDacs(int action) {
if (args.size() == 1) {
if (args[0] != "hard") {
throw RuntimeError("Unknown argument " + args[0] +
". Did you mean hard?");
". Did you mean hard?");
}
hardReset = true;
} else if (args.size() > 1) {
@ -1514,8 +1506,8 @@ std::string CmdProxy::UDPDestinationList(int action) {
}
if (rx_id < 0 || rx_id >= MAX_UDP_DESTINATION) {
throw RuntimeError(std::string("Invalid receiver index ") +
std::to_string(rx_id) +
std::string(" to set round robin entry."));
std::to_string(rx_id) +
std::string(" to set round robin entry."));
}
auto t = det->getDestinationUDPList(rx_id, std::vector<int>{det_id});
os << OutString(t) << '\n';
@ -1543,7 +1535,11 @@ std::string CmdProxy::UDPSourceIP(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[x.x.x.x] or auto\n\tIp address of the detector (source) udp interface. Must be same subnet as destination udp ip.\n\t[Eiger] Set only for 10G. For 1G, detector will replace with its own DHCP IP address. If 'auto' used, then ip is set to ip of rx_hostname."
os << "[x.x.x.x] or auto\n\tIp address of the detector (source) udp "
"interface. Must be same subnet as destination udp "
"ip.\n\t[Eiger] Set only for 10G. For 1G, detector will replace "
"with its own DHCP IP address. If 'auto' used, then ip is set to "
"ip of rx_hostname."
<< '\n';
} else if (action == defs::GET_ACTION) {
auto t = det->getSourceUDPIP(std::vector<int>{det_id});
@ -1565,7 +1561,7 @@ std::string CmdProxy::UDPSourceIP(int action) {
}
det->setSourceUDPIP(val, std::vector<int>{det_id});
os << val << '\n';
} else {
throw RuntimeError("Unknown action");
}
@ -1576,7 +1572,11 @@ std::string CmdProxy::UDPSourceIP2(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[x.x.x.x] or auto\n\t[Jungfrau][Gotthard2] Ip address of the detector (source) udp interface 2. Must be same subnet as destination udp ip2.\n\t [Jungfrau] top half or inner interface\n\t [Gotthard2] veto debugging. If 'auto' used, then ip is set to ip of rx_hostname."
os << "[x.x.x.x] or auto\n\t[Jungfrau][Gotthard2] Ip address of the "
"detector (source) udp interface 2. Must be same subnet as "
"destination udp ip2.\n\t [Jungfrau] top half or inner "
"interface\n\t [Gotthard2] veto debugging. If 'auto' used, then "
"ip is set to ip of rx_hostname."
<< '\n';
} else if (action == defs::GET_ACTION) {
auto t = det->getSourceUDPIP2(std::vector<int>{det_id});
@ -1591,14 +1591,14 @@ std::string CmdProxy::UDPSourceIP2(int action) {
IpAddr val;
if (args[0] == "auto") {
val = getIpFromAuto();
LOG(logINFO) << "Setting udp_srcip2 of detector " << det_id << " to "
<< val;
LOG(logINFO) << "Setting udp_srcip2 of detector " << det_id
<< " to " << val;
} else {
val = IpAddr(args[0]);
}
det->setSourceUDPIP2(val, std::vector<int>{det_id});
os << val << '\n';
} else {
throw RuntimeError("Unknown action");
}
@ -1744,7 +1744,8 @@ std::string CmdProxy::Rx_ROI(int action) {
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[xmin] [xmax] [ymin] [ymax]\n\tRegion of interest in "
"receiver.\n\tOnly allowed at multi module level and without gap pixels."
"receiver.\n\tOnly allowed at multi module level and without gap "
"pixels."
<< '\n';
} else if (action == defs::GET_ACTION) {
if (!args.empty()) {
@ -2009,7 +2010,7 @@ std::string CmdProxy::TemperatureEvent(int action) {
}
if (StringTo<int>(args[0]) != 0) {
throw RuntimeError("Unknown argument for temp event. Did you "
"mean 0 to reset event?");
"mean 0 to reset event?");
}
det->resetTemperatureEvent(std::vector<int>{det_id});
os << "cleared" << '\n';
@ -2144,8 +2145,7 @@ std::string CmdProxy::VetoFile(int action) {
"file should have 128 rows of gain index and 12 bit value in dec"
<< '\n';
} else if (action == defs::GET_ACTION) {
throw RuntimeError(
"cannot get vetofile. Did you mean vetophoton?");
throw RuntimeError("cannot get vetofile. Did you mean vetophoton?");
} else if (action == defs::PUT_ACTION) {
if (args.size() != 2) {
WrongNumberOfParameters(2);
@ -2266,8 +2266,7 @@ std::string CmdProxy::VetoAlgorithm(int action) {
defs::streamingInterface interface =
StringTo<defs::streamingInterface>(args[0]);
if (interface == defs::streamingInterface::NONE) {
throw RuntimeError(
"Must specify an interface to set algorithm");
throw RuntimeError("Must specify an interface to set algorithm");
}
auto t = det->getVetoAlgorithm(interface, std::vector<int>{det_id});
os << OutString(t) << ' ' << ToString(interface) << '\n';
@ -2279,8 +2278,7 @@ std::string CmdProxy::VetoAlgorithm(int action) {
defs::streamingInterface interface =
StringTo<defs::streamingInterface>(args[1]);
if (interface == defs::streamingInterface::NONE) {
throw RuntimeError(
"Must specify an interface to set algorithm");
throw RuntimeError("Must specify an interface to set algorithm");
}
det->setVetoAlgorithm(alg, interface, std::vector<int>{det_id});
os << ToString(alg) << ' ' << ToString(interface) << '\n';
@ -2368,7 +2366,9 @@ std::string CmdProxy::Counters(int action) {
if (args.empty()) {
WrongNumberOfParameters(1);
}
if (std::any_of(args.cbegin(), args.cend(), [](std::string s){ return (StringTo<int>(s) < 0 || StringTo<int>(s) > 2); })) {
if (std::any_of(args.cbegin(), args.cend(), [](std::string s) {
return (StringTo<int>(s) < 0 || StringTo<int>(s) > 2);
})) {
throw RuntimeError("Invalid counter indices list. Example: 0 1 2");
}
// convert vector to counter enable mask
@ -2402,8 +2402,7 @@ std::string CmdProxy::GateDelay(int action) {
} else if (cmd == "gatedelay3") {
gateIndex = 2;
} else {
throw RuntimeError(
"Unknown command, use list to list all commands");
throw RuntimeError("Unknown command, use list to list all commands");
}
std::ostringstream os;
@ -2705,30 +2704,35 @@ std::string CmdProxy::PatternWord(int action) {
return os.str();
}
void CmdProxy::GetLevelAndUpdateArgIndex(int action, std::string levelSeparatedCommand, int& level, int& iArg, size_t nGetArgs, size_t nPutArgs) {
void CmdProxy::GetLevelAndUpdateArgIndex(int action,
std::string levelSeparatedCommand,
int &level, int &iArg, size_t nGetArgs,
size_t nPutArgs) {
if (cmd == levelSeparatedCommand) {
++nGetArgs;
++nPutArgs;
} else {
LOG(logWARNING) << "This command is deprecated and will be removed. Please migrate to " << levelSeparatedCommand;
LOG(logWARNING) << "This command is deprecated and will be removed. "
"Please migrate to "
<< levelSeparatedCommand;
}
if (action == defs::GET_ACTION && args.size() != nGetArgs) {
WrongNumberOfParameters(nGetArgs);
} else if (action == defs::PUT_ACTION && args.size() != nPutArgs) {
WrongNumberOfParameters(nPutArgs);
}
}
if (cmd == levelSeparatedCommand) {
level = StringTo<int>(args[iArg++]);
level = StringTo<int>(args[iArg++]);
} else {
level = cmd[cmd.find_first_of("012")] - '0';
}
}
std::string CmdProxy::PatternLoopAddresses(int action) {
if (cmd != "patlimits" && cmd != "patloop0" && cmd != "patloop1" && cmd != "patloop2" && cmd != "patloop") {
throw RuntimeError(
"Unknown command, use list to list all commands");
}
if (cmd != "patlimits" && cmd != "patloop0" && cmd != "patloop1" &&
cmd != "patloop2" && cmd != "patloop") {
throw RuntimeError("Unknown command, use list to list all commands");
}
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
@ -2737,17 +2741,17 @@ std::string CmdProxy::PatternLoopAddresses(int action) {
"of complete pattern."
<< '\n';
} else if (cmd == "patloop") {
os << "[0-6] [start addr] [stop addr] \n\t[Ctb][Moench][Mythen3] Limits of the loop level provided."
<< "\n\t[Mythen3] Level options: 0-3 only."
<< '\n';
os << "[0-6] [start addr] [stop addr] \n\t[Ctb][Moench][Mythen3] "
"Limits of the loop level provided."
<< "\n\t[Mythen3] Level options: 0-3 only." << '\n';
} else {
os << "Depreciated command. Use patloop."
<< '\n';
}
os << "Depreciated command. Use patloop." << '\n';
}
} else {
int level = -1, iArg = 0, nGetArgs = 0, nPutArgs = 2;
if (cmd != "patlimits") {
GetLevelAndUpdateArgIndex(action, "patloop", level, iArg, nGetArgs, nPutArgs);
GetLevelAndUpdateArgIndex(action, "patloop", level, iArg, nGetArgs,
nPutArgs);
}
if (action == defs::GET_ACTION) {
auto t =
@ -2755,11 +2759,11 @@ std::string CmdProxy::PatternLoopAddresses(int action) {
os << OutStringHex(t, 4) << '\n';
} else if (action == defs::PUT_ACTION) {
int start = StringTo<int>(args[iArg++]);
int stop = StringTo<int>(args[iArg++]);
int stop = StringTo<int>(args[iArg++]);
det->setPatternLoopAddresses(level, start, stop,
std::vector<int>{det_id});
std::vector<int>{det_id});
os << '[' << ToStringHex(start, 4) << ", " << ToStringHex(stop, 4)
<< "]\n";
<< "]\n";
} else {
throw RuntimeError("Unknown action");
}
@ -2768,25 +2772,25 @@ std::string CmdProxy::PatternLoopAddresses(int action) {
}
std::string CmdProxy::PatternLoopCycles(int action) {
if (cmd != "patnloop0" && cmd != "patnloop1" && cmd != "patnloop2" && cmd != "patnloop") {
throw RuntimeError(
"Unknown command, use list to list all commands");
}
if (cmd != "patnloop0" && cmd != "patnloop1" && cmd != "patnloop2" &&
cmd != "patnloop") {
throw RuntimeError("Unknown command, use list to list all commands");
}
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
if (cmd == "patnloop") {
os << "[0-6] [n_cycles] \n\t[Ctb][Moench][Mythen3] Number of cycles of "
os << "[0-6] [n_cycles] \n\t[Ctb][Moench][Mythen3] Number of "
"cycles of "
"the loop level provided."
<< "\n\t[Mythen3] Level options: 0-3 only."
<< '\n';
<< "\n\t[Mythen3] Level options: 0-3 only." << '\n';
} else {
os << "Depreciated command. Use patnloop."
<< '\n';
}
os << "Depreciated command. Use patnloop." << '\n';
}
} else {
int level = -1, iArg = 0, nGetArgs = 0, nPutArgs = 1;
GetLevelAndUpdateArgIndex(action, "patnloop", level, iArg, nGetArgs, nPutArgs);
GetLevelAndUpdateArgIndex(action, "patnloop", level, iArg, nGetArgs,
nPutArgs);
if (action == defs::GET_ACTION) {
auto t = det->getPatternLoopCycles(level, std::vector<int>{det_id});
os << OutString(t) << '\n';
@ -2802,23 +2806,25 @@ std::string CmdProxy::PatternLoopCycles(int action) {
}
std::string CmdProxy::PatternWaitAddress(int action) {
if (cmd != "patwait0" && cmd != "patwait1" && cmd != "patwait2" && cmd != "patwait") {
throw RuntimeError(
"Unknown command, use list to list all commands");
}
if (cmd != "patwait0" && cmd != "patwait1" && cmd != "patwait2" &&
cmd != "patwait") {
throw RuntimeError("Unknown command, use list to list all commands");
}
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
if (cmd == "patwait") {
os << "[0-6] [addr] \n\t[Ctb][Moench][Mythen3] Wait address for loop level provided."
<< "\n\t[Mythen3] Level options: 0-3 only.";
os << "[0-6] [addr] \n\t[Ctb][Moench][Mythen3] Wait address for "
"loop level provided."
<< "\n\t[Mythen3] Level options: 0-3 only.";
} else {
os << "Depreciated command. Use patwait.";
}
os << '\n';
} else {
int level = -1, iArg = 0, nGetArgs = 0, nPutArgs = 1;
GetLevelAndUpdateArgIndex(action, "patwait", level, iArg, nGetArgs, nPutArgs);
GetLevelAndUpdateArgIndex(action, "patwait", level, iArg, nGetArgs,
nPutArgs);
if (action == defs::GET_ACTION) {
auto t = det->getPatternWaitAddr(level, std::vector<int>{det_id});
os << OutStringHex(t, 4) << '\n';
@ -2834,9 +2840,9 @@ std::string CmdProxy::PatternWaitAddress(int action) {
}
std::string CmdProxy::PatternWaitTime(int action) {
if (cmd != "patwaittime0" && cmd != "patwaittime1" && cmd != "patwaittime2" && cmd != "patwaittime") {
throw RuntimeError(
"Unknown command, use list to list all commands");
if (cmd != "patwaittime0" && cmd != "patwaittime1" &&
cmd != "patwaittime2" && cmd != "patwaittime") {
throw RuntimeError("Unknown command, use list to list all commands");
}
std::ostringstream os;
os << cmd << ' ';
@ -2844,15 +2850,14 @@ std::string CmdProxy::PatternWaitTime(int action) {
if (cmd == "patwaittime") {
os << "[0-6] [n_clk] \n\t[Ctb][Moench][Mythen3] Wait time in clock "
"cycles for the loop provided."
<< "\n\t[Mythen3] Level options: 0-3 only."
<< '\n';
<< "\n\t[Mythen3] Level options: 0-3 only." << '\n';
} else {
os << "Depreciated command. Use patwaittime."
<< '\n';
}
os << "Depreciated command. Use patwaittime." << '\n';
}
} else {
int level = -1, iArg = 0, nGetArgs = 0, nPutArgs = 1;
GetLevelAndUpdateArgIndex(action, "patwaittime", level, iArg, nGetArgs, nPutArgs);
GetLevelAndUpdateArgIndex(action, "patwaittime", level, iArg, nGetArgs,
nPutArgs);
if (action == defs::GET_ACTION) {
auto t = det->getPatternWaitTime(level, std::vector<int>{det_id});
os << OutString(t) << '\n';
@ -2965,9 +2970,8 @@ std::string CmdProxy::ProgramFpga(int action) {
bool forceDeteleNormalFile = false;
if (args.size() == 2) {
if (args[1] != "--force-delete-normal-file") {
throw RuntimeError(
"Could not scan second argument. Did you "
"mean --force-delete-normal-file?");
throw RuntimeError("Could not scan second argument. Did you "
"mean --force-delete-normal-file?");
}
forceDeteleNormalFile = true;
} else if (args.size() != 1) {

View File

@ -12,7 +12,7 @@
#include <vector>
namespace sls {
/** Macro to make an integer command.
* CMDNAME name of the function that does the command
* GETFCN Detector function to get
@ -55,7 +55,7 @@ namespace sls {
os << args[0] << '\n'; \
} \
} else { \
throw RuntimeError("Unknown action"); \
throw RuntimeError("Unknown action"); \
} \
return os.str(); \
}
@ -77,9 +77,9 @@ namespace sls {
WrongNumberOfParameters(1); \
} \
} else if (action == slsDetectorDefs::PUT_ACTION) { \
throw RuntimeError("cannot put"); \
throw RuntimeError("cannot put"); \
} else { \
throw RuntimeError("Unknown action"); \
throw RuntimeError("Unknown action"); \
} \
return os.str(); \
}
@ -104,7 +104,7 @@ namespace sls {
det->SETFCN(args[0], std::vector<int>{det_id}); \
os << args.front() << '\n'; \
} else { \
throw RuntimeError("Unknown action"); \
throw RuntimeError("Unknown action"); \
} \
return os.str(); \
}
@ -130,7 +130,7 @@ namespace sls {
det->SETFCN(val, std::vector<int>{det_id}); \
os << ToStringHex(val, 16) << '\n'; \
} else { \
throw RuntimeError("Unknown action"); \
throw RuntimeError("Unknown action"); \
} \
return os.str(); \
}
@ -156,7 +156,7 @@ namespace sls {
det->SETFCN(val, std::vector<int>{det_id}); \
os << args.front() << '\n'; \
} else { \
throw RuntimeError("Unknown action"); \
throw RuntimeError("Unknown action"); \
} \
return os.str(); \
}
@ -182,7 +182,7 @@ namespace sls {
det->SETFCN(val, std::vector<int>{det_id}); \
os << args.front() << '\n'; \
} else { \
throw RuntimeError("Unknown action"); \
throw RuntimeError("Unknown action"); \
} \
return os.str(); \
}
@ -208,7 +208,7 @@ namespace sls {
det->SETFCN(val, det_id); \
os << args.front() << '\n'; \
} else { \
throw RuntimeError("Unknown action"); \
throw RuntimeError("Unknown action"); \
} \
return os.str(); \
}
@ -234,7 +234,7 @@ namespace sls {
det->SETFCN(val, det_id); \
os << args.front() << '\n'; \
} else { \
throw RuntimeError("Unknown action"); \
throw RuntimeError("Unknown action"); \
} \
return os.str(); \
}
@ -254,8 +254,7 @@ namespace sls {
os << OutString(t) << '\n'; \
} else if (action == slsDetectorDefs::PUT_ACTION) { \
if (det_id != -1) { \
throw RuntimeError( \
"Cannot execute this at module level"); \
throw RuntimeError("Cannot execute this at module level"); \
} \
if (args.size() != 1) { \
WrongNumberOfParameters(1); \
@ -264,7 +263,7 @@ namespace sls {
det->SETFCN(val); \
os << args.front() << '\n'; \
} else { \
throw RuntimeError("Unknown action"); \
throw RuntimeError("Unknown action"); \
} \
return os.str(); \
}
@ -275,7 +274,7 @@ namespace sls {
std::ostringstream os; \
os << cmd << ' '; \
if (det_id != -1) { \
throw RuntimeError("Cannot execute this at module level"); \
throw RuntimeError("Cannot execute this at module level"); \
} \
if (action == slsDetectorDefs::HELP_ACTION) \
os << HLPSTR << '\n'; \
@ -293,7 +292,7 @@ namespace sls {
det->SETFCN(val); \
os << args.front() << '\n'; \
} else { \
throw RuntimeError("Unknown action"); \
throw RuntimeError("Unknown action"); \
} \
return os.str(); \
}
@ -319,7 +318,7 @@ namespace sls {
det->SETFCN(INDEX, val, std::vector<int>{det_id}); \
os << args.front() << '\n'; \
} else { \
throw RuntimeError("Unknown action"); \
throw RuntimeError("Unknown action"); \
} \
return os.str(); \
}
@ -347,7 +346,7 @@ namespace sls {
std::vector<int>{det_id}); \
os << args[0] << ' ' << args[1] << '\n'; \
} else { \
throw RuntimeError("Unknown action"); \
throw RuntimeError("Unknown action"); \
} \
return os.str(); \
}
@ -358,12 +357,12 @@ namespace sls {
std::ostringstream os; \
os << cmd << ' '; \
if (det_id != -1) { \
throw RuntimeError("Cannot execute this at module level"); \
throw RuntimeError("Cannot execute this at module level"); \
} \
if (action == slsDetectorDefs::HELP_ACTION) \
os << HLPSTR << '\n'; \
else if (action == slsDetectorDefs::GET_ACTION) { \
throw RuntimeError("Cannot get"); \
throw RuntimeError("Cannot get"); \
} else if (action == slsDetectorDefs::PUT_ACTION) { \
if (!args.empty()) { \
WrongNumberOfParameters(0); \
@ -371,7 +370,7 @@ namespace sls {
det->SETFCN(); \
os << "successful\n"; \
} else { \
throw RuntimeError("Unknown action"); \
throw RuntimeError("Unknown action"); \
} \
return os.str(); \
}
@ -384,7 +383,7 @@ namespace sls {
if (action == slsDetectorDefs::HELP_ACTION) \
os << HLPSTR << '\n'; \
else if (action == slsDetectorDefs::GET_ACTION) { \
throw RuntimeError("Cannot get"); \
throw RuntimeError("Cannot get"); \
} else if (action == slsDetectorDefs::PUT_ACTION) { \
if (!args.empty()) { \
WrongNumberOfParameters(0); \
@ -392,7 +391,7 @@ namespace sls {
det->SETFCN(std::vector<int>{det_id}); \
os << "successful\n"; \
} else { \
throw RuntimeError("Unknown action"); \
throw RuntimeError("Unknown action"); \
} \
return os.str(); \
}
@ -403,12 +402,12 @@ namespace sls {
std::ostringstream os; \
os << cmd << ' '; \
if (det_id != -1) { \
throw RuntimeError("Cannot execute this at module level"); \
throw RuntimeError("Cannot execute this at module level"); \
} \
if (action == slsDetectorDefs::HELP_ACTION) \
os << HLPSTR << '\n'; \
else if (action == slsDetectorDefs::GET_ACTION) { \
throw RuntimeError("Cannot get"); \
throw RuntimeError("Cannot get"); \
} else if (action == slsDetectorDefs::PUT_ACTION) { \
if (args.size() != 1) { \
WrongNumberOfParameters(1); \
@ -416,7 +415,7 @@ namespace sls {
det->SETFCN(args[0]); \
os << args.front() << '\n'; \
} else { \
throw RuntimeError("Unknown action"); \
throw RuntimeError("Unknown action"); \
} \
return os.str(); \
}
@ -429,7 +428,7 @@ namespace sls {
if (action == slsDetectorDefs::HELP_ACTION) \
os << HLPSTR << '\n'; \
else if (action == slsDetectorDefs::GET_ACTION) { \
throw RuntimeError("Cannot get"); \
throw RuntimeError("Cannot get"); \
} else if (action == slsDetectorDefs::PUT_ACTION) { \
if (args.size() != 1) { \
WrongNumberOfParameters(1); \
@ -437,7 +436,7 @@ namespace sls {
det->SETFCN(args[0], std::vector<int>{det_id}); \
os << args.front() << '\n'; \
} else { \
throw RuntimeError("Unknown action"); \
throw RuntimeError("Unknown action"); \
} \
return os.str(); \
}
@ -456,9 +455,9 @@ namespace sls {
auto t = det->GETFCN(std::vector<int>{det_id}); \
os << OutString(t) << '\n'; \
} else if (action == slsDetectorDefs::PUT_ACTION) { \
throw RuntimeError("Cannot put"); \
throw RuntimeError("Cannot put"); \
} else { \
throw RuntimeError("Unknown action"); \
throw RuntimeError("Unknown action"); \
} \
return os.str(); \
}
@ -475,11 +474,11 @@ namespace sls {
WrongNumberOfParameters(0); \
} \
auto t = det->GETFCN(); \
os << ToString(t) << '\n'; \
os << ToString(t) << '\n'; \
} else if (action == slsDetectorDefs::PUT_ACTION) { \
throw RuntimeError("Cannot put"); \
throw RuntimeError("Cannot put"); \
} else { \
throw RuntimeError("Unknown action"); \
throw RuntimeError("Unknown action"); \
} \
return os.str(); \
}
@ -498,9 +497,9 @@ namespace sls {
auto t = det->GETFCN(std::vector<int>{det_id}); \
os << OutStringHex(t) << '\n'; \
} else if (action == slsDetectorDefs::PUT_ACTION) { \
throw RuntimeError("Cannot put"); \
throw RuntimeError("Cannot put"); \
} else { \
throw RuntimeError("Unknown action"); \
throw RuntimeError("Unknown action"); \
} \
return os.str(); \
}
@ -518,9 +517,9 @@ namespace sls {
auto t = det->GETFCN(VAL, std::vector<int>{det_id}); \
os << OutString(t) << APPEND << '\n'; \
} else if (action == slsDetectorDefs::PUT_ACTION) { \
throw RuntimeError("Cannot put"); \
throw RuntimeError("Cannot put"); \
} else { \
throw RuntimeError("Unknown action"); \
throw RuntimeError("Unknown action"); \
} \
return os.str(); \
}
@ -1196,7 +1195,10 @@ class CmdProxy {
/* Pattern */
std::string Pattern(int action);
std::string PatternWord(int action);
void GetLevelAndUpdateArgIndex(int action, std::string levelSeparatedCommand, int& level, int& iArg, size_t nGetArgs, size_t nPutArgs);
void GetLevelAndUpdateArgIndex(int action,
std::string levelSeparatedCommand,
int &level, int &iArg, size_t nGetArgs,
size_t nPutArgs);
std::string PatternLoopAddresses(int action);
std::string PatternLoopCycles(int action);
std::string PatternWaitAddress(int action);
@ -1604,7 +1606,6 @@ class CmdProxy {
"out from in a round robin fashion. The entry must not have been "
"empty. Default: 0");
INTEGER_COMMAND_VEC_ID(
udp_srcmac, getSourceUDPMAC, setSourceUDPMAC, MacAddr,
"[x:x:x:x:x:x]\n\tMac address of the detector (source) udp "
@ -1981,8 +1982,7 @@ class CmdProxy {
"users only.");
INTEGER_COMMAND_VEC_ID(
gainmode, getGainMode, setGainMode,
StringTo<slsDetectorDefs::gainMode>,
gainmode, getGainMode, setGainMode, StringTo<slsDetectorDefs::gainMode>,
"[dynamicgain|forceswitchg1|forceswitchg2|fixg1|fixg2|fixg0]\n\t["
"Jungfrau] Gain mode.\n\tCAUTION: Do not use fixg0 without caution, "
"you can damage the detector!!!");
@ -2047,11 +2047,15 @@ class CmdProxy {
INTEGER_COMMAND_VEC_ID(interpolation, getInterpolation, setInterpolation,
StringTo<int>,
"[0, 1]\n\t[Mythen3] Enables or disables "
"interpolation. Default is disabled. Interpolation mode enables all counters and disables vth3. Disabling sets back counter mask and vth3.");
"interpolation. Default is disabled. Interpolation "
"mode enables all counters and disables vth3. "
"Disabling sets back counter mask and vth3.");
INTEGER_COMMAND_VEC_ID(pumpprobe, getPumpProbe, setPumpProbe, StringTo<int>,
"[0, 1]\n\t[Mythen3] Enables or disables pump probe "
"mode. Default is disabled. Pump probe mode only enables vth2. Disabling sets back to previous value.");
INTEGER_COMMAND_VEC_ID(
pumpprobe, getPumpProbe, setPumpProbe, StringTo<int>,
"[0, 1]\n\t[Mythen3] Enables or disables pump probe "
"mode. Default is disabled. Pump probe mode only enables vth2. "
"Disabling sets back to previous value.");
INTEGER_COMMAND_VEC_ID(apulse, getAnalogPulsing, setAnalogPulsing,
StringTo<int>,

View File

@ -10,9 +10,9 @@
namespace sls {
CtbConfig::CtbConfig(){
for (size_t i=0; i!=num_dacs; ++i){
setDacName(i, "dac"+ToString(i));
CtbConfig::CtbConfig() {
for (size_t i = 0; i != num_dacs; ++i) {
setDacName(i, "dac" + ToString(i));
}
}
@ -25,11 +25,11 @@ void CtbConfig::check_index(size_t i) const {
}
void CtbConfig::check_size(const std::string &name) const {
if (name.empty())
throw RuntimeError("Name needs to be at least one character");
// dacname_length -1 to account for \0 termination
// dacname_length -1 to account for \0 termination
if (!(name.size() < (name_length - 1))) {
std::ostringstream oss;
oss << "Length of name needs to be less than " << name_length - 1
@ -48,8 +48,8 @@ void CtbConfig::setDacName(size_t index, const std::string &name) {
memcpy(dst, &name[0], name.size());
}
void CtbConfig::setDacNames(const std::vector<std::string>& names){
for (size_t i = 0; i!=num_dacs; ++i){
void CtbConfig::setDacNames(const std::vector<std::string> &names) {
for (size_t i = 0; i != num_dacs; ++i) {
setDacName(i, names[i]);
}
}
@ -65,8 +65,6 @@ std::vector<std::string> CtbConfig::getDacNames() const {
return names;
}
const char* CtbConfig::shm_tag(){
return shm_tag_;
}
const char *CtbConfig::shm_tag() { return shm_tag_; }
} // namespace sls

View File

@ -3,11 +3,10 @@
#include <vector>
namespace sls {
class CtbConfig {
static constexpr size_t name_length = 20;
static constexpr size_t num_dacs = 18;
static constexpr const char* shm_tag_ = "ctbdacs";
static constexpr const char *shm_tag_ = "ctbdacs";
char dacnames[name_length * num_dacs]{};
void check_index(size_t i) const;
@ -15,17 +14,16 @@ class CtbConfig {
public:
CtbConfig();
CtbConfig(const CtbConfig&) = default;
CtbConfig(CtbConfig&&) = default;
CtbConfig& operator=(const CtbConfig&) = default;
CtbConfig(const CtbConfig &) = default;
CtbConfig(CtbConfig &&) = default;
CtbConfig &operator=(const CtbConfig &) = default;
~CtbConfig() = default;
void setDacNames(const std::vector<std::string> &names);
void setDacName(size_t index, const std::string &name);
std::string getDacName(size_t index) const;
std::vector<std::string> getDacNames() const;
static const char* shm_tag();
static const char *shm_tag();
};
} // namespace sls

View File

@ -55,8 +55,7 @@ void freeSharedMemory(int detectorIndex, int moduleIndex) {
using defs = slsDetectorDefs;
Detector::Detector(int shm_id)
: pimpl(make_unique<DetectorImpl>(shm_id)) {}
Detector::Detector(int shm_id) : pimpl(make_unique<DetectorImpl>(shm_id)) {}
Detector::~Detector() = default;
@ -1795,7 +1794,7 @@ void Detector::setVetoAlgorithm(const defs::vetoAlgorithm alg,
defs::streamingInterface interface,
Positions pos) {
LOG(logDEBUG) << "alg:" << ToString(alg)
<< " interface:" << ToString(interface);
<< " interface:" << ToString(interface);
pimpl->Parallel(&Module::setVetoAlgorithm, pos, alg, interface);
}

View File

@ -185,8 +185,7 @@ void DetectorImpl::initializeMembers(bool verify) {
// get objects from single det shared memory (open)
for (int i = 0; i < shm()->totalNumberOfModules; i++) {
try {
modules.push_back(
make_unique<Module>(detectorIndex, i, verify));
modules.push_back(make_unique<Module>(detectorIndex, i, verify));
} catch (...) {
modules.clear();
throw;
@ -307,8 +306,7 @@ void DetectorImpl::addModule(const std::string &hostname) {
}
auto pos = modules.size();
modules.emplace_back(
make_unique<Module>(type, detectorIndex, pos, false));
modules.emplace_back(make_unique<Module>(type, detectorIndex, pos, false));
shm()->totalNumberOfModules = modules.size();
modules[pos]->setControlPort(port);
modules[pos]->setStopPort(port + 1);
@ -459,17 +457,17 @@ int DetectorImpl::createReceivingDataSockets() {
try {
zmqSocket.push_back(
make_unique<ZmqSocket>(modules[iSocket / numUDPInterfaces]
->getClientStreamingIP()
.str()
.c_str(),
portnum));
->getClientStreamingIP()
.str()
.c_str(),
portnum));
// set high water mark
int hwm = shm()->zmqHwm;
if (hwm >= 0) {
zmqSocket[iSocket]->SetReceiveHighWaterMark(hwm);
if (zmqSocket[iSocket]->GetReceiveHighWaterMark() != hwm) {
throw ZmqSocketError("Could not set zmq rcv hwm to " +
std::to_string(hwm));
std::to_string(hwm));
}
}
LOG(logINFO) << "Zmq Client[" << iSocket << "] at "
@ -672,7 +670,6 @@ void DetectorImpl::readFrameFromReceiver() {
<< "\n\t databytes: " << multisize
<< "\n\t dynamicRange: " << dynamicRange;
// send data to callback
if (data) {
char *callbackImage = multiframe.get();
@ -1063,7 +1060,7 @@ void DetectorImpl::setClientStreamingHwm(const int limit) {
if (it->GetReceiveHighWaterMark() != limit) {
shm()->zmqHwm = -1;
throw ZmqSocketError("Could not set zmq rcv hwm to " +
std::to_string(limit));
std::to_string(limit));
}
}
LOG(logINFO) << "Setting Client Zmq socket rcv hwm to " << limit;
@ -1186,10 +1183,10 @@ void DetectorImpl::startAcquisition(bool blocking, std::vector<int> positions) {
std::iota(begin(positions), end(positions), 0);
}
// could be all slaves in positions
slaves.reserve(positions.size());
slaves.reserve(positions.size());
auto is_master = Parallel(&Module::isMaster, positions);
for (size_t i : positions) {
if (is_master[i])
if (is_master[i])
master.push_back(i);
else
slaves.push_back(i);
@ -1418,8 +1415,8 @@ std::vector<char> DetectorImpl::readProgrammingFile(const std::string &fname) {
}
Result<int> DetectorImpl::getDefaultDac(defs::dacIndex index,
defs::detectorSettings sett,
Positions pos) {
defs::detectorSettings sett,
Positions pos) {
return Parallel(&Module::getDefaultDac, pos, index, sett);
}
@ -1463,7 +1460,8 @@ defs::ROI DetectorImpl::getRxROI() const {
auto t = Parallel(&Module::getRxROI, {});
if (t.equal() && t.front().completeRoi()) {
LOG(logDEBUG) << "no roi";
return defs::ROI (0, shm()->numberOfChannels.x - 1, 0, shm()->numberOfChannels.y - 1);
return defs::ROI(0, shm()->numberOfChannels.x - 1, 0,
shm()->numberOfChannels.y - 1);
}
defs::xy numChansPerMod = modules[0]->getNumberOfChannels();
@ -1537,21 +1535,26 @@ void DetectorImpl::setRxROI(const defs::ROI arg) {
throw RuntimeError("Invalid Roi of size 0.");
}
if (arg.completeRoi()) {
throw RuntimeError("Did you mean the clear roi command (API: clearRxROI, cmd: rx_clearroi)?");
throw RuntimeError("Did you mean the clear roi command (API: "
"clearRxROI, cmd: rx_clearroi)?");
}
if (arg.xmin > arg.xmax || arg.ymin > arg.ymax) {
throw RuntimeError("Invalid Receiver Roi. xmin/ymin exceeds xmax/ymax.");
throw RuntimeError(
"Invalid Receiver Roi. xmin/ymin exceeds xmax/ymax.");
}
defs::xy numChansPerMod = modules[0]->getNumberOfChannels();
bool is2D = (numChansPerMod.y > 1 ? true : false);
defs::xy geometry = getPortGeometry();
if (!is2D && ((arg.ymin != -1 && arg.ymin != 0) || (arg.ymax != -1 && arg.ymax != 0))) {
throw RuntimeError("Invalid Receiver roi. Cannot set 2d roi for a 1d detector.");
if (!is2D && ((arg.ymin != -1 && arg.ymin != 0) ||
(arg.ymax != -1 && arg.ymax != 0))) {
throw RuntimeError(
"Invalid Receiver roi. Cannot set 2d roi for a 1d detector.");
}
if (arg.xmin < 0 || arg.xmax >= shm()->numberOfChannels.x || (is2D && (arg.ymin < 0 || arg.ymax >= shm()->numberOfChannels.y))) {
if (arg.xmin < 0 || arg.xmax >= shm()->numberOfChannels.x ||
(is2D && (arg.ymin < 0 || arg.ymax >= shm()->numberOfChannels.y))) {
throw RuntimeError("Invalid Receiver Roi. Outside detector range.");
}
@ -1576,7 +1579,8 @@ void DetectorImpl::setRxROI(const defs::ROI arg) {
--moduleRoi.xmax;
}
} else {
throw RuntimeError("Cannot have more than 2 modules for a Gotthard2 detector");
throw RuntimeError("Cannot have more than 2 modules for a "
"Gotthard2 detector");
}
} else {
// get module limits
@ -1593,27 +1597,27 @@ void DetectorImpl::setRxROI(const defs::ROI arg) {
if (arg.xmin > moduleFullRoi.xmax ||
arg.xmax < moduleFullRoi.xmin ||
(is2D && (arg.ymin > moduleFullRoi.ymax ||
arg.ymax < moduleFullRoi.ymin))) {
arg.ymax < moduleFullRoi.ymin))) {
moduleRoi.setNoRoi();
}
// incomplete module roi
else if (arg.xmin > moduleFullRoi.xmin ||
arg.xmax < moduleFullRoi.xmax ||
(is2D && (arg.ymin > moduleFullRoi.ymin ||
arg.ymax < moduleFullRoi.ymax))) {
arg.xmax < moduleFullRoi.xmax ||
(is2D && (arg.ymin > moduleFullRoi.ymin ||
arg.ymax < moduleFullRoi.ymax))) {
moduleRoi.xmin = (arg.xmin <= moduleFullRoi.xmin)
? 0
: (arg.xmin % numChansPerMod.x);
? 0
: (arg.xmin % numChansPerMod.x);
moduleRoi.xmax = (arg.xmax >= moduleFullRoi.xmax)
? numChansPerMod.x - 1
: (arg.xmax % numChansPerMod.x);
? numChansPerMod.x - 1
: (arg.xmax % numChansPerMod.x);
if (is2D) {
moduleRoi.ymin = (arg.ymin <= moduleFullRoi.ymin)
? 0
: (arg.ymin % numChansPerMod.y);
? 0
: (arg.ymin % numChansPerMod.y);
moduleRoi.ymax = (arg.ymax >= moduleFullRoi.ymax)
? numChansPerMod.y - 1
: (arg.ymax % numChansPerMod.y);
? numChansPerMod.y - 1
: (arg.ymax % numChansPerMod.y);
}
}
}
@ -1625,7 +1629,9 @@ void DetectorImpl::setRxROI(const defs::ROI arg) {
// metadata
if (arg.completeRoi()) {
modules[0]->setRxROIMetadata(defs::ROI (0, shm()->numberOfChannels.x - 1, 0, shm()->numberOfChannels.y - 1));
modules[0]->setRxROIMetadata(defs::ROI(0, shm()->numberOfChannels.x - 1,
0,
shm()->numberOfChannels.y - 1));
} else {
modules[0]->setRxROIMetadata(arg);
}
@ -1639,7 +1645,6 @@ void DetectorImpl::clearRxROI() {
shm()->rx_roi.ymax = -1;
}
std::vector<std::string> DetectorImpl::getCtbDacNames() const {
return ctb_shm()->getDacNames();
}

View File

@ -2,20 +2,20 @@
// Copyright (C) 2021 Contributors to the SLS Detector Package
#pragma once
#include "CtbConfig.h"
#include "SharedMemory.h"
#include "sls/Result.h"
#include "sls/logger.h"
#include "sls/sls_detector_defs.h"
#include "CtbConfig.h"
#include <future>
#include <memory>
#include <mutex>
#include <numeric>
#include <semaphore.h>
#include <string>
#include <thread>
#include <vector>
#include <future>
#include <numeric>
namespace sls {
@ -87,8 +87,8 @@ class DetectorImpl : public virtual slsDetectorDefs {
template <class CT> struct NonDeduced { using type = CT; };
template <typename RT, typename... CT>
Result<RT> Parallel(RT (Module::*somefunc)(CT...),
std::vector<int> positions,
typename NonDeduced<CT>::type... Args) {
std::vector<int> positions,
typename NonDeduced<CT>::type... Args) {
if (modules.empty())
throw RuntimeError("No modules added");
@ -115,8 +115,8 @@ class DetectorImpl : public virtual slsDetectorDefs {
template <typename RT, typename... CT>
Result<RT> Parallel(RT (Module::*somefunc)(CT...) const,
std::vector<int> positions,
typename NonDeduced<CT>::type... Args) const {
std::vector<int> positions,
typename NonDeduced<CT>::type... Args) const {
if (modules.empty())
throw RuntimeError("No modules added");
@ -142,8 +142,7 @@ class DetectorImpl : public virtual slsDetectorDefs {
}
template <typename... CT>
void Parallel(void (Module::*somefunc)(CT...),
std::vector<int> positions,
void Parallel(void (Module::*somefunc)(CT...), std::vector<int> positions,
typename NonDeduced<CT>::type... Args) {
if (modules.empty())
@ -296,9 +295,8 @@ class DetectorImpl : public virtual slsDetectorDefs {
std::vector<char> readProgrammingFile(const std::string &fname);
void setNumberofUDPInterfaces(int n, Positions pos);
Result<int> getDefaultDac(defs::dacIndex index,
defs::detectorSettings sett,
Positions pos = {});
Result<int> getDefaultDac(defs::dacIndex index, defs::detectorSettings sett,
Positions pos = {});
void setDefaultDac(defs::dacIndex index, int defaultValue,
defs::detectorSettings sett, Positions pos);
defs::ROI getRxROI() const;

View File

@ -237,15 +237,16 @@ void Module::setAllThresholdEnergy(std::array<int, 3> e_eV,
throw RuntimeError("This detector should have called with 3 energies");
}
if (shm()->trimEnergies.empty()) {
throw RuntimeError(
"Trim energies have not been defined for this module yet! Use trimen.");
throw RuntimeError("Trim energies have not been defined for this "
"module yet! Use trimen.");
}
std::vector<int> energy(e_eV.begin(), e_eV.end());
// if all energies are same
if (allEqualTo(energy, energy[0])) {
if (energy[0] == -1) {
throw RuntimeError("Every energy provided to set threshold energy is -1. Typo?");
throw RuntimeError(
"Every energy provided to set threshold energy is -1. Typo?");
}
energy.resize(1);
}
@ -309,8 +310,10 @@ void Module::setAllThresholdEnergy(std::array<int, 3> e_eV,
trim2, trimbits);
// csr
if (myMod1.reg != myMod2.reg) {
throw RuntimeError("setAllThresholdEnergy: chip shift register values do not match between files for energy (eV) " +
std::to_string(energy[i]));
throw RuntimeError(
"setAllThresholdEnergy: chip shift register values do not "
"match between files for energy (eV) " +
std::to_string(energy[i]));
}
myMods[i].reg = myMod1.reg;
}
@ -319,12 +322,10 @@ void Module::setAllThresholdEnergy(std::array<int, 3> e_eV,
sls_detector_module myMod{shm()->detType};
myMod = myMods[0];
// if multiple thresholds, combine
if (myMods.size() > 1) {
auto counters = getSetBits(getCounterMask());
// average vtrim of enabled counters
int sum = 0;
for (size_t i = 0; i < counters.size(); ++i) {
@ -364,7 +365,9 @@ void Module::setAllThresholdEnergy(std::array<int, 3> e_eV,
}
// csr
if (myMods[0].reg != myMods[1].reg || myMods[1].reg != myMods[2].reg) {
throw RuntimeError("setAllThresholdEnergy: chip shift register values do not match between files for all energies");
throw RuntimeError(
"setAllThresholdEnergy: chip shift register values do not "
"match between files for all energies");
}
}
@ -2397,8 +2400,7 @@ void Module::setReceiverDbitList(std::vector<int> list) {
}
for (auto &it : list) {
if (it < 0 || it > 63) {
throw RuntimeError(
"Dbit list value must be between 0 and 63\n");
throw RuntimeError("Dbit list value must be between 0 and 63\n");
}
}
std::sort(begin(list), end(list));
@ -3297,8 +3299,8 @@ void Module::setModule(sls_detector_module &module, bool trimbits) {
}
}
if (out_of_range) {
LOG(logWARNING)
<< "Some trimbits were out of range, these have been replaced with 0 or 63.";
LOG(logWARNING) << "Some trimbits were out of range, these have "
"been replaced with 0 or 63.";
}
// check dacs
out_of_range = false;
@ -3318,8 +3320,9 @@ void Module::setModule(sls_detector_module &module, bool trimbits) {
}
}
if (out_of_range) {
LOG(logWARNING) << "Some dacs were out of range, "
"these have been replaced with 0/200 or 2800/2400.";
LOG(logWARNING)
<< "Some dacs were out of range, "
"these have been replaced with 0/200 or 2800/2400.";
}
}
auto client = DetectorSocket(shm()->hostname, shm()->controlPort);
@ -3391,14 +3394,18 @@ void Module::sendModule(sls_detector_module *myMod, ClientSocket &client) {
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));
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));
throw RuntimeError("Module size " + std::to_string(ts) +
" sent does not match expected size to be sent " +
std::to_string(expectedBytesSent));
}
}
void Module::receiveModule(sls_detector_module *myMod, ClientSocket &client) {
constexpr TLogLevel level = logDEBUG1;
LOG(level) << "Receiving Module";
@ -3630,33 +3637,36 @@ sls_detector_module Module::readSettingsFile(const std::string &fname,
return myMod;
}
void Module::saveSettingsFile(sls_detector_module &myMod, const std::string &fname) {
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.");
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;
LOG(logINFO) << "Settings for " << shm()->hostname << " written to "
<< fname;
}
void Module::sendProgram(bool blackfin, std::vector<char> buffer,

View File

@ -791,22 +791,22 @@ class Module : public virtual slsDetectorDefs {
static const int NIOS_WRITE_TO_FLASH_TIME_KERNEL = 40;
enum mythen3_DacIndex {
M_VCASSH,
M_VTH2,
M_VRSHAPER,
M_VRSHAPER_N,
M_VIPRE_OUT,
M_VTH3,
M_VTH1,
M_VICIN,
M_VCAS,
M_VRPREAMP,
M_VCAL_N,
M_VIPRE,
M_VISHAPER,
M_VCAL_P,
M_VTRIM,
M_VDCSH
M_VCASSH,
M_VTH2,
M_VRSHAPER,
M_VRSHAPER_N,
M_VIPRE_OUT,
M_VTH3,
M_VTH1,
M_VICIN,
M_VCAS,
M_VRPREAMP,
M_VCAL_N,
M_VIPRE,
M_VISHAPER,
M_VCAL_P,
M_VTRIM,
M_VDCSH
};
enum eiger_DacIndex {

View File

@ -29,11 +29,13 @@ bool Pattern::operator==(const Pattern &other) const {
if (pat->limits[i] != other.pat->limits[i])
return false;
}
for (size_t i = 0; i < (sizeof(pat->startloop) / sizeof(pat->startloop[0])); ++i) {
for (size_t i = 0; i < (sizeof(pat->startloop) / sizeof(pat->startloop[0]));
++i) {
if (pat->startloop[i] != other.pat->startloop[i])
return false;
}
for (size_t i = 0; i < (sizeof(pat->stoploop) / sizeof(pat->stoploop[0])); ++i) {
for (size_t i = 0; i < (sizeof(pat->stoploop) / sizeof(pat->stoploop[0]));
++i) {
if (pat->stoploop[i] != other.pat->stoploop[i])
return false;
}
@ -70,11 +72,10 @@ void Pattern::validate() const {
for (int i = 0; i != MAX_PATTERN_LEVELS; ++i) {
if (pat->startloop[i] >= MAX_PATTERN_LENGTH ||
pat->stoploop[i] >= MAX_PATTERN_LENGTH) {
throw RuntimeError(
"Invalid Pattern loop address for level " + ToString(i) +
std::string(" [") + ToString(pat->startloop[i]) +
std::string(", ") + ToString(pat->stoploop[i]) +
std::string("]"));
throw RuntimeError("Invalid Pattern loop address for level " +
ToString(i) + std::string(" [") +
ToString(pat->startloop[i]) + std::string(", ") +
ToString(pat->stoploop[i]) + std::string("]"));
}
if (pat->wait[i] >= MAX_PATTERN_LENGTH) {
throw RuntimeError("Invalid Pattern wait address for level " +
@ -129,26 +130,27 @@ void Pattern::load(const std::string &fname) {
}
pat->limits[0] = StringTo<uint32_t>(args[1]);
pat->limits[1] = StringTo<uint32_t>(args[2]);
}
else if (cmd == "patloop0" || cmd == "patloop1" ||
} else if (cmd == "patloop0" || cmd == "patloop1" ||
cmd == "patloop2" || cmd == "patloop") {
int level = -1, iArg = 1;
if (cmd == "patloop") {
if (nargs != 3) {
throw RuntimeError("Invalid arguments for " +
ToString(args));
ToString(args));
}
level = StringTo<int>(args[iArg++]);
} else {
LOG(logWARNING) << "Depreciated command. Please use patloop next time.";
LOG(logWARNING)
<< "Depreciated command. Please use patloop next time.";
if (nargs != 2) {
throw RuntimeError("Invalid arguments for " +
ToString(args));
ToString(args));
}
level = cmd[cmd.find_first_of("012")] - '0';
}
if (level < 0 || level >= MAX_PATTERN_LEVELS) {
throw RuntimeError("Invalid Pattern level. Options 0-" + std::to_string(MAX_PATTERN_LEVELS - 1));
throw RuntimeError("Invalid Pattern level. Options 0-" +
std::to_string(MAX_PATTERN_LEVELS - 1));
}
int loop1 = StringTo<uint32_t>(args[iArg++]);
int loop2 = StringTo<uint32_t>(args[iArg++]);
@ -160,19 +162,21 @@ void Pattern::load(const std::string &fname) {
if (cmd == "patnloop") {
if (nargs != 2) {
throw RuntimeError("Invalid arguments for " +
ToString(args));
ToString(args));
}
level = StringTo<int>(args[iArg++]);
} else {
LOG(logWARNING) << "Depreciated command. Please use patnloop next time.";
LOG(logWARNING) << "Depreciated command. Please use "
"patnloop next time.";
if (nargs != 1) {
throw RuntimeError("Invalid arguments for " +
ToString(args));
ToString(args));
}
level = cmd[cmd.find_first_of("012")] - '0';
}
if (level < 0 || level >= MAX_PATTERN_LEVELS) {
throw RuntimeError("Invalid Pattern level. Options 0-" + std::to_string(MAX_PATTERN_LEVELS - 1));
throw RuntimeError("Invalid Pattern level. Options 0-" +
std::to_string(MAX_PATTERN_LEVELS - 1));
}
pat->nloop[level] = StringTo<uint32_t>(args[iArg++]);
} else if (cmd == "patwait0" || cmd == "patwait1" ||
@ -181,19 +185,21 @@ void Pattern::load(const std::string &fname) {
if (cmd == "patwait") {
if (nargs != 2) {
throw RuntimeError("Invalid arguments for " +
ToString(args));
ToString(args));
}
level = StringTo<int>(args[iArg++]);
} else {
LOG(logWARNING) << "Depreciated command. Please use patwait next time.";
LOG(logWARNING)
<< "Depreciated command. Please use patwait next time.";
if (nargs != 1) {
throw RuntimeError("Invalid arguments for " +
ToString(args));
ToString(args));
}
level = cmd[cmd.find_first_of("012")] - '0';
}
if (level < 0 || level >= MAX_PATTERN_LEVELS) {
throw RuntimeError("Invalid Pattern level. Options 0-" + std::to_string(MAX_PATTERN_LEVELS - 1));
throw RuntimeError("Invalid Pattern level. Options 0-" +
std::to_string(MAX_PATTERN_LEVELS - 1));
}
pat->wait[level] = StringTo<uint32_t>(args[iArg++]);
} else if (cmd == "patwaittime0" || cmd == "patwaittime1" ||
@ -202,19 +208,21 @@ void Pattern::load(const std::string &fname) {
if (cmd == "patwaittime") {
if (nargs != 2) {
throw RuntimeError("Invalid arguments for " +
ToString(args));
ToString(args));
}
level = StringTo<int>(args[iArg++]);
} else {
LOG(logWARNING) << "Depreciated command. Please use patwaittime next time.";
LOG(logWARNING) << "Depreciated command. Please use "
"patwaittime next time.";
if (nargs != 1) {
throw RuntimeError("Invalid arguments for " +
ToString(args));
ToString(args));
}
level = cmd[cmd.find_first_of("012")] - '0';
}
if (level < 0 || level >= MAX_PATTERN_LEVELS) {
throw RuntimeError("Invalid Pattern level. Options 0-" + std::to_string(MAX_PATTERN_LEVELS - 1));
throw RuntimeError("Invalid Pattern level. Options 0-" +
std::to_string(MAX_PATTERN_LEVELS - 1));
}
pat->waittime[level] = StringTo<uint64_t>(args[iArg++]);
} else {
@ -279,10 +287,12 @@ std::string Pattern::str() const {
<< ToStringHex(pat->limits[1], addr_width) << std::endl;
for (int i = 0; i != MAX_PATTERN_LEVELS; ++i) {
oss << "patloop " << i << ' ' << ToStringHex(pat->startloop[i], addr_width) << " "
oss << "patloop " << i << ' '
<< ToStringHex(pat->startloop[i], addr_width) << " "
<< ToStringHex(pat->stoploop[i], addr_width) << std::endl
<< "patnloop " << pat->nloop[i] << std::endl
<< "patwait " << i << ' ' << ToStringHex(pat->wait[i], addr_width) << std::endl
<< "patwait " << i << ' ' << ToStringHex(pat->wait[i], addr_width)
<< std::endl
<< "patwaittime " << i << ' ' << pat->waittime[i] << std::endl;
}

View File

@ -13,17 +13,16 @@
#include "sls/logger.h"
#include "sls/sls_detector_exceptions.h"
#include <cerrno> // errno
#include <cstdlib>
#include <cerrno> // errno
#include <cstring> // strerror
#include <fcntl.h> // O_CREAT, O_TRUNC..
#include <iostream>
#include <sstream>
#include <string>
#include <sys/mman.h> // shared memory
#include <sys/stat.h> // fstat
#include <unistd.h>
#include <iostream>
#include <string>
namespace sls {