29 "A workspace whose masking is to be extracted or a MaskWorkspace. ");
33 "A mask table workspace containing 3 columns: "
34 "XMin, XMax and DetectorIDsList. ");
37 "A comma separated list or array containing a "
38 "list of masked detector ID's ");
40 declareProperty(
"Xmin",
EMPTY_DBL(),
"Minimum of X-value.");
42 declareProperty(
"Xmax",
EMPTY_DBL(),
"Maximum of X-value.");
52 throw std::runtime_error(
"InputWorkspace cannot be cast to a MatrixWorkspace.");
55 bool m_inputIsMask =
false;
60 m_inputIsMask =
false;
68 throw std::runtime_error(
"XMin or XMax cannot be empty. XMin must be less than XMax.");
71 auto outws = std::make_shared<TableWorkspace>();
72 outws->addColumn(
"double",
"XMin");
73 outws->addColumn(
"double",
"XMax");
74 outws->addColumn(
"str",
"DetectorIDsList");
78 std::vector<detid_t> prevmaskeddetids;
80 g_log.
notice(
"Parse input masking table workspace.");
87 std::vector<detid_t> maskeddetids;
92 g_log.
debug() <<
"[DB] Number of masked detectors = " << maskeddetids.size() <<
".\n";
96 g_log.
notice() <<
"About to copying input table workspace content to output workspace."
100 g_log.
notice() <<
"There is no input workspace information to copy to "
116 std::vector<detid_t> maskeddetectorids;
119 if (masktablews->columnCount() != 3) {
120 g_log.
error(
"Mask table workspace must have more than 3 columns. First 3 "
121 "must be Xmin, Xmax and Spectrum List.");
122 return maskeddetectorids;
124 std::vector<std::string> colnames = masktablews->getColumnNames();
125 std::vector<std::string> chkcolumans(3);
126 chkcolumans[0] =
"XMin";
127 chkcolumans[1] =
"XMax";
128 chkcolumans[2] =
"DetectorIDsList";
129 for (
int i = 0; i < 3; ++i) {
130 if (colnames[i] != chkcolumans[i]) {
131 g_log.
error() <<
"Mask table workspace " << masktablews->getName() <<
"'s " << i <<
"-th column name is "
132 << colnames[i] <<
", while it should be " << chkcolumans[i] <<
". MaskWorkspace is invalid"
133 <<
" and thus not used.\n";
134 return maskeddetectorids;
140 size_t numrows = masktablews->rowCount();
142 std::string specliststr;
143 for (
size_t i = 0; i < numrows; ++i) {
144 TableRow tmprow = masktablews->getRow(i);
145 tmprow >> xmin >> xmax >> specliststr;
148 maskeddetectorids.insert(maskeddetectorids.end(), tmpdetidvec.begin(), tmpdetidvec.end());
151 return maskeddetectorids;
161 std::vector<detid_t> detidvec;
165 if (!detlist.
isValid().empty()) {
166 std::stringstream errss;
167 errss <<
"String '" << liststr <<
"' is unable to be converted to a list of detectors IDs. "
168 <<
"Validation mesage: " << detlist.
isValid();
170 throw std::runtime_error(errss.str());
174 size_t numdetids = detlist.
size();
175 detidvec.reserve(numdetids);
176 for (
size_t i = 0; i < numdetids; ++i) {
177 int tmpid = detlist.operator()()[i];
178 detidvec.emplace_back(tmpid);
179 g_log.
debug() <<
"[DB] Add detector ID: " << tmpid <<
".\n";
191 std::vector<detid_t> maskeddetids;
194 const auto &detectorInfo =
m_dataWS->detectorInfo();
195 if (detectorInfo.size() == 0)
196 throw std::runtime_error(
"There is no instrument in input workspace.");
199 const std::vector<detid_t> &detids = detectorInfo.detectorIDs();
201 for (
size_t i = 0; i < detectorInfo.size(); ++i) {
202 bool masked = detectorInfo.isMasked(i);
204 maskeddetids.emplace_back(detids[i]);
206 g_log.
debug() <<
"[DB] Detector No. " << i <<
": ID = " << detids[i] <<
", Masked = " << masked <<
".\n";
209 g_log.
notice() <<
"Extract mask: There are " << maskeddetids.size()
224 std::vector<detid_t> maskeddetids;
228 size_t numhist = maskws->getNumberHistograms();
229 for (
size_t i = 0; i < numhist; ++i) {
231 if (maskws->readY(i)[0] < 1.0E-9)
234 const auto &detidset = maskws->getSpectrum(i).getDetectorIDs();
235 std::copy(detidset.cbegin(), detidset.cend(), std::inserter(maskeddetids, maskeddetids.end()));
248 std::vector<std::string> sourcecolnames = sourceWS->getColumnNames();
249 std::vector<std::string> targetcolnames = targetWS->getColumnNames();
250 if (sourcecolnames.size() != targetcolnames.size()) {
251 std::stringstream errmsg;
252 errmsg <<
"Soruce table workspace " << sourceWS->getName() <<
" has different number of columns ("
253 << sourcecolnames.size() <<
") than target table workspace's (" << targetcolnames.size() <<
")";
254 throw std::runtime_error(errmsg.str());
256 for (
size_t i = 0; i < sourcecolnames.size(); ++i) {
257 if (sourcecolnames[i] != targetcolnames[i]) {
258 std::stringstream errss;
259 errss <<
"Source and target have incompatible column name at column " << i <<
". "
260 <<
"Column name of source is " << sourcecolnames[i] <<
"; "
261 <<
"Column name of target is " << targetcolnames[i];
262 throw std::runtime_error(errss.str());
267 size_t numrows = sourceWS->rowCount();
268 for (
size_t i = 0; i < numrows; ++i) {
270 std::string speclist;
271 TableRow tmprow = sourceWS->getRow(i);
272 tmprow >> xmin >> xmax >> speclist;
274 TableRow newrow = targetWS->appendRow();
275 newrow << xmin << xmax << speclist;
290 double xmin,
double xmax, std::vector<detid_t> prevmaskedids) {
292 size_t numdetids = maskeddetids.size();
293 if (numdetids == 0) {
294 std::stringstream warnss;
295 warnss <<
"Attempting to add an empty vector of masked detectors IDs to "
296 "output workspace. Operation failed.";
300 sort(maskeddetids.begin(), maskeddetids.end());
304 if (!prevmaskedids.empty()) {
305 sort(prevmaskedids.begin(), prevmaskedids.end());
307 numdetids = maskeddetids.size();
309 g_log.
debug() <<
"[DB] There is no previously masked detectors."
313 if (numdetids == 0) {
315 throw std::runtime_error(
"Empty detector ID list");
319 std::stringstream spectralist;
320 detid_t previd = maskeddetids[0];
321 detid_t headid = maskeddetids[0];
322 for (
size_t i = 1; i < numdetids; ++i) {
323 detid_t tmpid = maskeddetids[i];
324 if (tmpid == previd + 1) {
327 }
else if (tmpid > previd + 1) {
329 if (previd == headid) {
331 spectralist <<
" " << headid <<
", ";
334 spectralist <<
" " << headid <<
"-" << previd <<
", ";
341 g_log.
error() <<
"Current ID = " << tmpid <<
", Previous ID = " << previd <<
", Head ID = " << headid <<
".\n";
342 throw std::runtime_error(
"Impossible! Programming logic error!");
347 if (previd == headid)
348 spectralist <<
" " << headid;
350 spectralist <<
" " << headid <<
"-" << previd;
353 std::string specliststr = spectralist.str();
354 TableRow newrow = outws->appendRow();
355 newrow << xmin << xmax << specliststr;
365 std::vector<detid_t>::iterator firstsubiter, fiter;
366 firstsubiter = subtrahend.begin();
369 std::vector<detid_t> diff;
370 size_t numminend = minuend.size();
372 for (
size_t i = 0; i < numminend; ++i) {
374 fiter = lower_bound(firstsubiter, subtrahend.end(), tmpid);
376 if (fiter != subtrahend.end())
377 exist = *fiter == tmpid;
379 diff.emplace_back(tmpid);
381 firstsubiter = fiter;
#define DECLARE_ALGORITHM(classname)
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
TableRow represents a row in a TableWorkspace.
A property class for workspaces.
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 notice(const std::string &msg)
Logs at notice 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
Return the size of this property.
std::string isValid() const override
Overridden function that checks whether the property, if not overriden returns "".
std::shared_ptr< TableWorkspace > TableWorkspace_sptr
shared pointer to Mantid::DataObjects::TableWorkspace
std::shared_ptr< const MaskWorkspace > MaskWorkspace_const_sptr
shared pointer to a const MaskWorkspace
int32_t detid_t
Typedef for a detector ID.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
@ Input
An input workspace.
@ Output
An output workspace.