Skip to content

Commit 0ce8e5b

Browse files
Merge pull request #38869 from peterfpeterson/38504_save_groups_in_nxcansas_ornlnext
SaveNXcansSAS changes into `ornl-next`
2 parents 06055cd + 54fb8fe commit 0ce8e5b

File tree

12 files changed

+1192
-927
lines changed

12 files changed

+1192
-927
lines changed

Framework/DataHandling/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ set(SRC_FILES
141141
src/ModifyDetectorDotDatFile.cpp
142142
src/MoveInstrumentComponent.cpp
143143
src/MultiPeriodLoadMuonStrategy.cpp
144+
src/NXcanSASHelper.cpp
144145
src/NexusTester.cpp
145146
src/ORNLDataArchive.cpp
146147
src/PDLoadCharacterizations.cpp
@@ -182,6 +183,7 @@ set(SRC_FILES
182183
src/SaveNXSPE.cpp
183184
src/SaveNXTomo.cpp
184185
src/SaveNXcanSAS.cpp
186+
src/SaveNXcanSASBase.cpp
185187
src/SaveNexus.cpp
186188
src/SaveNexusESS.cpp
187189
src/SaveNexusGeometry.cpp
@@ -356,6 +358,7 @@ set(INC_FILES
356358
inc/MantidDataHandling/MoveInstrumentComponent.h
357359
inc/MantidDataHandling/MultiPeriodLoadMuonStrategy.h
358360
inc/MantidDataHandling/NXcanSASDefinitions.h
361+
inc/MantidDataHandling/NXcanSASHelper.h
359362
inc/MantidDataHandling/NexusTester.h
360363
inc/MantidDataHandling/ORNLDataArchive.h
361364
inc/MantidDataHandling/PDLoadCharacterizations.h
@@ -397,6 +400,7 @@ set(INC_FILES
397400
inc/MantidDataHandling/SaveNXSPE.h
398401
inc/MantidDataHandling/SaveNXTomo.h
399402
inc/MantidDataHandling/SaveNXcanSAS.h
403+
inc/MantidDataHandling/SaveNXcanSASBase.h
400404
inc/MantidDataHandling/SaveNexus.h
401405
inc/MantidDataHandling/SaveNexusESS.h
402406
inc/MantidDataHandling/SaveNexusGeometry.h
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Mantid Repository : https://github.com/mantidproject/mantid
2+
//
3+
// Copyright © 2025 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 +
7+
#pragma once
8+
9+
#include "MantidAPI/Algorithm.h"
10+
#include "MantidAPI/MatrixWorkspace_fwd.h"
11+
#include "MantidDataHandling/DllConfig.h"
12+
#include <H5Cpp.h>
13+
#include <filesystem>
14+
15+
namespace Mantid {
16+
namespace DataHandling {
17+
namespace NXcanSAS {
18+
// Helper functions for algorithms saving in NXcanSAS format.
19+
enum class WorkspaceDimensionality;
20+
21+
std::string MANTID_DATAHANDLING_DLL makeCanSASRelaxedName(const std::string &input);
22+
std::filesystem::path MANTID_DATAHANDLING_DLL prepareFilename(const std::string &baseFilename, int index,
23+
bool isGroup = false);
24+
void MANTID_DATAHANDLING_DLL addDetectors(H5::Group &group, const Mantid::API::MatrixWorkspace_sptr &workspace,
25+
const std::vector<std::string> &detectorNames);
26+
void MANTID_DATAHANDLING_DLL addInstrument(H5::Group &group, const Mantid::API::MatrixWorkspace_sptr &workspace,
27+
const std::string &radiationSource, const std::string &geometry,
28+
double beamHeight, double beamWidth,
29+
const std::vector<std::string> &detectorNames);
30+
void MANTID_DATAHANDLING_DLL addSample(H5::Group &group, const double &sampleThickness);
31+
void MANTID_DATAHANDLING_DLL addProcess(H5::Group &group, const Mantid::API::MatrixWorkspace_sptr &workspace);
32+
void MANTID_DATAHANDLING_DLL addProcess(H5::Group &group, const Mantid::API::MatrixWorkspace_sptr &workspace,
33+
const Mantid::API::MatrixWorkspace_sptr &canWorkspace);
34+
void MANTID_DATAHANDLING_DLL addProcessEntry(H5::Group &group, const std::string &entryName,
35+
const std::string &entryValue);
36+
void MANTID_DATAHANDLING_DLL addTransmission(H5::Group &group, const Mantid::API::MatrixWorkspace_const_sptr &workspace,
37+
const std::string &transmissionName);
38+
39+
void MANTID_DATAHANDLING_DLL addData1D(H5::Group &data, const Mantid::API::MatrixWorkspace_sptr &workspace);
40+
void MANTID_DATAHANDLING_DLL addData2D(H5::Group &data, const Mantid::API::MatrixWorkspace_sptr &workspace);
41+
42+
WorkspaceDimensionality MANTID_DATAHANDLING_DLL
43+
getWorkspaceDimensionality(const Mantid::API::MatrixWorkspace_sptr &workspace);
44+
std::vector<std::string> MANTID_DATAHANDLING_DLL splitDetectorNames(std::string detectorNames);
45+
46+
} // namespace NXcanSAS
47+
} // namespace DataHandling
48+
} // namespace Mantid

Framework/DataHandling/inc/MantidDataHandling/SaveNXcanSAS.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
// SPDX - License - Identifier: GPL - 3.0 +
77
#pragma once
88

9-
#include "MantidAPI/Algorithm.h"
109
#include "MantidDataHandling/DllConfig.h"
10+
#include "MantidDataHandling/SaveNXcanSASBase.h"
1111

1212
namespace Mantid {
1313
namespace DataHandling {
1414

1515
/** SaveNXcanSAS : Saves a reduced workspace in the NXcanSAS format. Currently
1616
* only MatrixWorkspaces resulting from 1D and 2D reductions are supported.
1717
*/
18-
class MANTID_DATAHANDLING_DLL SaveNXcanSAS final : public API::Algorithm {
18+
class MANTID_DATAHANDLING_DLL SaveNXcanSAS final : public SaveNXcanSASBase {
1919
public:
2020
/// Constructor
2121
SaveNXcanSAS();
@@ -26,6 +26,8 @@ class MANTID_DATAHANDLING_DLL SaveNXcanSAS final : public API::Algorithm {
2626
const std::string summary() const override {
2727
return "Save a MatrixWorkspace to a file in the NXcanSAS format (for both 1D and 2D data).";
2828
}
29+
/// Override processGroups
30+
bool processGroups() override;
2931

3032
/// Algorithm's version
3133
int version() const override { return (1); }
@@ -40,9 +42,10 @@ class MANTID_DATAHANDLING_DLL SaveNXcanSAS final : public API::Algorithm {
4042
void init() override;
4143
/// Execution code
4244
void exec() override;
43-
};
45+
void processAllWorkspaces();
4446

45-
std::string MANTID_DATAHANDLING_DLL makeCanSASRelaxedName(const std::string &input);
47+
std::vector<API::MatrixWorkspace_sptr> m_workspaces;
48+
};
4649

4750
} // namespace DataHandling
4851
} // namespace Mantid
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Mantid Repository : https://github.com/mantidproject/mantid
2+
//
3+
// Copyright &copy; 2025 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 +
7+
#pragma once
8+
9+
#include "MantidAPI/Algorithm.h"
10+
#include "MantidAPI/MatrixWorkspace_fwd.h"
11+
#include "MantidDataHandling/DllConfig.h"
12+
#include <H5Cpp.h>
13+
#include <filesystem>
14+
15+
namespace Mantid {
16+
namespace DataHandling {
17+
18+
/** SaveNXcanSASBase : Base class to save a reduced workspace in the NXcanSAS format. Currently
19+
* only MatrixWorkspaces resulting from
20+
* 1D and 2D reductions are supported.
21+
*/
22+
class MANTID_DATAHANDLING_DLL SaveNXcanSASBase : public API::Algorithm {
23+
protected:
24+
void saveSingleWorkspaceFile(const API::MatrixWorkspace_sptr &workspace, const std::filesystem::path &path);
25+
void addStandardMetadata(const Mantid::API::MatrixWorkspace_sptr &workspace, H5::Group &sasEntry);
26+
void addData(H5::Group &group, const Mantid::API::MatrixWorkspace_sptr &workspace);
27+
H5::Group addSasEntry(H5::H5File &file, const Mantid::API::MatrixWorkspace_sptr &workspace,
28+
const std::string &suffix);
29+
void initStandardProperties();
30+
std::map<std::string, std::string> validateStandardInputs();
31+
32+
std::unique_ptr<API::Progress> m_progress = nullptr;
33+
};
34+
35+
} // namespace DataHandling
36+
} // namespace Mantid

0 commit comments

Comments
 (0)