diff --git a/src/OutputFile.h b/src/OutputFile.h index 7d0d589a2b3a8d71a0db15cd26a2b3a90658fd5d..4c009f05b7a934347100f8bd403d0cfa76650f1a 100644 --- a/src/OutputFile.h +++ b/src/OutputFile.h @@ -10,6 +10,7 @@ #include <fstream> #include <iostream> #include <string> +#include <string_view> #include <thread> #include <utility> #include <vector> @@ -29,11 +30,57 @@ class OutputFile { lumisection_(lumisection), index_(index), rundir_(rundir) {} + OutputFile() : filePtr_(NULL), fileName_(""), fileHeader_(0, 0, 0, 0, 0, 0) {} + + OutputFile(std::string_view filepath, std::string_view filename, std::string_view run_dir, + FRDFileHeader_v2& header, uint32_t num_lumisection, uint32_t file_index) + : filepath_(filepath), + fileName_(filename), + rundir_(run_dir), + fileHeader_(header), + lumisection_(num_lumisection), + index_(file_index), + file_(filepath_ + "/" + fileName_, std::fstream::out | std::fstream::binary) { + // try { + // fstream(filepath_ + "/" + fileName_, ios::out | ios::binary); + // } catch (std::exception &e) { + // LOG(FATAL) << "Could not open file: " << filepath_ + "/" + fileName_ + // << ", exception: " << e.what(); + // } + } + + OutputFile(const OutputFile&) = delete; // Delete copy constructor + OutputFile& operator=(const OutputFile&) = delete; // Delete copy assignment operator + + OutputFile(OutputFile&& other) noexcept + : filepath_(std::move(other.filepath_)), + fileName_(std::move(other.fileName_)), + rundir_(std::move(other.rundir_)), + fileHeader_(std::move(other.fileHeader_)), + lumisection_(other.lumisection_), + index_(other.index_) { + file_ = std::move(other.file_); + } + + OutputFile& operator=(OutputFile&& other) noexcept { + if (this != &other) { + filepath_ = std::move(other.filepath_); + fileName_ = std::move(other.fileName_); + rundir_ = std::move(other.rundir_); + fileHeader_ = std::move(other.fileHeader_); + lumisection_ = other.lumisection_; + index_ = other.index_; + file_ = std::move(other.file_); + } + return *this; + } + std::string getFileName() { return fileName_; } FILE* getFilePtr() { return filePtr_; } FRDFileHeader_v2 getFileHeader() { return fileHeader_; } std::string getRunDir() { return rundir_; } + bool writeFileHeader() { fseek(filePtr_, 0, SEEK_SET); size_t written = fwrite(&fileHeader_, 1, sizeof(fileHeader_), filePtr_); @@ -84,10 +131,13 @@ class OutputFile { private: std::string filepath_; std::string fileName_; + std::string rundir_; + uint32_t index_; FRDFileHeader_v2 fileHeader_; uint32_t lumisection_; - uint32_t index_; - std::string rundir_; + + std::fstream file_; + FILE* filePtr_; }; #endif