Mantid
Loading...
Searching...
No Matches
LoadMask.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
21#include "MantidKernel/System.h"
22
23#include <fstream>
24#include <map>
25#include <sstream>
26
27#include <Poco/DOM/DOMParser.h>
28#include <Poco/DOM/Element.h>
29#include <Poco/DOM/NodeFilter.h>
30#include <Poco/DOM/NodeIterator.h>
31#include <Poco/DOM/NodeList.h>
32#include <Poco/Exception.h>
33
34#include <boost/algorithm/string.hpp>
35
36using Poco::XML::DOMParser;
37using Poco::XML::Node;
38using Poco::XML::NodeFilter;
39using Poco::XML::NodeIterator;
40using Poco::XML::NodeList;
41
42using namespace Mantid::Kernel;
43using namespace Mantid::API;
44using namespace std;
45
46namespace {
47// service routines
48//-------------------------------------------------------------------------------------------
60template <typename T>
61void convertToVector(const std::vector<T> &singles, const std::vector<T> &ranges, std::vector<T> &tot_singles) {
62
63 // find the size of the final vector of masked values
64 size_t n_total(singles.size() + tot_singles.size());
65 for (size_t i = 0; i < ranges.size(); i += 2) {
66 n_total += ranges[i + 1] - ranges[i] + 1;
67 }
68 // reserve space for all masked spectra
69 // for efficient memory operations
70 tot_singles.reserve(n_total);
71 // add singles to the existing singles
72 tot_singles.insert(tot_singles.end(), singles.begin(), singles.end());
73 // expand pairs
74 for (size_t i = 0; i < ranges.size(); i += 2) {
75 for (T obj_id = ranges[i]; obj_id < ranges[i + 1] + 1; ++obj_id) {
76 tot_singles.emplace_back(obj_id);
77 }
78 }
79}
80
89template <typename T> void parseRangeText(const std::string &inputstr, std::vector<T> &singles, std::vector<T> &pairs) {
90 // 1. Split ','
91 std::vector<std::string> rawstrings;
92 boost::split(rawstrings, inputstr, boost::is_any_of(","), boost::token_compress_on);
93
94 for (auto &rawstring : rawstrings) {
95 // a) Find '-':
96 boost::trim(rawstring);
97 bool containDash(true);
98 if (rawstring.find_first_of('-') == std::string::npos) {
99 containDash = false;
100 }
101
102 // Process appropriately
103 if (containDash) { // 4. Treat pairs
104 std::vector<std::string> ptemp;
105 boost::split(ptemp, rawstring, boost::is_any_of("-"), boost::token_compress_on);
106 if (ptemp.size() != 2) {
107 std::string error = "Range string " + rawstring + " has a wrong format!";
108 throw std::invalid_argument(error);
109 }
110 // b) parse
111 auto intstart = boost::lexical_cast<T>(ptemp[0]);
112 auto intend = boost::lexical_cast<T>(ptemp[1]);
113 if (intstart >= intend) {
114 std::string error = "Range string " + rawstring + " has wrong order of detectors ID!";
115 throw std::invalid_argument(error);
116 }
117 pairs.emplace_back(intstart);
118 pairs.emplace_back(intend);
119
120 } else { // 3. Treat singles
121 auto itemp = boost::lexical_cast<T>(rawstring);
122 singles.emplace_back(itemp);
123 }
124 } // ENDFOR i
125}
126
127/*
128 * Parse a line in an ISIS mask file string to vector
129 * Combination of 5 types of format for unit
130 * (1) a (2) a-b (3) a - b (4) a- b (5) a -b
131 * separated by space(s)
132 * @param ins -- input string in ISIS ASCII format
133 * @return ranges -- vector of a,b pairs converted from input
134 */
135void parseISISStringToVector(const std::string &ins, std::vector<Mantid::specnum_t> &ranges) {
136 // 1. Split by space
137 std::vector<string> splitstrings;
138 boost::split(splitstrings, ins, boost::is_any_of(" "), boost::token_compress_on);
139
140 // 2. Replace a-b to a - b, remove a-b and insert a, -, b
141 bool tocontinue = true;
142 size_t index = 0;
143 while (tocontinue) {
144 // a) Determine end of loop. Note that loop size changes
145 if (index == splitstrings.size() - 1) {
146 tocontinue = false;
147 }
148
149 // b) Need to split?
150 vector<string> temps;
151 boost::split(temps, splitstrings[index], boost::is_any_of("-"), boost::token_compress_on);
152 if (splitstrings[index] == "-" || temps.size() == 1) {
153 // Nothing to split
154 index++;
155 } else if (temps.size() == 2) {
156 // Has a '-' inside. Delete and Replace
157 temps.insert(temps.begin() + 1, "-");
158 splitstrings.erase(splitstrings.begin() + index);
159 for (size_t ic = 0; ic < 3; ic++) {
160 if (!temps[ic].empty()) {
161 splitstrings.insert(splitstrings.begin() + index, temps[ic]);
162 index++;
163 }
164 }
165 } else {
166 // Exception
167 std::string err = "String " + splitstrings[index] + " has too many '-'";
168 throw std::invalid_argument(err);
169 }
170
171 if (index >= splitstrings.size())
172 tocontinue = false;
173
174 } // END WHILE
175
176 // 3. Put to output integer vector
177 tocontinue = true;
178 index = 0;
179 while (tocontinue) {
180 // i) push to the starting vector
181 ranges.emplace_back(boost::lexical_cast<Mantid::specnum_t>(splitstrings[index]));
182
183 // ii) push the ending vector
184 if (index == splitstrings.size() - 1 || splitstrings[index + 1] != "-") {
185 // the next one is not '-'
186 ranges.emplace_back(boost::lexical_cast<Mantid::specnum_t>(splitstrings[index]));
187 index++;
188 } else {
189 // the next one is '-', thus read '-', next
190 ranges.emplace_back(boost::lexical_cast<Mantid::specnum_t>(splitstrings[index + 2]));
191 index += 3;
192 }
193
194 if (index >= splitstrings.size())
195 tocontinue = false;
196 } // END-WHILE
197}
198/*
199* Load and parse an ISIS masking file
200@param isisfilename :: the string containing full path to an ISIS mask file
201@param SpectraMasks :: output list of the spectra numbers to mask.
202*/
203void loadISISMaskFile(const std::string &isisfilename, std::vector<Mantid::specnum_t> &spectraMasks) {
204
205 std::vector<Mantid::specnum_t> ranges;
206
207 std::ifstream ifs;
208 ifs.open(isisfilename, std::ios::in);
209 if (!ifs.is_open()) {
210 throw std::invalid_argument("Cannot open ISIS mask file" + isisfilename);
211 }
212
213 std::string isisline;
214 while (getline(ifs, isisline)) {
215 boost::trim(isisline);
216
217 // a. skip empty line
218 if (isisline.empty())
219 continue;
220
221 // b. skip comment line
222 if (isisline.c_str()[0] < '0' || isisline.c_str()[0] > '9')
223 continue;
224
225 // c. parse
226 parseISISStringToVector(isisline, ranges);
227 }
228
229 // dummy helper vector as ISIS mask is always processed as pairs.
230 std::vector<Mantid::specnum_t> dummy;
231 convertToVector(dummy, ranges, spectraMasks);
232}
233
234} // namespace
235
236namespace Mantid::DataHandling {
237
239
240
241void LoadMask::init() {
242
243 // 1. Declare property
244 declareProperty("Instrument", "", std::make_shared<MandatoryValidator<std::string>>(),
245 "The name of the instrument to apply the mask.");
246
247 const std::vector<std::string> maskExts{".xml", ".msk"};
248 declareProperty(std::make_unique<FileProperty>("InputFile", "", FileProperty::Load, maskExts),
249 "Masking file for masking. Supported file format is XML and "
250 "ISIS ASCII. ");
251 declareProperty(std::make_unique<WorkspaceProperty<API::MatrixWorkspace>>("RefWorkspace", "", Direction::Input,
253 "The name of the workspace wich defines instrument and spectra, "
254 "used as the source of the spectra-detector map for the mask to load. "
255 "The instrument, attached to this workspace has to be the same as the "
256 "one specified by 'Instrument' property");
257
258 declareProperty(
259 std::make_unique<WorkspaceProperty<DataObjects::MaskWorkspace>>("OutputWorkspace", "Masking", Direction::Output),
260 "Output Masking Workspace");
261}
262
263//----------------------------------------------------------------------------------------------
267 reset();
268
269 // 1. Load Instrument and create output Mask workspace
270 const std::string instrumentname = getProperty("Instrument");
271 m_sourceMapWS = getProperty("RefWorkspace");
272
273 m_instrumentPropValue = instrumentname;
274 setProperty("Instrument", instrumentname);
275
277
278 if (m_sourceMapWS) { // check if the instruments are compatible
279 auto t_inst_name = m_maskWS->getInstrument()->getName();
280 auto r_inst_name = m_sourceMapWS->getInstrument()->getName();
281 if (t_inst_name != r_inst_name) {
282 throw std::invalid_argument("If reference workspace is provided, it has "
283 "to have instrument with the same name as "
284 "specified by 'Instrument' property");
285 }
286 }
287
288 setProperty("OutputWorkspace", m_maskWS);
289
290 m_defaultToUse = true;
291
292 // 2. Parse Mask File
293 std::string filename = getProperty("InputFile");
294
295 if (boost::ends_with(filename, "l") || boost::ends_with(filename, "L")) {
296 // 2.1 XML File
297 this->initializeXMLParser(filename);
298 this->parseXML();
299 } else if (boost::ends_with(filename, "k") || boost::ends_with(filename, "K")) {
300 // 2.2 ISIS Masking file
301 loadISISMaskFile(filename, m_maskSpecID);
302 m_defaultToUse = true;
303 } else {
304 g_log.error() << "File " << filename << " is not in supported format. \n";
305 return;
306 }
307 // 3. Translate and set geometry
308 g_log.information() << "To Mask: \n";
309
311
312 // unmasking is not implemented
313 // g_log.information() << "To UnMask: \n";
314
315 // As m_uMaskCompIdSingle is empty, this never works
317
318 // convert spectra ID to corresponded det-id-s
320
321 // 4. Apply
322 this->initDetectors();
323 const detid2index_map indexmap = m_maskWS->getDetectorIDToWorkspaceIndexMap(true);
324
325 this->processMaskOnDetectors(indexmap, true, m_maskDetID);
326 // TODO: Not implemented, but should work as soon as m_unMask contains
327 // something
328 this->processMaskOnDetectors(indexmap, false, m_unMaskDetID);
329}
330
332
333 if (!m_defaultToUse) { // Default is to use all detectors
334 size_t numHist = m_maskWS->getNumberHistograms();
335 for (size_t wkspIndex = 0; wkspIndex < numHist; wkspIndex++) {
336 m_maskWS->setMaskedIndex(wkspIndex);
337 }
338 }
339}
340
341//----------------------------------------------------------------------------------------------
348void LoadMask::processMaskOnDetectors(const detid2index_map &indexmap, bool tomask,
349 const std::vector<detid_t> &singledetids) {
350 // 1. Get index map
351 // 2. Mask
352 g_log.debug() << "Mask = " << tomask << " Final Single IDs Size = " << singledetids.size() << '\n';
353
354 for (auto detid : singledetids) {
355 detid2index_map::const_iterator it;
356 it = indexmap.find(detid);
357 if (it != indexmap.end()) {
358 size_t index = it->second;
359 m_maskWS->mutableY(index)[0] = (tomask) ? 1 : 0;
360 } else {
361 g_log.warning() << "Pixel w/ ID = " << detid << " Cannot Be Located\n";
362 }
363 }
364}
365
366//----------------------------------------------------------------------------------------------
374void LoadMask::componentToDetectors(const std::vector<std::string> &componentnames, std::vector<detid_t> &detectors) {
375 Geometry::Instrument_const_sptr minstrument = m_maskWS->getInstrument();
376
377 for (auto &componentname : componentnames) {
378 g_log.debug() << "Component name = " << componentname << '\n';
379
380 // a) get component
381 Geometry::IComponent_const_sptr component = minstrument->getComponentByName(componentname);
382 if (component)
383 g_log.debug() << "Component ID = " << component->getComponentID() << '\n';
384 else {
385 // A non-exiting component. Ignore
386 g_log.warning() << "Component " << componentname << " does not exist!\n";
387 continue;
388 }
389
390 // b) component -> component assembly --> children (more than detectors)
391 std::shared_ptr<const Geometry::ICompAssembly> asmb =
392 std::dynamic_pointer_cast<const Geometry::ICompAssembly>(component);
393 std::vector<Geometry::IComponent_const_sptr> children;
394 asmb->getChildren(children, true);
395
396 g_log.debug() << "Number of Children = " << children.size() << '\n';
397
398 size_t numdets(0);
399 detid_t id_min(std::numeric_limits<Mantid::detid_t>::max());
400 detid_t id_max(0);
401
402 for (const auto &child : children) {
403 // c) convert component to detector
404 Geometry::IDetector_const_sptr det = std::dynamic_pointer_cast<const Geometry::IDetector>(child);
405
406 if (det) {
407 detid_t detid = det->getID();
408 detectors.emplace_back(detid);
409 numdets++;
410 if (detid < id_min)
411 id_min = detid;
412 if (detid > id_max)
413 id_max = detid;
414 }
415 }
416
417 g_log.debug() << "Number of Detectors in Children = " << numdets << " Range = " << id_min << ", " << id_max
418 << '\n';
419 } // for component
420}
421
422//----------------------------------------------------------------------------------------------
428void LoadMask::bankToDetectors(const std::vector<std::string> &singlebanks, std::vector<detid_t> &detectors) {
429 std::stringstream infoss;
430 infoss << "Bank IDs to be converted to detectors: \n";
431 for (auto &singlebank : singlebanks) {
432 infoss << "Bank: " << singlebank << '\n';
433 }
434 g_log.debug(infoss.str());
435
436 Geometry::Instrument_const_sptr minstrument = m_maskWS->getInstrument();
437
438 for (auto &singlebank : singlebanks) {
439 std::vector<Geometry::IDetector_const_sptr> idetectors;
440
441 minstrument->getDetectorsInBank(idetectors, singlebank);
442 g_log.debug() << "Bank: " << singlebank << " has " << idetectors.size() << " detectors\n";
443
444 // a) get information
445 size_t numdets = idetectors.size();
446 detid_t detid_first = idetectors.front()->getID();
447 detid_t detid_last = idetectors.back()->getID();
448
449 // b) set detectors
450
451 for (const auto &det : idetectors) {
452 detid_t detid = det->getID();
453 detectors.emplace_back(detid);
454 }
455 g_log.debug() << "Number of Detectors in Bank " << singlebank << " is: " << numdets
456 << "\nRange From: " << detid_first << " To: " << detid_last << '\n';
457
458 } // ENDFOR
459}
460
461//----------------------------------------------------------------------------------------------
469void LoadMask::processMaskOnWorkspaceIndex(bool mask, std::vector<int32_t> &maskedSpecID,
470 std::vector<int32_t> &singleDetIds) {
471 // 1. Check
472 if (maskedSpecID.empty())
473 return;
474
475 if (m_sourceMapWS) {
476 // convert spectra masks into det-id mask using source workspace
477 convertSpMasksToDetIDs(*m_sourceMapWS, maskedSpecID, singleDetIds);
478 maskedSpecID.clear(); // spectra ID not needed any more as all converted to det-ids
479 return;
480 }
481 // 2. Get Map
482 const spec2index_map s2imap = m_maskWS->getSpectrumToWorkspaceIndexMap();
483
484 spec2index_map::const_iterator s2iter;
485
486 // 3. Set mask
487 auto spec0 = maskedSpecID[0];
488 auto prev_masks = spec0;
489 for (int spec2mask : maskedSpecID) {
490
491 s2iter = s2imap.find(spec2mask);
492 if (s2iter == s2imap.end()) {
493 // spectrum not found. bad branch
494 g_log.error() << "Spectrum " << spec2mask << " does not have an entry in GroupWorkspace's spec2index map\n";
495 throw std::runtime_error("Logic error");
496 } else {
497 size_t wsindex = s2iter->second;
498 if (wsindex >= m_maskWS->getNumberHistograms()) {
499 // workspace index is out of range. bad branch
500 g_log.error() << "Group workspace's spec2index map is set wrong: "
501 << " Found workspace index = " << wsindex << " for spectrum No " << spec2mask
502 << " with workspace size = " << m_maskWS->getNumberHistograms() << '\n';
503 } else {
504 // Finally set the masking;
505 m_maskWS->mutableY(wsindex)[0] = (mask) ? 1.0 : 0.0;
506 } // IF-ELSE: ws index out of range
507 } // IF-ELSE: spectrum No has an entry
508
509 if (spec2mask > prev_masks + 1) {
510 g_log.debug() << "Masked Spectrum " << spec0 << " To " << prev_masks << '\n';
511 spec0 = spec2mask;
512 }
513 } // FOR EACH SpecNo
514}
515
516//----------------------------------------------------------------------------------------------
520void LoadMask::initializeXMLParser(const std::string &filename) {
521 // const std::string instName
522 g_log.information() << "Load File " << filename << '\n';
523 const std::string xmlText = Kernel::Strings::loadFile(filename);
524 g_log.information("Successfully Load XML File");
525
526 // Set up the DOM parser and parse xml file
527 DOMParser pParser;
528 try {
529 m_pDoc = pParser.parseString(xmlText);
530 } catch (Poco::Exception &exc) {
531 throw Kernel::Exception::FileError(exc.displayText() + ". Unable to parse File:", filename);
532 } catch (...) {
533 throw Kernel::Exception::FileError("Unable to parse File:", filename);
534 }
535 // Get pointer to root element
536 m_pRootElem = m_pDoc->documentElement();
537 if (!m_pRootElem->hasChildNodes()) {
538 g_log.error("XML file: " + filename + "contains no root element.");
539 throw Kernel::Exception::InstrumentDefinitionError("No root element in XML instrument file", filename);
540 }
541}
542
543//----------------------------------------------------------------------------------------------
566 // 0. Check
567 if (!m_pDoc)
568 throw std::runtime_error("Call LoadMask::initialize() before parseXML.");
569
570 // 1. Parse and create a structure
571 Poco::AutoPtr<NodeList> pNL_type = m_pRootElem->getElementsByTagName("type");
572 g_log.information() << "Node Size = " << pNL_type->length() << '\n';
573
574 Poco::XML::NodeIterator it(m_pDoc, Poco::XML::NodeFilter::SHOW_ELEMENT);
575 Poco::XML::Node *pNode = it.nextNode();
576
577 std::vector<specnum_t> singleSp, pairSp;
578 std::vector<detid_t> maskSingleDet, maskPairDet;
579
580 bool ingroup = false;
581 while (pNode) {
582 const Poco::XML::XMLString value = pNode->innerText();
583
584 if (pNode->nodeName() == "group") {
585 // Node "group"
586 ingroup = true;
587
588 } else if (pNode->nodeName() == "component") {
589 // Node "component"
590 if (ingroup) {
591 m_maskCompIdSingle.emplace_back(value);
592 } else {
593 g_log.error() << "XML File hierarchical (component) error!\n";
594 }
595
596 } else if (pNode->nodeName() == "ids") {
597 // Node "ids"
598 if (ingroup) {
599 parseRangeText(value, singleSp, pairSp);
600 } else {
601 g_log.error() << "XML File (ids) hierarchical error!"
602 << " Inner Text = " << pNode->innerText() << '\n';
603 }
604
605 } else if (pNode->nodeName() == "detids") {
606 // Node "detids"
607 if (ingroup) {
608 parseRangeText(value, maskSingleDet, maskPairDet);
609 } else {
610 g_log.error() << "XML File (detids) hierarchical error!\n";
611 }
612
613 } else if (pNode->nodeName() == "detector-masking") {
614 // Node "detector-masking". Check default value
615 m_defaultToUse = true;
616 } // END-IF-ELSE: pNode->nodeName()
617
618 pNode = it.nextNode();
619 } // ENDWHILE
620
621 convertToVector(singleSp, pairSp, m_maskSpecID);
622 convertToVector(maskSingleDet, maskPairDet, m_maskDetID);
623 // NOTE: -- TODO: NOT IMPLEMENTD -- if unmasking is implemented, should be
624 // enabled
625 // convertToVector(umaskSingleDet, umaskPairDet, m_unMaskDetID);
626}
627
628/* Convert spectra mask into det-id mask using workspace as source of
629 *spectra-detector maps
630 *
631 * @param sourceWS -- the workspace containing source spectra-detector map
632 * to use on masks
633 * @param maskedSpecID -- vector of spectra id to mask
634 * @param singleDetIds -- output vector of detector ids to mask
635 */
636void LoadMask::convertSpMasksToDetIDs(const API::MatrixWorkspace &sourceWS, const std::vector<int32_t> &maskedSpecID,
637 std::vector<int32_t> &singleDetIds) {
638
640 detid2index_map sourceDetMap = sourceWS.getDetectorIDToWorkspaceIndexMap(false);
641
642 std::multimap<size_t, Mantid::detid_t> spectr2index_map;
643 for (auto &it : sourceDetMap) {
644 spectr2index_map.insert(std::pair<size_t, Mantid::detid_t>(it.second, it.first));
645 }
646 for (int i : maskedSpecID) {
647 // find spectra number from spectra ID for the source workspace
648 const auto itSpec = s2imap.find(i);
649 if (itSpec == s2imap.end()) {
650 throw std::runtime_error("Can not find spectra with ID: " + boost::lexical_cast<std::string>(i) +
651 " in the workspace" + sourceWS.getName());
652 }
653 size_t specN = itSpec->second;
654
655 // find detector range related to this spectra id in the source workspace
656 const auto source_range = spectr2index_map.equal_range(specN);
657 if (source_range.first == spectr2index_map.end()) {
658 throw std::runtime_error("Can not find spectra N: " + boost::lexical_cast<std::string>(specN) +
659 " in the workspace" + sourceWS.getName());
660 }
661 // add detectors to the masked det-id list
662 for (auto it = source_range.first; it != source_range.second; ++it) {
663 singleDetIds.emplace_back(it->second);
664 }
665 }
666}
667
668//----------------------------------------------------------------------------------------------
672
673 if (m_sourceMapWS) {
675 } else {
677 const bool ignoreDirs(true);
678 const std::string idfPath = API::FileFinder::Instance().getFullPath(m_instrumentPropValue, ignoreDirs);
679
680 auto loadInst = createChildAlgorithm("LoadInstrument");
681 loadInst->setProperty<MatrixWorkspace_sptr>("Workspace", tempWs);
682
683 if (idfPath.empty())
684 loadInst->setPropertyValue("InstrumentName", m_instrumentPropValue);
685 else
686 loadInst->setPropertyValue("Filename", m_instrumentPropValue);
687
688 loadInst->setProperty("RewriteSpectraMap", Mantid::Kernel::OptionalBool(false));
689 loadInst->executeAsChildAlg();
690
691 if (!loadInst->isExecuted()) {
692 g_log.error() << "Unable to load Instrument " << m_instrumentPropValue << '\n';
693 throw std::invalid_argument("Incorrect instrument name or invalid IDF given.");
694 }
695
697 }
698 m_maskWS->setTitle("Mask");
699}
700
705std::map<std::string, std::string> LoadMask::validateInputs() {
706
707 std::map<std::string, std::string> result;
708
709 API::MatrixWorkspace_sptr inputWS = getProperty("RefWorkspace");
710 std::string InstrName = getProperty("Instrument");
711 if (inputWS) {
712 boost::trim(InstrName);
713 boost::algorithm::to_lower(InstrName);
714 size_t len = InstrName.size();
717 bool IDF_provided{false};
718 // Check if the name ends up with .xml which means that idf file name
719 // is provided rather then an instrument name.
720 if (len > 4) {
721 if (InstrName.compare(len - 4, len, ".xml") == 0) {
722 IDF_provided = true;
723 } else {
724 IDF_provided = false;
725 }
726 } else {
727 IDF_provided = false;
728 }
729 try {
730 auto inst = inputWS->getInstrument();
731 std::string Name = inst->getName();
732 boost::algorithm::to_lower(Name);
733 if (Name != InstrName && !IDF_provided) {
734 result["RefWorkspace"] = "If both reference workspace and instrument name are defined, "
735 "workspace has to have the instrument with the same name\n"
736 "'Instrument' value: " +
737 InstrName + " Workspace Instrument name: " + Name;
738 }
740 result["RefWorkspace"] = "If reference workspace is defined, it mast have an instrument";
741 }
742 }
743
744 return result;
745}
746
748 // LoadMask instance may be reused, need to clear buffers.
749 m_maskDetID.clear();
750 m_unMaskDetID.clear();
751 m_maskSpecID.clear();
752 m_maskCompIdSingle.clear();
753 m_uMaskCompIdSingle.clear();
754}
755
756} // namespace Mantid::DataHandling
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
double value
The value of the point.
Definition: FitMW.cpp:51
double error
Definition: IndexPeaks.cpp:133
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
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.
Definition: Algorithm.cpp:842
Kernel::Logger & g_log
Definition: Algorithm.h:451
@ Load
allowed here which will be passed to the algorithm
Definition: FileProperty.h:52
Base MatrixWorkspace Abstract Class.
detid2index_map getDetectorIDToWorkspaceIndexMap(bool throwIfMultipleDets=false, bool ignoreIfNoValidDets=false) const
Return a map where: KEY is the DetectorID (pixel ID) VALUE is the Workspace Index.
spec2index_map getSpectrumToWorkspaceIndexMap() const
Return a map where: KEY is the Spectrum # VALUE is the Workspace Index.
A property class for workspaces.
const std::string & getName() const override
Get the workspace name.
Definition: Workspace.cpp:58
LoadMask : Load masking file to generate a SpecialWorkspace2D object (masking workspace).
Definition: LoadMask.h:34
DataObjects::MaskWorkspace_sptr m_maskWS
Mask Workspace.
Definition: LoadMask.h:80
void processMaskOnWorkspaceIndex(bool mask, std::vector< specnum_t > &maskedSpecID, std::vector< detid_t > &singleDetIds)
Convert spectrum to detector.
Definition: LoadMask.cpp:469
void processMaskOnDetectors(const detid2index_map &indexmap, bool tomask, const std::vector< detid_t > &singledetids)
Mask detectors or Unmask detectors.
Definition: LoadMask.cpp:348
void convertSpMasksToDetIDs(const API::MatrixWorkspace &sourceWS, const std::vector< specnum_t > &maskedSpecID, std::vector< detid_t > &singleDetIds)
Definition: LoadMask.cpp:636
std::vector< std::string > m_uMaskCompIdSingle
Definition: LoadMask.h:104
Poco::XML::Element * m_pRootElem
Root element of the parsed XML.
Definition: LoadMask.h:88
void componentToDetectors(const std::vector< std::string > &componentnames, std::vector< detid_t > &detectors)
Convert component to detectors.
Definition: LoadMask.cpp:374
std::map< std::string, std::string > validateInputs() override
Validates if either input workspace or instrument name is defined.
Definition: LoadMask.cpp:705
std::string m_instrumentPropValue
Instrument name.
Definition: LoadMask.h:82
std::vector< std::string > m_maskCompIdSingle
Definition: LoadMask.h:103
std::vector< detid_t > m_maskDetID
Definition: LoadMask.h:94
bool m_defaultToUse
Default setup. If true, not masking, but use the pixel.
Definition: LoadMask.h:91
void exec() override
Run the algorithm.
Definition: LoadMask.cpp:266
Poco::AutoPtr< Poco::XML::Document > m_pDoc
XML document loaded.
Definition: LoadMask.h:86
std::vector< specnum_t > m_maskSpecID
Definition: LoadMask.h:99
void intializeMaskWorkspace()
Initialize a Mask Workspace.
Definition: LoadMask.cpp:671
void initializeXMLParser(const std::string &filename)
Initialize XML parser.
Definition: LoadMask.cpp:520
void bankToDetectors(const std::vector< std::string > &singlebanks, std::vector< detid_t > &detectors)
Convert bank to detector.
Definition: LoadMask.cpp:428
std::vector< detid_t > m_unMaskDetID
Definition: LoadMask.h:96
API::MatrixWorkspace_sptr m_sourceMapWS
optional source workspace, containing spectra-detector mapping
Definition: LoadMask.h:84
Concrete workspace implementation.
Definition: Workspace2D.h:29
Records the filename and the description of failure.
Definition: Exception.h:98
Exception for errors associated with the instrument definition.
Definition: Exception.h:220
Exception for when an item is not found in a collection.
Definition: Exception.h:145
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.
Definition: Logger.cpp:114
void error(const std::string &msg)
Logs at error level.
Definition: Logger.cpp:77
void warning(const std::string &msg)
Logs at warning level.
Definition: Logger.cpp:86
void information(const std::string &msg)
Logs at information level.
Definition: Logger.cpp:105
Validator to check that a property is not left empty.
OptionalBool : Tri-state bool.
Definition: OptionalBool.h:25
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< MaskWorkspace > MaskWorkspace_sptr
shared pointer to the MaskWorkspace class
Definition: MaskWorkspace.h:64
std::shared_ptr< const IComponent > IComponent_const_sptr
Typdef of a shared pointer to a const IComponent.
Definition: IComponent.h:161
std::shared_ptr< const Mantid::Geometry::IDetector > IDetector_const_sptr
Shared pointer to IDetector (const version)
Definition: IDetector.h:102
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
MANTID_KERNEL_DLL std::string loadFile(const std::string &filename)
Loads the entire contents of a text file into a string.
Definition: Strings.cpp:28
std::unordered_map< specnum_t, size_t > spec2index_map
Map with key = spectrum number, value = workspace index.
int32_t detid_t
Typedef for a detector ID.
Definition: SpectrumInfo.h:21
std::unordered_map< detid_t, size_t > detid2index_map
Map with key = detector ID, value = workspace index.
STL namespace.
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54