Improvements before MAX IV test
This commit is contained in:
@@ -13,9 +13,10 @@ StreamWriter::StreamWriter(ZMQContext &context, Logger &in_logger, const std::st
|
||||
}
|
||||
|
||||
void StreamWriter::CollectImages(std::vector<HDF5DataFileStatistics> &v) {
|
||||
bool run = true;
|
||||
while (run && (image_puller.GetFrameType() != CBORStream2Deserializer::Type::START)) {
|
||||
if (image_puller.GetFrameType() == CBORStream2Deserializer::Type::IMAGE)
|
||||
bool run = WaitForImage();
|
||||
|
||||
while (run && !image_puller_output.cbor->start_message) {
|
||||
if (image_puller_output.cbor->msg_type == CBORImageType::IMAGE)
|
||||
logger.Warning("Missing meaningful image while waiting for START");
|
||||
run = WaitForImage();
|
||||
}
|
||||
@@ -23,58 +24,55 @@ void StreamWriter::CollectImages(std::vector<HDF5DataFileStatistics> &v) {
|
||||
if (!run)
|
||||
return;
|
||||
|
||||
StartMessage start_message = image_puller.GetStartMessage();
|
||||
logger.Info("Starting writing for dataset {} of {} images", start_message.file_prefix, start_message.number_of_images);
|
||||
logger.Info("Starting writing for dataset {} of {} images",
|
||||
image_puller_output.cbor->start_message->file_prefix,
|
||||
image_puller_output.cbor->start_message->number_of_images);
|
||||
state = StreamWriterState::Started;
|
||||
uint64_t max_image_number = 0;
|
||||
|
||||
processed_images = 0;
|
||||
processed_image_size = 0;
|
||||
file_prefix = start_message.file_prefix;
|
||||
file_prefix = image_puller_output.cbor->start_message->file_prefix;
|
||||
|
||||
CheckPath(start_message.file_prefix);
|
||||
MakeDirectory(start_message.file_prefix);
|
||||
HDF5Writer writer(start_message);
|
||||
CheckPath(image_puller_output.cbor->start_message->file_prefix);
|
||||
MakeDirectory(image_puller_output.cbor->start_message->file_prefix);
|
||||
HDF5Writer writer(*image_puller_output.cbor->start_message);
|
||||
std::unique_ptr<NXmx> master_file;
|
||||
if (!start_message.write_master_file || start_message.write_master_file.value())
|
||||
master_file = std::make_unique<NXmx>(start_message);
|
||||
if (!image_puller_output.cbor->start_message->write_master_file || image_puller_output.cbor->start_message->write_master_file.value())
|
||||
master_file = std::make_unique<NXmx>(*image_puller_output.cbor->start_message);
|
||||
|
||||
bool first_image = true;
|
||||
run = WaitForImage();
|
||||
while (run && (image_puller.GetFrameType() == CBORStream2Deserializer::Type::CALIBRATION)) {
|
||||
while (run && image_puller_output.cbor->calibration) {
|
||||
if (master_file)
|
||||
master_file->WriteCalibration(image_puller.GetCalibrationMessage());
|
||||
master_file->WriteCalibration(*image_puller_output.cbor->calibration);
|
||||
run = WaitForImage();
|
||||
}
|
||||
|
||||
while (run && (image_puller.GetFrameType() == CBORStream2Deserializer::Type::IMAGE)) {
|
||||
while (run && image_puller_output.cbor->data_message) {
|
||||
if (first_image) {
|
||||
state = StreamWriterState::Receiving;
|
||||
start_time = std::chrono::system_clock::now();
|
||||
first_image = false;
|
||||
}
|
||||
auto image_array = image_puller.GetDataMessage();
|
||||
writer.Write(image_array);
|
||||
if (max_image_number < image_array.number + 1)
|
||||
max_image_number = image_array.number + 1;
|
||||
|
||||
if (start_message.pixel_bit_depth == 0)
|
||||
start_message.pixel_bit_depth = image_array.image.pixel_depth_bytes * 8;
|
||||
writer.Write(*image_puller_output.cbor->data_message);
|
||||
if (max_image_number < image_puller_output.cbor->data_message->number + 1)
|
||||
max_image_number = image_puller_output.cbor->data_message->number + 1;
|
||||
|
||||
processed_images++;
|
||||
processed_image_size += image_array.image.size;
|
||||
processed_image_size += image_puller_output.cbor->data_message->image.size;
|
||||
run = WaitForImage();
|
||||
}
|
||||
|
||||
if (image_puller.GetFrameType() == CBORStream2Deserializer::Type::END) {
|
||||
EndMessage end_message = image_puller.GetEndMessage();
|
||||
if (run && image_puller_output.cbor->end_message) {
|
||||
end_time = std::chrono::system_clock::now();
|
||||
|
||||
if ((end_message.max_image_number == 0) && (max_image_number > 0))
|
||||
end_message.max_image_number = max_image_number;
|
||||
if ((image_puller_output.cbor->end_message->max_image_number == 0) && (max_image_number > 0))
|
||||
image_puller_output.cbor->end_message->max_image_number = max_image_number;
|
||||
|
||||
if (master_file)
|
||||
master_file->Finalize(end_message);
|
||||
master_file->Finalize(*image_puller_output.cbor->end_message);
|
||||
master_file.reset();
|
||||
state = StreamWriterState::Idle;
|
||||
}
|
||||
@@ -105,7 +103,8 @@ StreamWriterOutput StreamWriter::Run() {
|
||||
|
||||
bool StreamWriter::WaitForImage() {
|
||||
try {
|
||||
return image_puller.WaitForImage();
|
||||
image_puller_output = image_puller.WaitForImage();
|
||||
return (image_puller_output.cbor != nullptr);
|
||||
} catch (const JFJochException &e) {
|
||||
logger.ErrorException(e);
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user