Mantid
Loading...
Searching...
No Matches
LoadDetectorsGroupingFile.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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#include <sstream>
8
11#include "MantidAPI/Run.h"
22
24
25#include <Poco/DOM/DOMParser.h>
26#include <Poco/DOM/Element.h>
27#include <Poco/DOM/NamedNodeMap.h>
28#include <Poco/DOM/NodeFilter.h>
29#include <Poco/DOM/NodeIterator.h>
30#include <Poco/DOM/NodeList.h>
31#include <Poco/Exception.h>
32#include <Poco/String.h>
33#include <filesystem>
34
35using namespace Mantid::Kernel;
36using namespace Mantid::API;
37
38namespace Mantid::DataHandling {
39
40namespace {
41namespace PropertyNames {
42const std::string INPUT_FILE("InputFile");
43const std::string INPUT_WKSP("InputWorkspace");
44const std::string OUTPUT_WKSP("OutputWorkspace");
45} // namespace PropertyNames
46} // namespace
47
49
52
53 const std::vector<std::string> exts{".xml", ".map"};
54 declareProperty(std::make_unique<FileProperty>(PropertyNames::INPUT_FILE, "", FileProperty::Load, exts),
55 "The XML or Map file with full path.");
56
57 declareProperty(
59 "Optional: An input workspace with the instrument we want to use. This "
60 "will override what is specified in the grouping file.");
61
64 "The output workspace containing the loaded grouping information.");
65}
66
69 std::filesystem::path inputFile(static_cast<std::string>(getProperty(PropertyNames::INPUT_FILE)));
70
71 std::string ext = Poco::toLower(inputFile.extension().string().substr(1)); // skip `.`
72
73 // The number of steps depends on the type of input file
74 // Set them to zero for the moment
75 Progress progress(this, 0.0, 1.0, 0);
76
77 if (ext == "xml") {
78 // Deal with file as xml
79
80 progress.setNumSteps(6);
81 progress.report("Parsing XML file");
82
83 // 1. Parse XML File
84 LoadGroupXMLFile loader;
85 loader.loadXMLFile(inputFile.string());
86
88 if (inputWS) {
89 // use the instrument from the input workspace
90 m_instrument = inputWS->getInstrument();
91 } else if (loader.isGivenInstrumentName()) {
92 // Load an instrument, if given
93 const std::string instrumentName = loader.getInstrumentName();
94
95 std::string date;
96
97 if (loader.isGivenDate())
98 date = loader.getDate();
99
100 // Get a relevant IDF for a given instrument name and date. If date is
101 // empty -
102 // the most recent will be used.
103 const std::string instrumentFilename = InstrumentFileFinder::getInstrumentFilename(instrumentName, date);
104
105 // Load an instrument
106 Algorithm_sptr childAlg = this->createChildAlgorithm("LoadInstrument");
108 childAlg->setProperty<MatrixWorkspace_sptr>("Workspace", tempWS);
109 childAlg->setPropertyValue("Filename", instrumentFilename);
110 childAlg->setProperty("RewriteSpectraMap", Mantid::Kernel::OptionalBool(false));
111 childAlg->executeAsChildAlg();
112 m_instrument = tempWS->getInstrument();
113 }
114
115 progress.report("Checking detector IDs");
116
117 // 2. Check if detector IDs are given
118 if (!m_instrument && std::any_of(m_groupDetectorsMap.cbegin(), m_groupDetectorsMap.cend(),
119 [](const auto &pair) { return !pair.second.empty(); })) {
120 throw std::invalid_argument("Grouping file specifies detector ID without instrument name");
121 }
122
126
127 progress.report("Creating output workspace");
128
129 // 3. Create output workspace
131 m_groupWS->mutableRun().addProperty("Filename", inputFile.string());
132 setProperty("OutputWorkspace", m_groupWS);
133
134 progress.report("Setting geometry");
135
136 // 4. Translate and set geometry
137 this->setByComponents();
138 this->setByDetectors();
139 this->setBySpectrumNos();
140
141 progress.report("Checking grouping description");
142
143 // 5. Add grouping description, if specified
144 if (loader.isGivenDescription()) {
145 std::string description = loader.getDescription();
146 m_groupWS->mutableRun().addProperty("Description", description);
147 }
148
149 progress.report("Checking group names");
150
151 // 6. Add group names, if user has specified any
152 std::map<int, std::string> groupNamesMap = loader.getGroupNamesMap();
153
154 for (auto &group : groupNamesMap) {
155 std::string groupIdStr = std::to_string(group.first);
156 m_groupWS->mutableRun().addProperty("GroupName_" + groupIdStr, group.second);
157 }
158 } else if (ext == "map") {
159 // Deal with file as map
160
161 progress.setNumSteps(3);
162 progress.report("Parsing map file");
163
164 // Load data from file
165 LoadGroupMapFile loader(inputFile.string(), g_log);
166 loader.parseFile();
167
168 progress.report("Setting spectra map");
169
170 // In .map files we are dealing with spectra numbers only.
172
173 progress.report("Creating output workspace");
174
175 // There is no way to specify instrument name in .map file
177
178 m_groupWS->mutableRun().addProperty("Filename", inputFile.string());
179 setProperty("OutputWorkspace", m_groupWS);
180
181 this->setBySpectrumNos();
182 } else {
183 // Unknown file type
184 throw std::invalid_argument("File type is not supported: " + ext);
185 }
186}
187
188/*
189 * Convert Componenet -> Detector IDs -> Workspace Indices -> set group ID
190 */
192
193 // 0. Check
194 if (!m_instrument) {
195 const auto it = std::find_if(m_groupComponentsMap.cbegin(), m_groupComponentsMap.cend(),
196 [](const auto &pair) { return !pair.second.empty(); });
197 if (it != m_groupComponentsMap.cend()) {
198 g_log.error() << "Instrument is not specified in XML file. "
199 << "But tag 'component' is used in XML file for Group " << it->first << " It is not allowed"
200 << std::endl;
201 throw std::invalid_argument("XML definition involving component causes error");
202 }
203 }
204
205 // 1. Prepare
206 const detid2index_map indexmap = m_groupWS->getDetectorIDToWorkspaceIndexMap(true);
207 const auto &componentInfo = m_groupWS->componentInfo();
208 const auto &detectorInfo = m_groupWS->detectorInfo();
209
210 // 2. Set
211 for (auto &componentMap : m_groupComponentsMap) {
212 g_log.debug() << "Group ID = " << componentMap.first << " With " << componentMap.second.size() << " Components\n";
213
214 for (auto &componentName : componentMap.second) {
215
216 // a) get component by name and find its index
217 const size_t componentIndex = componentInfo.indexOfAny(componentName);
218
219 // b) get all detectors in the subtree of this component
220 const auto detectorIndices = componentInfo.detectorsInSubtree(componentIndex);
221
222 g_log.debug() << "Component Name = " << componentName << " Component index = " << componentIndex
223 << " Number of Children = " << detectorIndices.size() << '\n';
224
225 for (const auto &detIndex : detectorIndices) {
226 // c) get detector ID
227 const auto detid = detectorInfo.detid(detIndex);
228 auto itx = indexmap.find(detid);
229 if (itx != indexmap.end()) {
230 size_t wsindex = itx->second;
231 m_groupWS->mutableY(wsindex)[0] = componentMap.first;
232 } else {
233 g_log.error() << "Pixel w/ ID = " << detid << " Cannot Be Located\n";
234 }
235
236 } // ENDFOR (children of component)
237 } // ENDFOR (component)
238
239 } // ENDFOR GroupID
240}
241
242/* Set workspace->group ID map by detectors (range)
243 *
244 */
246
247 // 0. Check
248 if (!m_instrument && !m_groupDetectorsMap.empty()) {
249 const auto it = std::find_if(m_groupDetectorsMap.cbegin(), m_groupDetectorsMap.cend(),
250 [](const auto &pair) { return !pair.second.empty(); });
251 if (it != m_groupDetectorsMap.cend()) {
252 g_log.error() << "Instrument is not specified in XML file. "
253 << "But tag 'detid' is used in XML file for Group " << it->first << " It is not allowed"
254 << std::endl;
255 throw std::invalid_argument("XML definition involving component causes error");
256 }
257 }
258
259 // 1. Prepare
260 const detid2index_map indexmap = m_groupWS->getDetectorIDToWorkspaceIndexMap(true);
261
262 // 2. Set GroupingWorkspace
263 for (const auto &detectorMap : m_groupDetectorsMap) {
264 g_log.debug() << "Group ID = " << detectorMap.first << '\n';
265
266 for (auto detid : detectorMap.second) {
267 auto itx = indexmap.find(detid);
268
269 if (itx != indexmap.end()) {
270 size_t wsindex = itx->second;
271 m_groupWS->mutableY(wsindex)[0] = detectorMap.first;
272 } else {
273 g_log.error() << "Pixel w/ ID = " << detid << " Cannot Be Located\n";
274 }
275 } // ENDFOR detid (in range)
276 } // ENDFOR each group ID
277}
278
279/*
280 * Set workspace index/group id by spectrum Nos
281 */
283 // 1. Get map
284 const spec2index_map s2imap = m_groupWS->getSpectrumToWorkspaceIndexMap();
285 spec2index_map::const_iterator s2iter;
286
287 // 2. Locate in loop
288 // std::map<int, std::vector<int> > m_groupSpectraMap;
289 std::map<int, std::vector<int>>::iterator gsiter;
290 for (gsiter = m_groupSpectraMap.begin(); gsiter != m_groupSpectraMap.end(); ++gsiter) {
291 int groupid = gsiter->first;
292 for (auto specNo : gsiter->second) {
293 s2iter = s2imap.find(specNo);
294 if (s2iter == s2imap.end()) {
295 g_log.error() << "Spectrum " << specNo << " does not have an entry in GroupWorkspace's spec2index map\n";
296 throw std::runtime_error("Logic error");
297 } else {
298 size_t wsindex = s2iter->second;
299 if (wsindex >= m_groupWS->getNumberHistograms()) {
300 g_log.error() << "Group workspace's spec2index map is set wrong: "
301 << " Found workspace index = " << wsindex << " for spectrum No " << specNo
302 << " with workspace size = " << m_groupWS->getNumberHistograms() << '\n';
303 } else {
304 // Finally set the group workspace
305 m_groupWS->mutableY(wsindex)[0] = groupid;
306 } // IF-ELSE: ws index out of range
307 } // IF-ELSE: spectrum No has an entry
308 } // FOR: each spectrum No
309 } // FOR: each group ID
310}
311
312/* Initialize a GroupingWorkspace
313 *
314 */
316
317 if (m_instrument) {
318 // Create GroupingWorkspace with instrument
320 } else {
321 // 1b. Create GroupingWorkspace w/o instrument
323 }
324}
325
326/*
327 * Generate a GroupingWorkspace without instrument information
328 */
330 // 1. Generate a map
331 std::map<int, int> spectrumidgroupmap;
332 std::map<int, std::vector<int>>::iterator groupspeciter;
333 std::vector<int> specids;
334 for (groupspeciter = m_groupSpectraMap.begin(); groupspeciter != m_groupSpectraMap.end(); ++groupspeciter) {
335 int groupid = groupspeciter->first;
336 for (auto specid : groupspeciter->second) {
337 spectrumidgroupmap.emplace(specid, groupid);
338 specids.emplace_back(specid);
339 }
340 }
341
342 std::sort(specids.begin(), specids.end());
343
344 if (specids.size() != spectrumidgroupmap.size()) {
345 g_log.warning() << "Duplicate spectrum No is defined in input XML file!\n";
346 }
347
348 // 2. Initialize group workspace and set the spectrum workspace map
349 size_t numvectors = spectrumidgroupmap.size();
351
352 for (size_t i = 0; i < m_groupWS->getNumberHistograms(); i++) {
353 m_groupWS->getSpectrum(i).setSpectrumNo(specids[i]);
354 }
355}
356
357/*
358 * Initialization
359 */
361 : m_instrumentName(""), m_userGiveInstrument(false), m_date(""), m_userGiveDate(false), m_description(""),
362 m_userGiveDescription(false), m_pDoc(), m_groupComponentsMap(), m_groupDetectorsMap(), m_groupSpectraMap(),
363 m_startGroupID(1), m_groupNamesMap() {}
364
365void LoadGroupXMLFile::loadXMLFile(const std::string &xmlfilename) {
366
367 this->initializeXMLParser(xmlfilename);
368 this->parseXML();
369}
370
371/*
372 * Initalize Poco XML Parser
373 */
374void LoadGroupXMLFile::initializeXMLParser(const std::string &filename) {
375 const std::string xmlText = Kernel::Strings::loadFile(filename);
376
377 // Set up the DOM parser and parse xml file
378 Poco::XML::DOMParser pParser;
379 try {
380 m_pDoc = pParser.parseString(xmlText);
381 } catch (Poco::Exception &exc) {
382 throw Kernel::Exception::FileError(exc.displayText() + ". Unable to parse File:", filename);
383 } catch (...) {
384 throw Kernel::Exception::FileError("Unable to parse File:", filename);
385 }
386 if (!m_pDoc->documentElement()->hasChildNodes()) {
387 throw Kernel::Exception::InstrumentDefinitionError("No root element in XML instrument file", filename);
388 }
389}
390
391/*
392 * Parse XML file
393 */
395 // 0. Check
396 if (!m_pDoc)
397 throw std::runtime_error("Call LoadDetectorsGroupingFile::initialize() before parseXML.");
398
399 // 1. Parse and create a structure
400 Poco::XML::NodeIterator it(m_pDoc, Poco::XML::NodeFilter::SHOW_ELEMENT);
401 Poco::XML::Node *pNode = it.nextNode();
402
403 int curgroupid = m_startGroupID - 1;
404 bool isfirstgroup = true;
405
406 // Add flag to figure out it is automatic group ID or user-defined group ID
407 bool autogroupid = true;
408
409 // While loop to go over all nodes!
410 while (pNode) {
411
412 const Poco::XML::XMLString value = pNode->innerText();
413
414 if (pNode->nodeName() == "detector-grouping") {
415 // Node "detector-grouping" (first level)
416
417 // Optional instrument name
419
420 // Optional date for which is relevant
421 m_date = getAttributeValueByName(pNode, "idf-date", m_userGiveDate);
422
423 // Optional grouping description
425
426 } // "detector-grouping"
427 else if (pNode->nodeName() == "group") {
428 // Group Node: get ID, set map
429 // a) Find group ID
430 bool foundid;
431 std::string idstr = getAttributeValueByName(pNode, "ID", foundid);
432
433 if (isfirstgroup && foundid)
434 autogroupid = false;
435 else if (!isfirstgroup && !autogroupid && foundid)
436 autogroupid = false;
437 else
438 autogroupid = true;
439
440 isfirstgroup = false;
441
442 if (autogroupid) {
443 curgroupid++;
444 } else {
445 curgroupid = std::stoi(idstr);
446 }
447
448 // b) Set in map
449 auto itc = m_groupComponentsMap.find(curgroupid);
450 if (itc != m_groupComponentsMap.end()) {
451 // Error! Duplicate Group ID defined in XML
452 std::stringstream ss;
453 ss << "Map (group ID, components) has group ID " << curgroupid << " already. Duplicate Group ID error!\n";
454 throw std::invalid_argument(ss.str());
455 } else {
456 // When group ID is sorted, check if user has specified a group name
457 bool foundName;
458 std::string name = getAttributeValueByName(pNode, "name", foundName);
459 if (foundName)
460 m_groupNamesMap[curgroupid] = name;
461
462 // Set map
463 std::vector<std::string> tempcomponents;
464 std::vector<detid_t> tempdetids;
465 std::vector<int> tempspectrumids;
466 m_groupComponentsMap[curgroupid] = tempcomponents;
467 m_groupDetectorsMap[curgroupid] = tempdetids;
468 m_groupSpectraMap[curgroupid] = tempspectrumids;
469 }
470 } // "group"
471 else if (pNode->nodeName() == "component") {
472 // Node "component" = value
473 auto groupIt = m_groupComponentsMap.find(curgroupid);
474 if (groupIt == m_groupComponentsMap.end()) {
475 std::stringstream ss;
476 ss << "XML File (component) heirachial error!"
477 << " Inner Text = " << pNode->innerText() << '\n';
478 throw std::invalid_argument(ss.str());
479 } else {
480 bool valfound;
481 std::string val_value = this->getAttributeValueByName(pNode, "val", valfound);
482 std::string finalvalue;
483 if (valfound && !value.empty())
484 finalvalue.append(value).append(", ").append(val_value);
485 else if (value.empty())
486 finalvalue = val_value;
487 else
488 finalvalue = value;
489 groupIt->second.emplace_back(finalvalue);
490 }
491
492 } // Component
493 else if (pNode->nodeName() == "detids") {
494 // Node "detids"
495 auto groupIt = m_groupDetectorsMap.find(curgroupid);
496 if (groupIt == m_groupDetectorsMap.end()) {
497 std::stringstream ss;
498 ss << "XML File (detids) hierarchal error!"
499 << " Inner Text = " << pNode->innerText() << '\n';
500 throw std::invalid_argument(ss.str());
501 } else {
502 bool valfound;
503 std::string val_value = this->getAttributeValueByName(pNode, "val", valfound);
504 std::string finalvalue;
505 if (valfound && !value.empty())
506 finalvalue.append(value).append(", ").append(val_value);
507 else if (value.empty())
508 finalvalue = val_value;
509 else
510 finalvalue = value;
511
512 std::vector<int> parsedRange = Strings::parseRange(finalvalue);
513 groupIt->second.insert(groupIt->second.end(), parsedRange.begin(), parsedRange.end());
514 }
515 } // "detids"
516 else if (pNode->nodeName() == "ids") {
517 // Node ids: for spectrum number
518 auto groupIt = m_groupSpectraMap.find(curgroupid);
519 if (groupIt == m_groupSpectraMap.end()) {
520 std::stringstream ss;
521 ss << "XML File (ids) hierarchal error! "
522 << " Inner Text = " << pNode->innerText() << '\n';
523 throw std::invalid_argument(ss.str());
524 } else {
525 bool valfound;
526 std::string val_value = this->getAttributeValueByName(pNode, "val", valfound);
527 std::string finalvalue;
528 if (valfound && !value.empty())
529 finalvalue.append(value).append(", ").append(val_value);
530 else if (value.empty())
531 finalvalue = val_value;
532 else
533 finalvalue = value;
534
535 std::vector<int> parsedRange = Strings::parseRange(finalvalue);
536 groupIt->second.insert(groupIt->second.end(), parsedRange.begin(), parsedRange.end());
537 }
538 }
539
540 // Next Node!
541 pNode = it.nextNode();
542
543 } // ENDWHILE
544}
545
546/*
547 * Get attribute's value by name from a Node
548 */
549std::string LoadGroupXMLFile::getAttributeValueByName(Poco::XML::Node *pNode, const std::string &attributename,
550 bool &found) {
551 // 1. Init
552 Poco::AutoPtr<Poco::XML::NamedNodeMap> att = pNode->attributes();
553 found = false;
554 std::string value;
555
556 // 2. Loop to find
557 for (unsigned long i = 0; i < att->length(); ++i) {
558 Poco::XML::Node *cNode = att->item(i);
559 if (cNode->localName() == attributename) {
560 value = cNode->getNodeValue();
561 found = true;
562 break;
563 }
564 } // ENDFOR
565
566 return value;
567}
568
569// -----------------------------------------------------------------------------------------------
570
576LoadGroupMapFile::LoadGroupMapFile(const std::string &fileName, Kernel::Logger &log)
577 : m_fileName(fileName), m_log(log), m_lastLineRead(0) {
578 m_file.open(m_fileName.c_str(), std::ifstream::in);
579
580 if (!m_file)
581 throw Exception::FileError("Couldn't open file for reading", fileName);
582}
583
588 // Close the file, if terminate was not called
589 if (m_file.is_open())
590 m_file.close();
591}
592
597 try {
598 // We don't use the total number of groups report at the top of the file but
599 // we'll tell them
600 // later if there is a problem with it for their diagnostic purposes
601 size_t givenNoOfGroups;
602 std::string line;
603
604 if (!nextDataLine(line))
605 throw std::invalid_argument("The input file doesn't appear to contain any data");
606
607 if (Kernel::Strings::convert(line, givenNoOfGroups) != 1)
608 throw std::invalid_argument("Expected a single int for the number of groups");
609
610 // Parse groups
611 int currentGroupNo = 1;
612 while (true) {
613 // Read next line ("group spectrum no.") -> ignore the number itself
614 if (!nextDataLine(line))
615 // If file ended -> no more groups to read, so exit the loop silently
616 break;
617
618 // Try to read number of spectra
619 size_t noOfGroupSpectra;
620
621 if (!nextDataLine(line))
622 throw std::invalid_argument("Premature end of file, expecting the number of group spectra");
623
624 if (Kernel::Strings::convert(line, noOfGroupSpectra) != 1)
625 throw std::invalid_argument("Expected a single int for the number of group spectra");
626
627 std::vector<int> &groupSpectra = m_groupSpectraMap[currentGroupNo];
628
629 groupSpectra.reserve(noOfGroupSpectra);
630
631 // While have not read all the group spectra
632 while (groupSpectra.size() < noOfGroupSpectra) {
633 if (!nextDataLine(line))
634 throw std::invalid_argument("Premature end of file, expecting spectra list");
635
636 // Parse line with range. Exceptions will be catched as all others.
637 std::vector<int> readSpectra = Kernel::Strings::parseRange(line, " ");
638
639 groupSpectra.insert(groupSpectra.end(), readSpectra.begin(), readSpectra.end());
640 }
641
642 if (groupSpectra.size() != noOfGroupSpectra)
643 throw std::invalid_argument("Bad number of spectra list");
644
645 currentGroupNo++;
646 }
647
648 if (m_groupSpectraMap.size() != givenNoOfGroups) {
649 m_log.warning() << "The input file header states there are " << givenNoOfGroups << ", but the file contains "
650 << m_groupSpectraMap.size() << " groups\n";
651 }
652 } catch (std::invalid_argument &e) {
654 }
655}
656
663bool LoadGroupMapFile::nextDataLine(std::string &line) {
664 while (m_file) {
665 std::getline(m_file, line);
667
668 if (!m_file)
669 return false;
670
671 line = Poco::trim(line);
672
673 if (!line.empty() && line[0] != '#')
674 return true;
675 }
676
677 return false;
678}
679
680} // namespace Mantid::DataHandling
std::string name
Definition Run.cpp:60
#define DECLARE_ALGORITHM(classname)
Definition Algorithm.h:547
double value
The value of the point.
Definition FitMW.cpp:51
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
Kernel::Logger & g_log
Definition Algorithm.h:426
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
@ Load
allowed here which will be passed to the algorithm
static std::string getInstrumentFilename(const std::string &instrumentName, const std::string &date="")
Get the IDF using the instrument name and date.
Helper class for reporting progress from algorithms.
Definition Progress.h:25
A property class for workspaces.
std::map< int, std::vector< int > > m_groupSpectraMap
DataObjects::GroupingWorkspace_sptr m_groupWS
Grouping Workspace.
void intializeGroupingWorkspace()
Initialize a Mask Workspace.
void setBySpectrumNos()
Set workspace index/group ID by spectrum Number.
void setByComponents()
Set workspace->group ID map by components.
std::map< int, std::vector< std::string > > m_groupComponentsMap
Data structures to store XML to Group/Detector conversion map.
void generateNoInstrumentGroupWorkspace()
Generate a GroupingWorkspace w/o instrument.
std::map< int, std::vector< detid_t > > m_groupDetectorsMap
void setByDetectors()
Set workspace->group ID map by detectors (range)
Geometry::Instrument_const_sptr m_instrument
Instrument to use if given by user.
Class used to load a grouping information from .map file.
void parseFile()
Parses grouping information from .map file.
const std::map< int, std::vector< int > > & getGroupSpectraMap() const
Return the map parsed from file.
LoadGroupMapFile(const std::string &fileName, Kernel::Logger &log)
Constructor. Opens a 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.
bool nextDataLine(std::string &line)
Skips all the empty lines and comment lines, and returns next line with real data.
std::string m_description
Grouping description. Empty if not specified.
void loadXMLFile(const std::string &xmlfilename)
std::string m_date
Date in ISO 8601 for which this grouping is relevant.
const std::map< int, std::vector< detid_t > > & getGroupDetectorsMap() const
static std::string getAttributeValueByName(Poco::XML::Node *pNode, const std::string &attributename, bool &found)
Get attribute value from an XML node.
std::map< int, std::vector< std::string > > m_groupComponentsMap
Data structures to store XML to Group/Detector conversion map.
const std::map< int, std::vector< int > > & getGroupSpectraMap() const
bool m_userGiveDescription
Whether description is given by user.
const std::map< int, std::string > & getGroupNamesMap() const
Poco::AutoPtr< Poco::XML::Document > m_pDoc
XML document loaded.
const std::map< int, std::vector< std::string > > & getGroupComponentsMap() const
Data structures to store XML to Group/Detector conversion map.
bool m_userGiveDate
Whether date is given by user.
bool m_userGiveInstrument
User-define instrument name.
std::map< int, std::vector< detid_t > > m_groupDetectorsMap
std::map< int, std::string > m_groupNamesMap
Map of group names.
void initializeXMLParser(const std::string &filename)
Initialize XML parser.
std::map< int, std::vector< int > > m_groupSpectraMap
A GroupingWorkspace is a subclass of Workspace2D where each spectrum has a single number entry,...
Concrete workspace implementation.
Definition Workspace2D.h:30
Records the filename and the description of failure.
Definition Exception.h:98
Exception for errors associated with the instrument definition.
Definition Exception.h:220
Records the filename, the description of failure and the line on which it happened.
Definition Exception.h:115
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition Logger.h:51
void debug(const std::string &msg)
Logs at debug level.
Definition Logger.cpp:145
void error(const std::string &msg)
Logs at error level.
Definition Logger.cpp:108
void warning(const std::string &msg)
Logs at warning level.
Definition Logger.cpp:117
OptionalBool : Tri-state bool.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
std::shared_ptr< Algorithm > Algorithm_sptr
Typedef for a shared pointer to an Algorithm.
Definition Algorithm.h:52
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< GroupingWorkspace > GroupingWorkspace_sptr
shared pointer to the GroupingWorkspace class
MANTID_KERNEL_DLL std::vector< int > parseRange(const std::string &str, const std::string &elemSep=",", const std::string &rangeSep="-")
Parses a number range, e.g.
Definition Strings.cpp:1097
MANTID_KERNEL_DLL std::string loadFile(const std::string &filename)
Loads the entire contents of a text file into a string.
Definition Strings.cpp:27
int convert(const std::string &A, T &out)
Convert a string into a number.
Definition Strings.cpp:697
const std::string OUTPUT_WKSP("OutputWorkspace")
const std::string INPUT_WKSP("InputWorkspace")
std::unordered_map< specnum_t, size_t > spec2index_map
Map with key = spectrum number, value = workspace index.
std::unordered_map< detid_t, size_t > detid2index_map
Map with key = detector ID, value = workspace index.
std::string to_string(const wide_integer< Bits, Signed > &n)
@ Input
An input workspace.
Definition Property.h:54
@ Output
An output workspace.
Definition Property.h:55