Mantid
Loading...
Searching...
No Matches
LoadSQW.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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
10#include "MantidAPI/Progress.h"
14#include "MantidMDAlgorithms/DllConfig.h"
15#include <fstream>
16#include <string>
17
18namespace Mantid {
19namespace MDAlgorithms {
20
28/*==================================================================================
29 Region: Declarations and Definitions in the following region are candidates
30 for refactoring. Copied from MD_FileHoraceReader
31 ==================================================================================*/
32namespace LoadSQWHelper {
33/*Helper type lifted from MD_FileHoraceReader,
34 The structure describes the positions of the different sqw data parts in the
35 total binary sqw data file
36 TODO. Replace.*/
38 std::streamoff if_sqw_start;
39 std::streamoff n_dims_start;
40 std::streamoff sqw_header_start;
41 std::vector<std::streamoff> component_headers_starts;
42 std::streamoff detectors_start;
43 std::streamoff data_start;
44 std::streamoff geom_start;
45 std::streamoff npax_start;
46 std::streamoff s_start;
47 std::streamoff err_start;
48 std::streamoff n_cell_pix_start; // where data.npix array starts
49 std::streamoff min_max_start; // data range positions (uRange -- this is the
50 // data which describe the extents of the
51 // MDPixesl (events))
52 std::streamoff pix_start; //< event data positions
53 size_t mdImageSize; //< the variable describes the size of Horace MD image
54 //(number of pixels in Horace DND object or number of bins
55 // in Mantid Histo workspace)
56
61 // the following values have to be identified from the file
62 // itself
64 mdImageSize(0){}; // the following values have to be identified from the
65 // file itself
66
67 // the helper methods
69 void parse_sqw_main_header(std::ifstream &dataStream); // Legacy - candidate for removal
71 std::streamoff parse_component_header(std::ifstream &dataStream,
72 std::streamoff start_location); // Legacy -candidate for removal
75 std::streamoff parse_sqw_detpar(std::ifstream &dataStream,
76 std::streamoff start_location); // Legacy - candidate for removal
78 void parse_data_locations(std::ifstream &dataStream, std::streamoff data_start, std::vector<size_t> &nBins,
79 uint64_t &nDataPoints); // Legacy - candidate for removal
80};
81} // namespace LoadSQWHelper
82
83class MANTID_MDALGORITHMS_DLL LoadSQW : public API::IFileLoader<Kernel::FileDescriptor> {
84public:
85 LoadSQW();
86 ~LoadSQW() override;
87
89 const std::string name() const override { return "LoadSQW"; };
91 const std::string summary() const override {
92 return "Create a MDEventWorkspace with events in reciprocal space (Qx, Qy, "
93 "Qz, Energy) from a SQW file.";
94 }
95
97 int version() const override { return 1; };
99 const std::string category() const override { return "DataHandling\\SQW;MDAlgorithms\\DataHandling"; }
100
102 int confidence(Kernel::FileDescriptor &descriptor) const override;
103
104private:
105 void init() override;
106 void exec() override;
107
108protected: // for testing
110 virtual void readEvents(Mantid::DataObjects::MDEventWorkspace<DataObjects::MDEvent<4>, 4> *ws);
111
113 void readDNDDimensions(std::vector<Mantid::Geometry::MDHistoDimensionBuilder> &DimVectorOut,
114 bool arrangeByMDImage = true);
116 void readSQWDimensions(std::vector<Mantid::Geometry::MDHistoDimensionBuilder> &DimVectorOut);
117
119 virtual void addLattice(Mantid::DataObjects::MDEventWorkspace<DataObjects::MDEvent<4>, 4> *ws);
120
122 void parseMetadata(const std::string &fileName); // New controlling function
123 // over legacy ones.
125 void buildMDDimsBase(std::vector<Mantid::Geometry::MDHistoDimensionBuilder> &DimVector);
128 std::vector<Mantid::Geometry::MDHistoDimensionBuilder> &DimVector);
129
131 void readBoxSizes();
132
134 std::string m_fileName;
136 std::ifstream m_fileStream;
137
140
142 std::string m_outputFile;
143
147 // the array of horace boxe sizes;
148 std::vector<uint64_t> m_boxSizes;
149
152 size_t m_nDims;
154 std::vector<size_t> m_nBins;
155
156 /*==================================================================================
157 End Region
158 ==================================================================================*/
159};
160
161} // namespace MDAlgorithms
162} // namespace Mantid
Defines an interface to an algorithm that loads a file so that it can take part in the automatic sele...
Definition: IFileLoader.h:19
Helper class for reporting progress from algorithms.
Definition: Progress.h:25
Templated class for the multi-dimensional event workspace.
Templated class holding data about a neutron detection event in N-dimensions (for example,...
Definition: MDEvent.h:36
Defines a wrapper around an open file.
std::ifstream m_fileStream
File stream containing binary file data.
Definition: LoadSQW.h:136
std::string m_outputFile
OutputFilename param.
Definition: LoadSQW.h:142
LoadSQWHelper::dataPositions m_dataPositions
Instance of helper type, which describes the positions of the data within binary Horace file.
Definition: LoadSQW.h:146
std::vector< uint64_t > m_boxSizes
Definition: LoadSQW.h:148
std::string m_fileName
the name of the file to work with
Definition: LoadSQW.h:134
std::vector< size_t > m_nBins
number of bins in every non-integrated dimension
Definition: LoadSQW.h:154
const std::string name() const override
Algorithm's name for identification.
Definition: LoadSQW.h:89
Mantid::API::Progress * m_prog
Progress bar.
Definition: LoadSQW.h:139
const std::string summary() const override
Summary of algorithms purpose.
Definition: LoadSQW.h:91
int version() const override
Algorithm's version for identification.
Definition: LoadSQW.h:97
const std::string category() const override
Algorithm's category for identification.
Definition: LoadSQW.h:99
Helper class which provides the Collimation Length for SANS instruments.
std::vector< std::streamoff > component_headers_starts
Definition: LoadSQW.h:41
std::streamoff parse_sqw_detpar(std::ifstream &dataStream, std::streamoff start_location)
Block 3: Detpar: parse positions of the contributed detectors.
Definition: LoadSQW.cpp:768
std::streamoff parse_component_header(std::ifstream &dataStream, std::streamoff start_location)
Block 2: Header: Parse header of single SPE file.
Definition: LoadSQW.cpp:715
void parse_sqw_main_header(std::ifstream &dataStream)
Block 1: Main_header: Parse SQW main data header.
Definition: LoadSQW.cpp:670
void parse_data_locations(std::ifstream &dataStream, std::streamoff data_start, std::vector< size_t > &nBins, uint64_t &nDataPoints)
Block 4: Data: parse positions of the data fields.
Definition: LoadSQW.cpp:800