23 : m_msg(msg), m_count(
count), m_step(target /
count), m_next(m_step), m_progBar(progBar) {
38 m_next = std::numeric_limits<int64_t>::max();
56 const double phase,
const int64_t startTime,
const double tofMinBoundary,
57 const double tofMaxBoundary,
const double timeMinBoundary,
const double timeMaxBoundary)
58 : m_roi(roi), m_stride(stride), m_frames(0), m_framesValid(0), m_startTime(startTime), m_period(period),
59 m_phase(phase), m_tofMinBoundary(tofMinBoundary), m_tofMaxBoundary(tofMaxBoundary),
60 m_timeMinBoundary(timeMinBoundary), m_timeMaxBoundary(timeMaxBoundary) {}
100 auto frames =
static_cast<double>(
m_frames);
101 auto frameTime =
static_cast<int64_t
>(
m_period * frames * 1.0e3);
110 const int64_t startTime,
const double tofMinBoundary,
const double tofMaxBoundary,
111 const double timeMinBoundary,
const double timeMaxBoundary, std::vector<size_t> &eventCounts)
112 :
EventProcessor(roi, stride, period, phase, startTime, tofMinBoundary, tofMaxBoundary, timeMinBoundary,
114 m_eventCounts(eventCounts), m_tofMin(
std::numeric_limits<double>::max()),
115 m_tofMax(
std::numeric_limits<double>::min()) {}
131 const int64_t startTime,
const double tofMinBoundary,
const double tofMaxBoundary,
132 const double timeMinBoundary,
const double timeMaxBoundary,
133 std::vector<EventVector_pt> &eventVectors)
134 :
EventProcessor(roi, stride, period, phase, startTime, tofMinBoundary, tofMaxBoundary, timeMinBoundary,
136 m_eventVectors(eventVectors) {}
138 m_eventVectors[id]->emplace_back(tof, Types::Core::DateAndTime(pulse));
143 const double wavelength,
const double period,
144 const double phase,
const int64_t startTime,
145 const double tofMinBoundary,
const double tofMaxBoundary,
146 const double timeMinBoundary,
const double timeMaxBoundary,
147 std::vector<EventVector_pt> &eventVectors)
148 :
EventAssigner(roi, stride, period, phase, startTime, tofMinBoundary, tofMaxBoundary, timeMinBoundary,
149 timeMaxBoundary, eventVectors),
150 m_wavelength(wavelength) {}
160 m_handle = CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
170 return (FALSE != ReadFile(
m_handle, buffer, size, &bytesRead, NULL)) && (bytesRead == size);
173 return FALSE != SetFilePointerEx(
m_handle, *(LARGE_INTEGER *)&offset, (LARGE_INTEGER *)newPosition, whence);
184 return 1 == fread(buffer,
static_cast<size_t>(size), 1,
m_handle);
187 return (0 == fseek(
m_handle, offset, whence)) &&
188 ((newPosition ==
nullptr) || (0 <= (*newPosition =
static_cast<int64_t
>(ftell(
m_handle)))));
196 size_t value = std::accumulate((
const char *)
this, (
const char *)
this +
sizeof(
EntryHeader), (
size_t)0);
198 std::ostringstream buffer;
200 buffer << std::oct << std::setfill('0') << std::setw(static_cast<int>(
sizeof(
Checksum)) - 1) <<
value;
201 std::string
string = buffer.str();
203 std::copy(
string.cbegin(),
string.cend(),
Checksum);
207 std::ostringstream buffer;
209 buffer << std::oct << std::setfill('0') << std::setw(static_cast<int>(
sizeof(
FileSize)) - 1) <<
value;
210 std::string
string = buffer.str();
212 std::copy(
string.cbegin(),
string.cend(),
FileSize);
218 for (
size_t n =
sizeof(
FileSize) - 1;
n != 0; --
n) {
220 if ((
'0' <= c) && (c <=
'9'))
221 result = result * 8 + (c -
'0');
228 : m_good(true), m_file(path.c_str()), m_selected(static_cast<size_t>(-1)), m_position(0),
m_size(0),
229 m_bufferPosition(0), m_bufferAvailable(0) {
241 std::string fileName(header.FileName);
242 if (fileName.length() == 0)
247 fileInfo.
Size = header.readFileSize();
254 auto offset =
static_cast<size_t>(fileInfo.
Size % 512);
256 offset = 512 - offset;
325 return m_good && !overrun;
334 auto ptr =
reinterpret_cast<uint8_t *
>(dst);
351 auto bytesToRead =
static_cast<uint32_t
>(std::min<size_t>(size, std::numeric_limits<uint32_t>::max()));
360 result += bytesToRead;
389bool File::append(
const std::string &path,
const std::string &name,
const void *buffer,
size_t size) {
390 std::unique_ptr<FILE,
decltype(&fclose)> handle(fopen(path.c_str(),
"rb+"), fclose);
392 bool good = handle !=
nullptr;
393 int64_t lastHeaderPosition = 0;
394 int64_t targetPosition = -1;
400 lastHeaderPosition =
static_cast<int64_t
>(ftell(handle.get()));
404 good &= 0 <= (
position =
static_cast<int64_t
>(ftell(handle.get())));
409 std::string fileName(header.FileName);
410 if (fileName.length() == 0)
413 if (fileName == name)
414 targetPosition = lastHeaderPosition;
415 else if (targetPosition != -1)
416 throw std::runtime_error(
"format exception");
420 fileInfo.
Size = header.readFileSize();
422 auto offset =
static_cast<size_t>(fileInfo.
Size % 512);
424 offset = 512 - offset;
426 good &= 0 == fseek(handle.get(),
static_cast<long>(fileInfo.
Size + offset), SEEK_CUR);
432 if (targetPosition < 0)
433 targetPosition = lastHeaderPosition;
437 memset(padding, 0, 512);
442 memcpy(header.FileName, name.c_str(), name.size());
443 memset(header.FileMode,
'0',
sizeof(header.FileMode) - 1);
444 memset(header.OwnerUserID,
'0',
sizeof(header.OwnerUserID) - 1);
445 memset(header.OwnerGroupID,
'0',
sizeof(header.OwnerGroupID) - 1);
446 memset(header.LastModification,
'0',
sizeof(header.LastModification) - 1);
449 header.writeFileSize(size);
450 header.writeChecksum();
453 good &= 0 == fseek(handle.get(),
static_cast<long>(targetPosition), SEEK_SET);
455 good &= 1 == fwrite(padding, 512 -
sizeof(
EntryHeader), 1, handle.get());
458 good &= 1 == fwrite(buffer, size, 1, handle.get());
461 auto offset =
static_cast<size_t>(size % 512);
463 offset = 512 - offset;
465 good &= 1 == fwrite(padding, offset, 1, handle.get());
469 good &= 1 == fwrite(padding, 512, 1, handle.get());
size_t m_size
Maximum size of the store.
double value
The value of the point.
#define TarTypeFlag_NormalFile
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Helper class for reporting progress from algorithms.
void doReport(const std::string &msg="") override
Actually do the reporting, without changing the loop counter.
EventAssignerFixedWavelength(const std::vector< bool > &roi, const size_t stride, const double wavelength, const double period, const double phase, const int64_t startTime, const double tofMinBoundary, const double tofMaxBoundary, const double timeMinBoundary, const double timeMaxBoundary, std::vector< EventVector_pt > &eventVectors)
void addEventImpl(size_t id, int64_t pulse, double tof) override
EventAssigner(const std::vector< bool > &roi, const size_t stride, const double period, const double phase, int64_t startTime, const double tofMinBoundary, const double tofMaxBoundary, const double timeMinBoundary, const double timeMaxBoundary, std::vector< EventVector_pt > &eventVectors)
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
EventCounter(const std::vector< bool > &roi, const size_t stride, const double period, const double phase, const int64_t startTime, const double tofMinBoundary, const double tofMaxBoundary, const double timeMinBoundary, const double timeMaxBoundary, std::vector< size_t > &eventCounts)
std::vector< size_t > & m_eventCounts
const double m_timeMinBoundary
const double m_timeMaxBoundary
virtual void addEventImpl(size_t id, int64_t pulse, double tof)=0
void addEvent(size_t x, size_t y, double tof)
const double m_tofMinBoundary
const double m_tofMaxBoundary
EventProcessor(const std::vector< bool > &roi, size_t stride, const double period, const double phase, const int64_t startTime, const double tofMinBoundary, const double tofMaxBoundary, const double timeMinBoundary, const double timeMaxBoundary)
const std::vector< bool > & m_roi
bool seek(int64_t offset, int whence, int64_t *newPosition=nullptr)
bool read(void *buffer, uint32_t size)
FastReadOnlyFile(const char *filename)
void update(int64_t position)
API::Progress & m_progBar
ProgressTracker(API::Progress &progBar, const char *msg, int64_t target, size_t count)
std::vector< FileInfo > m_fileInfos
uint8_t m_buffer[BUFFER_SIZE]
std::vector< std::string > m_fileNames
const std::string & selected_name() const
int64_t selected_position() const
size_t read(void *dst, size_t size)
bool select(const char *file)
const std::vector< std::string > & files() const
static bool append(const std::string &path, const std::string &name, const void *buffer, size_t size)
bool skip(uint64_t offset)
int64_t selected_size() const
void reportIncrement(int inc, const std::string &msg="")
Sends the progress notification and increment the loop counter by more than one.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
void writeFileSize(int64_t value)