26#include "MantidTypes/Core/DateAndTime.h"
27#include "MantidTypes/Core/DateAndTimeHelpers.h"
29#include <Poco/DOM/DOMParser.h>
30#include <Poco/DOM/DOMWriter.h>
31#include <Poco/DOM/Document.h>
32#include <Poco/DOM/Element.h>
33#include <Poco/DOM/NodeFilter.h>
34#include <Poco/DOM/NodeIterator.h>
35#include <Poco/DOM/NodeList.h>
36#include <Poco/SAX/AttributesImpl.h>
37#include <Poco/String.h>
38#include <Poco/XML/XMLWriter.h>
40#include <boost/regex.hpp>
43#include <unordered_set>
49using Poco::XML::Document;
50using Poco::XML::DOMParser;
51using Poco::XML::Element;
53using Poco::XML::NodeFilter;
54using Poco::XML::NodeIterator;
55using Poco::XML::NodeList;
67 m_hasParameterElement_beenSet(false), m_haveDefaultFacing(false), m_deltaOffsets(false), m_angleConvertConst(1.0),
68 m_indirectPositions(false), m_mixedNeutronicPositions(false), m_cachingOption(NoneApplied) {
79 const std::string &xmlText)
81 m_hasParameterElement_beenSet(false), m_haveDefaultFacing(false), m_deltaOffsets(false), m_angleConvertConst(1.0),
82 m_indirectPositions(false), m_mixedNeutronicPositions(false), m_cachingOption(NoneApplied) {
96 const std::string &instName,
const std::string &xmlText)
98 m_hasParameterElement_beenSet(false), m_haveDefaultFacing(false), m_deltaOffsets(false), m_angleConvertConst(1.0),
99 m_indirectPositions(false), m_mixedNeutronicPositions(false), m_cachingOption(NoneApplied) {
100 initialise(xmlFile->getFileFullPathStr(), instName, xmlText, expectedCacheFile->getFileFullPathStr());
115 const std::string &xmlText,
const std::string &vtpFilename) {
138 if (vtpFilename.empty()) {
141 m_cacheFile = std::make_shared<const IDFObject>(vtpFilename);
161 if (!(xml.empty())) {
180 throw std::invalid_argument(
"Instrument XML string is empty");
186 }
catch (Poco::Exception &exc) {
187 throw std::invalid_argument(exc.displayText() +
". Unable to parse XML");
189 throw std::invalid_argument(
"Unable to parse XML");
202 const std::string &typeName)
const {
206 .append(
"contains more than one type element named ")
209 std::string(
"XML instrument file contains more than one type element named ")
226 Poco::XML::Element *pRootElem = pDoc->documentElement();
228 if (!pRootElem->hasChildNodes()) {
229 g_log.
error(
"Instrument XML contains no root element.");
237 const std::string filename =
m_xmlFile->getFileFullPathStr();
239 std::vector<Element *> typeElems;
240 std::vector<Element *> compElems;
243 if (typeElems.empty()) {
244 g_log.
error(
"XML file: " + filename +
"contains no type elements.");
298 const std::vector<Element *> &typeElems,
300 const size_t numberOfTypes = typeElems.size();
301 for (
size_t iType = 0; iType < numberOfTypes; ++iType) {
302 Element *pTypeElem = typeElems[iType];
303 std::string typeName = pTypeElem->getAttribute(
"name");
307 Poco::AutoPtr<NodeList> pNL_type_combine_into_one_shape =
308 pTypeElem->getElementsByTagName(
"combine-components-into-one-shape");
309 if (pNL_type_combine_into_one_shape->length() > 0) {
329 const std::string &filename,
330 const std::vector<Element *> &compElems) {
331 if (progressReporter)
334 for (
auto pElem : compElems) {
335 if (progressReporter)
336 progressReporter->
report(
"Loading instrument Definition");
347 for (Node *pNode = pElem->firstChild(); pNode !=
nullptr; pNode = pNode->nextSibling()) {
348 auto pChildElem =
dynamic_cast<Element *
>(pNode);
351 if (pChildElem->tagName() ==
"location") {
354 if (
isAssembly(pElem->getAttribute(
"type"))) {
359 }
else if (pChildElem->tagName() ==
"locations") {
379 const std::string &filename)
const {
380 Poco::AutoPtr<NodeList> pNL_location = pElem->getElementsByTagName(
"location");
381 Poco::AutoPtr<NodeList> pNL_locations = pElem->getElementsByTagName(
"locations");
383 if (pNL_location->length() == 0 && pNL_locations->length() == 0) {
384 g_log.
error(std::string(
"A component element must contain at least one "
385 "<location> or <locations> element") +
386 " even if it is just an empty location element of the form "
389 "<location> or <locations> element") +
390 " even if it is just an empty location element of the form "
405 const std::string &filename)
const {
406 if (idList.
counted !=
static_cast<int>(idList.
vec.size())) {
407 std::stringstream ss1, ss2;
408 ss1 << idList.
vec.size();
410 if (!pElem->hasAttribute(
"idlist")) {
411 g_log.
error(
"No detector ID list found for detectors of type " + pElem->getAttribute(
"type"));
412 }
else if (idList.
vec.empty()) {
413 g_log.
error(
"No detector IDs found for detectors in list " + pElem->getAttribute(
"idlist") +
414 "for detectors of type" + pElem->getAttribute(
"type"));
416 g_log.
error(
"The number of detector IDs listed in idlist named " + pElem->getAttribute(
"idlist") +
417 " is larger than the number of detectors listed in type = " + pElem->getAttribute(
"type"));
420 "Number of IDs listed in idlist (=" + ss1.str() +
") is larger than the number of detectors listed in type = " +
421 pElem->getAttribute(
"type") +
" (=" + ss2.str() +
").",
432 Poco::AutoPtr<NodeList> pNL_parameter = pRootElem->getElementsByTagName(
"parameter");
433 unsigned long numParameter = pNL_parameter->length();
439 NodeIterator it(pRootElem, NodeFilter::SHOW_ELEMENT);
440 Node *pNode = it.nextNode();
442 if (pNode->nodeName() ==
"parameter") {
443 auto pParameterElem =
dynamic_cast<Element *
>(pNode);
446 pNode = it.nextNode();
462 const std::string &filename,
463 const std::vector<Element *> &typeElems,
464 const size_t numberOfTypes) {
465 for (
size_t iType = 0; iType < numberOfTypes; ++iType) {
466 Element *pTypeElem = typeElems[iType];
467 std::string typeName = pTypeElem->getAttribute(
"name");
471 Poco::AutoPtr<NodeList> pNL_type_combine_into_one_shape =
472 pTypeElem->getElementsByTagName(
"combine-components-into-one-shape");
473 if (pNL_type_combine_into_one_shape->length() == 0)
486 if (
auto csgObj = std::dynamic_pointer_cast<CSGObject>(
mapTypeNameToShape[typeName])) {
487 csgObj->setName(
static_cast<int>(iType));
502 Element *pTypeElem,
const std::string &typeName) {
503 Poco::AutoPtr<NodeList> pNL_local = pTypeElem->getElementsByTagName(
"component");
504 if (pNL_local->length() == 0) {
511 if (
auto csgObj = std::dynamic_pointer_cast<CSGObject>(
mapTypeNameToShape[typeName])) {
512 csgObj->setName(
static_cast<int>(iType));
516 if (pTypeElem->hasAttribute(
"outline")) {
517 pTypeElem->setAttribute(
"object_created",
"no");
530 std::vector<Element *> &typeElems,
531 std::vector<Element *> &compElems)
const {
532 for (
auto pNode = pRootElem->firstChild(); pNode !=
nullptr; pNode = pNode->nextSibling()) {
533 auto pElem =
dynamic_cast<Element *
>(pNode);
535 if (pElem->tagName() ==
"type")
536 typeElems.emplace_back(pElem);
537 else if (pElem->tagName() ==
"component")
538 compElems.emplace_back(pElem);
559 const Poco::XML::Element *pCompElem,
IdList &idList) {
564 const Element *pRootLocationsElem = pLocationsDoc->documentElement();
565 const bool assembly =
isAssembly(pCompElem->getAttribute(
"type"));
567 auto *pElem =
dynamic_cast<Poco::XML::Element *
>(pRootLocationsElem->firstChild());
570 if (pElem->tagName() !=
"location") {
571 pElem =
dynamic_cast<Poco::XML::Element *
>(pElem->nextSibling());
581 pElem =
dynamic_cast<Poco::XML::Element *
>(pElem->nextSibling());
596 Poco::XML::DOMWriter writer;
597 writer.setNewLine(
"\n");
598 writer.setOptions(Poco::XML::XMLWriter::PRETTY_PRINT);
601 std::ofstream outFile(outFilename.c_str());
602 writer.writeNode(outFile, pDoc);
607 if (pElem->hasAttribute(
name)) {
608 const std::string &
value = pElem->getAttribute(
name);
609 if (!
value.empty()) {
611 return std::stod(
value);
613 std::stringstream msg;
614 msg <<
"failed to convert \"" <<
value <<
"\" to double for xml attribute \"" <<
name
615 <<
"\" - using 0. instead";
638 const double angleConvertConst,
const bool deltaOffsets) {
642 if (pElem->hasAttribute(
"rot")) {
643 double rotAngle = angleConvertConst *
attrToDouble(pElem,
"rot");
649 if (pElem->hasAttribute(
"axis-x"))
650 axis_x = std::stod(pElem->getAttribute(
"axis-x"));
651 if (pElem->hasAttribute(
"axis-y"))
652 axis_y = std::stod(pElem->getAttribute(
"axis-y"));
653 if (pElem->hasAttribute(
"axis-z"))
654 axis_z = std::stod(pElem->getAttribute(
"axis-z"));
662 Element *pRecursive =
nullptr;
663 Element *tElem = pElem->getChildElement(
"trans");
664 Element *rElem = pElem->getChildElement(
"rot");
665 bool stillTransElement =
true;
666 bool firstRound =
true;
667 while (stillTransElement) {
672 }
else if (pRecursive !=
nullptr) {
673 tElem = pRecursive->getChildElement(
"trans");
674 rElem = pRecursive->getChildElement(
"rot");
677 if (tElem && rElem) {
682 if (!tElem && !rElem) {
683 stillTransElement =
false;
696 compToGetRot.
setPos(posTrans);
706 double rotAngle = angleConvertConst *
attrToDouble(rElem,
"val");
712 if (rElem->hasAttribute(
"axis-x"))
713 axis_x = std::stod(rElem->getAttribute(
"axis-x"));
714 if (rElem->hasAttribute(
"axis-y"))
715 axis_y = std::stod(rElem->getAttribute(
"axis-y"));
716 if (rElem->hasAttribute(
"axis-z"))
717 axis_z = std::stod(rElem->getAttribute(
"axis-z"));
729 const Poco::XML::Element *pCompElem) {
734 auto pViewLocElem = pCompElem->getChildElement(
"side-by-side-view-location");
757 const Poco::XML::Element *pElem,
758 const double angleConvertConst,
759 const bool deltaOffsets) {
763 if (pElem->hasAttribute(
"r") || pElem->hasAttribute(
"t") || pElem->hasAttribute(
"p") || pElem->hasAttribute(
"R") ||
764 pElem->hasAttribute(
"theta") || pElem->hasAttribute(
"phi")) {
767 double theta = angleConvertConst *
attrToDouble(pElem,
"t");
768 double phi = angleConvertConst *
attrToDouble(pElem,
"p");
770 if (pElem->hasAttribute(
"R"))
772 if (pElem->hasAttribute(
"theta"))
773 theta = angleConvertConst *
attrToDouble(pElem,
"theta");
774 if (pElem->hasAttribute(
"phi"))
788 std::map<const Geometry::IComponent *, SphVec>::iterator it;
798 theta += parent.theta;
801 parentPos.
spherical(parent.r, parent.theta, parent.phi);
817 retVal = absPos - parentPos;
845 if (((pLocElem->tagName()) !=
"location") && ((pLocElem->tagName()) !=
"locations")) {
846 const std::string &tagname = pLocElem->tagName();
847 g_log.
error(
"Argument to function getParentComponent must be a pointer to "
848 "an XML element with tag name location or locations.");
849 throw std::logic_error(std::string(
"Argument to function getParentComponent must be a pointer "
850 "to an XML element") +
851 "with tag name location or locations." +
" The tag name is " + tagname);
857 Node *pCompNode = pLocElem->parentNode();
860 if (pCompNode->nodeType() == 1) {
861 pCompElem =
static_cast<Element *
>(pCompNode);
862 if ((pCompElem->tagName()) !=
"component") {
863 g_log.
error(
"Argument to function getParentComponent must be a XML "
864 "element sitting inside a component element.");
865 throw std::logic_error(
"Argument to function getParentComponent must be "
866 "a XML element sitting inside a component "
870 g_log.
error(
"Argument to function getParentComponent must be a XML element "
871 "whos parent is an element.");
872 throw std::logic_error(
"Argument to function getParentComponent must be a "
873 "XML element whos parent is an element.");
892 const Poco::XML::Element *pCompElem) {
895 if (pElem->hasAttribute(
"name"))
896 retVal = pElem->getAttribute(
"name");
897 else if (pCompElem->hasAttribute(
"name")) {
898 retVal = pCompElem->getAttribute(
"name");
900 retVal = pCompElem->getAttribute(
"type");
911 const std::string filename =
m_xmlFile->getFileFullPathStr();
913 if (!pRootElem->hasAttribute(
"valid-from")) {
917 DateAndTime
d(pRootElem->getAttribute(
"valid-from"));
925 if (!pRootElem->hasAttribute(
"valid-to")) {
926 DateAndTime
d = DateAndTime::getCurrentTime();
933 DateAndTime
d(pRootElem->getAttribute(
"valid-to"));
946 }
else if (input ==
"y") {
948 }
else if (input ==
"z") {
951 std::stringstream msg;
952 msg <<
"Cannot create \"" << label <<
"\" with axis direction other than \"x\", \"y\", or \"z\", found \"" << input
973 Element *offsetElement = defaults->getChildElement(
"offsets");
975 offsets = offsetElement->getAttribute(
"spherical");
976 if (offsets ==
"delta")
980 Element *defaultFacingElement = defaults->getChildElement(
"components-are-facing");
981 if (defaultFacingElement) {
988 Element *defaultView = defaults->getChildElement(
"default-view");
990 m_instrument->setDefaultViewAxis(defaultView->getAttribute(
"axis-view"));
991 if (defaultView->hasAttribute(
"view")) {
992 m_instrument->setDefaultView(defaultView->getAttribute(
"view"));
997 Element *angleUnit = defaults->getChildElement(
"angle");
999 if (angleUnit->getAttribute(
"unit") ==
"radian") {
1001 std::map<std::string, std::string> &units =
m_instrument->getLogfileUnit();
1002 units[
"angle"] =
"radian";
1010 if (defaults->getChildElement(
"indirect-neutronic-positions"))
1017 if (defaults->getChildElement(
"indirect-neutronic-positions-mixed")) {
1026 Element *referenceFrameElement = defaults->getChildElement(
"reference-frame");
1028 if (referenceFrameElement) {
1029 using Poco::XML::XMLString;
1031 Element *upElement = referenceFrameElement->getChildElement(
"pointing-up");
1032 Element *alongElement = referenceFrameElement->getChildElement(
"along-beam");
1033 Element *handednessElement = referenceFrameElement->getChildElement(
"handedness");
1034 Element *originElement = referenceFrameElement->getChildElement(
"origin");
1035 Element *thetaSignElement = referenceFrameElement->getChildElement(
"theta-sign");
1038 XMLString s_alongBeam(
"z");
1039 XMLString s_pointingUp(
"y");
1040 XMLString s_handedness(
"right");
1045 s_alongBeam = alongElement->getAttribute(
"axis");
1048 s_pointingUp = upElement->getAttribute(
"axis");
1050 if (handednessElement) {
1051 s_handedness = handednessElement->getAttribute(
"val");
1053 if (originElement) {
1054 s_origin = originElement->getAttribute(
"val");
1058 XMLString s_thetaSign(s_pointingUp);
1059 if (thetaSignElement) {
1060 s_thetaSign = thetaSignElement->getAttribute(
"axis");
1071 std::make_shared<ReferenceFrame>(pointingUp, alongBeam, thetaSign, handedness, s_origin));
1078 Poco::AutoPtr<NodeList> pNLexclude = location->getElementsByTagName(
"exclude");
1079 unsigned long numberExcludeEle = pNLexclude->length();
1080 std::vector<std::string> newExcludeList;
1081 for (
unsigned long i = 0; i < numberExcludeEle; i++) {
1082 auto *pExElem =
static_cast<Element *
>(pNLexclude->item(i));
1083 if (pExElem->hasAttribute(
"sub-part"))
1084 newExcludeList.emplace_back(pExElem->getAttribute(
"sub-part"));
1087 return newExcludeList;
1106 const Poco::XML::Element *pCompElem,
IdList &idList) {
1107 const std::string filename =
m_xmlFile->getFileFullPathStr();
1117 if (pCompElem->hasAttribute(
"idlist")) {
1118 std::string idlist = pCompElem->getAttribute(
"idlist");
1120 if (idlist != idList.
idname) {
1121 Element *pFound = pCompElem->ownerDocument()->getElementById(idlist,
"idname");
1123 if (pFound ==
nullptr) {
1125 "No <idlist> with name idname=\"" + idlist +
"\" present in instrument definition file.", filename);
1139 Element *pType =
getTypeElement[pCompElem->getAttribute(
"type")];
1140 std::string category;
1141 if (pType->hasAttribute(
"is"))
1142 category = pType->getAttribute(
"is");
1143 if (category ==
"SamplePos" || category ==
"samplePos") {
1145 }
else if (pType->hasAttribute(
"outline") && pType->getAttribute(
"outline") !=
"no") {
1165 if (category ==
"SamplePos" || category ==
"samplePos") {
1168 if (category ==
"Source" || category ==
"source") {
1174 Element *neutronic = pLocElem->getChildElement(
"neutronic");
1182 NodeIterator it(pType, NodeFilter::SHOW_ELEMENT);
1184 Node *pNode = it.nextNode();
1186 if (pNode->nodeName() ==
"location") {
1189 const Element *pElem =
static_cast<Element *
>(pNode);
1196 auto inExcluded = find(excludeList.cbegin(), excludeList.cend(),
1198 if (inExcluded == excludeList.end()) {
1209 if (pNode->nodeName() ==
"locations") {
1210 const Element *pLocationsElems =
static_cast<Element *
>(pNode);
1216 pNode = it.nextNode();
1220 if (pType->hasAttribute(
"outline") && pType->getAttribute(
"outline") !=
"no") {
1223 throw std::logic_error(
"Failed to cast ICompAssembly object to ObjCompAssembly");
1225 if (pType->getAttribute(
"object_created") ==
"no") {
1226 pType->setAttribute(
"object_created",
"yes");
1227 std::shared_ptr<Geometry::IObject>
obj = objAss->createOutline();
1231 pType->setAttribute(
"outline",
"no");
1232 g_log.
warning() <<
"Failed to create outline object for assembly " << pType->getAttribute(
"name") <<
'\n';
1241 const Poco::XML::Element *pLocElem,
1242 const Poco::XML::Element *pCompElem,
1243 const std::string &filename,
IdList &idList,
1244 const std::string &category) {
1252 if (idList.
counted >=
static_cast<int>(idList.
vec.size())) {
1253 std::stringstream ss1, ss2;
1254 ss1 << idList.
vec.size();
1256 if (idList.
idname.empty()) {
1257 g_log.
error(
"No list of detector IDs found for location element " +
name);
1260 }
else if (idList.
vec.empty()) {
1261 g_log.
error(
"No detector IDs found for detectors in list " + idList.
idname);
1263 g_log.
error(
"The number of detector IDs listed in idlist named " + idList.
idname +
1264 " is less then the number of detectors");
1267 "Number of IDs listed in idlist (=" + ss1.str() +
") is less than the number of detectors.", filename);
1270 std::string typeName = pCompElem->getAttribute(
"type");
1276 parent->
add(detector);
1291 m_neutronicPos[detector] = pLocElem->getChildElement(
"neutronic");
1295 if (pCompElem->hasAttribute(
"mark-as") || pLocElem->hasAttribute(
"mark-as")) {
1296 g_log.
warning() <<
"Attribute 'mark-as' is a deprecated attribute in "
1297 "Instrument Definition File."
1298 <<
" Please see the deprecated section of "
1299 "docs.mantidproject.org/concepts/InstrumentDefinitionFile for how to remove this "
1300 "warning message\n";
1304 if (category ==
"Monitor" || category ==
"monitor") {
1308 if ((pCompElem->hasAttribute(
"mark-as") && pCompElem->getAttribute(
"mark-as") ==
"monitor") ||
1309 (pLocElem->hasAttribute(
"mark-as") && pLocElem->getAttribute(
"mark-as") ==
"monitor")) {
1317 std::stringstream convert;
1318 convert << detector->
getID();
1320 "Detector with ID = " + convert.str() +
" present more then once in XML instrument file", filename);
1332 const Poco::XML::Element *pCompElem,
const std::string &filename,
1333 const Poco::XML::Element *pType) {
1357 std::string idfillorder;
1358 int idstepbyrow = 0;
1364 const std::string shapeType = pType->getAttribute(
"type");
1367 if (pType->hasAttribute(
"xpixels"))
1368 xpixels = std::stoi(pType->getAttribute(
"xpixels"));
1372 if (pType->hasAttribute(
"ypixels"))
1373 ypixels = std::stoi(pType->getAttribute(
"ypixels"));
1377 if (pType->hasAttribute(
"zpixels"))
1378 zpixels = std::stoi(pType->getAttribute(
"zpixels"));
1384 if (pCompElem->hasAttribute(
"idstart"))
1385 idstart = std::stoi(pCompElem->getAttribute(
"idstart"));
1386 if (pCompElem->hasAttribute(
"idfillorder"))
1387 idfillorder = pCompElem->getAttribute(
"idfillorder");
1389 if (!idfillorder.empty() && idfillorder[0] ==
'x')
1390 idstepbyrow = xpixels;
1391 else if (!idfillorder.empty() && idfillorder[0] ==
'y')
1392 idstepbyrow = ypixels;
1394 idstepbyrow = zpixels;
1396 if (pCompElem->hasAttribute(
"idstepbyrow")) {
1397 idstepbyrow = std::stoi(pCompElem->getAttribute(
"idstepbyrow"));
1400 if (pCompElem->hasAttribute(
"idstep"))
1401 idstep = std::stoi(pCompElem->getAttribute(
"idstep"));
1406 bank->initialize(shape, xpixels, xstart, xstep, ypixels, ystart, ystep, zpixels, zstart, zstep, idstart, idfillorder,
1407 idstepbyrow, idstep);
1412 for (
int z = 0;
z < bank->nelements(); ++
z) {
1413 auto zLayer = std::dynamic_pointer_cast<Geometry::ICompAssembly>((*bank)[
z]);
1414 for (
int x = 0;
x < zLayer->nelements(); ++
x) {
1415 auto xColumn = std::dynamic_pointer_cast<Geometry::ICompAssembly>((*zLayer)[
x]);
1416 for (
int y = 0;
y < xColumn->nelements(); ++
y) {
1417 std::shared_ptr<Geometry::Detector> detector = std::dynamic_pointer_cast<Geometry::Detector>((*xColumn)[
y]);
1420 auto *comp =
static_cast<IComponent *
>(detector.get());
1424 m_instrument->markAsDetectorIncomplete(detector.get());
1431 " in XML instrument file" + filename);
1436 const Poco::XML::Element *pLocElem,
1437 const Poco::XML::Element *pCompElem,
1438 const std::string &filename,
1439 const Poco::XML::Element *pType) {
1461 bool idfillbyfirst_y =
true;
1462 int idstepbyrow = 0;
1468 const std::string shapeType = pType->getAttribute(
"type");
1472 if (pType->hasAttribute(
"xpixels"))
1473 xpixels = std::stoi(pType->getAttribute(
"xpixels"));
1477 if (pType->hasAttribute(
"ypixels"))
1478 ypixels = std::stoi(pType->getAttribute(
"ypixels"));
1484 if (pCompElem->hasAttribute(
"idstart"))
1485 idstart = std::stoi(pCompElem->getAttribute(
"idstart"));
1486 if (pCompElem->hasAttribute(
"idfillbyfirst"))
1487 idfillbyfirst_y = (pCompElem->getAttribute(
"idfillbyfirst") ==
"y");
1489 if (idfillbyfirst_y)
1490 idstepbyrow = ypixels;
1492 idstepbyrow = xpixels;
1493 if (pCompElem->hasAttribute(
"idstepbyrow")) {
1494 idstepbyrow = std::stoi(pCompElem->getAttribute(
"idstepbyrow"));
1497 if (pCompElem->hasAttribute(
"idstep"))
1498 idstep = std::stoi(pCompElem->getAttribute(
"idstep"));
1503 bank->initialize(shape, xpixels, xstart, xstep, ypixels, ystart, ystep, idstart, idfillbyfirst_y, idstepbyrow,
1509 for (
int x = 0;
x < bank->nelements();
x++) {
1510 std::shared_ptr<Geometry::ICompAssembly> xColumn = std::dynamic_pointer_cast<Geometry::ICompAssembly>((*bank)[
x]);
1511 for (
int y = 0;
y < xColumn->nelements();
y++) {
1512 std::shared_ptr<Geometry::Detector> detector = std::dynamic_pointer_cast<Geometry::Detector>((*xColumn)[
y]);
1515 auto *comp =
static_cast<IComponent *
>(detector.get());
1519 m_instrument->markAsDetectorIncomplete(detector.get());
1525 name +
" in XML instrument file" + filename);
1530 const Poco::XML::Element *pLocElem,
1531 const Poco::XML::Element *pCompElem,
1532 const std::string &filename,
1533 const Poco::XML::Element *pType) {
1554 bool idfillbyfirst_y =
true;
1555 int idstepbyrow = 0;
1557 std::vector<double> xValues;
1558 std::vector<double> yValues;
1560 std::string typeName = pType->getAttribute(
"name");
1562 if (pType->hasAttribute(
"xpixels"))
1563 xpixels = std::stoi(pType->getAttribute(
"xpixels"));
1564 if (pType->hasAttribute(
"ypixels"))
1565 ypixels = std::stoi(pType->getAttribute(
"ypixels"));
1569 if (pCompElem->hasAttribute(
"idstart"))
1570 idstart = std::stoi(pCompElem->getAttribute(
"idstart"));
1571 if (pCompElem->hasAttribute(
"idfillbyfirst"))
1572 idfillbyfirst_y = (pCompElem->getAttribute(
"idfillbyfirst") ==
"y");
1574 if (idfillbyfirst_y)
1575 idstepbyrow = ypixels;
1577 idstepbyrow = xpixels;
1578 if (pCompElem->hasAttribute(
"idstepbyrow")) {
1579 idstepbyrow = std::stoi(pCompElem->getAttribute(
"idstepbyrow"));
1582 if (pCompElem->hasAttribute(
"idstep"))
1583 idstep = std::stoi(pCompElem->getAttribute(
"idstep"));
1586 Element *pElem =
nullptr;
1587 NodeIterator tags(pCompElem->ownerDocument(), NodeFilter::SHOW_ELEMENT);
1588 Node *pNode = tags.nextNode();
1591 auto *check =
static_cast<Element *
>(pNode);
1592 if (pNode->nodeName() ==
"type" && check->hasAttribute(
"is")) {
1593 std::string is = check->getAttribute(
"is");
1600 pNode = tags.nextNode();
1603 if (pElem ==
nullptr)
1607 Poco::AutoPtr<NodeList> pNL = pElem->getElementsByTagName(
"vertex");
1608 if (pNL->length() == 0)
1611 NodeIterator it(pElem, NodeFilter::SHOW_ELEMENT);
1613 pNode = it.nextNode();
1616 if (pNode->nodeName() ==
"vertex") {
1617 auto *pVertElem =
static_cast<Element *
>(pNode);
1619 if (pVertElem->hasAttribute(
"x"))
1621 if (pVertElem->hasAttribute(
"y"))
1625 pNode = it.nextNode();
1628 V3D zVector(0, 0, 1);
1629 bool isZBeam =
m_instrument->getReferenceFrame()->isVectorPointingAlongBeam(zVector);
1631 bank->initialize(xpixels, ypixels, std::move(xValues), std::move(yValues), isZBeam, idstart, idfillbyfirst_y,
1632 idstepbyrow, idstep);
1637 for (
int x = 0;
x < bank->nelements();
x++) {
1638 std::shared_ptr<Geometry::ICompAssembly> xColumn = std::dynamic_pointer_cast<Geometry::ICompAssembly>((*bank)[
x]);
1639 for (
int y = 0;
y < xColumn->nelements();
y++) {
1640 std::shared_ptr<Geometry::Detector> detector = std::dynamic_pointer_cast<Geometry::Detector>((*xColumn)[
y]);
1643 auto *comp =
static_cast<IComponent *
>(detector.get());
1647 m_instrument->markAsDetectorIncomplete(detector.get());
1653 name +
" in XML instrument file" + filename);
1677 const Poco::XML::Element *pCompElem,
IdList &idList) {
1678 const std::string filename =
m_xmlFile->getFileFullPathStr();
1685 if (pCompElem->hasAttribute(
"idlist")) {
1686 std::string idlist = pCompElem->getAttribute(
"idlist");
1688 if (idlist != idList.
idname) {
1689 Element *pFound = pCompElem->ownerDocument()->getElementById(idlist,
"idname");
1691 if (pFound ==
nullptr) {
1693 "No <idlist> with name idname=\"" + idlist +
"\" present in instrument definition file.", filename);
1706 std::string typeName = pCompElem->getAttribute(
"type");
1709 std::string category;
1710 if (pType->hasAttribute(
"is"))
1711 category = pType->getAttribute(
"is");
1713 static const boost::regex exp(
"Detector|detector|Monitor|monitor");
1722 }
else if (boost::regex_match(category, exp)) {
1728 if (category ==
"SamplePos" || category ==
"samplePos") {
1741 if (category ==
"Source" || category ==
"source") {
1770 const std::string filename =
m_xmlFile->getFileFullPathStr();
1772 if ((pE->tagName()) !=
"idlist") {
1773 g_log.
error(
"Argument to function createIdList must be a pointer to an XML "
1774 "element with tag name idlist.");
1775 throw std::logic_error(
"Argument to function createIdList must be a "
1776 "pointer to an XML element with tag name idlist.");
1781 idList.
idname = pE->getAttribute(
"idname");
1787 if (pE->hasAttribute(
"start")) {
1788 int startID = std::stoi(pE->getAttribute(
"start"));
1791 if (pE->hasAttribute(
"end"))
1792 endID = std::stoi(pE->getAttribute(
"end"));
1797 if (pE->hasAttribute(
"step"))
1798 increment = std::stoi(pE->getAttribute(
"step"));
1800 if (0 == increment) {
1801 std::stringstream ss;
1802 ss <<
"The step element cannot be zero, got start: " << startID <<
", end: " << endID <<
", step: " << increment;
1807 int steps = (endID - startID) / increment;
1809 std::stringstream ss;
1810 ss <<
"The start, end, and step elements do not allow a single id in "
1813 ss <<
"start: " << startID <<
", end: " << endID <<
", step: " << increment;
1818 idList.
vec.reserve(steps);
1819 for (
int i = startID; i != endID + increment; i += increment) {
1820 idList.
vec.emplace_back(i);
1825 Poco::AutoPtr<NodeList> pNL = pE->getElementsByTagName(
"id");
1827 if (pNL->length() == 0) {
1834 NodeIterator it(pE, NodeFilter::SHOW_ELEMENT);
1836 Node *pNode = it.nextNode();
1838 if (pNode->nodeName() ==
"id") {
1839 auto *pIDElem =
static_cast<Element *
>(pNode);
1841 if (pIDElem->hasAttribute(
"val")) {
1842 int valID = std::stoi(pIDElem->getAttribute(
"val"));
1843 idList.
vec.emplace_back(valID);
1844 }
else if (pIDElem->hasAttribute(
"start")) {
1845 int startID = std::stoi(pIDElem->getAttribute(
"start"));
1848 if (pIDElem->hasAttribute(
"end"))
1849 endID = std::stoi(pIDElem->getAttribute(
"end"));
1854 if (pIDElem->hasAttribute(
"step"))
1855 increment = std::stoi(pIDElem->getAttribute(
"step"));
1858 if (0 == increment) {
1859 std::stringstream ss;
1860 ss <<
"The step element cannot be zero, found step: " << increment;
1864 int numSteps = (endID - startID) / increment;
1866 std::stringstream ss;
1867 ss <<
"The start, end, and step elements do not allow a single "
1869 "in the idlist entry - ";
1870 ss <<
"start: " << startID <<
", end: " << endID <<
", step: " << increment;
1875 idList.
vec.reserve(numSteps);
1876 for (
int i = startID; i != endID + increment; i += increment) {
1877 idList.
vec.emplace_back(i);
1881 "id subelement of idlist " + std::string(
"element wrongly specified in XML instrument file"), filename);
1885 pNode = it.nextNode();
1900 const std::string filename =
m_xmlFile->getFileFullPathStr();
1940 const auto facingDirLength = facingDirection.
norm();
1941 if (facingDirLength == 0.0)
1943 facingDirection /= facingDirLength;
1951 R.
rotate(facingDirection);
1954 const auto normalLength = normal.
norm();
1955 if (normalLength == 0.) {
1958 normal /= normalLength;
1960 double theta = (180.0 / M_PI) * facingDirection.
angle(
z);
1962 if (normal.
norm() > 0.0)
1981 if (pElem->hasAttribute(
"r") || pElem->hasAttribute(
"t") || pElem->hasAttribute(
"p") || pElem->hasAttribute(
"R") ||
1982 pElem->hasAttribute(
"theta") || pElem->hasAttribute(
"phi")) {
1987 if (pElem->hasAttribute(
"R"))
1989 if (pElem->hasAttribute(
"theta"))
1991 if (pElem->hasAttribute(
"phi"))
2023 if ((pElem->tagName()) !=
"location") {
2024 g_log.
error(
"Second argument to function setLocation must be a pointer to "
2025 "an XML element with tag name location.");
2026 throw std::logic_error(
"Second argument to function setLocation must be a "
2027 "pointer to an XML element with tag name location.");
2030 Element *facingElem = pElem->getChildElement(
"facing");
2035 if (facingElem->hasAttribute(
"rot")) {
2046 if (facingElem->hasAttribute(
"val"))
2077 const std::string filename =
m_xmlFile->getFileFullPathStr();
2086 Poco::AutoPtr<NodeList> pNL_comp = pElem->childNodes();
2087 unsigned long pNL_comp_length = pNL_comp->length();
2089 for (
unsigned long i = 0; i < pNL_comp_length; i++) {
2092 if (!((pNL_comp->item(i))->nodeType() == Node::ELEMENT_NODE && ((pNL_comp->item(i))->nodeName()) ==
"parameter"))
2095 auto *pParamElem =
static_cast<Element *
>(pNL_comp->item(i));
2097 if (!pParamElem->hasAttribute(
"name"))
2099 "XML element with name or type = " + comp->
getName() +
2100 " contain <parameter> element with no name attribute in XML "
2104 std::string paramName = pParamElem->getAttribute(
"name");
2106 if (paramName ==
"rot" || paramName ==
"pos") {
2108 <<
" contains <parameter> element with name=\"" << paramName <<
"\"."
2109 <<
" This is a reserved Mantid keyword. Please use other name, "
2110 <<
"and see docs.mantidproject.org/concepts/InstrumentDefinitionFile for list of reserved "
2112 <<
" This parameter is ignored";
2116 std::string visible =
"true";
2117 if (pParamElem->hasAttribute(
"visible")) {
2118 visible = pParamElem->getAttribute(
"visible");
2121 DateAndTime validityDate;
2123 if (requestedDate.empty()) {
2124 validityDate = DateAndTime::getCurrentTime();
2126 validityDate.setFromISO8601(requestedDate);
2129 std::string logfileID;
2132 DateAndTime validFrom;
2133 DateAndTime validTo;
2135 std::string type =
"double";
2136 std::string extractSingleValueAs =
"mean";
2139 Poco::AutoPtr<NodeList> pNLvalue = pParamElem->getElementsByTagName(
"value");
2140 size_t numberValueEle = pNLvalue->length();
2141 Element *pValueElem;
2143 Poco::AutoPtr<NodeList> pNLlogfile = pParamElem->getElementsByTagName(
"logfile");
2144 size_t numberLogfileEle = pNLlogfile->length();
2145 Element *pLogfileElem;
2147 Poco::AutoPtr<NodeList> pNLLookUp = pParamElem->getElementsByTagName(
"lookuptable");
2148 size_t numberLookUp = pNLLookUp->length();
2150 Poco::AutoPtr<NodeList> pNLFormula = pParamElem->getElementsByTagName(
"formula");
2151 size_t numberFormula = pNLFormula->length();
2153 if ((numberValueEle > 0 && numberLogfileEle + numberLookUp + numberFormula > 0) ||
2154 (numberValueEle == 0 && numberLogfileEle + numberLookUp + numberFormula > 1)) {
2156 <<
" contains <parameter> element where the value of the "
2157 <<
"parameter has been specified more than once. See "
2158 <<
"docs.mantidproject.org/concepts/InstrumentDefinitionFile for how the value of the "
2159 <<
"parameter is set in this case.";
2162 if (numberValueEle + numberLogfileEle + numberLookUp + numberFormula == 0) {
2164 <<
" contains <parameter> for which no value is specified."
2165 <<
" See docs.mantidproject.org/concepts/InstrumentDefinitionFile for how to set the value"
2166 <<
" of a parameter. This parameter is ignored.";
2170 DateAndTime currentValidFrom;
2171 DateAndTime currentValidTo;
2172 currentValidFrom.setToMinimum();
2173 currentValidTo.setToMaximum();
2177 if (numberValueEle >= 1) {
2178 bool hasValue =
false;
2180 for (
unsigned long j = 0; j < numberValueEle; ++j) {
2181 pValueElem =
static_cast<Element *
>(pNLvalue->item(j));
2183 if (!pValueElem->hasAttribute((
"val")))
2186 validFrom.setToMinimum();
2187 if (pValueElem->hasAttribute(
"valid-from"))
2188 validFrom.setFromISO8601(pValueElem->getAttribute(
"valid-from"));
2190 validTo.setToMaximum();
2191 if (pValueElem->hasAttribute(
"valid-to"))
2192 validTo.setFromISO8601(pValueElem->getAttribute(
"valid-to"));
2194 if (validFrom <= validityDate && validityDate <= validTo &&
2195 (validFrom > currentValidFrom || (validFrom == currentValidFrom && validTo <= currentValidTo))) {
2197 currentValidFrom = validFrom;
2198 currentValidTo = validTo;
2202 value = pValueElem->getAttribute(
"val");
2207 "XML element with name or type = " + comp->
getName() +
2208 " contains <parameter> element with invalid syntax for its "
2209 "subelement <value>. Correct syntax is <value val=\"\"/>",
2213 }
else if (numberLogfileEle >= 1) {
2215 pLogfileElem =
static_cast<Element *
>(pNLlogfile->item(0));
2216 if (!pLogfileElem->hasAttribute(
"id"))
2218 "XML element with name or type = " + comp->
getName() +
2219 " contains <parameter> element with invalid syntax for its "
2220 "subelement logfile>." +
2221 " Correct syntax is <logfile id=\"\"/>",
2223 logfileID = pLogfileElem->getAttribute(
"id");
2225 if (pLogfileElem->hasAttribute(
"eq"))
2226 eq = pLogfileElem->getAttribute(
"eq");
2227 if (pLogfileElem->hasAttribute(
"extract-single-value-as"))
2228 extractSingleValueAs = pLogfileElem->getAttribute(
"extract-single-value-as");
2231 if (pParamElem->hasAttribute(
"type"))
2232 type = pParamElem->getAttribute(
"type");
2237 Poco::AutoPtr<NodeList> pNLFixed = pParamElem->getElementsByTagName(
"fixed");
2238 size_t numberFixed = pNLFixed->length();
2239 if (numberFixed >= 1) {
2245 std::string fittingFunction;
2248 if (type ==
"fitting") {
2249 size_t found = paramName.find(
':');
2250 if (found != std::string::npos) {
2252 size_t index = paramName.find(
':', found + 1);
2253 if (
index != std::string::npos) {
2254 g_log.
error() <<
"Fitting <parameter> in instrument definition file defined "
2256 <<
" more than one column character :. One must used.\n";
2258 fittingFunction = paramName.substr(0, found);
2259 paramName = paramName.substr(found + 1, paramName.size());
2265 std::ostringstream str;
2266 str << paramName <<
"=" <<
value;
2272 std::vector<std::string> constraint(2,
"");
2274 Poco::AutoPtr<NodeList> pNLMin = pParamElem->getElementsByTagName(
"min");
2275 size_t numberMin = pNLMin->length();
2276 Poco::AutoPtr<NodeList> pNLMax = pParamElem->getElementsByTagName(
"max");
2277 size_t numberMax = pNLMax->length();
2279 if (numberMin >= 1) {
2280 auto *pMin =
static_cast<Element *
>(pNLMin->item(0));
2281 constraint[0] = pMin->getAttribute(
"val");
2283 if (numberMax >= 1) {
2284 auto *pMax =
static_cast<Element *
>(pNLMax->item(0));
2285 constraint[1] = pMax->getAttribute(
"val");
2290 std::string penaltyFactor;
2292 Poco::AutoPtr<NodeList> pNL_penaltyFactor = pParamElem->getElementsByTagName(
"penalty-factor");
2293 size_t numberPenaltyFactor = pNL_penaltyFactor->length();
2295 if (numberPenaltyFactor >= 1) {
2296 auto *pPenaltyFactor =
static_cast<Element *
>(pNL_penaltyFactor->item(0));
2297 penaltyFactor = pPenaltyFactor->getAttribute(
"val");
2302 std::vector<std::string> allowedUnits = UnitFactory::Instance().getKeys();
2304 std::shared_ptr<Interpolation> interpolation = std::make_shared<Interpolation>();
2306 if (numberLookUp >= 1) {
2307 auto *pLookUp =
static_cast<Element *
>(pNLLookUp->item(0));
2309 if (pLookUp->hasAttribute(
"interpolation"))
2310 interpolation->setMethod(pLookUp->getAttribute(
"interpolation"));
2311 if (pLookUp->hasAttribute(
"x-unit")) {
2312 std::vector<std::string>::iterator it;
2313 it = find(allowedUnits.begin(), allowedUnits.end(), pLookUp->getAttribute(
"x-unit"));
2314 if (it == allowedUnits.end()) {
2315 g_log.
warning() <<
"x-unit used with interpolation table must be "
2316 "one of the recognised units "
2317 <<
" see http://docs.mantidproject.org/concepts/UnitFactory";
2319 interpolation->setXUnit(pLookUp->getAttribute(
"x-unit"));
2321 if (pLookUp->hasAttribute(
"y-unit")) {
2322 std::vector<std::string>::iterator it;
2323 it = find(allowedUnits.begin(), allowedUnits.end(), pLookUp->getAttribute(
"y-unit"));
2324 if (it == allowedUnits.end()) {
2325 g_log.
warning() <<
"y-unit used with interpolation table must be "
2326 "one of the recognised units "
2327 <<
" see http://docs.mantidproject.org/concepts/UnitFactory";
2329 interpolation->setYUnit(pLookUp->getAttribute(
"y-unit"));
2332 Poco::AutoPtr<NodeList> pNLpoint = pLookUp->getElementsByTagName(
"point");
2333 unsigned long numberPoint = pNLpoint->length();
2335 for (
unsigned long j = 0; j < numberPoint; j++) {
2336 const auto *pPoint =
static_cast<Element *
>(pNLpoint->item(j));
2339 interpolation->addPoint(
x,
y);
2345 std::string formula;
2346 std::string formulaUnit;
2347 std::string resultUnit;
2349 if (numberFormula >= 1) {
2350 auto *pFormula =
static_cast<Element *
>(pNLFormula->item(0));
2351 formula = pFormula->getAttribute(
"eq");
2352 if (pFormula->hasAttribute(
"unit")) {
2353 std::vector<std::string>::iterator it;
2354 it = find(allowedUnits.begin(), allowedUnits.end(), pFormula->getAttribute(
"unit"));
2355 if (it == allowedUnits.end()) {
2356 g_log.
warning() <<
"unit attribute used with formula must be one "
2357 "of the recognized units "
2358 <<
" see http://docs.mantidproject.org/concepts/UnitFactory";
2360 formulaUnit = pFormula->getAttribute(
"unit");
2362 if (pFormula->hasAttribute(
"result-unit"))
2363 resultUnit = pFormula->getAttribute(
"result-unit");
2366 std::string description;
2368 Poco::AutoPtr<NodeList> pNLDescription = pParamElem->getElementsByTagName(
"description");
2369 size_t numberDescription = pNLDescription->length();
2371 if (numberDescription >= 1) {
2373 auto *pDescription =
static_cast<Element *
>(pNLDescription->item(0));
2374 description = pDescription->getAttribute(
"is");
2381 const std::string cacheParamKey = fittingFunction.empty() ? paramName : fittingFunction +
":" + paramName;
2382 auto cacheKey = std::make_pair(cacheParamKey, comp);
2383 auto cacheValue = std::make_shared<XMLInstrumentParameter>(
2384 logfileID,
value, interpolation, formula, formulaUnit, resultUnit, paramName, type, tie, constraint,
2385 penaltyFactor, fittingFunction, extractSingleValueAs, eq, comp,
m_angleConvertConst, description, visible);
2386 auto inserted = logfileCache.emplace(cacheKey, cacheValue);
2387 if (!inserted.second) {
2388 logfileCache[cacheKey] = cacheValue;
2407 const std::string &requestedDate) {
2408 setComponentLinks(instrument, pRootElem, instrument->getLogfileCache(), progress, requestedDate);
2421 Poco::XML::Element *pRootElem,
2426 const auto &units = instrument->getLogfileUnit();
2427 const auto unit_it = units.find(
"angle");
2428 if (unit_it != units.end())
2429 if (unit_it->second ==
"radian")
2432 const std::string elemName =
"component-link";
2433 Poco::AutoPtr<NodeList> pNL_link = pRootElem->getElementsByTagName(elemName);
2434 unsigned long numberLinks = pNL_link->length();
2437 progress->
resetNumSteps(
static_cast<int64_t
>(numberLinks), 0.0, 0.95);
2439 Node *curNode = pRootElem->firstChild();
2441 if (curNode->nodeType() == Node::ELEMENT_NODE && curNode->nodeName() == elemName) {
2442 auto *curElem =
static_cast<Element *
>(curNode);
2447 progress->
report(
"Loading parameters");
2450 std::string
id = curElem->getAttribute(
"id");
2451 std::string
name = curElem->getAttribute(
"name");
2452 std::vector<std::shared_ptr<const Geometry::IComponent>> sharedIComp;
2455 if (
id.length() > 0) {
2457 std::stringstream(
id) >> detid;
2458 std::shared_ptr<const Geometry::IComponent> detector = instrument->getDetector(
static_cast<detid_t>(detid));
2463 g_log.
error() <<
"Error whilst loading parameters. No detector "
2466 g_log.
error() <<
"Please check that your detectors' ids are correct.\n";
2470 sharedIComp.emplace_back(detector);
2473 if (
name.length() > 0) {
2474 auto comp = std::dynamic_pointer_cast<const IComponent>(detector);
2476 bool consistent = (comp->getFullName() ==
name || comp->getName() ==
name);
2478 g_log.
warning() <<
"Error whilst loading parameters. Name '" <<
name <<
"' does not match id '" << detid
2480 g_log.
warning() <<
"Parameters have been applied to detector with id '" << detid
2481 <<
"'. Please check the name is correct.\n";
2487 if (
name.find(
'/', 0) == std::string::npos) {
2488 sharedIComp = instrument->getAllComponentsWithName(
name);
2490 std::shared_ptr<const Geometry::IComponent> shared = instrument->getComponentByName(
name);
2491 sharedIComp.emplace_back(shared);
2495 for (
auto &ptr : sharedIComp) {
2496 std::shared_ptr<const Geometry::Component> sharedComp =
2497 std::dynamic_pointer_cast<const Geometry::Component>(ptr);
2499 if (sharedComp->isParametrized()) {
2500 setLogfile(sharedComp->base(), curElem, logfileCache, requestedDate);
2502 setLogfile(ptr.get(), curElem, logfileCache, requestedDate);
2507 curNode = curNode->nextSibling();
2519 const std::string cacheFullPath = cacheToApply->getFileFullPathStr();
2522 std::shared_ptr<Mantid::Geometry::vtkGeometryCacheReader> reader;
2524 reader = std::make_shared<Mantid::Geometry::vtkGeometryCacheReader>(cacheFullPath);
2525 }
catch (
const std::exception &e) {
2526 g_log.
warning() <<
"Unable to read geometry cache " << cacheFullPath <<
": " << e.what()
2527 <<
"\nThe cache file will be deleted and recreated.\n";
2528 std::error_code removeError;
2529 std::filesystem::remove(cacheFullPath, removeError);
2531 g_log.
warning() <<
"Unable to delete the invalid geometry cache " << cacheFullPath <<
": "
2532 << removeError.message() <<
"\n";
2536 std::map<std::string, std::shared_ptr<Geometry::IObject>>::iterator objItr;
2539 if (
auto csgObj = std::dynamic_pointer_cast<CSGObject>(((*objItr).second))) {
2540 csgObj->setVtkGeometryCacheReader(reader);
2559 std::filesystem::path dir = usedCache->getParentDirectory();
2560 if (!dir.empty() && !std::filesystem::exists(dir)) {
2561 usedCache = std::move(fallBackCache);
2563 g_log.
information() <<
"Geometrycache directory does not exist, writing cache "
2564 "to system temp.\n";
2565 }
else if (!dir.empty() && (std::filesystem::status(dir).permissions() & std::filesystem::perms::owner_write) ==
2566 std::filesystem::perms::none) {
2567 usedCache = std::move(fallBackCache);
2569 g_log.
information() <<
"Geometrycache directory is read only, writing cache "
2570 "to system temp.\n";
2572 }
catch (std::filesystem::filesystem_error &) {
2573 g_log.
error() <<
"Unable to find instrument definition while attempting to "
2575 throw std::runtime_error(
"Unable to find instrument definition while "
2576 "attempting to write cache.\n");
2578 const std::string cacheFullPath = usedCache->getFileFullPathStr();
2579 g_log.
notice() <<
"Creating cache in " << cacheFullPath <<
"\n";
2581 std::map<std::string, std::shared_ptr<Geometry::IObject>>::iterator objItr;
2582 std::shared_ptr<Mantid::Geometry::vtkGeometryCacheWriter> writer(
2586 if (
auto csgObj = std::dynamic_pointer_cast<CSGObject>(((*objItr).second))) {
2587 csgObj->setVtkGeometryCacheWriter(writer);
2591 return cachingOption;
2602 std::filesystem::path fallBackPath =
2603 std::filesystem::path(ConfigService::Instance().getTempDir()) / (this->
getMangledName() +
".vtp");
2610 }
else if (fallBackCache->exists() &&
applyCache(fallBackCache)) {
2615 return cachingOption;
2628 auto physical = std::make_unique<Instrument>(*
m_instrument);
2630 m_instrument->setPhysicalInstrument(std::move(physical));
2635 if (component.second) {
2641 if (component.second->hasAttribute(
"type") &&
dynamic_cast<ObjComponent *
>(component.first)) {
2642 const Poco::XML::XMLString shapeName = component.second->getAttribute(
"type");
2646 auto objCmpt =
dynamic_cast<ObjComponent *
>(component.first);
2648 objCmpt->
setShape(shapeIt->second);
2659 auto *det =
dynamic_cast<Detector *
>(component.first);
2685 std::map<std::string, Poco::XML::Element *> &getTypeElement) {
2688 if (pElem->tagName() !=
"type")
2690 "must be a pointer to an XML "
2691 "element with tag name type.");
2694 Poco::AutoPtr<NodeList> pNLccioh = pElem->getElementsByTagName(
"combine-components-into-one-shape");
2695 if (pNLccioh->length() == 0) {
2697 "element with tag name type,") +
2698 " which contain a <combine-components-into-one-shape> element.");
2702 Poco::AutoPtr<NodeList> pNLalg = pElem->getElementsByTagName(
"algebra");
2703 if (pNLalg->length() == 0) {
2705 " includes a <combine-components-into-one-shape> element. See "
2706 "docs.mantidproject.org/concepts/InstrumentDefinitionFile.");
2710 Poco::AutoPtr<NodeList> pNL = pElem->getElementsByTagName(
"location");
2711 unsigned long numLocation = pNL->length();
2712 if (numLocation == 0) {
2715 " includes a <combine-components-into-one-shape> element. See "
2716 "docs.mantidproject.org/concepts/InstrumentDefinitionFile.");
2720 Poco::AutoPtr<NodeList> pNL_TransRot = pElem->getElementsByTagName(
"translate-rotate-combined-shape-to");
2721 const Element *pTransRot =
nullptr;
2722 if (pNL_TransRot->length() == 1) {
2723 pTransRot =
static_cast<Element *
>(pNL_TransRot->item(0));
2730 std::unordered_set<Element *> allComponentInType;
2731 std::vector<std::string> allLocationName;
2732 for (
unsigned long i = 0; i < numLocation; i++) {
2733 auto *pLoc =
static_cast<Element *
>(pNL->item(i));
2742 std::string locationElementName = pLoc->getAttribute(
"name");
2743 if (std::find(allLocationName.begin(), allLocationName.end(), locationElementName) == allLocationName.end())
2744 allLocationName.emplace_back(locationElementName);
2747 std::string(
"Names in a <type> element containing ") +
2748 "a <combine-components-into-one-shape> element must be unique. " +
"Here error is that " +
2749 locationElementName +
2750 " appears at least twice. See docs.mantidproject.org/concepts/InstrumentDefinitionFile.");
2753 auto baseCoor = std::make_unique<CompAssembly>(
"base");
2768 baseCoor = std::make_unique<CompAssembly>(
"base");
2778 Poco::AutoPtr<Document> pDoc;
2780 pDoc = pParser.parseString(cuboidStr);
2785 Element *pCuboid = pDoc->documentElement();
2786 Poco::AutoPtr<Node> fisse = (pElem->ownerDocument())->importNode(pCuboid,
true);
2787 pElem->appendChild(fisse);
2789 allComponentInType.insert(pCompElem);
2793 for (
const auto &component : allComponentInType)
2794 pElem->removeChild(component);
2806 const Poco::XML::Element *cuboidEle,
2807 const std::string &cuboidName) {
2808 Element *pElem_lfb =
getShapeElement(cuboidEle,
"left-front-bottom-point");
2809 Element *pElem_lft =
getShapeElement(cuboidEle,
"left-front-top-point");
2810 Element *pElem_lbb =
getShapeElement(cuboidEle,
"left-back-bottom-point");
2811 Element *pElem_rfb =
getShapeElement(cuboidEle,
"right-front-bottom-point");
2825 std::ostringstream obj_str;
2827 obj_str <<
"<cuboid id=\"" << cuboidName <<
"\">";
2828 obj_str <<
"<left-front-bottom-point ";
2829 obj_str <<
"x=\"" << p_lfb.
X();
2830 obj_str <<
"\" y=\"" << p_lfb.
Y();
2831 obj_str <<
"\" z=\"" << p_lfb.
Z();
2833 obj_str <<
"<left-front-top-point ";
2834 obj_str <<
"x=\"" << p_lft.
X();
2835 obj_str <<
"\" y=\"" << p_lft.
Y();
2836 obj_str <<
"\" z=\"" << p_lft.
Z();
2838 obj_str <<
"<left-back-bottom-point ";
2839 obj_str <<
"x=\"" << p_lbb.
X();
2840 obj_str <<
"\" y=\"" << p_lbb.
Y();
2841 obj_str <<
"\" z=\"" << p_lbb.
Z();
2843 obj_str <<
"<right-front-bottom-point ";
2844 obj_str <<
"x=\"" << p_rfb.
X();
2845 obj_str <<
"\" y=\"" << p_rfb.
Y();
2846 obj_str <<
"\" z=\"" << p_rfb.
Z();
2848 obj_str <<
"</cuboid>";
2850 return obj_str.str();
2860 comp->
add(dummyComp);
2878 const std::string &cuboidName) {
2880 Poco::AutoPtr<Document> pDoc;
2882 pDoc = pParser.parseString(cuboidXML);
2887 Element *pCuboid = pDoc->documentElement();
2901Poco::AutoPtr<Poco::XML::Document>
2904 size_t nElements(0);
2905 if (pElem->hasAttribute(
"n-elements")) {
2906 auto n = boost::lexical_cast<int>(
Strings::strip(pElem->getAttribute(
"n-elements")));
2911 nElements =
static_cast<size_t>(
n);
2915 "docs.mantidproject.org/concepts/InstrumentDefinitionFile.");
2919 if (pElem->hasAttribute(
"name")) {
2920 name = pElem->getAttribute(
"name");
2923 int nameCountStart(0);
2924 if (pElem->hasAttribute(
"name-count-start")) {
2925 nameCountStart = boost::lexical_cast<int>(
Strings::strip(pElem->getAttribute(
"name-count-start")));
2928 int nameCountIncrement(1);
2929 if (pElem->hasAttribute(
"name-count-increment")) {
2930 nameCountIncrement = boost::lexical_cast<int>(
Strings::strip(pElem->getAttribute(
"name-count-increment")));
2932 if (nameCountIncrement <= 0)
2937 std::set<std::string> rangeAttrs = {
"x",
"y",
"z",
"r",
"t",
"p",
"rot"};
2942 std::set<std::string> rotAttrs = {
"axis-x",
"axis-y",
"axis-z"};
2945 std::set<std::string> allAttrs;
2946 allAttrs.insert(rangeAttrs.begin(), rangeAttrs.end());
2947 allAttrs.insert(rotAttrs.begin(), rotAttrs.end());
2953 std::map<std::string, double> attrValues;
2956 for (
const auto &attr : allAttrs) {
2957 if (pElem->hasAttribute(attr)) {
2958 attrValues[attr] = boost::lexical_cast<double>(
Strings::strip(pElem->getAttribute(attr)));
2963 std::map<std::string, double> rangeAttrSteps;
2966 for (
const auto &rangeAttr : rangeAttrs) {
2967 std::string endAttr = rangeAttr +
"-end";
2968 if (pElem->hasAttribute(endAttr)) {
2969 if (attrValues.find(rangeAttr) == attrValues.end()) {
2973 double from = attrValues[rangeAttr];
2974 auto to = boost::lexical_cast<double>(
Strings::strip(pElem->getAttribute(endAttr)));
2976 rangeAttrSteps[rangeAttr] = (to - from) / (
static_cast<double>(nElements) - 1);
2980 Poco::AutoPtr<Document> pDoc =
new Document;
2981 Poco::AutoPtr<Element> pRoot = pDoc->createElement(
"expansion-of-locations-element");
2982 pDoc->appendChild(pRoot);
2984 for (
size_t i = 0; i < nElements; ++i) {
2985 Poco::AutoPtr<Element> pLoc = pDoc->createElement(
"location");
2987 if (!
name.empty()) {
2989 pLoc->setAttribute(
"name",
name +
std::to_string(nameCountStart + (i * nameCountIncrement)));
2993 for (
auto &attrValue : attrValues) {
2994 pLoc->setAttribute(attrValue.first, boost::lexical_cast<std::string>(attrValue.second));
2997 if (rangeAttrSteps.find(attrValue.first) != rangeAttrSteps.end()) {
2998 attrValue.second += rangeAttrSteps[attrValue.first];
3002 pRoot->appendChild(pLoc);
3016 if (!filename.empty()) {
3017 std::filesystem::path path =
3018 std::filesystem::path(ConfigService::Instance().getVTPFileDirectory()) / (filename +
".vtp");
3019 retVal = path.string();
3035 const std::string &
name) {
3038 Poco::AutoPtr<NodeList> pNL = pElem->getElementsByTagName(
name);
3039 if (pNL->length() != 1) {
3040 throw std::invalid_argument(
"XML element: <" + pElem->tagName() +
3041 "> must contain exactly one sub-element with name: <" +
name +
">.");
3043 auto *retVal =
static_cast<Element *
>(pNL->item(0));
3055 if (pElem->hasAttribute(
"R") || pElem->hasAttribute(
"theta") || pElem->hasAttribute(
"phi")) {
3061 }
else if (pElem->hasAttribute(
"r") || pElem->hasAttribute(
"t") || pElem->hasAttribute(
"p"))
3102 const Poco::XML::Element *pLocElem,
3103 std::map<std::string, Poco::XML::Element *> &getTypeElement,
3119 Element *pType =
getTypeElement[pCompElem->getAttribute(
"type")];
3127 Poco::AutoPtr<NodeList> pNL = pType->getElementsByTagName(
"location");
3128 if (pNL->length() == 0) {
3129 return pType->getAttribute(
"name");
3130 }
else if (pNL->length() == 1) {
3131 const auto *pElem =
static_cast<Element *
>(pNL->item(0));
3135 std::string(
"When using <combine-components-into-one-shape> ") +
3136 " the containing component elements are not allowed to contain "
3137 "multiple nested components. See docs.mantidproject.org/concepts/InstrumentDefinitionFile.");
double value
The value of the point.
std::map< DeltaEMode::Type, std::string > index
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
double obj
the value of the quadratic function
Class for Assembly of geometric components.
Component is a wrapper for a Component which can modify some of its parameters, e....
void setRot(const Kernel::Quat &) override
Set the orientation Kernel::Quaternion relative to parent (if present)
void setParent(IComponent *) override
Assign a parent IComponent. Previous parent link is lost.
Kernel::V3D getPos() const override
Get the position of the IComponent. Tree structure is traverse through the.
void setPos(double, double, double) override
Set the IComponent position, x, y, z respective to parent (if present)
This class represents a detector - i.e.
detid_t getID() const override
Gets the detector id.
GridDetector is a type of CompAssembly, an assembly of components.
static bool compareName(const std::string &proposedMatch)
Matches name to Structured Detector.
Class for Assembly of geometric components.
virtual int add(IComponent *)=0
Add a component to the assembly.
base class for Geometric IComponent
virtual Kernel::V3D getPos() const =0
Get the position of the IComponent. Tree structure is traverse through the.
virtual void setSideBySideViewPos(const Kernel::V2D &)=0
virtual void setPos(double, double, double)=0
Set the IComponent position, x, y, z respective to parent (if present)
virtual std::shared_ptr< const IComponent > getParent() const =0
Return a pointer to the current parent.
virtual Kernel::Quat getRotation() const =0
Get the absolute orientation of the IComponent.
virtual void translate(const Kernel::V3D &)=0
Copy the Rotation from another IComponent.
virtual void rotate(const Kernel::Quat &)=0
Rotate the IComponent. This is relative to parent.
virtual std::string getName() const =0
Get the IComponent name.
Creates an instrument data from a XML instrument description file.
bool m_deltaOffsets
Flag to indicate whether offsets given in spherical coordinates are to be added to the current positi...
void appendLocations(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElems, const Poco::XML::Element *pCompElem, IdList &idList)
Append <locations> in a locations element.
void createNeutronicInstrument()
If appropriate, creates a second instrument containing neutronic detector positions.
std::shared_ptr< Instrument > parseXML(Kernel::ProgressBase *progressReporter)
Parse XML contents.
void createStructuredDetector(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElem, const Poco::XML::Element *pCompElem, const std::string &filename, const Poco::XML::Element *pType)
void adjustTypesContainingCombineComponentsElement(ShapeFactory &shapeCreator, const std::string &filename, const std::vector< Poco::XML::Element * > &typeElems, size_t numberOfTypes)
Adjust each type which contains a <combine-components-into-one-shape> element.
void getTypeAndComponentPointers(const Poco::XML::Element *pRootElem, std::vector< Poco::XML::Element * > &typeElems, std::vector< Poco::XML::Element * > &compElems) const
Populate vectors of pointers to type and component xml elements.
void throwIfTypeNameNotUnique(const std::string &filename, const std::string &typeName) const
Throw exception if type name is not unique in the IDF.
std::map< const Geometry::IComponent *, SphVec > m_tempPosHolder
Map to store positions of parent components in spherical coordinates.
void createDetectorOrMonitor(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElem, const Poco::XML::Element *pCompElem, const std::string &filename, IdList &idList, const std::string &category)
std::string translateRotateXMLcuboid(Geometry::ICompAssembly *comp, const Poco::XML::Element *cuboidEle, const std::string &cuboidName)
Returns a translated and rotated <cuboid> element.
void createRectangularDetector(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElem, const Poco::XML::Element *pCompElem, const std::string &filename, const Poco::XML::Element *pType)
double m_angleConvertConst
when this const equals 1 it means that angle=degree (default) is set in IDF otherwise if this const e...
void appendLeaf(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElem, const Poco::XML::Element *pCompElem, IdList &idList)
Add XML element to parent assuming the element contains no other component elements.
std::string getMangledName()
Handle used in the singleton constructor for instrument file should append the value file sha-1 check...
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> ...
void adjust(Poco::XML::Element *pElem, const std::map< std::string, bool > &isTypeAssembly, std::map< std::string, Poco::XML::Element * > &getTypeElement)
Takes as input a <type> element containing a <combine-components-into-one-shape>, and adjust the <typ...
bool m_haveDefaultFacing
True if defaults->components-are-facing is set in instrument def. file.
void setLocation(Geometry::IComponent *comp, const Poco::XML::Element *pElem, const double angleConvertConst, const bool deltaOffsets=false)
Set location (position) of comp as specified in XML location element.
Kernel::V3D m_defaultFacing
Hold default facing position.
CachingOption getAppliedCachingOption() const
Get the applied caching option.
std::map< Geometry::IComponent *, Poco::XML::Element * > m_neutronicPos
A map containing the neutronic position for each detector.
void checkComponentContainsLocationElement(Poco::XML::Element *pElem, const std::string &filename) const
Check component has a <location> or <locations> element.
Kernel::V3D parseFacingElementToV3D(Poco::XML::Element *pElem)
Parse position of facing element to V3D.
void collateTypeInformation(const std::string &filename, const std::vector< Poco::XML::Element * > &typeElems, ShapeFactory &shapeCreator)
Collect some information about types for later use.
IDFObject_const_sptr m_cacheFile
Input vtp file.
void setSideBySideViewLocation(Geometry::IComponent *comp, const Poco::XML::Element *pCompElem)
Set location (position) of comp as specified in XML side-by-side-view-location element.
std::shared_ptr< Geometry::Instrument > m_instrument
For convenience added pointer to instrument here.
InstrumentDefinitionParser()
Default Constructor - not very functional in this state.
CachingOption writeAndApplyCache(IDFObject_const_sptr firstChoiceCache, IDFObject_const_sptr fallBackCache)
Write out a cache file.
bool m_mixedNeutronicPositions
True if the IDF has <indirect-neutronic-positions-mixed/> tag set, allowing detectors without <neutro...
Kernel::V3D parsePosition(Poco::XML::Element *pElem)
Get position coordinates from XML element.
void makeXYplaneFaceComponent(Geometry::IComponent *&in, const Geometry::ObjComponent *facing)
Make the shape defined in 1st argument face the component in the second argument.
Kernel::V3D getRelativeTranslation(const Geometry::IComponent *comp, const Poco::XML::Element *pElem, const double angleConvertConst, const bool deltaOffsets=false)
Calculate the position of comp relative to its parent from info provided by <location> element.
std::vector< Poco::XML::Element * > m_hasParameterElement
Holds all the xml elements that have a <parameter> child element.
void setFacing(Geometry::IComponent *comp, const Poco::XML::Element *pElem)
Set facing of comp as specified in XML facing element.
void readDefaults(Poco::XML::Element *defaults)
Reads the contents of the <defaults> element to set member variables,.
Poco::AutoPtr< Poco::XML::Document > m_pDoc
XML document is lazy loaded.
void populateIdList(Poco::XML::Element *pE, IdList &idList)
Method for populating IdList.
std::map< std::string, std::shared_ptr< Geometry::IObject > > mapTypeNameToShape
map which maps the type name to a shared pointer to a geometric shape
void createShapeIfTypeIsNotAnAssembly(Mantid::Geometry::ShapeFactory &shapeCreator, size_t iType, Poco::XML::Element *pTypeElem, const std::string &typeName)
Record type as an assembly if it contains a component, otherwise create a shape for it.
std::map< std::string, bool > isTypeAssembly
map which holds names of types and whether or not they are categorized as being assemblies,...
void setLogfile(const Geometry::IComponent *comp, const Poco::XML::Element *pElem, InstrumentParameterCache &logfileCache, const std::string &requestedDate=std::string())
Set parameter/logfile info (if any) associated with component.
void createGridDetector(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElem, const Poco::XML::Element *pCompElem, const std::string &filename, const Poco::XML::Element *pType)
const std::string createVTPFileName()
creates a vtp filename from a given xml filename
void parseLocationsForEachTopLevelComponent(Kernel::ProgressBase *progressReporter, const std::string &filename, const std::vector< Poco::XML::Element * > &compElems)
Aggregate locations and IDs for components.
static Poco::XML::Element * getParentComponent(const Poco::XML::Element *pLocElem)
Get parent component element of location element.
std::map< std::string, Poco::XML::Element * > getTypeElement
map which holds names of types and pointers to these type for fast retrieval in code
Poco::XML::Element * getShapeElement(const Poco::XML::Element *pElem, const std::string &name)
Return a subelement of an XML element.
void appendAssembly(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElem, const Poco::XML::Element *pCompElem, IdList &idList)
Add XML element to parent assuming the element contains other component elements.
std::vector< std::string > buildExcludeList(const Poco::XML::Element *const location)
void createVectorOfElementsContainingAParameterElement(Poco::XML::Element *pRootElem)
Create a vector of elements which contain a <parameter>
std::string getShapeCoorSysComp(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElem, std::map< std::string, Poco::XML::Element * > &getTypeElement, Geometry::ICompAssembly *&endAssembly)
This method returns the parent appended which its child components and also name of type of the last ...
CachingOption setupGeometryCache()
Reads in or creates the geometry cache ('vtp') file.
bool applyCache(const IDFObject_const_sptr &cacheToApply)
Reads from a cache file.
void setValidityRange(const Poco::XML::Element *pRootElem)
Check the validity range and add it to the instrument object.
bool m_hasParameterElement_beenSet
has m_hasParameterElement been set - used when public method setComponentLinks is used
IDFObject_const_sptr m_xmlFile
Input xml file.
double attrToDouble(const Poco::XML::Element *pElem, const std::string &name)
return 0 if the attribute doesn't exist.
void initialise(const std::string &filename, const std::string &instName, const std::string &xmlText, const std::string &vtpFilename)
shared Constructor logic
Poco::AutoPtr< Poco::XML::Document > convertLocationsElement(const Poco::XML::Element *pElem)
Take as input a <locations> element.
std::vector< Geometry::ObjComponent * > m_facingComponent
Container to hold all detectors and monitors added to the instrument.
std::string m_instName
Name of the instrument.
Kernel::V3D getAbsolutPositionInCompCoorSys(Geometry::ICompAssembly *comp, Kernel::V3D)
return absolute position of point which is set relative to the coordinate system of the input compone...
static std::string getNameOfLocationElement(const Poco::XML::Element *pElem, const Poco::XML::Element *pCompElem)
get name of location element
Poco::AutoPtr< Poco::XML::Document > getDocument()
lazy loads the document and returns a pointer
bool isAssembly(const std::string &) const
Return true if assembly, false if not assembly and throws exception if string not in assembly.
bool m_sideBySideViewLocation_exists
Store if xml text contains side-by-side-view-location string.
bool m_indirectPositions
Flag to indicate whether IDF contains physical & neutronic positions.
void checkIdListExistsAndDefinesEnoughIDs(const IdList &idList, Poco::XML::Element *pElem, const std::string &filename) const
Check IdList.
CachingOption m_cachingOption
Caching applied.
void saveDOM_Tree(const std::string &outFilename)
Save DOM tree to xml file.
Class for Assembly of geometric components.
Object Component class, this class brings together the physical attributes of the component to the po...
void setShape(std::shared_ptr< const IObject > newShape)
Set a new shape on the component void setShape(std::shared_ptr<const IObject> newShape);.
RectangularDetector is a type of CompAssembly, an assembly of components.
static bool compareName(const std::string &proposedMatch)
Matches name to Structured Detector.
Class originally intended to be used with the DataHandling 'LoadInstrument' algorithm.
std::shared_ptr< CSGObject > createShape(Poco::XML::Element *pElem)
Creates a geometric object from a DOM-element-node pointing to an element whose child nodes contain t...
StructuredDetector is a type of CompAssembly, an assembly of components.
static bool compareName(const std::string &proposedMatch)
Matches name to Structured Detector.
Writes the Geometry from Object to Cache.
Exception for when an item is already in a collection.
Exception for errors associated with the instrument definition.
The Logger class is in charge of the publishing messages from the framework through various channels.
void notice(const std::string &msg)
Logs at notice level.
void error(const std::string &msg)
Logs at error level.
void warning(const std::string &msg)
Logs at warning level.
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.
virtual bool hasCancellationBeenRequested() const
Override so that the reporter can inform whether a cancellation request has been used.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
void inverse()
Inverse a quaternion (in the sense of rotation inversion)
void rotate(V3D &) const
Rotate a vector.
Implements a 2-dimensional vector embedded in a 3D space, i.e.
constexpr double X() const noexcept
Get x.
constexpr V3D cross_prod(const V3D &v) const noexcept
Cross product (this * argument)
constexpr double Y() const noexcept
Get y.
void spherical(const double R, const double theta, const double phi) noexcept
Sets the vector position based on spherical coordinates.
double angle(const V3D &) const
Angle between this and another vector.
double norm() const noexcept
constexpr double Z() const noexcept
Get z.
Handedness
Type to distingusih between l and r handedness.
std::map< std::pair< std::string, const IComponent * >, std::shared_ptr< XMLInstrumentParameter > > InstrumentParameterCache
Convenience typedef.
Mantid::Kernel::Logger g_log("Goniometer")
std::shared_ptr< const AbstractIDFObject > IDFObject_const_sptr
PointingAlong axisNameToAxisType(const std::string &label, const std::string &input)
std::shared_ptr< Instrument > Instrument_sptr
Shared pointer to an instrument object.
PointingAlong
Type to describe pointing along options.
MANTID_KERNEL_DLL std::string sha1FromString(const std::string &input)
create a SHA-1 checksum from a string
MANTID_KERNEL_DLL std::string strip(const std::string &A)
strip pre/post spaces
MANTID_KERNEL_DLL V3D normalize(V3D v)
Normalizes a V3D.
Helper class which provides the Collimation Length for SANS instruments.
int32_t detid_t
Typedef for a detector ID.
std::string to_string(const wide_integer< Bits, Signed > &n)
Structure for holding detector IDs.
std::vector< int > vec
list of detector IDs
int counted
Used to count the number of detector encounted so far.
std::string idname
name of idlist
Stripped down vector that holds position in terms of spherical coordinates, Needed when processing in...