mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-04-21 19:30:03 +02:00

* Setting pattern from memory (#218) * ToString accepts c-style arrays * fixed patwait time bug in validation * Introduced pattern class * compile for servers too * Python binding for Pattern * added scanParameters in Python * slsReceiver: avoid potential memory leak around Implementation::generalData * additional constructors for scanPrameters in python * bugfix: avoid potentital memory leak in receiver if called outside constructor context * added scanParameters in Python * additional constructors for scanPrameters in python * M3defaultpattern (#227) * default pattern for m3 and moench including Python bindings * M3settings (#228) * some changes to compile on RH7 and in the server to load the default chip status register at startup * Updated mythen3DeectorServer_developer executable with correct initialization at startup Co-authored-by: Erik Frojdh <erik.frojdh@gmail.com> Co-authored-by: Anna Bergamaschi <anna.bergamaschi@psi.ch> * Pattern.h as a public header files (#229) * fixed buffer overflow but caused by using global instead of local enum * replacing out of range trimbits with edge values * replacing dac values that are out of range after interpolation * updated pybind11 to 2.6.2 * Mythen3 improved synchronization (#231) Disabling scans for multi module Mythen3, since there is no feedback of the detectors being ready startDetector first starts the slaves then the master acquire firs calls startDetector for the slaves then acquire on the master getMaster to read back from hardware which one is master * New server for JF to go with the new FW (#232) * Modified Jungfrau speed settings for HW1.0 - FW fix version 1.1.1, compilation date 210218 * Corrected bug. DBIT clk phase is implemented in both HW version 1.0 and 2.0. Previous version did not update the DBIT phase shift on the configuration of a speed. * fix for m3 scan with single module * m3 fw version * m3 server * bugfix for bottom when setting quad * new strategy for finding zmq based on cppzmq Co-authored-by: Dhanya Thattil <dhanya.thattil@psi.ch> Co-authored-by: Dhanya Thattil <33750417+thattil@users.noreply.github.com> Co-authored-by: Alejandro Homs Puron <ahoms@esrf.fr> Co-authored-by: Anna Bergamaschi <anna.bergamaschi@psi.ch> Co-authored-by: Xiaoqiang Wang <xiaoqiangwang@gmail.com> Co-authored-by: lopez_c <carlos.lopez-cuenca@psi.ch>
199 lines
6.3 KiB
C++
199 lines
6.3 KiB
C++
#pragma once
|
|
#include "sls/ToString.h"
|
|
#include "sls/TypeTraits.h"
|
|
#include <array>
|
|
#include <cassert>
|
|
#include <iostream>
|
|
#include <stdexcept>
|
|
#include <vector>
|
|
|
|
namespace sls {
|
|
template <typename T, size_t Capacity> class StaticVector {
|
|
|
|
public:
|
|
using size_type = typename std::array<T, Capacity>::size_type;
|
|
using value_type = typename std::array<T, Capacity>::value_type;
|
|
using iterator = typename std::array<T, Capacity>::iterator;
|
|
using const_iterator = typename std::array<T, Capacity>::const_iterator;
|
|
|
|
private:
|
|
size_type current_size{};
|
|
std::array<T, Capacity> data_;
|
|
|
|
public:
|
|
StaticVector() = default;
|
|
|
|
explicit StaticVector(std::initializer_list<T> l) : current_size(l.size()) {
|
|
size_check(l.size());
|
|
std::copy(l.begin(), l.end(), data_.begin());
|
|
}
|
|
|
|
/** Copy construct from another container */
|
|
template <typename V,
|
|
typename = typename std::enable_if<
|
|
is_container<V>::value &&
|
|
std::is_same<T, typename V::value_type>::value>::type>
|
|
StaticVector(const V &v) : current_size(v.size()) {
|
|
size_check(v.size());
|
|
std::copy(v.begin(), v.end(), data_.begin());
|
|
}
|
|
|
|
/** copy assignment from another container */
|
|
template <typename V>
|
|
typename std::enable_if<is_container<V>::value, StaticVector &>::type
|
|
operator=(const V &other) {
|
|
size_check(other.size());
|
|
std::copy(other.begin(), other.end(), data_.begin());
|
|
current_size = other.size();
|
|
return *this;
|
|
}
|
|
|
|
operator std::vector<T>() { return std::vector<T>(begin(), end()); }
|
|
|
|
T &operator[](size_t i) { return data_[i]; }
|
|
const T &operator[](size_t i) const { return data_[i]; }
|
|
constexpr size_type size() const noexcept { return current_size; }
|
|
bool empty() const noexcept { return current_size == 0; }
|
|
constexpr size_t capacity() const noexcept { return Capacity; }
|
|
|
|
void push_back(const T &value) {
|
|
if (current_size == Capacity) {
|
|
throw std::runtime_error("Container is full");
|
|
} else {
|
|
data_[current_size] = value;
|
|
++current_size;
|
|
}
|
|
}
|
|
|
|
void resize(size_t new_size) {
|
|
if (new_size > Capacity) {
|
|
throw std::runtime_error("Cannot resize beyond capacity");
|
|
} else {
|
|
current_size = new_size;
|
|
}
|
|
}
|
|
|
|
void erase(T *ptr) {
|
|
if (ptr >= begin() && ptr < end()) {
|
|
current_size = static_cast<size_t>(ptr - begin());
|
|
} else {
|
|
throw std::runtime_error("tried to erase with a ptr outside obj");
|
|
}
|
|
}
|
|
|
|
template <typename Container>
|
|
bool is_equal(const Container &c) const noexcept {
|
|
if (current_size != c.size()) {
|
|
return false;
|
|
} else {
|
|
for (size_t i = 0; i != current_size; ++i) {
|
|
if (data_[i] != c[i]) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
T &front() noexcept { return data_.front(); }
|
|
T &back() noexcept { return data_[current_size - 1]; }
|
|
constexpr const T &front() const noexcept { return data_.front(); }
|
|
constexpr const T &back() const noexcept { return data_[current_size - 1]; }
|
|
|
|
bool anyEqualTo(const T value) {
|
|
return std::any_of(
|
|
data_.cbegin(), data_.cend(),
|
|
[value](const T &element) { return element == value; });
|
|
}
|
|
|
|
// iterators
|
|
iterator begin() noexcept { return data_.begin(); }
|
|
// auto begin() noexcept -> decltype(data_.begin()) { return data_.begin();
|
|
// }
|
|
const_iterator begin() const noexcept { return data_.begin(); }
|
|
iterator end() noexcept { return &data_[current_size]; }
|
|
const_iterator end() const noexcept { return &data_[current_size]; }
|
|
const_iterator cbegin() const noexcept { return data_.cbegin(); }
|
|
const_iterator cend() const noexcept { return &data_[current_size]; }
|
|
|
|
void size_check(size_type s) const {
|
|
if (s > Capacity) {
|
|
throw std::runtime_error(
|
|
"Capacity needs to be same size or larger than vector");
|
|
}
|
|
}
|
|
|
|
} __attribute__((packed));
|
|
|
|
template <typename T, size_t CapacityLhs, typename V, size_t CapacityRhs>
|
|
bool operator==(const StaticVector<T, CapacityLhs> &lhs,
|
|
const StaticVector<V, CapacityRhs> &rhs) {
|
|
return lhs.is_equal(rhs);
|
|
}
|
|
|
|
template <typename T, size_t CapacityLhs, typename V, size_t CapacityRhs>
|
|
bool operator!=(const StaticVector<T, CapacityLhs> &lhs,
|
|
const StaticVector<V, CapacityRhs> &rhs) {
|
|
return !(lhs.is_equal(rhs));
|
|
}
|
|
|
|
// Compare with array
|
|
|
|
template <typename T, size_t CapacityLhs, typename V, size_t Size>
|
|
bool operator==(const StaticVector<T, CapacityLhs> &lhs,
|
|
const std::array<V, Size> &rhs) {
|
|
return lhs.is_equal(rhs);
|
|
}
|
|
|
|
template <typename T, size_t Size, typename V, size_t CapacityRhs>
|
|
bool operator==(const std::array<T, Size> &lhs,
|
|
const StaticVector<V, CapacityRhs> &rhs) {
|
|
return rhs.is_equal(lhs);
|
|
}
|
|
|
|
template <typename T, size_t CapacityLhs, typename V, size_t Size>
|
|
bool operator!=(const StaticVector<T, CapacityLhs> &lhs,
|
|
const std::array<V, Size> &rhs) {
|
|
return !lhs.is_equal(rhs);
|
|
}
|
|
|
|
template <typename T, size_t Size, typename V, size_t CapacityRhs>
|
|
bool operator!=(const std::array<T, Size> &lhs,
|
|
const StaticVector<V, CapacityRhs> &rhs) {
|
|
return !rhs.is_equal(lhs);
|
|
}
|
|
|
|
// Compare with vector
|
|
|
|
template <typename T, size_t CapacityLhs, typename V>
|
|
bool operator==(const StaticVector<T, CapacityLhs> &lhs,
|
|
const std::vector<V> &rhs) {
|
|
return lhs.is_equal(rhs);
|
|
}
|
|
|
|
template <typename T, typename V, size_t CapacityRhs>
|
|
bool operator==(const std::vector<T> &lhs,
|
|
const StaticVector<V, CapacityRhs> &rhs) {
|
|
return rhs.is_equal(lhs);
|
|
}
|
|
|
|
template <typename T, size_t CapacityLhs, typename V>
|
|
bool operator!=(const StaticVector<T, CapacityLhs> &lhs,
|
|
const std::vector<V> &rhs) {
|
|
return !lhs.is_equal(rhs);
|
|
}
|
|
|
|
template <typename T, typename V, size_t CapacityRhs>
|
|
bool operator!=(const std::vector<T> &lhs,
|
|
const StaticVector<V, CapacityRhs> &rhs) {
|
|
return !rhs.is_equal(lhs);
|
|
}
|
|
|
|
template <typename T, size_t Capacity>
|
|
std::ostream &operator<<(std::ostream &os,
|
|
const sls::StaticVector<T, Capacity> &c) {
|
|
return os << ToString(c);
|
|
}
|
|
|
|
} // namespace sls
|