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