Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build_documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build_wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/cmake.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/conda_deploy_library.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
8 changes: 4 additions & 4 deletions .github/workflows/conda_deploy_slsdet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
8 changes: 4 additions & 4 deletions .github/workflows/conda_library.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
8 changes: 4 additions & 4 deletions .github/workflows/conda_python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
15 changes: 6 additions & 9 deletions slsDetectorSoftware/src/CallerSpecial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(s) < 0 || StringTo<int>(s) > 2);
//convert args to string and then to a vector of ints
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the help string in both commands - such that it includes comma seperated values and list

auto counters = StringTo<std::vector<int>>( 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<int>(args[i]);
for (auto val : counters) {
// already enabled earlier
if (mask & (1 << val)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add the end use: os << ToString(counters) << '\n'; instead of args. Returns what you actually set.

std::ostringstream oss;
Expand Down Expand Up @@ -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<int>(args[i]);
}
t = StringTo<std::vector<int>>(ToString(args));
}
det->setRxDbitList(t, std::vector<int>{det_id});
os << ToString(args) << '\n';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here ToString(t)

Expand Down
38 changes: 36 additions & 2 deletions slsSupportLib/include/sls/ToString.h
Original file line number Diff line number Diff line change
@@ -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
*
Expand Down Expand Up @@ -353,7 +352,9 @@ T StringTo(const std::string &f, const std::string &unit) {
}
}

template <typename T> T StringTo(const std::string &t) {
template <typename T,
std::enable_if_t<!is_container<T>::value, int> = 0>
T StringTo(const std::string &t) {
std::string tmp{t};
auto unit = RemoveUnit(tmp);
return StringTo<T>(tmp, unit);
Expand Down Expand Up @@ -398,6 +399,7 @@ ToString(const T &obj) {
return obj.str();
}

/** Convert vector of strings to vector of type T */
template <typename T>
std::vector<T> StringTo(const std::vector<std::string> &strings) {
std::vector<T> result;
Expand All @@ -407,4 +409,36 @@ std::vector<T> StringTo(const std::vector<std::string> &strings) {
return result;
}

/** Parse comma-separated string into vector type T (e.g.,
* StringTo<std::vector<int>>()) */
template <typename T, std::enable_if_t<is_container<T>::value &&
!std::is_same_v<T, std::string>,
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 == ' ';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we throw if start of string is [ and end is not closing ] ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could but then we need to keep track of which symbols we found. I'm not sure it's needed but can be convinced.

}),
item.end());

try {
if (item.empty())
continue;
auto val = StringTo<ElementType>(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
9 changes: 9 additions & 0 deletions slsSupportLib/tests/test-ToString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,4 +415,13 @@ TEST_CASE("string to timingInfoDecoder") {
defs::timingInfoDecoder::SHINE);
}


TEST_CASE("Convert string to vector of ints") {
REQUIRE(StringTo<std::vector<int>>("1, 2, 3") == std::vector<int>{1, 2, 3});
REQUIRE(StringTo<std::vector<int>>(" 4 ,5,6 ") == std::vector<int>{4, 5, 6});
REQUIRE(StringTo<std::vector<int>>("[8]") == std::vector<int>{8});
REQUIRE(StringTo<std::vector<int>>("9, ") == std::vector<int>{9});
REQUIRE(StringTo<std::vector<int>>("") == std::vector<int>{});
}

} // namespace sls
Loading