Mantid
Loading...
Searching...
No Matches
SaveAscii2.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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 +
8#include "MantidAPI/Axis.h"
12#include "MantidAPI/Run.h"
25
26#include <boost/regex.hpp>
27#include <boost/tokenizer.hpp>
28#include <fstream>
29#include <set>
30
31namespace Mantid::DataHandling {
32// Register the algorithm into the algorithm factory
33DECLARE_ALGORITHM(SaveAscii2)
34
35using namespace Kernel;
36using namespace API;
37
40 : m_separatorIndex(), m_nBins(0), m_sep(), m_writeDX(false), m_writeID(false), m_isCommonBins(false),
41 m_writeSpectrumAxisValue(false), m_ws() {}
42
45 declareProperty(std::make_unique<WorkspaceProperty<Workspace>>("InputWorkspace", "", Direction::Input),
46 "The name of the workspace containing the data you want to save to a "
47 "Ascii file.");
48
49 declareProperty(std::make_unique<FileProperty>("Filename", "", FileProperty::Save, m_asciiExts),
50 "The filename of the output Ascii file.");
51
52 auto mustBePositive = std::make_shared<BoundedValidator<int>>();
53 mustBePositive->setLower(1);
54 auto mustBeZeroGreater = std::make_shared<BoundedValidator<int>>();
55 mustBeZeroGreater->setLower(0);
56 declareProperty("WorkspaceIndexMin", EMPTY_INT(), mustBeZeroGreater,
57 "The starting workspace index. Ignored for Table Workspaces.");
58 declareProperty("WorkspaceIndexMax", EMPTY_INT(), mustBeZeroGreater,
59 "The ending workspace index. Ignored for Table Workspaces.");
60 declareProperty(std::make_unique<ArrayProperty<int>>("SpectrumList"),
61 "List of workspace indices to save. Ignored for Table Workspaces.");
62 declareProperty("Precision", EMPTY_INT(), mustBePositive, "Precision of output double values.");
63 declareProperty("ScientificFormat", false,
64 "If true, the values will be "
65 "written to the file in "
66 "scientific notation.");
67 declareProperty("WriteXError", false,
68 "If true, the error on X will be written as the fourth "
69 "column. Ignored for Table Workspaces.");
70 declareProperty("WriteSpectrumID", true,
71 "If false, the spectrum No will not be written for "
72 "single-spectrum workspaces. "
73 "It is always written for workspaces with multiple spectra, "
74 "unless spectrum axis value is written. Ignored for Table Workspaces.");
75
76 declareProperty("CommentIndicator", "#", "Character(s) to put in front of comment lines.");
77
78 // For the ListValidator
79 std::string spacers[6][2] = {{"CSV", ","}, {"Tab", "\t"}, {"Space", " "},
80 {"Colon", ":"}, {"SemiColon", ";"}, {"UserDefined", "UserDefined"}};
81 std::vector<std::string> sepOptions;
82 for (auto &spacer : spacers) {
83 std::string option = spacer[0];
84 m_separatorIndex.insert(std::pair<std::string, std::string>(option, spacer[1]));
85 sepOptions.emplace_back(option);
86 }
87
88 declareProperty("Separator", "CSV", std::make_shared<StringListValidator>(sepOptions),
89 "The separator between data columns in the data file. The "
90 "possible values are \"CSV\", \"Tab\", "
91 "\"Space\", \"SemiColon\", \"Colon\" or \"UserDefined\".");
92
93 declareProperty(std::make_unique<PropertyWithValue<std::string>>("CustomSeparator", "", Direction::Input),
94 "If present, will override any specified choice given to Separator.");
95
96 setPropertySettings("CustomSeparator",
97 std::make_unique<VisibleWhenProperty>("Separator", IS_EQUAL_TO, "UserDefined"));
98 getPointerToProperty("CustomSeparator")->setAutoTrim(false);
99 declareProperty("ColumnHeader", true,
100 "If true, put column headers into file. Even if false, a header"
101 "is automatically added if the workspace is Distribution = true.");
102
103 declareProperty("SpectrumMetaData", "",
104 "A comma separated list that defines data that describes "
105 "each spectrum in a workspace. The valid options for this "
106 "are: SpectrumNumber,Q,Angle. Ignored for Table Workspaces.");
107
108 declareProperty("AppendToFile", false, "If true, don't overwrite the file. Append to the end of it. ");
109
110 declareProperty("RaggedWorkspace", true,
111 "If true, ensure that more than one xspectra is used. "
112 "Ignored for Table Workspaces."); // in testing
113
114 declareProperty("WriteSpectrumAxisValue", false,
115 "Write the spectrum axis value if requested. Ignored for "
116 "Table Workspaces.");
117
118 declareProperty(std::make_unique<ArrayProperty<std::string>>("LogList"),
119 "List of logs to write to the file header. Ignored for Table "
120 "Workspaces.");
121
122 declareProperty("OneSpectrumPerFile", false, "If true, each spectrum will be saved to an individual file");
123}
124
129 // Get the workspace
130 Workspace_const_sptr ws = getProperty("InputWorkspace");
131 m_ws = std::dynamic_pointer_cast<const MatrixWorkspace>(ws);
132 ITableWorkspace_const_sptr tws = std::dynamic_pointer_cast<const ITableWorkspace>(ws);
133 IMDHistoWorkspace_const_sptr mdws = std::dynamic_pointer_cast<const IMDHistoWorkspace>(ws);
134
135 // Get the properties valid for all workspaces
136 const bool writeHeader = getProperty("ColumnHeader");
137 const bool appendToFile = getProperty("AppendToFile");
138 std::string filename = getProperty("Filename");
139 int prec = getProperty("Precision");
140 bool scientific = getProperty("ScientificFormat");
141 std::string comment = getPropertyValue("CommentIndicator");
142
143 const std::string choice = getPropertyValue("Separator");
144 const std::string custom = getPropertyValue("CustomSeparator");
145 // If the custom separator property is not empty, then we use that under
146 // any circumstance.
147 if (!custom.empty()) {
148 m_sep = custom;
149 }
150 // Else if the separator drop down choice is not UserDefined then we use
151 // that.
152 else if (choice != "UserDefined") {
153 auto it = m_separatorIndex.find(choice);
154 m_sep = it->second;
155 }
156 // If we still have nothing, then we are forced to use a default.
157 if (m_sep.empty()) {
158 g_log.notice() << "\"UserDefined\" has been selected, but no custom "
159 "separator has been entered."
160 " Using default instead.";
161 m_sep = ",";
162 }
163
164 // handle table and 1 histo cuts workspaces
165 if (tws) {
166 return writeTableWorkspace(tws, filename, appendToFile, writeHeader, prec, scientific, comment);
167 } else if (mdws) {
168 return write1DHistoCut(mdws, filename, appendToFile, writeHeader, prec, scientific, comment);
169 }
170
171 if (!m_ws) {
172 throw std::runtime_error("SaveAscii does not know how to save this workspace type, " + ws->getName());
173 }
174
175 // Get the properties valid for matrix workspaces
176 std::vector<int> spec_list = getProperty("SpectrumList");
177 const int spec_min = getProperty("WorkspaceIndexMin");
178 const int spec_max = getProperty("WorkspaceIndexMax");
179 m_writeSpectrumAxisValue = getProperty("WriteSpectrumAxisValue");
180 m_writeDX = getProperty("WriteXError");
181
182 m_writeID = getProperty("WriteSpectrumID");
183 std::string metaDataString = getPropertyValue("SpectrumMetaData");
184 if (!metaDataString.empty()) {
185 m_metaData = stringListToVector(metaDataString);
186 auto containsSpectrumNumber = findElementInUnorderedStringVector(m_metaData, "spectrumnumber");
187 if (containsSpectrumNumber) {
188 try {
189 m_ws->getSpectrumToWorkspaceIndexMap();
190 } catch (const std::runtime_error &) {
191 throw std::runtime_error("SpectrumNumber is present in "
192 "SpectrumMetaData but the workspace does not "
193 "have a SpectrumAxis.");
194 }
195 }
196 }
197 if (m_writeID) {
198 auto containsSpectrumNumber = findElementInUnorderedStringVector(m_metaData, "spectrumnumber");
199 if (!containsSpectrumNumber) {
200 auto firstIter = m_metaData.begin();
201 m_metaData.insert(firstIter, "spectrumnumber");
202 }
203 }
204
206 auto spectrumAxis = m_ws->getAxis(1);
207 if (dynamic_cast<BinEdgeAxis *>(spectrumAxis)) {
208 m_axisProxy = std::make_unique<AxisHelper::BinEdgeAxisProxy>(spectrumAxis);
209 } else {
210 m_axisProxy = std::make_unique<AxisHelper::AxisProxy>(spectrumAxis);
211 }
212 }
213
214 // e + and - are included as they're part of the scientific notation
215 if (!boost::regex_match(m_sep.begin(), m_sep.end(), boost::regex("[^0-9e+-]+", boost::regex::perl))) {
216 throw std::invalid_argument("Separators cannot contain numeric characters, "
217 "plus signs, hyphens or 'e'");
218 }
219
220 if (comment.at(0) == m_sep.at(0) ||
221 !boost::regex_match(comment.begin(), comment.end(),
222 boost::regex("[^0-9e" + m_sep + "+-]+", boost::regex::perl))) {
223 throw std::invalid_argument("Comment markers cannot contain numeric "
224 "characters, plus signs, hyphens,"
225 " 'e' or the selected separator character");
226 }
227
228 // Create an spectra index list for output
229 std::set<int> idx;
230
231 auto nSpectra = static_cast<int>(m_ws->getNumberHistograms());
232 m_nBins = static_cast<int>(m_ws->blocksize());
233 m_isCommonBins = m_ws->isCommonBins(); // checking for ragged workspace
234
235 // Add spectra interval into the index list
236 if (spec_max != EMPTY_INT() && spec_min != EMPTY_INT()) {
237 if (spec_min >= nSpectra || spec_max >= nSpectra || spec_min < 0 || spec_max < 0 || spec_min > spec_max) {
238 throw std::invalid_argument("Inconsistent spectra interval");
239 }
240 for (int i = spec_min; i <= spec_max; i++) {
241 idx.insert(i);
242 }
243 }
244 // figure out how to read in readX and have them be seperate lists
245
246 // Add spectra list into the index list
247 if (!spec_list.empty()) {
248 for (auto &spec : spec_list) {
249 if (spec >= nSpectra) {
250 throw std::invalid_argument("Inconsistent spectra list");
251 } else {
252 idx.insert(spec);
253 }
254 }
255 }
256
257 // if no interval or spectra list, take all of them
258 if (idx.empty()) {
259 for (int i = 0; i < nSpectra; i++) {
260 idx.insert(i);
261 }
262 }
263
264 if (m_nBins == 0 || nSpectra == 0) {
265 throw std::runtime_error("Trying to save an empty workspace");
266 }
267
268 const bool oneSpectrumPerFile = getProperty("OneSpectrumPerFile");
269
270 Progress progress(this, 0.0, 1.0, idx.size());
271
272 // populate the meta data map
273 if (!m_metaData.empty()) {
275 }
276
277 const bool isDistribution = m_ws->isDistribution();
278 auto idxIt = idx.begin();
279 while (idxIt != idx.end()) {
280 std::string currentFilename;
281 if (oneSpectrumPerFile)
282 currentFilename = createSpectrumFilename(*idxIt);
283 else
284 currentFilename = filename;
285
286 std::ofstream file(currentFilename, (appendToFile ? std::ios::app : std::ios::out));
287
288 if (file.bad()) {
289 throw Exception::FileError("Unable to create file: ", currentFilename);
290 }
291 // Set the number precision
292 if (prec != EMPTY_INT()) {
293 file.precision(prec);
294 }
295 if (scientific) {
296 file << std::scientific;
297 }
298 const std::vector<std::string> logList = getProperty("LogList");
299 if (!logList.empty()) {
300 writeFileHeader(logList, file);
301 }
302 if (writeHeader || isDistribution) {
303 file << comment << " X " << m_sep << " Y " << m_sep << " E";
304 if (m_writeDX) {
305 file << " " << m_sep << " DX";
306 }
307 file << " Distribution=" << (isDistribution ? "true" : "false");
308 file << '\n';
309 }
310
311 // data writing
312 if (oneSpectrumPerFile) {
313 writeSpectrum(*idxIt, file);
314 progress.report();
315 idxIt++;
316 } else {
317 while (idxIt != idx.end()) {
318 writeSpectrum(*idxIt, file);
319 progress.report();
320 idxIt++;
321 }
322 }
323
324 file.unsetf(std::ios_base::floatfield);
325 file.close();
326 }
327}
328
335std::string SaveAscii2::createSpectrumFilename(size_t workspaceIndex) {
336 std::string filename = getProperty("Filename");
337 size_t extPosition{std::string::npos};
338 for (const std::string &ext : m_asciiExts) {
339 extPosition = filename.find(ext);
340 if (extPosition != std::string::npos)
341 break;
342 }
343 if (extPosition == std::string::npos)
344 extPosition = filename.size();
345
346 std::ostringstream ss;
347 ss << std::string(filename, 0, extPosition) << "_" << workspaceIndex;
348 auto axis = m_ws->getAxis(1);
349 if (axis->isNumeric()) {
350 auto binEdgeAxis = dynamic_cast<BinEdgeAxis *>(axis);
351 if (binEdgeAxis)
352 ss << "_" << binEdgeAxis->label(workspaceIndex) << axis->unit()->label().ascii();
353 else
354 ss << "_" << axis->getValue(workspaceIndex) << axis->unit()->label().ascii();
355 } else if (axis->isText())
356 ss << "_" << axis->label(workspaceIndex);
357 ss << std::string(filename, extPosition);
358
359 return ss.str();
360}
361
367void SaveAscii2::writeSpectrum(const int &wsIndex, std::ofstream &file) {
368
370 file << m_axisProxy->getCentre(wsIndex) << '\n';
371 } else {
372 for (auto iter = m_metaData.begin(); iter != m_metaData.end(); ++iter) {
373 auto value = m_metaDataMap[*iter][wsIndex];
374 file << value;
375 if (iter != m_metaData.end() - 1) {
376 file << " " << m_sep << " ";
377 }
378 }
379 file << '\n';
380 }
381 auto pointDeltas = m_ws->pointStandardDeviations(0);
382 auto points0 = m_ws->points(0);
383 auto pointsSpec = m_ws->points(wsIndex);
384 bool hasDx = m_ws->hasDx(0);
385 for (int bin = 0; bin < m_nBins; bin++) {
386 if (m_isCommonBins) {
387 file << points0[bin];
388 } else // checking for ragged workspace
389 {
390 file << pointsSpec[bin];
391 }
392 file << m_sep;
393 file << m_ws->y(wsIndex)[bin];
394
395 file << m_sep;
396 file << m_ws->e(wsIndex)[bin];
397 if (m_writeDX) {
398 if (hasDx) {
399 file << m_sep;
400 file << pointDeltas[bin];
401 } else {
402 g_log.information("SaveAscii2: WriteXError is requested but there are no Dx data in the workspace");
403 }
404 }
405 file << '\n';
406 }
407}
408
415std::vector<std::string> SaveAscii2::stringListToVector(std::string &inputString) {
416 const std::vector<std::string> validMetaData{"spectrumnumber", "q", "angle"};
417 boost::to_lower(inputString);
418 auto stringVector = Kernel::VectorHelper::splitStringIntoVector<std::string>(inputString);
419 const auto it = std::find_if(stringVector.cbegin(), stringVector.cend(), [&validMetaData](const auto &input) {
420 return std::find(validMetaData.begin(), validMetaData.end(), input) == validMetaData.end();
421 });
422 if (it != stringVector.cend()) {
423 throw std::runtime_error(*it + " is not recognised as a possible input "
424 "for SpectrumMetaData.\n Valid inputs "
425 "are: SpectrumNumber, Q, Angle.");
426 }
427
428 return stringVector;
429}
430
436 std::vector<std::string> qValues;
437 const auto nHist = m_ws->getNumberHistograms();
438 const auto &spectrumInfo = m_ws->spectrumInfo();
439 for (size_t i = 0; i < nHist; i++) {
440 double theta(0.0), efixed(0.0);
441 if (!spectrumInfo.isMonitor(i)) {
442 theta = 0.5 * spectrumInfo.twoTheta(i);
443 try {
444 std::shared_ptr<const Geometry::IDetector> detector(&spectrumInfo.detector(i), NoDeleting());
445 efixed = m_ws->getEFixed(detector);
446 } catch (std::runtime_error &) {
447 throw;
448 }
449 } else {
450 theta = 0.0;
451 efixed = DBL_MIN;
452 }
453 // Convert to MomentumTransfer
455 auto qValueStr = boost::lexical_cast<std::string>(qValue);
456 qValues.emplace_back(qValueStr);
457 }
458 m_metaDataMap["q"] = qValues;
459}
460
465 std::vector<std::string> spectrumNumbers;
466 const size_t nHist = m_ws->getNumberHistograms();
467 for (size_t i = 0; i < nHist; i++) {
468 const auto specNum = m_ws->getSpectrum(i).getSpectrumNo();
469 const auto specNumStr = std::to_string(specNum);
470 spectrumNumbers.emplace_back(specNumStr);
471 }
472 m_metaDataMap["spectrumnumber"] = spectrumNumbers;
473}
474
479 std::vector<std::string> angles;
480 const size_t nHist = m_ws->getNumberHistograms();
481 const auto &spectrumInfo = m_ws->spectrumInfo();
482 for (size_t i = 0; i < nHist; i++) {
483 const auto two_theta = spectrumInfo.twoTheta(i);
484 constexpr double rad2deg = 180. / M_PI;
485 const auto angleInDeg = two_theta * rad2deg;
486 const auto angleInDegStr = boost::lexical_cast<std::string>(angleInDeg);
487 angles.emplace_back(angleInDegStr);
488 }
489 m_metaDataMap["angle"] = angles;
490}
491
496 for (const auto &metaDataType : m_metaData) {
497 if (metaDataType == "spectrumnumber")
499 if (metaDataType == "q")
501 if (metaDataType == "angle")
503 }
504}
505
506bool SaveAscii2::findElementInUnorderedStringVector(const std::vector<std::string> &vector, const std::string &toFind) {
507 return std::find(vector.cbegin(), vector.cend(), toFind) != vector.cend();
508}
509
510void SaveAscii2::writeTableWorkspace(const ITableWorkspace_const_sptr &tws, const std::string &filename,
511 bool appendToFile, bool writeHeader, int prec, bool scientific,
512 const std::string &comment) {
513
514 std::ofstream file(filename.c_str(), (appendToFile ? std::ios::app : std::ios::out));
515
516 if (file.bad()) {
517 throw Exception::FileError("Unable to create file: ", filename);
518 }
519 // Set the number precision
520 if (prec != EMPTY_INT()) {
521 file.precision(prec);
522 }
523 if (scientific) {
524 file << std::scientific;
525 }
526
527 const auto columnCount = tws->columnCount();
528 if (writeHeader) {
529 // write the column names
530 file << comment << " ";
531 for (size_t colIndex = 0; colIndex < columnCount; colIndex++) {
532 file << tws->getColumn(colIndex)->name() << " ";
533 if (colIndex < columnCount - 1) {
534 file << m_sep << " ";
535 }
536 }
537 file << '\n';
538 // write the column types
539 file << comment << " ";
540 for (size_t colIndex = 0; colIndex < columnCount; colIndex++) {
541 file << tws->getColumn(colIndex)->type() << " ";
542 if (colIndex < columnCount - 1) {
543 file << m_sep << " ";
544 }
545 }
546 file << '\n';
547 } else {
548 g_log.warning("Please note that files written without headers cannot be "
549 "reloaded back into Mantid with LoadAscii.");
550 }
551
552 // write the data
553 const auto rowCount = tws->rowCount();
554 Progress progress(this, 0.0, 1.0, rowCount);
555 for (size_t rowIndex = 0; rowIndex < rowCount; rowIndex++) {
556 for (size_t colIndex = 0; colIndex < columnCount; colIndex++) {
557 tws->getColumn(colIndex)->print(rowIndex, file);
558 if (colIndex < columnCount - 1) {
559 file << m_sep;
560 }
561 }
562 file << "\n";
563 progress.report();
564 }
565
566 file.unsetf(std::ios_base::floatfield);
567 file.close();
568}
569
576std::pair<std::string, std::string> SaveAscii2::sampleLogValueUnit(const std::string &logName) {
577 auto run = m_ws->run();
578 // Gets the sample log value
579 std::string sampleLogValue = "";
580 try {
581 sampleLogValue = boost::lexical_cast<std::string>(run.getLogData(logName)->value());
582 } catch (Exception::NotFoundError &) {
583 g_log.warning("Log " + logName + " not found.");
584 sampleLogValue = "Not defined";
585 }
586 // Gets the sample log unit
587 std::string sampleLogUnit = "";
588 try {
589 sampleLogUnit = boost::lexical_cast<std::string>(run.getLogData(logName)->units());
590 } catch (Exception::NotFoundError &) {
591 sampleLogUnit = "";
592 }
593 return std::pair(sampleLogValue, sampleLogUnit);
594}
595
602void SaveAscii2::writeFileHeader(const std::vector<std::string> &logList, std::ofstream &outputFile) {
603 for (const auto &logName : logList) {
604 const std::pair<std::string, std::string> readLog = sampleLogValueUnit(logName);
605 auto logValue = boost::replace_all_copy(readLog.second, ",", ";");
606 outputFile << logName << m_sep << readLog.first << m_sep << logValue << '\n';
607 }
608 outputFile << '\n';
609}
610
611void SaveAscii2::write1DHistoCut(const IMDHistoWorkspace_const_sptr &mdws, const std::string &filename,
612 bool appendToFile, bool writeHeader, int prec, bool scientific,
613 const std::string &comment) {
614 auto dims = mdws->getNonIntegratedDimensions();
615 if (dims.size() != 1) {
616 throw std::runtime_error("SaveAscii does not support saving multidimentional MDHistoWorkspace, and only supports "
617 "1D MDHistoWorkspaces cuts");
618 }
619
620 std::ofstream file(filename.c_str(), (appendToFile ? std::ios::app : std::ios::out));
621
622 if (file.bad()) {
623 throw Exception::FileError("Unable to create file: ", filename);
624 }
625
626 if (prec != EMPTY_INT()) {
627 file.precision(prec);
628 }
629
630 if (scientific) {
631 file << std::scientific;
632 }
633
634 auto lastAlg = mdws->getHistory().lastAlgorithm();
635 auto &propsVec = lastAlg->getProperties();
636
638
639 if (writeHeader) {
640 // write last algorithm arguments
641 file << comment << " {";
642 for (size_t i = 0; i < propsVec.size(); i++) {
643 file << propsVec[i]->name() << ": " << propsVec[i]->valueAsPrettyStr();
644 if (i < propsVec.size() - 1)
645 file << m_sep << " ";
646 }
647 file << " }\n";
648
649 // write columns labels
650 auto dimName = dim->getName();
651 auto dimUnit = dim->getUnits().latex();
652
653 file << comment << " " << dimName << " " << dimUnit << m_sep << " "
654 << "Signal" << m_sep << " "
655 << "Error"
656 << "\n";
657 }
658
659 auto nbins = dim->getNBins();
660 auto binWidth = dim->getBinWidth() / 2;
661 auto binMax = dim->getMaximum();
662 auto binMin = dim->getMinimum();
663
664 auto start = binMin + binWidth;
665 auto end = binMax - binWidth;
666 auto step = (end - start) / float(nbins - 1);
667
668 auto nPoints = mdws->getNPoints();
669 auto signal = mdws->getSignalArray();
670 auto error = mdws->getErrorSquaredArray();
671
672 Progress progress(this, 0.0, 1.0, nbins);
673
674 // write data
675 for (size_t i = 0; i < nPoints; ++i) {
676 file << start + step * float(i) << m_sep << signal[i] << m_sep << std::sqrt(error[i]) << "\n";
677 progress.report();
678 }
679
680 file.unsetf(std::ios_base::floatfield);
681 file.close();
682
683 return;
684}
685} // namespace Mantid::DataHandling
#define DECLARE_ALGORITHM(classname)
Definition Algorithm.h:538
static char constexpr m_sep
double value
The value of the point.
Definition FitMW.cpp:51
double error
int64_t nSpectra
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Kernel::Property * getPointerToProperty(const std::string &name) const override
Get a property by name.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Kernel::Logger & g_log
Definition Algorithm.h:422
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
Stores numeric values that are assumed to be bin edge values.
Definition BinEdgeAxis.h:20
std::string label(const std::size_t &index) const override
Returns a text label which shows the value at the given bin index.
@ Save
to specify a file to write to, the file may or may not exist
Helper class for reporting progress from algorithms.
Definition Progress.h:25
A property class for workspaces.
bool findElementInUnorderedStringVector(const std::vector< std::string > &vector, const std::string &toFind)
API::MatrixWorkspace_const_sptr m_ws
Definition SaveAscii2.h:93
void populateAngleMetaData()
Populate the map with the Angle for each spectrum in the workspace.
void populateSpectrumNumberMetaData()
Populate the map with the SpectrumNumber for each Spectrum in the workspace.
void writeSpectrum(const int &wsIndex, std::ofstream &file)
Writes a spectrum to the file using a workspace index.
std::map< std::string, std::vector< std::string > > m_metaDataMap
Definition SaveAscii2.h:95
void writeTableWorkspace(const API::ITableWorkspace_const_sptr &tws, const std::string &filename, bool appendToFile, bool writeHeader, int prec, bool scientific, const std::string &comment)
void writeFileHeader(const std::vector< std::string > &logList, std::ofstream &file)
Write file header.
std::pair< std::string, std::string > sampleLogValueUnit(const std::string &logName)
Retrieve sample log value and its unit.
std::vector< std::string > stringListToVector(std::string &inputString)
Converts a comma separated list to a vector of strings Also ensures all strings are valid input.
SaveAscii2()
Default constructor.
void write1DHistoCut(const API::IMDHistoWorkspace_const_sptr &mdws, const std::string &filename, bool appendToFile, bool writeHeader, int prec, bool scientific, const std::string &comment)
void populateAllMetaData()
Populate all required meta data in the meta data map.
const std::vector< std::string > m_asciiExts
Definition SaveAscii2.h:97
void exec() override
Overwrites Algorithm method.
std::vector< std::string > m_metaData
Definition SaveAscii2.h:94
std::string createSpectrumFilename(size_t workspaceIndex)
Create the filename used for the export of a specific spectrum.
void init() override
Overwrites Algorithm method.
std::map< std::string, std::string > m_separatorIndex
Map the separator options to their string equivalents.
Definition SaveAscii2.h:85
void populateQMetaData()
Populate the map with the Q values associated with each spectrum in the workspace.
std::unique_ptr< AxisHelper::AxisProxy > m_axisProxy
Definition SaveAscii2.h:96
Void deleter for shared pointers.
Support for a property that holds an array of values.
Records the filename and the description of failure.
Definition Exception.h:98
Exception for when an item is not found in a collection.
Definition Exception.h:145
void setPropertySettings(const std::string &name, std::unique_ptr< IPropertySettings > settings)
void notice(const std::string &msg)
Logs at notice level.
Definition Logger.cpp:126
void warning(const std::string &msg)
Logs at warning level.
Definition Logger.cpp:117
void information(const std::string &msg)
Logs at information level.
Definition Logger.cpp:136
The concrete, templated class for properties.
void setAutoTrim(const bool &setting)
Sets if the property is set to automatically trim string unput values of whitespace.
Definition Property.cpp:362
static double convertToElasticQ(const double theta, const double efixed)
Convert to ElasticQ from Energy.
std::shared_ptr< const ITableWorkspace > ITableWorkspace_const_sptr
shared pointer to Mantid::API::ITableWorkspace (const version)
std::shared_ptr< const Workspace > Workspace_const_sptr
shared pointer to Mantid::API::Workspace (const version)
std::shared_ptr< const IMDHistoWorkspace > IMDHistoWorkspace_const_sptr
shared pointer to Mantid::API::IMDHistoWorkspace (const version)
std::shared_ptr< const IMDDimension > IMDDimension_const_sptr
Shared Pointer to const IMDDimension.
template DLLExport std::vector< std::string > splitStringIntoVector< std::string >(std::string listString, const std::string &separator)
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
Definition EmptyValues.h:24
std::string to_string(const wide_integer< Bits, Signed > &n)
@ Input
An input workspace.
Definition Property.h:53