Mantid
Loading...
Searching...
No Matches
LoadANSTOHelper.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
9//---------------------------------------------------
10// Includes
11//---------------------------------------------------
12
18#include <algorithm>
19#include <regex>
20
21#define TarTypeFlag_NormalFile '0'
22#define TarTypeFlag_HardLink '1'
23#define TarTypeFlag_SymbolicLink '2'
24#define TarTypeFlag_CharacterSpecial '3'
25#define TarTypeFlag_BlockSpecial '4'
26#define TarTypeFlag_Directory '5'
27#define TarTypeFlag_FIFO '6'
28#define TarTypeFlag_ContiguousFile '7'
29
30namespace Mantid {
31namespace DataHandling {
32namespace ANSTO {
33
35std::vector<std::string> filterDatasets(const Nexus::NXEntry &entry, const std::string &groupAddress,
36 const std::string &regexFilter);
37
39std::vector<std::string> filterGroups(const Nexus::NXEntry &entry, const std::string &groupAddress,
40 const std::string &regexFilter);
41
43using EventVector_pt = std::vector<Types::Event::TofEvent> *;
44
47private:
48 // fields
49 const std::string m_msg;
50 size_t m_count;
51 int64_t m_step;
52 int64_t m_next;
53 // matntid
55
56public:
57 // construction
58 ProgressTracker(API::Progress &progBar, const char *msg, int64_t target, size_t count);
60
61 // methods
62 void update(int64_t position);
63 void complete();
64 void setTarget(int64_t target);
65};
66
69public:
70 virtual ~BaseEventProcessor() = default;
71 virtual void newFrame() = 0;
72 virtual void addEvent(size_t x, size_t y, double tof) = 0;
73};
74
76protected:
77 // fields
78 const std::vector<bool> &m_roi;
79 const size_t m_stride;
80 // number of frames
81 size_t m_frames;
83 int64_t m_startTime;
84 // tof correction
85 const double m_period;
86 const double m_phase;
87 // boundaries
88 const double m_tofMinBoundary;
89 const double m_tofMaxBoundary;
90 const double m_timeMinBoundary;
91 const double m_timeMaxBoundary;
92
93 // methods
94 bool validFrame() const;
95 virtual void addEventImpl(size_t id, int64_t pulse, double tof) = 0;
96
97public:
98 // construction
99 EventProcessor(const std::vector<bool> &roi, size_t stride, const double period, const double phase,
100 const int64_t startTime, const double tofMinBoundary, const double tofMaxBoundary,
101 const double timeMinBoundary, const double timeMaxBoundary);
102
103 // methods
104 void newFrame() override;
105 void addEvent(size_t x, size_t y, double tof) override;
106};
107
109protected:
110 // fields
111 std::vector<size_t> &m_eventCounts;
112 // tof
113 double m_tofMin;
114 double m_tofMax;
115
116 // methods
117 void addEventImpl(size_t id, int64_t pulse, double tof) override;
118
119public:
120 // construction
121 EventCounter(const std::vector<bool> &roi, const size_t stride, const double period, const double phase,
122 const int64_t startTime, const double tofMinBoundary, const double tofMaxBoundary,
123 const double timeMinBoundary, const double timeMaxBoundary, std::vector<size_t> &eventCounts);
124
125 // properties
126 size_t numFrames() const;
127 double tofMin() const;
128 double tofMax() const;
129};
130
132protected:
133 // fields
134 std::vector<EventVector_pt> &m_eventVectors;
135
136 // methods
137 void addEventImpl(size_t id, int64_t pulse, double tof) override;
138
139public:
140 // construction
141 EventAssigner(const std::vector<bool> &roi, const size_t stride, const double period, const double phase,
142 int64_t startTime, const double tofMinBoundary, const double tofMaxBoundary,
143 const double timeMinBoundary, const double timeMaxBoundary, std::vector<EventVector_pt> &eventVectors);
144};
145
147protected:
148 // fields
150
151 // methods
152 void addEventImpl(size_t id, int64_t pulse, double tof) override;
153
154public:
155 // construction
156 EventAssignerFixedWavelength(const std::vector<bool> &roi, const size_t stride, const double wavelength,
157 const double period, const double phase, const int64_t startTime,
158 const double tofMinBoundary, const double tofMaxBoundary, const double timeMinBoundary,
159 const double timeMaxBoundary, std::vector<EventVector_pt> &eventVectors);
160};
161
163private:
164#ifdef _WIN32
165 HANDLE m_handle;
166#else
167 FILE *m_handle;
168#endif
169public:
170 // construction
171 FastReadOnlyFile(const char *filename);
173
174 // Prevent copying of a file handle
177
178 // properties
179 void *handle() const;
180
181 // methods
182 void close();
183 bool read(void *buffer, uint32_t size);
184 bool seek(int64_t offset, int whence, int64_t *newPosition = nullptr);
185};
186
187namespace Tar {
188
190 char FileName[100];
191 char FileMode[8];
192 char OwnerUserID[8];
194 char FileSize[12]; // in bytes (octal base)
195 char LastModification[12]; // time in numeric Unix time format (octal)
196 char Checksum[8];
198 char LinkedFileName[100];
199 char UStar[8];
204 char FilenamePrefix[155];
205
206 // methods
207 void writeChecksum();
208 void writeFileSize(int64_t value);
209 int64_t readFileSize();
210};
211
212class File {
213
214 static const auto BUFFER_SIZE = 4096;
215
216 struct FileInfo {
217 int64_t Offset;
218 int64_t Size;
219 };
220
221private:
222 // fields
223 bool m_good;
225 std::vector<std::string> m_fileNames;
226 std::vector<FileInfo> m_fileInfos;
227 // selected file
228 size_t m_selected; // index
229 int64_t m_position;
230 int64_t m_size;
231 // buffer
235
236 // not supported
237 File(const File &) = delete;
238 File &operator=(const File &) = delete;
239
240public:
241 // construction
242 explicit File(const std::string &path);
243 void close();
244
245 // properties
246 bool good() const;
247 const std::vector<std::string> &files() const;
248 // from selected file
249 const std::string &selected_name() const;
250 int64_t selected_position() const;
251 int64_t selected_size() const;
252
253 // methods
254 bool select(const char *file);
255 bool skip(uint64_t offset);
256 size_t read(void *dst, size_t size);
257 int read_byte();
258
259 // helpers
260 static bool append(const std::string &path, const std::string &name, const void *buffer, size_t size);
261};
262
263} // namespace Tar
264
265namespace Anxs {
266// options to capture timeseries data
267enum class ScanLog { Start, End, Mean };
268
269std::string extractWorkspaceTitle(const std::string &nxsFile);
270
271int64_t epochRelDateTimeBase(int64_t epochInNanoSeconds);
272
273template <typename T> bool loadNXDataSet(const Nexus::NXEntry &entry, const std::string &path, T &value, int index);
274bool loadNXString(const Nexus::NXEntry &entry, const std::string &path, std::string &value);
275
276bool isTimedDataSet(const Nexus::NXEntry &entry, const std::string &path);
277std::pair<uint64_t, uint64_t> getTimeScanLimits(const Nexus::NXEntry &entry, int datasetIx);
278std::pair<uint64_t, uint64_t> getHMScanLimits(const Nexus::NXEntry &entry, int datasetIx);
279
280template <typename T>
281uint64_t extractTimedDataSet(const Nexus::NXEntry &entry, const std::string &path, uint64_t startTime, uint64_t endTime,
282 std::vector<uint64_t> &times, std::vector<T> &events, std::string &units);
283template <typename T>
284bool extractTimedDataSet(const Nexus::NXEntry &entry, const std::string &path, uint64_t startTime, uint64_t endTime,
285 ScanLog valueOption, uint64_t &eventTime, T &eventValue, std::string &units);
286
287void ReadEventData(ProgressTracker &prog, const Nexus::NXEntry &entry, BaseEventProcessor *handler, uint64_t start_nsec,
288 uint64_t end_nsec, const std::string &neutron_path, int tube_resolution = 1024);
289
290} // namespace Anxs
291
292} // namespace ANSTO
293} // namespace DataHandling
294} // namespace Mantid
std::string name
Definition Run.cpp:60
double value
The value of the point.
Definition FitMW.cpp:51
double position
Definition GetAllEi.cpp:154
std::map< DeltaEMode::Type, std::string > index
int count
counter
Definition Matrix.cpp:37
Helper class for reporting progress from algorithms.
Definition Progress.h:25
abstract base class for processing events as they are read from the file
virtual void addEvent(size_t x, size_t y, double tof)=0
void addEventImpl(size_t id, int64_t pulse, double tof) override
void addEventImpl(size_t id, int64_t pulse, double tof) override
std::vector< EventVector_pt > & m_eventVectors
void addEventImpl(size_t id, int64_t pulse, double tof) override
void addEvent(size_t x, size_t y, double tof) override
virtual void addEventImpl(size_t id, int64_t pulse, double tof)=0
bool seek(int64_t offset, int whence, int64_t *newPosition=nullptr)
FastReadOnlyFile & operator=(FastReadOnlyFile)=delete
FastReadOnlyFile(const FastReadOnlyFile &)=delete
helper class to keep track of progress
std::vector< std::string > m_fileNames
const std::string & selected_name() const
size_t read(void *dst, size_t size)
const std::vector< std::string > & files() const
static bool append(const std::string &path, const std::string &name, const void *buffer, size_t size)
File & operator=(const File &)=delete
Implements NXentry Nexus class.
bool isTimedDataSet(const Nexus::NXEntry &entry, const std::string &path)
std::string extractWorkspaceTitle(const std::string &nxsFile)
bool loadNXString(const Nexus::NXEntry &entry, const std::string &path, std::string &value)
int64_t epochRelDateTimeBase(int64_t epochInNanoSeconds)
bool loadNXDataSet(const Nexus::NXEntry &entry, const std::string &path, T &value, int index)
std::pair< uint64_t, uint64_t > getHMScanLimits(const Nexus::NXEntry &entry, int datasetIx)
uint64_t extractTimedDataSet(const Nexus::NXEntry &entry, const std::string &path, uint64_t startTime, uint64_t endTime, std::vector< uint64_t > &times, std::vector< T > &events, std::string &units)
void ReadEventData(ProgressTracker &prog, const Nexus::NXEntry &entry, BaseEventProcessor *handler, uint64_t start_nsec, uint64_t end_nsec, const std::string &neutron_path, int tube_resolution=1024)
std::pair< uint64_t, uint64_t > getTimeScanLimits(const Nexus::NXEntry &entry, int datasetIx)
std::vector< Types::Event::TofEvent > * EventVector_pt
pointer to the vector of events
std::vector< std::string > filterGroups(const Nexus::NXEntry &entry, const std::string &groupAddress, const std::string &regexFilter)
extract groups from a group that match a regex filter
std::vector< std::string > filterDatasets(const Nexus::NXEntry &entry, const std::string &groupAddress, const std::string &regexFilter)
extract datasets from a group that match a regex filter
Helper class which provides the Collimation Length for SANS instruments.