mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-07 13:10:42 +02:00
move office
This commit is contained in:
parent
66f87b0f51
commit
718682aec8
6
.vscode/c_cpp_properties.json
vendored
6
.vscode/c_cpp_properties.json
vendored
@ -3,14 +3,16 @@
|
|||||||
{
|
{
|
||||||
"name": "Linux",
|
"name": "Linux",
|
||||||
"includePath": [
|
"includePath": [
|
||||||
"${workspaceFolder}/**"
|
"${workspaceFolder}/**",
|
||||||
|
"/usr/include"
|
||||||
],
|
],
|
||||||
"defines": [],
|
"defines": [],
|
||||||
"compilerPath": "/usr/bin/g++",
|
"compilerPath": "/usr/bin/g++",
|
||||||
"cStandard": "c17",
|
"cStandard": "c17",
|
||||||
"cppStandard": "c++17",
|
"cppStandard": "c++17",
|
||||||
"intelliSenseMode": "linux-gcc-x64",
|
"intelliSenseMode": "linux-gcc-x64",
|
||||||
"configurationProvider": "ms-vscode.cmake-tools"
|
"configurationProvider": "ms-vscode.cmake-tools",
|
||||||
|
"compilerArgs": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"version": 4
|
"version": 4
|
||||||
|
@ -9,6 +9,7 @@ project(aare
|
|||||||
|
|
||||||
cmake_policy(SET CMP0135 NEW)
|
cmake_policy(SET CMP0135 NEW)
|
||||||
|
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
target_include_directories(aare PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include )
|
|
||||||
|
|
||||||
target_include_directories(aare PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
target_include_directories(aare PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
|
||||||
|
target_sources(aare PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/defs.cpp")
|
||||||
|
|
||||||
|
|
||||||
|
27
src/common/defs.cpp
Normal file
27
src/common/defs.cpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#include "defs.hpp"
|
||||||
|
|
||||||
|
template <> DetectorType StringTo(std::string name) {
|
||||||
|
if (name == "Jungfrau")
|
||||||
|
return DetectorType::Jungfrau;
|
||||||
|
else if (name == "Eiger")
|
||||||
|
return DetectorType::Eiger;
|
||||||
|
else if (name == "Mythen3")
|
||||||
|
return DetectorType::Mythen3;
|
||||||
|
else if (name == "Moench")
|
||||||
|
return DetectorType::Moench;
|
||||||
|
else {
|
||||||
|
auto msg = fmt::format("Could not decode dector from: \"{}\"", name);
|
||||||
|
throw std::runtime_error(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <> TimingMode StringTo(std::string mode){
|
||||||
|
if (mode == "auto")
|
||||||
|
return TimingMode::Auto;
|
||||||
|
else if(mode == "trigger")
|
||||||
|
return TimingMode::Trigger;
|
||||||
|
else{
|
||||||
|
auto msg = fmt::format("Could not decode timing mode from: \"{}\"", mode);
|
||||||
|
throw std::runtime_error(msg);
|
||||||
|
}
|
||||||
|
}
|
47
src/common/defs.hpp
Normal file
47
src/common/defs.hpp
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <vector>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <string_view>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <fmt/format.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint64_t frameNumber;
|
||||||
|
uint32_t expLength;
|
||||||
|
uint32_t packetNumber;
|
||||||
|
uint64_t bunchId;
|
||||||
|
uint64_t timestamp;
|
||||||
|
uint16_t modId;
|
||||||
|
uint16_t row;
|
||||||
|
uint16_t column;
|
||||||
|
uint16_t reserved;
|
||||||
|
uint32_t debug;
|
||||||
|
uint16_t roundRNumber;
|
||||||
|
uint8_t detType;
|
||||||
|
uint8_t version;
|
||||||
|
uint8_t packetMask[64];
|
||||||
|
}__attribute__((packed)) sls_detector_header;
|
||||||
|
|
||||||
|
struct xy {
|
||||||
|
int row;
|
||||||
|
int col;
|
||||||
|
};
|
||||||
|
|
||||||
|
using image_shape = std::array<ssize_t, 2>;
|
||||||
|
using dynamic_shape = std::vector<ssize_t>;
|
||||||
|
|
||||||
|
enum class DetectorType { Jungfrau, Eiger, Mythen3, Moench };
|
||||||
|
|
||||||
|
enum class TimingMode {Auto, Trigger};
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
T StringTo(std::string sv){
|
||||||
|
return T(sv);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <> DetectorType StringTo(std::string);
|
||||||
|
|
||||||
|
template <> TimingMode StringTo(std::string);
|
||||||
|
|
@ -1,14 +0,0 @@
|
|||||||
#include <array>
|
|
||||||
#include <vector>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
using image_shape = std::array<ssize_t, 2>;
|
|
||||||
using dynamic_shape = std::vector<ssize_t>;
|
|
||||||
|
|
||||||
enum class DetectorType { Jungfrau, Eiger, Mythen3, Moench };
|
|
||||||
|
|
||||||
enum class TimingMode {Auto, Trigger};
|
|
||||||
DetectorType StringTo(std::string_view name);
|
|
@ -7,6 +7,7 @@
|
|||||||
class File
|
class File
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
std::filesystem::path fname;
|
||||||
std::filesystem::path base_path;
|
std::filesystem::path base_path;
|
||||||
std::string base_name,ext;
|
std::string base_name,ext;
|
||||||
int findex, n_subfiles;
|
int findex, n_subfiles;
|
||||||
@ -16,6 +17,7 @@ public:
|
|||||||
DetectorType type;
|
DetectorType type;
|
||||||
TimingMode timing_mode;
|
TimingMode timing_mode;
|
||||||
int subfile_rows, subfile_cols;
|
int subfile_rows, subfile_cols;
|
||||||
|
bool quad {false};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -23,18 +25,31 @@ public:
|
|||||||
ssize_t rows{};
|
ssize_t rows{};
|
||||||
ssize_t cols{};
|
ssize_t cols{};
|
||||||
uint8_t bitdepth{};
|
uint8_t bitdepth{};
|
||||||
DetectorType type{};
|
std::vector<xy> positions;
|
||||||
|
|
||||||
// File();
|
// File();
|
||||||
// ~File();
|
// ~File();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline size_t bytes_per_frame() const{
|
inline size_t bytes_per_frame() const{
|
||||||
return rows*cols*bitdepth/8;
|
return rows*cols*bitdepth/8;
|
||||||
|
|
||||||
}
|
}
|
||||||
inline size_t pixels() const{
|
inline size_t pixels() const{
|
||||||
return rows*cols;
|
return rows*cols;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO! Deal with fast quad and missing files
|
||||||
|
inline void find_number_of_subfiles() {
|
||||||
|
int n_mod = 0;
|
||||||
|
while (std::filesystem::exists(data_fname(n_mod, 0))) {
|
||||||
|
n_mod++;
|
||||||
|
}
|
||||||
|
n_subfiles = n_mod;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline std::filesystem::path master_fname() {
|
inline std::filesystem::path master_fname() {
|
||||||
return base_path / fmt::format("{}_master_{}{}", base_name, findex, ext);
|
return base_path / fmt::format("{}_master_{}{}", base_name, findex, ext);
|
||||||
}
|
}
|
||||||
|
@ -39,3 +39,38 @@ void FileFactory::parse_fname(File& file) {
|
|||||||
pos = file.base_name.find("_master_");
|
pos = file.base_name.find("_master_");
|
||||||
file.base_name.erase(pos);
|
file.base_name.erase(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename Header=sls_detector_header>
|
||||||
|
Header FileFactory::read_header(const std::filesystem::path &fname) {
|
||||||
|
Header h{};
|
||||||
|
FILE *fp = fopen(fname.c_str(), "r");
|
||||||
|
if (!fp)
|
||||||
|
throw std::runtime_error(
|
||||||
|
fmt::format("Could not open: {} for reading", fname.c_str()));
|
||||||
|
|
||||||
|
size_t rc = fread(reinterpret_cast<char *>(&h), sizeof(h), 1, fp);
|
||||||
|
fclose(fp);
|
||||||
|
if (rc != 1)
|
||||||
|
throw std::runtime_error("Could not read header from file");
|
||||||
|
return h;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileFactory::find_geometry(File& file) {
|
||||||
|
uint16_t r{};
|
||||||
|
uint16_t c{};
|
||||||
|
for (int i = 0; i != file.n_subfiles; ++i) {
|
||||||
|
auto h = this->read_header(file.data_fname(i, 0));
|
||||||
|
r = std::max(r, h.row);
|
||||||
|
c = std::max(c, h.column);
|
||||||
|
|
||||||
|
file.positions.push_back({h.row, h.column});
|
||||||
|
}
|
||||||
|
r++;
|
||||||
|
c++;
|
||||||
|
|
||||||
|
file.rows = r * file.subfile_rows;
|
||||||
|
file.cols = c * file.subfile_cols;
|
||||||
|
|
||||||
|
file.rows += (r - 1) * cfg.module_gap_row;
|
||||||
|
}
|
@ -12,10 +12,13 @@ public:
|
|||||||
// virtual int deleteFile() = 0;
|
// virtual int deleteFile() = 0;
|
||||||
virtual File loadFile(){};//TODO: add option to load all file to memory or keep it on disk
|
virtual File loadFile(){};//TODO: add option to load all file to memory or keep it on disk
|
||||||
virtual void parse_metadata(File&){};
|
virtual void parse_metadata(File&){};
|
||||||
|
|
||||||
// inline fs::path master_fname() const {
|
|
||||||
// return base_path / fmt::format("{}_master_{}{}", base_name, findex, ext);}
|
void find_geometry(File&){};
|
||||||
|
|
||||||
void parse_fname(File&);
|
void parse_fname(File&);
|
||||||
|
|
||||||
|
template <typename Header> Header read_header(const std::filesystem::path &fname);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -3,13 +3,14 @@
|
|||||||
#include "helpers.hpp"
|
#include "helpers.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include "defs.hpp"
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
JsonFileFactory::JsonFileFactory(std::filesystem::path fpath){
|
JsonFileFactory::JsonFileFactory(std::filesystem::path fpath){
|
||||||
if(not is_master_file(fpath))
|
if(not is_master_file(fpath))
|
||||||
throw std::runtime_error("Json file is not a master file");
|
throw std::runtime_error("Json file is not a master file");
|
||||||
@ -23,19 +24,21 @@ void JsonFileFactory::parse_metadata(File& file){
|
|||||||
ifs >> j;
|
ifs >> j;
|
||||||
double v = j["Version"];
|
double v = j["Version"];
|
||||||
file.version = fmt::format("{:.1f}", v);
|
file.version = fmt::format("{:.1f}", v);
|
||||||
file.type = StringTo<DetectorType>(j["Detector Type"].get<std::string>());
|
std::string tmp;
|
||||||
|
j["Detector Type"].get_to(tmp);
|
||||||
|
file.type = StringTo<DetectorType>(tmp);
|
||||||
file.timing_mode = StringTo<TimingMode>(j["Timing Mode"].get<std::string>());
|
file.timing_mode = StringTo<TimingMode>(j["Timing Mode"].get<std::string>());
|
||||||
file.total_frames = j["Frames in File"];
|
file.total_frames = j["Frames in File"];
|
||||||
file.subfile_cols = j["Pixels"]["x"];
|
file.subfile_cols = j["Pixels"]["x"];
|
||||||
file.subfile_rows = j["Pixels"]["y"];
|
file.subfile_rows = j["Pixels"]["y"];
|
||||||
if (type_ == DetectorType::Moench)
|
if (file.type == DetectorType::Moench)
|
||||||
bitdepth_ = 16;
|
file.bitdepth = 16;
|
||||||
else
|
else
|
||||||
bitdepth_ = j["Dynamic Range"];
|
file.bitdepth = j["Dynamic Range"];
|
||||||
|
|
||||||
// only Eiger had quad
|
// only Eiger had quad
|
||||||
if (type_ == DetectorType::Eiger) {
|
if (file.type == DetectorType::Eiger) {
|
||||||
quad_ = (j["Quad"] == 1);
|
file.quad = (j["Quad"] == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -46,8 +49,12 @@ void JsonFileFactory::parse_metadata(File& file){
|
|||||||
File JsonFileFactory::loadFile(){
|
File JsonFileFactory::loadFile(){
|
||||||
std::cout<<"Loading json file"<<std::endl;
|
std::cout<<"Loading json file"<<std::endl;
|
||||||
JsonFile file = JsonFile();
|
JsonFile file = JsonFile();
|
||||||
|
file.fname = fpath;
|
||||||
this->parse_fname(file);
|
this->parse_fname(file);
|
||||||
this->parse_metadata(file);
|
this->parse_metadata(file);
|
||||||
|
file.find_number_of_subfiles();
|
||||||
|
this->find_geometry(file);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,5 +9,6 @@ public:
|
|||||||
void parse_metadata(File&) override;
|
void parse_metadata(File&) override;
|
||||||
JsonFileFactory(std::filesystem::path fpath);
|
JsonFileFactory(std::filesystem::path fpath);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user