14#include <Poco/DOM/AutoPtr.h>
15#include <Poco/DOM/DOMWriter.h>
16#include <Poco/DOM/Document.h>
17#include <Poco/DOM/Element.h>
18#include <Poco/DOM/Text.h>
19#include <Poco/XML/XMLWriter.h>
39 "Workspace to output masking to XML file");
40 declareProperty(std::make_unique<FileProperty>(
"OutputFile",
"",
FileProperty::Save,
".xml"),
41 "File to save the detectors mask in XML format");
53 emAlg->setProperty(
"InputWorkspace", userInputWS);
54 emAlg->setPropertyValue(
"OutputWorkspace",
"tmp");
58 inpWS = std::dynamic_pointer_cast<DataObjects::SpecialWorkspace2D>(ws);
60 throw std::runtime_error(
"Unable to extract masking data using ExtractMask");
67 std::vector<detid_t> detid0s;
68 for (
size_t i = 0; i < inpWS->getNumberHistograms(); i++) {
69 if (inpWS->y(i).front() > 0.1) {
71 const auto &ids = inpWS->getSpectrum(i).getDetectorIDs();
72 std::copy(ids.cbegin(), ids.cend(), std::back_inserter(detid0s));
77 g_log.
debug() <<
"Number of detectors to be masked = " << detid0s.size() <<
'\n';
80 std::vector<detid_t> idx0sts;
81 std::vector<detid_t> idx0eds;
83 if (!detid0s.empty()) {
84 std::sort(detid0s.begin(), detid0s.end());
89 for (
size_t i = 1; i < detid0s.size(); i++) {
91 if (detid0s[i] == detid0s[i - 1] + 1) {
97 idx0sts.emplace_back(i0st);
98 idx0eds.emplace_back(i0ed);
107 idx0sts.emplace_back(i0st);
108 idx0eds.emplace_back(i0ed);
110 for (
size_t i = 0; i < idx0sts.size(); i++) {
111 g_log.
information() <<
"Section " << i <<
" : " << idx0sts[i] <<
" , " << idx0eds[i]
112 <<
" to be masked and recorded.\n";
118 AutoPtr<Document> pDoc =
new Document;
119 AutoPtr<Element> pRoot = pDoc->createElement(
"detector-masking");
120 pDoc->appendChild(pRoot);
124 AutoPtr<Element> pChildGroup = pDoc->createElement(
"group");
126 pRoot->appendChild(pChildGroup);
130 std::stringstream ss;
131 for (
size_t i = 0; i < idx0sts.size(); i++) {
132 size_t ist = idx0sts[i];
133 size_t ied = idx0eds[i];
136 bool writedata =
true;
138 ss << ist <<
"-" << ied;
139 }
else if (ist == ied) {
145 if (writedata && i < idx0sts.size() - 1) {
150 std::string textvalue = ss.str();
151 g_log.
debug() <<
"SaveMask main text: available section = " << idx0sts.size() <<
"\n" << textvalue <<
'\n';
154 AutoPtr<Element> pDetid = pDoc->createElement(
"detids");
155 AutoPtr<Text> pText1 = pDoc->createTextNode(textvalue);
156 pDetid->appendChild(pText1);
157 pChildGroup->appendChild(pDetid);
161 writer.setNewLine(
"\n");
162 writer.setOptions(XMLWriter::PRETTY_PRINT);
165 ofs.open(outxmlfilename.c_str(), std::fstream::out);
167 ofs <<
"<?xml version=\"1.0\"?>\n";
169 writer.writeNode(std::cout, pDoc);
170 writer.writeNode(ofs, pDoc);
#define DECLARE_ALGORITHM(classname)
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
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.
bool isLogging() const override
returns the status of logging, True = enabled
@ Save
to specify a file to write to, the file may or may not exist
A property class for workspaces.
SaveMaskingToFile : TODO: DESCRIPTION.
void exec() override
Main body to execute algorithm.
void debug(const std::string &msg)
Logs at debug level.
void information(const std::string &msg)
Logs at information level.
std::shared_ptr< Algorithm > Algorithm_sptr
Typedef for a shared pointer to an Algorithm.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< SpecialWorkspace2D > SpecialWorkspace2D_sptr
shared pointer to the SpecialWorkspace2D class
int32_t detid_t
Typedef for a detector ID.
@ Input
An input workspace.