mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-19 18:40:01 +02:00
WIP
This commit is contained in:
parent
4ceee97c03
commit
65ebd0baf0
@ -1,6 +1,7 @@
|
||||
#include <iostream>
|
||||
#include "Result.h"
|
||||
#include "ToString.h"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
auto main() -> int {
|
||||
|
||||
@ -31,25 +32,19 @@ auto main() -> int {
|
||||
std::cout << "vec2: " << ToString(vec2) << "\n";
|
||||
|
||||
|
||||
// WARNING this feature is still not decied, its convenient
|
||||
// but might turn out to be a source of bugs...
|
||||
// it is also possible to convert from Result<T> to T
|
||||
int r = res3;
|
||||
std::cout << "r: " << r << '\n';
|
||||
std::cout << "static_cast<int>: " << static_cast<int>(res3) << '\n';
|
||||
std::cout << "static_cast<double>: " << static_cast<double>(res3) << '\n';
|
||||
|
||||
int r2 = res;
|
||||
std::cout << "res: " << res << " converted to int: " << r2 << "\n";
|
||||
|
||||
//Using squash we can also convert to a single value
|
||||
// Using squash we can also convert to a single value
|
||||
std::cout << "res.squash(): " << res.squash() << '\n';
|
||||
std::cout << "res3.squash(): " << res3.squash() << '\n';
|
||||
|
||||
|
||||
//.squash also takes a default value
|
||||
std::cout << "res.squash(-1): " << res.squash(-1) << '\n';
|
||||
std::cout << "res3.squash(-1): " << res3.squash(-1) << '\n';
|
||||
|
||||
std::vector<int> ivec{1, 3, 5};
|
||||
|
||||
Result<sls::time::ns> nres(ivec);
|
||||
// for (const auto& i : ivec)
|
||||
// nres.push_back(sls::time::ns(i));
|
||||
std::cout << "nres: " << sls::ToString(nres) << '\n';
|
||||
//
|
||||
}
|
@ -13,6 +13,7 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "TimeHelper.h"
|
||||
#include "ToString.h"
|
||||
#include "container_utils.h"
|
||||
|
||||
@ -30,6 +31,34 @@ template <class T, class Allocator = std::allocator<T>> class Result {
|
||||
Result() = default;
|
||||
Result(std::initializer_list<T> list) : vec(list){};
|
||||
|
||||
template <typename V, typename = typename std::enable_if<
|
||||
std::is_integral<V>::value &&
|
||||
std::is_same<T, time::ns>::value>::type>
|
||||
Result(const std::vector<V> &from) {
|
||||
|
||||
vec.reserve(from.size());
|
||||
for (const auto &item : from)
|
||||
vec.push_back(T(item));
|
||||
}
|
||||
|
||||
template <typename V, typename = typename std::enable_if<
|
||||
std::is_integral<V>::value &&
|
||||
std::is_same<T, time::ns>::value>::type>
|
||||
Result(std::vector<V> &from) {
|
||||
vec.reserve(from.size());
|
||||
for (const auto &item : from)
|
||||
vec.push_back(T(item));
|
||||
}
|
||||
|
||||
template <typename V, typename = typename std::enable_if<
|
||||
std::is_integral<V>::value &&
|
||||
std::is_same<T, time::ns>::value>::type>
|
||||
Result(std::vector<V> &&from) {
|
||||
vec.reserve(from.size());
|
||||
for (const auto &item : from)
|
||||
vec.push_back(T(item));
|
||||
}
|
||||
|
||||
/**
|
||||
* Forward arguments to the constructor of std::vector
|
||||
* @tparam Args template paramter pack to forward
|
||||
@ -82,9 +111,6 @@ template <class T, class Allocator = std::allocator<T>> class Result {
|
||||
|
||||
/** Convert Result<T> to std::vector<T> */
|
||||
operator std::vector<T>() { return vec; }
|
||||
|
||||
/** Convert Result<T> to T using squash() */
|
||||
operator T() { return squash(); }
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -11,7 +11,6 @@ Detector::Detector(int multi_id)
|
||||
: pimpl(sls::make_unique<multiSlsDetector>(multi_id)) {}
|
||||
Detector::~Detector() = default;
|
||||
|
||||
|
||||
// Acquisition
|
||||
void Detector::acquire() { pimpl->acquire(); }
|
||||
|
||||
@ -26,13 +25,9 @@ Result<defs::runStatus> Detector::getReceiverStatus(Positions pos) {
|
||||
return pimpl->Parallel(&slsDetector::getReceiverStatus, pos);
|
||||
}
|
||||
|
||||
bool Detector::getAcquiringFlag() const{
|
||||
return pimpl->getAcquiringFlag();
|
||||
}
|
||||
bool Detector::getAcquiringFlag() const { return pimpl->getAcquiringFlag(); }
|
||||
|
||||
void Detector::setAcquiringFlag(bool value){
|
||||
pimpl->setAcquiringFlag(value);
|
||||
}
|
||||
void Detector::setAcquiringFlag(bool value) { pimpl->setAcquiringFlag(value); }
|
||||
|
||||
// Configuration
|
||||
Result<std::string> Detector::getHostname(Positions pos) const {
|
||||
@ -41,7 +36,6 @@ Result<std::string> Detector::getHostname(Positions pos) const {
|
||||
|
||||
void Detector::freeSharedMemory() { pimpl->freeSharedMemory(); }
|
||||
|
||||
|
||||
void Detector::setConfig(const std::string &fname) {
|
||||
pimpl->readConfigurationFile(fname);
|
||||
}
|
||||
@ -57,9 +51,8 @@ Result<uint32_t> Detector::getRegister(uint32_t addr, Positions pos) {
|
||||
}
|
||||
|
||||
Result<ns> Detector::getExptime(Positions pos) const {
|
||||
auto r = pimpl->Parallel(&slsDetector::setTimer, pos,
|
||||
defs::ACQUISITION_TIME, -1);
|
||||
return Result<ns>(begin(r), end(r));
|
||||
return pimpl->Parallel(&slsDetector::setTimer, pos, defs::ACQUISITION_TIME,
|
||||
-1);
|
||||
}
|
||||
|
||||
Result<uint64_t> Detector::getStartingFrameNumber(Positions pos) const {
|
||||
@ -75,9 +68,8 @@ void Detector::setExptime(ns t, Positions pos) {
|
||||
}
|
||||
|
||||
Result<ns> Detector::getSubExptime(Positions pos) const {
|
||||
auto r = pimpl->Parallel(&slsDetector::setTimer, pos,
|
||||
defs::SUBFRAME_ACQUISITION_TIME, -1);
|
||||
return Result<ns>(begin(r), end(r));
|
||||
return pimpl->Parallel(&slsDetector::setTimer, pos,
|
||||
defs::SUBFRAME_ACQUISITION_TIME, -1);
|
||||
}
|
||||
|
||||
void Detector::setSubExptime(ns t, Positions pos) {
|
||||
@ -86,9 +78,7 @@ void Detector::setSubExptime(ns t, Positions pos) {
|
||||
}
|
||||
|
||||
Result<ns> Detector::getPeriod(Positions pos) const {
|
||||
auto r =
|
||||
pimpl->Parallel(&slsDetector::setTimer, pos, defs::FRAME_PERIOD, -1);
|
||||
return Result<ns>(begin(r), end(r));
|
||||
return pimpl->Parallel(&slsDetector::setTimer, pos, defs::FRAME_PERIOD, -1);
|
||||
}
|
||||
|
||||
void Detector::setPeriod(ns t, Positions pos) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user