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

remove all file actions and rationalize passing of arguments

parent 9a1ad056
No related branches found
No related tags found
No related merge requests found
...@@ -7,60 +7,22 @@ ...@@ -7,60 +7,22 @@
#include <string> #include <string>
#include <system_error> #include <system_error>
#include "config.h"
#include "controls.h"
#include "log.h" #include "log.h"
#include "slice.h" #include "slice.h"
#include "tools.h" #include "tools.h"
/* Defines the journal file. Note: Filename prefix is added making the final OutputByOrbitStream::OutputByOrbitStream(ctrl &c, config &conf_)
* filename */
static const std::string journal_file{"index.journal"};
/* Defined where are the files stored before they are moved to the final
* destination */
static const std::string working_dir{"in_progress"};
static void create_output_directory(std::string &output_directory) {
struct stat sb;
/* check if path exists and is a directory */
if (stat(output_directory.c_str(), &sb) == 0) {
if (S_ISDIR(sb.st_mode)) { // output directory already exists
return;
}
std::string err = "ERROR The output directory path '" + output_directory +
"' exists, but the path is not a directory!";
LOG(ERROR) << err;
throw std::runtime_error(err);
}
if (!tools::filesystem::create_directories(output_directory)) {
std::string err =
tools::strerror("ERROR when creating the output directory '" + output_directory + "'");
LOG(ERROR) << err;
throw std::runtime_error(err);
}
LOG(TRACE) << "Created output directory: " << output_directory << "'.";
}
OutputByOrbitStream::OutputByOrbitStream(const std::string output_filename_base,
const std::string output_filename_prefix, ctrl &c,
config &conf_)
: tbb::filter(serial_in_order), : tbb::filter(serial_in_order),
my_output_filename_base(output_filename_base),
my_output_filename_prefix(output_filename_prefix),
totcounts(0), totcounts(0),
current_file_size(0), current_file_size(0),
file_count(-1), file_count(-1),
control(c), control(c),
current_run_number(0), current_run_number(0),
conf(conf_), conf(conf_),
fixedOrbitsPerFile(bool(conf.getNOrbitsPerFile())), output_file_handler_(conf.getOutputFilenameBase(), conf.getOutputFilenamePrefix()) {
outFile() {
LOG(TRACE) << "Created output filter at " << static_cast<void *>(this); LOG(TRACE) << "Created output filter at " << static_cast<void *>(this);
// Create the ouput directory
std::string output_directory = my_output_filename_base + "/" + working_dir;
create_output_directory(output_directory);
} }
void *OutputByOrbitStream::OutputFixedOrbits(Slice &out) { void *OutputByOrbitStream::OutputFixedOrbits(Slice &out) {
...@@ -107,18 +69,6 @@ void *OutputByOrbitStream::operator()(void *item) { ...@@ -107,18 +69,6 @@ void *OutputByOrbitStream::operator()(void *item) {
return NULL; return NULL;
} }
/*
* Create a properly formatted file name
* TODO: Change to C++
*/
static std::string format_run_file_stem(std::string &filename_prefix, uint32_t run_number,
int32_t file_count) {
char run_order_stem[PATH_MAX];
snprintf(run_order_stem, sizeof(run_order_stem), "%s_%06d_%06d.dat", filename_prefix.c_str(),
run_number, file_count);
return std::string(run_order_stem);
}
void OutputByOrbitStream::close_and_move_file() // Used for fixedNorbits per void OutputByOrbitStream::close_and_move_file() // Used for fixedNorbits per
// file option // file option
{ {
...@@ -137,24 +87,3 @@ void OutputByOrbitStream::close_and_move_file() // Used for fixedNorbits per ...@@ -137,24 +87,3 @@ void OutputByOrbitStream::close_and_move_file() // Used for fixedNorbits per
} }
current_run_number = control.run_number; current_run_number = control.run_number;
} }
void OutputByOrbitStream::open_file(uint32_t index_) // 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);
}
}
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