Use new binary writer

This commit is contained in:
2020-04-17 12:46:42 +02:00
parent e489568e67
commit c662411c61
+17 -69
View File
@@ -4,9 +4,7 @@
#include <UdpRecvModule.hpp>
#include <H5Writer.hpp>
#include <WriterUtils.hpp>
#include "MetadataBuffer.hpp"
#include "BufferedWriter.hpp"
#include "BinaryWriter.hpp"
#include "config.hpp"
#include "jungfrau.hpp"
#include "BufferUtils.hpp"
@@ -44,25 +42,9 @@ int main (int argc, char *argv[]) {
uint64_t n_missed_frames = 0;
uint64_t last_pulse_id = 0;
// TODO: Ugly hack.
std::stringstream latest_filename;
latest_filename << root_folder << "/";
latest_filename << device_name << "/";
latest_filename << "LATEST";
string str_latest_filename = latest_filename.str();
unordered_map<string, HeaderDataType> header_values {
{"pulse_id", HeaderDataType("uint64")},
{"frame_id", HeaderDataType("uint64")},
{"daq_rec", HeaderDataType("uint32")},
{"received_packets", HeaderDataType("uint16")},
{"recv_packets_1", HeaderDataType("uint64")},
{"recv_packets_2", HeaderDataType("uint64")},
};
MetadataBuffer metadata_buffer(FILE_MOD, header_values);
BufferedWriter writer("", FILE_MOD, metadata_buffer);
BinaryWriter writer(device_name, root_folder);
// TODO: Optimize this away and pass it with the RB.
auto* jf_file_format_buffer = new JFFileFormat();
while (true) {
auto data = ring_buffer.read();
@@ -72,62 +54,26 @@ int main (int argc, char *argv[]) {
continue;
}
auto pulse_id = data.first->pulse_id;
auto* metadata = data.first.get();
auto pulse_id = metadata->pulse_id;
auto frame_file = get_filename(
root_folder,
device_name,
pulse_id);
jf_file_format_buffer->pulse_id = pulse_id;
jf_file_format_buffer->frame_id = metadata->frame_index;
jf_file_format_buffer->daq_rec = metadata->daq_rec;
jf_file_format_buffer->n_recv_packets = metadata->n_recv_packets;
if (current_file != frame_file) {
// TODO: This executes only in first loop. Fix it.
if (writer.is_file_open()) {
memcpy(&(jf_file_format_buffer->data),
data.second,
JUNGFRAU_DATA_BYTES_PER_FRAME);
writer.write_metadata_to_file();
// TODO: Ugly hack from above, part 2.
stringstream latest_command;
latest_command << "echo " << current_file;
latest_command << " > " << str_latest_filename;
auto str_latest_command = latest_command.str();
system(str_latest_command.c_str());
writer.close_file();
}
current_file = frame_file;
WriterUtils::create_destination_folder(current_file);
writer.create_file(current_file);
}
auto file_frame_index = get_file_frame_index(pulse_id);
writer.write_data(
"image", file_frame_index,
data.second, {512,1024},
JUNGFRAU_DATA_BYTES_PER_FRAME, "uint16", "little");
writer.cache_metadata("pulse_id", file_frame_index,
(char*) &(data.first->pulse_id));
writer.cache_metadata("frame_id", file_frame_index,
(char*) &(data.first->frame_index));
writer.cache_metadata("daq_rec", file_frame_index,
(char*) &(data.first->daq_rec));
writer.cache_metadata("received_packets", file_frame_index,
(char*) &(data.first->n_recv_packets));
writer.cache_metadata("recv_packets_1", file_frame_index,
(char*) &(data.first->recv_packets_1));
writer.cache_metadata("recv_packets_2", file_frame_index,
(char*) &(data.first->recv_packets_2));
writer.write(pulse_id, jf_file_format_buffer);
ring_buffer.release(data.first->buffer_slot_index);
// TODO: Make real statistics, please.
n_stat_out++;
if (data.first->recv_packets_2 > 0 || data.first->recv_packets_1 > 0) {
if (data.first->n_recv_packets <= JUNGFRAU_N_PACKETS_PER_FRAME) {
n_frames_with_missing_packets++;
}
@@ -149,4 +95,6 @@ int main (int argc, char *argv[]) {
n_missed_frames = 0;
}
}
delete jf_file_format_buffer;
}