24using namespace Kernel;
37 "The name of the workspace containing the data you wish to save");
41 const std::vector<std::string> exts{
".his",
".txt",
""};
43 "The filename to use for the saved data");
44 declareProperty(
"IncludeHeader",
true,
"Whether to include the header lines (default: true)");
45 std::vector<std::string> header{
"ENGIN-X Format"};
46 declareProperty(
"OpenGenieFormat",
"ENGIN-X Format", std::make_shared<Kernel::StringListValidator>(header),
47 "The format required to successfully load the file to "
48 "OpenGenie: ENGIN-X Format (default)");
66 const int numOfSteps = 6;
67 Progress progressBar(
this, 0.0, 1.0, numOfSteps);
69 const std::string formatType =
getProperty(
"OpenGenieFormat");
71 if (formatType ==
"ENGIN-X Format") {
72 progressBar.
report(
"Generating ENGINX header");
77 progressBar.
report(
"Storing empty fields");
81 progressBar.
report(
"Processing workspace information");
85 progressBar.
report(
"Processing workspace data");
90 progressBar.
report(
"Processing log data");
93 std::ofstream outStream;
96 progressBar.
report(
"Writing to file");
120 const std::string xunitsVal =
"Time-of-Flight (\\\\gms)";
125 const std::string yunitsVal =
"Neutron counts / \\\\gms";
142 const double deltaValue = positionValues->
maxValue() - positionValues->minValue();
157 const std::string newLineStr =
"\r\n ";
159 const std::string outputType =
"GXRealarray\r\n 1";
162 std::string outputString(
" ");
166 for (
const auto val : histoData) {
167 if (valueCount % 10 == 0) {
168 outputString += newLineStr;
176 auto outDataString =
std::to_string(valueCount) +
" \r\n" + std::move(outputString);
185 const auto &detectorIds =
m_inputWS->getSpectrum(0).getDetectorIDs();
186 const std::string firstDetectorId =
std::to_string(*detectorIds.cbegin());
188 if (firstDetectorId.length() != 6) {
189 g_log.
warning(
"Could not determine bank ID as detector ID in ENGIN-X "
190 "workspace did not match expected format. You will need"
191 "manually specify the bank in OpenGenie");
197 const int bankNumber = firstDetectorId[1] ==
'0' ? 1 : 2;
209 const std::unordered_map<std::string, std::pair<std::string, std::string>> mantidGenieLogMapping = {
213 {
"gd_prtn_chrg", std::make_pair(
"microamps",
m_floatType)}};
215 const std::vector<Property *> &logData =
m_inputWS->run().getLogData();
217 for (
const auto &logEntry : logData) {
218 const std::string &logName = logEntry->name();
221 const auto foundMapping = mantidGenieLogMapping.find(logName);
222 if (foundMapping == mantidGenieLogMapping.cend()) {
228 const std::string outName = foundMapping->second.first;
229 const std::string outType = foundMapping->second.second;
230 std::string outValue;
233 if (outName ==
"x_pos" || outName ==
"y_pos" || outName ==
"z_pos") {
235 }
else if (outName ==
"microamps") {
238 const std::string effectiveTime =
std::to_string(std::stod(logEntry->value()) * 50.);
245 outValue = logEntry->value();
261 throw std::runtime_error(
"Trying to save an empty workspace");
263 throw std::runtime_error(
"Workspace has multiple spectra. This algorithm "
264 "can only save focused workspaces.");
265 }
else if (!
m_inputWS->isHistogramData()) {
266 throw std::runtime_error(
"This algorithm cannot save workspaces with event "
267 "data, please convert to histogram data first.");
278 const std::string filename =
getProperty(
"Filename");
280 stream.open(filename, std::ofstream::binary | std::ofstream::out);
282 g_log.
error(
"Unable to create file: " + filename);
293 const std::string floatVal =
"999.000";
325 const auto &specInfo =
m_inputWS->spectrumInfo();
330 const double two_theta = specInfo.twoTheta(0) * 180 / M_PI;
343 outfile <<
"# Open Genie ASCII File #\r\n"
362 outfile <<
" " <<
'"' << std::get<0>(outTuple) <<
'"' <<
"\r\n";
364 const std::string &outputType = std::get<1>(outTuple);
365 outfile <<
" " << outputType <<
"\r\n";
370 outfile <<
'"' << std::get<2>(outTuple) <<
'"';
372 outfile << std::get<2>(outTuple);
#define DECLARE_ALGORITHM(classname)
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
@ Save
to specify a file to write to, the file may or may not exist
Helper class for reporting progress from algorithms.
A property class for workspaces.
void determineEnginXBankId()
Determines the ENGIN-X bank from the detectors IDs present.
API::MatrixWorkspace_const_sptr m_inputWS
Workspace to save.
std::tuple< std::string, std::string, std::string > OutputBufferEntry
Typedef of a tuple containing the name, type and value as strings.
void getSampleLogs()
Parses and stores appropriate output logs into the output buffer.
std::vector< OutputBufferEntry > m_outputVector
Output buffer which holds the tuples to be written.
const std::string m_stringType
Output type - String.
const std::string m_intType
Output type - Integer.
void applyEnginxFormat()
Adds ENGINX related data which is required for OpenGenie.
void storeEmptyFields()
Stores fields that aren't found in the WS but required by OpenGenie.
const std::string m_floatType
Output type - Float.
void inputValidation()
Validates that workspace is focused and not empty.
void openFileStream(std::ofstream &stream)
Attempts to open the user specified file path as an output stream.
void writeDataToFile(std::ofstream &outfile)
sorts and writes out the data portion of the file
void exec() override
Execution code.
void calculateXYZDelta(const std::string &unit, const Kernel::Property *values)
Calculate delta x/y/z from the log files for ENGINX.
void storeWorkspaceInformation()
Stores parameters from the workspace which are required for OpenGenie.
void addToOutputBuffer(const std::string &outName, const std::string &outType, const std::string &outVal)
void convertWorkspaceData(const T &histoData, const char &axis)
Converts XYE data to a tuple containing the OPENGENIE string and store it into the output buffer.
Records the filename and the description of failure.
A non-templated interface to a TimeSeriesProperty.
void error(const std::string &msg)
Logs at error level.
void warning(const std::string &msg)
Logs at warning level.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
Base class for properties.
A specialised Property class for holding a series of time-value pairs.
TYPE maxValue() const
Returns the maximum value found in the series.
std::string to_string(const wide_integer< Bits, Signed > &n)
@ Input
An input workspace.