mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-06-23 03:57:57 +02:00
new folder structure
This commit is contained in:
23
core/CMakeLists.txt
Normal file
23
core/CMakeLists.txt
Normal file
@ -0,0 +1,23 @@
|
||||
|
||||
|
||||
set(SourceFiles
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/defs.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/Frame.cpp
|
||||
)
|
||||
|
||||
add_library(core STATIC ${SourceFiles})
|
||||
target_include_directories(core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||
target_link_libraries(core PUBLIC fmt::fmt)
|
||||
set_property(TARGET core PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
if(AARE_BUILD_TESTS)
|
||||
set(TestSources
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/defs.test.cpp
|
||||
)
|
||||
target_sources(tests PRIVATE ${TestSources} )
|
||||
|
||||
#Work around to remove, this is not the way to do it =)
|
||||
# target_include_directories(tests PRIVATE ${CMAKE_SOURCE_DIR}/include/common)
|
||||
target_link_libraries(tests PRIVATE core)
|
||||
|
||||
endif()
|
37
core/include/aare/Frame.hpp
Normal file
37
core/include/aare/Frame.hpp
Normal file
@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <sys/types.h>
|
||||
#include <cstdint>
|
||||
#include <bits/unique_ptr.h>
|
||||
#include <vector>
|
||||
#include "aare/defs.hpp"
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Frame class to represent a single frame of data
|
||||
* model class
|
||||
* should be able to work with streams coming from files or network
|
||||
*/
|
||||
|
||||
|
||||
template <class DataType> class Frame{
|
||||
|
||||
public:
|
||||
ssize_t rows;
|
||||
ssize_t cols;
|
||||
DataType* data;
|
||||
ssize_t bitdepth = sizeof(DataType)*8;
|
||||
|
||||
Frame(std::byte* fp, ssize_t rows, ssize_t cols);
|
||||
DataType get(int row, int col);
|
||||
|
||||
~Frame(){
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
typedef Frame<uint16_t> Frame16;
|
||||
typedef Frame<uint8_t> Frame8;
|
||||
typedef Frame<uint32_t> Frame32;
|
58
core/include/aare/defs.hpp
Normal file
58
core/include/aare/defs.hpp
Normal file
@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include <sys/types.h>
|
||||
#include <string_view>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <fmt/format.h>
|
||||
#include <variant>
|
||||
|
||||
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<class T>
|
||||
std::string toString(T sv){
|
||||
return T(sv);
|
||||
}
|
||||
|
||||
template <> DetectorType StringTo(std::string);
|
||||
template <> std::string toString(DetectorType type);
|
||||
|
||||
|
||||
template <> TimingMode StringTo(std::string);
|
||||
|
||||
using DataTypeVariants = std::variant<uint16_t, uint32_t>;
|
||||
|
23
core/src/Frame.cpp
Normal file
23
core/src/Frame.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
#include "aare/Frame.hpp"
|
||||
#include <iostream>
|
||||
|
||||
template <typename DataType>
|
||||
Frame<DataType>::Frame(std::byte* bytes, ssize_t rows, ssize_t cols):
|
||||
rows(rows), cols(cols) {
|
||||
data = new DataType[rows*cols];
|
||||
std::memcpy(data, bytes, rows*cols*sizeof(DataType));
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename DataType>
|
||||
DataType Frame<DataType>::get(int row, int col) {
|
||||
if (row < 0 || row >= rows || col < 0 || col >= cols) {
|
||||
std::cerr << "Invalid row or column index" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
return data[row*cols + col];
|
||||
}
|
||||
|
||||
|
||||
template class Frame<uint16_t>;
|
45
core/src/defs.cpp
Normal file
45
core/src/defs.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#include "aare/defs.hpp"
|
||||
|
||||
template <> std::string toString(DetectorType type) {
|
||||
switch (type) {
|
||||
case DetectorType::Jungfrau:
|
||||
return "Jungfrau";
|
||||
case DetectorType::Eiger:
|
||||
return "Eiger";
|
||||
case DetectorType::Mythen3:
|
||||
return "Mythen3";
|
||||
case DetectorType::Moench:
|
||||
return "Moench";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// template <> TimingMode StringTo<TimingMode>(std::string mode);
|
8
core/src/defs.test.cpp
Normal file
8
core/src/defs.test.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <string>
|
||||
#include "aare/defs.hpp"
|
||||
TEST_CASE("Enum to string conversion"){
|
||||
//By the way I don't think the enum string conversions should be in the defs.hpp file
|
||||
//but let's use this to show a test
|
||||
REQUIRE(toString(DetectorType::Jungfrau) == "Jungfrau");
|
||||
}
|
Reference in New Issue
Block a user