52 emAlg->setProperty(
"InputWorkspace", userInputWS);
53 emAlg->setPropertyValue(
"OutputWorkspace",
"tmp");
57 inpWS = std::dynamic_pointer_cast<DataObjects::SpecialWorkspace2D>(ws);
59 throw std::runtime_error(
"Unable to extract masking data using ExtractMask");
64 if (!outxmlfilename.ends_with(
".xml")) {
65 outxmlfilename +=
".xml";
70 std::vector<detid_t> detid0s;
71 for (
size_t i = 0; i < inpWS->getNumberHistograms(); i++) {
72 if (inpWS->y(i).front() > 0.1) {
74 const auto &ids = inpWS->getSpectrum(i).getDetectorIDs();
75 std::copy(ids.cbegin(), ids.cend(), std::back_inserter(detid0s));
80 g_log.
debug() <<
"Number of detectors to be masked = " << detid0s.size() <<
'\n';
83 std::vector<detid_t> idx0sts;
84 std::vector<detid_t> idx0eds;
86 if (!detid0s.empty()) {
87 std::sort(detid0s.begin(), detid0s.end());
92 for (
size_t i = 1; i < detid0s.size(); i++) {
94 if (detid0s[i] == detid0s[i - 1] + 1) {
100 idx0sts.emplace_back(i0st);
101 idx0eds.emplace_back(i0ed);
110 idx0sts.emplace_back(i0st);
111 idx0eds.emplace_back(i0ed);
113 for (
size_t i = 0; i < idx0sts.size(); i++) {
114 g_log.
information() <<
"Section " << i <<
" : " << idx0sts[i] <<
" , " << idx0eds[i]
115 <<
" to be masked and recorded.\n";
121 AutoPtr<Document> pDoc =
new Document;
122 AutoPtr<Element> pRoot = pDoc->createElement(
"detector-masking");
123 pDoc->appendChild(pRoot);
127 AutoPtr<Element> pChildGroup = pDoc->createElement(
"group");
129 pRoot->appendChild(pChildGroup);
133 std::stringstream ss;
134 for (
size_t i = 0; i < idx0sts.size(); i++) {
135 size_t ist = idx0sts[i];
136 size_t ied = idx0eds[i];
139 bool writedata =
true;
141 ss << ist <<
"-" << ied;
142 }
else if (ist == ied) {
148 if (writedata && i < idx0sts.size() - 1) {
153 std::string textvalue = ss.str();
154 g_log.
debug() <<
"SaveMask main text: available section = " << idx0sts.size() <<
"\n" << textvalue <<
'\n';
157 AutoPtr<Element> pDetid = pDoc->createElement(
"detids");
158 AutoPtr<Text> pText1 = pDoc->createTextNode(textvalue);
159 pDetid->appendChild(pText1);
160 pChildGroup->appendChild(pDetid);
164 writer.setNewLine(
"\n");
165 writer.setOptions(XMLWriter::PRETTY_PRINT);
168 ofs.open(outxmlfilename.c_str(), std::fstream::out);
170 ofs <<
"<?xml version=\"1.0\"?>\n";
172 writer.writeNode(std::cout, pDoc);
173 writer.writeNode(ofs, pDoc);
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.