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

various fixes in the file handler thread

parent be8af746
No related branches found
No related tags found
No related merge requests found
#include "OutputFileHandler.h" #include "OutputFileHandler.h"
#include <iomanip> #include <iomanip>
...@@ -10,11 +11,17 @@ const std::string OutputFileHandler::journal_file_ = "index.journal"; ...@@ -10,11 +11,17 @@ const std::string OutputFileHandler::journal_file_ = "index.journal";
tbb::concurrent_bounded_queue<std::pair<std::string, FILE *>> OutputFileHandler::files_to_close_ = tbb::concurrent_bounded_queue<std::pair<std::string, FILE *>> OutputFileHandler::files_to_close_ =
tbb::concurrent_bounded_queue<std::pair<std::string, FILE *>>(); tbb::concurrent_bounded_queue<std::pair<std::string, FILE *>>();
bool OutputFileHandler::file_handler_running_ = false; bool OutputFileHandler::file_handler_running_ = true;
void OutputFileHandler::enqueue_current_file_for_close_and_move_maybe() { void OutputFileHandler::enqueue_current_file_for_close_and_move_maybe() {
if (current_file_ != 0) if (current_file_ != 0) {
LOG(TRACE) << "queueing file: " << current_filename_ << " for closing, queue size now "
<< files_to_close_.size();
files_to_close_.push(std::pair<std::string, FILE *>(current_filename_, current_file_)); files_to_close_.push(std::pair<std::string, FILE *>(current_filename_, current_file_));
current_file_ = 0;
current_filename_ = std::string();
LOG(TRACE) << "queued " << current_filename_ << " queue size now " << files_to_close_.size();
}
} }
FILE *OutputFileHandler::getFile(uint32_t run, uint32_t index) { FILE *OutputFileHandler::getFile(uint32_t run, uint32_t index) {
...@@ -29,7 +36,7 @@ FILE *OutputFileHandler::getFile(uint32_t run, uint32_t index) { ...@@ -29,7 +36,7 @@ FILE *OutputFileHandler::getFile(uint32_t run, uint32_t index) {
void OutputFileHandler::create_output_directory_maybe(std::string &output_directory) { void OutputFileHandler::create_output_directory_maybe(std::string &output_directory) {
struct stat sb; struct stat sb;
LOG(TRACE) << "checking if working directory " << output_directory << " exists ";
/* check if path exists and is a directory */ /* check if path exists and is a directory */
if (stat(output_directory.c_str(), &sb) == 0) { if (stat(output_directory.c_str(), &sb) == 0) {
if (S_ISDIR(sb.st_mode)) { // output directory already exists if (S_ISDIR(sb.st_mode)) { // output directory already exists
...@@ -69,7 +76,7 @@ void OutputFileHandler::open_new_file() { ...@@ -69,7 +76,7 @@ void OutputFileHandler::open_new_file() {
std::string OutputFileHandler::format_filename(uint32_t run_number, uint32_t index) { std::string OutputFileHandler::format_filename(uint32_t run_number, uint32_t index) {
std::ostringstream ofilename; std::ostringstream ofilename;
ofilename << filename_prefix_ << "_" << std::setfill('0') << std::setw(6) << run_number << "_" ofilename << filename_prefix_ << "_" << std::setfill('0') << std::setw(6) << run_number << "_"
<< index << ".dat"; << std::setfill('0') << std::setw(6) << index << ".dat";
return ofilename.str(); return ofilename.str();
} }
...@@ -78,7 +85,10 @@ void OutputFileHandler::close_and_rename::operator()() const { ...@@ -78,7 +85,10 @@ void OutputFileHandler::close_and_rename::operator()() const {
while (file_handler_running_ || (files_to_close_.size() > 0)) { while (file_handler_running_ || (files_to_close_.size() > 0)) {
// std::cout << std::this_thread::get_id() << " try pop" << // std::cout << std::this_thread::get_id() << " try pop" <<
// files_to_close_.size() << std::endl; // files_to_close_.size() << std::endl;
LOG(TRACE) << "try pop now. queue size now " << files_to_close_.size();
files_to_close_.pop(n); files_to_close_.pop(n);
LOG(TRACE) << "popping file: " << n.first << " for closing, queue size now "
<< files_to_close_.size();
if (fclose(n.second) != 0) { if (fclose(n.second) != 0) {
LOG(ERROR) << tools::strerror("File close failed"); LOG(ERROR) << tools::strerror("File close failed");
} }
...@@ -90,4 +100,6 @@ void OutputFileHandler::close_and_rename::operator()() const { ...@@ -90,4 +100,6 @@ void OutputFileHandler::close_and_rename::operator()() const {
// std::cout << std::this_thread::get_id() << " popped " << n.first << " // std::cout << std::this_thread::get_id() << " popped " << n.first << "
// size now " << files_to_close_.size() << std::endl; // size now " << files_to_close_.size() << std::endl;
} }
LOG(TRACE) << "exiting close_and_rename. file_handler_running_ now " << file_handler_running_
<< " queue size now " << files_to_close_.size();
} }
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