From f6cc59c581c9c209ac52b88faba8773207ef886a Mon Sep 17 00:00:00 2001
From: Giovanna Lazzari Miotto <giovanna.lazzari.miotto@cern.ch>
Date: Tue, 23 Jul 2024 10:54:26 +0200
Subject: [PATCH] ref: Move run filename formatting to Detail ns

---
 src/OutputFileHandler.cc | 50 +++++++++++++++++++++++++++++++---------
 src/tools.cc             | 18 ---------------
 src/tools.h              |  4 ----
 3 files changed, 39 insertions(+), 33 deletions(-)

diff --git a/src/OutputFileHandler.cc b/src/OutputFileHandler.cc
index 922f8850..c1edb757 100644
--- a/src/OutputFileHandler.cc
+++ b/src/OutputFileHandler.cc
@@ -20,6 +20,33 @@ tbb::concurrent_bounded_queue<OutputFile> FileSink::commit_queue_ =
     tbb::concurrent_bounded_queue<OutputFile>();
 std::atomic<bool> FileSink::running_{true};
 
+std::string Detail::FormatRun(uint32_t run_number) {
+  std::stringstream ss;
+  ss << "run" << std::setfill('0') << std::setw(6) << run_number;
+  return ss.str();
+}
+
+std::string Detail::FormatLumisection(uint32_t ls) {
+  std::stringstream ss;
+  ss << "ls" << std::setfill('0') << std::setw(4) << ls;
+  return ss.str();
+}
+
+std::string Detail::FormatFileIndex(uint32_t index) {
+  std::stringstream ss;
+  ss << "index" << std::setfill('0') << std::setw(6) << index;
+  return ss.str();
+}
+// namespace Detail
+
+std::string OutputFileHandler::GetWorkingPath() const {
+  return base_path_ + "/" + Detail::FormatRun(run_.number) + "/in_progress";
+}
+
+std::string OutputFileHandler::GetPermanentPath() const {
+  return base_path_ + "/" + Detail::FormatRun(run_.number);
+}
+
 void FileSink::ProcessQueue() {
   OutputFile file;
   while (running_ && !commit_queue_.empty()) {
@@ -136,11 +163,11 @@ void OutputFileHandler::open_new_file() {
 // Create a properly formatted file name
 std::string OutputFileHandler::FormatFilename(uint32_t run_number, uint32_t index, uint32_t ls) {
   if (getCMSSWHeaders())
-    return tools::FormatRun(run_number) + "_" + tools::FormatLumisection(ls) + "_" +
-           tools::FormatFileIndex(index % (ls_.max_index + 1)) + loc_.filename_suffix;
+    return Detail::FormatRun(run_number) + "_" + Detail::FormatLumisection(ls) + "_" +
+           Detail::FormatFileIndex(index % (ls_.max_index + 1)) + loc_.filename_suffix;
   else
-    return loc_.filename_prefix + "_" + tools::FormatRun(run_number) + "_" +
-           tools::FormatFileIndex(index) + loc_.filename_suffix;
+    return loc_.filename_prefix + "_" + Detail::FormatRun(run_number) + "_" +
+           Detail::FormatFileIndex(index) + loc_.filename_suffix;
 }
 
 void OutputFileHandler::CommitLumisection(uint32_t ls_index) {
@@ -154,8 +181,8 @@ void OutputFileHandler::CommitLumisection(uint32_t ls_index) {
 void OutputFileHandler::WriteLumisectionFooter(uint32_t run_number, uint32_t ls_id,
                                                LumisectionMetadata md) {
   auto filename =
-      tools::FormatRun(run_number) + "_" + tools::FormatLumisection(ls_id) + "_EoLS.jsn";
-  auto full_path = loc_.GetRunDir(run_number) + "/" + filename;
+      Detail::FormatRun(run_number) + "_" + Detail::FormatLumisection(ls_id) + "_EoLS.jsn";
+  auto full_path = loc_.GetRunDir(run_.number) + "/" + filename;
   LOG(TRACE) << "Writing EoLS footer file " << filename;
 
   std::fstream ls_stream;
@@ -165,7 +192,7 @@ void OutputFileHandler::WriteLumisectionFooter(uint32_t run_number, uint32_t ls_
             << md.num_orbits << "\","                           // Total Events
             << "\"0\",\""                                       // NLost Events
             << md.file_size << "\"],\n  \"definition\":\""      // NBytes
-            << "/fff/ramdisk/" << tools::FormatRun(run_number)
+            << "/fff/ramdisk/" << Detail::FormatRun(run_number)
             << "/jsd/EoLS.jsd\",\n  \"source\":\"l1scout\"\n}";
   ls_stream.close();
 }
@@ -178,15 +205,16 @@ void OutputFileHandler::WriteRunFooter() {
     CommitLumisection(ls_index);
   }
 
-  auto EoR_filename = loc_.GetRunDir(run_.number) + "_" + tools::FormatLumisection(0) + "_EoR.jsn";
-  LOG(TRACE) << "Writing EoR file " << EoR_filename;
+  auto filename = Detail::FormatRun(run_.number) + "_" + Detail::FormatLumisection(0) + "_EoR.jsn";
+  auto full_path = loc_.GetRunDir(run_.number) + "/" + filename;
+  LOG(TRACE) << "Writing EoR file " << full_path;
   std::fstream EoR_file;
-  EoR_file.open(EoR_filename.c_str(), std::ios_base::out);
+  EoR_file.open(full_path.c_str(), std::ios_base::out);
   EoR_file << "{\n  \"data\":[\"" << run_.num_orbits   // NEvents
            << "\",\"" << run_.num_files                // NFiles
            << "\",\"" << ls_index << "\",\""           // NLumis
            << ls_index << "\"],\n  \"definition\":\""  // LastLumi
-           << "/fff/ramdisk/" << tools::FormatRun(run_.number)
+           << "/fff/ramdisk/" << Detail::FormatRun(run_.number)
            << "/jsd/EoR.jsd\",\n  \"source\":\"l1scout\"\n}";
   EoR_file.close();
 }
\ No newline at end of file
diff --git a/src/tools.cc b/src/tools.cc
index 24f4fd40..cbb6f318 100644
--- a/src/tools.cc
+++ b/src/tools.cc
@@ -6,24 +6,6 @@
 
 namespace tools {
 
-std::string FormatRun(uint32_t run_number) {
-  std::stringstream ss;
-  ss << "run" << std::setfill('0') << std::setw(6) << run_number;
-  return ss.str();
-}
-
-std::string FormatLumisection(uint32_t ls) {
-  std::stringstream ss;
-  ss << "ls" << std::setfill('0') << std::setw(4) << ls;
-  return ss.str();
-}
-
-std::string FormatFileIndex(uint32_t index) {
-  std::stringstream ss;
-  ss << "index" << std::setfill('0') << std::setw(6) << index;
-  return ss.str();
-}
-
 void CreateDirectory(std::string &dir_path) {
   struct stat sb;
   LOG(TRACE) << "checking if working directory " << dir_path << " exists ";
diff --git a/src/tools.h b/src/tools.h
index 8b9da6af..e5094c30 100644
--- a/src/tools.h
+++ b/src/tools.h
@@ -18,10 +18,6 @@
 
 namespace tools {
 
-std::string FormatRun(uint32_t run_number);
-std::string FormatLumisection(uint32_t ls);
-std::string FormatFileIndex(uint32_t index);
-
 void CreateDirectory(std::string &dir_path);
 
 /*
-- 
GitLab