Mantid
Loading...
Searching...
No Matches
SaveAscii2.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
9//----------------------------------------------------------------------
10// Includes
11//----------------------------------------------------------------------
12#include "MantidAPI/Algorithm.h"
13#include "MantidAPI/Axis.h"
16#include "MantidDataHandling/DllConfig.h"
17
18namespace Mantid {
19namespace DataHandling {
26namespace AxisHelper {
27
28struct AxisProxy {
30 virtual double getCentre(const int index) { return a->getValue(index); }
31 virtual ~AxisProxy() = default;
32
33protected:
35};
36
39 double getCentre(const int index) override { return (a->getValue(index) + a->getValue(index + 1)) / 2.; }
40};
41
42} // namespace AxisHelper
43
44class MANTID_DATAHANDLING_DLL SaveAscii2 final : public API::Algorithm {
45public:
47 SaveAscii2();
49 const std::string name() const override { return "SaveAscii"; }
51 const std::string summary() const override { return "Saves a 2D workspace to a ascii file."; }
53 int version() const override { return 2; }
54 const std::vector<std::string> seeAlso() const override {
55 return {"LoadAscii", "SaveCSV", "SaveDiffFittingAscii", "SaveReflectometryAscii",
56 "SaveOpenGenieAscii", "SaveGSS", "SaveFocusedXYE"};
57 }
59 const std::string category() const override { return "DataHandling\\Text"; }
60
61private:
63 void init() override;
65 void exec() override;
66 void writeTableWorkspace(const API::ITableWorkspace_const_sptr &tws, const std::string &filename, bool appendToFile,
67 bool writeHeader, int prec, bool scientific, const std::string &comment);
69 void writeSpectrum(const int &wsIndex, std::ofstream &file);
70 std::vector<std::string> stringListToVector(std::string &inputString);
71 void populateQMetaData();
72 void populateSpectrumNumberMetaData();
73 void populateAngleMetaData();
74 void populateAllMetaData();
75 bool findElementInUnorderedStringVector(const std::vector<std::string> &vector, const std::string &toFind);
77 std::pair<std::string, std::string> sampleLogValueUnit(const std::string &logName);
79 void writeFileHeader(const std::vector<std::string> &logList, std::ofstream &file);
80 std::string createSpectrumFilename(size_t workspaceIndex);
81
83 std::map<std::string, std::string> m_separatorIndex;
84
86 std::string m_sep;
92 std::vector<std::string> m_metaData;
93 std::map<std::string, std::vector<std::string>> m_metaDataMap;
94 std::unique_ptr<AxisHelper::AxisProxy> m_axisProxy;
95 const std::vector<std::string> m_asciiExts = {".dat", ".txt", ".csv"};
96};
97} // namespace DataHandling
98} // namespace Mantid
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:85
Class to represent the axis of a workspace.
Definition: Axis.h:30
double getValue(const std::size_t &index, const std::size_t &verticalIndex=0) const
Gets the value at the specified index.
Definition: Axis.cpp:51
Saves a workspace or selected spectra in a coma-separated ascii file.
Definition: SaveAscii2.h:44
const std::string name() const override
Algorithm's name for identification overriding a virtual method.
Definition: SaveAscii2.h:49
API::MatrixWorkspace_const_sptr m_ws
Definition: SaveAscii2.h:91
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: SaveAscii2.h:54
std::map< std::string, std::vector< std::string > > m_metaDataMap
Definition: SaveAscii2.h:93
std::vector< std::string > m_metaData
Definition: SaveAscii2.h:92
int version() const override
Algorithm's version for identification overriding a virtual method.
Definition: SaveAscii2.h:53
const std::string category() const override
Algorithm's category for identification overriding a virtual method.
Definition: SaveAscii2.h:59
std::map< std::string, std::string > m_separatorIndex
Map the separator options to their string equivalents.
Definition: SaveAscii2.h:83
std::unique_ptr< AxisHelper::AxisProxy > m_axisProxy
Definition: SaveAscii2.h:94
const std::string summary() const override
Summary of algorithms purpose.
Definition: SaveAscii2.h:51
std::shared_ptr< const ITableWorkspace > ITableWorkspace_const_sptr
shared pointer to Mantid::API::ITableWorkspace (const version)
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
Helper class which provides the Collimation Length for SANS instruments.
virtual double getCentre(const int index)
Definition: SaveAscii2.h:30
double getCentre(const int index) override
Definition: SaveAscii2.h:39