mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-20 02:40:03 +02:00
Parallel returns Result
This commit is contained in:
parent
dfbf7ab39a
commit
fc78bb9384
@ -40,7 +40,7 @@ auto main() -> int {
|
|||||||
std::cout << "res.squash(-1): " << res.squash(-1) << '\n';
|
std::cout << "res.squash(-1): " << res.squash(-1) << '\n';
|
||||||
std::cout << "res3.squash(-1): " << res3.squash(-1) << '\n';
|
std::cout << "res3.squash(-1): " << res3.squash(-1) << '\n';
|
||||||
|
|
||||||
std::vector<int> ivec{1, 3, 5};
|
Result<int> ivec{1, 3, 5};
|
||||||
|
|
||||||
Result<sls::time::ns> nres(ivec);
|
Result<sls::time::ns> nres(ivec);
|
||||||
// for (const auto& i : ivec)
|
// for (const auto& i : ivec)
|
||||||
|
@ -841,6 +841,21 @@ class Detector {
|
|||||||
|
|
||||||
/** [CTB] Value between 0-63 */
|
/** [CTB] Value between 0-63 */
|
||||||
void setExternalSamplingSource(int value, Positions pos = {});
|
void setExternalSamplingSource(int value, Positions pos = {});
|
||||||
|
|
||||||
|
/** [CTB] */
|
||||||
|
uint32_t getADCInvert() const;
|
||||||
|
|
||||||
|
/** [CTB]*/
|
||||||
|
void setADCInvert(uint32_t value);
|
||||||
|
|
||||||
|
/** [CTB]*/
|
||||||
|
uint32_t getADCEnableMask(int detPos = -1);
|
||||||
|
|
||||||
|
/** [CTB]*/
|
||||||
|
void setADCEnableMask(uint32_t mask);
|
||||||
|
|
||||||
|
/** [CTB]*/
|
||||||
|
uint32_t getADCEnableMask() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sls
|
} // namespace sls
|
@ -31,12 +31,13 @@ template <class T, class Allocator = std::allocator<T>> class Result {
|
|||||||
Result() = default;
|
Result() = default;
|
||||||
Result(std::initializer_list<T> list) : vec(list){};
|
Result(std::initializer_list<T> list) : vec(list){};
|
||||||
|
|
||||||
|
|
||||||
/** Custom constructor from integer type to Result<ns> or Result<bool> */
|
/** Custom constructor from integer type to Result<ns> or Result<bool> */
|
||||||
template <typename V, typename = typename std::enable_if<
|
template <typename V, typename = typename std::enable_if<
|
||||||
std::is_integral<V>::value &&
|
std::is_integral<V>::value &&
|
||||||
(std::is_same<T, time::ns>::value ||
|
(std::is_same<T, time::ns>::value ||
|
||||||
std::is_same<T, bool>::value)>::type>
|
std::is_same<T, bool>::value)>::type>
|
||||||
Result(const std::vector<V> &from) {
|
Result(const Result<V> &from) {
|
||||||
vec.reserve(from.size());
|
vec.reserve(from.size());
|
||||||
for (const auto &item : from)
|
for (const auto &item : from)
|
||||||
vec.push_back(T(item));
|
vec.push_back(T(item));
|
||||||
@ -47,7 +48,7 @@ template <class T, class Allocator = std::allocator<T>> class Result {
|
|||||||
std::is_integral<V>::value &&
|
std::is_integral<V>::value &&
|
||||||
(std::is_same<T, time::ns>::value ||
|
(std::is_same<T, time::ns>::value ||
|
||||||
std::is_same<T, bool>::value)>::type>
|
std::is_same<T, bool>::value)>::type>
|
||||||
Result(std::vector<V> &from) {
|
Result(Result<V> &from) {
|
||||||
vec.reserve(from.size());
|
vec.reserve(from.size());
|
||||||
for (const auto &item : from)
|
for (const auto &item : from)
|
||||||
vec.push_back(T(item));
|
vec.push_back(T(item));
|
||||||
@ -58,7 +59,7 @@ template <class T, class Allocator = std::allocator<T>> class Result {
|
|||||||
std::is_integral<V>::value &&
|
std::is_integral<V>::value &&
|
||||||
(std::is_same<T, time::ns>::value ||
|
(std::is_same<T, time::ns>::value ||
|
||||||
std::is_same<T, bool>::value)>::type>
|
std::is_same<T, bool>::value)>::type>
|
||||||
Result(std::vector<V> &&from) {
|
Result(Result<V> &&from) {
|
||||||
vec.reserve(from.size());
|
vec.reserve(from.size());
|
||||||
for (const auto &item : from)
|
for (const auto &item : from)
|
||||||
vec.push_back(T(item));
|
vec.push_back(T(item));
|
||||||
@ -90,6 +91,7 @@ template <class T, class Allocator = std::allocator<T>> class Result {
|
|||||||
auto empty() const noexcept -> decltype(vec.empty()) { return vec.empty(); }
|
auto empty() const noexcept -> decltype(vec.empty()) { return vec.empty(); }
|
||||||
auto front() -> decltype(vec.front()) { return vec.front(); }
|
auto front() -> decltype(vec.front()) { return vec.front(); }
|
||||||
auto front() const -> decltype(vec.front()) { return vec.front(); }
|
auto front() const -> decltype(vec.front()) { return vec.front(); }
|
||||||
|
void reserve(size_type new_cap) { vec.reserve(new_cap); }
|
||||||
|
|
||||||
template <typename V>
|
template <typename V>
|
||||||
auto push_back(V value) -> decltype(vec.push_back(value)) {
|
auto push_back(V value) -> decltype(vec.push_back(value)) {
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "SharedMemory.h"
|
#include "SharedMemory.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "sls_detector_defs.h"
|
#include "sls_detector_defs.h"
|
||||||
|
#include "Result.h"
|
||||||
|
|
||||||
class slsDetector;
|
class slsDetector;
|
||||||
class ZmqSocket;
|
class ZmqSocket;
|
||||||
@ -113,7 +114,7 @@ class multiSlsDetector : public virtual slsDetectorDefs {
|
|||||||
|
|
||||||
template <class CT> struct NonDeduced { using type = CT; };
|
template <class CT> struct NonDeduced { using type = CT; };
|
||||||
template <typename RT, typename... CT>
|
template <typename RT, typename... CT>
|
||||||
std::vector<RT> Parallel(RT (slsDetector::*somefunc)(CT...),
|
sls::Result<RT> Parallel(RT (slsDetector::*somefunc)(CT...),
|
||||||
std::vector<int> positions,
|
std::vector<int> positions,
|
||||||
typename NonDeduced<CT>::type... Args) {
|
typename NonDeduced<CT>::type... Args) {
|
||||||
|
|
||||||
@ -130,7 +131,7 @@ class multiSlsDetector : public virtual slsDetectorDefs {
|
|||||||
futures.push_back(std::async(std::launch::async, somefunc,
|
futures.push_back(std::async(std::launch::async, somefunc,
|
||||||
detectors[i].get(), Args...));
|
detectors[i].get(), Args...));
|
||||||
}
|
}
|
||||||
std::vector<RT> result;
|
sls::Result<RT> result;
|
||||||
result.reserve(positions.size());
|
result.reserve(positions.size());
|
||||||
for (auto &i : futures) {
|
for (auto &i : futures) {
|
||||||
result.push_back(i.get());
|
result.push_back(i.get());
|
||||||
@ -139,7 +140,7 @@ class multiSlsDetector : public virtual slsDetectorDefs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename RT, typename... CT>
|
template <typename RT, typename... CT>
|
||||||
std::vector<RT> Parallel(RT (slsDetector::*somefunc)(CT...) const,
|
sls::Result<RT> Parallel(RT (slsDetector::*somefunc)(CT...) const,
|
||||||
std::vector<int> positions,
|
std::vector<int> positions,
|
||||||
typename NonDeduced<CT>::type... Args) const {
|
typename NonDeduced<CT>::type... Args) const {
|
||||||
|
|
||||||
@ -156,7 +157,7 @@ class multiSlsDetector : public virtual slsDetectorDefs {
|
|||||||
futures.push_back(std::async(std::launch::async, somefunc,
|
futures.push_back(std::async(std::launch::async, somefunc,
|
||||||
detectors[i].get(), Args...));
|
detectors[i].get(), Args...));
|
||||||
}
|
}
|
||||||
std::vector<RT> result;
|
sls::Result<RT> result;
|
||||||
result.reserve(positions.size());
|
result.reserve(positions.size());
|
||||||
for (auto &i : futures) {
|
for (auto &i : futures) {
|
||||||
result.push_back(i.get());
|
result.push_back(i.get());
|
||||||
@ -1452,35 +1453,35 @@ class multiSlsDetector : public virtual slsDetectorDefs {
|
|||||||
* @param mask ADC Enable mask
|
* @param mask ADC Enable mask
|
||||||
* @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 setADCEnableMask(uint32_t mask, int detPos = -1);
|
void setADCEnableMask(uint32_t mask, int detPos = -1); //
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get ADC Enable Mask (CTB, Moench)
|
* Get ADC Enable Mask (CTB, Moench)
|
||||||
* @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 ADC Enable mask
|
* @returns ADC Enable mask
|
||||||
*/
|
*/
|
||||||
uint32_t getADCEnableMask(int detPos = -1);
|
uint32_t getADCEnableMask(int detPos = -1); //
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set ADC invert register (CTB, Moench)
|
* Set ADC invert register (CTB, Moench)
|
||||||
* @param value ADC invert value
|
* @param value ADC invert 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 setADCInvert(uint32_t value, int detPos = -1);
|
void setADCInvert(uint32_t value, int detPos = -1); //
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get ADC invert register (CTB, Moench)
|
* Get ADC invert register (CTB, Moench)
|
||||||
* @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 ADC invert value
|
* @returns ADC invert value
|
||||||
*/
|
*/
|
||||||
uint32_t getADCInvert(int detPos = -1);
|
uint32_t getADCInvert(int detPos = -1); //
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set external sampling source (CTB only)
|
* Set external sampling source (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 setExternalSamplingSource(int value, int detPos = -1);
|
void setExternalSamplingSource(int value, int detPos = -1); //
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get external sampling source (CTB only)
|
* Get external sampling source (CTB only)
|
||||||
|
@ -731,4 +731,22 @@ void Detector::setExternalSamplingSource(int value, Positions pos) {
|
|||||||
pimpl->Parallel(&slsDetector::setExternalSamplingSource, pos, value);
|
pimpl->Parallel(&slsDetector::setExternalSamplingSource, pos, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t Detector::getADCInvert() const {
|
||||||
|
auto res = pimpl->Parallel(&slsDetector::getADCInvert, {});
|
||||||
|
return res.tsquash("Different Values for function getADCInvert");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Detector::setADCInvert(uint32_t value) {
|
||||||
|
pimpl->Parallel(&slsDetector::setADCInvert, {}, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t Detector::getADCEnableMask() const {
|
||||||
|
return pimpl->Parallel(&slsDetector::getADCEnableMask, {})
|
||||||
|
.tsquash("Values of ADC enable mask cannot be different");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Detector::setADCEnableMask(uint32_t mask) {
|
||||||
|
pimpl->Parallel(&slsDetector::setADCEnableMask, {}, mask);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace sls
|
} // namespace sls
|
Loading…
x
Reference in New Issue
Block a user