Mantid
Loading...
Searching...
No Matches
LoadRawHelper.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 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
11#include "MantidAPI/Run.h"
13#include "MantidDataHandling/DllConfig.h"
16#include "MantidHistogramData/HistogramX.h"
18#include "MantidTypes/Core/DateAndTime.h"
19#include "MantidTypes/SpectrumDefinition.h"
20
21#include <climits>
22#include <filesystem>
23#include <list>
24#include <memory>
25
26class ISISRAW;
27class ISISRAW2;
28
29namespace Mantid {
30namespace API {
31class SpectrumDetectorMapping;
32}
33
34namespace DataHandling {
38class MANTID_DATAHANDLING_DLL LoadRawHelper : public API::IFileLoader<Kernel::FileDescriptor> {
39public:
42 // Define destructor in .cpp as we have unique_ptr to forward declared
43 // ISISRAW2
44 ~LoadRawHelper() override;
46 const std::string name() const override { return "LoadRawHelper"; }
48 int version() const override { return 1; }
50 const std::string summary() const override { return "Helper class for LoadRaw algorithms."; }
52 FILE *openRawFile(const std::string &fileName);
54 void loadRunParameters(const API::MatrixWorkspace_sptr &localWorkspace, ISISRAW *const = nullptr) const;
55
57 int confidence(Kernel::FileDescriptor &descriptor) const override;
58
60 static std::list<std::string> searchForLogFiles(const std::filesystem::path &pathToRawFile);
62 static bool isExcludeMonitors(const std::string &monitorOption);
64 static bool isSeparateMonitors(const std::string &monitorOption);
66 static bool isIncludeMonitors(const std::string &monitorOption);
67
68 static void ProcessLoadMonitorOptions(bool &bincludeMonitors, bool &bseparateMonitors, bool &bexcludeMonitors,
69 const API::Algorithm *pAlgo);
71 static void createMonitorWorkspace(DataObjects::Workspace2D_sptr &monws_sptr,
72 const DataObjects::Workspace2D_sptr &normalws_sptr,
73 API::WorkspaceGroup_sptr &mongrp_sptr, const int64_t mwsSpecs,
74 const int64_t nwsSpecs, const int64_t numberOfPeriods, const int64_t lengthIn,
75 const std::string &title, API::Algorithm *const pAlg);
77 static API::WorkspaceGroup_sptr createGroupWorkspace();
78
81 int64_t nVectors = -1, int64_t xLengthIn = -1,
82 int64_t yLengthIn = -1);
83
85 static DataObjects::Workspace2D_sptr createWorkspace(int64_t nVectors, int64_t xlengthIn, int64_t ylengthIn,
86 const std::string &title);
87
89 static void setWorkspaceProperty(const std::string &propertyName, const std::string &title,
90 const API::WorkspaceGroup_sptr &grpws_sptr,
91 const DataObjects::Workspace2D_sptr &ws_sptr, int64_t numberOfPeriods,
92 [[maybe_unused]] bool bMonitor, API::Algorithm *const pAlg);
93
95 static void setWorkspaceProperty(const DataObjects::Workspace2D_sptr &ws_sptr,
96 const API::WorkspaceGroup_sptr &grpws_sptr, const int64_t period, bool bmonitors,
97 API::Algorithm *const pAlg);
98
100 static Types::Core::DateAndTime extractStartTime(ISISRAW &isisRaw);
101
103 static Types::Core::DateAndTime extractEndTime(ISISRAW &isisRaw);
104
105protected:
107 void init() override;
109 void readTitle(FILE *file, std::string &title);
111 void readworkspaceParameters(specnum_t &numberOfSpectra, int &numberOfPeriods, int64_t &lengthIn,
112 int64_t &noTimeRegimes);
113
115 void skipData(FILE *file, int hist);
116 void skipData(FILE *file, int64_t hist);
117
119 void ioRaw(FILE *file, bool from_file);
120
122 bool readData(FILE *file, int hist);
123 bool readData(FILE *file, int64_t hist);
124
125 // Constructs the time channel (X) vector(s)
126 std::vector<std::shared_ptr<HistogramData::HistogramX>> getTimeChannels(const int64_t &regimes,
127 const int64_t &lengthIn);
129 void runLoadInstrument(const std::string &fileName, const DataObjects::Workspace2D_sptr &, double, double);
131 void runLoadInstrumentFromRaw(const std::string &fileName, const DataObjects::Workspace2D_sptr &);
133 void runLoadMappingTable(const std::string &fileName, const DataObjects::Workspace2D_sptr &);
135 void runLoadLog(const std::string &fileName, const DataObjects::Workspace2D_sptr &, double, double);
136
138 void createPeriodLogs(int64_t period, const DataObjects::Workspace2D_sptr &local_workspace);
139
141 std::vector<specnum_t> getmonitorSpectrumList(const API::SpectrumDetectorMapping &mapping);
142
144 void setWorkspaceData(const DataObjects::Workspace2D_sptr &newWorkspace,
145 const std::vector<std::shared_ptr<HistogramData::HistogramX>> &timeChannelsVec, int64_t wsIndex,
146 specnum_t nspecNum, int64_t noTimeRegimes, int64_t lengthIn, int64_t binStart);
147
149 float getProtonCharge() const;
151 void setProtonCharge(API::Run &run);
153 void setRunNumber(API::Run &run);
154
156 int getNumberofTimeRegimes();
158 ISISRAW2 &isisRaw() const;
160 void reset();
161
163 void setOptionalProperties(const int &spec_min, const int &spec_max, const std::vector<int> &spec_list);
165 void checkOptionalProperties();
167 specnum_t calculateWorkspaceSize();
169 void calculateWorkspacesizes(const std::vector<specnum_t> &monitorSpecList, specnum_t &normalwsSpecs,
170 specnum_t &monitorwsSpecs);
172 void loadSpectra(FILE *file, const int &period, const int &total_specs, const DataObjects::Workspace2D_sptr &ws_sptr,
173 const std::vector<std::shared_ptr<HistogramData::HistogramX>> &);
174
176 bool m_list;
180 std::vector<specnum_t> m_spec_list;
187
188private:
190 void exec() override;
192 static std::string convertMonthLabelToIntStr(std::string month);
193
195 mutable std::unique_ptr<ISISRAW2> m_isis_raw;
197 std::vector<std::string> m_cache_options;
199 std::map<specnum_t, specnum_t> m_specTimeRegimes;
201 double m_prog;
202
205
207 std::vector<specnum_t> m_monitordetectorList;
208
211
214
216 std::unique_ptr<API::ISISRunLogs> m_logCreator;
217
219 std::string extractLogName(const std::string &path);
220};
221
222} // namespace DataHandling
223} // namespace Mantid
isis raw file.
Definition isisraw2.h:13
isis raw file.
Definition isisraw.h:267
Base class from which all concrete algorithm classes should be derived.
Definition Algorithm.h:76
Defines an interface to an algorithm that loads a file so that it can take part in the automatic sele...
Definition IFileLoader.h:19
This class stores information regarding an experimental run as a series of log entries.
Definition Run.h:35
A minimal class to hold the mapping between the spectrum number and its related detector ID numbers f...
Helper class for LoadRaw algorithms.
bool m_interval
Have the spectrum_min/max properties been set?
const std::string name() const override
Algorithm's name for identification overriding a virtual method.
specnum_t m_total_specs
the total nuumber of spectra
std::unique_ptr< API::ISISRunLogs > m_logCreator
A ptr to the log creator.
std::map< specnum_t, specnum_t > m_specTimeRegimes
A map for storing the time regime for each spectrum.
int version() const override
Algorithm's version for identification overriding a virtual method.
specnum_t m_spec_max
The value of the spectrum_max property.
bool m_bmspeclist
boolean for list spectra options
double m_prog
The current value of the progress counter.
std::vector< specnum_t > m_spec_list
The value of the spectrum_list property.
std::vector< std::string > m_cache_options
Allowed values for the cache property.
std::unique_ptr< ISISRAW2 > m_isis_raw
ISISRAW class instance which does raw file reading.
specnum_t m_spec_min
The value of the spectrum_min property.
specnum_t m_numberOfSpectra
number of spectra
~LoadRawHelper() override
Destructor.
bool m_list
Has the spectrum_list property been set?
const std::string summary() const override
Summary of algorithms purpose.
int m_numberOfPeriods
The number of periods in the raw file.
std::vector< specnum_t > m_monitordetectorList
a vector holding the indexes of monitors
Defines a wrapper around an open file.
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
std::shared_ptr< T > createWorkspace(InitArgs... args)
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
Mantid::Types::Core::DateAndTime DLLExport extractEndTime(const std::string &filename)
Gets the start time from the nexus file.
Mantid::Types::Core::DateAndTime DLLExport extractStartTime(const std::string &filename)
Extracts the start and the end time from a Nexus file.
std::shared_ptr< Workspace2D > Workspace2D_sptr
shared pointer to Mantid::DataObjects::Workspace2D
Helper class which provides the Collimation Length for SANS instruments.
int32_t specnum_t
Typedef for a spectrum Number.
Definition IDTypes.h:14