mirror of
https://github.com/paulscherrerinstitute/sf_daq_buffer.git
synced 2026-04-23 01:32:42 +02:00
Read also images from SWMR files
This commit is contained in:
+44
-11
@@ -27,12 +27,17 @@ int main (int argc, char *argv[]) {
|
||||
string current_filename = root_folder + "/" + device_name + "/CURRENT";
|
||||
|
||||
uint64_t pulse_id_buffer[1000];
|
||||
uint16_t image_buffer[100*2*512*1024];
|
||||
|
||||
string last_open_file = "";
|
||||
uint64_t last_pulse_id = 0;
|
||||
|
||||
int current_file_last_processed = -1;
|
||||
|
||||
while (true) {
|
||||
auto filename = BufferUtils::get_latest_file(current_filename);
|
||||
|
||||
// Next file not yet ready.
|
||||
if (last_open_file == filename) {
|
||||
this_thread::sleep_for(chrono::milliseconds(100));
|
||||
cout << "Waiting for CURRENT to change." << endl;
|
||||
@@ -41,7 +46,7 @@ int main (int argc, char *argv[]) {
|
||||
|
||||
std::cout << "Opening " << filename << endl;
|
||||
last_open_file = filename;
|
||||
last_pulse_id = 0;
|
||||
current_file_last_processed = -1;
|
||||
|
||||
H5::H5File input_file(filename, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ);
|
||||
auto image_dataset = input_file.openDataSet("image");
|
||||
@@ -50,32 +55,60 @@ int main (int argc, char *argv[]) {
|
||||
::memset(pulse_id_buffer, 0, sizeof(pulse_id_buffer));
|
||||
|
||||
while (true) {
|
||||
this_thread::sleep_for(chrono::milliseconds(100));
|
||||
H5Drefresh(pulse_id_dataset.getId());
|
||||
|
||||
pulse_id_dataset.read(
|
||||
pulse_id_buffer,
|
||||
H5::PredType::NATIVE_UINT64);
|
||||
|
||||
auto file_frame_index =
|
||||
BufferUtils::get_file_frame_index(last_pulse_id);
|
||||
|
||||
size_t n_new_pulses = 0;
|
||||
for (size_t i=file_frame_index; i<1000; i++) {
|
||||
if (pulse_id_buffer[i] > last_pulse_id) {
|
||||
last_pulse_id = pulse_id_buffer[i];
|
||||
for (size_t i=current_file_last_processed+1; i<1000; i++) {
|
||||
if (pulse_id_buffer[i] > 0) {
|
||||
n_new_pulses++;
|
||||
}
|
||||
}
|
||||
|
||||
// There is more stuff to be processed.
|
||||
if (n_new_pulses > 0) {
|
||||
cout << last_pulse_id << " and n_new_pulses ";
|
||||
cout << n_new_pulses << endl;
|
||||
// TODO: Just temporary due to buffer size.
|
||||
if (n_new_pulses > 100) {
|
||||
n_new_pulses = 100;
|
||||
}
|
||||
|
||||
uint64_t start_pulse_id = current_file_last_processed+1;
|
||||
uint64_t end_pulse_id =
|
||||
current_file_last_processed + n_new_pulses;
|
||||
|
||||
|
||||
hsize_t buff_dim[3] = {100, 512, 1024};
|
||||
H5::DataSpace buffer_space (3, buff_dim);
|
||||
hsize_t b_count[] = {n_new_pulses, 512, 1024};
|
||||
hsize_t b_start[] = {0, 0, 0};
|
||||
buffer_space.selectHyperslab(H5S_SELECT_SET, b_count, b_start);
|
||||
|
||||
hsize_t disk_dim[3] = {1000, 512, 1024};
|
||||
H5::DataSpace disk_space(3, disk_dim);
|
||||
|
||||
hsize_t d_count[] = {n_new_pulses, 512, 1024};
|
||||
hsize_t d_start[] = {start_pulse_id, 0, 0};
|
||||
disk_space.selectHyperslab(H5S_SELECT_SET, d_count, d_start);
|
||||
|
||||
image_dataset.read(
|
||||
image_buffer,
|
||||
H5::PredType::NATIVE_UINT16,
|
||||
buffer_space,
|
||||
disk_space);
|
||||
|
||||
current_file_last_processed = end_pulse_id;
|
||||
}
|
||||
|
||||
// Time for next file.
|
||||
if (pulse_id_buffer[999] != 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Stream delay.
|
||||
this_thread::sleep_for(chrono::milliseconds(100));
|
||||
H5Drefresh(pulse_id_dataset.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user