Mantid
Loading...
Searching...
No Matches
LoadDetectorsGroupingFile.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2011 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
10#include "MantidDataHandling/DllConfig.h"
12
13#include <Poco/DOM/Document.h>
14
15#include <fstream>
16
17namespace Poco {
18namespace XML {
19class Element;
20class Node;
21} // namespace XML
22} // namespace Poco
23
24namespace Mantid {
25namespace DataHandling {
26
36class MANTID_DATAHANDLING_DLL LoadDetectorsGroupingFile final : public API::Algorithm {
37public:
39 const std::string name() const override { return "LoadDetectorsGroupingFile"; };
41 const std::string summary() const override {
42 return "Load an XML or Map file, which contains definition of detectors "
43 "grouping, to a GroupingWorkspace.";
44 }
45
47 int version() const override { return 1; };
48 const std::vector<std::string> seeAlso() const override { return {"SaveDetectorsGrouping", "GroupDetectors"}; }
50 const std::string category() const override { return "DataHandling\\Grouping;Transforms\\Grouping"; }
51
52private:
54 void init() override;
56 void exec() override;
58 void initializeXMLParser(const std::string &filename);
60 void parseXML();
62 void intializeGroupingWorkspace();
64 void setByComponents();
66 void setByDetectors();
68 void setBySpectrumNos();
70 void parseDetectorIDs(std::string inputstring, std::vector<detid_t> &detids);
72 void parseSpectrumNos(std::string inputstring, std::vector<int> &specids);
74 static std::string getAttributeValueByName(Poco::XML::Node *pNode, std::string attributename, bool &found);
76 void parseRangeText(std::string inputstr, std::vector<int32_t> &singles, std::vector<int32_t> &pairs);
78 void generateNoInstrumentGroupWorkspace();
79
82
85
87 Poco::XML::Document *m_pDoc{nullptr};
89 Poco::XML::Element *m_pRootElem{nullptr};
90
92 std::map<int, std::vector<std::string>> m_groupComponentsMap;
93 std::map<int, std::vector<detid_t>> m_groupDetectorsMap;
94 std::map<int, std::vector<int>> m_groupSpectraMap;
95};
96
97class MANTID_DATAHANDLING_DLL LoadGroupXMLFile {
98public:
100
101 void loadXMLFile(const std::string &xmlfilename);
102 void setDefaultStartingGroupID(int startgroupid) { m_startGroupID = startgroupid; }
103
104 std::string getInstrumentName() { return m_instrumentName; }
105 bool isGivenInstrumentName() { return m_userGiveInstrument; }
106
107 std::string getDate() { return m_date; }
108 bool isGivenDate() { return m_userGiveDate; }
109
110 std::string getDescription() { return m_description; }
111 bool isGivenDescription() { return m_userGiveDescription; }
112
114 std::map<int, std::vector<std::string>> getGroupComponentsMap() { return m_groupComponentsMap; }
115 std::map<int, std::vector<detid_t>> getGroupDetectorsMap() { return m_groupDetectorsMap; }
116 std::map<int, std::vector<int>> getGroupSpectraMap() { return m_groupSpectraMap; }
117
118 std::map<int, std::string> getGroupNamesMap() { return m_groupNamesMap; }
119
120private:
122 std::string m_instrumentName;
125
127 std::string m_date;
130
132 std::string m_description;
135
137 Poco::AutoPtr<Poco::XML::Document> m_pDoc;
139 std::map<int, std::vector<std::string>> m_groupComponentsMap;
140 std::map<int, std::vector<detid_t>> m_groupDetectorsMap;
141 std::map<int, std::vector<int>> m_groupSpectraMap;
143
145 std::map<int, std::string> m_groupNamesMap;
146
148 void initializeXMLParser(const std::string &filename);
150 void parseXML();
152 static std::string getAttributeValueByName(Poco::XML::Node *pNode, const std::string &attributename, bool &found);
153};
154
161class MANTID_DATAHANDLING_DLL LoadGroupMapFile {
162public:
164 LoadGroupMapFile(const std::string &fileName, Kernel::Logger &log);
165
168
170 void parseFile();
171
175 std::map<int, std::vector<int>> getGroupSpectraMap() { return m_groupSpectraMap; }
176
177private:
180 bool nextDataLine(std::string &line);
181
183 const std::string m_fileName;
184
187
189 std::map<int, std::vector<int>> m_groupSpectraMap;
190
192 std::ifstream m_file;
193
196};
197
198} // namespace DataHandling
199} // namespace Mantid
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:85
std::map< int, std::vector< int > > m_groupSpectraMap
DataObjects::GroupingWorkspace_sptr m_groupWS
Grouping Workspace.
const std::string name() const override
function to return a name of the algorithm, must be overridden in all algorithms
std::map< int, std::vector< std::string > > m_groupComponentsMap
Data structures to store XML to Group/Detector conversion map.
std::map< int, std::vector< detid_t > > m_groupDetectorsMap
const std::string category() const override
Algorithm's category for identification.
void initializeXMLParser(const std::string &filename)
Initialize XML parser.
void parseRangeText(std::string inputstr, std::vector< int32_t > &singles, std::vector< int32_t > &pairs)
Split and convert string.
const std::vector< std::string > seeAlso() const override
Function to return all of the seeAlso (these are not validated) algorithms related to this algorithm....
int version() const override
Algorithm's version for identification.
const std::string summary() const override
Summary of algorithms purpose.
Geometry::Instrument_const_sptr m_instrument
Instrument to use if given by user.
static std::string getAttributeValueByName(Poco::XML::Node *pNode, std::string attributename, bool &found)
Get attribute value from an XML node.
void parseDetectorIDs(std::string inputstring, std::vector< detid_t > &detids)
Convert detector ID combination string to vector of detectors.
void parseSpectrumNos(std::string inputstring, std::vector< int > &specids)
Convert spectrum Nos combination string to vector of spectrum Nos.
Class used to load a grouping information from .map file.
std::map< int, std::vector< int > > m_groupSpectraMap
group_id -> [list of spectra]
const std::string m_fileName
The name of the file being parsed.
int m_lastLineRead
Number of the last line parsed.
std::ifstream m_file
The file being parsed.
std::map< int, std::vector< int > > getGroupSpectraMap()
Return the map parsed from file.
std::map< int, std::vector< std::string > > getGroupComponentsMap()
Data structures to store XML to Group/Detector conversion map.
std::string m_description
Grouping description. Empty if not specified.
std::map< int, std::vector< detid_t > > getGroupDetectorsMap()
std::string m_date
Date in ISO 8601 for which this grouping is relevant.
std::map< int, std::vector< std::string > > m_groupComponentsMap
Data structures to store XML to Group/Detector conversion map.
bool m_userGiveDescription
Whether description is given by user.
Poco::AutoPtr< Poco::XML::Document > m_pDoc
XML document loaded.
bool m_userGiveDate
Whether date is given by user.
std::map< int, std::string > getGroupNamesMap()
bool m_userGiveInstrument
User-define instrument name.
std::map< int, std::vector< int > > getGroupSpectraMap()
std::map< int, std::vector< detid_t > > m_groupDetectorsMap
std::map< int, std::string > m_groupNamesMap
Map of group names.
std::map< int, std::vector< int > > m_groupSpectraMap
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition: Logger.h:52
std::shared_ptr< GroupingWorkspace > GroupingWorkspace_sptr
shared pointer to the GroupingWorkspace class
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
Helper class which provides the Collimation Length for SANS instruments.
Definition: Algorithm.h:30