mirror of
https://github.com/paulscherrerinstitute/sf_daq_buffer.git
synced 2026-05-06 19:04:13 +02:00
Tidy up jf_live_writer
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#ifndef SFWRITER_HPP
|
||||
#define SFWRITER_HPP
|
||||
#ifndef JF_LIVE_WRITER_HPP
|
||||
#define JF_LIVE_WRITER_HPP
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@@ -32,28 +32,28 @@ class JFH5Writer {
|
||||
hid_t daq_rec_dataset_id_ = -1;
|
||||
hid_t is_good_dataset_id_ = -1;
|
||||
|
||||
hid_t get_datatype(const int bits_per_pixel);
|
||||
void open_file(const std::string& output_file, const uint32_t n_images);
|
||||
static hid_t get_datatype(int bits_per_pixel);
|
||||
void open_file(const std::string& output_file, uint32_t n_images);
|
||||
void close_file();
|
||||
|
||||
public:
|
||||
JFH5Writer(const BufferUtils::DetectorConfig config);
|
||||
explicit JFH5Writer(const BufferUtils::DetectorConfig& config);
|
||||
~JFH5Writer();
|
||||
|
||||
void open_run(const int64_t run_id,
|
||||
const uint32_t n_images,
|
||||
const uint32_t image_y_size,
|
||||
const uint32_t image_x_size,
|
||||
const uint32_t bits_per_pixel);
|
||||
void open_run(int64_t run_id,
|
||||
uint32_t n_images,
|
||||
uint32_t image_y_size,
|
||||
uint32_t image_x_size,
|
||||
uint32_t bits_per_pixel);
|
||||
void close_run();
|
||||
|
||||
void write_data(const int64_t run_id,
|
||||
const uint32_t index,
|
||||
void write_data(int64_t run_id,
|
||||
uint32_t index,
|
||||
const char* data);
|
||||
|
||||
void write_meta(const int64_t run_id,
|
||||
const uint32_t index,
|
||||
void write_meta(int64_t run_id,
|
||||
uint32_t index,
|
||||
const ImageMetadata& meta);
|
||||
};
|
||||
|
||||
#endif //SFWRITER_HPP
|
||||
#endif //JF_LIVE_WRITER_HPP
|
||||
|
||||
@@ -11,13 +11,13 @@ class WriterStats {
|
||||
const std::string detector_name_;
|
||||
const size_t stats_modulo_;
|
||||
|
||||
uint32_t image_n_bytes_;
|
||||
uint32_t image_n_bytes_{};
|
||||
|
||||
int image_counter_;
|
||||
uint64_t total_bytes_;
|
||||
int image_counter_{};
|
||||
uint64_t total_bytes_{};
|
||||
|
||||
uint32_t total_buffer_write_us_;
|
||||
uint32_t max_buffer_write_us_;
|
||||
uint32_t total_buffer_write_us_{};
|
||||
uint32_t max_buffer_write_us_{};
|
||||
std::chrono::time_point<std::chrono::steady_clock> stats_interval_start_;
|
||||
|
||||
void reset_counters();
|
||||
@@ -25,7 +25,7 @@ class WriterStats {
|
||||
|
||||
public:
|
||||
WriterStats(
|
||||
const std::string &detector_name,
|
||||
std::string detector_name,
|
||||
const size_t stats_modulo);
|
||||
void setup_run(const StoreStream& meta);
|
||||
void start_image_write();
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
#include "JFH5Writer.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
#include <H5version.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
#include "JFH5Writer.hpp"
|
||||
#include "live_writer_config.hpp"
|
||||
#include "buffer_config.hpp"
|
||||
#include "formats.hpp"
|
||||
@@ -19,7 +15,7 @@ using namespace std;
|
||||
using namespace buffer_config;
|
||||
using namespace live_writer_config;
|
||||
|
||||
JFH5Writer::JFH5Writer(const BufferUtils::DetectorConfig config):
|
||||
JFH5Writer::JFH5Writer(const BufferUtils::DetectorConfig& config):
|
||||
root_folder_(config.buffer_folder),
|
||||
detector_name_(config.detector_name)
|
||||
{
|
||||
@@ -140,7 +136,7 @@ void JFH5Writer::open_file(const string& output_file, const uint32_t n_images)
|
||||
}
|
||||
|
||||
hsize_t image_dataset_dims[] = {n_images, image_y_size_, image_x_size_};
|
||||
auto image_space_id = H5Screate_simple(3, image_dataset_dims, NULL);
|
||||
auto image_space_id = H5Screate_simple(3, image_dataset_dims, nullptr);
|
||||
if (image_space_id < 0) {
|
||||
throw runtime_error("Cannot create image dataset space.");
|
||||
}
|
||||
@@ -162,12 +158,12 @@ void JFH5Writer::open_file(const string& output_file, const uint32_t n_images)
|
||||
|
||||
// Create metadata datasets.
|
||||
hsize_t meta_dataset_dims[] = {n_images};
|
||||
auto meta_space_id = H5Screate_simple(1, meta_dataset_dims, NULL);
|
||||
auto meta_space_id = H5Screate_simple(1, meta_dataset_dims, nullptr);
|
||||
if (meta_space_id < 0) {
|
||||
throw runtime_error("Cannot create meta dataset space.");
|
||||
}
|
||||
|
||||
auto create_meta_dataset = [&](string name, hid_t data_type) {
|
||||
auto create_meta_dataset = [&](const string& name, hid_t data_type) {
|
||||
auto dataset_id = H5Dcreate(
|
||||
data_group_id, name.c_str(), data_type, meta_space_id,
|
||||
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
#include <iostream>
|
||||
#include <utility>
|
||||
#include "WriterStats.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace chrono;
|
||||
|
||||
WriterStats::WriterStats(
|
||||
const string& detector_name,
|
||||
string detector_name,
|
||||
const size_t stats_modulo) :
|
||||
detector_name_(detector_name),
|
||||
detector_name_(std::move(detector_name)),
|
||||
stats_modulo_(stats_modulo)
|
||||
{
|
||||
reset_counters();
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <zmq.h>
|
||||
#include <RamBuffer.hpp>
|
||||
#include <BufferUtils.hpp>
|
||||
#include <mpi.h>
|
||||
|
||||
#include "RamBuffer.hpp"
|
||||
#include "BufferUtils.hpp"
|
||||
#include "live_writer_config.hpp"
|
||||
#include "WriterStats.hpp"
|
||||
#include "broker_format.hpp"
|
||||
#include <mpi.h>
|
||||
#include <JFH5Writer.hpp>
|
||||
|
||||
#include "JFH5Writer.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace buffer_config;
|
||||
@@ -27,7 +27,7 @@ int main (int argc, char *argv[])
|
||||
|
||||
auto const config = BufferUtils::read_json_config(string(argv[1]));
|
||||
|
||||
MPI_Init(NULL, NULL);
|
||||
MPI_Init(nullptr, nullptr);
|
||||
|
||||
int n_writers;
|
||||
MPI_Comm_size(MPI_COMM_WORLD, &n_writers);
|
||||
@@ -80,6 +80,4 @@ int main (int argc, char *argv[])
|
||||
writer.write_meta(meta.run_id, meta.i_image, meta.image_metadata);
|
||||
}
|
||||
}
|
||||
|
||||
MPI_Finalize();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user