Skip to content
Snippets Groups Projects
Commit f4cde9d0 authored by Emilio Meschi's avatar Emilio Meschi :bicyclist_tone1: Committed by Thomas Owen James
Browse files

class to delegate file output file actions

parent b976d8c5
No related branches found
No related tags found
No related merge requests found
#ifndef OUTPUTFILEHANDLER_H
#define OUTPUTFILEHANDLER_H
#include <cstdint>
#include <cstdio>
#include <string>
class OutputFileHandler {
public:
OutputFileHandler(const std::string filename_base_path, const std::string filename_prefix)
: filename_base_path_(filename_base_path),
filename_prefix_(filename_prefix),
working_files_basepath_(filename_base_path_ + "/" + working_dir_) {
create_output_directory_maybe(working_files_basepath_);
}
virtual ~OutputFileHandler() {}
void open_file(uint32_t index,
uint32_t run); // Used for fixedNorbits per file option
{
// Create a new file
std::string output_directory = my_output_filename_base + "/" + working_dir;
create_output_directory(output_directory);
std::string current_filename_a =
output_directory + "/" +
format_run_file_stem(my_output_filename_prefix, current_run_number, index_);
std::string filename =
output_directory + "/" +
format_run_file_stem(my_output_filename_prefix, control.run_number, index_);
LOG(INFO) << "opening file with index " << index_;
outFile.setFile(fopen(filename.c_str(), "w"));
outFile.setIndex(index_);
if (outFile.getFile() == NULL) {
std::string err = tools::strerror("ERROR when creating file '" + current_filename_a + "'");
LOG(ERROR) << err;
throw std::runtime_error(err);
}
}
private:
void create_output_directory_maybe(std::string &output_directory);
// name of subdir where the files are stored before they are moved to the
// final destination
static constexpr std::string working_dir_{"in_progress"};
// name of the journal file. Note: Filename prefix is added making the final
// filename
static constexpr std::string journal_file_{"index.journal"};
std::string filename_base_path_;
std::string filename_prefix_;
std::string working_files_basepath_;
uint32_t current_run_number_;
FILE *current_file_;
int32_t current_index_;
};
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment