Mantid
Loading...
Searching...
No Matches
LoadAscii2.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 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
11#include "MantidDataHandling/DllConfig.h"
14
15#include <list>
16
17namespace Mantid {
18namespace DataHandling {
35class MANTID_DATAHANDLING_DLL LoadAscii2 : public API::IFileLoader<Kernel::FileDescriptor> {
36public:
38 LoadAscii2();
40 const std::string name() const override { return "LoadAscii"; }
42 const std::string summary() const override {
43 return "Loads data from a text file and stores it in a 2D workspace "
44 "or Table Workspace.";
45 }
46
48 int version() const override { return 2; }
49 const std::vector<std::string> seeAlso() const override { return {"SaveAscii"}; }
51 const std::string category() const override { return "DataHandling\\Text"; }
53 int confidence(Kernel::FileDescriptor &descriptor) const override;
54
55protected:
57 virtual API::Workspace_sptr readData(std::ifstream &file);
59 virtual API::Workspace_sptr readTable(std::ifstream &file);
61 bool skipLine(const std::string &line, bool header = false) const;
63 bool badLine(const std::string &line) const;
65 void newSpectra();
67 void inconsistantIDCheck() const;
69 int splitIntoColumns(std::list<std::string> &columns, const std::string &str) const;
71 void fillInputValues(std::vector<double> &values, const std::list<std::string> &columns) const;
72 // write the values in the current line to teh end fo teh current spectra
73 void addToCurrentSpectra(const std::list<std::string> &columns);
74 // check that the number of columns in the current line match the number found
75 // previously
76 void checkLineColumns(const size_t &cols) const;
77 // interpret a line that has been deemed valid enough to look at.
78 void parseLine(const std::string &line, std::list<std::string> &columns);
79 // find the number of columns we should expect from now on
80 void setcolumns(std::ifstream &file, std::string &line, std::list<std::string> &columns);
81 // wirte the spectra to the workspace
82 void writeToWorkspace(API::MatrixWorkspace_sptr &localWorkspace, const size_t &numSpectra) const;
83 // Process the header information. This implementation just skips it entirely.
84 void processHeader(std::ifstream &file);
85 // Set the Distribution on the workspace, either from input property or file header
86 bool setDistribution(std::ifstream &file);
88 std::string m_columnSep;
89
90private:
92 void init() override;
94 void exec() override;
95
97 std::map<std::string, std::string> m_separatorIndex;
98 std::string m_comment;
99 size_t m_baseCols;
100 size_t m_specNo;
102 size_t m_curBins;
105 size_t m_lineNo;
106 std::vector<DataObjects::Histogram1D> m_spectra;
107 std::unique_ptr<DataObjects::Histogram1D> m_curSpectra;
108 std::vector<double> m_curDx;
109 std::vector<double> m_spectrumAxis;
110};
111
112} // namespace DataHandling
113} // namespace Mantid
Defines an interface to an algorithm that loads a file so that it can take part in the automatic sele...
Definition: IFileLoader.h:19
Loads a workspace from an ascii file.
Definition: LoadAscii2.h:35
const std::string summary() const override
Summary of algorithms purpose.
Definition: LoadAscii2.h:42
int version() const override
The version number.
Definition: LoadAscii2.h:48
std::string m_columnSep
The column separator.
Definition: LoadAscii2.h:88
std::unique_ptr< DataObjects::Histogram1D > m_curSpectra
Definition: LoadAscii2.h:107
std::map< std::string, std::string > m_separatorIndex
Map the separator options to their string equivalents.
Definition: LoadAscii2.h:97
std::vector< double > m_curDx
Definition: LoadAscii2.h:108
std::vector< DataObjects::Histogram1D > m_spectra
Definition: LoadAscii2.h:106
const std::string name() const override
The name of the algorithm.
Definition: LoadAscii2.h:40
const std::string category() const override
The category.
Definition: LoadAscii2.h:51
std::vector< double > m_spectrumAxis
Definition: LoadAscii2.h:109
const std::vector< std::string > seeAlso() const override
Function to return all of the seeAlso (these are not validated) algorithms related to this algorithm....
Definition: LoadAscii2.h:49
Defines a wrapper around an open file.
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Definition: Workspace_fwd.h:20
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
Helper class which provides the Collimation Length for SANS instruments.