30 :
API::
Algorithm(), id_xmin(-1), id_xmax(-1), id_spec(-1), id_dets(-1), m_useDetectorID(false),
31 m_useSpectrumID(false) {}
36 std::make_shared<HistogramValidator>()),
37 "Input Workspace to mask bins. ");
39 "Output Workspace with bins masked.");
42 "Input TableWorkspace containing parameters, XMin and "
43 "XMax and either SpectraList or DetectorIDsList");
45 std::make_unique<IndexTypeProperty>(
"InputWorkspaceIndexType",
static_cast<int>(IndexType::SpectrumNum) |
46 static_cast<int>(IndexType::WorkspaceIndex)),
47 "Identity input index list as spectra or index numbers");
69 bool firstloop =
true;
74 g_log.
debug() <<
"There will be " << numcalls <<
" calls to MaskBins"
76 for (
size_t ib = 0; ib < numcalls; ++ib) {
79 maskbins->initialize();
86 maskbins->setProperty(
"InputWorkspace", dataws);
90 throw runtime_error(
"Programming logic error.");
91 maskbins->setProperty(
"InputWorkspace", outputws);
93 maskbins->setProperty(
"OutputWorkspace", this->
getPropertyValue(
"OutputWorkspace"));
94 const std::string &indexType =
getProperty(
"InputWorkspaceIndexType");
95 maskbins->setPropertyValue(
"InputWorkspaceIndexType", indexType);
96 maskbins->setPropertyValue(
"InputWorkspaceIndexSet",
m_spectraVec[ib]);
97 maskbins->setProperty(
"XMin",
m_xminVec[ib]);
98 maskbins->setProperty(
"XMax",
m_xmaxVec[ib]);
100 bool isexec = maskbins->execute();
103 errmsg <<
"MaskBins() is not executed for row " << ib <<
"\n";
105 throw std::runtime_error(errmsg.str());
107 g_log.
debug(
"MaskBins() is executed successfully.");
110 outputws = maskbins->getProperty(
"OutputWorkspace");
113 errmsg <<
"OutputWorkspace cannot be obtained from algorithm row " << ib <<
". ";
115 throw std::runtime_error(errmsg.str());
135 throw std::invalid_argument(
"Input workspace is not a table workspace.");
136 g_log.
debug() <<
"Lines of parameters workspace = " << masktblws->rowCount() <<
'\n';
139 vector<std::string> colnames = masktblws->getColumnNames();
149 for (
int i = 0; i < static_cast<int>(colnames.size()); ++i) {
150 string colname = colnames[i];
151 transform(colname.begin(), colname.end(), colname.begin(), ::tolower);
152 if (colname ==
"xmin")
154 else if (colname ==
"xmax")
156 else if (colname.starts_with(
"spec")) {
158 }
else if (colname.starts_with(
"detectorid")) {
161 g_log.
warning() <<
"In TableWorkspace " << masktblws->getName() <<
", column " << i <<
" with name " << colname
162 <<
" is not used by MaskBinsFromTable.";
167 throw runtime_error(
"Either Xmin nor Xmax is not given. ");
169 throw runtime_error(
"Neither SpectraList nor DetectorIDList is given.");
176 size_t numrows = masktblws->rowCount();
177 for (
size_t i = 0; i < numrows; ++i) {
178 double xmin = masktblws->cell<
double>(i,
static_cast<size_t>(
id_xmin));
179 double xmax = masktblws->cell<
double>(i,
static_cast<size_t>(
id_xmax));
183 spectralist = masktblws->cell<
string>(i,
static_cast<size_t>(
id_spec));
186 string detidslist = masktblws->cell<
string>(i,
static_cast<size_t>(
id_dets));
190 g_log.
debug() <<
"Row " << i <<
" XMin = " << xmin <<
" XMax = " << xmax <<
" SpectraList = " << spectralist
208 const std::string &detidliststr) {
210 vector<int> detidvec;
213 size_t numitems = parser.
size();
214 for (
size_t i = 0; i < numitems; ++i) {
215 detidvec.emplace_back(parser.operator()()[i]);
216 g_log.
debug() <<
"[DB] DetetorID = " << detidvec.back() <<
" to mask.";
220 vector<size_t> wsindexvec;
222 detid2index_map refermap = dataws->getDetectorIDToWorkspaceIndexMap(
false);
223 for (
size_t i = 0; i < numitems; ++i) {
225 detid2index_map::const_iterator fiter = refermap.find(detid);
226 if (fiter != refermap.end()) {
227 size_t wsindex = fiter->second;
228 wsindexvec.emplace_back(wsindex);
230 g_log.
warning() <<
"Detector ID " << detid <<
" cannot be mapped to any workspace index/spectrum."
236 if (wsindexvec.empty())
237 throw runtime_error(
"There is no spectrum found for input detectors list.");
239 sort(wsindexvec.begin(), wsindexvec.end());
243 size_t headid = wsindexvec[0];
244 size_t previd = wsindexvec[0];
246 for (
size_t i = 1; i < wsindexvec.size(); ++i) {
247 size_t currid = wsindexvec[i];
248 if (currid > previd + 1) {
250 if (headid == previd)
251 rss << headid <<
", ";
253 rss << headid <<
"-" << previd <<
", ";
265 if (headid == previd)
268 rss << headid <<
"-" << previd;
270 string spectraliststr(rss.str());
272 return spectraliststr;
#define DECLARE_ALGORITHM(classname)
Base class from which all concrete algorithm classes should be derived.
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
A property class for workspaces.
MaskBinsFromTable : TODO: DESCRIPTION.
void init() override
Virtual method - must be overridden by concrete algorithm.
int id_xmin
Column indexes of XMin, XMax, SpectraList, DetectorIDsList.
void exec() override
Main execution body.
std::string convertToSpectraList(const API::MatrixWorkspace_sptr &dataws, const std::string &detidliststr)
Convert a list of detector IDs list (string) to a list of spectra/workspace indexes list.
std::vector< std::string > m_spectraVec
void maskBins(const API::MatrixWorkspace_sptr &dataws)
Call MaskBins.
std::vector< double > m_xminVec
Vector to store XMin, XMax and SpectraList.
void processMaskBinWorkspace(const DataObjects::TableWorkspace_sptr &masktblws, const API::MatrixWorkspace_sptr &dataws)
Process input Mask bin TableWorkspace.
std::vector< double > m_xmaxVec
Support for a property that holds an array of values.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void debug(const std::string &msg)
Logs at debug level.
void error(const std::string &msg)
Logs at error level.
void warning(const std::string &msg)
Logs at warning level.
int size() const override
Get the size of the property.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< TableWorkspace > TableWorkspace_sptr
shared pointer to Mantid::DataObjects::TableWorkspace
int32_t detid_t
Typedef for a detector ID.
std::unordered_map< detid_t, size_t > detid2index_map
Map with key = detector ID, value = workspace index.
@ Input
An input workspace.
@ Output
An output workspace.