mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-19 00:07:13 +02:00
Counters (#71)
* mythen3: adding counters mask, firmware still takes only number of counters for now * mythen3: checking if module attached before powering on chip * bug fix: loop inital declaration not allowed in c * fix scope eiger test * mythen3: renamed setCounters to setCounterMask and getCounterMask in API * mythen3 replacing counting bits with popcount Co-authored-by: Erik Fröjdh <erik.frojdh@gmail.com>
This commit is contained in:

committed by
Erik Fröjdh

parent
70c54f4315
commit
de53747ddd
@ -26,8 +26,8 @@ std::ostream &operator<<(std::ostream &os,
|
||||
}
|
||||
|
||||
void CmdProxy::Call(const std::string &command,
|
||||
const std::vector<std::string> &arguments,
|
||||
int detector_id, int action, std::ostream &os) {
|
||||
const std::vector<std::string> &arguments, int detector_id,
|
||||
int action, std::ostream &os) {
|
||||
cmd = command;
|
||||
args = arguments;
|
||||
det_id = detector_id;
|
||||
@ -38,7 +38,8 @@ void CmdProxy::Call(const std::string &command,
|
||||
if (it != functions.end()) {
|
||||
os << ((*this).*(it->second))(action);
|
||||
} else {
|
||||
throw sls::RuntimeError(cmd + " Unknown command, use list to list all commands");
|
||||
throw sls::RuntimeError(
|
||||
cmd + " Unknown command, use list to list all commands");
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,7 +56,6 @@ bool CmdProxy::ReplaceIfDepreciated(std::string &command) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string> CmdProxy::GetProxyCommands() {
|
||||
std::vector<std::string> commands;
|
||||
for (const auto &it : functions)
|
||||
@ -703,8 +703,8 @@ std::vector<std::string> CmdProxy::DacCommands() {
|
||||
case defs::MYTHEN3:
|
||||
return std::vector<std::string>{
|
||||
"vcassh", "vth2", "vshaper", "vshaperneg", "vipre_out", "vth3",
|
||||
"vth1", "vicin", "vcas", "vpreamp", "vph", "vipre",
|
||||
"viinsh", "vpl", "vtrim", "vdcsh"};
|
||||
"vth1", "vicin", "vcas", "vpreamp", "vpl", "vipre",
|
||||
"viinsh", "vph", "vtrim", "vdcsh"};
|
||||
break;
|
||||
case defs::CHIPTESTBOARD:
|
||||
return std::vector<std::string>{
|
||||
@ -1151,69 +1151,125 @@ std::string CmdProxy::ClearROI(int action) {
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
||||
/* Gotthard2 Specific */
|
||||
|
||||
std::string CmdProxy::InjectChannel(int action) {
|
||||
std::ostringstream os;
|
||||
std::ostringstream os;
|
||||
os << cmd << ' ';
|
||||
if (action == defs::HELP_ACTION) {
|
||||
os << "[offset] [increment]\n\t[Gotthard2] Inject channels with current source for calibration. Offset is starting channel that is injected, increment determines succeeding channels to be injected." << '\n';
|
||||
os << "[offset] [increment]\n\t[Gotthard2] Inject channels with "
|
||||
"current source for calibration. Offset is starting channel that "
|
||||
"is injected, increment determines succeeding channels to be "
|
||||
"injected."
|
||||
<< '\n';
|
||||
} else if (action == defs::GET_ACTION) {
|
||||
if (!args.empty()) {
|
||||
WrongNumberOfParameters(0);
|
||||
}
|
||||
auto t = det->getInjectChannel({det_id});
|
||||
os << OutString(t) << '\n';
|
||||
} else if (action == defs::PUT_ACTION) {
|
||||
if (!args.empty()) {
|
||||
WrongNumberOfParameters(0);
|
||||
}
|
||||
auto t = det->getInjectChannel({det_id});
|
||||
os << OutString(t) << '\n';
|
||||
} else if (action == defs::PUT_ACTION) {
|
||||
if (args.size() != 2) {
|
||||
WrongNumberOfParameters(2);
|
||||
}
|
||||
det->setInjectChannel(std::stoi(args[0]), std::stoi(args[1]), {det_id});
|
||||
WrongNumberOfParameters(2);
|
||||
}
|
||||
det->setInjectChannel(std::stoi(args[0]), std::stoi(args[1]), {det_id});
|
||||
os << sls::ToString(args) << '\n';
|
||||
} else {
|
||||
} else {
|
||||
throw sls::RuntimeError("Unknown action");
|
||||
}
|
||||
return os.str();
|
||||
}
|
||||
|
||||
std::string CmdProxy::VetoPhoton(int action) {
|
||||
std::ostringstream os;
|
||||
std::ostringstream os;
|
||||
os << cmd << ' ';
|
||||
if (action == defs::HELP_ACTION) {
|
||||
os << "[n_chip] [#photons] [energy in keV] [reference file]\n\t[Gotthard2] Set veto reference for 128 channels for chip n_chip according to referenc file and #photons and energy in keV." << '\n';
|
||||
os << "[n_chip] [#photons] [energy in keV] [reference "
|
||||
"file]\n\t[Gotthard2] Set veto reference for 128 channels for "
|
||||
"chip n_chip according to referenc file and #photons and energy "
|
||||
"in keV."
|
||||
<< '\n';
|
||||
} else if (action == defs::GET_ACTION) {
|
||||
if (args.size() != 1) {
|
||||
WrongNumberOfParameters(1);
|
||||
}
|
||||
auto t = det->getVetoPhoton(std::stoi(args[0]), {det_id});
|
||||
os << args[0] << ' ' << OutStringHex(t) << '\n';
|
||||
} else if (action == defs::PUT_ACTION) {
|
||||
if (args.size() != 1) {
|
||||
WrongNumberOfParameters(1);
|
||||
}
|
||||
auto t = det->getVetoPhoton(std::stoi(args[0]), {det_id});
|
||||
os << args[0] << ' ' << OutStringHex(t) << '\n';
|
||||
} else if (action == defs::PUT_ACTION) {
|
||||
if (args.size() != 4) {
|
||||
WrongNumberOfParameters(4);
|
||||
}
|
||||
det->setVetoPhoton(std::stoi(args[0]), std::stoi(args[1]), std::stoi(args[2]), args[3], {det_id});
|
||||
WrongNumberOfParameters(4);
|
||||
}
|
||||
det->setVetoPhoton(std::stoi(args[0]), std::stoi(args[1]),
|
||||
std::stoi(args[2]), args[3], {det_id});
|
||||
os << sls::ToString(args) << '\n';
|
||||
} else {
|
||||
} else {
|
||||
throw sls::RuntimeError("Unknown action");
|
||||
}
|
||||
return os.str();
|
||||
}
|
||||
|
||||
std::string CmdProxy::VetoReference(int action) {
|
||||
std::ostringstream os;
|
||||
std::ostringstream os;
|
||||
os << cmd << ' ';
|
||||
if (action == defs::HELP_ACTION) {
|
||||
os << "[gain index] [12 bit value in hex] \n\t[Gotthard2] Set veto reference for all 128 channels for all chips." << '\n';
|
||||
os << "[gain index] [12 bit value in hex] \n\t[Gotthard2] Set veto "
|
||||
"reference for all 128 channels for all chips."
|
||||
<< '\n';
|
||||
} else if (action == defs::GET_ACTION) {
|
||||
throw sls::RuntimeError("cannot get vetoref. Did you mean vetophoton?");
|
||||
} else if (action == defs::PUT_ACTION) {
|
||||
} else if (action == defs::PUT_ACTION) {
|
||||
if (args.size() != 2) {
|
||||
WrongNumberOfParameters(2);
|
||||
}
|
||||
det->setVetoReference(std::stoi(args[0]), stoiHex(args[1]), {det_id});
|
||||
WrongNumberOfParameters(2);
|
||||
}
|
||||
det->setVetoReference(std::stoi(args[0]), stoiHex(args[1]), {det_id});
|
||||
os << sls::ToString(args) << '\n';
|
||||
} else {
|
||||
} else {
|
||||
throw sls::RuntimeError("Unknown action");
|
||||
}
|
||||
return os.str();
|
||||
}
|
||||
|
||||
/* Mythen3 Specific */
|
||||
|
||||
std::string CmdProxy::Counters(int action) {
|
||||
std::ostringstream os;
|
||||
os << cmd << ' ';
|
||||
if (action == defs::HELP_ACTION) {
|
||||
os << "[i0] [i1] [i2]... \n\t[Mythen3] List of counters enabled. Each "
|
||||
"element in list can be 0 - 2 and must be non repetitive."
|
||||
<< '\n';
|
||||
} else if (action == defs::GET_ACTION) {
|
||||
if (!args.empty()) {
|
||||
WrongNumberOfParameters(0);
|
||||
}
|
||||
auto mask = det->getCounterMask({det_id}).squash(-1);
|
||||
// scan counter enable mask to get vector
|
||||
std::vector <int> result;
|
||||
for (size_t i = 0; i < 32; ++i) {
|
||||
if (mask & (1 << i)) {
|
||||
result.push_back((int)i);
|
||||
}
|
||||
}
|
||||
os << sls::ToString(result) << '\n';
|
||||
} else if (action == defs::PUT_ACTION) {
|
||||
if (args.empty()) {
|
||||
WrongNumberOfParameters(1);
|
||||
}
|
||||
// convert vector to counter enable mask
|
||||
uint32_t mask = 0;
|
||||
for (size_t i = 0; i < args.size(); ++i) {
|
||||
int val = std::stoi(args[i]);
|
||||
// already enabled earlier
|
||||
if (mask & (1 << val)) {
|
||||
std::ostringstream oss;
|
||||
oss << "Duplicate counter values (" << val << ") in arguments";
|
||||
throw sls::RuntimeError(oss.str());
|
||||
}
|
||||
mask |= (1 << val);
|
||||
}
|
||||
det->setCounterMask(mask, {det_id});
|
||||
os << sls::ToString(args) << '\n';
|
||||
} else {
|
||||
throw sls::RuntimeError("Unknown action");
|
||||
}
|
||||
return os.str();
|
||||
@ -1335,7 +1391,8 @@ std::string CmdProxy::ReceiverDbitList(int action) {
|
||||
if (action == defs::HELP_ACTION) {
|
||||
os << "[all] or [i0] [i1] [i2]... \n\t[Ctb] List of digital signal "
|
||||
"bits read out. If all is used instead of a list, all digital "
|
||||
"bits (64) enabled. Each element in list can be 0 - 63 and non "
|
||||
"bits (64) enabled. Each element in list can be 0 - 63 and must "
|
||||
"be non "
|
||||
"repetitive."
|
||||
<< '\n';
|
||||
} else if (action == defs::GET_ACTION) {
|
||||
|
@ -529,6 +529,7 @@ class CmdProxy {
|
||||
{"digitest", "imagetest"},
|
||||
|
||||
/* Gotthard2 Specific */
|
||||
/* Mythen3 Specific */
|
||||
/* CTB Specific */
|
||||
{"flags", "romode"},
|
||||
{"i_a", "im_a"},
|
||||
@ -785,6 +786,9 @@ class CmdProxy {
|
||||
{"vetoref", &CmdProxy::VetoReference},
|
||||
{"burstmode", &CmdProxy::burstmode},
|
||||
|
||||
/* Mythen3 Specific */
|
||||
{"counters", &CmdProxy::Counters},
|
||||
|
||||
/* CTB Specific */
|
||||
{"samples", &CmdProxy::Samples},
|
||||
{"asamples", &CmdProxy::asamples},
|
||||
@ -938,7 +942,9 @@ class CmdProxy {
|
||||
/* Gotthard2 Specific */
|
||||
std::string InjectChannel(int action);
|
||||
std::string VetoPhoton(int action);
|
||||
std::string VetoReference(int action);
|
||||
std::string VetoReference(int action);
|
||||
/* Mythen3 Specific */
|
||||
std::string Counters(int action);
|
||||
/* CTB Specific */
|
||||
std::string Samples(int action);
|
||||
std::string Dbitphase(int action);
|
||||
@ -1526,6 +1532,8 @@ class CmdProxy {
|
||||
INTEGER_COMMAND(burstmode, getBurstMode, setBurstMode, std::stoi,
|
||||
"[0, 1]\n\t[Gotthard2] 1 sets to burst mode. 0 sets to continuous mode. Default is burst mode.");
|
||||
|
||||
/* Mythen3 Specific */
|
||||
|
||||
/* CTB Specific */
|
||||
|
||||
INTEGER_COMMAND(asamples, getNumberOfAnalogSamples, setNumberOfAnalogSamples, std::stoi,
|
||||
|
@ -1188,6 +1188,16 @@ Result<bool> Detector::getBurstMode(Positions pos) {
|
||||
return pimpl->Parallel(&slsDetector::getBurstMode, pos);
|
||||
}
|
||||
|
||||
// Mythen3 Specific
|
||||
|
||||
Result<uint32_t> Detector::getCounterMask(Positions pos) const {
|
||||
return pimpl->Parallel(&slsDetector::getCounterMask, pos);
|
||||
}
|
||||
|
||||
void Detector::setCounterMask(uint32_t countermask, Positions pos) {
|
||||
pimpl->Parallel(&slsDetector::setCounterMask, pos, countermask);
|
||||
}
|
||||
|
||||
// CTB Specific
|
||||
|
||||
Result<int> Detector::getNumberOfAnalogSamples(Positions pos) const {
|
||||
|
@ -1720,36 +1720,6 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) {
|
||||
shm()->useReceiverFlag = true;
|
||||
checkReceiverVersionCompatibility();
|
||||
|
||||
FILE_LOG(logDEBUG)
|
||||
<< "detector type:"
|
||||
<< (ToString(shm()->myDetectorType))
|
||||
<< "\ndetector id:" << detId
|
||||
<< "\ndetector hostname:" << shm()->hostname
|
||||
<< "\nfile path:" << shm()->rxFilePath
|
||||
<< "\nfile name:" << shm()->rxFileName
|
||||
<< "\nfile index:" << shm()->rxFileIndex
|
||||
<< "\nfile format:" << shm()->rxFileFormat
|
||||
<< "\nr_framesperfile:" << shm()->rxFramesPerFile
|
||||
<< "\nr_discardpolicy:" << shm()->rxFrameDiscardMode
|
||||
<< "\nr_padding:" << shm()->rxFramePadding
|
||||
<< "\nwrite enable:" << shm()->rxFileWrite
|
||||
<< "\nmaster write enable:" << shm()->rxMasterFileWrite
|
||||
<< "\noverwrite enable:" << shm()->rxFileOverWrite
|
||||
<< "\ndynamic range:" << shm()->dynamicRange
|
||||
<< "\nflippeddatax:" << (shm()->flippedDataX)
|
||||
<< "\nactivated: " << shm()->activated
|
||||
<< "\nreceiver deactivated padding: " << shm()->rxPadDeactivatedModules
|
||||
<< "\nsilent Mode:" << shm()->rxSilentMode
|
||||
<< "\n10GbE:" << shm()->tenGigaEnable
|
||||
<< "\nGap pixels: " << shm()->gappixels
|
||||
<< "\nr_readfreq:" << shm()->rxReadFreq
|
||||
<< "\nrx streaming port:" << shm()->rxZmqport
|
||||
<< "\nrx streaming source ip:" << shm()->rxZmqip
|
||||
<< "\nrx additional json header:" << shm()->rxAdditionalJsonHeader
|
||||
<< "\nrx_datastream:" << enableDataStreamingFromReceiver(-1)
|
||||
<< "\nrx_dbitlistsize:" << shm()->rxDbitList.size()
|
||||
<< "\nrx_DbitOffset:" << shm()->rxDbitOffset << std::endl;
|
||||
|
||||
if (setDetectorType(shm()->myDetectorType) != GENERIC) {
|
||||
sendMultiDetectorSize();
|
||||
setDetectorId();
|
||||
@ -1821,6 +1791,10 @@ std::string slsDetector::setReceiverHostname(const std::string &receiverIP) {
|
||||
sendROItoReceiver();
|
||||
break;
|
||||
|
||||
case MYTHEN3:
|
||||
sendNumberofCounterstoReceiver(getCounterMask());
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -3531,6 +3505,9 @@ std::vector<uint64_t> slsDetector::getNumMissingPackets() const {
|
||||
throw RuntimeError("Receiver " + std::to_string(detId) +
|
||||
" returned error: " + std::string(mess));
|
||||
} else {
|
||||
if (ret == FORCE_UPDATE) {
|
||||
updateCachedReceiverVariables();
|
||||
}
|
||||
int nports = -1;
|
||||
client.Receive(&nports, sizeof(nports));
|
||||
uint64_t mp[nports];
|
||||
@ -3888,6 +3865,27 @@ void slsDetector::setPipeline(int clkIndex, int value) {
|
||||
sendToDetector(F_SET_PIPELINE, args, nullptr);
|
||||
}
|
||||
|
||||
void slsDetector::setCounterMask(uint32_t countermask) {
|
||||
FILE_LOG(logDEBUG1) << "Setting Counter mask to " << countermask;
|
||||
sendToDetector(F_SET_COUNTER_MASK, countermask, nullptr);
|
||||
sendNumberofCounterstoReceiver(countermask);
|
||||
}
|
||||
|
||||
void slsDetector::sendNumberofCounterstoReceiver(uint32_t countermask) {
|
||||
if (shm()->useReceiverFlag) {
|
||||
int ncounters = __builtin_popcount(countermask);
|
||||
FILE_LOG(logDEBUG1) << "Sending Reciver #counters: " << ncounters;
|
||||
sendToReceiver(F_RECEIVER_SET_NUM_COUNTERS, ncounters, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t slsDetector::getCounterMask() {
|
||||
uint32_t retval = 0;
|
||||
sendToDetector(F_GET_COUNTER_MASK, nullptr, retval);
|
||||
FILE_LOG(logDEBUG1) << "Received counter mask: " << retval;
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
sls_detector_module slsDetector::interpolateTrim(sls_detector_module *a,
|
||||
sls_detector_module *b,
|
||||
|
@ -1862,6 +1862,15 @@ class slsDetector : public virtual slsDetectorDefs {
|
||||
|
||||
/** [Ctb][Moench] */
|
||||
void setPipeline(int clkIndex, int value);
|
||||
|
||||
/** [Mythen3] */
|
||||
void setCounterMask(uint32_t countermask);
|
||||
|
||||
/** [Mythen3] */
|
||||
void sendNumberofCounterstoReceiver(uint32_t countermask);
|
||||
|
||||
/** [Mythen3] */
|
||||
uint32_t getCounterMask();
|
||||
|
||||
private:
|
||||
/**
|
||||
|
Reference in New Issue
Block a user