Merge pull request #111 from slsdetectorgroup/shm

Shm
This commit is contained in:
Dhanya Thattil
2020-07-07 13:35:52 +02:00
committed by GitHub
50 changed files with 1646 additions and 1170 deletions

View File

@ -394,7 +394,16 @@ class Detector {
/** [Eiger] Sends an internal software trigger to the detector */
void sendSoftwareTrigger(Positions pos = {});
// TODO: remove resetframescaught in receiver
Result<defs::scanParameters> getScan(Positions pos = {}) const;
/** enables/ disables scans for dac, trimbits [Eiger/ Mythen3]
* TRIMBIT_SCAN. Enabling scan sets number of frames to number of steps in
* receiver. Disabling scan sets number of frames to 1 */
void setScan(const defs::scanParameters t);
/** gets scan error message in case of error during scan in case of non
* blocking acquisition (startDetector, not acquire) */
Result<std::string> getScanErrorMessage(Positions pos = {}) const;
/**************************************************
* *

View File

@ -178,7 +178,7 @@ std::string CmdProxy::VirtualServer(int action) {
return os.str();
}
std::string CmdProxy::acquire(int action) {
std::string CmdProxy::Acquire(int action) {
std::ostringstream os;
if (action == defs::HELP_ACTION) {
os << cmd << " - Acquire the number of frames set up.\n";
@ -991,6 +991,60 @@ std::string CmdProxy::DetectorStatus(int action) {
return os.str();
}
std::string CmdProxy::Scan(int action) {
std::ostringstream os;
os << cmd << ' ';
if (action == defs::HELP_ACTION) {
os << "[dac_name|0|trimbit_scan] [start_val] [stop_val] "
"[step_size] [dac settling time ns|us|ms|s]\n\tConfigures to "
"scan dac and sets number of frames to number of steps. Must "
"acquire after this. To cancel the scan configuration "
"set dac to '0' without further arguments. This also sets number "
"of frames back to 1."
"\n\t[Eiger]Use trimbit_scan as dac name for a trimbit scan."
<< '\n';
} else if (action == defs::GET_ACTION) {
if (args.size() != 0) {
WrongNumberOfParameters(0);
}
auto t = det->getScan();
os << OutString(t) << '\n';
} else if (action == defs::PUT_ACTION) {
if (det_id != -1) {
throw sls::RuntimeError(
"Cannot configure scan at module level");
}
// disable
if (args.size() == 1) {
if (StringTo<int>(args[0]) != 0) {
throw sls::RuntimeError("Did you mean '0' to disable?");
}
det->setScan(defs::scanParameters());
}
// enable without settling time
else if (args.size() == 4) {
det->setScan(defs::scanParameters(
StringTo<defs::dacIndex>(args[0]), StringTo<int>(args[1]),
StringTo<int>(args[2]), StringTo<int>(args[3])));
}
// enable with all parameters
else if (args.size() == 5) {
std::string time_str(args[4]);
std::string unit = RemoveUnit(time_str);
auto t = StringTo<time::ns>(time_str, unit);
det->setScan(defs::scanParameters(
StringTo<defs::dacIndex>(args[0]), StringTo<int>(args[1]),
StringTo<int>(args[2]), StringTo<int>(args[3]), t));
} else {
WrongNumberOfParameters(4);
}
os << ToString(args) << '\n';
} else {
throw sls::RuntimeError("Unknown action");
}
return os.str();
}
/* Network Configuration (Detector<->Receiver) */
std::string CmdProxy::UDPDestinationIP(int action) {

View File

@ -612,7 +612,7 @@ class CmdProxy {
{"gappixels", &CmdProxy::GapPixels},
/* acquisition parameters */
{"acquire", &CmdProxy::acquire},
{"acquire", &CmdProxy::Acquire},
{"frames", &CmdProxy::frames},
{"triggers", &CmdProxy::triggers},
{"exptime", &CmdProxy::Exptime},
@ -737,6 +737,8 @@ class CmdProxy {
{"rx_missingpackets", &CmdProxy::rx_missingpackets},
{"startingfnum", &CmdProxy::startingfnum},
{"trigger", &CmdProxy::trigger},
{"scan", &CmdProxy::Scan},
{"scanerrmsg", &CmdProxy::scanerrmsg},
/* Network Configuration (Detector<->Receiver) */
{"numinterfaces", &CmdProxy::numinterfaces},
@ -965,7 +967,7 @@ class CmdProxy {
std::string SettingsList(int action);
std::string GapPixels(int action);
/* acquisition parameters */
std::string acquire(int action);
std::string Acquire(int action);
std::string Exptime(int action);
std::string Speed(int action);
std::string Adcphase(int action);
@ -983,6 +985,7 @@ class CmdProxy {
/* acquisition */
std::string ReceiverStatus(int action);
std::string DetectorStatus(int action);
std::string Scan(int action);
/* Network Configuration (Detector<->Receiver) */
std::string UDPDestinationIP(int action);
std::string UDPDestinationIP2(int action);
@ -1552,6 +1555,10 @@ class CmdProxy {
trigger, sendSoftwareTrigger,
"\n\t[Eiger] Sends software trigger signal to detector.");
GET_COMMAND(scanerrmsg, getScanErrorMessage,
"\n\tGets Scan error message if scan ended in error for non "
"blocking acquisitions.");
/* Network Configuration (Detector<->Receiver) */
INTEGER_COMMAND(

View File

@ -525,9 +525,6 @@ void Detector::startReceiver() { pimpl->Parallel(&Module::startReceiver, {}); }
void Detector::stopReceiver() { pimpl->Parallel(&Module::stopReceiver, {}); }
void Detector::startDetector() {
if (getDetectorType().squash() == defs::EIGER) {
pimpl->Parallel(&Module::prepareAcquisition, {});
}
pimpl->Parallel(&Module::startAcquisition, {});
}
@ -562,6 +559,18 @@ void Detector::sendSoftwareTrigger(Positions pos) {
pimpl->Parallel(&Module::sendSoftwareTrigger, pos);
}
Result<defs::scanParameters> Detector::getScan(Positions pos) const {
return pimpl->Parallel(&Module::getScan, pos);
}
void Detector::setScan(const defs::scanParameters t) {
pimpl->Parallel(&Module::setScan, {}, t);
}
Result<std::string> Detector::getScanErrorMessage(Positions pos) const {
return pimpl->Parallel(&Module::getScanErrorMessage, pos);
}
// Network Configuration (Detector<->Receiver)
Result<int> Detector::getNumberofUDPInterfaces(Positions pos) const {

View File

@ -1046,9 +1046,6 @@ int DetectorImpl::acquire() {
// start and read all
try {
if (multi_shm()->multiDetectorType == EIGER) {
Parallel(&Module::prepareAcquisition, {});
}
Parallel(&Module::startAndReadAll, {});
} catch (...) {
if (receiver)

View File

@ -367,8 +367,6 @@ void Module::stopReceiver() {
sendToReceiver(F_STOP_RECEIVER, arg, nullptr);
}
void Module::prepareAcquisition() { sendToDetector(F_PREPARE_ACQUISITION); }
void Module::startAcquisition() {
shm()->stoppedFlag = false;
sendToDetector(F_START_ACQUISITION);
@ -451,6 +449,22 @@ void Module::setStartingFrameNumber(uint64_t value) {
void Module::sendSoftwareTrigger() { sendToDetectorStop(F_SOFTWARE_TRIGGER); }
defs::scanParameters Module::getScan() {
return sendToDetector<defs::scanParameters>(F_GET_SCAN);
}
void Module::setScan(const defs::scanParameters t) {
auto retval = sendToDetector<int64_t>(F_SET_SCAN, t);
// if disabled, retval is 1, else its number of steps
setNumberOfFrames(retval);
}
std::string Module::getScanErrorMessage() {
char retval[MAX_STR_LENGTH]{};
sendToDetector(F_GET_SCAN_ERROR_MESSAGE, nullptr, retval);
return retval;
}
// Network Configuration (Detector<->Receiver)
int Module::getNumberofUDPInterfacesFromShm() {

View File

@ -155,7 +155,6 @@ class Module : public virtual slsDetectorDefs {
* ************************************************/
void startReceiver();
void stopReceiver();
void prepareAcquisition();
void startAcquisition();
void stopAcquisition();
void startAndReadAll();
@ -167,6 +166,9 @@ class Module : public virtual slsDetectorDefs {
uint64_t getStartingFrameNumber();
void setStartingFrameNumber(uint64_t value);
void sendSoftwareTrigger();
defs::scanParameters getScan();
void setScan(const defs::scanParameters t);
std::string getScanErrorMessage();
/**************************************************
* *

View File

@ -1178,6 +1178,134 @@ TEST_CASE("startingfnum", "[.cmd][.new]") {
}
}
TEST_CASE("scan", "[.cmd][.new]") {
Detector det;
CmdProxy proxy(&det);
defs::dacIndex ind = defs::DAC_0;
defs::dacIndex notImplementedInd = defs::DAC_0;
auto det_type = det.getDetectorType().squash();
switch (det_type) {
case defs::CHIPTESTBOARD:
ind = defs::DAC_0;
notImplementedInd = defs::VSVP;
break;
case defs::EIGER:
ind = defs::VCMP_LL;
notImplementedInd = defs::VCASCP_PB;
break;
case defs::JUNGFRAU:
ind = defs::VB_COMP;
notImplementedInd = defs::VSVP;
break;
case defs::GOTTHARD:
ind = defs::VREF_DS;
notImplementedInd = defs::VSVP;
break;
case defs::MOENCH:
ind = defs::VBP_COLBUF;
notImplementedInd = defs::VSVP;
break;
case defs::GOTTHARD2:
ind = defs::VB_COMP_FE;
notImplementedInd = defs::VSVP;
break;
case defs::MYTHEN3:
ind = defs::VTH2;
notImplementedInd = defs::VSVP;
break;
default:
break;
}
// when taking acquisition
// auto previous = det.getDAC(ind, false);
// auto notImplementedPrevious = det.getDAC(notImplementedInd, false);
{
std::ostringstream oss;
proxy.Call("scan", {sls::ToString(ind), "500", "1500", "500"}, -1, PUT,
oss);
REQUIRE(oss.str() ==
"scan [" + sls::ToString(ind) + ", 500, 1500, 500]\n");
}
{
std::ostringstream oss;
proxy.Call("scan", {}, -1, GET, oss);
REQUIRE(oss.str() == "scan [[enabled\ndac " + sls::ToString(ind) +
"\nstart 500\nstop 1500\nstep "
"500\nsettleTime 1ms\n]]\n");
}
{
std::ostringstream oss;
proxy.Call("scan", {sls::ToString(ind), "500", "1500", "500", "2s"}, -1,
PUT, oss);
REQUIRE(oss.str() ==
"scan [" + sls::ToString(ind) + ", 500, 1500, 500, 2s]\n");
}
{
std::ostringstream oss;
proxy.Call("scan", {}, -1, GET, oss);
REQUIRE(oss.str() == "scan [[enabled\ndac " + sls::ToString(ind) +
"\nstart 500\nstop 1500\nstep "
"500\nsettleTime 2s\n]]\n");
}
{
std::ostringstream oss;
proxy.Call("scan", {"0"}, -1, PUT, oss);
REQUIRE(oss.str() == "scan [0]\n");
}
{
std::ostringstream oss;
proxy.Call("scan", {}, -1, GET, oss);
REQUIRE(oss.str() == "scan [[disabled]]\n");
}
{
std::ostringstream oss;
proxy.Call("scan", {sls::ToString(ind), "1500", "500", "-500"}, -1, PUT,
oss);
REQUIRE(oss.str() ==
"scan [" + sls::ToString(ind) + ", 1500, 500, -500]\n");
}
REQUIRE_THROWS(proxy.Call(
"scan", {sls::ToString(notImplementedInd), "500", "1500", "500"}, -1,
PUT));
REQUIRE_THROWS(proxy.Call(
"scan", {sls::ToString(ind), "500", "1500", "-500"}, -1, PUT));
REQUIRE_THROWS(proxy.Call(
"scan", {sls::ToString(ind), "1500", "500", "500"}, -1, PUT));
if (det_type == defs::MYTHEN3 || defs::EIGER) {
{
std::ostringstream oss;
proxy.Call("scan", {"trimbit_scan", "0", "63", "16", "2s"}, -1, PUT,
oss);
REQUIRE(oss.str() == "scan [trimbit_scan, 0, 63, 16, 2s]\n");
}
{
std::ostringstream oss;
proxy.Call("scan", {}, -1, GET, oss);
REQUIRE(oss.str() ==
"scan [[enabled\ndac trimbit_scan\nstart 0\nstop 48\nstep "
"16\nsettleTime 2s\n]]\n");
}
}
// acquire for each?
// when taking acquisition
// Reset all dacs to previous value
// for (int i = 0; i != det.size(); ++i) {
// det.setDAC(ind, previous[i], false, {i});
// det.setDAC(notImplementedInd, notImplementedPrevious[i], false, {i});
// }
}
TEST_CASE("scanerrmsg", "[.cmd][.new]") {
Detector det;
CmdProxy proxy(&det);
REQUIRE_NOTHROW(proxy.Call("scanerrmsg", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("scanerrmsg", {""}, -1, PUT));
}
TEST_CASE("gappixels", "[.cmd][.new]") {
Detector det;
CmdProxy proxy(&det);