From 5292075a0acfbf0f4aeab1974b4bd17a5aa41fad Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Fri, 9 Aug 2019 09:35:02 +0200 Subject: [PATCH 1/2] WIP --- slsDetectorSoftware/include/Detector.h | 27 +++++++++++++ .../include/multiSlsDetector.h | 16 ++++---- slsDetectorSoftware/src/Detector.cpp | 38 ++++++++++++++++++- 3 files changed, 72 insertions(+), 9 deletions(-) diff --git a/slsDetectorSoftware/include/Detector.h b/slsDetectorSoftware/include/Detector.h index 732e3ee7a..d5e8919eb 100644 --- a/slsDetectorSoftware/include/Detector.h +++ b/slsDetectorSoftware/include/Detector.h @@ -814,6 +814,33 @@ class Detector { void setActive(bool active, Positions pos = {}); Result getActive(Positions pos = {}) const; + + /** [Gotthard][Jungfrau][CTB] not possible to read back*/ + void writeAdcRegister(uint32_t addr, uint32_t value, Positions pos = {}); + + /** [CTB] How much digital data in bytes is skipped */ + Result getReceiverDbitOffset(Positions pos = {}) const; + + /** [CTB] Set how many bytes of digital data to skip */ + void setReceiverDbitOffset(int value, Positions pos = {}); + + /** [CTB] Which of the bits 0-63 to save*/ + Result> getReceiverDbitList(Positions pos = {}) const; + + /** [CTB] Which of the bits 0-63 to save*/ + void setReceiverDbitList(std::vector list, Positions pos = {}); + + /** [CTB] */ + Result getExternalSampling(Positions pos = {}) const; + + /** [CTB] */ + void setExternalSampling(bool value, Positions pos = {}); + + /** [CTB] */ + Result getExternalSamplingSource(Positions pos = {}) const; + + /** [CTB] Value between 0-63 */ + void setExternalSamplingSource(int value, Positions pos = {}); }; } // namespace sls \ No newline at end of file diff --git a/slsDetectorSoftware/include/multiSlsDetector.h b/slsDetectorSoftware/include/multiSlsDetector.h index 9826b9477..33cd3778b 100755 --- a/slsDetectorSoftware/include/multiSlsDetector.h +++ b/slsDetectorSoftware/include/multiSlsDetector.h @@ -1494,42 +1494,42 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param value external sampling source (Option: 0-63) * @param detPos -1 for all detectors in list or specific detector position */ - void setExternalSampling(bool value, int detPos = -1); + void setExternalSampling(bool value, int detPos = -1); // /** * Get external sampling source (CTB only) * @param detPos -1 for all detectors in list or specific detector position * @returns external sampling enable */ - int getExternalSampling(int detPos = -1); + int getExternalSampling(int detPos = -1); // /** * Set external sampling enable (CTB only) * @param list external sampling source (Option: 0-63) * @param detPos -1 for all detectors in list or specific detector position */ - void setReceiverDbitList(std::vector list, int detPos = -1); + void setReceiverDbitList(std::vector list, int detPos = -1); // /** * Get external sampling source (CTB only) * @param detPos -1 for all detectors in list or specific detector position * @returns external sampling enable */ - std::vector getReceiverDbitList(int detPos = -1); + std::vector getReceiverDbitList(int detPos = -1); // /** * Set digital data offset in bytes (CTB only) * @param value digital data offset in bytes * @param detPos -1 for all detectors in list or specific detector position */ - void setReceiverDbitOffset(int value, int detPos = -1); + void setReceiverDbitOffset(int value, int detPos = -1); // /** * Get digital data offset in bytes (CTB only) * @param detPos -1 for all detectors in list or specific detector position * @returns digital data offset in bytes */ - int getReceiverDbitOffset(int detPos = -1); + int getReceiverDbitOffset(int detPos = -1); // /** * Write to ADC register (Gotthard, Jungfrau, ChipTestBoard). For expert @@ -1538,7 +1538,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param val value * @param detPos -1 for all detectors in list or specific detector position */ - void writeAdcRegister(uint32_t addr, uint32_t val, int detPos = -1); + void writeAdcRegister(uint32_t addr, uint32_t val, int detPos = -1); // /** * Activates/Deactivates the detector (Eiger only) @@ -1546,7 +1546,7 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns 0 (inactive) or 1 (active)for activate mode */ - int activate(int const enable = -1, int detPos = -1); + int activate(int const enable = -1, int detPos = -1); // /** * Set deactivated Receiver padding mode (Eiger only) diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index c1736160e..1598c9c4c 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -688,7 +688,43 @@ void Detector::setActive(bool active, Positions pos){ } Result Detector::getActive(Positions pos) const{ - pimpl->Parallel(&slsDetector::activate, pos, -1); + return pimpl->Parallel(&slsDetector::activate, pos, -1); +} + +void Detector::writeAdcRegister(uint32_t addr, uint32_t value, Positions pos){ + pimpl->Parallel(&slsDetector::writeAdcRegister, pos, addr, value); +} + +Result Detector::getReceiverDbitOffset(Positions pos) const{ + return pimpl->Parallel(&slsDetector::getReceiverDbitOffset, pos); +} + +void Detector::setReceiverDbitOffset(int value, Positions pos){ + pimpl->Parallel(&slsDetector::setReceiverDbitOffset, pos, value); +} + +Result> Detector::getReceiverDbitList(Positions pos) const{ + return pimpl->Parallel(&slsDetector::getReceiverDbitList, pos); +} + +void Detector::setReceiverDbitList(std::vector list, Positions pos){ + pimpl->Parallel(&slsDetector::setReceiverDbitList, pos, list); +} + +Result Detector::getExternalSampling(Positions pos) const{ + return pimpl->Parallel(&slsDetector::getExternalSampling, pos); +} + +void Detector::setExternalSampling(bool value, Positions pos){ + pimpl->Parallel(&slsDetector::setExternalSampling, pos, value); +} + +Result Detector::getExternalSamplingSource(Positions pos) const{ + return pimpl->Parallel(&slsDetector::getExternalSamplingSource, pos); +} + +void Detector::setExternalSamplingSource(int value, Positions pos){ + pimpl->Parallel(&slsDetector::setExternalSamplingSource, pos, value); } } // namespace sls \ No newline at end of file From dfbf7ab39a2195f416a0299a3a5f4e28a02acf31 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Fri, 9 Aug 2019 11:00:12 +0200 Subject: [PATCH 2/2] tsquash --- slsDetectorSoftware/include/Result.h | 10 ++++- .../include/multiSlsDetector.h | 6 ++- slsDetectorSoftware/src/Detector.cpp | 40 ++++++++++--------- slsDetectorSoftware/src/multiSlsDetector.cpp | 10 +++++ slsDetectorSoftware/tests/test-Result.cpp | 11 +++++ slsSupportLib/include/sls_detector_defs.h | 12 ++++++ 6 files changed, 69 insertions(+), 20 deletions(-) diff --git a/slsDetectorSoftware/include/Result.h b/slsDetectorSoftware/include/Result.h index 33ce0c04a..9127ddfc1 100644 --- a/slsDetectorSoftware/include/Result.h +++ b/slsDetectorSoftware/include/Result.h @@ -105,11 +105,19 @@ template > class Result { */ T squash() const { return Squash(vec); } + T tsquash(const std::string &error_msg) { + if (equal()) + return vec.front(); + else + throw RuntimeError(error_msg); + } /** * If all elements are equal return the front value, otherwise * return the supplied default value */ - T squash(T default_value) const { return Squash(vec, default_value); } + T squash(const T &default_value) const { + return Squash(vec, default_value); + } /** Test whether all elements of the result are equal */ bool equal() const noexcept { return allEqual(vec); } diff --git a/slsDetectorSoftware/include/multiSlsDetector.h b/slsDetectorSoftware/include/multiSlsDetector.h index 33cd3778b..fca6716e9 100755 --- a/slsDetectorSoftware/include/multiSlsDetector.h +++ b/slsDetectorSoftware/include/multiSlsDetector.h @@ -1487,7 +1487,9 @@ class multiSlsDetector : public virtual slsDetectorDefs { * @param detPos -1 for all detectors in list or specific detector position * @returns external sampling source */ - int getExternalSamplingSource(int detPos = -1); + int getExternalSamplingSource(int detPos = -1); // + + /** * Set external sampling enable (CTB only) @@ -1592,6 +1594,8 @@ class multiSlsDetector : public virtual slsDetectorDefs { */ int enableGapPixels(int val = -1, int detPos = -1); // + + void setGapPixelsEnable(bool enable, sls::Positions pos = {}); /** * Sets the number of trim energies and their value (Eiger) * diff --git a/slsDetectorSoftware/src/Detector.cpp b/slsDetectorSoftware/src/Detector.cpp index 1598c9c4c..64e76d565 100644 --- a/slsDetectorSoftware/src/Detector.cpp +++ b/slsDetectorSoftware/src/Detector.cpp @@ -345,9 +345,7 @@ void Detector::startReadOut() { pimpl->Parallel(&slsDetector::startReadOut, {}); } -void Detector::readAll() { - pimpl->Parallel(&slsDetector::readAll, {}); -} +void Detector::readAll() { pimpl->Parallel(&slsDetector::readAll, {}); } void Detector::configureMAC(Positions pos) { pimpl->Parallel(&slsDetector::configureMAC, pos); @@ -565,7 +563,14 @@ Result Detector::getAutoCompDisable(Positions pos) const { } void Detector::setPowerChip(bool on, Positions pos) { - pimpl->Parallel(&slsDetector::powerChip, pos, static_cast(on)); + if (on && pimpl->getNumberOfDetectors() > 3) { + for (int i = 0; i != pimpl->getNumberOfDetectors(); ++i) { + pimpl->powerChip(static_cast(on), i); + usleep(1000 * 1000); + } + } else { + pimpl->Parallel(&slsDetector::powerChip, pos, static_cast(on)); + } } Result Detector::getPowerChip(Positions pos) const { @@ -653,8 +658,7 @@ void Detector::setTrimEn(std::vector energies, Positions pos) { } void Detector::setGapPixelsEnable(bool enable, Positions pos) { - pimpl->Parallel(&slsDetector::enableGapPixels, pos, - static_cast(enable)); + pimpl->setGapPixelsEnable(enable, pos); } Result Detector::getGapPixelEnable(Positions pos) const { @@ -683,47 +687,47 @@ Result Detector::getRxPadDeactivatedMod(Positions pos) const { return pimpl->Parallel(&slsDetector::setDeactivatedRxrPaddingMode, pos, -1); } -void Detector::setActive(bool active, Positions pos){ +void Detector::setActive(bool active, Positions pos) { pimpl->Parallel(&slsDetector::activate, pos, static_cast(active)); } -Result Detector::getActive(Positions pos) const{ +Result Detector::getActive(Positions pos) const { return pimpl->Parallel(&slsDetector::activate, pos, -1); } -void Detector::writeAdcRegister(uint32_t addr, uint32_t value, Positions pos){ +void Detector::writeAdcRegister(uint32_t addr, uint32_t value, Positions pos) { pimpl->Parallel(&slsDetector::writeAdcRegister, pos, addr, value); } -Result Detector::getReceiverDbitOffset(Positions pos) const{ +Result Detector::getReceiverDbitOffset(Positions pos) const { return pimpl->Parallel(&slsDetector::getReceiverDbitOffset, pos); } -void Detector::setReceiverDbitOffset(int value, Positions pos){ +void Detector::setReceiverDbitOffset(int value, Positions pos) { pimpl->Parallel(&slsDetector::setReceiverDbitOffset, pos, value); } -Result> Detector::getReceiverDbitList(Positions pos) const{ +Result> Detector::getReceiverDbitList(Positions pos) const { return pimpl->Parallel(&slsDetector::getReceiverDbitList, pos); } -void Detector::setReceiverDbitList(std::vector list, Positions pos){ +void Detector::setReceiverDbitList(std::vector list, Positions pos) { pimpl->Parallel(&slsDetector::setReceiverDbitList, pos, list); } -Result Detector::getExternalSampling(Positions pos) const{ +Result Detector::getExternalSampling(Positions pos) const { return pimpl->Parallel(&slsDetector::getExternalSampling, pos); } -void Detector::setExternalSampling(bool value, Positions pos){ +void Detector::setExternalSampling(bool value, Positions pos) { pimpl->Parallel(&slsDetector::setExternalSampling, pos, value); } -Result Detector::getExternalSamplingSource(Positions pos) const{ +Result Detector::getExternalSamplingSource(Positions pos) const { return pimpl->Parallel(&slsDetector::getExternalSamplingSource, pos); } - -void Detector::setExternalSamplingSource(int value, Positions pos){ + +void Detector::setExternalSamplingSource(int value, Positions pos) { pimpl->Parallel(&slsDetector::setExternalSamplingSource, pos, value); } diff --git a/slsDetectorSoftware/src/multiSlsDetector.cpp b/slsDetectorSoftware/src/multiSlsDetector.cpp index 14e54848b..9288cc168 100755 --- a/slsDetectorSoftware/src/multiSlsDetector.cpp +++ b/slsDetectorSoftware/src/multiSlsDetector.cpp @@ -2747,6 +2747,16 @@ int multiSlsDetector::enableGapPixels(int val, int detPos) { return ret; } +void multiSlsDetector::setGapPixelsEnable(bool enable, Positions pos){ + Parallel(&slsDetector::enableGapPixels, pos, static_cast(enable)); + + // update data bytes incl gap pixels + auto r2 = serialCall(&slsDetector::getDataBytesInclGapPixels); + multi_shm()->dataBytesInclGapPixels = sls::sum(r2); + updateOffsets(); + +} + int multiSlsDetector::setTrimEn(std::vector energies, int detPos) { if (detPos >= 0) { return detectors[detPos]->setTrimEn(energies); diff --git a/slsDetectorSoftware/tests/test-Result.cpp b/slsDetectorSoftware/tests/test-Result.cpp index 73e3878df..88fb762bc 100644 --- a/slsDetectorSoftware/tests/test-Result.cpp +++ b/slsDetectorSoftware/tests/test-Result.cpp @@ -2,6 +2,7 @@ #include "catch.hpp" #include +#include using sls::Result; @@ -73,3 +74,13 @@ TEST_CASE("equal", "[n2]"){ res.push_back(1.3); REQUIRE(res.equal() == false); } + +TEST_CASE("throws for tsquash", "[n2]"){ + Result res{1,2,3}; + REQUIRE_THROWS(res.tsquash("something is wrong")); +} + +TEST_CASE("", "[n2]"){ + Result res{"hej", "hej", "hej"}; + REQUIRE(res.squash() == "hej"); +} \ No newline at end of file diff --git a/slsSupportLib/include/sls_detector_defs.h b/slsSupportLib/include/sls_detector_defs.h index ec3d5022f..d94ba4401 100755 --- a/slsSupportLib/include/sls_detector_defs.h +++ b/slsSupportLib/include/sls_detector_defs.h @@ -68,6 +68,8 @@ // typedef char mystring[MAX_STR_LENGTH]; + + #ifdef __cplusplus class slsDetectorDefs { public: @@ -1300,3 +1302,13 @@ typedef struct { #else } sls_detector_module; #endif + + +#ifdef __cplusplus +//TODO! discuss this +#include //hmm... but currently no way around +namespace sls{ +using Positions = const std::vector &; +using defs = slsDetectorDefs; +} +#endif \ No newline at end of file