diff --git a/src/config.h b/src/config.h index 2114b66598de1459bf8eb5d0078ef61c64319e22..bf70abc0446639d4eb2c40cf68d564a6f8aab601 100644 --- a/src/config.h +++ b/src/config.h @@ -66,7 +66,10 @@ public: std::string v = vmap.at("pt_cut"); return boost::lexical_cast<uint32_t>(v.c_str()); } - + const std::string& getOutputFilenamePrefix() const + { + return vmap.at("output_filename_prefix"); + } const std::string& getOutputFilenameBase() const { return vmap.at("output_filename_base"); diff --git a/src/output.cc b/src/output.cc index e29e3dd3986d57aea33eb71c1e0c8b458527faea..44c196489a83fd0b73e1ef89bb326ef9898c3962 100644 --- a/src/output.cc +++ b/src/output.cc @@ -8,7 +8,7 @@ #include <iostream> #include <stdio.h> -/* Defines the journal file */ +/* Defines the journal file. Note: Filename prefix is added making the final filename */ static const std::string journal_file { "index.journal" }; /* Defined where are the files stored before they are moved to the final destination */ @@ -37,33 +37,33 @@ static void create_output_directory(std::string& output_directory) LOG(TRACE) << "Created output directory: " << output_directory << "'."; } -OutputStream::OutputStream( const char* output_file_base, ctrl& c, std::string system_name_) : +OutputStream::OutputStream( const std::string output_filename_base, const std::string output_filename_prefix, ctrl& c) : tbb::filter(serial_in_order), - my_output_file_base(output_file_base), + my_output_filename_base(output_filename_base), + my_output_filename_prefix(output_filename_prefix), totcounts(0), current_file_size(0), file_count(-1), control(c), current_file(0), current_run_number(0), - journal_name(my_output_file_base + "/" + journal_file), - system_name(system_name_) + journal_name(my_output_filename_base + "/" + output_filename_prefix + '_' + journal_file) { LOG(TRACE) << "Created output filter at " << static_cast<void*>(this); // Create the ouput directory - std::string output_directory = my_output_file_base + "/" + working_dir; + std::string output_directory = my_output_filename_base + "/" + working_dir; create_output_directory(output_directory); } -static void update_journal(std::string journal_name, uint32_t run_number, std::string system_name, uint32_t index) +static void update_journal(std::string journal_name, uint32_t run_number, uint32_t index) { std::string new_journal_name = journal_name + ".new"; // Create a new journal file std::ofstream journal (new_journal_name); if (journal.is_open()) { - journal << run_number << "\n" << system_name << "\n" << index << "\n"; + journal << run_number << "\n" << index << "\n"; journal.close(); } else { LOG(ERROR) << "WARNING: Unable to open journal file"; @@ -75,11 +75,11 @@ static void update_journal(std::string journal_name, uint32_t run_number, std::s } } -static bool read_journal(std::string journal_name, uint32_t& run_number, std::string system_name, uint32_t& index) +static bool read_journal(std::string journal_name, uint32_t& run_number, uint32_t& index) { std::ifstream journal (journal_name); if (journal.is_open()) { - journal >> run_number >> system_name >> index; + journal >> run_number >> index; journal.close(); return true; } @@ -117,10 +117,10 @@ void* OutputStream::operator()( void* item ) * Create a properly formated file name * TODO: Change to C++ */ -static std::string format_run_file_stem(uint32_t run_number, std::string system_name, int32_t file_count) +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), "scout_%06d_%s_%06d.dat", run_number, system_name.c_str(), file_count); + 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); } @@ -131,9 +131,9 @@ void OutputStream::close_and_move_current_file() fclose(current_file); current_file = NULL; - std::string run_file = format_run_file_stem(current_run_number, system_name, file_count); - std::string current_file_name = my_output_file_base + "/" + working_dir + "/" + run_file; - std::string target_file_name = my_output_file_base + "/" + run_file; + std::string run_file = format_run_file_stem(my_output_filename_prefix, current_run_number, file_count); + std::string current_file_name = my_output_filename_base + "/" + working_dir + "/" + run_file; + std::string target_file_name = my_output_filename_base + "/" + run_file; LOG(INFO) << "rename: " << current_file_name << " to " << target_file_name; if ( rename(current_file_name.c_str(), target_file_name.c_str()) < 0 ) { @@ -163,7 +163,7 @@ void OutputStream::open_next_file() uint32_t journal_run_number; uint32_t index; - if (read_journal(journal_name, journal_run_number, system_name, index)) { + if (read_journal(journal_name, journal_run_number, index)) { LOG(INFO) << "We have journal:"; LOG(INFO) << " run_number: " << journal_run_number; LOG(INFO) << " index: " << index; @@ -179,11 +179,11 @@ void OutputStream::open_next_file() } // Create the ouput directory - std::string output_directory = my_output_file_base + "/" + working_dir; + std::string output_directory = my_output_filename_base + "/" + working_dir; create_output_directory(output_directory); // Create a new file - std::string current_filename = output_directory + "/" + format_run_file_stem(current_run_number, system_name,file_count); + std::string current_filename = output_directory + "/" + format_run_file_stem(my_output_filename_prefix, current_run_number, file_count); current_file = fopen( current_filename.c_str(), "w" ); if (current_file == NULL) { std::string err = tools::strerror("ERROR when creating file '" + current_filename + "'"); @@ -192,5 +192,5 @@ void OutputStream::open_next_file() } // Update journal file (with the next index file) - update_journal(journal_name, current_run_number, system_name, file_count+1); + update_journal(journal_name, current_run_number, file_count+1); } diff --git a/src/output.h b/src/output.h index 7f844e016b9397547aff3d1dfb16607fe4e3a237..cb6de035781aa7bfbcefaf227f2c68d93a8ecb87 100644 --- a/src/output.h +++ b/src/output.h @@ -13,7 +13,7 @@ class OutputStream: public tbb::filter { public: - OutputStream( const char* output_file_base, ctrl& c, std::string system_name_ ); + OutputStream( const std::string output_filename_base, const std::string output_filename_prefix, ctrl& c ); void* operator()( void* item ) /*override*/; private: @@ -21,7 +21,8 @@ private: void close_and_move_current_file(); private: - std::string my_output_file_base; + std::string my_output_filename_base; + std::string my_output_filename_prefix; uint32_t totcounts; uint64_t current_file_size; int32_t file_count; @@ -29,7 +30,6 @@ private: FILE *current_file; uint32_t current_run_number; std::string journal_name; - std::string system_name; }; #endif diff --git a/src/scdaq.cc b/src/scdaq.cc index 5d1289c8dfd5fadff16ebec95c8a64772bdc2975..d8a254cd6c8b8f34f253744db91eb5d26939efa3 100644 --- a/src/scdaq.cc +++ b/src/scdaq.cc @@ -83,10 +83,8 @@ int run_pipeline( int nbThreads, ctrl& control, config& conf ) pipeline.add_filter(elastic_processor); } - std::string output_file_base = conf.getOutputFilenameBase(); - // Create file-writing stage and add it to the pipeline - OutputStream output_stream( output_file_base.c_str(), control, conf.getSystemName()); + OutputStream output_stream( conf.getOutputFilenameBase(), conf.getOutputFilenamePrefix(), control); pipeline.add_filter( output_stream ); // Run the pipeline