27using namespace Kernel;
35 const std::vector<std::string> exts{
".dat",
".txt"};
37 "The name of the text file to read, including its full or "
38 "relative path. The file extension must be .txt or .dat.");
40 "The name of the workspace that will be created, filled with the read-in "
41 "data and stored in the [[Analysis Data Service]].");
44 units.insert(units.begin(),
"MomemtumTransfer");
45 declareProperty(
"Unit",
"Energy", std::make_shared<Kernel::StringListValidator>(units),
46 "The unit to assign to the X axis (anything known to the "
47 "[[Unit Factory]] or \"Dimensionless\")");
55 std::ifstream file(filename.c_str());
57 file.seekg(0, std::ios::end);
59 file.seekg(0, std::ios::beg);
62 std::vector<double> input;
71 file.seekg(0, std::ios::beg);
74 while (getline(file, str)) {
75 progress.report(
static_cast<int>(file.tellg()));
80 if (str.empty() && specNum != -1) {
81 auto histogram = localWorkspace->histogram(specNum);
83 localWorkspace->setHistogram(specNum, histogram);
95 throw "Undefined number of spectra";
97 if (
static_cast<size_t>(specNum) == (
nSpectra - 1)) {
98 auto histogram = localWorkspace->histogram(specNum);
100 localWorkspace->setHistogram(specNum, histogram);
117 size_t spectra_nbr = 0;
119 while (getline(file, str)) {
122 if (str[0] ==
'#' && str[1] ==
'L') {
136 if (!line.empty() && line[0] !=
'#') {
138 const std::string sep =
" ";
140 buffer.reserve(buffer.size() + tok.
size());
141 std::transform(tok.
cbegin(), tok.
cend(), std::back_inserter(buffer),
142 [](
const auto &beg) { return std::stod(beg); });
153 std::vector<double>
x,
y, e;
155 auto isHist = input.size() % 3 > 0;
156 auto nElements = (isHist) ? input.size() - 1 : input.size() - 2;
158 x.reserve(nElements);
159 y.reserve(nElements);
160 e.reserve(nElements);
163 x.emplace_back(input[
index]);
165 y.emplace_back(input[
index]);
167 e.emplace_back(input[
index]);
170 histogram.resize(
y.size());
175 x.emplace_back(input.back());
176 histogram.setBinEdges(
x);
178 histogram.setPoints(
x);
181 histogram.setCounts(
y);
182 histogram.setCountStandardDeviations(e);
#define DECLARE_ALGORITHM(classname)
std::map< DeltaEMode::Type, std::string > index
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
@ Load
allowed here which will be passed to the algorithm
Helper class for reporting progress from algorithms.
A property class for workspaces.
void exec() override
Executes the algorithm.
void init() override
Initialisation method.
void readHistogram(const std::vector< double > &input, HistogramData::Histogram &histogram) const
Helper method for reading a single histogram.
void readLine(const std::string &line, std::vector< double > &buffer) const
Helper method for reading a line from the file.
size_t readNumberOfSpectra(std::ifstream &file) const
Helper method for reading the number of spectra from the file.
LoadSpec()
Empty constructor.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
@ TOK_IGNORE_EMPTY
ignore empty tokens
std::size_t size() const noexcept
Get the total number of tokens.
ConstIterator cend() const
Const iterator referring to the past-the-end element in the container.
ConstIterator cbegin() const
Const iterator referring to first element in the container.
std::unique_ptr< T > create(const P &parent, const IndexArg &indexArg, const HistArg &histArg)
This is the create() method that all the other create() methods call.
@ Output
An output workspace.