Skip to content
Snippets Groups Projects
Commit 159f8616 authored by Anthony Lim's avatar Anthony Lim
Browse files

refs #28155 LoadMuonLogs keeps processing when duplicate is found

parent 80acf94a
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,8 @@
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/Algorithm.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidNexus/MuonNexusReader.h"
namespace Mantid {
......@@ -65,7 +67,9 @@ private:
/// Overwrites Algorithm method
void exec() override;
/// Adds a log to the workspace
void addLogValueFromIndex(MuonNexusReader &nxload, const int &index,
API::MatrixWorkspace_sptr &localWorkspace, std::set<std::string> &logNames);
/// The name and path of an input file. This may be the filename of a raw
/// datafile or the name of a specific log file.
std::string m_filename;
......
......@@ -10,10 +10,17 @@
#include "MantidAPI/Sample.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidKernel/TimeSeriesProperty.h"
#include "MantidNexus/MuonNexusReader.h"
#include <algorithm>
#include <ctime>
namespace {
void toLower(std::string &name) {
std::transform(name.begin(), name.end(), name.begin(),
[](unsigned char c) { return std::tolower(c); });
}
} // namespace
namespace Mantid {
namespace DataHandling {
......@@ -56,7 +63,6 @@ void LoadMuonLog::exec() {
// on the filename
m_filename = getPropertyValue("Filename");
MuonNexusReader nxload;
nxload.readLogData(m_filename);
......@@ -65,49 +71,74 @@ void LoadMuonLog::exec() {
// Also set the sample name at this point, as part of the sample related log
// data.
const MatrixWorkspace_sptr localWorkspace = getProperty("Workspace");
MatrixWorkspace_sptr localWorkspace = getProperty("Workspace");
localWorkspace->mutableSample().setName(nxload.getSampleName());
std::set<std::string> logNames;
auto logs = localWorkspace->mutableRun().getLogData();
// need to remove case
for (auto log : logs) {
std::string name = log->name();
toLower(name);
logNames.insert(name);
}
// Attempt to load the content of each NXlog section into the Sample object
// Assumes that MuonNexusReader has read all log data
// Two cases of double or string data allowed
Progress prog(this, 0.0, 1.0, nxload.numberOfLogs());
for (int i = 0; i < nxload.numberOfLogs(); i++) {
std::string logName = nxload.getLogName(i);
auto l_PropertyDouble =
std::make_unique<TimeSeriesProperty<double>>(logName);
auto l_PropertyString =
std::make_unique<TimeSeriesProperty<std::string>>(logName);
// Read log file into Property which is then stored in Sample object
if (!nxload.logTypeNumeric(i)) {
std::string logValue;
std::time_t logTime;
for (int j = 0; j < nxload.getLogLength(i); j++) {
nxload.getLogStringValues(i, j, logTime, logValue);
l_PropertyString->addValue(logTime, logValue);
}
} else {
double logValue;
std::time_t logTime;
for (int j = 0; j < nxload.getLogLength(i); j++) {
nxload.getLogValues(i, j, logTime, logValue);
l_PropertyDouble->addValue(logTime, logValue);
}
}
// store Property in Sample object and delete unused object
if (nxload.logTypeNumeric(i)) {
localWorkspace->mutableRun().addLogData(std::move(l_PropertyDouble));
} else {
localWorkspace->mutableRun().addLogData(std::move(l_PropertyString));
}
addLogValueFromIndex(nxload, i, localWorkspace, logNames);
prog.report();
} // end for
}
// operation was a success and ended normally
}
void LoadMuonLog::addLogValueFromIndex(
MuonNexusReader &nxload, const int &index,
API::MatrixWorkspace_sptr &localWorkspace,
std::set<std::string> &logNames) {
std::string newLogName = nxload.getLogName(index);
// want to keep the original case for the logs
std::string logNameLower = nxload.getLogName(index);
toLower(logNameLower);
// check if log name already exists
if (logNames.find(logNameLower) != logNames.end()) {
g_log.warning("The log " + newLogName +
" is already in the nexus file. The sample log names are case insensitive.");
return;
}
logNames.insert(newLogName);
auto l_PropertyDouble =
std::make_unique<TimeSeriesProperty<double>>(newLogName);
auto l_PropertyString =
std::make_unique<TimeSeriesProperty<std::string>>(newLogName);
// Read log file into Property which is then stored in Sample object
if (!nxload.logTypeNumeric(index)) {
std::string logValue;
std::time_t logTime;
for (int j = 0; j < nxload.getLogLength(index); j++) {
nxload.getLogStringValues(index, j, logTime, logValue);
l_PropertyString->addValue(logTime, logValue);
}
} else {
double logValue;
std::time_t logTime;
for (int j = 0; j < nxload.getLogLength(index); j++) {
nxload.getLogValues(index, j, logTime, logValue);
l_PropertyDouble->addValue(logTime, logValue);
}
}
// store Property in Sample object and delete unused object
if (nxload.logTypeNumeric(index)) {
localWorkspace->mutableRun().addLogData(std::move(l_PropertyDouble));
} else {
localWorkspace->mutableRun().addLogData(std::move(l_PropertyString));
}
}
/** change each element of the string to lower case
* @param strToConvert :: The input string
* @returns The string but with all characters in lower case
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment