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");
66 std::vector<detid_t> detid0s;
67 for (
size_t i = 0; i < inpWS->getNumberHistograms(); i++) {
68 if (inpWS->y(i).front() > 0.1) {
70 const auto &ids = inpWS->getSpectrum(i).getDetectorIDs();
71 std::copy(ids.cbegin(), ids.cend(), std::back_inserter(detid0s));
76 g_log.
debug() <<
"Number of detectors to be masked = " << detid0s.size() <<
'\n';
79 std::vector<detid_t> idx0sts;
80 std::vector<detid_t> idx0eds;
82 if (!detid0s.empty()) {
83 std::sort(detid0s.begin(), detid0s.end());
88 for (
size_t i = 1; i < detid0s.size(); i++) {
90 if (detid0s[i] == detid0s[i - 1] + 1) {
96 idx0sts.emplace_back(i0st);
97 idx0eds.emplace_back(i0ed);
106 idx0sts.emplace_back(i0st);
107 idx0eds.emplace_back(i0ed);
109 for (
size_t i = 0; i < idx0sts.size(); i++) {
110 g_log.
information() <<
"Section " << i <<
" : " << idx0sts[i] <<
" , " << idx0eds[i]
111 <<
" to be masked and recorded.\n";
117 AutoPtr<Document> pDoc =
new Document;
118 AutoPtr<Element> pRoot = pDoc->createElement(
"detector-masking");
119 pDoc->appendChild(pRoot);
123 AutoPtr<Element> pChildGroup = pDoc->createElement(
"group");
125 pRoot->appendChild(pChildGroup);
129 std::stringstream ss;
130 for (
size_t i = 0; i < idx0sts.size(); i++) {
131 size_t ist = idx0sts[i];
132 size_t ied = idx0eds[i];
135 bool writedata =
true;
137 ss << ist <<
"-" << ied;
138 }
else if (ist == ied) {
144 if (writedata && i < idx0sts.size() - 1) {
149 std::string textvalue = ss.str();
150 g_log.
debug() <<
"SaveMask main text: available section = " << idx0sts.size() <<
"\n" << textvalue <<
'\n';
153 AutoPtr<Element> pDetid = pDoc->createElement(
"detids");
154 AutoPtr<Text> pText1 = pDoc->createTextNode(textvalue);
155 pDetid->appendChild(pText1);
156 pChildGroup->appendChild(pDetid);
160 writer.setNewLine(
"\n");
161 writer.setOptions(XMLWriter::PRETTY_PRINT);
164 ofs.open(outxmlfilename.c_str(), std::fstream::out);
166 ofs <<
"<?xml version=\"1.0\"?>\n";
168 writer.writeNode(std::cout, pDoc);
169 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.