16#include <Poco/DOM/AutoPtr.h>
17#include <Poco/DOM/DOMParser.h>
18#include <Poco/DOM/Document.h>
19#include <Poco/DOM/Element.h>
20#include <Poco/DOM/NodeFilter.h>
21#include <Poco/DOM/NodeIterator.h>
22#include <Poco/DOM/NodeList.h>
27using Poco::XML::AutoPtr;
28using Poco::XML::Document;
29using Poco::XML::DOMParser;
30using Poco::XML::Element;
36using namespace Kernel;
38using Geometry::Instrument;
46 "The name of the workspace to load the instrument parameters into.");
48 "The filename (including its full or relative path) of a parameter "
49 "definition file. The file extension must either be .xml or .XML.");
50 declareProperty(
"ParameterXML",
"",
"The parameter definition XML as a string.");
69 if (filename.empty() && parameterXMLProperty->
isDefault()) {
71 "property of LoadParameterFile most be "
72 "specified to load an IDF",
80 Instrument_sptr instrument = std::const_pointer_cast<Instrument>(localWorkspace->getInstrument()->baseInstrument());
84 AutoPtr<Document> pDoc;
89 prog.
report(
"Parsing XML");
91 const auto parseStartTime = std::chrono::high_resolution_clock::now();
96 pDoc = pParser.parseString(parameterXML);
97 }
catch (Poco::Exception &exc) {
105 std::filesystem::path ipfFile(filename);
106 if (!std::filesystem::exists(ipfFile)) {
107 std::filesystem::path filePath(filename);
109 (std::filesystem::path(Kernel::ConfigService::Instance().getInstrumentDirectory()) / filePath.filename())
113 pDoc = pParser.parse(filename);
114 }
catch (Poco::Exception &exc) {
120 addTimer(
"xmlParsing", parseStartTime, std::chrono::high_resolution_clock::now());
123 Element *pRootElem = pDoc->documentElement();
124 if (!pRootElem->hasChildNodes()) {
129 const auto linkStartTime = std::chrono::high_resolution_clock::now();
131 loadInstr.
setComponentLinks(instrument, pRootElem, &prog, localWorkspace->getWorkspaceStartDate());
132 addTimer(
"setComponentLinks", linkStartTime, std::chrono::high_resolution_clock::now());
135 const auto populateStartTime = std::chrono::high_resolution_clock::now();
136 localWorkspace->populateInstrumentParameters();
137 addTimer(
"populateInstrumentParameters", populateStartTime, std::chrono::high_resolution_clock::now());
139 if (!filename.empty()) {
140 localWorkspace->instrumentParameters().addParameterFilename(filename);
#define DECLARE_ALGORITHM(classname)
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
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.
void addTimer(const std::string &name, const Kernel::time_point_ns &begin, const Kernel::time_point_ns &end)
@ OptionalLoad
to specify a file to read but the file doesn't have to exist
Helper class for reporting progress from algorithms.
A property class for workspaces.
void init() override
Initialisation method.
void exec() override
Executes the algorithm.
Creates an instrument data from a XML instrument description file.
void setComponentLinks(std::shared_ptr< Geometry::Instrument > &instrument, Poco::XML::Element *pRootElem, Kernel::ProgressBase *progress=nullptr, const std::string &requestedDate=std::string())
Add/overwrite any parameters specified in instrument with param values specified in <component-link> ...
Records the filename and the description of failure.
Exception for errors associated with the instrument definition.
void information(const std::string &msg)
Logs at information level.
void resetNumSteps(int64_t nsteps, double start, double end)
Change the number of steps between start/end.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
Base class for properties.
virtual bool isDefault() const =0
Overriden function that returns if property has the same value that it was initialised with,...
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< Instrument > Instrument_sptr
Shared pointer to an instrument object.
@ InOut
Both an input & output workspace.