diff --git a/.github/workflows/build_documentation.yml b/.github/workflows/build_documentation.yml index be3dc4a62..fef09501b 100644 --- a/.github/workflows/build_documentation.yml +++ b/.github/workflows/build_documentation.yml @@ -35,7 +35,7 @@ jobs: shell: "bash -l {0}" steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 with: fetch-depth: 0 # Fetch all history for proper git operations token: ${{ secrets.GITHUB_TOKEN }} # Use the default token @@ -84,7 +84,7 @@ jobs: --date "$(date +'%d.%m.%Y')" - name: Checkout gh-pages - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: ref: gh-pages path: gh-pages diff --git a/.github/workflows/build_wheel.yml b/.github/workflows/build_wheel.yml index 05e4dc66c..2d5a2dbaa 100644 --- a/.github/workflows/build_wheel.yml +++ b/.github/workflows/build_wheel.yml @@ -34,12 +34,12 @@ jobs: name: Build source distribution runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Build sdist run: pipx run build --sdist - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@v7 with: name: cibw-sdist path: dist/*.tar.gz diff --git a/.github/workflows/cmake.yaml b/.github/workflows/cmake.yaml index 773700f1c..1c4d7b0f6 100644 --- a/.github/workflows/cmake.yaml +++ b/.github/workflows/cmake.yaml @@ -14,8 +14,8 @@ jobs: runs-on: ubuntu-latest name: Configure and build using cmake steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 + - uses: actions/checkout@v6 + - uses: actions/setup-python@v6 with: python-version: 3.12 cache: 'pip' diff --git a/.github/workflows/conda_deploy_library.yaml b/.github/workflows/conda_deploy_library.yaml index 6b5fb996e..68d046aff 100644 --- a/.github/workflows/conda_deploy_library.yaml +++ b/.github/workflows/conda_deploy_library.yaml @@ -21,10 +21,10 @@ jobs: shell: "bash -l {0}" steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Get conda - uses: conda-incubator/setup-miniconda@v3.0.4 + uses: conda-incubator/setup-miniconda@v4 with: python-version: ${{ matrix.python-version }} channels: conda-forge @@ -38,10 +38,10 @@ jobs: - name: Build env: CONDA_TOKEN: ${{ secrets.CONDA_TOKEN }} - run: conda build conda-recipes/main-library --user slsdetectorgroup --token ${CONDA_TOKEN} --output-folder build_output + run: conda-build conda-recipes/main-library --user slsdetectorgroup --token ${CONDA_TOKEN} --output-folder build_output - name: Upload all Conda to github as artifacts - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v7 with: name: conda-packages path: build_output/** # Uploads all packages \ No newline at end of file diff --git a/.github/workflows/conda_deploy_slsdet.yaml b/.github/workflows/conda_deploy_slsdet.yaml index d25bffa74..4207132bf 100644 --- a/.github/workflows/conda_deploy_slsdet.yaml +++ b/.github/workflows/conda_deploy_slsdet.yaml @@ -21,10 +21,10 @@ jobs: shell: "bash -l {0}" steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Get conda - uses: conda-incubator/setup-miniconda@v3.0.4 + uses: conda-incubator/setup-miniconda@v4 with: python-version: ${{ matrix.python-version }} channels: conda-forge @@ -38,10 +38,10 @@ jobs: - name: Build env: CONDA_TOKEN: ${{ secrets.CONDA_TOKEN }} - run: conda build conda-recipes/python-client --user slsdetectorgroup --token ${CONDA_TOKEN} --output-folder build_output + run: conda-build conda-recipes/python-client --user slsdetectorgroup --token ${CONDA_TOKEN} --output-folder build_output - name: Upload all Conda packages - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v7 with: name: conda-packages path: build_output/** # Uploads all packages \ No newline at end of file diff --git a/.github/workflows/conda_library.yaml b/.github/workflows/conda_library.yaml index 23f94d467..1086021c7 100644 --- a/.github/workflows/conda_library.yaml +++ b/.github/workflows/conda_library.yaml @@ -18,10 +18,10 @@ jobs: shell: "bash -l {0}" steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Get conda - uses: conda-incubator/setup-miniconda@v3.0.4 + uses: conda-incubator/setup-miniconda@v4 with: python-version: ${{ matrix.python-version }} channels: conda-forge @@ -33,10 +33,10 @@ jobs: run: conda config --set anaconda_upload no - name: Build - run: conda build conda-recipes/main-library --output-folder build_output + run: conda-build conda-recipes/main-library --output-folder build_output - name: Upload all Conda packages - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v7 with: name: conda-packages path: build_output/** # Uploads all packages \ No newline at end of file diff --git a/.github/workflows/conda_python.yaml b/.github/workflows/conda_python.yaml index 4b12cb3ff..18d18e62e 100644 --- a/.github/workflows/conda_python.yaml +++ b/.github/workflows/conda_python.yaml @@ -18,10 +18,10 @@ jobs: shell: "bash -l {0}" steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - name: Get conda - uses: conda-incubator/setup-miniconda@v3.0.4 + uses: conda-incubator/setup-miniconda@v4 with: python-version: ${{ matrix.python-version }} channels: conda-forge @@ -33,10 +33,10 @@ jobs: run: conda config --set anaconda_upload no - name: Build - run: conda build conda-recipes/python-client --output-folder build_output + run: conda-build conda-recipes/python-client --output-folder build_output - name: Upload all Conda packages - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v7 with: name: conda-packages path: build_output/** # Uploads all packages \ No newline at end of file diff --git a/slsDetectorSoftware/src/CallerSpecial.cpp b/slsDetectorSoftware/src/CallerSpecial.cpp index dc2ae8c6c..a2975d758 100644 --- a/slsDetectorSoftware/src/CallerSpecial.cpp +++ b/slsDetectorSoftware/src/CallerSpecial.cpp @@ -1014,15 +1014,16 @@ std::string Caller::counters(int action) { if (args.empty()) { WrongNumberOfParameters(1); } - if (std::any_of(args.cbegin(), args.cend(), [](std::string s) { - return (StringTo(s) < 0 || StringTo(s) > 2); + //convert args to string and then to a vector of ints + auto counters = StringTo>( ToString(args)); + if (std::any_of(counters.cbegin(), counters.cend(), [](int val) { + return (val < 0 || val > 2); })) { throw RuntimeError("Invalid counter indices list. Example: 0 1 2"); } // convert vector to counter enable mask uint32_t mask = 0; - for (size_t i = 0; i < args.size(); ++i) { - int val = StringTo(args[i]); + for (auto val : counters) { // already enabled earlier if (mask & (1 << val)) { std::ostringstream oss; @@ -1226,11 +1227,7 @@ std::string Caller::rx_dbitlist(int action) { } // 'none' option already covered as t is empty by default else if (args[0] != "none") { - unsigned int ntrim = args.size(); - t.resize(ntrim); - for (unsigned int i = 0; i < ntrim; ++i) { - t[i] = StringTo(args[i]); - } + t = StringTo>(ToString(args)); } det->setRxDbitList(t, std::vector{det_id}); os << ToString(args) << '\n'; diff --git a/slsSupportLib/include/sls/ToString.h b/slsSupportLib/include/sls/ToString.h index 7035f9c38..28347f1eb 100644 --- a/slsSupportLib/include/sls/ToString.h +++ b/slsSupportLib/include/sls/ToString.h @@ -1,7 +1,6 @@ // SPDX-License-Identifier: LGPL-3.0-or-other // Copyright (C) 2021 Contributors to the SLS Detector Package #pragma once - /** * \file ToString.h * @@ -353,7 +352,9 @@ T StringTo(const std::string &f, const std::string &unit) { } } -template T StringTo(const std::string &t) { +template ::value, int> = 0> +T StringTo(const std::string &t) { std::string tmp{t}; auto unit = RemoveUnit(tmp); return StringTo(tmp, unit); @@ -398,6 +399,7 @@ ToString(const T &obj) { return obj.str(); } +/** Convert vector of strings to vector of type T */ template std::vector StringTo(const std::vector &strings) { std::vector result; @@ -407,4 +409,36 @@ std::vector StringTo(const std::vector &strings) { return result; } +/** Parse comma-separated string into vector type T (e.g., + * StringTo>()) */ +template ::value && + !std::is_same_v, + int> = 0> +T StringTo(const std::string &s) { + using ElementType = typename T::value_type; + T res; + std::istringstream ss(s); + std::string item; + while (std::getline(ss, item, ',')) { + item.erase(std::remove_if(item.begin(), item.end(), + [](char c) { + return c == '[' || c == ']' || c == '"' || + c == ' '; + }), + item.end()); + + try { + if (item.empty()) + continue; + auto val = StringTo(item); + res.push_back(val); + } catch (const std::exception &e) { + throw RuntimeError("Could not convert '" + item + + "' to the container element type. " + + std::string(e.what())); + } + } + return res; +} + } // namespace sls diff --git a/slsSupportLib/tests/test-ToString.cpp b/slsSupportLib/tests/test-ToString.cpp index 0c35bdfc0..0d7ebaf3d 100644 --- a/slsSupportLib/tests/test-ToString.cpp +++ b/slsSupportLib/tests/test-ToString.cpp @@ -415,4 +415,13 @@ TEST_CASE("string to timingInfoDecoder") { defs::timingInfoDecoder::SHINE); } + +TEST_CASE("Convert string to vector of ints") { + REQUIRE(StringTo>("1, 2, 3") == std::vector{1, 2, 3}); + REQUIRE(StringTo>(" 4 ,5,6 ") == std::vector{4, 5, 6}); + REQUIRE(StringTo>("[8]") == std::vector{8}); + REQUIRE(StringTo>("9, ") == std::vector{9}); + REQUIRE(StringTo>("") == std::vector{}); +} + } // namespace sls