SaveReflCustomAscii.cpp 2.12 KB
Newer Older
1
2
#include "MantidDataHandling/SaveReflCustomAscii.h"
#include "MantidDataHandling/AsciiPointBase.h"
3
#include "MantidAPI/MatrixWorkspace.h"
4
#include "MantidAPI/Run.h"
5
#include "MantidKernel/ArrayProperty.h"
6

7
8
#include <fstream>

9
10
11
12
13
14
namespace Mantid {
namespace DataHandling {
// Register the algorithm into the algorithm factory
DECLARE_ALGORITHM(SaveReflCustomAscii)
using namespace Kernel;
using namespace API;
15

16
17
/// virtual method to set the extra properties required for this algorithm
void SaveReflCustomAscii::extraProps() {
18
  declareProperty(make_unique<ArrayProperty<std::string>>("LogList"),
19
20
21
22
23
24
                  "List of logs to write to file.");
  declareProperty("Title", "", "Text to be written to the Title field");
  declareProperty(
      "WriteDeltaQ", false,
      "If true, the error on DeltaQ will be written as the fourth column.");
  declareProperty("Subtitle", false, "If true, subtitle added to header.");
25
  appendSeparatorProperty();
26
}
27

28
29
30
31
32
33
34
35
/** virtual method to add information to the file before the data
 *  @param file :: pointer to output file stream
 */
void SaveReflCustomAscii::extraHeaders(std::ofstream &file) {
  auto samp = m_ws->run();
  bool subtitle = getProperty("Subtitle");
  std::string subtitleEntry;
  std::string title = getProperty("Title");
36

37
  if (!title.empty()) // if is toggled
38
  {
39
    file << "#" << title << '\n';
40
  }
41

42
43
44
45
46
  if (subtitle) {
    try {
      subtitleEntry = samp.getLogData("run_title")->value();
    } catch (Kernel::Exception::NotFoundError &) {
      subtitleEntry = "";
47
    }
48
49
  }

50
  file << "#" << subtitleEntry << '\n';
51
52
53

  const std::vector<std::string> logList = getProperty("LogList");
  /// logs
54
55
56
  for (const auto &log : logList) {
    file << boost::lexical_cast<std::string>(log) << ": "
         << boost::lexical_cast<std::string>(samp.getLogData(log)->value())
57
         << '\n';
58
59
  }
}
60

61
62
63
64
65
66
void SaveReflCustomAscii::data(std::ofstream &file,
                               const std::vector<double> &XData,
                               bool exportDeltaQ) {
  exportDeltaQ = getProperty("WriteDeltaQ");
  AsciiPointBase::data(file, XData, exportDeltaQ);
}
67

68
} // namespace DataHandling
69
} // namespace Mantid