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"
17#include "MantidDataHandling/DllConfig.h"
18
19namespace Mantid {
20namespace DataHandling {
27namespace AxisHelper {
28
29struct AxisProxy {
31 virtual double getCentre(const int index) { return a->getValue(index); }
32 virtual ~AxisProxy() = default;
33
34protected:
36};
37
40 double getCentre(const int index) override { return (a->getValue(index) + a->getValue(index + 1)) / 2.; }
41};
42
43} // namespace AxisHelper
44
45class MANTID_DATAHANDLING_DLL SaveAscii2 final : public API::Algorithm {
46public:
48 SaveAscii2();
50 const std::string name() const override { return "SaveAscii"; }
52 const std::string summary() const override { return "Saves a 2D workspace to a ascii file."; }
54 int version() const override { return 2; }
55 const std::vector<std::string> seeAlso() const override {
56 return {"LoadAscii", "SaveCSV", "SaveReflectometryAscii", "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);
68 void write1DHistoCut(const API::IMDHistoWorkspace_const_sptr &mdws, const std::string &filename, bool appendToFile,
69 bool writeHeader, int prec, bool scientific, const std::string &comment);
71 void writeSpectrum(const int &wsIndex, std::ofstream &file);
72 std::vector<std::string> stringListToVector(std::string &inputString);
73 void populateQMetaData();
74 void populateSpectrumNumberMetaData();
75 void populateAngleMetaData();
76 void populateAllMetaData();
77 bool findElementInUnorderedStringVector(const std::vector<std::string> &vector, const std::string &toFind);
79 std::pair<std::string, std::string> sampleLogValueUnit(const std::string &logName);
81 void writeFileHeader(const std::vector<std::string> &logList, std::ofstream &file);
82 std::string createSpectrumFilename(size_t workspaceIndex);
83
85 std::map<std::string, std::string> m_separatorIndex;
86
88 std::string m_sep;
94 std::vector<std::string> m_metaData;
95 std::map<std::string, std::vector<std::string>> m_metaDataMap;
96 std::unique_ptr<AxisHelper::AxisProxy> m_axisProxy;
97 const std::vector<std::string> m_asciiExts = {".dat", ".txt", ".csv"};
98};
99} // namespace DataHandling
100} // namespace Mantid
std::map< DeltaEMode::Type, std::string > index
Base class from which all concrete algorithm classes should be derived.
Definition Algorithm.h:76
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:45
const std::string name() const override
Algorithm's name for identification overriding a virtual method.
Definition SaveAscii2.h:50
API::MatrixWorkspace_const_sptr m_ws
Definition SaveAscii2.h:93
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:55
std::map< std::string, std::vector< std::string > > m_metaDataMap
Definition SaveAscii2.h:95
std::vector< std::string > m_metaData
Definition SaveAscii2.h:94
int version() const override
Algorithm's version for identification overriding a virtual method.
Definition SaveAscii2.h:54
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:85
std::unique_ptr< AxisHelper::AxisProxy > m_axisProxy
Definition SaveAscii2.h:96
const std::string summary() const override
Summary of algorithms purpose.
Definition SaveAscii2.h:52
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)
std::shared_ptr< const IMDHistoWorkspace > IMDHistoWorkspace_const_sptr
shared pointer to Mantid::API::IMDHistoWorkspace (const version)
Helper class which provides the Collimation Length for SANS instruments.
virtual double getCentre(const int index)
Definition SaveAscii2.h:31
double getCentre(const int index) override
Definition SaveAscii2.h:40