diff --git a/slsDetectorSoftware/src/Module.cpp b/slsDetectorSoftware/src/Module.cpp index a2ae089a7..618361c07 100644 --- a/slsDetectorSoftware/src/Module.cpp +++ b/slsDetectorSoftware/src/Module.cpp @@ -2164,12 +2164,12 @@ void Module::setReceiverDbitList(const std::vector &list) { "Dbit list value must be between 0 and 63\n"); } } - sls::FixedCapacityContainer arg = list; + sls::StaticVector arg = list; sendToReceiver(F_SET_RECEIVER_DBIT_LIST, arg, nullptr); } std::vector Module::getReceiverDbitList() const { - return sendToReceiver>( + return sendToReceiver>( F_GET_RECEIVER_DBIT_LIST); } diff --git a/slsDetectorSoftware/src/Module.h b/slsDetectorSoftware/src/Module.h index c25d56976..b8cccfd93 100644 --- a/slsDetectorSoftware/src/Module.h +++ b/slsDetectorSoftware/src/Module.h @@ -1,7 +1,7 @@ #pragma once #include "ClientSocket.h" -#include "FixedCapacityContainer.h" #include "SharedMemory.h" +#include "StaticVector.h" #include "logger.h" #include "network_utils.h" #include "sls_detector_defs.h" @@ -51,7 +51,7 @@ struct sharedSlsDetector { char settingsDir[MAX_STR_LENGTH]; /** list of the energies at which the detector has been trimmed */ - sls::FixedCapacityContainer trimEnergies; + sls::StaticVector trimEnergies; /** number of channels per chip in one direction */ slsDetectorDefs::xy nChan; diff --git a/slsReceiverSoftware/src/ClientInterface.cpp b/slsReceiverSoftware/src/ClientInterface.cpp index bb62d21a2..c717d7143 100644 --- a/slsReceiverSoftware/src/ClientInterface.cpp +++ b/slsReceiverSoftware/src/ClientInterface.cpp @@ -1,6 +1,6 @@ #include "ClientInterface.h" -#include "FixedCapacityContainer.h" #include "ServerSocket.h" +#include "StaticVector.h" #include "ToString.h" #include "sls_detector_exceptions.h" #include "string_utils.h" @@ -335,39 +335,39 @@ int ClientInterface::get_version(Interface &socket) { int ClientInterface::setup_receiver(Interface &socket) { auto arg = socket.Receive(); LOG(logDEBUG) << "detType:" << arg.detType << std::endl - << "multiSize.x:" << arg.multiSize.x << std::endl - << "multiSize.y:" << arg.multiSize.y << std::endl - << "detId:" << arg.detId << std::endl - << "hostname:" << arg.hostname << std::endl - << "udpInterfaces:" << arg.udpInterfaces << std::endl - << "udp_dstport:" << arg.udp_dstport << std::endl - << "udp_dstip:" << sls::IpAddr(arg.udp_dstip) << std::endl - << "udp_dstmac:" << sls::MacAddr(arg.udp_dstmac) << std::endl - << "udp_dstport2:" << arg.udp_dstport2 << std::endl - << "udp_dstip2:" << sls::IpAddr(arg.udp_dstip2) << std::endl - << "udp_dstmac2:" << sls::MacAddr(arg.udp_dstmac2) - << std::endl - << "frames:" << arg.frames << std::endl - << "triggers:" << arg.triggers << std::endl - << "bursts:" << arg.bursts << std::endl - << "analogSamples:" << arg.analogSamples << std::endl - << "digitalSamples:" << arg.digitalSamples << std::endl - << "expTimeNs:" << arg.expTimeNs << std::endl - << "periodNs:" << arg.periodNs << std::endl - << "subExpTimeNs:" << arg.subExpTimeNs << std::endl - << "subDeadTimeNs:" << arg.subDeadTimeNs << std::endl - << "activate:" << arg.activate << std::endl - << "quad:" << arg.quad << std::endl - << "dynamicRange:" << arg.dynamicRange << std::endl - << "timMode:" << arg.timMode << std::endl - << "tenGiga:" << arg.tenGiga << std::endl - << "roMode:" << arg.roMode << std::endl - << "adcMask:" << arg.adcMask << std::endl - << "adc10gMask:" << arg.adc10gMask << std::endl - << "roi.xmin:" << arg.roi.xmin << std::endl - << "roi.xmax:" << arg.roi.xmax << std::endl - << "countermask:" << arg.countermask << std::endl - << "burstType:" << arg.burstType << std::endl; + << "multiSize.x:" << arg.multiSize.x << std::endl + << "multiSize.y:" << arg.multiSize.y << std::endl + << "detId:" << arg.detId << std::endl + << "hostname:" << arg.hostname << std::endl + << "udpInterfaces:" << arg.udpInterfaces << std::endl + << "udp_dstport:" << arg.udp_dstport << std::endl + << "udp_dstip:" << sls::IpAddr(arg.udp_dstip) << std::endl + << "udp_dstmac:" << sls::MacAddr(arg.udp_dstmac) << std::endl + << "udp_dstport2:" << arg.udp_dstport2 << std::endl + << "udp_dstip2:" << sls::IpAddr(arg.udp_dstip2) << std::endl + << "udp_dstmac2:" << sls::MacAddr(arg.udp_dstmac2) + << std::endl + << "frames:" << arg.frames << std::endl + << "triggers:" << arg.triggers << std::endl + << "bursts:" << arg.bursts << std::endl + << "analogSamples:" << arg.analogSamples << std::endl + << "digitalSamples:" << arg.digitalSamples << std::endl + << "expTimeNs:" << arg.expTimeNs << std::endl + << "periodNs:" << arg.periodNs << std::endl + << "subExpTimeNs:" << arg.subExpTimeNs << std::endl + << "subDeadTimeNs:" << arg.subDeadTimeNs << std::endl + << "activate:" << arg.activate << std::endl + << "quad:" << arg.quad << std::endl + << "dynamicRange:" << arg.dynamicRange << std::endl + << "timMode:" << arg.timMode << std::endl + << "tenGiga:" << arg.tenGiga << std::endl + << "roMode:" << arg.roMode << std::endl + << "adcMask:" << arg.adcMask << std::endl + << "adc10gMask:" << arg.adc10gMask << std::endl + << "roi.xmin:" << arg.roi.xmin << std::endl + << "roi.xmax:" << arg.roi.xmax << std::endl + << "countermask:" << arg.countermask << std::endl + << "burstType:" << arg.burstType << std::endl; // if object exists, verify unlocked and idle, else only verify lock // (connecting first time) @@ -388,15 +388,15 @@ int ClientInterface::setup_receiver(Interface &socket) { // update retvals only if detmac is not the same as in detector sls::MacAddr retvals[2]; if (arg.udp_dstip != 0) { - sls::MacAddr r = setUdpIp(sls::IpAddr(arg.udp_dstip)); - sls::MacAddr detMac{arg.udp_dstmac}; + sls::MacAddr r = setUdpIp(sls::IpAddr(arg.udp_dstip)); + sls::MacAddr detMac{arg.udp_dstmac}; if (detMac != r) { retvals[0] = r; } } if (arg.udp_dstip2 != 0) { - sls::MacAddr r = setUdpIp2(sls::IpAddr(arg.udp_dstip2)); - sls::MacAddr detMac{arg.udp_dstmac2}; + sls::MacAddr r = setUdpIp2(sls::IpAddr(arg.udp_dstip2)); + sls::MacAddr detMac{arg.udp_dstmac2}; if (detMac != r) { retvals[1] = r; } @@ -1399,7 +1399,7 @@ int ClientInterface::set_adc_mask(Interface &socket) { } int ClientInterface::set_dbit_list(Interface &socket) { - sls::FixedCapacityContainer args; + sls::StaticVector args; socket.Receive(args); if (myDetectorType != CHIPTESTBOARD) functionNotImplemented(); @@ -1416,7 +1416,7 @@ int ClientInterface::set_dbit_list(Interface &socket) { int ClientInterface::get_dbit_list(Interface &socket) { if (myDetectorType != CHIPTESTBOARD) functionNotImplemented(); - sls::FixedCapacityContainer retval; + sls::StaticVector retval; retval = impl()->getDbitList(); LOG(logDEBUG1) << "Dbit list size retval:" << retval.size(); return socket.sendResult(retval); diff --git a/slsSupportLib/CMakeLists.txt b/slsSupportLib/CMakeLists.txt index d75ef8034..74b282708 100755 --- a/slsSupportLib/CMakeLists.txt +++ b/slsSupportLib/CMakeLists.txt @@ -28,7 +28,7 @@ set(PUBLICHEADERS include/ServerSocket.h include/ServerInterface.h include/network_utils.h - include/FixedCapacityContainer.h + include/StaticVector.h include/ToString.h include/TimeHelper.h include/TypeTraits.h diff --git a/slsSupportLib/include/FixedCapacityContainer.h b/slsSupportLib/include/StaticVector.h similarity index 81% rename from slsSupportLib/include/FixedCapacityContainer.h rename to slsSupportLib/include/StaticVector.h index 699a83db7..ea5c027e4 100644 --- a/slsSupportLib/include/FixedCapacityContainer.h +++ b/slsSupportLib/include/StaticVector.h @@ -7,7 +7,7 @@ #include namespace sls { -template class FixedCapacityContainer { +template class StaticVector { public: using size_type = typename std::array::size_type; @@ -20,10 +20,9 @@ template class FixedCapacityContainer { std::array data_; public: - FixedCapacityContainer() = default; + StaticVector() = default; - explicit FixedCapacityContainer(std::initializer_list l) - : current_size(l.size()) { + explicit StaticVector(std::initializer_list l) : current_size(l.size()) { size_check(l.size()); std::copy(l.begin(), l.end(), data_.begin()); } @@ -33,15 +32,14 @@ template class FixedCapacityContainer { typename = typename std::enable_if< is_container::value && std::is_same::value>::type> - FixedCapacityContainer(const V &v) : current_size(v.size()) { + 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 std::enable_if::value, - FixedCapacityContainer &>::type + typename std::enable_if::value, StaticVector &>::type operator=(const V &other) { size_check(other.size()); std::copy(other.begin(), other.end(), data_.begin()); @@ -49,7 +47,7 @@ template class FixedCapacityContainer { return *this; } - /** Compare FixedCapacityContainer with any other container*/ + /** Compare StaticVector with any other container*/ // template // typename std::enable_if::value, bool>::type // operator==(const V &other) const noexcept { @@ -143,66 +141,66 @@ template class FixedCapacityContainer { } __attribute__((packed)); template -bool operator==(const FixedCapacityContainer &lhs, - const FixedCapacityContainer &rhs) { +bool operator==(const StaticVector &lhs, + const StaticVector &rhs) { return lhs.is_equal(rhs); } template -bool operator!=(const FixedCapacityContainer &lhs, - const FixedCapacityContainer &rhs) { +bool operator!=(const StaticVector &lhs, + const StaticVector &rhs) { return !(lhs.is_equal(rhs)); } // Compare with array template -bool operator==(const FixedCapacityContainer &lhs, +bool operator==(const StaticVector &lhs, const std::array &rhs) { return lhs.is_equal(rhs); } template bool operator==(const std::array &lhs, - const FixedCapacityContainer &rhs) { + const StaticVector &rhs) { return rhs.is_equal(lhs); } template -bool operator!=(const FixedCapacityContainer &lhs, +bool operator!=(const StaticVector &lhs, const std::array &rhs) { return !lhs.is_equal(rhs); } template bool operator!=(const std::array &lhs, - const FixedCapacityContainer &rhs) { + const StaticVector &rhs) { return !rhs.is_equal(lhs); } // Compare with vector template -bool operator==(const FixedCapacityContainer &lhs, +bool operator==(const StaticVector &lhs, const std::vector &rhs) { return lhs.is_equal(rhs); } template bool operator==(const std::vector &lhs, - const FixedCapacityContainer &rhs) { + const StaticVector &rhs) { return rhs.is_equal(lhs); } template -bool operator!=(const FixedCapacityContainer &lhs, +bool operator!=(const StaticVector &lhs, const std::vector &rhs) { return !lhs.is_equal(rhs); } template bool operator!=(const std::vector &lhs, - const FixedCapacityContainer &rhs) { + const StaticVector &rhs) { return !rhs.is_equal(lhs); } @@ -210,7 +208,7 @@ bool operator!=(const std::vector &lhs, // template // typename std::enable_if::value, bool>::type operator==( // const C &container, -// const FixedCapacityContainer &fixed_container) noexcept { +// const StaticVector &fixed_container) noexcept { // return fixed_container.operator==(container); // } @@ -218,7 +216,7 @@ bool operator!=(const std::vector &lhs, // template // typename std::enable_if::value, bool>::type operator!=( // const C &container, -// const FixedCapacityContainer &fixed_container) noexcept { +// const StaticVector &fixed_container) noexcept { // return fixed_container.operator!=(container); // } diff --git a/slsSupportLib/include/ToString.h b/slsSupportLib/include/ToString.h index fdd0db241..b066b878d 100644 --- a/slsSupportLib/include/ToString.h +++ b/slsSupportLib/include/ToString.h @@ -7,7 +7,7 @@ * */ -#include "FixedCapacityContainer.h" +#include "StaticVector.h" #include "TimeHelper.h" #include "TypeTraits.h" #include "sls_detector_defs.h" @@ -42,7 +42,7 @@ std::ostream &operator<<(std::ostream &os, const slsDetectorDefs::ROI &roi); template std::ostream &operator<<(std::ostream &os, - const sls::FixedCapacityContainer &c) { + const sls::StaticVector &c) { return os << ToString(c); } diff --git a/slsSupportLib/tests/CMakeLists.txt b/slsSupportLib/tests/CMakeLists.txt index 8832c3315..45861cefe 100755 --- a/slsSupportLib/tests/CMakeLists.txt +++ b/slsSupportLib/tests/CMakeLists.txt @@ -5,7 +5,7 @@ target_sources(tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/test-Timer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-sls_detector_defs.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-Sockets.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/test-FixedCapacityContainer.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test-StaticVector.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-ToString.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-TypeTraits.cpp ${CMAKE_CURRENT_SOURCE_DIR}/test-UdpRxSocket.cpp diff --git a/slsSupportLib/tests/test-FixedCapacityContainer.cpp b/slsSupportLib/tests/test-StaticVector.cpp similarity index 82% rename from slsSupportLib/tests/test-FixedCapacityContainer.cpp rename to slsSupportLib/tests/test-StaticVector.cpp index 90b460de7..bf6bba5df 100644 --- a/slsSupportLib/tests/test-FixedCapacityContainer.cpp +++ b/slsSupportLib/tests/test-StaticVector.cpp @@ -1,19 +1,19 @@ -#include "FixedCapacityContainer.h" +#include "StaticVector.h" #include "TypeTraits.h" #include "catch.hpp" #include #include -using sls::FixedCapacityContainer; +using sls::StaticVector; -TEST_CASE("FixedCapacityContainer is a container") { - REQUIRE(sls::is_container>::value == true); +TEST_CASE("StaticVector is a container") { + REQUIRE(sls::is_container>::value == true); } -TEST_CASE("Comparing FixedCapacity containers") { - FixedCapacityContainer a{0, 1, 2}; - FixedCapacityContainer b{0, 1, 2}; - FixedCapacityContainer c{0, 1, 2, 4}; +TEST_CASE("Comparing StaticVector containers") { + StaticVector a{0, 1, 2}; + StaticVector b{0, 1, 2}; + StaticVector c{0, 1, 2, 4}; REQUIRE(a == b); REQUIRE_FALSE(a != b); @@ -27,7 +27,7 @@ TEST_CASE("Comparing FixedCapacity containers") { TEST_CASE("Compare array and fixed capacity container") { std::array arr{1, 2, 3}; std::array arr2{1, 7, 3}; - FixedCapacityContainer fcc{1, 2, 3}; + StaticVector fcc{1, 2, 3}; REQUIRE(fcc == arr); REQUIRE(arr == fcc); REQUIRE_FALSE(fcc != arr); @@ -39,7 +39,7 @@ TEST_CASE("Compare array and fixed capacity container") { TEST_CASE("Compare vector and fixed capacity container") { std::vector vec{1, 2, 3}; std::vector vec2{10, 2, 3}; - FixedCapacityContainer fcc{1, 2, 3}; + StaticVector fcc{1, 2, 3}; REQUIRE(fcc == vec); REQUIRE(vec == fcc); REQUIRE_FALSE(fcc != vec); @@ -50,51 +50,51 @@ TEST_CASE("Compare vector and fixed capacity container") { TEST_CASE("Construct from vector") { std::vector vec{1, 2, 3}; - FixedCapacityContainer fcc{vec}; + StaticVector fcc{vec}; REQUIRE(fcc == vec); } TEST_CASE("Copy construct from vector") { std::vector vec{1, 2, 3}; - FixedCapacityContainer fcc = vec; + StaticVector fcc = vec; REQUIRE(fcc == vec); } TEST_CASE("Copy assignment from vector") { std::vector vec{1, 2, 3}; - FixedCapacityContainer fcc; + StaticVector fcc; fcc = vec; REQUIRE(fcc == vec); } TEST_CASE("Construct from array") { std::array arr{1, 2, 3}; - FixedCapacityContainer fcc{arr}; + StaticVector fcc{arr}; REQUIRE(fcc == arr); } TEST_CASE("Copy assign from array") { std::array arr{1, 2, 3}; - FixedCapacityContainer fcc; + StaticVector fcc; fcc = arr; REQUIRE(fcc == arr); } TEST_CASE("Copy construct from array") { std::array arr{1, 2, 3}; - FixedCapacityContainer fcc = arr; + StaticVector fcc = arr; REQUIRE(fcc == arr); } TEST_CASE("Free function and method gives the same iterators") { - FixedCapacityContainer fcc{1, 2, 3}; + StaticVector fcc{1, 2, 3}; REQUIRE(std::begin(fcc) == fcc.begin()); } -SCENARIO("FixedCapacityContainers can be sized and resized", "[support]") { +SCENARIO("StaticVectors can be sized and resized", "[support]") { GIVEN("A default constructed container") { constexpr size_t n_elem = 5; - FixedCapacityContainer vec; + StaticVector vec; REQUIRE(vec.empty()); REQUIRE(vec.size() == 0); // NOLINT @@ -131,8 +131,8 @@ SCENARIO("FixedCapacityContainers can be sized and resized", "[support]") { } } - GIVEN("A FixedCapacityContainer constructed form a std::initializer list") { - FixedCapacityContainer vec{23, 52, 11}; + GIVEN("A StaticVector constructed form a std::initializer list") { + StaticVector vec{23, 52, 11}; REQUIRE(vec.size() == 3); REQUIRE(vec.capacity() == 10); REQUIRE(vec[0] == 23); @@ -174,7 +174,7 @@ SCENARIO("FixedCapacityContainers can be sized and resized", "[support]") { GIVEN("An std::vector of size 3") { std::vector standard_vector{5, 2, 1}; WHEN("we construct a fixed capacity container from it") { - FixedCapacityContainer vec(standard_vector); + StaticVector vec(standard_vector); THEN("size and data matches") { REQUIRE(vec.size() == 3); REQUIRE(vec[0] == 5); @@ -188,10 +188,10 @@ SCENARIO("FixedCapacityContainers can be sized and resized", "[support]") { } } -SCENARIO("Comparison of FixedCapacityContainers", "[support]") { +SCENARIO("Comparison of StaticVectors", "[support]") { GIVEN("Two containers containers that are equal at the start") { - FixedCapacityContainer a{0, 1, 2}; - FixedCapacityContainer b{0, 1, 2}; + StaticVector a{0, 1, 2}; + StaticVector b{0, 1, 2}; REQUIRE(a == b); REQUIRE_FALSE(a != b); @@ -199,8 +199,8 @@ SCENARIO("Comparison of FixedCapacityContainers", "[support]") { a.push_back(4); THEN("they are not equal anymore") { REQUIRE(a != b); } } - WHEN("Compared to a FixedCapacityContainer with different capacity") { - FixedCapacityContainer c{0, 1, 2}; + WHEN("Compared to a StaticVector with different capacity") { + StaticVector c{0, 1, 2}; THEN("The comparison still holds") { REQUIRE(a == c); REQUIRE_FALSE(a != c); @@ -232,7 +232,7 @@ SCENARIO("Comparison of FixedCapacityContainers", "[support]") { SCENARIO("Sorting, removing and other manipulation of a container", "[support]") { GIVEN("An unsorted container") { - FixedCapacityContainer a{14, 12, 90, 12}; + StaticVector a{14, 12, 90, 12}; WHEN("We sort it") { std::sort(a.begin(), a.end()); THEN("Elements appear sorted") { @@ -264,8 +264,8 @@ SCENARIO("Sorting, removing and other manipulation of a container", SCENARIO("Assigning containers to each other", "[support]") { GIVEN("Two containers") { - FixedCapacityContainer a{1, 2, 3}; - FixedCapacityContainer b{4, 5, 6}; + StaticVector a{1, 2, 3}; + StaticVector b{4, 5, 6}; WHEN("a is assigned to b") { a = b; THEN("A deep copy is made and both containers are equal") { @@ -278,7 +278,7 @@ SCENARIO("Assigning containers to each other", "[support]") { } } WHEN("A new object is create from an old one") { - FixedCapacityContainer c(a); + StaticVector c(a); THEN("A deep copy is also made") { REQUIRE(c == a); REQUIRE(&c != &a); @@ -288,8 +288,8 @@ SCENARIO("Assigning containers to each other", "[support]") { REQUIRE(c[2] == 3); } } - WHEN("We create a const FixedCapacityContainer") { - const FixedCapacityContainer c(a); + WHEN("We create a const StaticVector") { + const StaticVector c(a); THEN("The values are still the same using const operators") { REQUIRE(c[0] == 1); REQUIRE(c[1] == 2); @@ -302,8 +302,8 @@ SCENARIO("Assigning containers to each other", "[support]") { } SCENARIO("Converting to vector", "[support]") { - GIVEN("a FixedCapacityContainer") { - FixedCapacityContainer a{1, 2, 3}; + GIVEN("a StaticVector") { + StaticVector a{1, 2, 3}; WHEN("Converted into a vector") { std::vector b(a); THEN("Data and size matches") { diff --git a/slsSupportLib/tests/test-ToString.cpp b/slsSupportLib/tests/test-ToString.cpp index f08216b4d..8ce0ddd48 100644 --- a/slsSupportLib/tests/test-ToString.cpp +++ b/slsSupportLib/tests/test-ToString.cpp @@ -232,15 +232,15 @@ TEST_CASE("Streaming of slsDetectorDefs::ROI") { REQUIRE(oss.str() == "[-10, 1]"); } -TEST_CASE("sls::FixedCapacityContainer") { - sls::FixedCapacityContainer vec; +TEST_CASE("sls::StaticVector") { + sls::StaticVector vec; vec.push_back(3); vec.push_back(8); REQUIRE(ToString(vec) == "[3, 8]"); } -TEST_CASE("sls::FixedCapacityContainer stream") { - sls::FixedCapacityContainer vec; +TEST_CASE("sls::StaticVector stream") { + sls::StaticVector vec; vec.push_back(33); vec.push_back(85667); vec.push_back(2);