Skip to content

Commit

Permalink
Merge pull request #38582 from mantidproject/refactor_Save_NXcanSAS
Browse files Browse the repository at this point in the history
Refactor SaveNXcanSAS algorithm to support different variants
  • Loading branch information
SilkeSchomann authored Jan 13, 2025
2 parents 6ee0b15 + f5cc1c8 commit 61bf054
Show file tree
Hide file tree
Showing 8 changed files with 1,013 additions and 894 deletions.
4 changes: 4 additions & 0 deletions Framework/DataHandling/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ set(SRC_FILES
src/ModifyDetectorDotDatFile.cpp
src/MoveInstrumentComponent.cpp
src/MultiPeriodLoadMuonStrategy.cpp
src/NXcanSASHelper.cpp
src/NexusTester.cpp
src/ORNLDataArchive.cpp
src/PDLoadCharacterizations.cpp
Expand Down Expand Up @@ -184,6 +185,7 @@ set(SRC_FILES
src/SaveNXSPE.cpp
src/SaveNXTomo.cpp
src/SaveNXcanSAS.cpp
src/SaveNXcanSASBase.cpp
src/SaveNexus.cpp
src/SaveNexusESS.cpp
src/SaveNexusGeometry.cpp
Expand Down Expand Up @@ -359,6 +361,7 @@ set(INC_FILES
inc/MantidDataHandling/MoveInstrumentComponent.h
inc/MantidDataHandling/MultiPeriodLoadMuonStrategy.h
inc/MantidDataHandling/NXcanSASDefinitions.h
inc/MantidDataHandling/NXcanSASHelper.h
inc/MantidDataHandling/NexusTester.h
inc/MantidDataHandling/ORNLDataArchive.h
inc/MantidDataHandling/PDLoadCharacterizations.h
Expand Down Expand Up @@ -401,6 +404,7 @@ set(INC_FILES
inc/MantidDataHandling/SaveNXSPE.h
inc/MantidDataHandling/SaveNXTomo.h
inc/MantidDataHandling/SaveNXcanSAS.h
inc/MantidDataHandling/SaveNXcanSASBase.h
inc/MantidDataHandling/SaveNexus.h
inc/MantidDataHandling/SaveNexusESS.h
inc/MantidDataHandling/SaveNexusGeometry.h
Expand Down
46 changes: 46 additions & 0 deletions Framework/DataHandling/inc/MantidDataHandling/NXcanSASHelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2025 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#pragma once

#include "MantidAPI/Algorithm.h"
#include "MantidAPI/MatrixWorkspace_fwd.h"
#include "MantidDataHandling/DllConfig.h"
#include <H5Cpp.h>

namespace Mantid {
namespace DataHandling {
namespace NXcanSAS {
// Helper functions for algorithms saving in NXcanSAS format.
enum class WorkspaceDimensionality;

std::string MANTID_DATAHANDLING_DLL makeCanSASRelaxedName(const std::string &input);

void MANTID_DATAHANDLING_DLL addDetectors(H5::Group &group, const Mantid::API::MatrixWorkspace_sptr &workspace,
const std::vector<std::string> &detectorNames);
void MANTID_DATAHANDLING_DLL addInstrument(H5::Group &group, const Mantid::API::MatrixWorkspace_sptr &workspace,
const std::string &radiationSource, const std::string &geometry,
double beamHeight, double beamWidth,
const std::vector<std::string> &detectorNames);
void MANTID_DATAHANDLING_DLL addSample(H5::Group &group, const double &sampleThickness);
void MANTID_DATAHANDLING_DLL addProcess(H5::Group &group, const Mantid::API::MatrixWorkspace_sptr &workspace);
void MANTID_DATAHANDLING_DLL addProcess(H5::Group &group, const Mantid::API::MatrixWorkspace_sptr &workspace,
const Mantid::API::MatrixWorkspace_sptr &canWorkspace);
void MANTID_DATAHANDLING_DLL addProcessEntry(H5::Group &group, const std::string &entryName,
const std::string &entryValue);
void MANTID_DATAHANDLING_DLL addTransmission(H5::Group &group, const Mantid::API::MatrixWorkspace_const_sptr &workspace,
const std::string &transmissionName);

void MANTID_DATAHANDLING_DLL addData1D(H5::Group &data, const Mantid::API::MatrixWorkspace_sptr &workspace);
void MANTID_DATAHANDLING_DLL addData2D(H5::Group &data, const Mantid::API::MatrixWorkspace_sptr &workspace);

WorkspaceDimensionality MANTID_DATAHANDLING_DLL
getWorkspaceDimensionality(const Mantid::API::MatrixWorkspace_sptr &workspace);
std::vector<std::string> MANTID_DATAHANDLING_DLL splitDetectorNames(std::string detectorNames);

} // namespace NXcanSAS
} // namespace DataHandling
} // namespace Mantid
6 changes: 2 additions & 4 deletions Framework/DataHandling/inc/MantidDataHandling/SaveNXcanSAS.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
// SPDX - License - Identifier: GPL - 3.0 +
#pragma once

#include "MantidAPI/Algorithm.h"
#include "MantidDataHandling/DllConfig.h"
#include "MantidDataHandling/SaveNXcanSASBase.h"

namespace Mantid {
namespace DataHandling {

/** SaveNXcanSAS : Saves a reduced workspace in the NXcanSAS format. Currently
* only MatrixWorkspaces resulting from 1D and 2D reductions are supported.
*/
class MANTID_DATAHANDLING_DLL SaveNXcanSAS final : public API::Algorithm {
class MANTID_DATAHANDLING_DLL SaveNXcanSAS final : public SaveNXcanSASBase {
public:
/// Constructor
SaveNXcanSAS();
Expand All @@ -42,7 +42,5 @@ class MANTID_DATAHANDLING_DLL SaveNXcanSAS final : public API::Algorithm {
void exec() override;
};

std::string MANTID_DATAHANDLING_DLL makeCanSASRelaxedName(const std::string &input);

} // namespace DataHandling
} // namespace Mantid
32 changes: 32 additions & 0 deletions Framework/DataHandling/inc/MantidDataHandling/SaveNXcanSASBase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright &copy; 2025 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#pragma once

#include "MantidAPI/Algorithm.h"
#include "MantidAPI/MatrixWorkspace_fwd.h"
#include "MantidDataHandling/DllConfig.h"
#include <H5Cpp.h>

namespace Mantid {
namespace DataHandling {

/** SaveNXcanSASBase : Base class to save a reduced workspace in the NXcanSAS format. Currently
* only MatrixWorkspaces resulting from
* 1D and 2D reductions are supported.
*/
class MANTID_DATAHANDLING_DLL SaveNXcanSASBase : public API::Algorithm {
protected:
void addStandardMetadata(const Mantid::API::MatrixWorkspace_sptr &workspace, H5::Group &sasEntry);
void addData(H5::Group &group, const Mantid::API::MatrixWorkspace_sptr &workspace);
H5::Group addSasEntry(H5::H5File &file, const Mantid::API::MatrixWorkspace_sptr &workspace,
const std::string &suffix);
void initStandardProperties();
std::map<std::string, std::string> validateStandardInputs();
};

} // namespace DataHandling
} // namespace Mantid
Loading

0 comments on commit 61bf054

Please sign in to comment.