27using namespace Kernel;
40 "The name of the workspace containing the data you wish to save");
44 const std::vector<std::string> exts{
".his",
".txt",
""};
46 "The filename to use for the saved data");
47 declareProperty(
"IncludeHeader",
true,
"Whether to include the header lines (default: true)");
48 std::vector<std::string> header{
"ENGIN-X Format"};
49 declareProperty(
"OpenGenieFormat",
"ENGIN-X Format", std::make_shared<Kernel::StringListValidator>(header),
50 "The format required to successfully load the file to "
51 "OpenGenie: ENGIN-X Format (default)");
69 const int numOfSteps = 6;
70 Progress progressBar(
this, 0.0, 1.0, numOfSteps);
72 const std::string formatType =
getProperty(
"OpenGenieFormat");
74 if (formatType ==
"ENGIN-X Format") {
75 progressBar.
report(
"Generating ENGINX header");
80 progressBar.
report(
"Storing empty fields");
84 progressBar.
report(
"Processing workspace information");
88 progressBar.
report(
"Processing workspace data");
93 progressBar.
report(
"Processing log data");
96 std::ofstream outStream;
99 progressBar.
report(
"Writing to file");
123 const std::string xunitsVal =
"Time-of-Flight (\\\\gms)";
128 const std::string yunitsVal =
"Neutron counts / \\\\gms";
145 const double deltaValue = positionValues->
maxValue() - positionValues->minValue();
160 const std::string newLineStr =
"\r\n ";
162 const std::string outputType =
"GXRealarray\r\n 1";
165 std::string outputString(
" ");
169 for (
const auto val : histoData) {
170 if (valueCount % 10 == 0) {
171 outputString += newLineStr;
179 auto outDataString =
std::to_string(valueCount) +
" \r\n" + std::move(outputString);
188 const auto &detectorIds =
m_inputWS->getSpectrum(0).getDetectorIDs();
189 const std::string firstDetectorId =
std::to_string(*detectorIds.cbegin());
191 if (firstDetectorId.length() != 6) {
192 g_log.
warning(
"Could not determine bank ID as detector ID in ENGIN-X "
193 "workspace did not match expected format. You will need"
194 "manually specify the bank in OpenGenie");
200 const int bankNumber = firstDetectorId[1] ==
'0' ? 1 : 2;
212 const std::unordered_map<std::string, std::pair<std::string, std::string>> mantidGenieLogMapping = {
216 {
"gd_prtn_chrg", std::make_pair(
"microamps",
m_floatType)}};
218 const std::vector<Property *> &logData =
m_inputWS->run().getLogData();
220 for (
const auto &logEntry : logData) {
221 const std::string &logName = logEntry->name();
224 const auto foundMapping = mantidGenieLogMapping.find(logName);
225 if (foundMapping == mantidGenieLogMapping.cend()) {
231 const std::string outName = foundMapping->second.first;
232 const std::string outType = foundMapping->second.second;
233 std::string outValue;
236 if (outName ==
"x_pos" || outName ==
"y_pos" || outName ==
"z_pos") {
238 }
else if (outName ==
"microamps") {
241 const std::string effectiveTime =
std::to_string(std::stod(logEntry->value()) * 50.);
248 outValue = logEntry->value();
264 throw std::runtime_error(
"Trying to save an empty workspace");
266 throw std::runtime_error(
"Workspace has multiple spectra. This algorithm "
267 "can only save focused workspaces.");
268 }
else if (!
m_inputWS->isHistogramData()) {
269 throw std::runtime_error(
"This algorithm cannot save workspaces with event "
270 "data, please convert to histogram data first.");
283 const std::string filename =
getProperty(
"Filename");
285 stream.open(filename, std::ofstream::binary | std::ofstream::out);
287 g_log.
error(
"Unable to create file: " + filename);
298 const std::string floatVal =
"999.000";
330 const auto &specInfo =
m_inputWS->spectrumInfo();
335 const double two_theta = specInfo.twoTheta(0) * 180 / M_PI;
348 outfile <<
"# Open Genie ASCII File #\r\n"
367 outfile <<
" " <<
'"' << std::get<0>(outTuple) <<
'"' <<
"\r\n";
369 const std::string &outputType = std::get<1>(outTuple);
370 outfile <<
" " << outputType <<
"\r\n";
375 outfile <<
'"' << std::get<2>(outTuple) <<
'"';
377 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.