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
62 std::string getMangledName();
63
65 static Poco::XML::Element *getParentComponent(const Poco::XML::Element *pLocElem);
66
68 static std::string getNameOfLocationElement(const Poco::XML::Element *pElem, const Poco::XML::Element *pCompElem);
69
71 void saveDOM_Tree(std::string &outFilename);
72
74 CachingOption getAppliedCachingOption() const;
75
77 const std::string createVTPFileName();
78
79private:
81 void initialise(const std::string &filename, const std::string &instName, const std::string &xmlText,
82 const std::string &vtpFilename);
83
85 Poco::AutoPtr<Poco::XML::Document> getDocument();
86
88 void setLocation(Geometry::IComponent *comp, const Poco::XML::Element *pElem, const double angleConvertConst,
89 const bool deltaOffsets = false);
90
93 Kernel::V3D getRelativeTranslation(const Geometry::IComponent *comp, const Poco::XML::Element *pElem,
94 const double angleConvertConst, const bool deltaOffsets = false);
95
97 void setValidityRange(const Poco::XML::Element *pRootElem);
98
100 void readDefaults(Poco::XML::Element *defaults);
101
103 struct IdList {
107 std::vector<int> vec;
109 std::string idname;
110
112 IdList() : counted(0){};
113
115 bool empty() { return vec.empty(); };
116
118 void reset() {
119 counted = 0;
120 vec.clear();
121 };
122 };
123
125 void populateIdList(Poco::XML::Element *pE, IdList &idList);
126
127 std::vector<std::string> buildExcludeList(const Poco::XML::Element *const location);
128
131 void appendAssembly(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElem,
132 const Poco::XML::Element *pCompElem, IdList &idList);
135 bool isAssembly(const std::string &) const;
136
139 void appendLeaf(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElem,
140 const Poco::XML::Element *pCompElem, IdList &idList);
141
142 void createDetectorOrMonitor(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElem,
143 const Poco::XML::Element *pCompElem, const std::string &filename, IdList &idList,
144 const std::string &category);
145
146 void createGridDetector(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElem,
147 const Poco::XML::Element *pCompElem, const std::string &filename,
148 const Poco::XML::Element *pType);
149
150 void createRectangularDetector(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElem,
151 const Poco::XML::Element *pCompElem, const std::string &filename,
152 const Poco::XML::Element *pType);
153
154 void createStructuredDetector(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
159 void appendLocations(Geometry::ICompAssembly *parent, const Poco::XML::Element *pLocElems,
160 const Poco::XML::Element *pCompElem, IdList &idList);
161
163 void setLogfile(const Geometry::IComponent *comp, const Poco::XML::Element *pElem,
164 InstrumentParameterCache &logfileCache, const std::string &requestedDate = std::string());
165
167 Kernel::V3D parseFacingElementToV3D(Poco::XML::Element *pElem);
169 void setFacing(Geometry::IComponent *comp, const Poco::XML::Element *pElem);
172 void makeXYplaneFaceComponent(Geometry::IComponent *&in, const Geometry::ObjComponent *facing);
175 void makeXYplaneFaceComponent(Geometry::IComponent *&in, const Kernel::V3D &facingPoint);
176
178 CachingOption setupGeometryCache();
179
182 void createNeutronicInstrument();
183
190 void adjust(Poco::XML::Element *pElem, std::map<std::string, bool> &isTypeAssembly,
191 std::map<std::string, Poco::XML::Element *> &getTypeElement);
192
196 Poco::AutoPtr<Poco::XML::Document> convertLocationsElement(const Poco::XML::Element *pElem);
197
200 double attrToDouble(const Poco::XML::Element *pElem, const std::string &name);
201
203 void getTypeAndComponentPointers(const Poco::XML::Element *pRootElem, std::vector<Poco::XML::Element *> &typeElems,
204 std::vector<Poco::XML::Element *> &compElems) const;
205
207 void throwIfTypeNameNotUnique(const std::string &filename, const std::string &typeName) const;
208
211 void createShapeIfTypeIsNotAnAssembly(Mantid::Geometry::ShapeFactory &shapeCreator, size_t iType,
212 Poco::XML::Element *pTypeElem, const std::string &typeName);
213
216 void adjustTypesContainingCombineComponentsElement(ShapeFactory &shapeCreator, const std::string &filename,
217 const std::vector<Poco::XML::Element *> &typeElems,
218 size_t numberOfTypes);
219
221 void createVectorOfElementsContainingAParameterElement(Poco::XML::Element *pRootElem);
222
224 void checkIdListExistsAndDefinesEnoughIDs(const IdList &idList, Poco::XML::Element *pElem,
225 const std::string &filename) const;
226
228 void checkComponentContainsLocationElement(Poco::XML::Element *pElem, const std::string &filename) const;
229
231 void parseLocationsForEachTopLevelComponent(Kernel::ProgressBase *progressReporter, const std::string &filename,
232 const std::vector<Poco::XML::Element *> &compElems);
233
235 void collateTypeInformation(const std::string &filename, const std::vector<Poco::XML::Element *> &typeElems,
236 ShapeFactory &shapeCreator);
237
238public: // for testing
241 Kernel::V3D getAbsolutPositionInCompCoorSys(Geometry::ICompAssembly *comp, Kernel::V3D);
242
243private:
245 void applyCache(const IDFObject_const_sptr &cacheToApply);
246
248 CachingOption writeAndApplyCache(IDFObject_const_sptr firstChoiceCache, IDFObject_const_sptr fallBackCache);
249
252 std::string getShapeCoorSysComp(Geometry::ICompAssembly *parent, Poco::XML::Element *pLocElem,
253 std::map<std::string, Poco::XML::Element *> &getTypeElement,
254 Geometry::ICompAssembly *&endAssembly);
255
257 std::string translateRotateXMLcuboid(Geometry::ICompAssembly *comp, const Poco::XML::Element *cuboidEle,
258 const std::string &cuboidName);
260 std::string translateRotateXMLcuboid(Geometry::ICompAssembly *comp, const std::string &cuboidXML,
261 const std::string &cuboidName);
262
264 Poco::XML::Element *getShapeElement(const Poco::XML::Element *pElem, const std::string &name);
265
267 Kernel::V3D parsePosition(Poco::XML::Element *pElem);
268
271
274
276 std::string m_instName;
277
279 Poco::AutoPtr<Poco::XML::Document> m_pDoc;
280
289 std::vector<Poco::XML::Element *> m_hasParameterElement;
298 std::map<std::string, bool> isTypeAssembly;
300 std::map<std::string, std::shared_ptr<Geometry::IObject>> mapTypeNameToShape;
304 std::vector<Geometry::ObjComponent *> m_facingComponent;
311 std::map<std::string, Poco::XML::Element *> getTypeElement;
312
314 std::shared_ptr<Geometry::Instrument> m_instrument;
315
320
326
331 std::map<Geometry::IComponent *, Poco::XML::Element *> m_neutronicPos;
332
338 struct SphVec {
340 double r, theta, phi;
341 SphVec() : r(0.0), theta(0.0), phi(0.0) {}
342 SphVec(const double &r, const double &theta, const double &phi) : r(r), theta(theta), phi(phi) {}
344 };
345
347 std::map<const Geometry::IComponent *, SphVec> m_tempPosHolder;
348
351};
352
353} // namespace Geometry
354} // namespace Mantid
Class for Assembly of geometric components.
Definition: ICompAssembly.h:30
base class for Geometric IComponent
Definition: IComponent.h:51
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.
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_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...
Definition: ObjComponent.h:33
Class originally intended to be used with the DataHandling 'LoadInstrument' algorithm.
Definition: ShapeFactory.h:89
Class for 3D vectors.
Definition: V3D.h:34
std::map< std::pair< std::string, const IComponent * >, std::shared_ptr< XMLInstrumentParameter > > InstrumentParameterCache
Convenience typedef.
Definition: Instrument.h:37
std::shared_ptr< const AbstractIDFObject > IDFObject_const_sptr
Definition: IDFObject.h:92
Helper class which provides the Collimation Length for SANS instruments.
Definition: Algorithm.h:30
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...