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
10#include "MantidAPI/Run.h"
15#include "MantidHistogramData/HistogramX.h"
17#include "MantidTypes/Core/DateAndTime.h"
18#include "MantidTypes/SpectrumDefinition.h"
19
20#include <climits>
21#include <list>
22#include <memory>
23
24class ISISRAW;
25class ISISRAW2;
26
27namespace Poco {
28class Path;
29}
30
31namespace Mantid {
32namespace API {
33class SpectrumDetectorMapping;
34}
35
36namespace DataHandling {
40class MANTID_DATAHANDLING_DLL LoadRawHelper : public API::IFileLoader<Kernel::FileDescriptor> {
41public:
44 // Define destructor in .cpp as we have unique_ptr to forward declared
45 // ISISRAW2
48 const std::string name() const override { return "LoadRawHelper"; }
50 int version() const override { return 1; }
52 const std::string summary() const override { return "Helper class for LoadRaw algorithms."; }
54 FILE *openRawFile(const std::string &fileName);
56 void loadRunParameters(const API::MatrixWorkspace_sptr &localWorkspace, ISISRAW *const = nullptr) const;
57
59 int confidence(Kernel::FileDescriptor &descriptor) const override;
60
62 static std::list<std::string> searchForLogFiles(const Poco::Path &pathToRawFile);
64 static bool isExcludeMonitors(const std::string &monitorOption);
66 static bool isSeparateMonitors(const std::string &monitorOption);
68 static bool isIncludeMonitors(const std::string &monitorOption);
69
70 static void ProcessLoadMonitorOptions(bool &bincludeMonitors, bool &bseparateMonitors, bool &bexcludeMonitors,
71 API::Algorithm *const pAlgo);
73 static void createMonitorWorkspace(DataObjects::Workspace2D_sptr &monws_sptr,
74 const DataObjects::Workspace2D_sptr &normalws_sptr,
75 API::WorkspaceGroup_sptr &mongrp_sptr, const int64_t mwsSpecs,
76 const int64_t nwsSpecs, const int64_t numberOfPeriods, const int64_t lengthIn,
77 const std::string &title, API::Algorithm *const pAlg);
79 static API::WorkspaceGroup_sptr createGroupWorkspace();
80
83 int64_t nVectors = -1, int64_t xLengthIn = -1,
84 int64_t yLengthIn = -1);
85
87 static DataObjects::Workspace2D_sptr createWorkspace(int64_t nVectors, int64_t xlengthIn, int64_t ylengthIn,
88 const std::string &title);
89
91 static void setWorkspaceProperty(const std::string &propertyName, const std::string &title,
92 const API::WorkspaceGroup_sptr &grpws_sptr,
93 const DataObjects::Workspace2D_sptr &ws_sptr, int64_t numberOfPeriods,
94 [[maybe_unused]] bool bMonitor, API::Algorithm *const pAlg);
95
97 static void setWorkspaceProperty(const DataObjects::Workspace2D_sptr &ws_sptr,
98 const API::WorkspaceGroup_sptr &grpws_sptr, const int64_t period, bool bmonitors,
99 API::Algorithm *const pAlg);
100
102 static Types::Core::DateAndTime extractStartTime(ISISRAW &isisRaw);
103
105 static Types::Core::DateAndTime extractEndTime(ISISRAW &isisRaw);
106
107protected:
109 void init() override;
111 void readTitle(FILE *file, std::string &title);
113 void readworkspaceParameters(specnum_t &numberOfSpectra, int &numberOfPeriods, int64_t &lengthIn,
114 int64_t &noTimeRegimes);
115
117 void skipData(FILE *file, int hist);
118 void skipData(FILE *file, int64_t hist);
119
121 void ioRaw(FILE *file, bool from_file);
122
124 bool readData(FILE *file, int hist);
125 bool readData(FILE *file, int64_t hist);
126
127 // Constructs the time channel (X) vector(s)
128 std::vector<std::shared_ptr<HistogramData::HistogramX>> getTimeChannels(const int64_t &regimes,
129 const int64_t &lengthIn);
131 void runLoadInstrument(const std::string &fileName, const DataObjects::Workspace2D_sptr &, double, double);
133 void runLoadInstrumentFromRaw(const std::string &fileName, const DataObjects::Workspace2D_sptr &);
135 void runLoadMappingTable(const std::string &fileName, const DataObjects::Workspace2D_sptr &);
137 void runLoadLog(const std::string &fileName, const DataObjects::Workspace2D_sptr &, double, double);
138
140 void createPeriodLogs(int64_t period, const DataObjects::Workspace2D_sptr &local_workspace);
141
143 std::vector<specnum_t> getmonitorSpectrumList(const API::SpectrumDetectorMapping &mapping);
144
146 void setWorkspaceData(const DataObjects::Workspace2D_sptr &newWorkspace,
147 const std::vector<std::shared_ptr<HistogramData::HistogramX>> &timeChannelsVec, int64_t wsIndex,
148 specnum_t nspecNum, int64_t noTimeRegimes, int64_t lengthIn, int64_t binStart);
149
151 float getProtonCharge() const;
153 void setProtonCharge(API::Run &run);
155 void setRunNumber(API::Run &run);
156
158 int getNumberofTimeRegimes();
160 ISISRAW2 &isisRaw() const;
162 void reset();
163
165 void setOptionalProperties(const int &spec_min, const int &spec_max, const std::vector<int> &spec_list);
167 void checkOptionalProperties();
169 specnum_t calculateWorkspaceSize();
171 void calculateWorkspacesizes(const std::vector<specnum_t> &monitorSpecList, specnum_t &normalwsSpecs,
172 specnum_t &monitorwsSpecs);
174 void loadSpectra(FILE *file, const int &period, const int &total_specs, const DataObjects::Workspace2D_sptr &ws_sptr,
175 const std::vector<std::shared_ptr<HistogramData::HistogramX>> &);
176
178 bool m_list;
182 std::vector<specnum_t> m_spec_list;
189
190private:
192 void exec() override;
194 static std::string convertMonthLabelToIntStr(std::string month);
195
197 mutable std::unique_ptr<ISISRAW2> m_isis_raw;
199 std::vector<std::string> m_cache_options;
201 std::map<specnum_t, specnum_t> m_specTimeRegimes;
203 double m_prog;
204
207
209 std::vector<specnum_t> m_monitordetectorList;
210
213
216
218 std::unique_ptr<ISISRunLogs> m_logCreator;
219
221 std::string extractLogName(const std::string &path);
222};
223
224} // namespace DataHandling
225} // namespace Mantid
isis raw file.
Definition: isisraw2.h:13
isis raw file.
Definition: isisraw.h:272
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:85
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:38
A minimal class to hold the mapping between the spectrum number and its related detector ID numbers f...
Helper class for LoadRaw algorithms.
Definition: LoadRawHelper.h:40
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.
Definition: LoadRawHelper.h:48
specnum_t m_total_specs
the total nuumber of spectra
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.
Definition: LoadRawHelper.h:50
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.
std::unique_ptr< ISISRunLogs > m_logCreator
A ptr to the log creator.
specnum_t m_spec_min
The value of the spectrum_min property.
specnum_t m_numberOfSpectra
number of spectra
bool m_list
Has the spectrum_list property been set?
const std::string summary() const override
Summary of algorithms purpose.
Definition: LoadRawHelper.h:52
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:16
Definition: Algorithm.h:30