14#include <boost/variant/get.hpp>
24size_t NCELL_ITEM_CACHED = 100;
30class ColumnNameToType {
67const std::string typeFromName(
const std::string &name) {
68 static ColumnNameToType typeIndex;
69 auto iter = typeIndex.data().find(name);
70 if (iter != typeIndex.data().end()) {
73 throw std::runtime_error(
"PeakColumn - Unknown column name: \"" + name +
75 "Peak column names/types must be explicitly marked in PeakColumn.cpp");
89 const std::string key =
"PeakColumn.hklPrec";
91 this->
m_hklPrec = hklPrec.get_value_or(2);
92 if (!hklPrec.is_initialized()) {
93 g_log.
information() <<
"In PeakColumn constructor, did not find any value for '" << key
94 <<
"' from the Config Service. Using default: " << this->m_hklPrec <<
"\n";
105 if (type() ==
"double") {
106 return typeid(double);
107 }
else if (type() ==
"int") {
109 }
else if (type() ==
"str") {
110 return typeid(std::string);
111 }
else if (type() ==
"V3D") {
114 throw std::runtime_error(
"PeakColumn::get_type_info() - Unknown column type: " + m_name);
120 if (type() ==
"double") {
121 return typeid(
double *);
122 }
else if (type() ==
"int") {
123 return typeid(
int *);
124 }
else if (type() ==
"str") {
125 return typeid(std::string *);
126 }
else if (type() ==
"V3D") {
127 return typeid(
V3D *);
129 throw std::runtime_error(
"PeakColumn::get_pointer_type_info() -: " + m_name);
140 T &peak = m_peaks[
index];
141 auto fullPeak =
dynamic_cast<Peak *
>(&peak);
143 s.imbue(std::locale(
"C"));
144 std::ios::fmtflags fflags(s.flags());
145 if (m_name ==
"RunNumber")
146 s << peak.getRunNumber();
147 else if (m_name ==
"DetID" && fullPeak) {
148 s << fullPeak->getDetectorID();
149 }
else if (m_name ==
"BankName" && fullPeak)
150 s << fullPeak->getBankName();
151 else if (m_name ==
"QLab")
152 s << peak.getQLabFrame();
153 else if (m_name ==
"QSample")
154 s << peak.getQSampleFrame();
155 else if (m_name ==
"h") {
156 s << std::fixed << std::setprecision(m_hklPrec) << peak.getH();
157 }
else if (m_name ==
"k") {
158 s << std::fixed << std::setprecision(m_hklPrec) << peak.getK();
159 }
else if (m_name ==
"l") {
160 s << std::fixed << std::setprecision(m_hklPrec) << peak.getL();
161 }
else if (m_name ==
"PeakNumber") {
162 s << peak.getPeakNumber();
164 s << peak.getValueByColName(m_name);
176 if (this->getReadOnly() ||
index >= m_peaks.size())
184 g_log.
error() <<
"Could not convert string '" << text <<
"' to a number.\n";
187 setPeakHKLOrRunNumber(
index, val);
196 if (this->getReadOnly() ||
index >= m_peaks.size())
202 }
catch (std::exception &e) {
203 g_log.
error() <<
"Could not convert input to a number. " << e.what() <<
'\n';
207 setPeakHKLOrRunNumber(
index, val);
213 return !((m_name ==
"h") || (m_name ==
"k") || (m_name ==
"l") || (m_name ==
"RunNumber"));
224 return sizeof(double) *
static_cast<long int>(m_peaks.size());
236 "added through the PeaksWorkspace "
249 "inserted through the PeaksWorkspace "
262 "remove through the PeaksWorkspace "
272 const auto *constThis =
const_cast<const PeakColumn *
>(
this);
273 return const_cast<void *
>(constThis->void_pointer(
index));
282 const T &peak = m_peaks[
index];
291 if (m_oldRows.size() > NCELL_ITEM_CACHED) {
292 m_oldRows.pop_back();
294 auto &
value = m_oldRows.front();
296 if (type() ==
"double") {
297 value = peak.getValueByColName(m_name);
298 return boost::get<double>(&
value);
299 }
else if (m_name ==
"RunNumber") {
300 value = peak.getRunNumber();
301 return boost::get<int>(&
value);
302 }
else if (m_name ==
"PeakNumber") {
303 value = peak.getPeakNumber();
304 return boost::get<int>(&
value);
305 }
else if (m_name ==
"DetID" && fullPeak) {
306 value = fullPeak->getDetectorID();
307 return boost::get<int>(&
value);
308 }
else if (m_name ==
"BankName" && fullPeak) {
309 value = fullPeak->getBankName();
310 return boost::get<std::string>(&
value);
311 }
else if (m_name ==
"QLab") {
312 value = peak.getQLabFrame();
313 return boost::get<Kernel::V3D>(&
value);
314 }
else if (m_name ==
"QSample") {
315 value = peak.getQSampleFrame();
316 return boost::get<Kernel::V3D>(&
value);
318 throw std::runtime_error(
"void_pointer() - Unknown peak column name or type: " + m_name);
328 throw std::runtime_error(
"PeakColumn::toDouble() not implemented, PeakColumn "
329 "is has no general write access");
333 throw std::runtime_error(
"fromDouble() not implemented, PeakColumn is has no "
334 "general write access");
338 T &peak = m_peaks[
index];
341 else if (m_name ==
"k")
343 else if (m_name ==
"l")
345 else if (m_name ==
"RunNumber")
346 peak.setRunNumber(
static_cast<int>(val));
348 throw std::runtime_error(
"Unexpected column " + m_name +
" being set.");
double value
The value of the point.
std::map< DeltaEMode::Type, std::string > index
std::unordered_map< std::string, std::string > m_type_index
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
const std::string & name() const
Name (caption) of the column.
PeakColumn : a Column sub-class used to display peak information as a TableWorkspace.
void fromDouble(size_t i, double value) override
Assign from double.
const std::type_info & get_type_info() const override
Returns typeid for the data in the column.
void * void_pointer(size_t index) override
Pointer to a data element.
void remove(size_t index) override
Removes an item.
bool isBool() const override
Specialized type check.
void insert(size_t index) override
Inserts an item.
bool getReadOnly() const override
PeakColumn(std::vector< T > &peaks, const std::string &name)
Construct a column with a reference to the peaks list, a name & type.
void setPeakHKLOrRunNumber(const size_t index, const double val)
Sets the correct value in the referenced peak.
const std::type_info & get_pointer_type_info() const override
Returns typeid for the pointer type to the data element in the column.
int m_hklPrec
Precision of hkl in table workspace.
bool isNumber() const override
Are elements of the column interpretable as a number?
void read(size_t index, const std::string &text) override
Read in some text and convert to a number in the PeaksWorkspace.
double toDouble(size_t i) const override
Cast to double.
void resize(size_t count) override
Sets the new column size.
boost::variant< double, int, std::string, Kernel::V3D > CacheValueType
Type of the row cache value.
long int sizeOfData() const override
Must return overall memory size taken by the column.
PeakColumn * clone() const override
Clone.
void print(size_t index, std::ostream &s) const override
Prints.
Structure describing a single-crystal peak.
Marks code as not implemented yet.
The Logger class is in charge of the publishing messages from the framework through various channels.
void error(const std::string &msg)
Logs at error level.
void information(const std::string &msg)
Logs at information level.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
Kernel::Logger g_log("ExperimentInfo")
static logger object
int convert(const std::string &A, T &out)
Convert a string into a number.