From 37a57d92dc7c1cd281eec4c786449b1add3616a8 Mon Sep 17 00:00:00 2001 From: Giovanna Lazzari Miotto <giovanna.lazzari.miotto@cern.ch> Date: Thu, 14 Mar 2024 11:45:13 +0100 Subject: [PATCH] Refactor some GetFile logic into MaybeCommitFile --- src/OutputByOrbit.cc | 4 ++-- src/OutputFileHandler.cc | 40 ++++++++++++++++++++++++++-------------- src/OutputFileHandler.h | 2 +- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/OutputByOrbit.cc b/src/OutputByOrbit.cc index e5e1f9fa..4c89b68d 100644 --- a/src/OutputByOrbit.cc +++ b/src/OutputByOrbit.cc @@ -32,7 +32,7 @@ void OutputByOrbitStream::OutputFixedOrbits(Slice &out) { if (!out.isInitialized()) { return; } - auto file = output_file_handler_.getFile(control_.run_number, index); + auto file = output_file_handler_.GetFile(control_.run_number, index); size_t n = file->Write(out.begin(), out.size()); output_file_handler_.upFileSize(n); output_file_handler_.upNOrbits(conf_.num_orbits_per_packet_); @@ -41,8 +41,8 @@ void OutputByOrbitStream::OutputFixedOrbits(Slice &out) { // file to close LOG(TRACE) << "the run was stopped. queueing the last file for close and " "rename "; + // output_file_handler_.write_EoR_file(); output_file_handler_.enqueue_current_file_for_close_and_move_maybe(); - // TODO: Need to write EoR file here, probably. } } } diff --git a/src/OutputFileHandler.cc b/src/OutputFileHandler.cc index 37a9b37e..1b6e1765 100644 --- a/src/OutputFileHandler.cc +++ b/src/OutputFileHandler.cc @@ -46,28 +46,39 @@ void OutputFileHandler::enqueue_current_file_for_close_and_move_maybe() { } } -std::shared_ptr<OutputFile>& OutputFileHandler::getFile(uint32_t run, uint32_t index) { +bool OutputFileHandler::MaybeCommitFile(uint32_t run, uint32_t index) { bool is_new_run = (current_run_number_ != static_cast<int>(run)); bool is_new_index = (current_index_ != static_cast<int>(index)); - // TODO: We should maybe move this out of this function... - if (current_run_number_ > 0 && is_new_run && getCMSSWHeaders()) { - OutputFileHandler::write_EoR_file(); + if (current_run_number_ >= 0 && is_new_run) { + // Write by default even without cmssw headers present + write_EoR_file(); } - if (is_new_run || is_new_index) { + bool do_commit_file = is_new_run || is_new_index; + + if (do_commit_file) { enqueue_current_file_for_close_and_move_maybe(); - if (is_new_run) { - run_NOrbits_ = 0; - LOG(TRACE) << "Previous run: " << current_run_number_ << " | New run: " << run; - } - if (is_new_index) { - LOG(TRACE) << "Previous index: " << current_index_ << " | New index: " << index; - } + } - current_index_ = static_cast<int>(index); + if (new_run) { + LOG(TRACE) << "Previous run: " << current_run_number_ << " | New run: " << run; + LOG(TRACE) << "Previous index: " << current_index_ << " | New index: " << index; + + run_NOrbits_ = 0; current_run_number_ = static_cast<int>(run); + current_index_ = static_cast<int>(index); run_dir_ = base_path_ + "/" + GetRunFormatted(current_run_number_); + } else if (is_new_index) { + LOG(TRACE) << "Previous index: " << current_index_ << " | New index: " << index; + current_index_ = static_cast<int>(index); + } + + return do_commit_file; +} + +std::shared_ptr<OutputFile>& OutputFileHandler::GetFile(uint32_t run, uint32_t index) { + if (MaybeCommitFile(run, index)) { open_new_file(); } return outputFile_; @@ -199,7 +210,8 @@ void OutputFileHandler::write_EoR_file() { assert(current_index_ > 0 && nOrbitsPerFile_ > 0); int ls = int(1) + (current_index_ * nOrbitsPerFile_) / constants::N_orbits_per_lumisection; std::stringstream EoR_filename; - EoR_filename << run_dir_ << "/" << GetRunFormatted(current_run_number_) << "_ls0000_EoR.jsn"; + EoR_filename << run_dir_ << "/" << GetRunFormatted(current_run_number_) << "_" + << GetLumiFormatted(0) << "_EoR.jsn"; LOG(TRACE) << "Writing EoR file " << EoR_filename.str(); std::fstream EoR_file; EoR_file.open(EoR_filename.str().c_str(), std::ios_base::out); diff --git a/src/OutputFileHandler.h b/src/OutputFileHandler.h index 7d27baa9..1a0a07dc 100644 --- a/src/OutputFileHandler.h +++ b/src/OutputFileHandler.h @@ -71,7 +71,7 @@ class OutputFileHandler { void enqueue_current_file_for_close_and_move_maybe(); - std::shared_ptr<OutputFile> &getFile(uint32_t run, uint32_t index); + std::shared_ptr<OutputFile> &GetFile(uint32_t run, uint32_t index); bool HasOpenFile() { return outputFile_->IsOpen(); } -- GitLab