49const std::string
SaveDiffCal::summary()
const {
return "Saves a calibration file for powder diffraction"; }
57 "An output workspace.");
61 "Optional: A GroupingWorkspace giving the grouping info.");
65 "Optional: A MaskWorkspace giving which detectors are masked.");
68 "Path to the .h5 file that will be created.");
72 std::map<std::string, std::string> result;
75 if (
bool(calibrationWS)) {
76 size_t numRows = calibrationWS->rowCount();
78 result[
"CalibrationWorkspace"] =
"Cannot save empty table";
81 if (
bool(groupingWS) && numRows < groupingWS->getNumberHistograms()) {
82 result[
"GroupingWorkspace"] =
"Must have equal or less number of spectra as the table has rows";
85 if (
bool(maskWS) && numRows < maskWS->getNumberHistograms()) {
86 result[
"MaskWorkspace"] =
"Must have equal or less number of spectra as the table has rows";
93 if ((!groupingWS) && (!maskWS)) {
94 const std::string msg(
"Failed to supply any input workspace");
95 result[
"CalibrationWorkspace"] = msg;
96 result[
"GroupingWorkspace"] = msg;
97 result[
"MaskWorkspace"] = msg;
122 if (
name !=
"difc") {
123 bool allZeros = std::all_of(data.cbegin(), data.cend(), [](
const auto &
value) { return value == 0; });
141 auto data = column->numeric_fill<int32_t>(
m_numValues);
152 throw std::runtime_error(
"Encountered null pointer in SaveDiffCal::writeDetIdsfromSVWS which should be impossible");
154 std::vector<int32_t> values;
156 const auto &detids = ws->getSpectrum(i).getDetectorIDs();
157 std::transform(detids.cbegin(), detids.cend(), std::back_inserter(values),
158 [](
const auto &detid) { return static_cast<int32_t>(detid); });
177 const bool isMask = (
name ==
"use");
183 for (
size_t i = 0; i < ws->getNumberHistograms(); ++i) {
184 auto &ids = ws->getSpectrum(i).getDetectorIDs();
188 auto value =
static_cast<int32_t
>(ws->getValue(found->first));
196 for (
const auto &indexes : found->second) {
197 values[indexes] =
value;
210 auto detids = detidCol->numeric_fill<
detid_t>();
212 const size_t numDets = detids.size();
213 for (
size_t i = 0; i < numDets; ++i) {
220 throw std::runtime_error(
221 "Encountered null pointer in SaveDiffCal::generateDetidToIndex which should be impossible");
225 std::size_t
index = 0;
227 const auto &detids = ws->getSpectrum(i).getDetectorIDs();
228 for (
const auto &detid : detids) {
237 const std::vector<std::string> names =
m_calibrationWS->getColumnNames();
238 return std::any_of(names.cbegin(), names.cend(), [&ColumnName](
const auto &
name) { return name == ColumnName; });
257 }
else if (groupingWS) {
265 if (groupingWS && groupingWS->isDetectorIDMappingEmpty())
266 groupingWS->buildDetectorIDMapping();
270 if (std::filesystem::exists(filename)) {
271 std::filesystem::remove(filename);
292 }
else if (groupingWS) {
315 std::string instrumentName;
316 std::string instrumentSource;
317 if (
bool(groupingWS)) {
318 instrumentName = groupingWS->getInstrument()->getName();
319 instrumentSource = groupingWS->instrumentMetadata().filename();
322 if (instrumentName.empty()) {
323 instrumentName = maskWS->getInstrument()->getName();
325 if (instrumentSource.empty()) {
326 instrumentSource = maskWS->instrumentMetadata().filename();
329 if (!instrumentSource.empty()) {
330 instrumentSource = std::filesystem::path(instrumentSource).filename().string();
334 auto instrumentGroup = calibrationGroup.createGroup(
"instrument");
336 if (!instrumentName.empty()) {
339 if (!instrumentSource.empty()) {
340 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.
std::map< detid_t, std::vector< size_t > > m_detidToIndex
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.
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.