/
LoadNexusProcessed.h
209 lines (170 loc) · 9.7 KB
/
LoadNexusProcessed.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2007 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
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/IFileLoader.h"
#include "MantidAPI/ITableWorkspace_fwd.h"
#include "MantidAPI/MatrixWorkspace_fwd.h"
#include "MantidHistogramData/BinEdges.h"
#include "MantidKernel/NexusDescriptor.h"
#include "MantidKernel/cow_ptr.h"
#include "MantidNexus/NexusClasses.h"
#include <map>
#include <vector>
namespace NeXus {
class File;
}
namespace Mantid {
namespace DataHandling {
/**
Loads a workspace from a NeXus Processed entry in a NeXus file.
LoadNexusProcessed is an algorithm and as such inherits
from the Algorithm class, via DataHandlingCommand, and overrides
the init() & exec() methods.
Required Properties:
<UL>
<LI> Filename - The name of the input NeXus file (must exist) </LI>
<LI> InputWorkspace - The name of the workspace to put the data </LI>
</UL>
*/
class DLLExport LoadNexusProcessed : public API::IFileLoader<Kernel::NexusDescriptor> {
public:
/// Default constructor
LoadNexusProcessed();
/// Destructor
~LoadNexusProcessed() override;
/// Algorithm's name for identification overriding a virtual method
const std::string name() const override { return "LoadNexusProcessed"; }
/// Summary of algorithms purpose
const std::string summary() const override {
return "The LoadNexusProcessed algorithm will read the given Nexus "
"Processed data file containing a Mantid Workspace. The data is "
"placed in the named workspace. LoadNexusProcessed may be invoked "
"by LoadNexus if it is given a Nexus file of this type.";
}
/// Algorithm's version for identification overriding a virtual method
int version() const override { return 1; };
const std::vector<std::string> seeAlso() const override { return {"LoadNexus"}; }
/// Algorithm's category for identification overriding a virtual method
const std::string category() const override { return "DataHandling\\Nexus"; }
/// Returns a confidence value that this algorithm can load a file
int confidence(Kernel::NexusDescriptor &descriptor) const override;
protected:
/// Read the spectra
void readInstrumentGroup(Mantid::NeXus::NXEntry &mtd_entry, API::MatrixWorkspace &local_workspace);
private:
virtual void readSpectraToDetectorMapping(Mantid::NeXus::NXEntry &mtd_entry, Mantid::API::MatrixWorkspace &ws);
/// Validates the input Min < Max and Max < Maximum_Int
std::map<std::string, std::string> validateInputs() override;
/// Overwrites Algorithm method.
void init() override;
/// Overwrites Algorithm method
void exec() override;
/// Create the workspace name if it's part of a group workspace
std::string buildWorkspaceName(const std::string &name, const std::string &baseName, size_t wsIndex);
/// Add an index to the name if it already exists in the workspace
void correctForWorkspaceNameClash(std::string &wsName);
/// Extract the workspace name
std::vector<std::string> extractWorkspaceNames(Mantid::NeXus::NXRoot &root, size_t nWorkspaceEntries);
/// Load the workspace name attribute if it exists
std::string loadWorkspaceName(Mantid::NeXus::NXRoot &root, const std::string &entry_name);
/// Load nexus geometry and apply to workspace
virtual bool loadNexusGeometry(Mantid::API::Workspace &, const int, Kernel::Logger &,
const std::string &) { /*do nothing*/
return false;
}
/// Load a single entry
API::Workspace_sptr loadEntry(Mantid::NeXus::NXRoot &root, const std::string &entry_name, const double &progressStart,
const double &progressRange);
API::Workspace_sptr loadTableEntry(Mantid::NeXus::NXEntry &entry);
/// Load a numeric column to the TableWorkspace.
template <typename ColumnType, typename NexusType>
void loadNumericColumn(const Mantid::NeXus::NXData &tableData, const std::string &dataSetName,
const API::ITableWorkspace_sptr &tableWs, const std::string &columnType);
/// Loads a vector column to the TableWorkspace.
template <typename Type>
void loadVectorColumn(const Mantid::NeXus::NXData &tableData, const std::string &dataSetName,
const API::ITableWorkspace_sptr &tableWs, const std::string &columnType);
/// Loads a V3D column to the TableWorkspace.
void loadV3DColumn(Mantid::NeXus::NXDouble &data, const API::ITableWorkspace_sptr &tableWs);
API::Workspace_sptr loadPeaksEntry(Mantid::NeXus::NXEntry &entry);
API::Workspace_sptr loadLeanElasticPeaksEntry(Mantid::NeXus::NXEntry &entry);
API::MatrixWorkspace_sptr loadEventEntry(Mantid::NeXus::NXData &wksp_cls, Mantid::NeXus::NXDouble &xbins,
const double &progressStart, const double &progressRange);
API::MatrixWorkspace_sptr loadNonEventEntry(Mantid::NeXus::NXData &wksp_cls, Mantid::NeXus::NXDouble &xbins,
const double &progressStart, const double &progressRange,
const Mantid::NeXus::NXEntry &mtd_entry, const int xlength,
std::string &workspaceType);
/// Read the data from the sample group
void readSampleGroup(Mantid::NeXus::NXEntry &mtd_entry, API::MatrixWorkspace_sptr local_workspace);
/// Add a property to the sample object
bool addSampleProperty(Mantid::NeXus::NXMainClass &sample_entry, const std::string &entryName,
API::Sample &sampleDetails);
/// Splits a string of exactly three words into the separate words
void getWordsInString(const std::string &words3, std::string &w1, std::string &w2, std::string &w3);
/// Splits a string of exactly four words into the separate words
void getWordsInString(const std::string &words4, std::string &w1, std::string &w2, std::string &w3, std::string &w4);
/// Read the bin masking information
void readBinMasking(Mantid::NeXus::NXData &wksp_cls, const API::MatrixWorkspace_sptr &local_workspace);
/// Load a block of data into the workspace where it is assumed that the x
/// bins have already been cached
void loadBlock(Mantid::NeXus::NXDataSetTyped<double> &data, Mantid::NeXus::NXDataSetTyped<double> &errors,
Mantid::NeXus::NXDataSetTyped<double> &farea, bool hasFArea, Mantid::NeXus::NXDouble &xErrors,
bool hasXErrors, int blocksize, int nchannels, int &hist,
const API::MatrixWorkspace_sptr &local_workspace);
/// Load a block of data into the workspace where it is assumed that the x
/// bins have already been cached
void loadBlock(Mantid::NeXus::NXDataSetTyped<double> &data, Mantid::NeXus::NXDataSetTyped<double> &errors,
Mantid::NeXus::NXDataSetTyped<double> &farea, bool hasFArea, Mantid::NeXus::NXDouble &xErrors,
bool hasXErrors, int blocksize, int nchannels, int &hist, int &wsIndex,
const API::MatrixWorkspace_sptr &local_workspace);
/// Load a block of data into the workspace
void loadBlock(Mantid::NeXus::NXDataSetTyped<double> &data, Mantid::NeXus::NXDataSetTyped<double> &errors,
Mantid::NeXus::NXDataSetTyped<double> &farea, bool hasFArea, Mantid::NeXus::NXDouble &xErrors,
bool hasXErrors, Mantid::NeXus::NXDouble &xbins, int blocksize, int nchannels, int &hist, int &wsIndex,
const API::MatrixWorkspace_sptr &local_workspace);
/// Load the data from a non-spectra axis (Numeric/Text) into the workspace
void loadNonSpectraAxis(const API::MatrixWorkspace_sptr &local_workspace, Mantid::NeXus::NXData &data);
/// Validates the optional 'spectra to read' properties, if they have been set
void checkOptionalProperties(const std::size_t numberofspectra);
/// calculates the workspace size
std::size_t calculateWorkspaceSize(const std::size_t numberofspectra, bool gen_filtered_list = false);
/// Accellerated multiperiod loading
Mantid::API::Workspace_sptr doAccelleratedMultiPeriodLoading(Mantid::NeXus::NXRoot &root,
const std::string &entryName,
Mantid::API::MatrixWorkspace_sptr &tempMatrixWorkspace,
const size_t nWorkspaceEntries, const size_t p);
/// applies log filtering of the loaded logs if required
void applyLogFiltering(const Mantid::API::Workspace_sptr &local_workspace);
/// Does the current workspace have uniform binning
bool m_shared_bins;
/// The cached x binning if we have bins
HistogramData::BinEdges m_xbins;
/// Numeric values for the second axis, if applicable
MantidVec m_axis1vals;
/// Flag set if list of spectra to save is specifed
bool m_list;
/// Flag set if interval of spectra to write is set
bool m_interval;
/// The value of the spectrum_min property
int m_spec_min;
/// The value of the spectrum_max property
int m_spec_max;
/// The value of the spectrum_list property
std::vector<int> m_spec_list;
/// list of spectra filtered by min/max/list, currently
/// used only when loading data into event_workspace
std::vector<int> m_filtered_spec_idxs;
// Handle to the NeXus file
std::unique_ptr<::NeXus::File> m_nexusFile;
};
/// to sort the algorithmhistory vector
bool UDlesserExecCount(const Mantid::NeXus::NXClassInfo &elem1, const Mantid::NeXus::NXClassInfo &elem2);
} // namespace DataHandling
} // namespace Mantid