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

OutputFile: Add new constructors

parent 9f4142a9
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <string_view>
#include <thread> #include <thread>
#include <utility> #include <utility>
#include <vector> #include <vector>
...@@ -29,11 +30,57 @@ class OutputFile { ...@@ -29,11 +30,57 @@ class OutputFile {
lumisection_(lumisection), lumisection_(lumisection),
index_(index), index_(index),
rundir_(rundir) {} rundir_(rundir) {}
OutputFile() : filePtr_(NULL), fileName_(""), fileHeader_(0, 0, 0, 0, 0, 0) {} 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_; } std::string getFileName() { return fileName_; }
FILE* getFilePtr() { return filePtr_; } FILE* getFilePtr() { return filePtr_; }
FRDFileHeader_v2 getFileHeader() { return fileHeader_; } FRDFileHeader_v2 getFileHeader() { return fileHeader_; }
std::string getRunDir() { return rundir_; } std::string getRunDir() { return rundir_; }
bool writeFileHeader() { bool writeFileHeader() {
fseek(filePtr_, 0, SEEK_SET); fseek(filePtr_, 0, SEEK_SET);
size_t written = fwrite(&fileHeader_, 1, sizeof(fileHeader_), filePtr_); size_t written = fwrite(&fileHeader_, 1, sizeof(fileHeader_), filePtr_);
...@@ -84,10 +131,13 @@ class OutputFile { ...@@ -84,10 +131,13 @@ class OutputFile {
private: private:
std::string filepath_; std::string filepath_;
std::string fileName_; std::string fileName_;
std::string rundir_;
uint32_t index_;
FRDFileHeader_v2 fileHeader_; FRDFileHeader_v2 fileHeader_;
uint32_t lumisection_; uint32_t lumisection_;
uint32_t index_;
std::string rundir_; std::fstream file_;
FILE* filePtr_;
}; };
#endif #endif
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