19#include <Poco/DOM/DOMParser.h>
20#include <Poco/DOM/Document.h>
21#include <Poco/DOM/Element.h>
22#include <Poco/DOM/NodeList.h>
36using namespace Kernel;
52 std::make_shared<InstrumentValidator>()),
53 "A workspace that refers to the instrument of interest. You "
54 "can use [[LoadEmptyInstrument]] to create such a "
58 const std::vector<std::string> exts{
".cal",
".xml"};
60 "Either as a XML grouping file (see [[GroupDetectors]]) or as a "
61 "[[CalFile]] (.cal extension).");
63 std::vector<std::string> select{
"True",
"False"};
64 declareProperty(
"ShowUnselected",
"True", std::make_shared<StringListValidator>(select),
65 "Whether to show detectors that are not in any group");
69 "The name of the output workspace");
90 throw std::runtime_error(
"Failed when creating a Workspace2D from the input!");
92 const std::string groupfile =
getProperty(
"GroupingFilename");
94 if (!groupfile.empty()) {
95 std::string filename(groupfile);
96 std::transform(filename.begin(), filename.end(), filename.begin(), tolower);
97 if (filename.find(
".xml") != std::string::npos) {
105 const int64_t nHist = localWorkspace->getNumberHistograms();
108 const std::string su =
getProperty(
"ShowUnselected");
109 auto showunselected = bool(su ==
"True");
110 bool success =
false;
112 for (int64_t i = 0; i < nHist; i++) {
113 auto &spec = localWorkspace->getSpectrum(i);
114 const auto &dets = spec.getDetectorIDs();
117 spec.mutableY()[0] = 0.0;
121 calmap::const_iterator it =
calibration.find(*dets.begin());
124 spec.mutableY()[0] = 0.0;
127 if (showunselected) {
128 if (((*it).second).second == 0)
129 spec.mutableY()[0] = 0.0;
131 spec.mutableY()[0] =
static_cast<double>(((*it).second).first);
133 spec.mutableY()[0] =
static_cast<double>(((*it).second).first);
142 localWorkspace.reset();
143 throw std::runtime_error(
"Fail to found a detector in " + groupfile +
" existing in instrument " + inst->getName());
154 std::ifstream grFile(filename.c_str());
155 if (!grFile.is_open()) {
156 g_log.
error() <<
"Unable to open grouping file " << filename <<
'\n';
161 while (getline(grFile, str)) {
163 if (str.empty() || str[0] ==
'#')
165 std::istringstream istr(str);
166 int n, udet, sel, group;
168 istr >>
n >> udet >> offset >> sel >> group;
183 Poco::XML::DOMParser xmlParser;
184 Poco::AutoPtr<Poco::XML::Document> file;
186 file = xmlParser.parse(filename);
191 Poco::XML::Element *root = file->documentElement();
193 if (!root->hasChildNodes()) {
197 Poco::AutoPtr<Poco::XML::NodeList> groups = root->getElementsByTagName(
"group");
199 if (groups->length() == 0) {
203 auto nGroups =
static_cast<unsigned int>(groups->length());
204 for (
unsigned int i = 0; i < nGroups; i++) {
206 auto *elem =
static_cast<Poco::XML::Element *
>(groups->item(i));
207 Poco::XML::Element *group = elem->getChildElement(
"detids");
213 std::string ids = group->getAttribute(
"val");
218 for (
const auto &
value : data) {
222 detID = boost::lexical_cast<int>(
value);
223 }
catch (boost::bad_lexical_cast &) {
229 calibration[detID] = std::pair<int, int>(i + 1, 1);
#define DECLARE_ALGORITHM(classname)
double value
The value of the point.
Base class from which all concrete algorithm classes should be derived.
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
A specialized class for dealing with file properties.
@ Load
allowed here which will be passed to the algorithm
Base MatrixWorkspace Abstract Class.
A property class for workspaces.
void exec() override
Execution code.
ReadGroupsFromFile()
(Empty) Constructor
void init() override
Initialisation code.
void readXMLGroupingFile(const std::string &filename)
Read an XML Grouping File.
void readGroupingFile(const std::string &filename)
Read a grouping file and construct the calibration map.
calmap calibration
Calibration map containing the detector entries found in the *.cal file.
Records the filename and the description of failure.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void error(const std::string &msg)
Logs at error level.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
Iterator begin()
Iterator referring to first element in the container.
@ TOK_TRIM
remove leading and trailing whitespace from tokens
Iterator end()
Iterator referring to the past-the-end element in the container.
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< Workspace2D > Workspace2D_sptr
shared pointer to Mantid::DataObjects::Workspace2D
std::unique_ptr< T > create(const P &parent, const IndexArg &indexArg, const HistArg &histArg)
This is the create() method that all the other create() methods call.
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
@ Input
An input workspace.
@ Output
An output workspace.