Mantid
Loading...
Searching...
No Matches
SpinStateHelpers.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2025 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7
11
12#include <algorithm>
13#include <vector>
14
15namespace Mantid {
16namespace Kernel {
17namespace SpinStateHelpers {
18
19/*
20For a given workspace group, spin state order, and desired spin state, this method will
21return the index of the specified workspace in the group, using the position of the desired spin
22state in the spin state order.
23*/
24std::optional<size_t> indexOfWorkspaceForSpinState(const std::vector<std::string> &spinStateOrder,
25 std::string targetSpinState) {
26 Strings::stripInPlace(targetSpinState);
27 size_t const index =
28 std::find(spinStateOrder.cbegin(), spinStateOrder.cend(), targetSpinState) - spinStateOrder.cbegin();
29 if (index == spinStateOrder.size()) {
30 return std::nullopt;
31 }
32 return index;
33}
34
35/*
36For a given spin state input string of the form e.g. "01,11,00,10", split the string
37into a vector of individual spin states. This will also trim any leading/trailing
38whitespace in the individual spin states.
39*/
40std::vector<std::string> splitSpinStateString(const std::string &spinStates) {
41 StringTokenizer tokens{spinStates, ",", StringTokenizer::TOK_TRIM};
42 return std::vector<std::string>{tokens.begin(), tokens.end()};
43}
44} // namespace SpinStateHelpers
45} // namespace Kernel
46} // namespace Mantid
std::map< DeltaEMode::Type, std::string > index
Iterator begin()
Iterator referring to first element in the container.
@ TOK_TRIM
remove leading and trailing whitespace from tokens
MANTID_KERNEL_DLL std::vector< std::string > splitSpinStateString(const std::string &spinStates)
MANTID_KERNEL_DLL std::optional< size_t > indexOfWorkspaceForSpinState(const std::vector< std::string > &spinStateOrder, std::string targetSpinState)
MANTID_KERNEL_DLL void stripInPlace(std::string &A)
strip pre/post spaces
Definition Strings.cpp:429
Helper class which provides the Collimation Length for SANS instruments.