Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable TOF imaging output #56

Merged
merged 38 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
c74ce5d
add example config
KedoKudo Aug 16, 2024
0573623
add new dep for json handling
KedoKudo Aug 16, 2024
79a9fc9
add json config parser
KedoKudo Aug 16, 2024
308c651
refactor CMake and include new targets
KedoKudo Aug 16, 2024
4d0c28b
use interface design
KedoKudo Aug 18, 2024
5597fb2
refactor the json parser
KedoKudo Aug 18, 2024
f22bff5
update CLI to allow new config
KedoKudo Aug 18, 2024
0669b10
proper tof range
KedoKudo Aug 19, 2024
0c6d36d
fix output unit
KedoKudo Aug 19, 2024
0890220
add super resolution option
KedoKudo Aug 19, 2024
6b3c147
add 2D histogram
KedoKudo Aug 19, 2024
1b275f1
add skeleton for writer
KedoKudo Aug 19, 2024
5609e52
draft implementation
KedoKudo Aug 19, 2024
339ac0d
enalbe accumulating mode
KedoKudo Aug 20, 2024
dc602ac
add new arg for hits to tof img
KedoKudo Aug 20, 2024
c46c842
allow both hit and neutron tiff img mode
KedoKudo Aug 20, 2024
c0d2568
tbb tiff writing
KedoKudo Aug 20, 2024
ad52e49
update docs
KedoKudo Aug 21, 2024
00a7e5a
separating cli core and app
KedoKudo Aug 21, 2024
6efe643
add unit test
KedoKudo Aug 21, 2024
b9ef9e2
remove outdated code
KedoKudo Aug 21, 2024
4e0035c
add semi auto reducer
KedoKudo Aug 21, 2024
6e52980
track processed files
KedoKudo Aug 21, 2024
1bcbb63
refactor cmd arg parser to be consistent
KedoKudo Aug 21, 2024
e8e0aef
add auto monitor capability
KedoKudo Aug 21, 2024
c896e36
change spectra file format to match tpx2
KedoKudo Aug 22, 2024
a3ec7c7
fix typos
KedoKudo Aug 22, 2024
4768939
fix failing unit test
KedoKudo Aug 22, 2024
c31e21a
update readme
KedoKudo Aug 22, 2024
dcabc22
clang-format
KedoKudo Aug 22, 2024
78615cb
Revert "clang-format"
KedoKudo Aug 22, 2024
a4a7e73
comment out duplicate compiler settings
KedoKudo Aug 22, 2024
cdf28f4
address review comments
KedoKudo Aug 22, 2024
f07ff8d
fix potential fall through
KedoKudo Aug 22, 2024
cf1be8b
address review feedback
KedoKudo Aug 26, 2024
f2c986e
address review cmt on cp vector
KedoKudo Aug 26, 2024
bbba359
address review comments
KedoKudo Aug 26, 2024
d1e8bbc
switch to const as suggested
KedoKudo Aug 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions sophiread/.clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,3 @@ WhitespaceSensitiveMacros:
- BOOST_PP_STRINGIZE
- NS_SWIFT_NAME
- CF_SWIFT_NAME
...
KedoKudo marked this conversation as resolved.
Show resolved Hide resolved

67 changes: 48 additions & 19 deletions sophiread/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,43 +1,65 @@
# Sophiread CMakeLists.txt
cmake_minimum_required(VERSION 3.20)

execute_process(COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/scripts/version.sh -s print
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE SOPHIREAD_VERSION)
OUTPUT_VARIABLE SOPHIREAD_VERSION
RESULT_VARIABLE VERSION_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT VERSION_RESULT EQUAL 0)
message(FATAL_ERROR "Failed to determine version")
endif()

project("Sophiread" VERSION ${SOPHIREAD_VERSION})

# set(CMAKE_BUILD_TYPE DEBUG)
# This is to avoid accidentally using Homebrew header/lib instead of the one from micromamba
if(DEFINED ENV{CONDA_PREFIX})
KedoKudo marked this conversation as resolved.
Show resolved Hide resolved
set(CMAKE_PREFIX_PATH $ENV{CONDA_PREFIX} ${CMAKE_PREFIX_PATH})
endif()

if(NOT CMAKE_BUILD_TYPE)
KedoKudo marked this conversation as resolved.
Show resolved Hide resolved
set(CMAKE_BUILD_TYPE Release)
endif()

set(CMAKE_CXX_STANDARD 20)
# set(CMAKE_AUTOMOC ON) # for meta object compiler, needed for Qt5

# Dependencies
find_package(Eigen3 REQUIRED)
find_package(spdlog REQUIRED)
find_package(HDF5 REQUIRED COMPONENTS CXX)
find_package(GTest REQUIRED)
find_package(nlohmann_json 3.2.0 REQUIRED)
find_package(TBB REQUIRED)
find_package(TIFF REQUIRED)
find_package(spdlog 1.8.0 REQUIRED)
find_package(fmt 7.0.0 REQUIRED)
# find_package(Qt5 COMPONENTS Widgets REQUIRED)

include_directories(${HDF5_INCLUDE_DIRS})

link_directories(
$ENV{CONDA_PREFIX}/lib
)

# Testing setup
enable_testing()
include(GoogleTest)
file(COPY ${CMAKE_SOURCE_DIR}/resources/data DESTINATION ${CMAKE_BINARY_DIR})

# Add compiler flags
add_compile_options(
-O3
-std=c++20
-march=native
-ffast-math
-pthread
-Wall
-Wextra
# Copy resources
add_custom_command(
KedoKudo marked this conversation as resolved.
Show resolved Hide resolved
OUTPUT ${CMAKE_BINARY_DIR}/data
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/resources/data
${CMAKE_BINARY_DIR}/data
DEPENDS ${CMAKE_SOURCE_DIR}/resources/data
)
add_custom_target(copy_resources ALL DEPENDS ${CMAKE_BINARY_DIR}/data)

# Add compiler flags
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
KedoKudo marked this conversation as resolved.
Show resolved Hide resolved
add_compile_options(
-march=native
-ffast-math
-pthread
-Wall
-Wextra
)
endif()

# Add Sophiread library
# NOTE: this will take care of the testing as well
Expand Down Expand Up @@ -65,6 +87,13 @@ if(DOXYGEN_FOUND)
COMMENT "Generating API documentation with Doxygen"
VERBATIM
)
if(APPLE)
set(OPEN_COMMAND open)
elseif(UNIX)
set(OPEN_COMMAND xdg-open)
elseif(WIN32)
set(OPEN_COMMAND start)
endif()
add_custom_command(TARGET docs POST_BUILD
COMMAND ${CMAKE_COMMAND} -E chdir
${CMAKE_BINARY_DIR}/docs/html
Expand Down
227 changes: 65 additions & 162 deletions sophiread/FastSophiread/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
# Config SophireadLib
include_directories(
include
$ENV{CONDA_PREFIX}/include
${EIGEN3_INCLUDE_DIR}
${HDF5_INCLUDE_DIRS}
)

link_directories(
$ENV{CONDA_PREFIX}/lib
)

# Config FastSophireadLib
set(SRC_FAST_FILES
src/abs.cpp
src/centroid.cpp
Expand All @@ -21,164 +10,78 @@ set(SRC_FAST_FILES

# ------------- SophireadLibFast -------------- #
add_library(FastSophiread ${SRC_FAST_FILES})

# ----------------- TESTS ----------------- #
# DiskIO Tests
add_executable(
SophireadTests_diskio
tests/test_disk_io.cpp
)
target_link_libraries(
SophireadTests_diskio
FastSophiread
tbb
spdlog::spdlog
GTest::GTest
GTest::Main
${HDF5_LIBRARIES}
)
gtest_discover_tests(SophireadTests_diskio)
# Hit Test
add_executable(
SophireadTests_hit
tests/test_hit.cpp
)
target_link_libraries(
SophireadTests_hit
FastSophiread
pthread
tbb
spdlog::spdlog
GTest::GTest
GTest::Main
)
gtest_discover_tests(SophireadTests_hit)
# TPX3 Test
add_executable(
SophireadTests_tpx3
tests/test_tpx3.cpp
)
target_link_libraries(
SophireadTests_tpx3
FastSophiread
pthread
tbb
spdlog::spdlog
GTest::GTest
GTest::Main
${HDF5_LIBRARIES}
)
gtest_discover_tests(SophireadTests_tpx3)
# ABS Test
add_executable(
SophireadTests_abs
tests/test_abs.cpp
)
target_link_libraries(
SophireadTests_abs
FastSophiread
pthread
tbb
spdlog::spdlog
GTest::GTest
GTest::Main
)
gtest_discover_tests(SophireadTests_abs)
# Centroid Test
add_executable(
SophireadTests_centroid
tests/test_centroid.cpp
)
target_link_libraries(
SophireadTests_centroid
FastSophiread
pthread
tbb
spdlog::spdlog
GTest::GTest
GTest::Main
)
gtest_discover_tests(SophireadTests_centroid)
# Fast Gaussian Test
add_executable(
SophireadTests_fastgaussian
tests/test_fastgaussian.cpp
target_include_directories(FastSophiread
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
$ENV{CONDA_PREFIX}/include
${EIGEN3_INCLUDE_DIR}
${HDF5_INCLUDE_DIRS}
)
target_link_libraries(
SophireadTests_fastgaussian
FastSophiread
pthread
tbb
spdlog::spdlog
GTest::GTest
GTest::Main
target_link_directories(FastSophiread
PRIVATE
$ENV{CONDA_PREFIX}/lib
)
gtest_discover_tests(SophireadTests_fastgaussian)

# ----------------- TESTS ----------------- #
function(add_sophiread_test test_name)
add_executable(${test_name} tests/test_${test_name}.cpp)
target_link_libraries(${test_name}
PRIVATE
FastSophiread
pthread
TBB::tbb
spdlog::spdlog
GTest::GTest
GTest::Main
${ARGN}
)
gtest_discover_tests(${test_name})
endfunction()
# Add tests
add_sophiread_test(disk_io ${HDF5_LIBRARIES})
add_sophiread_test(hit)
add_sophiread_test(tpx3 ${HDF5_LIBRARIES})
add_sophiread_test(abs)
add_sophiread_test(centroid)
add_sophiread_test(fastgaussian)


# ------------------ Benchmarks ------------------ #
# Raw2Hits Benchmark
add_executable(
SophireadBenchmarks_raw2hits
benchmarks/benchmark_raw2hits.cpp
)
target_link_libraries(
SophireadBenchmarks_raw2hits
FastSophiread
pthread
tbb
spdlog::spdlog
${HDF5_LIBRARIES}
)
add_custom_command(TARGET SophireadBenchmarks_raw2hits POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink
${PROJECT_BINARY_DIR}/FastSophiread/SophireadBenchmarks_raw2hits
${PROJECT_BINARY_DIR}/FastSophireadBenchmarks_raw2hits.app
)
# Hits2Events Benchmark
add_executable(
SophireadBenchmarks_hits2events
benchmarks/benchmark_hits2events.cpp
)
target_link_libraries(
SophireadBenchmarks_hits2events
FastSophiread
pthread
tbb
spdlog::spdlog
)
add_custom_command(TARGET SophireadBenchmarks_hits2events POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink
${PROJECT_BINARY_DIR}/FastSophiread/SophireadBenchmarks_hits2events
${PROJECT_BINARY_DIR}/FastSophireadBenchmarks_hits2events.app
)
# Raw2Events Benchmark
add_executable(
SophireadBenchmarks_raw2events
benchmarks/benchmark_raw2events.cpp
)
target_link_libraries(
SophireadBenchmarks_raw2events
FastSophiread
pthread
tbb
spdlog::spdlog
${HDF5_LIBRARIES}
)
add_custom_command(TARGET SophireadBenchmarks_raw2events POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink
${PROJECT_BINARY_DIR}/FastSophiread/SophireadBenchmarks_raw2events
${PROJECT_BINARY_DIR}/FastSophireadBenchmarks_raw2events.app
)
# CLI
add_executable(
FastSophireadBenchmarksCLI
# Define a function to add benchmark targets
function(add_sophiread_benchmark NAME)
set(TARGET_NAME SophireadBenchmarks_${NAME})
add_executable(${TARGET_NAME} benchmarks/benchmark_${NAME}.cpp)

target_link_libraries(${TARGET_NAME}
PRIVATE
FastSophiread
pthread
TBB::tbb
spdlog::spdlog
${ARGN} # Additional libraries passed as arguments
)

add_custom_command(TARGET ${TARGET_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink
${PROJECT_BINARY_DIR}/FastSophiread/${TARGET_NAME}
${PROJECT_BINARY_DIR}/FastSophireadBenchmarks_${NAME}.app
)
endfunction()

# Add benchmarks
add_sophiread_benchmark(raw2hits ${HDF5_LIBRARIES})
add_sophiread_benchmark(hits2events)
add_sophiread_benchmark(raw2events ${HDF5_LIBRARIES})

# ----------------- CLI ----------------- #
add_executable(FastSophireadBenchmarksCLI
benchmarks/benchmark_mmap.cpp
)
target_link_libraries(
FastSophireadBenchmarksCLI
target_link_libraries(FastSophireadBenchmarksCLI
PRIVATE
FastSophiread
pthread
tbb
TBB::tbb
spdlog::spdlog
${HDF5_LIBRARIES}
)
Expand Down
8 changes: 4 additions & 4 deletions sophiread/FastSophiread/benchmarks/benchmark_mmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,19 @@ void saveEventsToHDF5(const std::string out_file_name, const std::vector<Neutron
y_dataset.write(y.data(), float_type);
// -- write TOF_ns
std::vector<double> tof_ns(events.size());
std::transform(events.begin(), events.end(), tof_ns.begin(),
std::transform(events.cbegin(), events.cend(), tof_ns.begin(),
[](const Neutron &event) { return event.getTOF_ns(); });
H5::DataSet tof_ns_dataset = group.createDataSet("tof", float_type, dataspace);
tof_ns_dataset.write(tof_ns.data(), float_type);
// -- write Nhits
std::vector<int> nhits(events.size());
std::transform(events.begin(), events.end(), nhits.begin(),
std::transform(events.cbegin(), events.cend(), nhits.begin(),
[](const Neutron &event) { return event.getNHits(); });
H5::DataSet nhits_dataset = group.createDataSet("nHits", int_type, dataspace);
nhits_dataset.write(nhits.data(), int_type);
// -- write TOT
std::vector<double> tot(events.size());
std::transform(events.begin(), events.end(), tot.begin(), [](const Neutron &event) { return event.getTOT(); });
std::transform(events.cbegin(), events.cend(), tot.begin(), [](const Neutron &event) { return event.getTOT(); });
H5::DataSet tot_dataset = group.createDataSet("tot", float_type, dataspace);
tot_dataset.write(tot.data(), float_type);
// -- close file
Expand Down Expand Up @@ -260,7 +260,7 @@ int main(int argc, char* argv[])

spdlog::debug("@{:p}, {}", raw_data.map, raw_data.max);

if ( raw_data.map == NULL )
if ( raw_data.map == nullptr )
{
spdlog::error("Insufficient memory: {}", in_tpx3);
exit(EXIT_FAILURE);
Expand Down
Loading
Loading