Mantid
Loading...
Searching...
No Matches
CreateGroupingWorkspace.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 +
16#include "MantidKernel/System.h"
17#include <boost/algorithm/string/detail/classification.hpp>
18#include <boost/algorithm/string/split.hpp>
19#include <boost/algorithm/string/trim.hpp>
20#include <fstream>
21#include <queue>
22#include <utility>
23
24using namespace Mantid;
25using namespace Mantid::API;
26using namespace Mantid::Geometry;
27
28namespace {
29Mantid::Kernel::Logger g_log("CreateGroupingWorkspace");
30
31void removeSpacesFromString(std::string &str) { str.erase(std::remove_if(str.begin(), str.end(), isspace), str.end()); }
32
38void extendVectorBy(std::vector<std::string> &vec, const std::vector<std::string> &extension) {
39 vec.reserve(vec.size() + std::distance(extension.cbegin(), extension.cend()));
40 vec.insert(vec.end(), extension.cbegin(), extension.cend());
41}
42
50std::vector<std::string> splitStringBy(const std::string &str, const std::string &delimiter) {
51 std::vector<std::string> subStrings;
52 boost::split(subStrings, str, boost::is_any_of(delimiter));
53 subStrings.erase(std::remove_if(subStrings.begin(), subStrings.end(),
54 [](const std::string &subString) { return subString.empty(); }),
55 subStrings.cend());
56 return subStrings;
57}
58
65bool hasSeparator(const std::string &str, const std::string &separator) {
66 return str.find(separator) != std::string::npos;
67}
68
76std::vector<std::string> getDetectorRangeFromLimits(int lower, int upper) {
77 std::vector<std::string> detectorIds;
78 detectorIds.reserve(static_cast<std::size_t>(upper - lower + 1));
79 for (auto i = lower; i <= upper; ++i)
80 detectorIds.emplace_back(std::to_string(i));
81 return detectorIds;
82}
83
90std::vector<std::string> groupsFromColonRange(const std::string &groupString) {
91 const auto splitByColon = splitStringBy(groupString, ":");
92 if (splitByColon.size() > 2)
93 throw std::runtime_error("Expected a single colon separator.");
94
95 if (splitByColon.size() == 2)
96 return getDetectorRangeFromLimits(std::stoi(splitByColon[0]), std::stoi(splitByColon[1]));
97 return splitByColon;
98}
99
107std::vector<std::string> expandGroupsWithColonSeparator(const std::vector<std::string> &groupsToExpand) {
108 std::vector<std::string> expandedGroupStrings;
109 for (const auto &groupString : groupsToExpand)
110 extendVectorBy(expandedGroupStrings, groupsFromColonRange(groupString));
111 return expandedGroupStrings;
112}
113
123void addDetectorToGroup(const std::vector<detid_t> &allowedDetectorIDs, std::map<detid_t, int> &detectorIDToGroup,
124 int detectorID, int groupID) {
125 const auto iter = std::find(allowedDetectorIDs.cbegin(), allowedDetectorIDs.cend(), detectorID);
126 if (iter == allowedDetectorIDs.cend())
127 throw std::runtime_error("The Detector ID '" + std::to_string(detectorID) +
128 "' is not valid for this instrument component.");
129
130 detectorIDToGroup[detectorID] = groupID;
131}
132
143void addDashSeparatedDetectorIDsToSameGroup(const std::vector<detid_t> &allowedDetectorIDs,
144 std::map<detid_t, int> &detectorIDToGroup, const std::string &groupString,
145 int groupID) {
146 const auto splitByDash = splitStringBy(groupString, "-");
147
148 if (splitByDash.size() < 2)
149 throw std::runtime_error("Expected at least one dash separator.");
150 else if (splitByDash.size() > 2)
151 throw std::runtime_error("Expected a single dash separator.");
152
153 for (auto i = std::stoi(splitByDash[0]); i <= std::stoi(splitByDash[1]); ++i)
154 addDetectorToGroup(allowedDetectorIDs, detectorIDToGroup, i, groupID);
155}
156
167void addPlusSeparatedDetectorIDsToSameGroup(const std::vector<detid_t> &allowedDetectorIDs,
168 std::map<detid_t, int> &detectorIDToGroup, const std::string &groupString,
169 int groupID) {
170 const auto splitByPlus = splitStringBy(groupString, "+");
171 if (splitByPlus.size() < 2)
172 throw std::runtime_error("Expected at least one plus separator.");
173
174 for (const auto &id : splitByPlus)
175 addDetectorToGroup(allowedDetectorIDs, detectorIDToGroup, std::stoi(id), groupID);
176}
177
184std::vector<detid_t> getAllowedDetectorIDs(const Instrument_const_sptr &instrument, const std::string &componentName) {
185 std::vector<IDetector_const_sptr> detectors;
186 detectors.reserve(instrument->getNumberDetectors());
187 instrument->getDetectorsInBank(detectors, componentName);
188
189 std::vector<detid_t> detectorIDs;
190 detectorIDs.reserve(detectors.size());
191 std::transform(detectors.cbegin(), detectors.cend(), std::back_inserter(detectorIDs),
192 [](const IDetector_const_sptr &detector) { return detector->getID(); });
193 return detectorIDs;
194}
195
205std::map<detid_t, int> mapGroupingStringsToGroupIDs(const std::vector<detid_t> &allowedDetectorIDs,
206 const std::vector<std::string> &groupingStrings) {
207 std::map<detid_t, int> detectorIDToGroup;
208 for (auto j = 0; j < static_cast<int>(groupingStrings.size()); ++j) {
209 if (hasSeparator(groupingStrings[j], "+"))
210 addPlusSeparatedDetectorIDsToSameGroup(allowedDetectorIDs, detectorIDToGroup, groupingStrings[j], j + 1);
211 else if (hasSeparator(groupingStrings[j], "-"))
212 addDashSeparatedDetectorIDsToSameGroup(allowedDetectorIDs, detectorIDToGroup, groupingStrings[j], j + 1);
213 else
214 addDetectorToGroup(allowedDetectorIDs, detectorIDToGroup, std::stoi(groupingStrings[j]), j + 1);
215 }
216 return detectorIDToGroup;
217}
218
227std::map<detid_t, int> makeGroupingByCustomString(const Instrument_const_sptr &instrument,
228 const std::string &componentName, std::string &customGroupingString) {
229 removeSpacesFromString(customGroupingString);
230
231 const auto detectorIDs = getAllowedDetectorIDs(instrument, componentName);
232 const auto groupStrings = expandGroupsWithColonSeparator(splitStringBy(customGroupingString, ","));
233
234 return mapGroupingStringsToGroupIDs(detectorIDs, groupStrings);
235}
236
237} // namespace
238
239namespace Mantid::Algorithms {
240
241// Register the algorithm into the AlgorithmFactory
242DECLARE_ALGORITHM(CreateGroupingWorkspace)
243
244using namespace Mantid::Kernel;
245using namespace Mantid::API;
246using namespace Mantid::Geometry;
247using namespace Mantid::DataObjects;
248
249const std::string CreateGroupingWorkspace::name() const { return "CreateGroupingWorkspace"; }
250
251int CreateGroupingWorkspace::version() const { return 1; }
252
253const std::string CreateGroupingWorkspace::category() const { return "Utility\\Workspaces;Transforms\\Grouping"; }
254
255//----------------------------------------------------------------------------------------------
256
257//----------------------------------------------------------------------------------------------
261 declareProperty(std::make_unique<WorkspaceProperty<>>("InputWorkspace", "", Direction::Input, PropertyMode::Optional),
262 "Optional: An input workspace with the instrument we want to use.");
263
264 declareProperty(std::make_unique<PropertyWithValue<std::string>>("InstrumentName", "", Direction::Input),
265 "Optional: Name of the instrument to base the "
266 "GroupingWorkspace on which to base the GroupingWorkspace.");
267
268 declareProperty(std::make_unique<FileProperty>("InstrumentFilename", "", FileProperty::OptionalLoad, ".xml"),
269 "Optional: Path to the instrument definition file on which "
270 "to base the GroupingWorkspace.");
271
272 declareProperty(std::make_unique<FileProperty>("OldCalFilename", "", FileProperty::OptionalLoad, ".cal"),
273 "Optional: Path to the old-style .cal grouping/calibration "
274 "file (multi-column ASCII). You must also specify the "
275 "instrument.");
276
277 declareProperty("GroupNames", "",
278 "Optional: A string of the instrument component names to use "
279 "as separate groups. "
280 "Use / or , to separate multiple groups. "
281 "If empty, then an empty GroupingWorkspace will be created.");
282
283 std::vector<std::string> grouping{"", "All", "Group", "2_4Grouping", "Column", "bank"};
284 declareProperty("GroupDetectorsBy", "", std::make_shared<StringListValidator>(grouping),
285 "Only used if GroupNames is empty");
286 declareProperty("MaxRecursionDepth", 5, "Number of levels to search into the instrument (default=5)");
287
288 declareProperty("FixedGroupCount", 0, std::make_shared<BoundedValidator<int>>(0, INT_MAX),
289 "Used to distribute the detectors of a given component into "
290 "a fixed number of groups");
291 declareProperty("CustomGroupingString", "",
292 "This takes a comma separated list of grouped detector IDs. An example "
293 "of the syntax is 1,2+3,4-6,7:10. The documentation page for this "
294 "algorithm gives a full explanation of this syntax.");
295 declareProperty("ComponentName", "",
296 "Specify the instrument component to "
297 "group into a fixed number of groups");
298
299 declareProperty(std::make_unique<WorkspaceProperty<GroupingWorkspace>>("OutputWorkspace", "", Direction::Output),
300 "An output GroupingWorkspace.");
301
302 std::string inputs("Specify Instrument");
303 setPropertyGroup("InputWorkspace", inputs);
304 setPropertyGroup("InstrumentName", inputs);
305 setPropertyGroup("InstrumentFilename", inputs);
306
307 std::string groupby("Specify Grouping");
308 setPropertyGroup("GroupNames", groupby);
309 setPropertyGroup("GroupDetectorsBy", groupby);
310 setPropertyGroup("MaxRecursionDepth", groupby);
311 setPropertyGroup("FixedGroupCount", groupby);
312 setPropertyGroup("ComponentName", groupby);
313 setPropertyGroup("CustomGroupingString", groupby);
314
315 // output properties
316 declareProperty("NumberGroupedSpectraResult", EMPTY_INT(), "The number of spectra in groups", Direction::Output);
317 declareProperty("NumberGroupsResult", EMPTY_INT(), "The number of groups", Direction::Output);
318}
319
320std::map<std::string, std::string> CreateGroupingWorkspace::validateInputs() {
321 std::map<std::string, std::string> result;
322
323 // only allow specifying the instrument in one way
324 int numInstrument = 0;
325 if (!isDefault("InputWorkspace"))
326 numInstrument += 1;
327 if (!isDefault("InstrumentName"))
328 numInstrument += 1;
329 if (!isDefault("InstrumentFilename"))
330 numInstrument += 1;
331 if (numInstrument == 0) {
332 std::string msg("Must supply an instrument");
333 result["InputWorkspace"] = msg;
334 result["InstrumentName"] = msg;
335 result["InstrumentFilename"] = msg;
336 } else if (numInstrument > 1) {
337 std::string msg("Must supply an instrument only one way");
338
339 if (!isDefault("InputWorkspace"))
340 result["InputWorkspace"] = msg;
341 if (!isDefault("InstrumentName"))
342 result["InstrumentName"] = msg;
343 if (!isDefault("InstrumentFilename"))
344 result["InstrumentFilename"] = msg;
345 }
346
347 // only allow specifying the grouping one way
348 int numGroupings = 0;
349 if (!isDefault("GroupNames"))
350 numGroupings += 1;
351 if (!isDefault("GroupDetectorsBy"))
352 numGroupings += 1;
353 if (!isDefault("ComponentName"))
354 numGroupings += 1;
355 if (numGroupings != 1) {
356 std::string msg("Must supply grouping only one way");
357 if (!isDefault("GroupNames"))
358 result["GroupNames"] = msg;
359 if (!isDefault("GroupDetectorsBy"))
360 result["GroupDetectorsBy"] = msg;
361 if (!isDefault("ComponentName"))
362 result["ComponentName"] = msg;
363 }
364
365 std::string customGroupingString = getPropertyValue("CustomGroupingString");
366 std::string componentName = getPropertyValue("ComponentName");
367
368 if (!componentName.empty() && !customGroupingString.empty()) {
369 try {
370 (void)makeGroupingByCustomString(getInstrument(), componentName, customGroupingString);
371 } catch (const std::runtime_error &ex) {
372 result["CustomGroupingString"] = ex.what();
373 }
374 }
375
376 return result;
377}
378
379//------------------------------------------------------------------------------------------------
386std::map<detid_t, int> readGroupingFile(const std::string &groupingFileName, Progress &prog) {
387 std::ifstream grFile(groupingFileName.c_str());
388 if (!grFile.is_open()) {
389 throw Exception::FileError("Error reading .cal file", groupingFileName);
390 }
391 std::map<detid_t, int> detIDtoGroup;
392 std::string str;
393 while (getline(grFile, str)) {
394 // Comment
395 if (str.empty() || str[0] == '#')
396 continue;
397 std::istringstream istr(str);
398 int n, udet, sel, group;
399 double offset;
400 istr >> n >> udet >> offset >> sel >> group;
401 if ((sel) && (group > 0)) {
402 detIDtoGroup[udet] = group; // Register this detector id
403 }
404 prog.report();
405 }
406 grFile.close();
407 return detIDtoGroup;
408}
409
419std::map<detid_t, int> makeGroupingByNumGroups(const std::string &compName, int numGroups,
420 const Instrument_const_sptr &inst, Progress &prog) {
421 std::map<detid_t, int> detIDtoGroup;
422
423 // Get detectors for given instument component
424 std::vector<IDetector_const_sptr> detectors;
425 inst->getDetectorsInBank(detectors, compName);
426 size_t numDetectors = detectors.size();
427
428 // Sanity check for following calculation
429 if (numGroups > static_cast<int>(numDetectors))
430 throw std::runtime_error("Number of groups must be less than or "
431 "equal to number of detectors");
432
433 // Calculate number of detectors per group
434 int detectorsPerGroup = static_cast<int>(numDetectors) / numGroups;
435
436 // Map detectors to group
437 for (unsigned int detIndex = 0; detIndex < numDetectors; detIndex++) {
438 int detectorID = detectors[detIndex]->getID();
439 int groupNum = (detIndex / detectorsPerGroup) + 1;
440
441 // Ignore any detectors the do not fit nicely into the group divisions
442 if (groupNum <= numGroups)
443 detIDtoGroup[detectorID] = groupNum;
444
445 prog.report();
446 }
447 return detIDtoGroup;
448}
449
450//------------------------------------------------------------------------------------------------
458bool groupnumber(std::string groupi, std::string groupj) {
459 int i = 0;
460 std::string groupName = std::move(groupi);
461 // Take out the "group" part of the group name and convert to an int
462 groupName.erase(remove_if(groupName.begin(), groupName.end(), std::not_fn(::isdigit)), groupName.end());
463 Strings::convert(groupName, i);
464 int j = 0;
465 groupName = std::move(groupj);
466 // Take out the "group" part of the group name and convert to an int
467 groupName.erase(remove_if(groupName.begin(), groupName.end(), std::not_fn(::isdigit)), groupName.end());
468 Strings::convert(groupName, j);
469 return (i < j);
470}
471
472//------------------------------------------------------------------------------------------------
481std::map<detid_t, int> makeGroupingByNames(std::string GroupNames, const Instrument_const_sptr &inst, Progress &prog,
482 bool sortnames) {
483 // This will contain the grouping
484 std::map<detid_t, int> detIDtoGroup;
485
486 // Split the names of the group and insert in a vector
487 std::vector<std::string> vgroups;
488 boost::split(vgroups, GroupNames, boost::algorithm::detail::is_any_ofF<char>(",/*"));
489 while (vgroups.back().empty()) {
490 vgroups.pop_back();
491 }
492 if (sortnames) {
493 std::sort(vgroups.begin(), vgroups.end(), groupnumber);
494 }
495
496 // Trim and assign incremental number to each group
497 std::map<std::string, int> group_map;
498 int index = 0;
499 for (auto &vgroup : vgroups) {
500 boost::trim(vgroup);
501 group_map[vgroup] = ++index;
502 }
503
504 // Find Detectors that belong to groups
505 if (!group_map.empty()) {
506 // Find Detectors that belong to groups
507 using sptr_ICompAss = std::shared_ptr<const Geometry::ICompAssembly>;
508 using sptr_IComp = std::shared_ptr<const Geometry::IComponent>;
509 using sptr_IDet = std::shared_ptr<const Geometry::IDetector>;
510 std::queue<std::pair<sptr_ICompAss, int>> assemblies;
511 sptr_ICompAss current = std::dynamic_pointer_cast<const Geometry::ICompAssembly>(inst);
512 sptr_IDet currentDet;
513 sptr_IComp currentIComp;
514 sptr_ICompAss currentchild;
515
516 int top_group, child_group;
517
518 if (current.get()) {
519 top_group = group_map[current->getName()]; // Return 0 if not in map
520 assemblies.emplace(current, top_group);
521 }
522
523 prog.setNumSteps(int(assemblies.size()));
524
525 while (!assemblies.empty()) // Travel the tree from the instrument point
526 {
527 current = assemblies.front().first;
528 top_group = assemblies.front().second;
529 assemblies.pop();
530 int nchilds = current->nelements();
531 if (nchilds != 0) {
532 for (int i = 0; i < nchilds; ++i) {
533 currentIComp = (*(current.get()))[i]; // Get child
534 currentDet = std::dynamic_pointer_cast<const Geometry::IDetector>(currentIComp);
535 if (currentDet.get()) // Is detector
536 {
537 if (top_group > 0) {
538 detIDtoGroup[currentDet->getID()] = top_group;
539 }
540 } else // Is an assembly, push in the queue
541 {
542 currentchild = std::dynamic_pointer_cast<const Geometry::ICompAssembly>(currentIComp);
543 if (currentchild.get()) {
544 child_group = group_map[currentchild->getName()];
545 if (child_group == 0)
546 child_group = top_group;
547 assemblies.emplace(currentchild, child_group);
548 }
549 }
550 }
551 }
552 prog.report();
553 }
554 }
555 return detIDtoGroup;
556}
557
558//----------------------------------------------------------------------------------------------
562 MatrixWorkspace_sptr inWS = getProperty("InputWorkspace");
563 std::string InstrumentName = getPropertyValue("InstrumentName");
564 std::string InstrumentFilename = getPropertyValue("InstrumentFilename");
565 std::string OldCalFilename = getPropertyValue("OldCalFilename");
566 std::string GroupNames = getPropertyValue("GroupNames");
567 std::string grouping = getPropertyValue("GroupDetectorsBy");
568 int numGroups = getProperty("FixedGroupCount");
569 std::string customGroupingString = getPropertyValue("CustomGroupingString");
570 std::string componentName = getPropertyValue("ComponentName");
571
572 // Some validation
573 int numParams = 0;
574 if (inWS)
575 numParams++;
576 if (!InstrumentName.empty())
577 numParams++;
578 if (!InstrumentFilename.empty())
579 numParams++;
580
581 if (numParams > 1)
582 throw std::invalid_argument("You must specify exactly ONE way to get an "
583 "instrument (workspace, instrument name, or "
584 "IDF file). You specified more than one.");
585 if (numParams == 0)
586 throw std::invalid_argument("You must specify exactly ONE way to get an "
587 "instrument (workspace, instrument name, or "
588 "IDF file). You specified none.");
589
590 if (!OldCalFilename.empty() && !GroupNames.empty())
591 throw std::invalid_argument("You must specify either to use the "
592 "OldCalFilename parameter OR GroupNames but "
593 "not both!");
594
595 bool sortnames = false;
596
597 const auto inst = getInstrument();
598
599 // Validation for 2_4Grouping input used only for SNAP
600 if (inst->getName() != "SNAP" && grouping == "2_4Grouping") {
601 const std::string message("2_4Grouping only works for SNAP.");
602 g_log.error(message);
603 throw std::invalid_argument(message);
604 }
605
606 if (GroupNames.empty() && OldCalFilename.empty()) {
607 if (grouping == "All") {
608 GroupNames = inst->getName();
609 } else if (inst->getName() == "SNAP" && grouping == "Group") {
610 GroupNames = "East,West";
611 } else if (inst->getName() == "POWGEN" && grouping == "Group") {
612 GroupNames = "South,North";
613 } else if (inst->getName() == "SNAP" && grouping == "2_4Grouping") {
614 GroupNames = "Column1,Column2,Column3,Column4,Column5,Column6,";
615 } else {
616 sortnames = true;
617 GroupNames = "";
618 int maxRecurseDepth = this->getProperty("MaxRecursionDepth");
619
620 PRAGMA_OMP(parallel for schedule(dynamic, 1) )
621 for (int num = 0; num < 300; ++num) {
623 std::ostringstream mess;
624 mess << grouping << num;
625 IComponent_const_sptr comp = inst->getComponentByName(mess.str(), maxRecurseDepth);
626 PARALLEL_CRITICAL(GroupNames)
627 if (comp)
628 GroupNames += mess.str() + ",";
630 }
632 }
633 }
634
635 // --------------------------- Create the output --------------------------
636 auto outWS = std::make_shared<GroupingWorkspace>(inst);
637 this->setProperty("OutputWorkspace", outWS);
638
639 // This will get the grouping
640 std::map<detid_t, int> detIDtoGroup;
641
642 Progress prog(this, 0.2, 1.0, outWS->getNumberHistograms());
643 // Make the grouping one of three ways:
644 if (!GroupNames.empty()) {
645 detIDtoGroup = makeGroupingByNames(GroupNames, inst, prog, sortnames);
646 if (grouping == "2_4Grouping") {
647 std::map<detid_t, int>::const_iterator it_end = detIDtoGroup.end();
648 std::map<detid_t, int>::const_iterator it;
649 for (it = detIDtoGroup.begin(); it != it_end; ++it) {
650 if (it->second < 5)
651 detIDtoGroup[it->first] = 1;
652 else
653 detIDtoGroup[it->first] = 2;
654 }
655 }
656
657 } else if (!OldCalFilename.empty())
658 detIDtoGroup = readGroupingFile(OldCalFilename, prog);
659 else if ((numGroups > 0) && !componentName.empty())
660 detIDtoGroup = makeGroupingByNumGroups(componentName, numGroups, inst, prog);
661 else if (!customGroupingString.empty() && !componentName.empty()) {
662 try {
663 detIDtoGroup = makeGroupingByCustomString(inst, componentName, customGroupingString);
664 } catch (const std::runtime_error &ex) {
665 g_log.error(ex.what());
666 return;
667 }
668 }
669
670 g_log.information() << detIDtoGroup.size() << " entries in the detectorID-to-group map.\n";
671 setProperty("NumberGroupedSpectraResult", static_cast<int>(detIDtoGroup.size()));
672
673 if (detIDtoGroup.empty()) {
674 g_log.warning() << "Creating empty group workspace\n";
675 setProperty("NumberGroupsResult", static_cast<int>(0));
676 } else {
677 size_t numNotFound = 0;
678
679 // Make the groups, if any
680 std::map<detid_t, int>::const_iterator it_end = detIDtoGroup.end();
681 std::map<detid_t, int>::const_iterator it;
682 std::unordered_set<int> groupCount;
683 for (it = detIDtoGroup.begin(); it != it_end; ++it) {
684 int detID = it->first;
685 int group = it->second;
686 groupCount.insert(group);
687 try {
688 outWS->setValue(detID, double(group));
689 } catch (std::invalid_argument &) {
690 numNotFound++;
691 }
692 }
693 setProperty("NumberGroupsResult", static_cast<int>(groupCount.size()));
694
695 if (numNotFound > 0)
696 g_log.warning() << numNotFound << " detector IDs (out of " << detIDtoGroup.size()
697 << ") were not found in the instrument\n.";
698 }
699}
700
702 MatrixWorkspace_sptr inputWorkspace = getProperty("InputWorkspace");
703 std::string instrumentName = getPropertyValue("InstrumentName");
704 std::string instrumentFilename = getPropertyValue("InstrumentFilename");
705
706 Instrument_const_sptr instrument;
707 if (inputWorkspace) {
708 instrument = inputWorkspace->getInstrument();
709 } else {
710 Algorithm_sptr childAlg = createChildAlgorithm("LoadInstrument", 0.0, 0.2);
711 MatrixWorkspace_sptr tempWS = std::make_shared<Workspace2D>();
712 childAlg->setProperty<MatrixWorkspace_sptr>("Workspace", tempWS);
713 childAlg->setPropertyValue("Filename", instrumentFilename);
714 childAlg->setProperty("RewriteSpectraMap", Mantid::Kernel::OptionalBool(true));
715 childAlg->setPropertyValue("InstrumentName", instrumentName);
716 childAlg->executeAsChildAlg();
717 instrument = tempWS->getInstrument();
718 }
719 return instrument;
720}
721
722} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
#define PARALLEL_START_INTERRUPT_REGION
Begins a block to skip processing is the algorithm has been interupted Note the end of the block if n...
Definition: MultiThreaded.h:94
#define PARALLEL_CRITICAL(name)
#define PARALLEL_END_INTERRUPT_REGION
Ends a block to skip processing is the algorithm has been interupted Note the start of the block if n...
#define PRAGMA_OMP(expression)
#define PARALLEL_CHECK_INTERRUPT_REGION
Adds a check after a Parallel region to see if it was interupted.
double lower
lower and upper bounds on the multiplier, if known
double upper
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Definition: Algorithm.cpp:1913
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
Definition: Algorithm.cpp:2026
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
bool isDefault(const std::string &name) const
Definition: Algorithm.cpp:2084
@ OptionalLoad
to specify a file to read but the file doesn't have to exist
Definition: FileProperty.h:53
Helper class for reporting progress from algorithms.
Definition: Progress.h:25
A property class for workspaces.
void init() override
Initialise the properties.
const std::string category() const override
Algorithm's category for identification.
std::map< std::string, std::string > validateInputs() override
Cross-check properties with each other.
const std::string name() const override
Algorithm's name for identification.
Mantid::Geometry::Instrument_const_sptr getInstrument()
int version() const override
Algorithm's version for identification.
BoundedValidator is a validator that requires the values to be between upper or lower bounds,...
Records the filename and the description of failure.
Definition: Exception.h:98
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void setPropertyGroup(const std::string &name, const std::string &group)
Set the group for a given property.
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition: Logger.h:52
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
void information(const std::string &msg)
Logs at information level.
Definition: Logger.cpp:105
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
void setNumSteps(int64_t nsteps)
Change the number of steps between start/end.
The concrete, templated class for properties.
EXPORT_OPT_MANTIDQT_COMMON std::vector< std::string > splitStringBy(std::string const &str, std::string const &delimiter)
Splits the string by the given delimiters.
Kernel::Logger g_log("ExperimentInfo")
static logger object
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::map< detid_t, int > makeGroupingByNumGroups(const std::string &compName, int numGroups, const Instrument_const_sptr &inst, Progress &prog)
Creates a mapping based on a fixed number of groups for a given instrument component.
std::map< detid_t, int > readGroupingFile(const std::string &groupingFileName, Progress &prog)
Read old-style .cal file to get the grouping.
std::map< detid_t, int > makeGroupingByNames(std::string GroupNames, const Instrument_const_sptr &inst, Progress &prog, bool sortnames)
Use bank names to build grouping.
bool groupnumber(std::string groupi, std::string groupj)
Use group numbers for sorting.
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
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
int convert(const std::string &A, T &out)
Convert a string into a number.
Definition: Strings.cpp:665
Helper class which provides the Collimation Length for SANS instruments.
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
Definition: EmptyValues.h:25
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