14#include <boost/variant/get.hpp>
24size_t NCELL_ITEM_CACHED = 100;
30class ColumnNameToType {
69const std::string typeFromName(
const std::string &
name) {
70 static ColumnNameToType typeIndex;
71 auto iter = typeIndex.data().find(
name);
72 if (iter != typeIndex.data().end()) {
75 throw std::runtime_error(
"PeakColumn - Unknown column name: \"" +
name +
77 "Peak column names/types must be explicitly marked in PeakColumn.cpp");
91 const std::string key =
"PeakColumn.hklPrec";
92 auto hklPrec = ConfigService::Instance().getValue<
int>(key);
94 if (!hklPrec.has_value()) {
95 g_log.
information() <<
"In PeakColumn constructor, did not find any value for '" << key
96 <<
"' from the Config Service. Using default: " << this->m_hklPrec <<
"\n";
107 if (type() ==
"double") {
108 return typeid(double);
109 }
else if (type() ==
"int") {
111 }
else if (type() ==
"str") {
112 return typeid(std::string);
113 }
else if (type() ==
"V3D") {
116 throw std::runtime_error(
"PeakColumn::get_type_info() - Unknown column type: " + m_name);
122 if (type() ==
"double") {
123 return typeid(
double *);
124 }
else if (type() ==
"int") {
125 return typeid(
int *);
126 }
else if (type() ==
"str") {
127 return typeid(std::string *);
128 }
else if (type() ==
"V3D") {
129 return typeid(
V3D *);
131 throw std::runtime_error(
"PeakColumn::get_pointer_type_info() -: " + m_name);
142 T &peak = m_peaks[
index];
143 auto fullPeak =
dynamic_cast<Peak *
>(&peak);
145 s.imbue(std::locale(
"C"));
146 std::ios::fmtflags fflags(s.flags());
147 if (m_name ==
"RunNumber")
148 s << peak.getRunNumber();
149 else if (m_name ==
"DetID" && fullPeak) {
150 s << fullPeak->getDetectorID();
151 }
else if (m_name ==
"BankName" && fullPeak)
152 s << fullPeak->getBankName();
153 else if (m_name ==
"QLab")
154 s << peak.getQLabFrame();
155 else if (m_name ==
"QSample")
156 s << peak.getQSampleFrame();
157 else if (m_name ==
"h") {
158 s << std::fixed << std::setprecision(m_hklPrec) << peak.getH();
159 }
else if (m_name ==
"k") {
160 s << std::fixed << std::setprecision(m_hklPrec) << peak.getK();
161 }
else if (m_name ==
"l") {
162 s << std::fixed << std::setprecision(m_hklPrec) << peak.getL();
163 }
else if (m_name ==
"PeakNumber") {
164 s << peak.getPeakNumber();
165 }
else if (m_name ==
"IntHKL") {
166 s << peak.getIntHKL();
167 }
else if (m_name ==
"IntMNP") {
168 s << peak.getIntMNP();
170 s << peak.getValueByColName(m_name);
182 if (this->getReadOnly() ||
index >= m_peaks.size())
190 g_log.
error() <<
"Could not convert string '" << text <<
"' to a number.\n";
193 setPeakHKLOrRunNumber(
index, val);
202 if (this->getReadOnly() ||
index >= m_peaks.size())
208 }
catch (std::exception &e) {
209 g_log.
error() <<
"Could not convert input to a number. " << e.what() <<
'\n';
213 setPeakHKLOrRunNumber(
index, val);
219 return !((m_name ==
"h") || (m_name ==
"k") || (m_name ==
"l") || (m_name ==
"RunNumber"));
230 return sizeof(double) *
static_cast<long int>(m_peaks.size());
242 "added through the PeaksWorkspace "
255 "inserted through the PeaksWorkspace "
268 "remove through the PeaksWorkspace "
278 const auto *constThis =
const_cast<const PeakColumn *
>(
this);
279 return const_cast<void *
>(constThis->void_pointer(
index));
288 const T &peak = m_peaks[
index];
297 if (m_oldRows.size() > NCELL_ITEM_CACHED) {
298 m_oldRows.pop_back();
300 auto &
value = m_oldRows.front();
302 if (type() ==
"double") {
304 return boost::get<double>(&
value);
305 }
else if (m_name ==
"RunNumber") {
306 value = peak.getRunNumber();
307 return boost::get<int>(&
value);
308 }
else if (m_name ==
"PeakNumber") {
309 value = peak.getPeakNumber();
310 return boost::get<int>(&
value);
311 }
else if (m_name ==
"DetID" && fullPeak) {
312 value = fullPeak->getDetectorID();
313 return boost::get<int>(&
value);
314 }
else if (m_name ==
"BankName" && fullPeak) {
315 value = fullPeak->getBankName();
316 return boost::get<std::string>(&
value);
317 }
else if (m_name ==
"QLab") {
318 value = peak.getQLabFrame();
319 return boost::get<Kernel::V3D>(&
value);
320 }
else if (m_name ==
"QSample") {
321 value = peak.getQSampleFrame();
322 return boost::get<Kernel::V3D>(&
value);
323 }
else if (m_name ==
"IntHKL") {
324 value = peak.getIntHKL();
325 return boost::get<Kernel::V3D>(&
value);
326 }
else if (m_name ==
"IntMNP") {
327 value = peak.getIntMNP();
328 return boost::get<Kernel::V3D>(&
value);
330 throw std::runtime_error(
"void_pointer() - Unknown peak column name or type: " + m_name);
340 throw std::runtime_error(
"PeakColumn::toDouble() not implemented, PeakColumn "
341 "is has no general write access");
345 throw std::runtime_error(
"fromDouble() not implemented, PeakColumn is has no "
346 "general write access");
350 T &peak = m_peaks[
index];
353 else if (m_name ==
"k")
355 else if (m_name ==
"l")
357 else if (m_name ==
"RunNumber")
358 peak.setRunNumber(
static_cast<int>(val));
360 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.
double getValueByColName(std::string colName) const override
Helper function for displaying/sorting peaks.
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.
Kernel::Logger g_log("ExperimentInfo")
static logger object
int convert(const std::string &A, T &out)
Convert a string into a number.