Skip to content
Snippets Groups Projects
Commit 9f4142a9 authored by Giovanna Lazzari Miotto's avatar Giovanna Lazzari Miotto :mushroom:
Browse files

Add Rename and Flush functions

parent 15e74a59
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <atomic> #include <atomic>
#include <cstdint> #include <cstdint>
#include <cstdio> #include <cstdio>
#include <filesystem>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <string> #include <string>
...@@ -14,6 +15,9 @@ ...@@ -14,6 +15,9 @@
#include <vector> #include <vector>
#include "cmssw/FRDFileHeader_v2.h" #include "cmssw/FRDFileHeader_v2.h"
#include "log.h"
namespace fs = std::filesystem;
class OutputFile { class OutputFile {
public: public:
...@@ -53,13 +57,32 @@ class OutputFile { ...@@ -53,13 +57,32 @@ class OutputFile {
} }
} }
std::string GetFullPath() const { return fs::path(rundir_) / filepath_ / fileName_; }
void Rename(const std::string& new_path) const {
fs::path from = GetFullPath();
fs::path to = new_path;
try {
fs::rename(from, to);
} catch (fs::filesystem_error& err) {
LOG(FATAL) << "Error renaming file: " << err.what();
}
}
void Flush() {
if (file_.is_open()) {
file_.close();
}
}
void setFileHeader(FRDFileHeader_v2 fileHeader) { fileHeader_ = fileHeader; } void setFileHeader(FRDFileHeader_v2 fileHeader) { fileHeader_ = fileHeader; }
uint32_t Lumisection() { return lumisection_; } uint32_t Lumisection() { return lumisection_; }
uint32_t Index() { return index_; } uint32_t Index() { return index_; }
private: private:
FILE* filePtr_; std::string filepath_;
std::string fileName_; std::string fileName_;
FRDFileHeader_v2 fileHeader_; FRDFileHeader_v2 fileHeader_;
uint32_t lumisection_; uint32_t lumisection_;
......
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