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
39using EventVector_pt = std::vector<Types::Event::TofEvent> *;
40
43private:
44 // fields
45 const std::string m_msg;
46 size_t m_count;
47 int64_t m_step;
48 int64_t m_next;
49 // matntid
51
52public:
53 // construction
54 ProgressTracker(API::Progress &progBar, const char *msg, int64_t target, size_t count);
56
57 // methods
58 void update(int64_t position);
59 void complete();
60 void setTarget(int64_t target);
61};
62
64protected:
65 // fields
66 const std::vector<bool> &m_roi;
67 const size_t m_stride;
68 // number of frames
69 size_t m_frames;
71 int64_t m_startTime;
72 // tof correction
73 const double m_period;
74 const double m_phase;
75 // boundaries
76 const double m_tofMinBoundary;
77 const double m_tofMaxBoundary;
78 const double m_timeMinBoundary;
79 const double m_timeMaxBoundary;
80
81 // methods
82 bool validFrame() const;
83 virtual void addEventImpl(size_t id, int64_t pulse, double tof) = 0;
84
85public:
86 // construction
87 EventProcessor(const std::vector<bool> &roi, size_t stride, const double period, const double phase,
88 const int64_t startTime, const double tofMinBoundary, const double tofMaxBoundary,
89 const double timeMinBoundary, const double timeMaxBoundary);
90
91 // methods
92 void newFrame();
93 void addEvent(size_t x, size_t y, double tof);
94};
95
97protected:
98 // fields
99 std::vector<size_t> &m_eventCounts;
100 // tof
101 double m_tofMin;
102 double m_tofMax;
103
104 // methods
105 void addEventImpl(size_t id, int64_t pulse, double tof) override;
106
107public:
108 // construction
109 EventCounter(const std::vector<bool> &roi, const size_t stride, const double period, const double phase,
110 const int64_t startTime, const double tofMinBoundary, const double tofMaxBoundary,
111 const double timeMinBoundary, const double timeMaxBoundary, std::vector<size_t> &eventCounts);
112
113 // properties
114 size_t numFrames() const;
115 double tofMin() const;
116 double tofMax() const;
117};
118
120protected:
121 // fields
122 std::vector<EventVector_pt> &m_eventVectors;
123
124 // methods
125 void addEventImpl(size_t id, int64_t pulse, double tof) override;
126
127public:
128 // construction
129 EventAssigner(const std::vector<bool> &roi, const size_t stride, const double period, const double phase,
130 int64_t startTime, const double tofMinBoundary, const double tofMaxBoundary,
131 const double timeMinBoundary, const double timeMaxBoundary, std::vector<EventVector_pt> &eventVectors);
132};
133
135protected:
136 // fields
138
139 // methods
140 void addEventImpl(size_t id, int64_t pulse, double tof) override;
141
142public:
143 // construction
144 EventAssignerFixedWavelength(const std::vector<bool> &roi, const size_t stride, const double wavelength,
145 const double period, const double phase, const int64_t startTime,
146 const double tofMinBoundary, const double tofMaxBoundary, const double timeMinBoundary,
147 const double timeMaxBoundary, std::vector<EventVector_pt> &eventVectors);
148};
149
151private:
152#ifdef _WIN32
153 HANDLE m_handle;
154#else
155 FILE *m_handle;
156#endif
157public:
158 // construction
159 FastReadOnlyFile(const char *filename);
161
162 // Prevent copying of a file handle
165
166 // properties
167 void *handle() const;
168
169 // methods
170 void close();
171 bool read(void *buffer, uint32_t size);
172 bool seek(int64_t offset, int whence, int64_t *newPosition = nullptr);
173};
174
175namespace Tar {
176
178 char FileName[100];
179 char FileMode[8];
180 char OwnerUserID[8];
182 char FileSize[12]; // in bytes (octal base)
183 char LastModification[12]; // time in numeric Unix time format (octal)
184 char Checksum[8];
186 char LinkedFileName[100];
187 char UStar[8];
192 char FilenamePrefix[155];
193
194 // methods
195 void writeChecksum();
196 void writeFileSize(int64_t value);
197 int64_t readFileSize();
198};
199
200class File {
201
202 static const auto BUFFER_SIZE = 4096;
203
204 struct FileInfo {
205 int64_t Offset;
206 int64_t Size;
207 };
208
209private:
210 // fields
211 bool m_good;
213 std::vector<std::string> m_fileNames;
214 std::vector<FileInfo> m_fileInfos;
215 // selected file
216 size_t m_selected; // index
217 int64_t m_position;
218 int64_t m_size;
219 // buffer
223
224 // not supported
225 File(const File &) = delete;
226 File &operator=(const File &) = delete;
227
228public:
229 // construction
230 explicit File(const std::string &path);
231 void close();
232
233 // properties
234 bool good() const;
235 const std::vector<std::string> &files() const;
236 // from selected file
237 const std::string &selected_name() const;
238 int64_t selected_position() const;
239 int64_t selected_size() const;
240
241 // methods
242 bool select(const char *file);
243 bool skip(uint64_t offset);
244 size_t read(void *dst, size_t size);
245 int read_byte();
246
247 // helpers
248 static bool append(const std::string &path, const std::string &name, const void *buffer, size_t size);
249};
250
251} // namespace Tar
252
253namespace Anxs {
254// options to capture timeseries data
255enum class ScanLog { Start, End, Mean };
256
257std::string extractWorkspaceTitle(const std::string &nxsFile);
258
259int64_t epochRelDateTimeBase(int64_t epochInNanoSeconds);
260
261template <typename T> bool loadNXDataSet(const Nexus::NXEntry &entry, const std::string &path, T &value, int index);
262bool loadNXString(const Nexus::NXEntry &entry, const std::string &path, std::string &value);
263
264bool isTimedDataSet(const Nexus::NXEntry &entry, const std::string &path);
265std::pair<uint64_t, uint64_t> getTimeScanLimits(const Nexus::NXEntry &entry, int datasetIx);
266std::pair<uint64_t, uint64_t> getHMScanLimits(const Nexus::NXEntry &entry, int datasetIx);
267
268template <typename T>
269uint64_t extractTimedDataSet(const Nexus::NXEntry &entry, const std::string &path, uint64_t startTime, uint64_t endTime,
270 std::vector<uint64_t> &times, std::vector<T> &events, std::string &units);
271template <typename T>
272bool extractTimedDataSet(const Nexus::NXEntry &entry, const std::string &path, uint64_t startTime, uint64_t endTime,
273 ScanLog valueOption, uint64_t &eventTime, T &eventValue, std::string &units);
274
275void ReadEventData(ProgressTracker &prog, const Nexus::NXEntry &entry, EventProcessor *handler, uint64_t start_nsec,
276 uint64_t end_nsec, const std::string &neutron_path, int tube_resolution = 1024);
277
278} // namespace Anxs
279
280} // namespace ANSTO
281} // namespace DataHandling
282} // 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
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
virtual void addEventImpl(size_t id, int64_t pulse, double tof)=0
void addEvent(size_t x, size_t y, double tof)
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)
void ReadEventData(ProgressTracker &prog, const Nexus::NXEntry &entry, EventProcessor *handler, uint64_t start_nsec, uint64_t end_nsec, const std::string &neutron_path, int tube_resolution=1024)
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)
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 > 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.