This commit is contained in:
Erik Frojdh 2019-08-09 11:00:12 +02:00
parent 5292075a0a
commit dfbf7ab39a
6 changed files with 69 additions and 20 deletions

View File

@ -105,11 +105,19 @@ template <class T, class Allocator = std::allocator<T>> 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); }

View File

@ -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)
*

View File

@ -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<bool> Detector::getAutoCompDisable(Positions pos) const {
}
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 {
@ -653,8 +658,7 @@ void Detector::setTrimEn(std::vector<int> energies, Positions pos) {
}
void Detector::setGapPixelsEnable(bool enable, Positions pos) {
pimpl->Parallel(&slsDetector::enableGapPixels, pos,
static_cast<int>(enable));
pimpl->setGapPixelsEnable(enable, pos);
}
Result<bool> Detector::getGapPixelEnable(Positions pos) const {
@ -683,47 +687,47 @@ Result<bool> 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<int>(active));
}
Result<bool> Detector::getActive(Positions pos) const{
Result<bool> 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<int> Detector::getReceiverDbitOffset(Positions pos) const{
Result<int> 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<std::vector<int>> Detector::getReceiverDbitList(Positions pos) const{
Result<std::vector<int>> Detector::getReceiverDbitList(Positions pos) const {
return pimpl->Parallel(&slsDetector::getReceiverDbitList, pos);
}
void Detector::setReceiverDbitList(std::vector<int> list, Positions pos){
void Detector::setReceiverDbitList(std::vector<int> list, Positions pos) {
pimpl->Parallel(&slsDetector::setReceiverDbitList, pos, list);
}
Result<int> Detector::getExternalSampling(Positions pos) const{
Result<int> 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<int> Detector::getExternalSamplingSource(Positions pos) const{
Result<int> 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);
}

View File

@ -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<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) {
if (detPos >= 0) {
return detectors[detPos]->setTrimEn(energies);

View File

@ -2,6 +2,7 @@
#include "catch.hpp"
#include <type_traits>
#include <string>
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<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];
#ifdef __cplusplus
class slsDetectorDefs {
public:
@ -1300,3 +1302,13 @@ typedef struct {
#else
} sls_detector_module;
#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