Improve debug output

This commit is contained in:
2018-01-10 12:04:00 +01:00
parent 724b7a1444
commit de37caaa25
2 changed files with 37 additions and 29 deletions
+31 -24
View File
@@ -10,6 +10,8 @@ extern "C"
#include "H5DOpublic.h"
}
using namespace std;
hsize_t expand_dataset(const H5::DataSet& dataset, hsize_t frame_index, hsize_t dataset_increase_step)
{
hsize_t dataset_rank = 3;
@@ -19,11 +21,11 @@ hsize_t expand_dataset(const H5::DataSet& dataset, hsize_t frame_index, hsize_t
dataset_dimension[0] = frame_index + dataset_increase_step;
#ifdef DEBUG
std::cout << "[expand_dataset] Expanding dataspace to size (";
cout << "[expand_dataset] Expanding dataspace to size (";
for (hsize_t i=0; i<dataset_rank; ++i) {
std::cout << dataset_dimension[i] << ",";
cout << dataset_dimension[i] << ",";
}
std::cout << ")" << std::endl;
cout << ")" << endl;
#endif
dataset.extend(dataset_dimension);
@@ -40,22 +42,27 @@ void compact_dataset(const H5::DataSet& dataset, hsize_t max_frame_index)
dataset_dimension[0] = max_frame_index + 1;
#ifdef DEBUG
std::cout << "[compact_dataset] Compacting dataspace to size (";
cout << "[compact_dataset] Compacting dataspace to size (";
for (hsize_t i=0; i<dataset_rank; ++i) {
std::cout << dataset_dimension[i] << ",";
cout << dataset_dimension[i] << ",";
}
std::cout << ")" << std::endl;
cout << ")" << endl;
#endif
dataset.extend(dataset_dimension);
}
HDF5ChunkedWriter::HDF5ChunkedWriter(const std::string filename, const std::string dataset_name, hsize_t frames_per_file, hsize_t initial_dataset_size)
HDF5ChunkedWriter::HDF5ChunkedWriter(const string filename, const string dataset_name, hsize_t frames_per_file, hsize_t initial_dataset_size) :
filename(filename), dataset_name(dataset_name), frames_per_file(frames_per_file), initial_dataset_size(initial_dataset_size)
{
this->filename = filename;
this->dataset_name = dataset_name;
this->frames_per_file = frames_per_file;
this->initial_dataset_size = initial_dataset_size;
#ifdef DEBUG
cout << "[HDF5ChunkedWriter::HDF5ChunkedWriter] Creating chunked writer";
cout << " with filename " << filename;
cout << " and dataset_name " << dataset_name;
cout << " and frames_per_file " << frames_per_file;
cout << " and initial_dataset_size " << initial_dataset_size;
cout << endl;
#endif
}
HDF5ChunkedWriter::~HDF5ChunkedWriter()
@@ -67,14 +74,14 @@ void HDF5ChunkedWriter::close_file()
{
if (file.getId() == -1) {
#ifdef DEBUG
std::cout << "[HDF5ChunkedWriter::close_file] Trying to close an already closed file." << std::endl;
cout << "[HDF5ChunkedWriter::close_file] Trying to close an already closed file." << endl;
#endif
return;
}
#ifdef DEBUG
std::cout << "[HDF5ChunkedWriter::close_file] Closing file." << std::endl;
cout << "[HDF5ChunkedWriter::close_file] Closing file." << endl;
#endif
compact_dataset(dataset, max_frame_index);
@@ -92,7 +99,7 @@ void HDF5ChunkedWriter::close_file()
auto image_nr_high = max_frame_in_dataset + 1;
#ifdef DEBUG
std::cout << "[HDF5ChunkedWriter::close_file] Setting dataset attribute image_nr_low=" << image_nr_low << " and image_nr_high=" << image_nr_high << std::endl;
cout << "[HDF5ChunkedWriter::close_file] Setting dataset attribute image_nr_low=" << image_nr_low << " and image_nr_high=" << image_nr_high << endl;
#endif
// H5::IntType int_type(H5::PredType::NATIVE_UINT32);
@@ -123,10 +130,10 @@ void HDF5ChunkedWriter::write_data(size_t frame_index, size_t* frame_shape, size
if( H5DOwrite_chunk(dataset.getId(), H5P_DEFAULT, filters, offset, data_bytes_size, data) )
{
std::stringstream error_message;
error_message << "Error while writing chunk to file at offset " << relative_frame_index << "." << std::endl;
stringstream error_message;
error_message << "Error while writing chunk to file at offset " << relative_frame_index << "." << endl;
throw std::invalid_argument( error_message.str() );
throw invalid_argument( error_message.str() );
}
}
@@ -141,18 +148,18 @@ void HDF5ChunkedWriter::create_file(size_t* frame_shape, hsize_t frame_chunk) {
// In case frames_per_file is > 0, the filename variable is a template for the filename.
if (frames_per_file) {
#ifdef DEBUG
std::cout << "[HDF5ChunkedWriter::create_file] Frames per file is defined. Format " << filename << " with frame_chunk " << frame_chunk << std::endl;
cout << "[HDF5ChunkedWriter::create_file] Frames per file is defined. Format " << filename << " with frame_chunk " << frame_chunk << endl;
#endif
// Space for 10 digits should be enough.
char buffer[filename.length() + 10];
sprintf(buffer, filename.c_str(), frame_chunk);
target_filename = std::string(buffer);
target_filename = string(buffer);
}
#ifdef DEBUG
std::cout << "[HDF5ChunkedWriter::create_file] Creating filename " << target_filename << std::endl;
cout << "[HDF5ChunkedWriter::create_file] Creating filename " << target_filename << endl;
#endif
// TODO: Create folder if it does not exist.
@@ -168,11 +175,11 @@ void HDF5ChunkedWriter::create_file(size_t* frame_shape, hsize_t frame_chunk) {
H5::DataSpace dataspace(dataset_rank, dataset_dimension, max_dataset_dimension);
#ifdef DEBUG
std::cout << "[HDF5ChunkedWriter::create_file] Creating dataspace of size (";
cout << "[HDF5ChunkedWriter::create_file] Creating dataspace of size (";
for (hsize_t i=0; i<dataset_rank; ++i) {
std::cout << dataset_dimension[i] << ",";
cout << dataset_dimension[i] << ",";
}
std::cout << ")" << std::endl;
cout << ")" << endl;
#endif
// Set chunking to single image.
@@ -207,7 +214,7 @@ hsize_t HDF5ChunkedWriter::prepare_storage_for_frame(size_t frame_index, size_t*
}
#ifdef DEBUG
std::cout << "[HDF5ChunkedWriter::prepare_storage_for_frame] Received frame index " << frame_index << " and processed as relative frame index " << relative_frame_index << std::endl;
cout << "[HDF5ChunkedWriter::prepare_storage_for_frame] Received frame index " << frame_index << " and processed as relative frame index " << relative_frame_index << endl;
#endif
// Open the file if needed.
+6 -5
View File
@@ -80,11 +80,12 @@ void run_writer(string connect_address, string output_file, uint64_t n_images){
RingBuffer ring_buffer(n_slots);
#ifdef DEBUG
cout << "[h5_zmq_writer::run_writer] Running writer with ";
cout << "connect_address " << connect_address << " " << std::endl;
cout << "output_file " << output_file << " " << std::endl;
cout << "n_slots " << n_slots << " " << std::endl;
cout << "n_io_threads " << n_io_threads << " " << std::endl;
cout << "[h5_zmq_writer::run_writer] Running writer";
cout << " with connect_address " << connect_address << " ";
cout << " and output_file " << output_file << " ";
cout << " and n_slots " << n_slots << " ";
cout << " and n_io_threads " << n_io_threads << " ";
cout << endl;
#endif
thread receiver_thread(receive, &manager, &ring_buffer, connect_address, n_io_threads);