16#include "MantidHistogramData/HistogramMath.h"
17#include "MantidIndexing/Group.h"
18#include "MantidIndexing/IndexInfo.h"
19#include "MantidIndexing/SpectrumNumber.h"
25#include "MantidTypes/SpectrumDefinition.h"
27#include <boost/algorithm/string/classification.hpp>
28#include <boost/algorithm/string/split.hpp>
29#include <boost/algorithm/string/trim.hpp>
30#include <boost/regex.hpp>
36using namespace Kernel;
38using namespace DataObjects;
42enum class Behaviour { SUM, AVERAGE };
53void convertGroupsToMapFile(
const std::vector<std::vector<int>> &groups,
const SpectraAxis &axis,
54 std::stringstream &commands) {
57 commands << groups.size() <<
"\n";
58 for (
auto &group : groups) {
59 const int groupId = axis.spectraNo(group[0]);
60 const auto groupSize =
static_cast<int>(group.size());
63 commands <<
"# Group " << groupId;
64 commands <<
", contains " << groupSize <<
" spectra.\n";
66 commands << groupId <<
"\n";
67 commands << groupSize <<
"\n";
72 for (
size_t j = 0; j < group.size(); ++j) {
73 commands << (j > 0 ?
" " :
"") << axis.spectraNo(group[j]);
83void forceSpectraAxis(MatrixWorkspace &ws) {
84 if (
dynamic_cast<SpectraAxis *
>(ws.getAxis(1))) {
87 ws.replaceAxis(1, std::make_unique<SpectraAxis>(&ws));
101 std::make_shared<CommonBinsValidator>()),
102 "The name of the input 2D workspace");
104 "The name of the output workspace");
106 const std::vector<std::string> exts{
".map",
".xml"};
108 "A file that consists of lists of spectra numbers to group. See the "
109 "help for the file format");
111 "An array of group IDs to exclude when reading from an XML file.");
113 "If true, use sequential spectrum numbers, otherwise use the group "
114 "number from MapFile as spectrum numbers.");
116 "Describes how this algorithm should group the detectors. "
117 "See the help for full instructions.");
119 "An array containing a list of the spectrum numbers to combine "
120 "(DetectorList and WorkspaceIndexList are ignored if this is set)");
122 "An array of detector IDs to combine (WorkspaceIndexList is "
123 "ignored if this is set)");
125 "An array of workspace indices to combine");
127 "If true ungrouped spectra will be copied to the output workspace "
128 "and placed after the groups");
130 const std::vector<std::string> groupTypes{
"Sum",
"Average"};
132 declareProperty(
"Behaviour",
"Sum", std::make_shared<StringListValidator>(groupTypes),
133 "Whether to sum or average the values when grouping detectors.");
136 "Keep the output workspace as an EventWorkspace, if the "
137 "input has events.");
140 "The name of a workspace to copy the grouping from. "
141 "This can be either a normal workspace or a grouping workspace, but they "
142 "must be from the same instrument. "
143 "Detector ids are used to match up the spectra to be grouped. "
144 "If this option is selected all file and list options will be ignored.");
152 const bool preserveEvents =
getProperty(
"PreserveEvents");
154 if (eventW !=
nullptr && preserveEvents) {
159 const size_t numInHists = inputWS->getNumberHistograms();
165 std::vector<int64_t> unGroupedInds;
167 unGroupedInds.reserve(numInHists);
168 for (
size_t i = 0; i < numInHists; i++) {
169 unGroupedInds.emplace_back(i);
176 const std::set<int64_t> unGroupedSet(unGroupedInds.begin(), unGroupedInds.end());
179 const bool keepAll =
getProperty(
"KeepUngroupedSpectra");
182 const size_t numUnGrouped = keepAll ? unGroupedSet.size() - 1 : 0;
185 inputWS,
m_GroupWsInds.size() + numUnGrouped, inputWS->x(0).size(), inputWS->blocksize()));
189 throw std::invalid_argument(
"Input workspace must be an EventWorkspace or Workspace2D");
195 ((1.0 -
m_FracCompl) / (
static_cast<double>(numInHists - unGroupedSet.size()) + 1.)) *
196 (keepAll ?
static_cast<double>(numInHists - unGroupedSet.size()) /
static_cast<double>(numInHists) : 1.);
199 auto indexInfo = Indexing::IndexInfo(0);
200 const size_t outIndex =
formGroups(inputWS, outputWS, prog4Copy, keepAll, unGroupedSet, indexInfo);
205 moveOthers(unGroupedSet, *inputWS, *outputWS, outIndex);
208 outputWS->setIndexInfo(indexInfo);
213 forceSpectraAxis(*outputWS);
222 const size_t numInHists = inputWS->getNumberHistograms();
228 std::vector<int64_t> unGroupedInds;
230 unGroupedInds.reserve(numInHists);
231 for (
size_t i = 0; i < numInHists; i++) {
232 unGroupedInds.emplace_back(i);
241 const std::set<int64_t> unGroupedSet(unGroupedInds.begin(), unGroupedInds.end());
244 const bool keepAll =
getProperty(
"KeepUngroupedSpectra");
247 const size_t numUnGrouped = keepAll ? unGroupedSet.size() - 1 : 0;
251 "EventWorkspace",
m_GroupWsInds.size() + numUnGrouped, inputWS->x(0).size(), inputWS->blocksize()));
259 ((1.0 -
m_FracCompl) / (
static_cast<double>(numInHists - unGroupedSet.size()) + 1.)) *
260 (keepAll ?
static_cast<double>(numInHists - unGroupedSet.size()) /
static_cast<double>(numInHists) : 1.);
268 moveOthers(unGroupedSet, *inputWS, *outputWS, outIndex);
272 outputWS->setAllX(inputWS->binEdges(0));
277 forceSpectraAxis(*outputWS);
294 if (groupingWS_sptr) {
296 std::dynamic_pointer_cast<const DataObjects::GroupingWorkspace>(groupingWS_sptr);
298 g_log.
debug() <<
"Extracting grouping from GroupingWorkspace (" << groupWS->getName() <<
")\n";
301 g_log.
debug() <<
"Extracting grouping from MatrixWorkspace (" << groupingWS_sptr->getName() <<
")\n";
308 const std::string filename =
getProperty(
"MapFile");
309 if (!filename.empty()) {
312 std::string filenameCopy(filename);
313 std::transform(filenameCopy.begin(), filenameCopy.end(), filenameCopy.begin(), tolower);
314 if ((filenameCopy.find(
".xml")) != std::string::npos) {
321 }
catch (std::exception &) {
322 g_log.
error() <<
name() <<
": Error reading input file " << filename <<
'\n';
328 const std::string instructions =
getProperty(
"GroupingPattern");
329 if (!instructions.empty()) {
334 auto groups = Kernel::Strings::parseGroups<int>(instructions);
336 std::stringstream commandsSS;
337 convertGroupsToMapFile(groups, axis, commandsSS);
340 std::string firstLine;
341 std::getline(commandsSS, firstLine);
344 readFile(specs2index, commandsSS, lineNum, unUsedSpec,
350 const std::vector<specnum_t> spectraList =
getProperty(
"SpectraList");
352 const std::vector<size_t> indexList =
getProperty(
"WorkspaceIndexList");
355 if (!spectraList.empty()) {
357 g_log.
debug() <<
"Converted " << spectraList.size() <<
" spectra numbers into spectra indices to be combined\n";
366 }
else if (!indexList.empty()) {
371 auto maxIn =
static_cast<size_t>(
workspace->getNumberHistograms() - 1);
373 auto it = indices0.begin();
374 for (; it != indices0.end(); ++it) {
377 <<
" doesn't exist in the input workspace, the highest "
380 throw std::out_of_range(
"One of the spectra requested to group does "
381 "not exist in the input workspace");
388 <<
": File, WorkspaceIndexList, SpectraList, "
389 "and DetectorList properties are all "
391 throw std::invalid_argument(
"All list properties are empty, nothing to group");
397 auto index = indices0.begin();
417 std::vector<int64_t> &unUsedSpec) {
420 g_log.
debug() <<
"Opening input file ... " << fname;
421 std::ifstream File(fname.c_str(), std::ios::in);
423 std::string firstLine;
424 std::getline(File, firstLine);
429 g_log.
debug() <<
" file state failbit set after read attempt\n";
432 g_log.
debug() <<
" success opening input file " << fname <<
'\n';
448 int totalNumberOfGroups =
readInt(firstLine);
454 std::getline(File, firstLine), lineNum++;
455 totalNumberOfGroups =
readInt(firstLine);
458 bool ignoreGroupNo =
getProperty(
"IgnoreGroupNumber");
459 readFile(specs2index, File, lineNum, unUsedSpec, ignoreGroupNo);
461 if (
m_GroupWsInds.size() !=
static_cast<size_t>(totalNumberOfGroups)) {
462 g_log.
warning() <<
"The input file header states there are " << totalNumberOfGroups <<
" but the file contains "
469 catch (std::invalid_argument &e) {
470 g_log.
debug() <<
"Exception thrown: " << e.what() <<
'\n';
474 error =
"Input output error while reading file ";
477 }
catch (boost::bad_lexical_cast &e) {
478 g_log.
debug() <<
"Exception thrown: " << e.what() <<
'\n';
480 std::string
error(std::string(
"Problem reading integer value \"") + e.what() + std::string(
"\" near line number ") +
483 error =
"Input output error while reading file ";
501 std::vector<int64_t> &unUsedSpec) {
518 const std::vector<int> groupIDsToExclude =
getProperty(
"ExcludeGroupNumbers");
519 for (
const auto &groupID : groupIDsToExclude) {
520 const auto detectorIter = mGroupDetectorsMap.find(groupID);
521 if (detectorIter != mGroupDetectorsMap.cend())
522 mGroupDetectorsMap.erase(detectorIter);
523 const auto spectraIter = mGroupSpectraMap.find(groupID);
524 if (spectraIter != mGroupSpectraMap.cend())
525 mGroupSpectraMap.erase(spectraIter);
529 for (
const auto &det : mGroupDetectorsMap) {
534 for (
const auto &det : mGroupDetectorsMap) {
535 int groupid = det.first;
536 const std::vector<detid_t> &detids = det.second;
542 std::vector<size_t> &wsindexes = sit->second;
544 for (
auto detid : detids) {
545 auto ind = detIdToWiMap.find(detid);
546 if (ind != detIdToWiMap.end()) {
547 size_t wsid = ind->second;
548 wsindexes.emplace_back(wsid);
549 unUsedSpec[wsid] = (
USED);
551 g_log.
error() <<
"Detector with ID " << detid <<
" is not found in instrument \n";
557 for (
const auto &pit : mGroupSpectraMap) {
558 int groupid = pit.first;
559 const std::vector<int> &spectra = pit.second;
565 std::vector<size_t> &wsindexes = sit->second;
567 for (
auto specNum : spectra) {
568 auto ind = specs2index.find(specNum);
569 if (ind != specs2index.end()) {
570 size_t wsid = ind->second;
571 wsindexes.emplace_back(wsid);
572 unUsedSpec[wsid] = (
USED);
574 g_log.
error() <<
"Spectrum with ID " << specNum <<
" is not found in instrument \n";
589 std::vector<int64_t> &unUsedSpec) {
592 using Group2SetMapType = std::map<size_t, std::set<size_t>>;
593 Group2SetMapType group2WSIndexSetmap;
595 const auto &spectrumInfo = groupWS->spectrumInfo();
596 const auto &detectorIDs = groupWS->detectorInfo().detectorIDs();
597 for (
size_t i = 0; i < spectrumInfo.size(); ++i) {
599 size_t groupid =
static_cast<int>(groupWS->y(i)[0]);
602 group2WSIndexSetmap.insert({groupid, std::set<size_t>()});
604 std::set<size_t> &targetWSIndexSet = group2WSIndexSetmap[groupid];
605 for (
const auto &spectrumDefinition : spectrumInfo.spectrumDefinition(i)) {
607 size_t targetWSIndex = detIdToWiMap[detectorIDs[spectrumDefinition.first]];
608 targetWSIndexSet.insert(targetWSIndex);
610 unUsedSpec[targetWSIndex] = (
USED);
616 for (
auto &dit : group2WSIndexSetmap) {
617 size_t groupid = dit.first;
618 std::set<size_t> &targetWSIndexSet = dit.second;
620 std::vector<size_t>(targetWSIndexSet.begin(), targetWSIndexSet.end()));
634 std::vector<int64_t> &unUsedSpec) {
637 using Group2SetMapType = std::map<size_t, std::set<size_t>>;
638 Group2SetMapType group2WSIndexSetmap;
640 const auto &spectrumInfo = groupWS->spectrumInfo();
641 const auto &detectorIDs = groupWS->detectorInfo().detectorIDs();
642 for (
size_t i = 0; i < spectrumInfo.size(); ++i) {
645 group2WSIndexSetmap.insert({groupid, std::set<size_t>()});
648 if (spectrumInfo.spectrumDefinition(i).size() > 1) {
649 std::set<size_t> &targetWSIndexSet = group2WSIndexSetmap[groupid];
650 for (
const auto &spectrumDefinition : spectrumInfo.spectrumDefinition(i)) {
652 size_t targetWSIndex = detIdToWiMap[detectorIDs[spectrumDefinition.first]];
653 targetWSIndexSet.insert(targetWSIndex);
655 unUsedSpec[targetWSIndex] = (
USED);
661 for (
auto &dit : group2WSIndexSetmap) {
662 size_t groupid = dit.first;
663 std::set<size_t> &targetWSIndexSet = dit.second;
664 if (!targetWSIndexSet.empty()) {
665 std::vector<size_t> tempv;
666 tempv.assign(targetWSIndexSet.begin(), targetWSIndexSet.end());
683 if (dataComment.
begin() != dataComment.
end()) {
685 if (data.
count() == 1) {
686 if (!data[0].empty()) {
688 return boost::lexical_cast<int>(data[0]);
689 }
catch (boost::bad_lexical_cast &e) {
690 g_log.
debug() <<
"Exception thrown: " << e.what() <<
'\n';
691 throw std::invalid_argument(
"Error reading file, integer expected");
695 if (data.
count() == 0) {
700 g_log.
debug() <<
"Error: found " << data.
count() <<
" strings the first string is " << data[0] <<
'\n';
701 throw std::invalid_argument(
"Problem reading file, a singe integer expected");
720 std::vector<int64_t> &unUsedSpec,
const bool ignoreGroupNumber) {
722 int oldSpectrumNo = 1;
725 std::string thisLine;
727 std::getline(File, thisLine), lineNum++;
737 const int spectrumNo = ignoreGroupNumber ? oldSpectrumNo++ : groupNo;
743 throw std::invalid_argument(
"Premature end of file, expecting an "
744 "integer with the number of spectra in the "
746 std::getline(File, thisLine), lineNum++;
747 numberOfSpectra =
readInt(thisLine);
750 if (numberOfSpectra <= 0) {
751 throw std::invalid_argument(
"The number of spectra is zero or negative");
759 throw std::invalid_argument(
"Premature end of file, found number of "
760 "spectra specification but no spectra "
762 std::getline(File, thisLine), lineNum++;
765 }
while (
static_cast<int>(
m_GroupWsInds[spectrumNo].size()) < numberOfSpectra);
769 throw std::invalid_argument(std::string(
"Bad number of spectra "
770 "specification or spectra list "
771 "near line number ") +
793 std::vector<size_t> &output, std::vector<int64_t> &unUsedSpec,
794 const std::string &seperator) {
797 for (
const auto &itr : dataComment) {
798 std::vector<size_t> specNums;
799 specNums.reserve(output.capacity());
803 std::vector<size_t>::const_iterator specN = specNums.begin();
804 for (; specN != specNums.end(); ++specN) {
805 auto spectrumNum =
static_cast<specnum_t>(*specN);
806 auto ind = specs2index.find(spectrumNum);
807 if (ind == specs2index.end()) {
809 <<
" referred to in the input file was not found in the "
811 throw std::invalid_argument(
"Spectrum number " +
std::to_string(spectrumNum) +
" not found");
813 if (unUsedSpec[ind->second] !=
USED) {
816 unUsedSpec[ind->second] =
USED;
817 output.emplace_back(ind->second);
819 output.emplace_back(ind->second);
836 DataHandling::GroupDetectors2::storage_map::size_type numInHists) {
838 double progEstim = 2. *
static_cast<double>(numGroupsRead) /
static_cast<double>(numInHists);
841 progEstim =
READFILE * progEstim / (1 + progEstim);
864 const bool keepAll,
const std::set<int64_t> &unGroupedSet,
865 Indexing::IndexInfo &indexInfo) {
866 const std::string behaviourChoice =
getProperty(
"Behaviour");
867 const auto behaviour = behaviourChoice ==
"Sum" ? Behaviour::SUM : Behaviour::AVERAGE;
869 const auto &spectrumInfo = inputWS->spectrumInfo();
870 const auto nFinalHistograms =
m_GroupWsInds.size() + (keepAll ? unGroupedSet.size() : 0);
871 auto spectrumGroups = std::vector<std::vector<size_t>>();
872 spectrumGroups.reserve(nFinalHistograms);
873 auto spectrumNumbers = std::vector<Indexing::SpectrumNumber>();
874 spectrumNumbers.reserve(nFinalHistograms);
878 auto &outSpec = outputWS->getSpectrum(outIndex);
881 spectrumNumbers.emplace_back(group.first);
883 outSpec.clearDetectorIDs();
887 outSpec.setSharedX(inputWS->sharedX(0));
890 std::vector<size_t> spectrumGroup;
891 spectrumGroup.reserve(group.second.size());
893 auto &Ys = outSpec.mutableY();
894 auto &Es = outSpec.mutableE();
895 std::vector<double> sum(Ys.size(), 0.);
896 std::vector<double> errorSum(Ys.size(), 0.);
897 std::vector<int>
count(Ys.size(), 0);
898 for (
auto originalWI : group.second) {
899 const auto &inSpec = inputWS->getSpectrum(originalWI);
900 outSpec.addDetectorIDs(inSpec.getDetectorIDs());
901 spectrumGroup.emplace_back(originalWI);
902 if (spectrumInfo.hasDetectors(originalWI) && spectrumInfo.isMasked(originalWI)) {
905 const auto &inYs = inputWS->y(originalWI);
906 const auto &inEs = inputWS->e(originalWI);
907 if (inputWS->hasMaskedBins(originalWI)) {
908 const auto &maskedBins = inputWS->maskedBins(originalWI);
909 for (
size_t binIndex = 0; binIndex < inYs.size(); ++binIndex) {
910 if (maskedBins.count(binIndex) == 0) {
911 sum[binIndex] += inYs[binIndex];
912 errorSum[binIndex] += inEs[binIndex] * inEs[binIndex];
913 count[binIndex] += 1;
917 for (
size_t binIndex = 0; binIndex < inYs.size(); ++binIndex) {
918 sum[binIndex] += inYs[binIndex];
919 errorSum[binIndex] += inEs[binIndex] * inEs[binIndex];
920 count[binIndex] += 1;
924 spectrumGroups.emplace_back(std::move(spectrumGroup));
925 for (
size_t binIndex = 0; binIndex < sum.size(); ++binIndex) {
926 errorSum[binIndex] = std::sqrt(errorSum[binIndex]);
927 if (behaviour == Behaviour::AVERAGE) {
928 const auto n =
static_cast<double>(
count[binIndex]);
931 errorSum[binIndex] /=
n;
934 errorSum[binIndex] = 0;
937 Ys[binIndex] = sum[binIndex];
938 Es[binIndex] = errorSum[binIndex];
955 for (
const auto originalWI : unGroupedSet) {
960 spectrumGroups.emplace_back(1, originalWI);
962 auto spectrumNumber = inputWS->getSpectrum(originalWI).getSpectrumNo();
963 spectrumNumbers.emplace_back(spectrumNumber);
967 indexInfo = Indexing::group(inputWS->indexInfo(), std::move(spectrumNumbers), spectrumGroups);
982 if (inputWS->detectorInfo().isScanning())
983 throw std::runtime_error(
"GroupDetectors does not currently support "
984 "EventWorkspaces with detector scans.");
987 const std::string behaviour =
getProperty(
"Behaviour");
989 if (behaviour ==
"Average")
1002 bool requireDivide(
false);
1003 const auto &spectrumInfo = inputWS->spectrumInfo();
1006 EventList &outEL = outputWS->getSpectrum(outIndex);
1016 size_t nonMaskedSpectra(0);
1017 beh->mutableX(outIndex)[0] = 0.0;
1018 beh->mutableE(outIndex)[0] = 0.0;
1019 for (
auto originalWI : it->second) {
1020 const EventList &fromEL = inputWS->getSpectrum(originalWI);
1026 if (!spectrumInfo.hasDetectors(originalWI) || !spectrumInfo.isMasked(originalWI)) {
1030 if (nonMaskedSpectra == 0)
1033 requireDivide = (nonMaskedSpectra > 1);
1034 beh->mutableY(outIndex)[0] =
static_cast<double>(nonMaskedSpectra);
1047 if (bhv == 1 && requireDivide) {
1048 g_log.
debug() <<
"Running Divide algorithm to perform averaging.\n";
1050 divide->initialize();
1057 g_log.
debug() <<
name() <<
" created " << outIndex <<
" new grouped spectra\n";
1082 auto readPostion = beforeHyphen.
begin();
1083 if (readPostion == beforeHyphen.
end()) {
1084 throw std::invalid_argument(
"'-' found at the start of a list, can't "
1085 "interpret range specification");
1087 for (; readPostion != beforeHyphen.
end(); ++readPostion) {
1088 outList.emplace_back(boost::lexical_cast<size_t>(*readPostion));
1092 const size_t rangeStart = outList.back();
1093 if (loop + 1 == ranges.
count()) {
1098 readPostion = afterHyphen.
begin();
1099 if (readPostion == afterHyphen.
end()) {
1100 throw std::invalid_argument(
"A '-' follows straight after another '-', "
1101 "can't interpret range specification");
1105 const auto rangeEnd = boost::lexical_cast<size_t>(*readPostion);
1109 if (rangeStart > rangeEnd) {
1110 throw std::invalid_argument(
"A range where the first integer is larger "
1111 "than the second is not allowed");
1115 for (
size_t j = rangeStart + 1; j < rangeEnd; j++) {
1116 outList.emplace_back(j);
1120 }
while (loop < ranges.
count());
1121 }
catch (boost::bad_lexical_cast &e) {
1122 throw std::invalid_argument(std::string(
"Expected list of integers, exception thrown: ") + e.what());
1124 if (*(line.end() - 1) ==
'-') {
1125 throw std::invalid_argument(
"'-' found at the end of a list, can't interpret range specification");
1135 std::map<std::string, std::string> errors;
1139 static const boost::regex re(R
"(^\s*[0-9]+\s*$|^(\s*,*[0-9]+(\s*(,|:|\+|\-)\s*)*[0-9]*)*$)");
1142 if (!pattern.empty() && !boost::regex_match(pattern, re)) {
1143 errors[
"GroupingPattern"] =
"GroupingPattern is not well formed: " + pattern;
1145 }
catch (boost::exception &) {
1148 for (
const auto &groupStr : groups) {
1149 if (!pattern.empty() && !boost::regex_match(groupStr, re)) {
1150 errors[
"GroupingPattern"] =
"GroupingPattern is not well formed: " + pattern;
#define DECLARE_ALGORITHM(classname)
IPeaksWorkspace_sptr workspace
std::map< DeltaEMode::Type, std::string > index
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
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.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
void interruption_point()
This is called during long-running operations, and check if the algorithm has requested that it be ca...
@ OptionalLoad
to specify a file to read but the file doesn't have to exist
void addDetectorIDs(const std::set< detid_t > &detIDs)
Add a set of detector IDs to the set of detector IDs.
void clearDetectorIDs()
Clear the detector IDs set.
const std::set< detid_t > & getDetectorIDs() const
Get a const reference to the detector IDs set.
void setSpectrumNo(specnum_t num)
Sets the the spectrum number of this spectrum.
Class to represent the spectra axis of a workspace.
spec2index_map getSpectraIndexMap() const
Returns a map where spectra is the key and index is the value This is used for efficient search of sp...
A property class for workspaces.
static void getList(const std::string &line, std::vector< size_t > &outList)
Expands any ranges in the input string of non-negative integers, eg.
double m_FracCompl
An estimate of the percentage of the algorithm runtimes that has been completed.
void readFile(const spec2index_map &specs2index, std::istream &File, size_t &lineNum, std::vector< int64_t > &unUsedSpec, const bool ignoreGroupNumber)
Reads from the file getting in order: an unused integer, on the next line the number of spectra in th...
static const double OPENINGFILE
required to check that the X bin boundaries are the same as a percentage of total algorithm run time
void processMatrixWorkspace(const API::MatrixWorkspace_const_sptr &groupWS, const API::MatrixWorkspace_const_sptr &workspace, std::vector< int64_t > &unUsedSpec)
Get groupings from a matrix workspace.
storage_map m_GroupWsInds
stores lists of spectra indexes to group, although we never do an index search on it
std::map< std::string, std::string > validateInputs() override
Validate inputs.
const std::string name() const override
Algorithm's name for identification overriding a virtual method.
void moveOthers(const std::set< int64_t > &unGroupedSet, const TIn &inputWS, TOut &outputWS, size_t outIndex)
Copy the ungrouped spectra from the input workspace to the output.
void processFile(const std::string &fname, const API::MatrixWorkspace_const_sptr &workspace, std::vector< int64_t > &unUsedSpec)
gets the list of spectra index numbers from a file of spectra numbers
static const double CHECKBINS
a (worse case) estimate of the time
void processXMLFile(const std::string &fname, const API::MatrixWorkspace_const_sptr &workspace, std::vector< int64_t > &unUsedSpec)
gets groupings from XML file
size_t formGroups(const API::MatrixWorkspace_const_sptr &inputWS, const API::MatrixWorkspace_sptr &outputWS, const double prog4Copy, const bool keepAll, const std::set< int64_t > &unGroupedSet, Indexing::IndexInfo &indexInfo)
Copy the and combine the histograms that the user requested from the input into the output workspace.
static const double READFILE
if a file must be read in estimate that
void exec() override
Virtual method - must be overridden by concrete algorithm.
static const int INTERVAL
reading it will take this percentage of the algorithm execution time
int readInt(const std::string &line)
used while reading the file turns the string into an integer number (if possible),...
void getGroups(const API::MatrixWorkspace_const_sptr &workspace, std::vector< int64_t > &unUsedSpec)
read in the input parameters and see what findout what will be to grouped
void processGroupingWorkspace(const DataObjects::GroupingWorkspace_const_sptr &groupWS, const API::MatrixWorkspace_const_sptr &workspace, std::vector< int64_t > &unUsedSpec)
Get groupings from groupingworkspace.
@ EMPTY_LINE
spectrum will be included in a group, any other value and it isn't.
@ USED
goes in the unGrouped spectra list to say that a
@ IGNORE_SPACES
value means that we found any empty line
void init() override
Virtual method - must be overridden by concrete algorithm.
void readSpectraIndexes(const std::string &line, const spec2index_map &specs2index, std::vector< size_t > &output, std::vector< int64_t > &unUsedSpec, const std::string &seperator="#")
used while reading the file reads reads spectra numbers from the string and returns spectra indexes
double fileReadProg(DataHandling::GroupDetectors2::storage_map::size_type numGroupsRead, DataHandling::GroupDetectors2::storage_map::size_type numInHists)
Estimate how much what has been read from the input file constitutes progress for the algorithm.
size_t formGroupsEvent(const DataObjects::EventWorkspace_const_sptr &inputWS, const DataObjects::EventWorkspace_sptr &outputWS, const double prog4Copy)
Copy the and combine the event lists that the user requested from the input into the output workspace...
void loadXMLFile(const std::string &xmlfilename)
std::map< int, std::vector< detid_t > > getGroupDetectorsMap()
void setDefaultStartingGroupID(int startgroupid)
std::map< int, std::vector< int > > getGroupSpectraMap()
Support for a property that holds an array of values.
Records the filename and the description of failure.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
ListValidator is a validator that requires the value of a property to be one of a defined list of pos...
void debug(const std::string &msg)
Logs at debug level.
void error(const std::string &msg)
Logs at error level.
void warning(const std::string &msg)
Logs at warning level.
void information(const std::string &msg)
Logs at information level.
The concrete, templated class for properties.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
Iterator begin()
Iterator referring to first element in the container.
@ TOK_TRIM
remove leading and trailing whitespace from tokens
Iterator end()
Iterator referring to the past-the-end element in the container.
std::size_t count() const
Get the total number of tokens.
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< const GroupingWorkspace > GroupingWorkspace_const_sptr
shared pointer to a const GroupingWorkspace
std::shared_ptr< const EventWorkspace > EventWorkspace_const_sptr
shared pointer to a const Workspace2D
std::shared_ptr< EventWorkspace > EventWorkspace_sptr
shared pointer to the EventWorkspace class
std::unique_ptr< T > create(const P &parent, const IndexArg &indexArg, const HistArg &histArg)
This is the create() method that all the other create() methods call.
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.
int32_t specnum_t
Typedef for a spectrum Number.
std::string to_string(const wide_integer< Bits, Signed > &n)
@ Input
An input workspace.
@ Output
An output workspace.