Mantid
Loading...
Searching...
No Matches
InstrumentDefinitionParser.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 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 +
7#pragma once
8
11#include "MantidKernel/V3D.h"
12#include <Poco/AutoPtr.h>
13#include <Poco/DOM/Document.h>
14#include <string>
15#include <vector>
16
17namespace Poco {
18namespace XML {
19class Element;
20}
21} // namespace Poco
22
23namespace Mantid {
24namespace Kernel {
25class ProgressBase;
26}
27
28namespace Geometry {
29class ICompAssembly;
30class IComponent;
31class Instrument;
32class ObjComponent;
33class IObject;
34class ShapeFactory;
35
43class MANTID_GEOMETRY_DLL InstrumentDefinitionParser {
44public:
46 InstrumentDefinitionParser(const std::string &filename, const std::string &instName, const std::string &xmlText);
47 InstrumentDefinitionParser(const IDFObject_const_sptr &xmlFile, const IDFObject_const_sptr &expectedCacheFile,
48 const std::string &instName, const std::string &xmlText);
50
52 enum CachingOption { NoneApplied, ReadGeomCache, ReadFallBack, WroteGeomCache, WroteCacheTemp };
53
55 std::shared_ptr<Instrument> parseXML(Kernel::ProgressBase *progressReporter);
56
59 void setComponentLinks(std::shared_ptr<Geometry::Instrument> &instrument, Poco::XML::Element *pRootElem,
60 Kernel::ProgressBase *progress = nullptr, const std::string &requestedDate = std::string());
61
64 void setComponentLinks(const std::shared_ptr<const Geometry::Instrument> &instrument, Poco::XML::Element *pRootElem,
65 InstrumentParameterCache &logfileCache, Kernel::ProgressBase *progress = nullptr,
66 const std::string &requestedDate = std::string());
67
68 std::string getMangledName();
69
71 static Poco::XML::Element *getParentComponent(const Poco::XML::Element *pLocElem);
72
74 static std::string getNameOfLocationElement(const Poco::XML::Element *pElem, const Poco::XML::Element *pCompElem);
75
77 void saveDOM_Tree(const std::string &outFilename);
78
80 CachingOption getAppliedCachingOption() const;
81
83 const std::string createVTPFileName();
84
85private:
87 void initialise(const std::string &filename, const std::string &instName, const std::string &xmlText,
88 const std::string &vtpFilename);
89
91 Poco::AutoPtr<Poco::XML::Document> getDocument();
92
94 void setLocation(Geometry::IComponent *comp, const Poco::XML::Element *pElem, const double angleConvertConst,
95 const bool deltaOffsets = false);
97 void setSideBySideViewLocation(Geometry::IComponent *comp, const Poco::XML::Element *pCompElem);
98
101 Kernel::V3D getRelativeTranslation(const Geometry::IComponent *comp, const Poco::XML::Element *pElem,
102 const double angleConvertConst, const bool deltaOffsets = false);
103
105 void setValidityRange(const Poco::XML::Element *pRootElem);
106
108 void readDefaults(Poco::XML::Element *defaults);
109
111 struct IdList {
115 std::vector<int> vec;
117 std::string idname;
118
120 IdList() : counted(0) {};
121
123 bool empty() { return vec.empty(); };
124
126 void reset() {
127 counted = 0;
128 vec.clear();
129 };
130 };
131
133 void populateIdList(Poco::XML::Element *pE, IdList &idList);
134
135 std::vector<std::string> buildExcludeList(const Poco::XML::Element *const location);
136
139 void appendAssembly(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElem,
140 const Poco::XML::Element *pCompElem, IdList &idList);
143 bool isAssembly(const std::string &) const;
144
147 void appendLeaf(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElem,
148 const Poco::XML::Element *pCompElem, IdList &idList);
149
150 void createDetectorOrMonitor(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElem,
151 const Poco::XML::Element *pCompElem, const std::string &filename, IdList &idList,
152 const std::string &category);
153
154 void createGridDetector(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElem,
155 const Poco::XML::Element *pCompElem, const std::string &filename,
156 const Poco::XML::Element *pType);
157
158 void createRectangularDetector(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElem,
159 const Poco::XML::Element *pCompElem, const std::string &filename,
160 const Poco::XML::Element *pType);
161
162 void createStructuredDetector(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElem,
163 const Poco::XML::Element *pCompElem, const std::string &filename,
164 const Poco::XML::Element *pType);
165
167 void appendLocations(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElems,
168 const Poco::XML::Element *pCompElem, IdList &idList);
169
171 void setLogfile(const Geometry::IComponent *comp, const Poco::XML::Element *pElem,
172 InstrumentParameterCache &logfileCache, const std::string &requestedDate = std::string());
173
175 Kernel::V3D parseFacingElementToV3D(Poco::XML::Element *pElem);
177 void setFacing(Geometry::IComponent *comp, const Poco::XML::Element *pElem);
180 void makeXYplaneFaceComponent(Geometry::IComponent *&in, const Geometry::ObjComponent *facing);
183 void makeXYplaneFaceComponent(Geometry::IComponent *&in, const Kernel::V3D &facingPoint);
184
186 CachingOption setupGeometryCache();
187
190 void createNeutronicInstrument();
191
198 void adjust(Poco::XML::Element *pElem, const std::map<std::string, bool> &isTypeAssembly,
199 std::map<std::string, Poco::XML::Element *> &getTypeElement);
200
204 Poco::AutoPtr<Poco::XML::Document> convertLocationsElement(const Poco::XML::Element *pElem);
205
208 double attrToDouble(const Poco::XML::Element *pElem, const std::string &name);
209
211 void getTypeAndComponentPointers(const Poco::XML::Element *pRootElem, std::vector<Poco::XML::Element *> &typeElems,
212 std::vector<Poco::XML::Element *> &compElems) const;
213
215 void throwIfTypeNameNotUnique(const std::string &filename, const std::string &typeName) const;
216
219 void createShapeIfTypeIsNotAnAssembly(Mantid::Geometry::ShapeFactory &shapeCreator, size_t iType,
220 Poco::XML::Element *pTypeElem, const std::string &typeName);
221
224 void adjustTypesContainingCombineComponentsElement(ShapeFactory &shapeCreator, const std::string &filename,
225 const std::vector<Poco::XML::Element *> &typeElems,
226 size_t numberOfTypes);
227
229 void createVectorOfElementsContainingAParameterElement(Poco::XML::Element *pRootElem);
230
232 void checkIdListExistsAndDefinesEnoughIDs(const IdList &idList, Poco::XML::Element *pElem,
233 const std::string &filename) const;
234
236 void checkComponentContainsLocationElement(Poco::XML::Element *pElem, const std::string &filename) const;
237
239 void parseLocationsForEachTopLevelComponent(Kernel::ProgressBase *progressReporter, const std::string &filename,
240 const std::vector<Poco::XML::Element *> &compElems);
241
243 void collateTypeInformation(const std::string &filename, const std::vector<Poco::XML::Element *> &typeElems,
244 ShapeFactory &shapeCreator);
245
246public: // for testing
249 Kernel::V3D getAbsolutPositionInCompCoorSys(Geometry::ICompAssembly *comp, Kernel::V3D);
250
251private:
254 bool applyCache(const IDFObject_const_sptr &cacheToApply);
255
257 CachingOption writeAndApplyCache(IDFObject_const_sptr firstChoiceCache, IDFObject_const_sptr fallBackCache);
258
261 std::string getShapeCoorSysComp(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElem,
262 std::map<std::string, Poco::XML::Element *> &getTypeElement,
263 Geometry::ICompAssembly *&endAssembly);
264
266 std::string translateRotateXMLcuboid(Geometry::ICompAssembly *comp, const Poco::XML::Element *cuboidEle,
267 const std::string &cuboidName);
269 std::string translateRotateXMLcuboid(Geometry::ICompAssembly *comp, const std::string &cuboidXML,
270 const std::string &cuboidName);
271
273 Poco::XML::Element *getShapeElement(const Poco::XML::Element *pElem, const std::string &name);
274
276 Kernel::V3D parsePosition(Poco::XML::Element *pElem);
277
280
283
285 std::string m_instName;
286
289
291 Poco::AutoPtr<Poco::XML::Document> m_pDoc;
292
301 std::vector<Poco::XML::Element *> m_hasParameterElement;
310 std::map<std::string, bool> isTypeAssembly;
312 std::map<std::string, std::shared_ptr<Geometry::IObject>> mapTypeNameToShape;
316 std::vector<Geometry::ObjComponent *> m_facingComponent;
323 std::map<std::string, Poco::XML::Element *> getTypeElement;
324
326 std::shared_ptr<Geometry::Instrument> m_instrument;
327
332
338
343 std::map<Geometry::IComponent *, Poco::XML::Element *> m_neutronicPos;
344
349
355 struct SphVec {
357 double r, theta, phi;
358 SphVec() : r(0.0), theta(0.0), phi(0.0) {}
359 SphVec(const double &r, const double &theta, const double &phi) : r(r), theta(theta), phi(phi) {}
361 };
362
364 std::map<const Geometry::IComponent *, SphVec> m_tempPosHolder;
365
368};
369
370} // namespace Geometry
371} // namespace Mantid
std::string name
Definition Run.cpp:60
std::vector< T > const * vec
Class for Assembly of geometric components.
base class for Geometric IComponent
Definition IComponent.h:53
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...
std::map< const Geometry::IComponent *, SphVec > m_tempPosHolder
Map to store positions of parent components in spherical coordinates.
double m_angleConvertConst
when this const equals 1 it means that angle=degree (default) is set in IDF otherwise if this const e...
bool m_haveDefaultFacing
True if defaults->components-are-facing is set in instrument def. file.
Kernel::V3D m_defaultFacing
Hold default facing position.
std::map< Geometry::IComponent *, Poco::XML::Element * > m_neutronicPos
A map containing the neutronic position for each detector.
std::shared_ptr< Geometry::Instrument > m_instrument
For convenience added pointer to instrument here.
bool m_mixedNeutronicPositions
True if the IDF has <indirect-neutronic-positions-mixed/> tag set, allowing detectors without <neutro...
std::vector< Poco::XML::Element * > m_hasParameterElement
Holds all the xml elements that have a <parameter> child element.
Poco::AutoPtr< Poco::XML::Document > m_pDoc
XML document is lazy loaded.
std::map< std::string, std::shared_ptr< Geometry::IObject > > mapTypeNameToShape
map which maps the type name to a shared pointer to a geometric shape
std::map< std::string, bool > isTypeAssembly
map which holds names of types and whether or not they are categorized as being assemblies,...
std::map< std::string, Poco::XML::Element * > getTypeElement
map which holds names of types and pointers to these type for fast retrieval in code
bool m_hasParameterElement_beenSet
has m_hasParameterElement been set - used when public method setComponentLinks is used
std::vector< Geometry::ObjComponent * > m_facingComponent
Container to hold all detectors and monitors added to the instrument.
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.
Object Component class, this class brings together the physical attributes of the component to the po...
Class originally intended to be used with the DataHandling 'LoadInstrument' algorithm.
Class for 3D vectors.
Definition V3D.h:35
std::map< std::pair< std::string, const IComponent * >, std::shared_ptr< XMLInstrumentParameter > > InstrumentParameterCache
Convenience typedef.
Definition Instrument.h:40
std::shared_ptr< const AbstractIDFObject > IDFObject_const_sptr
Definition IDFObject.h:94
Helper class which provides the Collimation Length for SANS instruments.
int counted
Used to count the number of detector encounted so far.
Stripped down vector that holds position in terms of spherical coordinates, Needed when processing in...