Mantid
Loading...
Searching...
No Matches
LoadSpice2D.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 +
9#include "MantidAPI/Axis.h"
12#include "MantidAPI/Run.h"
23
24#include <boost/lexical_cast.hpp>
25#include <boost/regex.hpp>
26
28#include <Poco/DOM/DOMParser.h>
29#include <Poco/DOM/Document.h>
30#include <Poco/DOM/Element.h>
31#include <Poco/DOM/Node.h>
32#include <Poco/DOM/NodeList.h>
33#include <Poco/DOM/Text.h>
34#include <Poco/Path.h>
35#include <Poco/SAX/InputSource.h>
36
37#include <algorithm>
38#include <memory>
39#include <sstream>
40#include <string>
41#include <utility>
42#include <vector>
43
44using Poco::XML::Document;
45using Poco::XML::DOMParser;
46using Poco::XML::Element;
47
48namespace Mantid::DataHandling {
49
52using Types::Core::DateAndTime;
53using namespace Kernel;
54using namespace API;
55using namespace Geometry;
56using namespace DataObjects;
57
58// Register the algorithm into the AlgorithmFactory
60
61// Parse string and convert to numeric type
62template <class T> bool from_string(T &t, const std::string &s, std::ios_base &(*f)(std::ios_base &)) {
63 std::istringstream iss(s);
64 return !(iss >> f >> t).fail();
65}
66
78void store_value(const DataObjects::Workspace2D_sptr &ws, int specID, double value, double error, double wavelength,
79 double dwavelength) {
80 auto &X = ws->mutableX(specID);
81 auto &Y = ws->mutableY(specID);
82 auto &E = ws->mutableE(specID);
83 // The following is mostly to make Mantid happy by defining a histogram with
84 // a single bin around the neutron wavelength
85 X[0] = wavelength - dwavelength / 2.0;
86 X[1] = wavelength + dwavelength / 2.0;
87 Y[0] = value;
88 E[0] = error;
89 ws->getSpectrum(specID).setSpectrumNo(specID);
90}
91
99 if (descriptor.extension() != ".xml")
100 return 0;
101
102 std::istream &is = descriptor.data();
103 int confidence(0);
104
105 { // start of inner scope
106 Poco::XML::InputSource src(is);
107 // Set up the DOM parser and parse xml file
108 DOMParser pParser;
109 Poco::AutoPtr<Document> pDoc;
110 try {
111 pDoc = pParser.parse(&src);
112 } catch (Poco::Exception &e) {
113 throw Kernel::Exception::FileError("Unable to parse File (" + descriptor.filename() + ")", e.displayText());
114 } catch (...) {
115 throw Kernel::Exception::FileError("Unable to parse File:", descriptor.filename());
116 }
117 // Get pointer to root element
118 Element *pRootElem = pDoc->documentElement();
119 if (pRootElem) {
120 if (pRootElem->tagName() == "SPICErack") {
121 confidence = 80;
122 }
123 }
124 } // end of inner scope
125
126 return confidence;
127}
128
131 declareProperty(std::make_unique<API::FileProperty>("Filename", "", API::FileProperty::Load, ".xml"),
132 "The name of the input xml file to load");
134 std::make_unique<API::WorkspaceProperty<API::Workspace>>("OutputWorkspace", "", Kernel::Direction::Output),
135 "The name of the Output workspace");
136
137 // Optionally, we can specify the wavelength and wavelength spread and
138 // overwrite
139 // the value in the data file (used when the data file is not populated)
140 auto mustBePositive = std::make_shared<Kernel::BoundedValidator<double>>();
141 mustBePositive->setLower(0.0);
142 declareProperty("Wavelength", EMPTY_DBL(), mustBePositive,
143 "Optional wavelength value to use when loading the data file "
144 "(Angstrom). This value will be used instead of the value "
145 "found in the data file.");
146 declareProperty("WavelengthSpread", 0.1, mustBePositive,
147 "Optional wavelength spread value to use when loading the "
148 "data file (Angstrom). This value will be used instead of "
149 "the value found in the data file.");
150}
151
152/*
153 * Main method.
154 * Creates an XML handler. All tag values will be a map.
155 * Creates and loads the workspace with the data
156 *
157 */
159
161 setTimes();
162 const std::vector<std::string> tags_to_ignore{"Detector", "DetectorWing"};
163 std::map<std::string, std::string> metadata = m_xmlHandler.get_metadata(tags_to_ignore);
164
166 setWavelength(metadata);
167
168 std::vector<int> data = getData("//Data");
169
170 double monitorCounts = 0;
171 from_string<double>(monitorCounts, metadata["Counters/monitor"], std::dec);
172 double countingTime = 0;
173 from_string<double>(countingTime, metadata["Counters/time"], std::dec);
174 createWorkspace(data, metadata["Header/Scan_Title"], monitorCounts, countingTime);
175
176 // Add all metadata to the WS
178
180
181 // run load instrument
182 std::string instrument = metadata["Header/Instrument"];
183
184 // ugly hack for Biosans wing detector:
185 // it tests if there is metadata tagged with the wing detector
186 // if so, puts the detector in the right angle
187 if (metadata.find("Motor_Positions/det_west_wing_rot") != metadata.end()) {
188 auto angle = boost::lexical_cast<double>(metadata["Motor_Positions/det_west_wing_rot"]);
189 rotateDetector(-angle);
190 }
191 // sample_detector_distances
192 detectorDistance(metadata);
193 detectorTranslation(metadata);
194 runLoadInstrument(instrument, m_workspace);
195 setProperty("OutputWorkspace", m_workspace);
196}
197
202std::pair<int, int> LoadSpice2D::parseDetectorDimensions(const std::string &dims_str) {
203
204 // Read in the detector dimensions from the Detector tag
205
206 std::pair<int, int> dims = std::make_pair(0, 0);
207
208 boost::regex b_re_sig(R"(INT\d+\[(\d+),(\d+)\])");
209 if (boost::regex_match(dims_str, b_re_sig)) {
210 boost::match_results<std::string::const_iterator> match;
211 boost::regex_search(dims_str, match, b_re_sig);
212 // match[0] is the full string
213 Kernel::Strings::convert(match[1], dims.first);
214 Kernel::Strings::convert(match[2], dims.second);
215 }
216 if (dims.first == 0 || dims.second == 0)
217 g_log.notice() << "Could not read in the number of pixels!" << '\n';
218 return dims;
219}
220
225void LoadSpice2D::addMetadataAsRunProperties(const std::map<std::string, std::string> &metadata) {
226
227 for (const auto &keyValuePair : metadata) {
228 std::string key = keyValuePair.first;
229 std::replace(key.begin(), key.end(), '/', '_');
230 m_workspace->mutableRun().addProperty(key, keyValuePair.second, true);
231 }
232}
233
238
239 m_wavelength_input = getProperty("Wavelength");
240 m_wavelength_spread_input = getProperty("WavelengthSpread");
241
242 g_log.debug() << "setInputPropertiesAsMemberProperties: " << m_wavelength_input << " , " << m_wavelength_input
243 << '\n';
244
245 std::string fileName = getPropertyValue("Filename");
246 // Set up the XmlHandler handler and parse xml file
247 try {
248 m_xmlHandler = XmlHandler(fileName);
249 } catch (...) {
250 throw Kernel::Exception::FileError("Unable to parse File:", fileName);
251 }
252}
253
258void LoadSpice2D::setWavelength(std::map<std::string, std::string> &metadata) {
259 // Read in wavelength and wavelength spread
260
261 g_log.debug() << "setWavelength: " << m_wavelength_input << " , " << m_wavelength_input << '\n';
262
264 std::string s = metadata["Header/wavelength"];
265 from_string<double>(m_wavelength, s, std::dec);
266 s = metadata["Header/wavelength_spread"];
267 from_string<double>(m_dwavelength, s, std::dec);
268
269 // 20160720: New wavelength will be a ratio
270 // UGLY HACK! Comparing dates...
271 DateAndTime changingDate("2016-06-13 00:00:00");
272 if (m_startTime >= changingDate) {
273 g_log.debug() << "Using wavelength spread as a ratio" << '\n';
275 }
276
277 g_log.debug() << "setWavelength: " << m_wavelength << " , " << m_dwavelength << '\n';
278
279 } else {
282 }
283}
288std::vector<int> LoadSpice2D::getData(const std::string &dataXpath = "//Data") {
289
290 // data container
291 std::vector<int> data;
292 unsigned int totalDataSize = 0;
293
294 // let's see how many detectors we have
295 std::vector<std::string> detectors = m_xmlHandler.get_subnodes(dataXpath);
296 g_log.debug() << "Number the detectors found in Xpath " << dataXpath << " = " << detectors.size() << '\n';
297
298 // iterate every detector in the xml file
299 for (const auto &detector : detectors) {
300 std::string detectorXpath = std::string(dataXpath).append("/").append(detector);
301 // type : INT32[192,256]
302 std::map<std::string, std::string> attributes = m_xmlHandler.get_attributes_from_tag(detectorXpath);
303 std::pair<int, int> dims = parseDetectorDimensions(attributes["type"]);
304
305 // Horrible hack:
306 // Some old files had a: //Data/DetectorWing with dimensions:
307 // 16 x 256 = 4096. This must be ignored as it is not in the IDF.
308 if (detectorXpath.find("DetectorWing") != std::string::npos && dims.first * dims.second <= 4096)
309 break;
310
311 totalDataSize += dims.first * dims.second;
312 g_log.debug() << "Parsing detector XPath " << detectorXpath << " with dimensions: " << dims.first << " x "
313 << dims.second << " = " << dims.first * dims.second << '\n';
314
315 std::string data_str = m_xmlHandler.get_text_from_tag(detectorXpath);
316 g_log.debug() << "The size of detector contents (xpath = " << detectorXpath << ") is " << data_str.size()
317 << " bytes." << '\n';
318
319 // convert string data into a vector<int>
320 std::stringstream iss(data_str);
321 double number;
322 while (iss >> number) {
323 data.emplace_back(static_cast<int>(number));
324 }
325 g_log.debug() << "Detector XPath: " << detectorXpath
326 << " parsed. Total size of data processed up to now = " << data.size() << " from a total of "
327 << totalDataSize << '\n';
328 }
329
330 if (data.size() != totalDataSize) {
331 g_log.error() << "Total data size = " << totalDataSize << ". Parsed data size = " << data.size() << '\n';
332 throw Kernel::Exception::NotImplementedError("Inconsistent data set: There were more data pixels found than "
333 "declared in the Spice XML meta-data.");
334 }
335 return data;
336}
337
341void LoadSpice2D::createWorkspace(const std::vector<int> &data, const std::string &title, double monitor1_counts,
342 double monitor2_counts) {
343 int nBins = 1;
344 int numSpectra = static_cast<int>(data.size()) + LoadSpice2D::nMonitors;
345
346 m_workspace = std::dynamic_pointer_cast<DataObjects::Workspace2D>(
347 API::WorkspaceFactory::Instance().create("Workspace2D", numSpectra, nBins + 1, nBins));
348 m_workspace->setTitle(title);
349 m_workspace->getAxis(0)->unit() = Kernel::UnitFactory::Instance().create("Wavelength");
350 m_workspace->setYUnit("");
351
352 int specID = 0;
353 // Store monitor counts in the beggining
354 store_value(m_workspace, specID++, monitor1_counts, monitor1_counts > 0 ? sqrt(monitor1_counts) : 0.0, m_wavelength,
356 store_value(m_workspace, specID++, monitor2_counts, 0.0, m_wavelength, m_dwavelength);
357
358 // Store detector pixels
359 for (auto count : data) {
360 // Data uncertainties, computed according to the HFIR/IGOR reduction code
361 // The following is what I would suggest instead...
362 // error = count > 0 ? sqrt((double)count) : 0.0;
363 double error = sqrt(0.5 + fabs(static_cast<double>(count) - 0.5));
365 }
366}
367
371template <class T>
372T LoadSpice2D::addRunProperty(std::map<std::string, std::string> &metadata, const std::string &oldName,
373 const std::string &newName, const std::string &units) {
374
375 std::string value_str = metadata[oldName];
376 T value;
377 from_string<T>(value, value_str, std::dec);
378 m_workspace->mutableRun().addProperty(newName, value, units, true);
379 return value;
380}
381
382template <class T> void LoadSpice2D::addRunProperty(const std::string &name, const T &value, const std::string &units) {
383 m_workspace->mutableRun().addProperty(name, value, units, true);
384}
385
401void LoadSpice2D::setBeamTrapRunProperty(std::map<std::string, std::string> &metadata) {
402
403 std::vector<double> trapDiameters = {76.2, 50.8, 76.2, 101.6};
404 // default use the shortest trap
405 double trapDiameterInUse = trapDiameters[1];
406
407 std::vector<double> trapMotorPositions;
408 trapMotorPositions.emplace_back(boost::lexical_cast<double>(metadata["Motor_Positions/trap_y_25mm"]));
409 trapMotorPositions.emplace_back(boost::lexical_cast<double>(metadata["Motor_Positions/trap_y_50mm"]));
410 trapMotorPositions.emplace_back(boost::lexical_cast<double>(metadata["Motor_Positions/trap_y_76mm"]));
411 trapMotorPositions.emplace_back(boost::lexical_cast<double>(metadata["Motor_Positions/trap_y_101mm"]));
412
413 // Check how many traps are in use (store indexes):
414 std::vector<size_t> trapIndexInUse;
415 for (size_t i = 0; i < trapMotorPositions.size(); i++) {
416 if (trapMotorPositions[i] > 26.0) {
417 // Resting positions are below 25. Make sure we have one trap in use!
418 trapIndexInUse.emplace_back(i);
419 }
420 }
421
422 g_log.debug() << "trapIndexInUse length:" << trapIndexInUse.size() << "\n";
423
424 // store trap diameters in use
425 std::vector<double> trapDiametersInUse;
426 trapDiametersInUse.reserve(trapIndexInUse.size());
427 std::transform(trapIndexInUse.cbegin(), trapIndexInUse.cend(), std::back_inserter(trapDiametersInUse),
428 [&trapDiameters](const auto index) { return trapDiameters[index]; });
429
430 g_log.debug() << "trapDiametersInUse length:" << trapDiametersInUse.size() << "\n";
431
432 // The maximum value for the trapDiametersInUse is the trap in use
433 auto trapDiameterInUseIt = std::max_element(trapDiametersInUse.begin(), trapDiametersInUse.end());
434 if (trapDiameterInUseIt != trapDiametersInUse.end())
435 trapDiameterInUse = *trapDiameterInUseIt;
436
437 g_log.debug() << "trapDiameterInUse:" << trapDiameterInUse << "\n";
438
439 addRunProperty<double>("beam-trap-diameter", trapDiameterInUse, "mm");
440}
441
443 // start_time
444 std::map<std::string, std::string> attributes = m_xmlHandler.get_attributes_from_tag("/");
445
446 m_startTime = DateAndTime(attributes["start_time"]);
447 m_endTime = DateAndTime(attributes["end_time"]);
448}
449
450void LoadSpice2D::setMetadataAsRunProperties(std::map<std::string, std::string> &metadata) {
451
452 setBeamTrapRunProperty(metadata);
453
454 addRunProperty<std::string>("start_time", m_startTime.toISO8601String(), "");
455 addRunProperty<std::string>("run_start", m_startTime.toISO8601String(), "");
456
457 m_workspace->mutableRun().setStartAndEndTime(m_startTime, m_endTime);
458
459 // sample thickness
460 // XML 1.03: source distance is now in meters
461 double sample_thickness;
462 from_string<double>(sample_thickness, metadata["Header/Sample_Thickness"], std::dec);
463 if (m_sansSpiceXmlFormatVersion >= 1.03) {
464 g_log.debug() << "sans_spice_xml_format_version >= 1.03 :: sample_thickness "
465 "in mm. Converting to cm...";
466 sample_thickness *= 0.1;
467 }
468 addRunProperty<double>("sample-thickness", sample_thickness, "cm");
469
470 addRunProperty<double>(metadata, "Header/Sample_Thickness", "sample-thickness", "mm");
471
472 addRunProperty<double>(metadata, "Header/source_aperture_size", "source-aperture-diameter", "mm");
473 addRunProperty<double>(metadata, "Header/sample_aperture_size", "sample-aperture-diameter", "mm");
474
475 // XML 1.03: source distance is now in meters
476 double source_distance;
477 from_string<double>(source_distance, metadata["Header/source_distance"], std::dec);
478 if (m_sansSpiceXmlFormatVersion >= 1.03) {
479 g_log.debug() << "sans_spice_xml_format_version >= 1.03 :: source_distance "
480 "in meters. Converting to mm...";
481 source_distance *= 1000.0;
482 }
483 addRunProperty<double>("source-sample-distance", source_distance, "mm");
484
485 addRunProperty<int>(metadata, "Motor_Positions/nguides", "number-of-guides", "");
486
487 addRunProperty<double>("wavelength", m_wavelength, "Angstrom");
488 addRunProperty<double>("wavelength-spread", m_dwavelength, "Angstrom");
489 addRunProperty<double>("wavelength-spread-ratio", m_dwavelength / m_wavelength);
490
491 addRunProperty<double>(metadata, "Counters/monitor", "monitor", "");
492 addRunProperty<double>(metadata, "Counters/time", "timer", "sec");
493}
494
515void LoadSpice2D::detectorDistance(std::map<std::string, std::string> &metadata) {
516
517 double sample_detector_distance = 0, sample_detector_distance_offset = 0, sample_si_window_distance = 0;
518
519 // check if it's the new format
520 if (metadata.find("Motor_Positions/sample_det_dist") != metadata.end()) {
521 // Old Format
522 from_string<double>(sample_detector_distance, metadata["Motor_Positions/sample_det_dist"], std::dec);
523 sample_detector_distance *= 1000.0;
524 addRunProperty<double>("sample-detector-distance", sample_detector_distance, "mm");
525 sample_detector_distance_offset =
526 addRunProperty<double>(metadata, "Header/tank_internal_offset", "sample-detector-distance-offset", "mm");
527 sample_si_window_distance =
528 addRunProperty<double>(metadata, "Header/sample_to_flange", "sample-si-window-distance", "mm");
529
530 } else {
531 // New format:
532 from_string<double>(sample_detector_distance, metadata["Motor_Positions/flange_det_dist"], std::dec);
533 sample_detector_distance *= 1000.0;
534 addRunProperty<double>("sample-detector-distance-offset", 0, "mm");
535 addRunProperty<double>("sample-detector-distance", sample_detector_distance, "mm");
536 sample_si_window_distance =
537 addRunProperty<double>(metadata, "Header/sample_to_flange", "sample-si-window-distance", "mm");
538 }
539
540 double total_sample_detector_distance;
541 if (metadata.find("Motor_Positions/sdd") != metadata.end()) {
542
543 // When sdd exists overrides all the distances
544 from_string<double>(total_sample_detector_distance, metadata["Motor_Positions/sdd"], std::dec);
545 total_sample_detector_distance *= 1000.0;
546 sample_detector_distance = total_sample_detector_distance;
547
548 addRunProperty<double>("sample-detector-distance-offset", 0, "mm");
549 addRunProperty<double>("sample-detector-distance", sample_detector_distance, "mm");
550 addRunProperty<double>("sample-si-window-distance", 0, "mm");
551
552 g_log.debug() << "Sample-Detector-Distance from SDD tag = " << total_sample_detector_distance << '\n';
553
554 } else {
555 total_sample_detector_distance =
556 sample_detector_distance + sample_detector_distance_offset + sample_si_window_distance;
557 }
558 addRunProperty<double>("total-sample-detector-distance", total_sample_detector_distance, "mm");
559
560 // Add to the log!
561 API::Run &runDetails = m_workspace->mutableRun();
563 p->addValue(DateAndTime::getCurrentTime(), total_sample_detector_distance);
564 runDetails.addLogData(p);
565
566 // Store sample-detector distance
567 declareProperty("SampleDetectorDistance", sample_detector_distance, Kernel::Direction::Output);
568}
572void LoadSpice2D::detectorTranslation(std::map<std::string, std::string> &metadata) {
573
574 // detectorTranslations
575 double detectorTranslation = 0;
576 from_string<double>(detectorTranslation, metadata["Motor_Positions/detector_trans"], std::dec);
577 // Add to the log!
578 API::Run &runDetails = m_workspace->mutableRun();
579 auto *p = new Mantid::Kernel::TimeSeriesProperty<double>("detector-translation");
580 p->addValue(DateAndTime::getCurrentTime(), detectorTranslation);
581 runDetails.addLogData(p);
582
583 g_log.debug() << "Detector Translation = " << detectorTranslation << " mm." << '\n';
584}
585
590void LoadSpice2D::runLoadInstrument(const std::string &inst_name, const DataObjects::Workspace2D_sptr &localWorkspace) {
591
592 auto loadInst = createChildAlgorithm("LoadInstrument");
593
594 // Now execute the Child Algorithm. Catch and log any error, but don't stop.
595 try {
596 loadInst->setPropertyValue("InstrumentName", inst_name);
597 loadInst->setProperty<API::MatrixWorkspace_sptr>("Workspace", localWorkspace);
598 loadInst->setProperty("RewriteSpectraMap", Mantid::Kernel::OptionalBool(true));
599 loadInst->execute();
600 } catch (std::invalid_argument &) {
601 g_log.information("Invalid argument to LoadInstrument Child Algorithm");
602 } catch (std::runtime_error &) {
603 g_log.information("Unable to successfully run LoadInstrument Child Algorithm");
604 }
605}
606
607/* This method throws not found error if a element is not found in the xml
608 * file
609 * @param elem :: pointer to element
610 * @param name :: element name
611 * @param fileName :: xml file name
612 */
613void LoadSpice2D::throwException(Poco::XML::Element *elem, const std::string &name, const std::string &fileName) {
614 if (!elem) {
615 throw Kernel::Exception::NotFoundError(name + " element not found in Spice XML file", fileName);
616 }
617}
618
625void LoadSpice2D::rotateDetector(const double &angle) {
626
627 g_log.notice() << "Rotating Wing Detector " << angle << " degrees." << '\n';
628
629 API::Run &runDetails = m_workspace->mutableRun();
630 auto *p = new Mantid::Kernel::TimeSeriesProperty<double>("rotangle");
631 // auto p = boost::make_shared <Mantid::Kernel::TimeSeriesProperty<double>
632 //>("rotangle");
633
634 p->addValue(DateAndTime::getCurrentTime(), angle);
635 runDetails.addLogData(p);
636}
637
638/***
639 * 2016/11/09 : There is a new tag sans_spice_xml_format_version in the XML
640 * It identifies changes in the XML format.
641 * Useful to test tags rather than using the date.
642 * @param metadata
643 */
644void LoadSpice2D::setSansSpiceXmlFormatVersion(std::map<std::string, std::string> &metadata) {
645
646 if (metadata.find("Header/sans_spice_xml_format_version") != metadata.end()) {
647 m_sansSpiceXmlFormatVersion = boost::lexical_cast<double>(metadata["Header/sans_spice_xml_format_version"]);
648 }
649 g_log.debug() << "Sans_spice_xml_format_version == " << m_sansSpiceXmlFormatVersion << "\n";
650}
651} // namespace Mantid::DataHandling
double value
The value of the point.
Definition: FitMW.cpp:51
double error
Definition: IndexPeaks.cpp:133
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
#define fabs(x)
Definition: Matrix.cpp:22
int count
counter
Definition: Matrix.cpp:37
#define DECLARE_FILELOADER_ALGORITHM(classname)
DECLARE_FILELOADER_ALGORITHM should be used in place of the standard DECLARE_ALGORITHM macro when wri...
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Definition: Algorithm.cpp:1913
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
Definition: Algorithm.cpp:2026
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
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.
Definition: Algorithm.cpp:842
static bool isEmpty(const NumT toCheck)
checks that the value was not set by users, uses the value in empty double/int.
@ Load
allowed here which will be passed to the algorithm
Definition: FileProperty.h:52
void addLogData(Kernel::Property *p)
Add a log entry.
Definition: LogManager.h:115
This class stores information regarding an experimental run as a series of log entries.
Definition: Run.h:38
A property class for workspaces.
void setBeamTrapRunProperty(std::map< std::string, std::string > &metadata)
Sets the beam trap as Run Property There's several beamstrap position.
const std::string name() const override
Algorithm's name for identification overriding a virtual method.
Definition: LoadSpice2D.h:61
int confidence(Kernel::FileDescriptor &descriptor) const override
Returns a confidence value that this algorithm can load a file.
Definition: LoadSpice2D.cpp:98
static const int nMonitors
Number of monitors.
Definition: LoadSpice2D.h:75
DataObjects::Workspace2D_sptr m_workspace
Definition: LoadSpice2D.h:114
void setWavelength(std::map< std::string, std::string > &metadata)
Gets the wavelength and wavelength spread from the metadata and sets them as class attributes.
Mantid::Types::Core::DateAndTime m_endTime
Definition: LoadSpice2D.h:122
std::pair< int, int > parseDetectorDimensions(const std::string &)
Parse the 2 integers of the form: INT32[192,256].
void runLoadInstrument(const std::string &inst_name, const DataObjects::Workspace2D_sptr &localWorkspace)
Run LoadInstrument Child Algorithm.
Mantid::Types::Core::DateAndTime m_startTime
Definition: LoadSpice2D.h:121
void addMetadataAsRunProperties(const std::map< std::string, std::string > &)
Adds map of the form key:value as Workspace run properties.
void detectorTranslation(std::map< std::string, std::string > &metadata)
Puts a numeric series in the log with the value of detector translation.
void detectorDistance(std::map< std::string, std::string > &metadata)
Calculates the detector distances and sets them as Run properties Here fog starts: GPSANS: distance =...
void throwException(Poco::XML::Element *elem, const std::string &name, const std::string &fileName)
This method throws not found error if a element is not found in the xml file.
std::vector< int > getData(const std::string &)
Parses the data dimensions and stores them as member variables Reads the data and returns a vector.
void init() override
Overwrites Algorithm method.
T addRunProperty(std::map< std::string, std::string > &metadata, const std::string &oldName, const std::string &newName, const std::string &units="")
Inserts a property in the run with a new name!
void setSansSpiceXmlFormatVersion(std::map< std::string, std::string > &metadata)
void setMetadataAsRunProperties(std::map< std::string, std::string > &metadata)
void rotateDetector(const double &)
This will rotate the detector named componentName around z-axis.
Mantid::DataHandling::XmlHandler m_xmlHandler
Definition: LoadSpice2D.h:117
void exec() override
Overwrites Algorithm method.
void setInputPropertiesAsMemberProperties()
Get the input algorithm properties and sets them as class attributes.
std::string get_text_from_tag(const std::string &)
Definition: XmlHandler.cpp:57
std::map< std::string, std::string > get_metadata(const std::vector< std::string > &tags_to_ignore)
Build dictionary {string : string } of all tags in the dictionary Composed tags: / replaced by _.
Definition: XmlHandler.cpp:37
std::map< std::string, std::string > get_attributes_from_tag(const std::string &)
Definition: XmlHandler.cpp:67
std::vector< std::string > get_subnodes(const std::string &)
Returns list of sub-nodes for a xpath node For: xpath = //Data/ Returns: Detector ,...
Definition: XmlHandler.cpp:87
Records the filename and the description of failure.
Definition: Exception.h:98
Exception for when an item is not found in a collection.
Definition: Exception.h:145
Marks code as not implemented yet.
Definition: Exception.h:138
Defines a wrapper around an open file.
const std::string & filename() const
Access the filename.
std::istream & data()
Access the open file stream.
const std::string & extension() const
Access the file extension.
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:114
void notice(const std::string &msg)
Logs at notice level.
Definition: Logger.cpp:95
void error(const std::string &msg)
Logs at error level.
Definition: Logger.cpp:77
void information(const std::string &msg)
Logs at information level.
Definition: Logger.cpp:105
OptionalBool : Tri-state bool.
Definition: OptionalBool.h:25
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
A specialised Property class for holding a series of time-value pairs.
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
bool from_string(T &t, const std::string &s, std::ios_base &(*f)(std::ios_base &))
Definition: LoadSpice2D.cpp:62
void store_value(const DataObjects::Workspace2D_sptr &ws, int specID, double value, double error, double wavelength, double dwavelength)
Convenience function to store a detector value into a given spectrum.
Definition: LoadSpice2D.cpp:78
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.
int convert(const std::string &A, T &out)
Convert a string into a number.
Definition: Strings.cpp:665
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
Definition: EmptyValues.h:43
STL namespace.
Describes the direction (within an algorithm) of a Property.
Definition: Property.h:50
@ Output
An output workspace.
Definition: Property.h:54