48const std::string
SaveDiffCal::summary()
const {
return "Saves a calibration file for powder diffraction"; }
56 "An output workspace.");
60 "Optional: A GroupingWorkspace giving the grouping info.");
64 "Optional: A MaskWorkspace giving which detectors are masked.");
67 "Path to the .h5 file that will be created.");
71 std::map<std::string, std::string> result;
74 if (
bool(calibrationWS)) {
75 size_t numRows = calibrationWS->rowCount();
77 result[
"CalibrationWorkspace"] =
"Cannot save empty table";
80 if (
bool(groupingWS) && numRows < groupingWS->getNumberHistograms()) {
81 result[
"GroupingWorkspace"] =
"Must have equal or less number of spectra as the table has rows";
84 if (
bool(maskWS) && numRows < maskWS->getNumberHistograms()) {
85 result[
"MaskWorkspace"] =
"Must have equal or less number of spectra as the table has rows";
92 if ((!groupingWS) && (!maskWS)) {
93 const std::string msg(
"Failed to supply any input workspace");
94 result[
"CalibrationWorkspace"] = msg;
95 result[
"GroupingWorkspace"] = msg;
96 result[
"MaskWorkspace"] = msg;
121 if (
name !=
"difc") {
122 bool allZeros = std::all_of(data.cbegin(), data.cend(), [](
const auto &
value) { return value == 0; });
140 auto data = column->numeric_fill<int32_t>(
m_numValues);
151 throw std::runtime_error(
"Encountered null pointer in SaveDiffCal::writeDetIdsfromSVWS which should be impossible");
153 std::vector<int32_t> values;
155 const auto &detids = ws->getSpectrum(i).getDetectorIDs();
156 std::transform(detids.cbegin(), detids.cend(), std::back_inserter(values),
157 [](
const auto &detid) { return static_cast<int32_t>(detid); });
176 const bool isMask = (
name ==
"use");
183 auto &ids = ws->getSpectrum(i).getDetectorIDs();
187 auto value =
static_cast<int32_t
>(ws->getValue(found->first));
195 values[found->second] =
value;
207 auto detids = detidCol->numeric_fill<
detid_t>();
209 const size_t numDets = detids.size();
210 for (
size_t i = 0; i < numDets; ++i) {
217 throw std::runtime_error(
218 "Encountered null pointer in SaveDiffCal::generateDetidToIndex which should be impossible");
222 std::size_t
index = 0;
224 const auto &detids = ws->getSpectrum(i).getDetectorIDs();
225 for (
const auto &detid : detids) {
234 const std::vector<std::string> names =
m_calibrationWS->getColumnNames();
235 return std::any_of(names.cbegin(), names.cend(), [&ColumnName](
const auto &
name) { return name == ColumnName; });
251 m_numValues = std::numeric_limits<std::size_t>::max();
263 }
else if (groupingWS) {
269 if (groupingWS && groupingWS->isDetectorIDMappingEmpty())
270 groupingWS->buildDetectorIDMapping();
274 if (std::filesystem::exists(filename)) {
275 std::filesystem::remove(filename);
296 }
else if (groupingWS) {
319 std::string instrumentName;
320 std::string instrumentSource;
321 if (
bool(groupingWS)) {
322 instrumentName = groupingWS->getInstrument()->getName();
323 instrumentSource = groupingWS->getInstrument()->getFilename();
326 if (instrumentName.empty()) {
327 instrumentName = maskWS->getInstrument()->getName();
329 if (instrumentSource.empty()) {
330 instrumentSource = maskWS->getInstrument()->getFilename();
333 if (!instrumentSource.empty()) {
334 instrumentSource = std::filesystem::path(instrumentSource).filename().string();
338 auto instrumentGroup = calibrationGroup.createGroup(
"instrument");
340 if (!instrumentName.empty()) {
343 if (!instrumentSource.empty()) {
344 H5Util::write(instrumentGroup,
"instrument_source", instrumentSource);
#define DECLARE_ALGORITHM(classname)
double value
The value of the point.
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.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
A specialized class for dealing with file properties.
@ Save
to specify a file to write to, the file may or may not exist
ITableWorkspace is an implementation of Workspace in which the data are organised in columns of same ...
A property class for workspaces.
SaveDiffCal : TODO: DESCRIPTION.
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
void writeIntFieldFromTable(H5::Group &group, const std::string &name)
Create a dataset under a given group with a given name Use CalibrationWorkspace to retrieve the data.
API::ITableWorkspace_sptr m_calibrationWS
const std::string category() const override
Algorithm's category for identification.
void writeDoubleFieldFromTable(H5::Group &group, const std::string &name)
Create a dataset under a given group with a given name Use CalibrationWorkspace to retrieve the data.
int version() const override
Algorithm's version for identification.
void init() override
Initialize the algorithm's properties.
std::map< detid_t, size_t > m_detidToIndex
void writeDetIdsfromSVWS(H5::Group &group, const std::string &name, const DataObjects::SpecialWorkspace2D_const_sptr &ws)
void writeDoubleFieldZeros(H5::Group &group, const std::string &name)
void generateDetidToIndex()
const std::string name() const override
Algorithms name for identification.
bool tableHasColumn(const std::string &ColumnName) const
std::map< std::string, std::string > validateInputs() override
Perform validation of ALL the input properties of the algorithm.
void exec() override
Execute the algorithm.
void writeIntFieldFromSVWS(H5::Group &group, const std::string &name, const DataObjects::SpecialWorkspace2D_const_sptr &ws)
Create a dataset under a given group with a given name Use GroupingWorkspace or MaskWorkspace to retr...
A GroupingWorkspace is a subclass of Workspace2D where each spectrum has a single number entry,...
void information(const std::string &msg)
Logs at information level.
std::shared_ptr< const ITableWorkspace > ITableWorkspace_const_sptr
shared pointer to Mantid::API::ITableWorkspace (const version)
std::shared_ptr< const GroupingWorkspace > GroupingWorkspace_const_sptr
shared pointer to a const GroupingWorkspace
std::shared_ptr< const SpecialWorkspace2D > SpecialWorkspace2D_const_sptr
shared pointer to a const SpecialWorkspace2D
std::shared_ptr< GroupingWorkspace > GroupingWorkspace_sptr
shared pointer to the GroupingWorkspace class
std::shared_ptr< const MaskWorkspace > MaskWorkspace_const_sptr
shared pointer to a const MaskWorkspace
void writeArray1D(H5::Group &group, const std::string &name, const std::vector< NumT > &values)
MANTID_NEXUS_DLL void writeStrAttribute(const H5::H5Object &object, const std::string &name, const std::string &value)
MANTID_NEXUS_DLL H5::FileAccPropList defaultFileAcc()
Default file access is H5F_CLOSE_STRONG.
MANTID_NEXUS_DLL H5::Group createGroupNXS(H5::H5File &file, const std::string &name, const std::string &nxtype)
MANTID_NEXUS_DLL void write(H5::Group &group, const std::string &name, const std::string &value)
int32_t detid_t
Typedef for a detector ID.
Enumeration for a mandatory/optional property.
Describes the direction (within an algorithm) of a Property.
@ Input
An input workspace.