Merge branch 'developer' of github.com:slsdetectorgroup/slsDetectorPackage into developer

This commit is contained in:
maliakal_d 2019-04-18 11:16:33 +02:00
commit f3beda6bcf
12 changed files with 185 additions and 53 deletions

View File

@ -17,7 +17,7 @@ e = ExperimentalDetector()
a = read_my302_file('/home/l_frojdh/Downloads/run_d0_5.raw', 104, 24)
# a = read_my302_file('/home/l_frojdh/Downloads/run_d0_5.raw', 104, 24)
# ncols = 192
# start = 600
# end = 1800

View File

@ -1355,6 +1355,38 @@ class Detector:
self._api.configureNetworkParameters()
#TODO! can we make this one function?
@property
def patnloop0(self):
return self._api.getPatternLoops(0, -1)
@patnloop0.setter
def patnloop0(self, n):
self._api.setPatternLoops(0, -1, -1, n, -1)
@property
def patnloop1(self):
return self._api.getPatternLoops(1, -1)
@patnloop1.setter
def patnloop1(self, n):
self._api.setPatternLoops(1, -1, -1, n, -1)
@property
def patnloop2(self):
return self._api.getPatternLoops(2, -1)
@patnloop2.setter
def patnloop2(self, n):
self._api.setPatternLoops(2, -1, -1, n, -1)
def setPatternWord(self, addr, word, det_id = -1):
self._api.setPatternWord(addr, word, det_id)
def setPatternLoops(self, level, start, stop, n, det_id=-1):
self._api.setPatternLoops(level, start, stop, n, det_id)
def free_shared_memory(multi_id=0):
"""
Function to free the shared memory but do not initialize with new

View File

@ -1,12 +1,12 @@
#ifndef DETECTOR_H
#define DETECTOR_H
#include <array>
#include <cstdint>
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>
#include <stdexcept>
#include "error_defs.h"
#include "multiSlsDetector.h"
#include "slsDetector.h"
@ -244,6 +244,21 @@ class Detector {
std::vector<double> getRateCorrection();
void setPatternLoops(uint64_t level, uint64_t start, uint64_t stop,
uint64_t n, int detPos) {
det.setPatternLoops(level, start, stop, n, detPos);
}
std::array<uint64_t, 3> getPatternLoops(uint64_t level, int detPos) {
return det.getPatternLoops(level, detPos);
}
void setPatternWord(int addr, uint64_t word, int detPos){
det.setPatternWord(addr, word, detPos);
}
bool getFlippedDataX(int i) {
return det.getFlippedData(slsDetectorDefs::dimension::X, i);
}

View File

@ -262,6 +262,10 @@ PYBIND11_MODULE(_sls_detector, m)
.def("getTenGigabitEthernet", &Detector::getTenGigabitEthernet)
.def("setTenGigabitEthernet", &Detector::setTenGigabitEthernet)
.def("getPatternLoops", &Detector::getPatternLoops)
.def("setPatternLoops", &Detector::setPatternLoops)
.def("setPatternWord", &Detector::setPatternWord)
.def("getImageSize", &Detector::getImageSize)
.def("setImageSize", &Detector::setImageSize)
.def("getNumberOfDetectors", &Detector::getNumberOfDetectors)
@ -269,6 +273,7 @@ PYBIND11_MODULE(_sls_detector, m)
//Experimental API to use the multi directly and inherit from to reduce
//code duplication need to investigate how to handle documentation
py::class_<multiSlsDetector> multiDetectorApi(m, "multiDetectorApi");
@ -283,6 +288,9 @@ py::class_<multiSlsDetector> multiDetectorApi(m, "multiDetectorApi");
py::cpp_function(&multiSlsDetector::getDetectorNumber))
.def("_getReceiverUDPIP", &multiSlsDetector::getReceiverUDPIP)
.def("_setReceiverUDPIP", &multiSlsDetector::setReceiverUDPIP)
.def("_getPatternLoops", &multiSlsDetector::getPatternLoops)
.def("_setPatternLoops", &multiSlsDetector::setPatternLoops)
.def("_setPatternWord", &multiSlsDetector::setPatternWord)
;
py::module io = m.def_submodule("io", "Submodule for io");

View File

@ -1824,9 +1824,13 @@ class multiSlsDetector : public virtual slsDetectorDefs {
* @param detPos -1 for all detectors in list or specific detector position
* @returns OK/FAIL
*/
int setPatternLoops(int level, int &start, int &stop, int &n,
int setPatternLoops(uint64_t level, uint64_t start, uint64_t stop, uint64_t n,
int detPos = -1);
std::array<uint64_t, 3> getPatternLoops(uint64_t level, int detPos = -1);
/**
* Sets the wait address in the CTB
* @param level 0,1,2, wait level

View File

@ -10,6 +10,7 @@ class ClientInterface;
#include <cmath>
#include <vector>
#include <array>
class multiSlsDetector;
class ServerInterface;
@ -1657,7 +1658,9 @@ class slsDetector : public virtual slsDetectorDefs{
* @param n number of loops (if level >=0)
* @returns OK/FAIL
*/
int setPatternLoops(int level, int &start, int &stop, int &n);
int setPatternLoops(uint64_t level, uint64_t start, uint64_t stop, uint64_t n);
std::array<uint64_t, 3> getPatternLoops(uint64_t level);
/**
* Sets the wait address in the CTB

View File

@ -3602,7 +3602,7 @@ uint64_t multiSlsDetector::setPatternWord(int addr, uint64_t word, int detPos) {
return sls::minusOneIfDifferent(r);
}
int multiSlsDetector::setPatternLoops(int level, int &start, int &stop, int &n, int detPos) {
int multiSlsDetector::setPatternLoops(uint64_t level, uint64_t start, uint64_t stop, uint64_t n, int detPos) {
// single
if (detPos >= 0) {
return detectors[detPos]->setPatternLoops(level, start, stop, n);
@ -3616,6 +3616,14 @@ int multiSlsDetector::setPatternLoops(int level, int &start, int &stop, int &n,
return sls::allEqualTo(r, static_cast<int>(OK)) ? OK : FAIL;
}
std::array<uint64_t, 3> multiSlsDetector::getPatternLoops(uint64_t level, int detPos){
if (detPos >= 0)
return detectors[detPos]->getPatternLoops(level);
auto r = parallelCall(&slsDetector::getPatternLoops, level);
return sls::minusOneIfDifferent(r);
}
int multiSlsDetector::setPatternWaitAddr(int level, int addr, int detPos) {
// single
if (detPos >= 0) {

View File

@ -4498,14 +4498,12 @@ uint64_t slsDetector::setPatternWord(uint64_t addr, uint64_t word) {
return retval;
}
int slsDetector::setPatternLoops(int level, int &start, int &stop, int &n) {
// TODO!(Erik) Should we change function signature to accept uint64_t?
int slsDetector::setPatternLoops(uint64_t level, uint64_t start, uint64_t stop,
uint64_t n) {
int fnum = F_SET_PATTERN;
int ret = FAIL;
uint64_t mode = 1; // sets loop
uint64_t args[5]{mode, static_cast<uint64_t>(level),
static_cast<uint64_t>(start), static_cast<uint64_t>(stop),
static_cast<uint64_t>(n)};
uint64_t args[]{mode, level, start, stop, n};
int retvals[3]{};
FILE_LOG(logDEBUG1) << "Setting Pat Loops, level: " << level
<< ", start: " << start << ", stop: " << stop
@ -4518,9 +4516,9 @@ int slsDetector::setPatternLoops(int level, int &start, int &stop, int &n) {
sizeof(retvals));
FILE_LOG(logDEBUG1) << "Set Pat Loops: " << retvals[0] << ", "
<< retvals[1] << ", " << retvals[2];
start = retvals[0];
stop = retvals[1];
n = retvals[2];
assert(start == retvals[0]);
assert(stop == retvals[1]);
assert(n == retvals[2]);
}
if (ret == FORCE_UPDATE) {
updateDetector();
@ -4528,6 +4526,35 @@ int slsDetector::setPatternLoops(int level, int &start, int &stop, int &n) {
return ret;
}
std::array<uint64_t, 3> slsDetector::getPatternLoops(uint64_t level) {
int fnum = F_SET_PATTERN;
int ret = FAIL;
uint64_t mode = 1; // sets loop
uint64_t args[]{mode, level, static_cast<uint64_t>(-1),
static_cast<uint64_t>(-1), static_cast<uint64_t>(-1)};
int retvals[3]{};
FILE_LOG(logDEBUG1) << "Setting Pat Loops, level: " << level
<< ", start: " << -1 << ", stop: " << -1
<< ", n: " << -1;
if (detector_shm()->onlineFlag == ONLINE_FLAG) {
auto client = DetectorSocket(detector_shm()->hostname,
detector_shm()->controlPort);
ret = client.sendCommandThenRead(fnum, args, sizeof(args), retvals,
sizeof(retvals));
FILE_LOG(logDEBUG1) << "Get Pat Loops: " << retvals[0] << ", "
<< retvals[1] << ", " << retvals[2];
}
if (ret == FORCE_UPDATE) {
updateDetector();
}
std::array<uint64_t, 3> r{};
r[0] = retvals[0];
r[1] = retvals[1];
r[2] = retvals[2];
return r;
}
int slsDetector::setPatternWaitAddr(uint64_t level, uint64_t addr) {
int fnum = F_SET_PATTERN;
int ret = FAIL;

View File

@ -5295,11 +5295,13 @@ std::string slsDetectorCommand::cmdPattern(int narg, char *args[], int action, i
myDet->setPatternLoops(-1, start, stop, n, detPos);
}
start = -1;
stop = -1;
n = -1;
myDet->setPatternLoops(-1, start, stop, n, detPos);
os << std::hex << start << " " << stop; // << " "<< std::dec << n ;
// start = -1;
// stop = -1;
// n = -1;
// myDet->setPatternLoops(-1, start, stop, n, detPos);
auto r = myDet->getPatternLoops(-1, detPos);
os << std::hex << r[0] << " " << r[1];
// os << std::hex << start << " " << stop; // << " "<< std::dec << n ;
} else if (cmd == "patloop0") {
//get start, stop from stdin
@ -5321,11 +5323,13 @@ std::string slsDetectorCommand::cmdPattern(int narg, char *args[], int action, i
myDet->setPatternLoops(0, start, stop, n, detPos);
}
start = -1;
stop = -1;
n = -1;
myDet->setPatternLoops(0, start, stop, n, detPos);
os << std::hex << start << " " << stop; // << " "<< std::dec << n ;
// start = -1;
// stop = -1;
// n = -1;
// myDet->setPatternLoops(0, start, stop, n, detPos);
// os << std::hex << start << " " << stop; // << " "<< std::dec << n ;
auto r = myDet->getPatternLoops(0, detPos);
os << std::hex << r[0] << " " << r[1];
} else if (cmd == "patloop1") {
@ -5347,11 +5351,13 @@ std::string slsDetectorCommand::cmdPattern(int narg, char *args[], int action, i
myDet->setPatternLoops(1, start, stop, n, detPos);
}
start = -1;
stop = -1;
n = -1;
myDet->setPatternLoops(1, start, stop, n, detPos);
os << std::hex << start << " " << stop; // << " "<< std::dec << n ;
// start = -1;
// stop = -1;
// n = -1;
// myDet->setPatternLoops(1, start, stop, n, detPos);
// os << std::hex << start << " " << stop; // << " "<< std::dec << n ;
auto r = myDet->getPatternLoops(1, detPos);
os << std::hex << r[0] << " " << r[1];
} else if (cmd == "patloop2") {
@ -5373,12 +5379,13 @@ std::string slsDetectorCommand::cmdPattern(int narg, char *args[], int action, i
myDet->setPatternLoops(2, start, stop, n, detPos);
}
start = -1;
stop = -1;
n = -1;
myDet->setPatternLoops(2, start, stop, n, detPos);
os << std::hex << start << " " << stop << std::dec; // << " "<< std::dec << n ;
// start = -1;
// stop = -1;
// n = -1;
// myDet->setPatternLoops(2, start, stop, n, detPos);
// os << std::hex << start << " " << stop << std::dec; // << " "<< std::dec << n ;
auto r = myDet->getPatternLoops(2, detPos);
os << std::hex << r[0] << " " << r[1];
} else if (cmd == "patnloop0") {
start = -1;
stop = -1;
@ -5393,11 +5400,13 @@ std::string slsDetectorCommand::cmdPattern(int narg, char *args[], int action, i
myDet->setPatternLoops(0, start, stop, n, detPos);
}
start = -1;
stop = -1;
n = -1;
myDet->setPatternLoops(0, start, stop, n, detPos);
os << n;
// start = -1;
// stop = -1;
// n = -1;
// myDet->setPatternLoops(0, start, stop, n, detPos);
// os << n;
auto r = myDet->getPatternLoops(0, detPos);
os << std::hex << r[2];
} else if (cmd == "patnloop1") {
start = -1;
@ -5413,11 +5422,13 @@ std::string slsDetectorCommand::cmdPattern(int narg, char *args[], int action, i
myDet->setPatternLoops(1, start, stop, n, detPos);
}
start = -1;
stop = -1;
n = -1;
myDet->setPatternLoops(1, start, stop, n, detPos);
os << n;
// start = -1;
// stop = -1;
// n = -1;
// myDet->setPatternLoops(1, start, stop, n, detPos);
// os << n;
auto r = myDet->getPatternLoops(1, detPos);
os << std::hex << r[2];
} else if (cmd == "patnloop2") {
@ -5434,11 +5445,13 @@ std::string slsDetectorCommand::cmdPattern(int narg, char *args[], int action, i
myDet->setPatternLoops(2, start, stop, n, detPos);
}
start = -1;
stop = -1;
n = -1;
myDet->setPatternLoops(2, start, stop, n, detPos);
os << n;
// start = -1;
// stop = -1;
// n = -1;
// myDet->setPatternLoops(2, start, stop, n, detPos);
// os << n;
auto r = myDet->getPatternLoops(2, detPos);
os << std::hex << r[2];
} else if (cmd == "patwait0") {

View File

@ -109,6 +109,19 @@ minusOneIfDifferent(const std::vector<std::vector<T>> &container) {
return std::vector<T>{-1};
}
template <typename T, size_t size>
std::array<T, size>
minusOneIfDifferent(const std::vector<std::array<T,size>> &container) {
if (allEqual(container))
return container.front();
std::array<T,size> arr;
arr.fill(static_cast<T>(-1));
return arr;
}
} // namespace sls
#endif // CONTAINER_UTILS_H

View File

@ -1040,7 +1040,6 @@ typedef struct {
int *chanregs; /**< is the pointer to the array of the channel registers */
#ifdef __cplusplus
sls_detector_module()
: serialnumber(0), nchan(0), nchip(0), ndac(0), reg(0), iodelay(0),
tau(0), eV(0), dacs(nullptr), chanregs(nullptr) {}
@ -1049,8 +1048,6 @@ typedef struct {
detParameters parameters{type};
int nch = parameters.nChanX * parameters.nChanY;
int nc = parameters.nChipX * parameters.nChipY;
// int nd = parameters.nDacs;
ndac = parameters.nDacs;
nchip = nc;
nchan = nch * nc;

View File

@ -122,4 +122,16 @@ TEST_CASE("vector of bool", "[support]"){
CHECK(minusOneIfDifferent(a) == 1);
CHECK(minusOneIfDifferent(b) == 0);
CHECK(minusOneIfDifferent(c) == -1);
}
TEST_CASE("compare a vector of arrays", "[support]"){
std::vector<std::array<uint64_t, 3>> vec0{{5,6,8},{5,6,8},{5,6,8}};
CHECK(minusOneIfDifferent(vec0) == std::array<uint64_t, 3>{5,6,8});
std::array<uint64_t, 3> arr;
arr.fill(-1);
std::vector<std::array<uint64_t, 3>> vec1{{5,90,8},{5,6,8},{5,6,8}};
CHECK(minusOneIfDifferent(vec1) == arr);
}