Skip to content

Commit

Permalink
save work
Browse files Browse the repository at this point in the history
  • Loading branch information
Bechir-Brahem committed Feb 19, 2024
1 parent 9906c58 commit a6ff0fc
Show file tree
Hide file tree
Showing 18 changed files with 341 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ BasedOnStyle: LLVM
IndentWidth: 4

UseTab: Never
ColumnLimit: 80
ColumnLimit: 120
AlignConsecutiveAssignments: false
AlignConsecutiveMacros: true
3 changes: 2 additions & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 55 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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 changes: 16 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 25 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -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"
}
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Binary file added data/m3_d0_f0_0.raw
Binary file not shown.
55 changes: 55 additions & 0 deletions data/m3_master_0.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
1 change: 1 addition & 0 deletions src/file_io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
57 changes: 35 additions & 22 deletions src/file_io/file/File.hpp
Original file line number Diff line number Diff line change
@@ -1,43 +1,56 @@
#pragma once

#include <filesystem>
#include "defs.hpp"
#include <filesystem>
#include <fmt/core.h>
#include "SubFile.hpp"

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
{
public:
std::filesystem::path fname;
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{};

std::string version;
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
Expand All @@ -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 changes: 71 additions & 0 deletions src/file_io/file/SubFile.cpp
Original file line number Diff line number Diff line change
@@ -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>;
Loading

0 comments on commit a6ff0fc

Please sign in to comment.