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
17
18#define TarTypeFlag_NormalFile '0'
19#define TarTypeFlag_HardLink '1'
20#define TarTypeFlag_SymbolicLink '2'
21#define TarTypeFlag_CharacterSpecial '3'
22#define TarTypeFlag_BlockSpecial '4'
23#define TarTypeFlag_Directory '5'
24#define TarTypeFlag_FIFO '6'
25#define TarTypeFlag_ContiguousFile '7'
26
27namespace Mantid {
28namespace DataHandling {
29namespace ANSTO {
30
32using EventVector_pt = std::vector<Types::Event::TofEvent> *;
33
36private:
37 // fields
38 const std::string m_msg;
39 size_t m_count;
40 int64_t m_step;
41 int64_t m_next;
42 // matntid
44
45public:
46 // construction
47 ProgressTracker(API::Progress &progBar, const char *msg, int64_t target, size_t count);
49
50 // methods
51 void update(int64_t position);
52 void complete();
53};
54
56protected:
57 // fields
58 const std::vector<bool> &m_roi;
59 const size_t m_stride;
60 // number of frames
61 size_t m_frames;
63 int64_t m_startTime;
64 // tof correction
65 const double m_period;
66 const double m_phase;
67 // boundaries
68 const double m_tofMinBoundary;
69 const double m_tofMaxBoundary;
70 const double m_timeMinBoundary;
71 const double m_timeMaxBoundary;
72
73 // methods
74 bool validFrame() const;
75 virtual void addEventImpl(size_t id, int64_t pulse, double tof) = 0;
76
77public:
78 // construction
79 EventProcessor(const std::vector<bool> &roi, size_t stride, const double period, const double phase,
80 const int64_t startTime, const double tofMinBoundary, const double tofMaxBoundary,
81 const double timeMinBoundary, const double timeMaxBoundary);
82
83 // methods
84 void newFrame();
85 void addEvent(size_t x, size_t y, double tof);
86};
87
89protected:
90 // fields
91 std::vector<size_t> &m_eventCounts;
92 // tof
93 double m_tofMin;
94 double m_tofMax;
95
96 // methods
97 void addEventImpl(size_t id, int64_t pulse, double tof) override;
98
99public:
100 // construction
101 EventCounter(const std::vector<bool> &roi, const size_t stride, const double period, const double phase,
102 const int64_t startTime, const double tofMinBoundary, const double tofMaxBoundary,
103 const double timeMinBoundary, const double timeMaxBoundary, std::vector<size_t> &eventCounts);
104
105 // properties
106 size_t numFrames() const;
107 double tofMin() const;
108 double tofMax() const;
109};
110
112protected:
113 // fields
114 std::vector<EventVector_pt> &m_eventVectors;
115
116 // methods
117 void addEventImpl(size_t id, int64_t pulse, double tof) override;
118
119public:
120 // construction
121 EventAssigner(const std::vector<bool> &roi, const size_t stride, const double period, const double phase,
122 int64_t startTime, const double tofMinBoundary, const double tofMaxBoundary,
123 const double timeMinBoundary, const double timeMaxBoundary, std::vector<EventVector_pt> &eventVectors);
124};
125
127protected:
128 // fields
130
131 // methods
132 void addEventImpl(size_t id, int64_t pulse, double tof) override;
133
134public:
135 // construction
136 EventAssignerFixedWavelength(const std::vector<bool> &roi, const size_t stride, const double wavelength,
137 const double period, const double phase, const int64_t startTime,
138 const double tofMinBoundary, const double tofMaxBoundary, const double timeMinBoundary,
139 const double timeMaxBoundary, std::vector<EventVector_pt> &eventVectors);
140};
141
143private:
144#ifdef _WIN32
145 HANDLE m_handle;
146#else
147 FILE *m_handle;
148#endif
149public:
150 // construction
151 FastReadOnlyFile(const char *filename);
153
154 // Prevent copying of a file handle
157
158 // properties
159 void *handle() const;
160
161 // methods
162 void close();
163 bool read(void *buffer, uint32_t size);
164 bool seek(int64_t offset, int whence, int64_t *newPosition = nullptr);
165};
166
167namespace Tar {
168
170 // cppcheck-suppress unusedStructMember
171 char FileName[100];
172 // cppcheck-suppress unusedStructMember
173 char FileMode[8];
174 // cppcheck-suppress unusedStructMember
175 char OwnerUserID[8];
176 // cppcheck-suppress unusedStructMember
178 // cppcheck-suppress unusedStructMember
179 char FileSize[12]; // in bytes (octal base)
180 // cppcheck-suppress unusedStructMember
181 char LastModification[12]; // time in numeric Unix time format (octal)
182 // cppcheck-suppress unusedStructMember
183 char Checksum[8];
184 // cppcheck-suppress unusedStructMember
186 // cppcheck-suppress unusedStructMember
187 char LinkedFileName[100];
188 // cppcheck-suppress unusedStructMember
189 char UStar[8];
190 // cppcheck-suppress unusedStructMember
192 // cppcheck-suppress unusedStructMember
194 // cppcheck-suppress unusedStructMember
196 // cppcheck-suppress unusedStructMember
198 // cppcheck-suppress unusedStructMember
199 char FilenamePrefix[155];
200
201 // methods
202 void writeChecksum();
203 void writeFileSize(int64_t value);
204 int64_t readFileSize();
205};
206
207class File {
208
209 static const auto BUFFER_SIZE = 4096;
210
211 struct FileInfo {
212 int64_t Offset;
213 int64_t Size;
214 };
215
216private:
217 // fields
218 bool m_good;
220 std::vector<std::string> m_fileNames;
221 std::vector<FileInfo> m_fileInfos;
222 // selected file
223 size_t m_selected; // index
224 int64_t m_position;
225 int64_t m_size;
226 // buffer
230
231 // not supported
232 File(const File &);
233 File &operator=(const File &);
234
235public:
236 // construction
237 File(const std::string &path);
238 void close();
239
240 // properties
241 bool good() const;
242 const std::vector<std::string> &files() const;
243 // from selected file
244 const std::string &selected_name() const;
245 int64_t selected_position() const;
246 int64_t selected_size() const;
247
248 // methods
249 bool select(const char *file);
250 bool skip(uint64_t offset);
251 size_t read(void *dst, size_t size);
252 int read_byte();
253
254 // helpers
255 static bool append(const std::string &path, const std::string &name, const void *buffer, size_t size);
256};
257
258} // namespace Tar
259} // namespace ANSTO
260} // namespace DataHandling
261} // namespace Mantid
double value
The value of the point.
Definition: FitMW.cpp:51
double position
Definition: GetAllEi.cpp:154
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
bool read(void *buffer, uint32_t size)
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)
std::vector< Types::Event::TofEvent > * EventVector_pt
pointer to the vector of events
Helper class which provides the Collimation Length for SANS instruments.