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 efixed = m_ws->getEFixed(spectrumInfo.firstDetectorID(i));
445 } catch (std::runtime_error &) {
446 throw;
447 }
448 } else {
449 theta = 0.0;
450 efixed = DBL_MIN;
451 }
452 // Convert to MomentumTransfer
454 auto qValueStr = boost::lexical_cast<std::string>(qValue);
455 qValues.emplace_back(qValueStr);
456 }
457 m_metaDataMap["q"] = qValues;
458}
459
464 std::vector<std::string> spectrumNumbers;
465 const size_t nHist = m_ws->getNumberHistograms();
466 for (size_t i = 0; i < nHist; i++) {
467 const auto specNum = m_ws->getSpectrum(i).getSpectrumNo();
468 const auto specNumStr = std::to_string(specNum);
469 spectrumNumbers.emplace_back(specNumStr);
470 }
471 m_metaDataMap["spectrumnumber"] = spectrumNumbers;
472}
473
478 std::vector<std::string> angles;
479 const size_t nHist = m_ws->getNumberHistograms();
480 const auto &spectrumInfo = m_ws->spectrumInfo();
481 for (size_t i = 0; i < nHist; i++) {
482 const auto two_theta = spectrumInfo.twoTheta(i);
483 constexpr double rad2deg = 180. / M_PI;
484 const auto angleInDeg = two_theta * rad2deg;
485 const auto angleInDegStr = boost::lexical_cast<std::string>(angleInDeg);
486 angles.emplace_back(angleInDegStr);
487 }
488 m_metaDataMap["angle"] = angles;
489}
490
495 for (const auto &metaDataType : m_metaData) {
496 if (metaDataType == "spectrumnumber")
498 if (metaDataType == "q")
500 if (metaDataType == "angle")
502 }
503}
504
505bool SaveAscii2::findElementInUnorderedStringVector(const std::vector<std::string> &vector, const std::string &toFind) {
506 return std::find(vector.cbegin(), vector.cend(), toFind) != vector.cend();
507}
508
509void SaveAscii2::writeTableWorkspace(const ITableWorkspace_const_sptr &tws, const std::string &filename,
510 bool appendToFile, bool writeHeader, int prec, bool scientific,
511 const std::string &comment) {
512
513 std::ofstream file(filename.c_str(), (appendToFile ? std::ios::app : std::ios::out));
514
515 if (file.bad()) {
516 throw Exception::FileError("Unable to create file: ", filename);
517 }
518 // Set the number precision
519 if (prec != EMPTY_INT()) {
520 file.precision(prec);
521 }
522 if (scientific) {
523 file << std::scientific;
524 }
525
526 const auto columnCount = tws->columnCount();
527 if (writeHeader) {
528 // write the column names
529 file << comment << " ";
530 for (size_t colIndex = 0; colIndex < columnCount; colIndex++) {
531 file << tws->getColumn(colIndex)->name() << " ";
532 if (colIndex < columnCount - 1) {
533 file << m_sep << " ";
534 }
535 }
536 file << '\n';
537 // write the column types
538 file << comment << " ";
539 for (size_t colIndex = 0; colIndex < columnCount; colIndex++) {
540 file << tws->getColumn(colIndex)->type() << " ";
541 if (colIndex < columnCount - 1) {
542 file << m_sep << " ";
543 }
544 }
545 file << '\n';
546 } else {
547 g_log.warning("Please note that files written without headers cannot be "
548 "reloaded back into Mantid with LoadAscii.");
549 }
550
551 // write the data
552 const auto rowCount = tws->rowCount();
553 Progress progress(this, 0.0, 1.0, rowCount);
554 for (size_t rowIndex = 0; rowIndex < rowCount; rowIndex++) {
555 for (size_t colIndex = 0; colIndex < columnCount; colIndex++) {
556 tws->getColumn(colIndex)->print(rowIndex, file);
557 if (colIndex < columnCount - 1) {
558 file << m_sep;
559 }
560 }
561 file << "\n";
562 progress.report();
563 }
564
565 file.unsetf(std::ios_base::floatfield);
566 file.close();
567}
568
575std::pair<std::string, std::string> SaveAscii2::sampleLogValueUnit(const std::string &logName) {
576 auto run = m_ws->run();
577 // Gets the sample log value
578 std::string sampleLogValue = "";
579 try {
580 sampleLogValue = boost::lexical_cast<std::string>(run.getLogData(logName)->value());
581 } catch (Exception::NotFoundError &) {
582 g_log.warning("Log " + logName + " not found.");
583 sampleLogValue = "Not defined";
584 }
585 // Gets the sample log unit
586 std::string sampleLogUnit = "";
587 try {
588 sampleLogUnit = boost::lexical_cast<std::string>(run.getLogData(logName)->units());
589 } catch (Exception::NotFoundError &) {
590 sampleLogUnit = "";
591 }
592 return std::pair(sampleLogValue, sampleLogUnit);
593}
594
601void SaveAscii2::writeFileHeader(const std::vector<std::string> &logList, std::ofstream &outputFile) {
602 for (const auto &logName : logList) {
603 const std::pair<std::string, std::string> readLog = sampleLogValueUnit(logName);
604 auto logValue = boost::replace_all_copy(readLog.second, ",", ";");
605 outputFile << logName << m_sep << readLog.first << m_sep << logValue << '\n';
606 }
607 outputFile << '\n';
608}
609
610void SaveAscii2::write1DHistoCut(const IMDHistoWorkspace_const_sptr &mdws, const std::string &filename,
611 bool appendToFile, bool writeHeader, int prec, bool scientific,
612 const std::string &comment) {
613 auto dims = mdws->getNonIntegratedDimensions();
614 if (dims.size() != 1) {
615 throw std::runtime_error("SaveAscii does not support saving multidimentional MDHistoWorkspace, and only supports "
616 "1D MDHistoWorkspaces cuts");
617 }
618
619 std::ofstream file(filename.c_str(), (appendToFile ? std::ios::app : std::ios::out));
620
621 if (file.bad()) {
622 throw Exception::FileError("Unable to create file: ", filename);
623 }
624
625 if (prec != EMPTY_INT()) {
626 file.precision(prec);
627 }
628
629 if (scientific) {
630 file << std::scientific;
631 }
632
633 auto lastAlg = mdws->getHistory().lastAlgorithm();
634 auto &propsVec = lastAlg->getProperties();
635
637
638 if (writeHeader) {
639 // write last algorithm arguments
640 file << comment << " {";
641 for (size_t i = 0; i < propsVec.size(); i++) {
642 file << propsVec[i]->name() << ": " << propsVec[i]->valueAsPrettyStr();
643 if (i < propsVec.size() - 1)
644 file << m_sep << " ";
645 }
646 file << " }\n";
647
648 // write columns labels
649 auto dimName = dim->getName();
650 auto dimUnit = dim->getUnits().latex();
651
652 file << comment << " " << dimName << " " << dimUnit << m_sep << " "
653 << "Signal" << m_sep << " "
654 << "Error"
655 << "\n";
656 }
657
658 auto nbins = dim->getNBins();
659 auto binWidth = dim->getBinWidth() / 2;
660 auto binMax = dim->getMaximum();
661 auto binMin = dim->getMinimum();
662
663 auto start = binMin + binWidth;
664 auto end = binMax - binWidth;
665 auto step = (end - start) / float(nbins - 1);
666
667 auto nPoints = mdws->getNPoints();
668 auto signal = mdws->getSignalArray();
669 auto error = mdws->getErrorSquaredArray();
670
671 Progress progress(this, 0.0, 1.0, nbins);
672
673 // write data
674 for (size_t i = 0; i < nPoints; ++i) {
675 file << start + step * float(i) << m_sep << signal[i] << m_sep << std::sqrt(error[i]) << "\n";
676 progress.report();
677 }
678
679 file.unsetf(std::ios_base::floatfield);
680 file.close();
681
682 return;
683}
684} // namespace Mantid::DataHandling
#define DECLARE_ALGORITHM(classname)
Definition Algorithm.h:547
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:426
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
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 const > settings)
Add a PropertySettings instance to the chain of settings for a given property.
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:364
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 MANTID_KERNEL_DLL 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:54