merge resolved

This commit is contained in:
maliakal_d 2019-08-09 11:12:31 +02:00
commit a6e8be2d67
7 changed files with 127 additions and 13 deletions

View File

@ -922,6 +922,33 @@ class Detector {
void setActive(bool active, Positions pos = {}); void setActive(bool active, Positions pos = {});
Result<bool> getActive(Positions pos = {}) const; Result<bool> 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<int> 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<std::vector<int>> getReceiverDbitList(Positions pos = {}) const;
/** [CTB] Which of the bits 0-63 to save*/
void setReceiverDbitList(std::vector<int> list, Positions pos = {});
/** [CTB] */
Result<int> getExternalSampling(Positions pos = {}) const;
/** [CTB] */
void setExternalSampling(bool value, Positions pos = {});
/** [CTB] */
Result<int> getExternalSamplingSource(Positions pos = {}) const;
/** [CTB] Value between 0-63 */
void setExternalSamplingSource(int value, Positions pos = {});
}; };
} // namespace sls } // namespace sls

View File

@ -105,11 +105,19 @@ template <class T, class Allocator = std::allocator<T>> class Result {
*/ */
T squash() const { return Squash(vec); } 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 * If all elements are equal return the front value, otherwise
* return the supplied default value * 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 */ /** Test whether all elements of the result are equal */
bool equal() const noexcept { return allEqual(vec); } bool equal() const noexcept { return allEqual(vec); }

View File

@ -1476,49 +1476,51 @@ class multiSlsDetector : public virtual slsDetectorDefs {
* @param detPos -1 for all detectors in list or specific detector position * @param detPos -1 for all detectors in list or specific detector position
* @returns external sampling source * @returns external sampling source
*/ */
int getExternalSamplingSource(int detPos = -1); int getExternalSamplingSource(int detPos = -1); //
/** /**
* Set external sampling enable (CTB only) * Set external sampling enable (CTB only)
* @param value external sampling source (Option: 0-63) * @param value external sampling source (Option: 0-63)
* @param detPos -1 for all detectors in list or specific detector position * @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) * Get external sampling source (CTB only)
* @param detPos -1 for all detectors in list or specific detector position * @param detPos -1 for all detectors in list or specific detector position
* @returns external sampling enable * @returns external sampling enable
*/ */
int getExternalSampling(int detPos = -1); int getExternalSampling(int detPos = -1); //
/** /**
* Set external sampling enable (CTB only) * Set external sampling enable (CTB only)
* @param list external sampling source (Option: 0-63) * @param list external sampling source (Option: 0-63)
* @param detPos -1 for all detectors in list or specific detector position * @param detPos -1 for all detectors in list or specific detector position
*/ */
void setReceiverDbitList(std::vector<int> list, int detPos = -1); void setReceiverDbitList(std::vector<int> list, int detPos = -1); //
/** /**
* Get external sampling source (CTB only) * Get external sampling source (CTB only)
* @param detPos -1 for all detectors in list or specific detector position * @param detPos -1 for all detectors in list or specific detector position
* @returns external sampling enable * @returns external sampling enable
*/ */
std::vector<int> getReceiverDbitList(int detPos = -1); std::vector<int> getReceiverDbitList(int detPos = -1); //
/** /**
* Set digital data offset in bytes (CTB only) * Set digital data offset in bytes (CTB only)
* @param value digital data offset in bytes * @param value digital data offset in bytes
* @param detPos -1 for all detectors in list or specific detector position * @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) * Get digital data offset in bytes (CTB only)
* @param detPos -1 for all detectors in list or specific detector position * @param detPos -1 for all detectors in list or specific detector position
* @returns digital data offset in bytes * @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 * Write to ADC register (Gotthard, Jungfrau, ChipTestBoard). For expert
@ -1527,7 +1529,7 @@ class multiSlsDetector : public virtual slsDetectorDefs {
* @param val value * @param val value
* @param detPos -1 for all detectors in list or specific detector position * @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) * Activates/Deactivates the detector (Eiger only)
@ -1535,7 +1537,7 @@ class multiSlsDetector : public virtual slsDetectorDefs {
* @param detPos -1 for all detectors in list or specific detector position * @param detPos -1 for all detectors in list or specific detector position
* @returns 0 (inactive) or 1 (active)for activate mode * @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) * Set deactivated Receiver padding mode (Eiger only)
@ -1581,6 +1583,8 @@ class multiSlsDetector : public virtual slsDetectorDefs {
*/ */
int enableGapPixels(int val = -1, int detPos = -1); // 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) * Sets the number of trim energies and their value (Eiger)
* *

View File

@ -631,7 +631,14 @@ Result<bool> Detector::getAutoCompDisable(Positions pos) const {
} }
void Detector::setPowerChip(bool on, Positions pos) { void Detector::setPowerChip(bool on, Positions pos) {
pimpl->Parallel(&slsDetector::powerChip, pos, static_cast<int>(on)); if (on && pimpl->getNumberOfDetectors() > 3) {
for (int i = 0; i != pimpl->getNumberOfDetectors(); ++i) {
pimpl->powerChip(static_cast<int>(on), i);
usleep(1000 * 1000);
}
} else {
pimpl->Parallel(&slsDetector::powerChip, pos, static_cast<int>(on));
}
} }
Result<bool> Detector::getPowerChip(Positions pos) const { Result<bool> Detector::getPowerChip(Positions pos) const {
@ -719,8 +726,7 @@ void Detector::setTrimEn(std::vector<int> energies, Positions pos) {
} }
void Detector::setGapPixelsEnable(bool enable, Positions pos) { void Detector::setGapPixelsEnable(bool enable, Positions pos) {
pimpl->Parallel(&slsDetector::enableGapPixels, pos, pimpl->setGapPixelsEnable(enable, pos);
static_cast<int>(enable));
} }
Result<bool> Detector::getGapPixelEnable(Positions pos) const { Result<bool> Detector::getGapPixelEnable(Positions pos) const {
@ -757,4 +763,40 @@ Result<bool> Detector::getActive(Positions pos) const {
return 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<int> 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<std::vector<int>> Detector::getReceiverDbitList(Positions pos) const {
return pimpl->Parallel(&slsDetector::getReceiverDbitList, pos);
}
void Detector::setReceiverDbitList(std::vector<int> list, Positions pos) {
pimpl->Parallel(&slsDetector::setReceiverDbitList, pos, list);
}
Result<int> 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<int> 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 } // namespace sls

View File

@ -2710,6 +2710,16 @@ int multiSlsDetector::enableGapPixels(int val, int detPos) {
return ret; return ret;
} }
void multiSlsDetector::setGapPixelsEnable(bool enable, Positions pos){
Parallel(&slsDetector::enableGapPixels, pos, static_cast<int>(enable));
// update data bytes incl gap pixels
auto r2 = serialCall(&slsDetector::getDataBytesInclGapPixels);
multi_shm()->dataBytesInclGapPixels = sls::sum(r2);
updateOffsets();
}
int multiSlsDetector::setTrimEn(std::vector<int> energies, int detPos) { int multiSlsDetector::setTrimEn(std::vector<int> energies, int detPos) {
if (detPos >= 0) { if (detPos >= 0) {
return detectors[detPos]->setTrimEn(energies); return detectors[detPos]->setTrimEn(energies);

View File

@ -2,6 +2,7 @@
#include "catch.hpp" #include "catch.hpp"
#include <type_traits> #include <type_traits>
#include <string>
using sls::Result; using sls::Result;
@ -73,3 +74,13 @@ TEST_CASE("equal", "[n2]"){
res.push_back(1.3); res.push_back(1.3);
REQUIRE(res.equal() == false); REQUIRE(res.equal() == false);
} }
TEST_CASE("throws for tsquash", "[n2]"){
Result<int> res{1,2,3};
REQUIRE_THROWS(res.tsquash("something is wrong"));
}
TEST_CASE("", "[n2]"){
Result<std::string> res{"hej", "hej", "hej"};
REQUIRE(res.squash() == "hej");
}

View File

@ -68,6 +68,8 @@
// typedef char mystring[MAX_STR_LENGTH]; // typedef char mystring[MAX_STR_LENGTH];
#ifdef __cplusplus #ifdef __cplusplus
class slsDetectorDefs { class slsDetectorDefs {
public: public:
@ -1297,3 +1299,13 @@ typedef struct {
#else #else
} sls_detector_module; } sls_detector_module;
#endif #endif
#ifdef __cplusplus
//TODO! discuss this
#include <vector> //hmm... but currently no way around
namespace sls{
using Positions = const std::vector<int> &;
using defs = slsDetectorDefs;
}
#endif