Skip to content
Snippets Groups Projects
Commit fa37a99a authored by Antti Soininen's avatar Antti Soininen
Browse files

Fix a bug in PeakColumn::read().

Re #18366
parent 1f537432
No related branches found
No related tags found
No related merge requests found
......@@ -80,6 +80,7 @@ private:
typedef boost::variant<double, int, std::string, Kernel::V3D> CacheValueType;
///
mutable std::list<CacheValueType> m_oldRows;
void setPeakHKLOrRunNumber(const size_t index, const double val);
};
} // namespace Mantid
......
......@@ -165,36 +165,18 @@ void PeakColumn::print(size_t index, std::ostream &s) const {
*/
void PeakColumn::read(size_t index, const std::string &text) {
// Don't modify read-only ones
if (this->getReadOnly())
if (this->getReadOnly() || index >= m_peaks.size())
return;
// Avoid going out of bounds
if (size_t(index) >= m_peaks.size())
return;
// Reference to the peak in the workspace
Peak &peak = m_peaks[index];
// Convert to a double
double val = 0;
int success = Strings::convert(text, val);
int ival = static_cast<int>(val);
if (success == 0) {
g_log.error() << "Could not convert string '" << text << "' to a number.\n";
return;
}
if (m_name == "h")
peak.setH(val);
else if (m_name == "k")
peak.setK(val);
else if (m_name == "l")
peak.setL(val);
else if (m_name == "RunNumber")
peak.setRunNumber(ival);
else
throw std::runtime_error("Unexpected column " + m_name + " being set.");
setPeakHKLOrRunNumber(index, val);
}
/** Read in from stream and convert to a number in the PeaksWorkspace
......@@ -203,9 +185,19 @@ void PeakColumn::read(size_t index, const std::string &text) {
* @param in :: input stream
*/
void PeakColumn::read(const size_t index, std::istream &in) {
std::string s;
in >> s;
read(index, s);
if (this->getReadOnly() || index >= m_peaks.size())
return;
double val;
try {
in >> val;
}
catch (std::exception &e) {
g_log.error() << "Could not convert input to a number.\n";
return;
}
setPeakHKLOrRunNumber(index, val);
}
//-------------------------------------------------------------------------------------
......@@ -332,5 +324,19 @@ void PeakColumn::fromDouble(size_t /*index*/, double /*value*/) {
"general write access");
}
void PeakColumn::setPeakHKLOrRunNumber(const size_t index, const double val) {
Peak &peak = m_peaks[index];
if (m_name == "h")
peak.setH(val);
else if (m_name == "k")
peak.setK(val);
else if (m_name == "l")
peak.setL(val);
else if (m_name == "RunNumber")
peak.setRunNumber(static_cast<int>(val));
else
throw std::runtime_error("Unexpected column " + m_name + " being set.");
}
} // namespace Mantid
} // namespace DataObjects
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