Mantid
Loading...
Searching...
No Matches
MultiFileNameParser.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2010 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#pragma once
8
9//----------------------------------------------------------------------
10// Includes
11//----------------------------------------------------------------------
12
13#include "MantidKernel/DllConfig.h"
14
15#include <set>
16#include <string>
17#include <utility>
18#include <vector>
19
20namespace Mantid {
21namespace Kernel {
22namespace MultiFileNameParsing {
25MANTID_KERNEL_DLL std::string suggestWorkspaceName(const std::vector<std::string> &fileNames);
26
28namespace Regexs {
29extern const std::string INST, UNDERSCORE, SPACE;
30extern const std::string COMMA, PLUS, MINUS, COLON;
32extern const std::string ANY, LIST;
33} // namespace Regexs
34
38class MANTID_KERNEL_DLL ReverseCaselessCompare {
39public:
40 bool operator()(const std::string &a, const std::string &b) const;
41};
42
62class MANTID_KERNEL_DLL Parser {
63public:
65 Parser();
67 ~Parser() = default;
68
70 void parse(const std::string &multiFileName);
71
73 std::vector<std::vector<unsigned int>> runs() const { return m_runs; }
75 std::vector<std::vector<std::string>> fileNames() const { return m_fileNames; }
77 std::string dirString() const { return m_dirString; }
79 std::string instString() const { return m_instString; }
81 std::string underscoreString() const { return m_underscoreString; }
83 std::string runString() const { return m_runString; }
85 std::string extString() const { return m_extString; }
88 std::vector<std::vector<unsigned int>> parseMultiRunString(std::string runString);
90 bool trimWhiteSpaces() const;
92 void setTrimWhiteSpaces(const bool &setting);
93
94private:
96 void clear();
98 void split();
99
101 std::vector<std::vector<unsigned int>> m_runs;
103 std::vector<std::vector<std::string>> m_fileNames;
105 std::string m_multiFileName;
107 std::string m_dirString, m_instString, m_underscoreString, m_runString, m_extString;
109 std::set<std::string, ReverseCaselessCompare> m_validInstNames;
112};
113
119class MANTID_KERNEL_DLL GenerateFileName {
120public:
122 GenerateFileName(std::string prefix, std::string suffix, std::string instString);
123
126 std::vector<std::string> operator()(const std::vector<unsigned int> &runs);
128 std::string operator()(unsigned int run);
129
130private:
132 std::string m_prefix;
134 std::string m_suffix;
136 std::string m_instString;
137};
138
147class MANTID_KERNEL_DLL RunRangeList {
148public:
150 RunRangeList();
151
152 // Returns the list of run ranges.
153 std::set<std::pair<unsigned int, unsigned int>> rangeList() const { return m_rangeList; };
154
156 void addRun(const unsigned int run);
158 void addRunRange(const unsigned int from, const unsigned int to);
160 void addRunRange(const std::pair<unsigned int, unsigned int> &range);
161
162private:
165 std::set<std::pair<unsigned int, unsigned int>> m_rangeList;
166};
167
168} // namespace MultiFileNameParsing
169
170} // namespace Kernel
171} // namespace Mantid
A functor that generates a vector of file names from the given vector of runs, and other state passed...
std::string m_instString
String that identifies the instrument.
std::string m_prefix
String that prefixes any generated file names.
std::string m_suffix
String that suffixes any generated file names.
This class takes a string representing multiple files and parses it into a vector of vectors of file ...
std::string runString() const
Return the parsed run string.
std::vector< std::vector< unsigned int > > runs() const
Return the vector of vectors of parsed file names.
std::string underscoreString() const
Return the parsed underscore string.
std::string m_multiFileName
The given string to parse.
std::vector< std::vector< std::string > > m_fileNames
A vector of vectors of the parsed file names.
std::string instString() const
Return the parsed instrument string.
std::vector< std::vector< unsigned int > > m_runs
A vector of vectors of the parsed runs.
std::set< std::string, ReverseCaselessCompare > m_validInstNames
All the valid instrument names.
bool m_trimWhiteSpaces
Flag to determine if string input should be trimmed of whitespace.
std::string dirString() const
Return the parsed directory string.
std::string extString() const
Return the parsed extension string.
std::string m_dirString
The various sections of the given string to parse.
std::vector< std::vector< std::string > > fileNames() const
Return the vector of vectors of parsed file names.
Comparator for set that holds instrument names in Parser.
A class that holds a list of ranges of runs.
std::set< std::pair< unsigned int, unsigned int > > m_rangeList
A set of pairs of unsigned ints, where each pair represents a range of runs.
std::set< std::pair< unsigned int, unsigned int > > rangeList() const
void split(const int A, int &S, int &V)
Split a number into the sign and positive value.
Definition: Acomp.cpp:42
MANTID_KERNEL_DLL std::string suggestWorkspaceName(const std::vector< std::string > &fileNames)
Suggests a workspace name, given a vector of file names.
Helper class which provides the Collimation Length for SANS instruments.