2021-08-23 10:00:36 -04:00
|
|
|
#ifndef MASKFILE_H
|
|
|
|
#define MASKFILE_H
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <fstream>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "Nucleus.h"
|
2021-10-08 14:17:20 -04:00
|
|
|
#include "RxnType.h"
|
2021-08-23 10:00:36 -04:00
|
|
|
|
|
|
|
namespace Mask {
|
|
|
|
|
2021-09-03 17:03:41 -04:00
|
|
|
struct MaskFileHeader {
|
2021-10-08 14:17:20 -04:00
|
|
|
RxnType rxn_type = RxnType::None;
|
2021-09-03 17:03:41 -04:00
|
|
|
int nsamples = -1;
|
2021-08-23 10:00:36 -04:00
|
|
|
};
|
|
|
|
|
2021-09-03 17:03:41 -04:00
|
|
|
struct MaskFileData {
|
|
|
|
std::vector<double> E, KE, p, theta, phi; //ordered: target, (if not decay)projectile, ejectile, residual, break1...
|
|
|
|
std::vector<int> Z, A;
|
|
|
|
std::vector<bool> detect_flag;
|
|
|
|
bool eof = false; //flag on end of file
|
|
|
|
};
|
2021-08-23 10:00:36 -04:00
|
|
|
|
2021-09-03 17:03:41 -04:00
|
|
|
class MaskFile {
|
|
|
|
public:
|
|
|
|
enum class FileType {
|
|
|
|
read,
|
|
|
|
write,
|
|
|
|
append,
|
|
|
|
none
|
|
|
|
};
|
2021-08-23 10:00:36 -04:00
|
|
|
|
2021-09-03 17:03:41 -04:00
|
|
|
MaskFile();
|
|
|
|
MaskFile(const std::string& name, MaskFile::FileType type);
|
|
|
|
bool Open(const std::string& name, MaskFile::FileType type);
|
|
|
|
inline bool IsOpen() { return file.is_open(); }
|
|
|
|
void Close();
|
|
|
|
|
2021-10-08 14:17:20 -04:00
|
|
|
void WriteHeader(RxnType rxn_type, int nsamples);
|
2021-10-08 16:20:46 -04:00
|
|
|
void WriteData(const std::vector<Nucleus>& data);
|
|
|
|
void WriteData(const MaskFileData& data);
|
2021-09-03 17:03:41 -04:00
|
|
|
MaskFileHeader ReadHeader();
|
|
|
|
MaskFileData ReadData();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
2021-08-23 10:00:36 -04:00
|
|
|
|
2021-09-03 17:03:41 -04:00
|
|
|
FileType file_type;
|
|
|
|
std::string filename;
|
2021-12-03 09:28:08 -05:00
|
|
|
uint64_t buffer_position;
|
|
|
|
uint64_t buffer_end;
|
2021-10-08 14:37:26 -04:00
|
|
|
uint32_t data_size;
|
2021-10-08 14:17:20 -04:00
|
|
|
RxnType m_rxn_type;
|
2021-10-08 14:37:26 -04:00
|
|
|
uint32_t buffersize_bytes;
|
2021-09-03 17:03:41 -04:00
|
|
|
|
|
|
|
std::fstream file;
|
|
|
|
|
|
|
|
std::vector<char> data_buffer;
|
|
|
|
|
2021-10-08 14:37:26 -04:00
|
|
|
static constexpr uint32_t onestep_rxn_n = 2;
|
|
|
|
static constexpr uint32_t twostep_rxn_n = 4;
|
|
|
|
static constexpr uint32_t threestep_rxn_n = 6;
|
2021-09-03 17:03:41 -04:00
|
|
|
|
2021-10-08 14:37:26 -04:00
|
|
|
static constexpr uint64_t buffersize = 10000; //number of events
|
2021-09-03 17:03:41 -04:00
|
|
|
static constexpr int width = 0;
|
|
|
|
static constexpr int precision = 3;
|
2021-08-23 10:00:36 -04:00
|
|
|
|
2021-09-03 17:03:41 -04:00
|
|
|
static constexpr std::size_t double_size = sizeof(double);
|
2021-10-08 14:37:26 -04:00
|
|
|
static constexpr std::size_t int_size = sizeof(uint32_t);
|
2021-09-03 17:03:41 -04:00
|
|
|
static constexpr std::size_t bool_size = sizeof(bool);
|
|
|
|
};
|
2021-08-23 10:00:36 -04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|