mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-05 12:30:39 +02:00
save work
This commit is contained in:
parent
9906c5886c
commit
a6ff0fc794
@ -2,6 +2,6 @@ BasedOnStyle: LLVM
|
||||
IndentWidth: 4
|
||||
|
||||
UseTab: Never
|
||||
ColumnLimit: 80
|
||||
ColumnLimit: 120
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveMacros: true
|
3
.vscode/c_cpp_properties.json
vendored
3
.vscode/c_cpp_properties.json
vendored
@ -12,7 +12,8 @@
|
||||
"cppStandard": "c++17",
|
||||
"intelliSenseMode": "linux-gcc-x64",
|
||||
"configurationProvider": "ms-vscode.cmake-tools",
|
||||
"compilerArgs": []
|
||||
"compilerArgs": [],
|
||||
"compileCommands": "/home/l_bechir/github/aare/build/compile_commands.json"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
|
55
.vscode/launch.json
vendored
Normal file
55
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "(gdb) Launch",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/build/aare",
|
||||
"args": [],
|
||||
"stopAtEntry": true,
|
||||
"cwd": "${fileDirname}",
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"MIMode": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
},
|
||||
{
|
||||
"description": "Set Disassembly Flavor to Intel",
|
||||
"text": "-gdb-set disassembly-flavor intel",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "C/C++: g++ build and debug active file",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${fileDirname}/${fileBasenameNoExtension}",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${fileDirname}",
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"MIMode": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
},
|
||||
{
|
||||
"description": "Set Disassembly Flavor to Intel",
|
||||
"text": "-gdb-set disassembly-flavor intel",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
],
|
||||
"preLaunchTask": "C/C++: g++ build active file",
|
||||
"miDebuggerPath": "/usr/bin/gdb"
|
||||
}
|
||||
],
|
||||
"version": "2.0.0"
|
||||
}
|
17
.vscode/settings.json
vendored
17
.vscode/settings.json
vendored
@ -70,7 +70,22 @@
|
||||
"stop_token": "cpp",
|
||||
"thread": "cpp",
|
||||
"valarray": "cpp",
|
||||
"variant": "cpp"
|
||||
"variant": "cpp",
|
||||
"bitset": "cpp",
|
||||
"charconv": "cpp",
|
||||
"chrono": "cpp",
|
||||
"format": "cpp",
|
||||
"__bit_reference": "cpp",
|
||||
"__config": "cpp",
|
||||
"__hash_table": "cpp",
|
||||
"__locale": "cpp",
|
||||
"__node_handle": "cpp",
|
||||
"__split_buffer": "cpp",
|
||||
"__threading_support": "cpp",
|
||||
"__verbose_abort": "cpp",
|
||||
"execution": "cpp",
|
||||
"ios": "cpp",
|
||||
"locale": "cpp"
|
||||
},
|
||||
"C_Cpp.errorSquiggles": "enabled"
|
||||
}
|
25
.vscode/tasks.json
vendored
Normal file
25
.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"tasks": [
|
||||
{
|
||||
"type": "cppbuild",
|
||||
"label": "C/C++: g++ build active file",
|
||||
"command": "/usr/bin/g++",
|
||||
"args": [
|
||||
"-fdiagnostics-color=always",
|
||||
"-g",
|
||||
"${file}",
|
||||
"-o",
|
||||
"${fileDirname}/${fileBasenameNoExtension}"
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${fileDirname}"
|
||||
},
|
||||
"problemMatcher": [
|
||||
"$gcc"
|
||||
],
|
||||
"group": "build",
|
||||
"detail": "Task generated by Debugger."
|
||||
}
|
||||
],
|
||||
"version": "2.0.0"
|
||||
}
|
@ -25,7 +25,7 @@ find_package(fmt 6 REQUIRED)
|
||||
set(CMAKE_BUILD_TYPE "Debug")
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set(OPTIMIZATION_FLAGS "-Og -ggdb3")
|
||||
set(OPTIMIZATION_FLAGS "-Og -ggdb3 -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC")
|
||||
else()
|
||||
set(OPTIMIZATION_FLAGS "-O3")
|
||||
endif()
|
||||
|
BIN
data/m3_d0_f0_0.raw
Normal file
BIN
data/m3_d0_f0_0.raw
Normal file
Binary file not shown.
55
data/m3_master_0.json
Normal file
55
data/m3_master_0.json
Normal file
@ -0,0 +1,55 @@
|
||||
{
|
||||
"Version": 7.1,
|
||||
"Timestamp": "Wed Sep 21 13:48:10 2022",
|
||||
"Detector Type": "Mythen3",
|
||||
"Timing Mode": "auto",
|
||||
"Geometry": {
|
||||
"x": 1,
|
||||
"y": 1
|
||||
},
|
||||
"Image Size in bytes": 15360,
|
||||
"Pixels": {
|
||||
"x": 3840,
|
||||
"y": 1
|
||||
},
|
||||
"Max Frames Per File": 10000,
|
||||
"Frame Discard Policy": "nodiscard",
|
||||
"Frame Padding": 1,
|
||||
"Scan Parameters": "[disabled]",
|
||||
"Total Frames": 1,
|
||||
"Receiver Roi": {
|
||||
"xmin": 4294967295,
|
||||
"xmax": 4294967295,
|
||||
"ymin": 4294967295,
|
||||
"ymax": 4294967295
|
||||
},
|
||||
"Dynamic Range": 32,
|
||||
"Ten Giga": 1,
|
||||
"Period": "2ms",
|
||||
"Counter Mask": "0x7",
|
||||
"Exptime1": "0.1s",
|
||||
"Exptime2": "0.1s",
|
||||
"Exptime3": "0.1s",
|
||||
"GateDelay1": "0ns",
|
||||
"GateDelay2": "0ns",
|
||||
"GateDelay3": "0ns",
|
||||
"Gates": 1,
|
||||
"Threshold Energies": "[-1, -1, -1]",
|
||||
"Frames in File": 1,
|
||||
"Frame Header Format": {
|
||||
"Frame Number": "8 bytes",
|
||||
"SubFrame Number/ExpLength": "4 bytes",
|
||||
"Packet Number": "4 bytes",
|
||||
"Bunch ID": "8 bytes",
|
||||
"Timestamp": "8 bytes",
|
||||
"Module Id": "2 bytes",
|
||||
"Row": "2 bytes",
|
||||
"Column": "2 bytes",
|
||||
"Reserved": "2 bytes",
|
||||
"Debug": "4 bytes",
|
||||
"Round Robin Number": "2 bytes",
|
||||
"Detector Type": "1 byte",
|
||||
"Header Version": "1 byte",
|
||||
"Packets Caught Mask": "64 bytes"
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ target_include_directories(aare PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
|
||||
set(FILE_IO_SOURCES "file/File.cpp"
|
||||
"file/JsonFile.cpp"
|
||||
"file/SubFile.cpp"
|
||||
"file_factory/FileFactory.cpp"
|
||||
"file_factory/JsonFileFactory.cpp"
|
||||
"file_factory/RawFileFactory.cpp"
|
||||
|
@ -1,15 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include "defs.hpp"
|
||||
#include <filesystem>
|
||||
#include <fmt/core.h>
|
||||
#include "SubFile.hpp"
|
||||
|
||||
class File
|
||||
{
|
||||
public:
|
||||
std::filesystem::path fname;
|
||||
struct RawFileConfig {
|
||||
int module_gap_row{};
|
||||
int module_gap_col{};
|
||||
|
||||
bool operator==(const RawFileConfig &other) const {
|
||||
if (module_gap_col != other.module_gap_col)
|
||||
return false;
|
||||
if (module_gap_row != other.module_gap_row)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
class File {
|
||||
private:
|
||||
using config = RawFileConfig;
|
||||
public:
|
||||
std::vector<SubFileVariants> subfiles;
|
||||
std::filesystem::path fname;
|
||||
std::filesystem::path base_path;
|
||||
std::string base_name,ext;
|
||||
std::string base_name, ext;
|
||||
int findex, n_subfiles;
|
||||
size_t total_frames{};
|
||||
|
||||
@ -17,27 +35,22 @@ std::filesystem::path fname;
|
||||
DetectorType type;
|
||||
TimingMode timing_mode;
|
||||
int subfile_rows, subfile_cols;
|
||||
bool quad {false};
|
||||
|
||||
|
||||
|
||||
bool quad{false};
|
||||
|
||||
ssize_t rows{};
|
||||
ssize_t cols{};
|
||||
uint8_t bitdepth{};
|
||||
std::vector<xy> positions;
|
||||
|
||||
config cfg{0,0};
|
||||
// File();
|
||||
// ~File();
|
||||
|
||||
|
||||
|
||||
|
||||
inline size_t bytes_per_frame() const{
|
||||
return rows*cols*bitdepth/8;
|
||||
}
|
||||
inline size_t pixels() const{
|
||||
return rows*cols;
|
||||
inline size_t bytes_per_frame() const { return rows * cols * bitdepth / 8; }
|
||||
inline size_t pixels() const { return rows * cols; }
|
||||
inline void set_config(int row,int col){
|
||||
cfg.module_gap_row = row;
|
||||
cfg.module_gap_col = col;
|
||||
}
|
||||
|
||||
// TODO! Deal with fast quad and missing files
|
||||
@ -49,13 +62,13 @@ std::filesystem::path fname;
|
||||
n_subfiles = n_mod;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
inline std::filesystem::path data_fname(int mod_id, int file_id) {
|
||||
return base_path / fmt::format("{}_d{}_f{}_{}.raw", base_name, mod_id, file_id, findex);
|
||||
return base_path / fmt::format("{}_d{}_f{}_{}.raw", base_name, mod_id,
|
||||
file_id, findex);
|
||||
}
|
||||
// size_t total_frames();
|
||||
|
||||
};
|
||||
|
71
src/file_io/file/SubFile.cpp
Normal file
71
src/file_io/file/SubFile.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
#include "SubFile.hpp"
|
||||
#include <iostream>
|
||||
// #include <filesystem>
|
||||
|
||||
/**
|
||||
* SubFile methods
|
||||
*
|
||||
*
|
||||
*/
|
||||
template <class Header, class DataType>
|
||||
SubFile<Header, DataType>::SubFile(std::filesystem::path fname, ssize_t rows, ssize_t cols) : rows(rows), cols(cols) {
|
||||
fp = fopen(fname.c_str(), "rb");
|
||||
if (fp == nullptr) {
|
||||
throw std::runtime_error("Could not open file " + fname.string());
|
||||
}
|
||||
std::cout<<"File opened"<<std::endl;
|
||||
n_frames = std::filesystem::file_size(fname) / (sizeof(Header) + rows * cols * sizeof(DataType));
|
||||
std::cout<<"Number of frames: "<<n_frames<<std::endl;
|
||||
|
||||
}
|
||||
/**
|
||||
* NormalSubFile methods
|
||||
*/
|
||||
template <class Header, class DataType>
|
||||
NormalSubFile<Header, DataType>::NormalSubFile(std::filesystem::path fname, ssize_t rows, ssize_t cols)
|
||||
: SubFile<Header, DataType>(fname, rows, cols){};
|
||||
|
||||
template <class Header, class DataType> size_t NormalSubFile<Header, DataType>::read_impl(std::byte *buffer) {
|
||||
return fread(reinterpret_cast<char *>(buffer), sizeof(DataType) * this->rows * this->cols, 1, this->fp);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* ReorderM03SubFile methods
|
||||
*/
|
||||
template <class Header, class DataType>
|
||||
ReorderM03SubFile<Header, DataType>::ReorderM03SubFile(std::filesystem::path fname, ssize_t rows, ssize_t cols)
|
||||
: SubFile<Header, DataType>(fname, rows, cols){};
|
||||
|
||||
template <class Header, class DataType> size_t ReorderM03SubFile<Header, DataType>::read_impl(std::byte *buffer) {
|
||||
std::vector<DataType> tmp(this->pixels_per_frame());
|
||||
size_t rc = fread(reinterpret_cast<char *>(&tmp[0]), this->bytes_per_frame(), 1, this->fp);
|
||||
|
||||
int adc_nr[32] = {300, 325, 350, 375, 300, 325, 350, 375, 200, 225, 250, 275, 200, 225, 250, 275,
|
||||
100, 125, 150, 175, 100, 125, 150, 175, 0, 25, 50, 75, 0, 25, 50, 75};
|
||||
int sc_width = 25;
|
||||
int nadc = 32;
|
||||
int pixels_per_sc = 5000;
|
||||
|
||||
auto dst = reinterpret_cast<DataType *>(buffer);
|
||||
int pixel = 0;
|
||||
for (int i = 0; i != pixels_per_sc; ++i) {
|
||||
for (int i_adc = 0; i_adc != nadc; ++i_adc) {
|
||||
int col = adc_nr[i_adc] + (i % sc_width);
|
||||
int row;
|
||||
if ((i_adc / 4) % 2 == 0)
|
||||
row = 199 - int(i / sc_width);
|
||||
else
|
||||
row = 200 + int(i / sc_width);
|
||||
|
||||
dst[col + row * 400] = tmp[pixel];
|
||||
pixel++;
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
};
|
||||
|
||||
template class NormalSubFile<sls_detector_header, uint16_t>;
|
||||
template class NormalSubFile<sls_detector_header, uint32_t>;
|
||||
template class ReorderM03SubFile<sls_detector_header, uint16_t>;
|
47
src/file_io/file/SubFile.hpp
Normal file
47
src/file_io/file/SubFile.hpp
Normal file
@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
#include "defs.hpp"
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <variant>
|
||||
|
||||
template <class Header, class DataType> class SubFile {
|
||||
protected:
|
||||
FILE *fp = nullptr;
|
||||
|
||||
public:
|
||||
SubFile(std::filesystem::path fname, ssize_t rows, ssize_t cols);
|
||||
inline size_t bytes_per_frame() const { return sizeof(DataType) * rows * cols; }
|
||||
|
||||
inline size_t pixels_per_frame() const { return rows * cols; }
|
||||
|
||||
|
||||
ssize_t rows{};
|
||||
ssize_t cols{};
|
||||
ssize_t n_frames{};
|
||||
int sub_file_index_{};
|
||||
size_t read_impl(std::byte *buffer){};
|
||||
|
||||
};
|
||||
|
||||
template <class Header, class DataType> class NormalSubFile : public SubFile<Header, DataType> {
|
||||
public:
|
||||
NormalSubFile(std::filesystem::path fname, ssize_t rows, ssize_t cols);
|
||||
size_t read_impl(std::byte *buffer);
|
||||
};
|
||||
|
||||
// template <class Header, class DataType>
|
||||
// class FlipSubFile : public SubFile<Header, DataType>{
|
||||
// size_t read_impl() override;
|
||||
// };
|
||||
|
||||
template <class Header, class DataType> class ReorderM03SubFile : public SubFile<Header, DataType> {
|
||||
public:
|
||||
ReorderM03SubFile(std::filesystem::path fname, ssize_t rows, ssize_t cols);
|
||||
size_t read_impl(std::byte *buffer);
|
||||
};
|
||||
|
||||
using JungfrauSubFile = NormalSubFile<sls_detector_header, uint16_t>;
|
||||
using Moench03SubFile = ReorderM03SubFile<sls_detector_header, uint16_t>;
|
||||
using Mythen3SubFile = NormalSubFile<sls_detector_header, uint32_t>;
|
||||
|
||||
using SubFileVariants = std::variant<JungfrauSubFile, Mythen3SubFile, Moench03SubFile>;
|
@ -72,5 +72,5 @@ void FileFactory::find_geometry(File& file) {
|
||||
file.rows = r * file.subfile_rows;
|
||||
file.cols = c * file.subfile_cols;
|
||||
|
||||
file.rows += (r - 1) * cfg.module_gap_row;
|
||||
file.rows += (r - 1) * file.cfg.module_gap_row;
|
||||
}
|
@ -14,7 +14,7 @@ public:
|
||||
virtual void parse_metadata(File&){};
|
||||
|
||||
|
||||
void find_geometry(File&){};
|
||||
void find_geometry(File&);
|
||||
void parse_fname(File&);
|
||||
|
||||
template <typename Header> Header read_header(const std::filesystem::path &fname);
|
||||
|
@ -1,33 +1,32 @@
|
||||
#include "JsonFileFactory.hpp"
|
||||
#include "JsonFile.hpp"
|
||||
#include "helpers.hpp"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include "defs.hpp"
|
||||
#include "helpers.hpp"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "SubFile.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
|
||||
|
||||
JsonFileFactory::JsonFileFactory(std::filesystem::path fpath){
|
||||
if(not is_master_file(fpath))
|
||||
JsonFileFactory::JsonFileFactory(std::filesystem::path fpath) {
|
||||
if (not is_master_file(fpath))
|
||||
throw std::runtime_error("Json file is not a master file");
|
||||
this->fpath = fpath;
|
||||
}
|
||||
|
||||
void JsonFileFactory::parse_metadata(File& file){
|
||||
std::cout<<"Parsing metadata"<<std::endl;
|
||||
void JsonFileFactory::parse_metadata(File &file) {
|
||||
std::cout << "Parsing metadata" << std::endl;
|
||||
std::ifstream ifs(file.master_fname());
|
||||
json j;
|
||||
ifs >> j;
|
||||
double v = j["Version"];
|
||||
file.version = fmt::format("{:.1f}", v);
|
||||
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>());
|
||||
// std::string tmp;
|
||||
// j["Detector Type"].get_to(tmp);
|
||||
file.type = StringTo<DetectorType>(j["Detector Type"].get<std::string>());
|
||||
file.timing_mode =
|
||||
StringTo<TimingMode>(j["Timing Mode"].get<std::string>());
|
||||
file.total_frames = j["Frames in File"];
|
||||
file.subfile_cols = j["Pixels"]["x"];
|
||||
file.subfile_rows = j["Pixels"]["y"];
|
||||
@ -40,24 +39,30 @@ void JsonFileFactory::parse_metadata(File& file){
|
||||
if (file.type == DetectorType::Eiger) {
|
||||
file.quad = (j["Quad"] == 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
File JsonFileFactory::loadFile(){
|
||||
std::cout<<"Loading json file"<<std::endl;
|
||||
void JsonFileFactory::open_subfiles(File &file) {
|
||||
for (int i = 0; i != file.n_subfiles; ++i) {
|
||||
if (file.type == DetectorType::Jungfrau)
|
||||
file.subfiles.push_back(JungfrauSubFile(file.data_fname(i, 0), file.subfile_rows, file.subfile_cols));
|
||||
else if (file.type == DetectorType::Mythen3)
|
||||
file.subfiles.push_back(Mythen3SubFile(file.data_fname(i, 0), file.subfile_rows, file.subfile_cols));
|
||||
else if (file.type == DetectorType::Moench)
|
||||
file.subfiles.push_back(Moench03SubFile(file.data_fname(i, 0), file.subfile_rows, file.subfile_cols));
|
||||
else
|
||||
throw std::runtime_error("File not supported");
|
||||
}
|
||||
}
|
||||
|
||||
File JsonFileFactory::loadFile() {
|
||||
std::cout << "Loading json file" << std::endl;
|
||||
JsonFile file = JsonFile();
|
||||
file.fname = fpath;
|
||||
this->parse_fname(file);
|
||||
this->parse_metadata(file);
|
||||
file.find_number_of_subfiles();
|
||||
this->find_geometry(file);
|
||||
|
||||
|
||||
|
||||
|
||||
this->open_subfiles(file);
|
||||
|
||||
return file;
|
||||
}
|
@ -8,6 +8,7 @@ public:
|
||||
File loadFile() override;
|
||||
void parse_metadata(File&) override;
|
||||
JsonFileFactory(std::filesystem::path fpath);
|
||||
void open_subfiles(File&);
|
||||
|
||||
|
||||
};
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
|
||||
int main() {
|
||||
FileFactory fileFactory=FileFactory::getFactory(std::filesystem::current_path()/"test.json");
|
||||
|
||||
FileFactory fileFactory=FileFactory::getFactory(std::filesystem::path("/home/l_bechir/github/aare")/"data"/"m3_master_0.json");
|
||||
std::cout<<"filefactory is of instance: "<<typeid(fileFactory).name()<<std::endl;
|
||||
File f = fileFactory.loadFile();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user