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