Commit b4a220cb authored by Robert Applin's avatar Robert Applin
Browse files

Refs #29984. Write out to map file.

parent 03fee7f8
......@@ -314,13 +314,14 @@ void CreateGroupingWorkspace::init() {
std::make_shared<BoundedValidator<int>>(0, INT_MAX),
"Used to distribute the detectors of a given component into "
"a fixed number of groups");
declareProperty("CustomGroupingString", "",
"This follows the same grouping patterns used in the "
":ref:`GroupDetectors <algm-GroupDetectors>` algorithm. An "
"example of the syntax is 1,2+3,4-6,7:9. This would group "
"detectors as: Group 1: Detector 1, Group 2: Detectors 2 and "
"3, Group 3: Detectors 4, 5 and 6, Group 4: Detector 7, "
"Group 5: Detector 8, Group 6: Detector 9.");
declareProperty(
"CustomGroupingString", "",
"This follows the same grouping patterns used in the "
":ref:`GroupDetectors <algm-GroupDetectors>` algorithm. An "
"example of the syntax is 1,2+3,4-6,7:9. This would group "
"detectors as follows: Group 1: Detector 1, Group 2: Detectors 2 and "
"3, Group 3: Detectors 4, 5 and 6, Group 4: Detector 7, "
"Group 5: Detector 8, Group 6: Detector 9.");
declareProperty("ComponentName", "",
"Specify the instrument component to "
"group into a fixed number of groups");
......
......@@ -56,8 +56,8 @@ private:
void printToXML(const std::map<int, std::vector<detid_t>> &groupdetidrangemap,
const std::string &xmlfilename);
/// Print Grouping to MAP file
void printToMap(const std::map<int, std::vector<detid_t>> &groupdetidrangemap,
const std::string &mapfilename);
void printToMap(std::map<int, std::vector<detid_t>> &groupToDetectorIDsMap,
const std::string &mapFilename);
// GroupingWorkspace
DataObjects::GroupingWorkspace_const_sptr mGroupWS;
......
......@@ -22,6 +22,8 @@
#include <fstream>
#include <sstream>
#include <boost/algorithm/string.hpp>
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Poco::XML;
......@@ -39,6 +41,23 @@ bool hasExtention(std::string filename, const std::string &extention) {
extention.length(), extention) == 0;
}
int numberOfDetectorIDs(const std::vector<Mantid::detid_t> &detectorIDs) {
return detectorIDs[1] - detectorIDs[0] + 1;
}
std::string
spaceSeperatedString(const std::vector<Mantid::detid_t> &detectorIDs) {
if (detectorIDs[0] == detectorIDs[1]) {
return std::to_string(detectorIDs[0]);
} else {
std::string detectorString;
for (auto id = detectorIDs[0]; id <= detectorIDs[1]; ++id)
detectorString += std::to_string(id) + " ";
boost::algorithm::trim(detectorString);
return detectorString;
}
}
} // namespace
namespace Mantid {
......@@ -259,9 +278,35 @@ void SaveDetectorsGrouping::printToXML(
ofs.close();
}
/** Creates a MAP file using the detector IDs found in a grouping workspace. The
* format of a MAP file is as follows:
*
* Line 1 - Number of groups.
*
* For N = 2 to N = Number of groups:
*
* Line N - Group ID.
* Line N + 1 - Number of detectors in group.
* Line N + 2 - Space seperated list of Detector IDs.
*/
void SaveDetectorsGrouping::printToMap(
const std::map<int, std::vector<detid_t>> &groupdetidrangemap,
const std::string &mapfilename) {}
std::map<int, std::vector<detid_t>> &groupToDetectorIDsMap,
const std::string &mapFilename) {
const auto removeIter = groupToDetectorIDsMap.find(0);
if (removeIter != groupToDetectorIDsMap.cend())
groupToDetectorIDsMap.erase(removeIter);
std::ofstream ofs;
ofs.open(mapFilename.c_str(), std::fstream::out);
ofs << std::to_string(groupToDetectorIDsMap.size()) + "\n";
for (auto detectorIds : groupToDetectorIDsMap) {
ofs << std::to_string(detectorIds.first) + "\n";
ofs << std::to_string(numberOfDetectorIDs(detectorIds.second)) + "\n";
ofs << spaceSeperatedString(detectorIds.second) + "\n";
}
ofs.close();
}
} // namespace DataHandling
} // namespace Mantid
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment