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