17#include <Poco/DOM/AutoPtr.h>
18#include <Poco/DOM/DOMParser.h>
19#include <Poco/DOM/Document.h>
20#include <Poco/DOM/Element.h>
21#include <Poco/DOM/NodeFilter.h>
22#include <Poco/DOM/NodeIterator.h>
23#include <Poco/DOM/NodeList.h>
28using Poco::XML::AutoPtr;
29using Poco::XML::Document;
30using Poco::XML::DOMParser;
31using Poco::XML::Element;
37using namespace Kernel;
39using Geometry::Instrument;
47 "The name of the workspace to load the instrument parameters into.");
49 "The filename (including its full or relative path) of a parameter "
50 "definition file. The file extension must either be .xml or .XML.");
51 declareProperty(
"ParameterXML",
"",
"The parameter definition XML as a string.");
70 if (filename.empty() && parameterXMLProperty->
isDefault()) {
72 "property of LoadParameterFile most be "
73 "specified to load an IDF",
80 const auto 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();
132 loadInstr.
setComponentLinks(instrument, pRootElem, logfileCache, &prog, localWorkspace->getWorkspaceStartDate());
134 auto &componentInfo = localWorkspace->mutableComponentInfo();
135 for (
const auto &[key, parameter] : logfileCache) {
136 const auto index = componentInfo.indexOfOrInvalid(key.second);
138 componentInfo.addLogfileParameter(
index, key.first, parameter);
141 addTimer(
"setComponentLinks", linkStartTime, std::chrono::high_resolution_clock::now());
144 const auto populateStartTime = std::chrono::high_resolution_clock::now();
145 localWorkspace->populateInstrumentParameters();
146 addTimer(
"populateInstrumentParameters", populateStartTime, std::chrono::high_resolution_clock::now());
148 if (!filename.empty()) {
149 localWorkspace->instrumentParameters().addParameterFilename(filename);
#define DECLARE_ALGORITHM(classname)
std::map< DeltaEMode::Type, std::string > index
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.
static constexpr size_t invalidIndex
Returned by indexOfOrInvalid() for a component ID that is not part of this instrument.
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::map< std::pair< std::string, const IComponent * >, std::shared_ptr< XMLInstrumentParameter > > InstrumentParameterCache
Convenience typedef.
@ InOut
Both an input & output workspace.