Merge pull request #11 from slsdetectorgroup/project_structure

Project structure
This commit is contained in:
Bechir Braham 2024-03-08 11:28:15 +01:00 committed by GitHub
commit 0d552d6f75
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
34 changed files with 149 additions and 131 deletions

View File

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.12)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 17) #TODO! Global or per target?
project(aare
VERSION 0.1
DESCRIPTION "Data processing library for PSI detectors"
@ -10,81 +10,76 @@ project(aare
cmake_policy(SET CMP0135 NEW)
cmake_policy(SET CMP0079 NEW)
include(GNUInstallDirs)
include(FetchContent)
option(USE_SANITIZER "Sanitizers for debugging" ON)
option(DISABLE_WARNINGS "Disbale compilation warnings" OFF)
option(USE_PYTHON "Build python bindings" ON)
option(AARE_BUILD_TESTS "Build tests" OFF)
option(AARE_USE_SANITIZER "Sanitizers for debugging" ON)
option(AARE_PYTHON_BINDINGS "Build python bindings" ON)
option(AARE_TESTS "Build tests" OFF)
option(AARE_EXAMPLES "Build examples" OFF)
#TODO! Should this be on the top level or move it down to the component
#that needs it?
FetchContent_Declare(json
GIT_REPOSITORY https://github.com/nlohmann/json
GIT_TAG v3.11.3
)
FetchContent_MakeAvailable(json)
if(AARE_BUILD_TESTS)
add_subdirectory(tests)
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
find_package(fmt 6 REQUIRED)
set(CMAKE_BUILD_TYPE "Debug")
# set(CMAKE_BUILD_TYPE "Debug")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(OPTIMIZATION_FLAGS "-Og -ggdb3 -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC")
else()
set(OPTIMIZATION_FLAGS "-O3")
# if (CMAKE_BUILD_TYPE STREQUAL "Debug")
# set(OPTIMIZATION_FLAGS "-Og -ggdb3 -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC")
# else()
# set(OPTIMIZATION_FLAGS "-O3")
# endif()
# set(OPTIONAL_FLAGS "")
# if(DISABLE_WARNINGS)
# set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -Wall -Wextra -pedantic -Wno-unused-parameter -Wshadow -Wformat=2 -Wold-style-cast -Wnon-virtual-dtor -Wfloat-equal -Wconversion -Wlogical-op -Wshift-overflow=2 -Woverloaded-virtual -Winline")
# endif()
# if(USE_SANITIZER)
# set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -fdiagnostics-parseable-fixits -fdiagnostics-generate-patch -fdiagnostics-show-template-tree -fsanitize=address,undefined,pointer-compare -fno-sanitize-recover -D_FORTIFY_SOURCE=2 -fstack-protector -fno-omit-frame-pointer ")
# endif()
# set(SUPPRESSED_WARNINGS "-Wno-return-type")
# set(CMAKE_CXX_FLAGS "${OPTIMIZATION_FLAGS} ${SUPPRESSED_WARNINGS}")
if(AARE_BUILD_TESTS)
add_subdirectory(tests)
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(OPTIONAL_FLAGS "")
if(DISABLE_WARNINGS)
set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -Wall -Wextra -pedantic -Wno-unused-parameter -Wshadow -Wformat=2 -Wold-style-cast -Wnon-virtual-dtor -Wfloat-equal -Wconversion -Wlogical-op -Wshift-overflow=2 -Woverloaded-virtual -Winline")
endif()
if(USE_SANITIZER)
set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -fdiagnostics-parseable-fixits -fdiagnostics-generate-patch -fdiagnostics-show-template-tree -fsanitize=address,undefined,pointer-compare -fno-sanitize-recover -D_FORTIFY_SOURCE=2 -fstack-protector -fno-omit-frame-pointer ")
endif()
set(SUPPRESSED_WARNINGS "-Wno-return-type")
set(CMAKE_CXX_FLAGS "${OPTIMIZATION_FLAGS} ${SUPPRESSED_WARNINGS}")
if(USE_PYTHON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif(USE_PYTHON)
include_directories(include)
add_subdirectory(src)
add_subdirectory(core)
add_subdirectory(file_io)
#Overall target to link to when using the library
add_library(aare INTERFACE)
target_link_libraries(aare INTERFACE common core file_io)
target_link_libraries(aare INTERFACE core file_io)
target_include_directories(aare INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
add_subdirectory(examples)
target_link_libraries(example PUBLIC aare)
if(USE_PYTHON)
find_package (Python 3.11 COMPONENTS Interpreter Development)
find_package(pybind11 2.11 REQUIRED)
if(AARE_PYTHON_BINDINGS)
add_subdirectory(python)
target_link_libraries(_aare PRIVATE aare nlohmann_json::nlohmann_json fmt::fmt)
endif()

View File

@ -4,5 +4,13 @@ Data analysis library for PSI hybrid detectors
## Folder structure
| Folder | subfolder | Content |
|----------|---------------|-------------------------------------|
| include/ | aare/ | top level header/s |
| core/ | include/ | public headers for core |
| | src/ | source files and non public headers |
## file_io class diagram
![file_io class diagram](./extra/uml/out/file_io/ClassDiagram.png)

23
core/CMakeLists.txt Normal file
View 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()

View File

@ -4,7 +4,7 @@
#include <cstdint>
#include <bits/unique_ptr.h>
#include <vector>
#include "common/defs.hpp"
#include "aare/defs.hpp"

View File

@ -1,4 +1,4 @@
#include "core/Frame.hpp"
#include "aare/Frame.hpp"
#include <iostream>
template <typename DataType>

View File

@ -1,4 +1,4 @@
#include "common/defs.hpp"
#include "aare/defs.hpp"
template <> std::string toString(DetectorType type) {
switch (type) {

View File

@ -1,6 +1,6 @@
#include <catch2/catch_test_macros.hpp>
#include <string>
#include "defs.hpp"
#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

View File

@ -1,6 +1,6 @@
// Your First C++ Program
#include <iostream>
#include "file_io/FileHandler.hpp"
#include "aare/FileHandler.hpp"
using JFileHandler = FileHandler<DetectorType::Jungfrau,uint16_t>;
using JFile = File<DetectorType::Jungfrau,uint16_t>;

28
file_io/CMakeLists.txt Normal file
View File

@ -0,0 +1,28 @@
set(SourceFiles
${CMAKE_CURRENT_SOURCE_DIR}/src/File.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/FileFactory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/helpers.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/JsonFile.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/JsonFileFactory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/SubFile.cpp
)
add_library(file_io STATIC ${SourceFiles})
target_include_directories(file_io PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(file_io PUBLIC fmt::fmt core nlohmann_json::nlohmann_json)
set_property(TARGET file_io 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 file_io)
# endif()

View File

@ -1,8 +1,9 @@
#pragma once
#include "common/defs.hpp"
#include "core/Frame.hpp"
#include "aare/defs.hpp"
#include "aare/Frame.hpp"
#include "SubFile.hpp"
#include <filesystem>
#include <fmt/core.h>
#include <iostream>

View File

@ -1,6 +1,7 @@
#pragma once
#include <filesystem>
#include "file_io/File.hpp"
#include "aare/File.hpp"
template <DetectorType detector,typename DataType>
class FileFactory{
// Class that will be used to create File objects

View File

@ -1,6 +1,7 @@
#include <filesystem>
#include "file_io/FileFactory.hpp"
#include "file_io/File.hpp"
#include "aare/FileFactory.hpp"
#include "aare/File.hpp"
template <DetectorType detector,typename DataType>
class FileHandler{
private:

View File

@ -1,7 +1,7 @@
#pragma once
#include "file_io/File.hpp"
#include "core/Frame.hpp"
#include "common/defs.hpp"
#include "aare/File.hpp"
#include "aare/Frame.hpp"
#include "aare/defs.hpp"
template <DetectorType detector, typename DataType>
class JsonFile : public File<detector, DataType> {

View File

@ -1,4 +1,4 @@
#include "file_io/FileFactory.hpp"
#include "aare/FileFactory.hpp"
template <DetectorType detector,typename DataType>
class JsonFileFactory: public FileFactory<detector,DataType>
{

View File

@ -1,4 +1,4 @@
#include "file_io/File.hpp"
#include "aare/File.hpp"
#include <filesystem>
template<DetectorType detector,typename DataType>
class RawFileFactory{

View File

@ -1,5 +1,5 @@
#pragma once
#include "common/defs.hpp"
#include "aare/defs.hpp"
#include <cstdint>
#include <filesystem>
#include <variant>

View File

@ -1,6 +1,6 @@
#pragma once
#include "file_io/File.hpp"
#include "aare/File.hpp"
#include <filesystem>
#include <fmt/core.h>

View File

@ -1,4 +1,5 @@
#include "file_io/File.hpp"
#include "aare/File.hpp"
template <DetectorType detector, typename DataType>
File<detector,DataType>::~File<detector,DataType>() {
for (auto& subfile : subfiles) {

View File

@ -1,6 +1,6 @@
#include "file_io/FileFactory.hpp"
#include "file_io/File.hpp"
#include "file_io/JsonFileFactory.hpp"
#include "aare/FileFactory.hpp"
#include "aare/File.hpp"
#include "aare/JsonFileFactory.hpp"
#include <iostream>
template <DetectorType detector, typename DataType>

View File

@ -1,4 +1,4 @@
#include "file_io/JsonFile.hpp"
#include "aare/JsonFile.hpp"
#include <typeinfo>
template <DetectorType detector, typename DataType>

View File

@ -1,8 +1,8 @@
#include "file_io/JsonFileFactory.hpp"
#include "file_io/JsonFile.hpp"
#include "file_io/SubFile.hpp"
#include "common/defs.hpp"
#include "file_io/helpers.hpp"
#include "aare/JsonFileFactory.hpp"
#include "aare/JsonFile.hpp"
#include "aare/SubFile.hpp"
#include "aare/defs.hpp"
#include "aare/helpers.hpp"
#include <fstream>
#include <iostream>
#include <nlohmann/json.hpp>

View File

@ -1,4 +1,4 @@
#include "file_io/SubFile.hpp"
#include "aare/SubFile.hpp"
#include <iostream>
// #include <filesystem>

View File

@ -1,4 +1,4 @@
#include "file_io/helpers.hpp"
#include "aare/helpers.hpp"
bool is_master_file(std::filesystem::path fpath) {

1
include/aare/aare.hpp Normal file
View File

@ -0,0 +1 @@
//This is the top level header to include and what most users will use

View File

@ -1 +1,8 @@
find_package (Python 3.11 COMPONENTS Interpreter Development)
find_package(pybind11 2.11 REQUIRED)
pybind11_add_module(_aare src/bindings.cpp)
set_target_properties(_aare PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
)
target_link_libraries(_aare PRIVATE aare)

View File

@ -3,9 +3,9 @@
#include <pybind11/pybind11.h>
#include <string>
#include "common/defs.hpp"
#include "core/Frame.hpp"
#include "file_io/FileHandler.hpp"
#include "aare/defs.hpp"
#include "aare/Frame.hpp"
#include "aare/FileHandler.hpp"
namespace py = pybind11;

1
src/.gitignore vendored
View File

@ -1 +0,0 @@

View File

@ -1,4 +0,0 @@
add_subdirectory(file_io)
add_subdirectory(core)
add_subdirectory(processing)
add_subdirectory(common)

View File

@ -1,16 +0,0 @@
add_library(common "${CMAKE_CURRENT_SOURCE_DIR}/defs.cpp")
target_link_libraries(common PUBLIC fmt::fmt)
if(AARE_BUILD_TESTS)
set(TestSources
${CMAKE_CURRENT_SOURCE_DIR}/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 common)
endif()

View File

@ -1,10 +0,0 @@
# target_include_directories(aare PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
# target_sources(aare PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/Frame.cpp")
add_library(core "${CMAKE_CURRENT_SOURCE_DIR}/Frame.cpp")
target_link_libraries(core PUBLIC common)

View File

@ -1,16 +0,0 @@
set(FILE_IO_SOURCES "file/File.cpp"
"file/JsonFile.cpp"
"file/SubFile.cpp"
"file_factory/FileFactory.cpp"
"file_factory/JsonFileFactory.cpp"
"helpers.cpp"
)
# append ${CMAKE_CURRENT_SOURCE_DIR} to the list of sources using for loop
foreach(FILE_IO_SOURCE ${FILE_IO_SOURCES})
list(APPEND FILE_IO_SOURCES_WITH_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${FILE_IO_SOURCE}")
endforeach()
add_library(file_io ${FILE_IO_SOURCES_WITH_PATH})
target_link_libraries(file_io common fmt::fmt core nlohmann_json::nlohmann_json)

1
tests/.gitignore vendored
View File

@ -1 +0,0 @@