mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-05-14 00:12:11 +02:00
Merge branch 'developer' into apidhanya
This commit is contained in:
commit
e246a33269
@ -2,43 +2,44 @@
|
||||
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include "TimeHelper.h"
|
||||
#include "ToString.h"
|
||||
// std::ostream &operator<<(std::ostream &os, const std::chrono::nanoseconds &t) {
|
||||
// os << t.count() << "ns";
|
||||
// return os;
|
||||
// }
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, const std::chrono::nanoseconds &t) {
|
||||
os << t.count() << "ns";
|
||||
return os;
|
||||
}
|
||||
// template <typename T, typename _ = void>
|
||||
// struct is_container : std::false_type {};
|
||||
|
||||
template <typename T, typename _ = void>
|
||||
struct is_container : std::false_type {};
|
||||
// template <typename... Ts> struct is_container_helper {};
|
||||
|
||||
template <typename... Ts> struct is_container_helper {};
|
||||
// template <typename T>
|
||||
// struct is_container<
|
||||
// T, typename std::conditional<
|
||||
// false,
|
||||
// is_container_helper<typename T::value_type, typename T::size_type,
|
||||
// typename T::iterator, typename T::const_iterator,
|
||||
// decltype(std::declval<T>().size()),
|
||||
// decltype(std::declval<T>().begin()),
|
||||
// decltype(std::declval<T>().end()),
|
||||
// decltype(std::declval<T>().cbegin()),
|
||||
// decltype(std::declval<T>().cend()),
|
||||
// decltype(std::declval<T>().empty())>,
|
||||
// void>::type> : public std::true_type {};
|
||||
|
||||
template <typename T>
|
||||
struct is_container<
|
||||
T, typename std::conditional<
|
||||
false,
|
||||
is_container_helper<typename T::value_type, typename T::size_type,
|
||||
typename T::iterator, typename T::const_iterator,
|
||||
decltype(std::declval<T>().size()),
|
||||
decltype(std::declval<T>().begin()),
|
||||
decltype(std::declval<T>().end()),
|
||||
decltype(std::declval<T>().cbegin()),
|
||||
decltype(std::declval<T>().cend()),
|
||||
decltype(std::declval<T>().empty())>,
|
||||
void>::type> : public std::true_type {};
|
||||
|
||||
template <typename Container>
|
||||
auto operator<<(std::ostream &os, const Container &con) ->
|
||||
typename std::enable_if<is_container<Container>::value,
|
||||
std::ostream &>::type {
|
||||
if (con.empty())
|
||||
return os << "[]";
|
||||
auto it = con.cbegin();
|
||||
os << '[' << *it++;
|
||||
while (it != con.cend())
|
||||
os << ", " << *it++;
|
||||
return os << ']';
|
||||
}
|
||||
// template <typename Container>
|
||||
// auto operator<<(std::ostream &os, const Container &con) ->
|
||||
// typename std::enable_if<is_container<Container>::value,
|
||||
// std::ostream &>::type {
|
||||
// if (con.empty())
|
||||
// return os << "[]";
|
||||
// auto it = con.cbegin();
|
||||
// os << '[' << *it++;
|
||||
// while (it != con.cend())
|
||||
// os << ", " << *it++;
|
||||
// return os << ']';
|
||||
// }
|
||||
|
||||
using sls::Detector;
|
||||
using std::chrono::nanoseconds;
|
||||
@ -57,7 +58,7 @@ int main() {
|
||||
// std::cout << "exptime: " <<t1 << '\n';
|
||||
|
||||
std::cout << "Period: " << d.getPeriod() << '\n';
|
||||
std::cout << "Period: " << d.getPeriod().squash() << '\n';
|
||||
std::cout << "Period: " << sls::ToString(d.getPeriod().squash()) << '\n';
|
||||
// std::cout << "fname: " << d.getFname() << "\n";
|
||||
|
||||
// std::cout << "fwrite: " << std::boolalpha << d.getFwrite() << '\n';
|
||||
|
@ -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,38 @@ template <class T, class Allocator = std::allocator<T>> class Result {
|
||||
Result() = default;
|
||||
Result(std::initializer_list<T> list) : vec(list){};
|
||||
|
||||
|
||||
/** Custom constructor from integer type to Result<ns> */
|
||||
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));
|
||||
}
|
||||
|
||||
/** Custom constructor from integer type to Result<ns> */
|
||||
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));
|
||||
}
|
||||
|
||||
/** Custom constructor from integer type to Result<ns> */
|
||||
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 +115,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(); }
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -51,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 {
|
||||
@ -69,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) {
|
||||
@ -80,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