From 389920406bdc078f2405352cff58ab35f7e9b0a5 Mon Sep 17 00:00:00 2001 From: "s.zharko@gsi.de" <s.zharko@gsi.de> Date: Fri, 29 Nov 2024 14:22:18 +0100 Subject: [PATCH 1/4] Algo: moving the PartitionedVector, PartitionedSpan and PODVector into a separate header-only library --- algo/CMakeLists.txt | 44 +++------------------ algo/base/CMakeLists.txt | 1 + algo/base/pvector/CMakeLists.txt | 21 ++++++++++ algo/base/{util => pvector}/PODAllocator.h | 0 algo/base/{ => pvector}/PODVector.h | 2 +- algo/base/{ => pvector}/PartitionedSpan.h | 27 ++++++------- algo/base/{ => pvector}/PartitionedVector.h | 23 ++++++----- algo/test/_GTestPartitionedSpan.cxx | 3 ++ algo/test/_GTestPartitionedVector.cxx | 2 + 9 files changed, 57 insertions(+), 66 deletions(-) create mode 100644 algo/base/pvector/CMakeLists.txt rename algo/base/{util => pvector}/PODAllocator.h (100%) rename algo/base/{ => pvector}/PODVector.h (96%) rename algo/base/{ => pvector}/PartitionedSpan.h (88%) rename algo/base/{ => pvector}/PartitionedVector.h (91%) diff --git a/algo/CMakeLists.txt b/algo/CMakeLists.txt index 612c11a1a5..4f7f9b50ef 100644 --- a/algo/CMakeLists.txt +++ b/algo/CMakeLists.txt @@ -52,13 +52,12 @@ if (CBM_ONLINE_STANDALONE) add_subdirectory(../external external) endif() -add_subdirectory(kfp) +add_subdirectory(base) add_subdirectory(log) +add_subdirectory(ca) add_subdirectory(data) add_subdirectory(kf) -add_subdirectory(ca) -add_subdirectory(base) -#add_subdirectory(kfp) # For KFParticleOnline +add_subdirectory(kfp) # exclude unittests from being build inside the container if (NOT CBM_ONLINE_STANDALONE) @@ -217,6 +216,7 @@ target_include_directories(Algo target_link_libraries(Algo PUBLIC OnlineData + PVector KfCore CaCore ROOT::GenVector @@ -294,6 +294,7 @@ if (NOT CBM_ONLINE_STANDALONE) target_link_libraries(AlgoOffline PUBLIC CbmData + PVector KfCoreOffline CaCoreOffline ROOT::GenVector @@ -361,46 +362,11 @@ install(DIRECTORY evbuild TYPE INCLUDE FILES_MATCHING PATTERN "*.h") install( FILES - base/ChainContext.h - base/Definitions.h - base/HistogramSender.h - base/Options.h - base/RecoParams.h - base/SubChain.h - base/System.h - base/PartitionedVector.h - base/PartitionedSpan.h - base/DigiData.h - base/PODVector.h - base/AlgoTraits.h - base/AuxDigiData.h - base/BuildInfo.h - base/Exceptions.h - base/MainConfig.h - evselector/DigiEventSelector.h - evselector/DigiEventSelectorConfig.h - trigger/DigiTriggerConfig.h - trigger/HitMultTrigger.h - trigger/TimeClusterTrigger.h - trigger/V0Trigger.h - trigger/V0TriggerConfig.h - unpack/CommonUnpacker.h - unpack/UnpackMSBase.h - global/ParFiles.h global/Reco.h global/RecoResults.h global/RecoResultsInputArchive.h global/RecoResultsOutputArchive.h global/StorableRecoResults.h - qa/Accumulators.h - qa/Histogram.h - ca/TrackingChain.h - ca/TrackingChainConfig.h - ca/TrackingDefs.h - ca/TrackingSetup.h - # NOTE: SZh 20.11.2023: - # The ca/qa directory depends on the online qa classes, so for now it has to be a part of the Algo library. - ca/qa/CaQa.h DESTINATION include/ ) diff --git a/algo/base/CMakeLists.txt b/algo/base/CMakeLists.txt index 93b295fe0a..ec043f688c 100644 --- a/algo/base/CMakeLists.txt +++ b/algo/base/CMakeLists.txt @@ -1 +1,2 @@ add_subdirectory(yaml) +add_subdirectory(pvector) diff --git a/algo/base/pvector/CMakeLists.txt b/algo/base/pvector/CMakeLists.txt new file mode 100644 index 0000000000..dd79d38da0 --- /dev/null +++ b/algo/base/pvector/CMakeLists.txt @@ -0,0 +1,21 @@ +set(INCLUDE_DIRECTORIES + ${CMAKE_CURRENT_SOURCE_DIR} +) + +add_library(PVector INTERFACE) + +target_include_directories(PVector + INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_link_libraries(PVector + INTERFACE GSL +) + +install( + FILES + PartitionedVector.h + PartitionedSpan.h + DESTINATION + include/ +) diff --git a/algo/base/util/PODAllocator.h b/algo/base/pvector/PODAllocator.h similarity index 100% rename from algo/base/util/PODAllocator.h rename to algo/base/pvector/PODAllocator.h diff --git a/algo/base/PODVector.h b/algo/base/pvector/PODVector.h similarity index 96% rename from algo/base/PODVector.h rename to algo/base/pvector/PODVector.h index 16f1ceed51..587f50bce1 100644 --- a/algo/base/PODVector.h +++ b/algo/base/pvector/PODVector.h @@ -4,7 +4,7 @@ #ifndef CBM_ALGO_BASE_POD_VECTOR_H #define CBM_ALGO_BASE_POD_VECTOR_H -#include "util/PODAllocator.h" +#include "PODAllocator.h" #include <vector> diff --git a/algo/base/PartitionedSpan.h b/algo/base/pvector/PartitionedSpan.h similarity index 88% rename from algo/base/PartitionedSpan.h rename to algo/base/pvector/PartitionedSpan.h index c626b75552..beac6c2a7f 100644 --- a/algo/base/PartitionedSpan.h +++ b/algo/base/pvector/PartitionedSpan.h @@ -4,12 +4,11 @@ #ifndef CBM_ALGO_BASE_PARTITIONED_SPAN_H #define CBM_ALGO_BASE_PARTITIONED_SPAN_H -#include "Definitions.h" - #include <array> #include <gsl/span> #include <stdexcept> #include <vector> +#include <cstdint> namespace cbm::algo { @@ -36,7 +35,7 @@ namespace cbm::algo // #if defined(__INTELLISENSE__) || defined(__clang__) template<typename Allocator> PartitionedSpan(std::vector<T, Allocator>& container, gsl::span<const size_t> offsets, - gsl::span<const u32> addresses) + gsl::span<const uint32_t> addresses) : fData(container) , fOffsets(offsets) , fAdresses(addresses) @@ -47,7 +46,7 @@ namespace cbm::algo // FIXME disable if T is non-const via SFINAE, otherwise get misleading compiler errors template<typename Allocator> PartitionedSpan(const std::vector<T, Allocator>& container, gsl::span<const size_t> offsets, - gsl::span<const u32> addresses) + gsl::span<const uint32_t> addresses) : fData(container) , fOffsets(offsets) , fAdresses(addresses) @@ -56,7 +55,7 @@ namespace cbm::algo } template<size_t N> - PartitionedSpan(std::array<T, N>& container, gsl::span<const size_t> offsets, gsl::span<const u32> addresses) + PartitionedSpan(std::array<T, N>& container, gsl::span<const size_t> offsets, gsl::span<const uint32_t> addresses) : fData(container) , fOffsets(offsets) , fAdresses(addresses) @@ -66,7 +65,7 @@ namespace cbm::algo // FIXME disable if T is non-const via SFINAE template<size_t N> - PartitionedSpan(const std::array<T, N>& container, gsl::span<const size_t> offsets, gsl::span<const u32> addresses) + PartitionedSpan(const std::array<T, N>& container, gsl::span<const size_t> offsets, gsl::span<const uint32_t> addresses) : fData(container) , fOffsets(offsets) , fAdresses(addresses) @@ -75,7 +74,7 @@ namespace cbm::algo } // #endif - PartitionedSpan(gsl::span<T> data, gsl::span<const size_t> offsets, gsl::span<const u32> addresses) + PartitionedSpan(gsl::span<T> data, gsl::span<const size_t> offsets, gsl::span<const uint32_t> addresses) : fData(data) , fOffsets(offsets) , fAdresses(addresses) @@ -115,16 +114,16 @@ namespace cbm::algo return UnsafePartitionSpan(i); } - u32 Address(size_t i) const + uint32_t Address(size_t i) const { EnsureBounds(i); return fAdresses[i]; } - std::pair<gsl::span<T>, u32> Partition(size_t i) const + std::pair<gsl::span<T>, uint32_t> Partition(size_t i) const { EnsureBounds(i); - return std::pair<gsl::span<T>, u32>(UnsafePartitionSpan(i), fAdresses[i]); + return std::pair<gsl::span<T>, uint32_t>(UnsafePartitionSpan(i), fAdresses[i]); } size_t NPartitions() const { return fAdresses.size(); } @@ -139,7 +138,7 @@ namespace cbm::algo gsl::span<T> Data() const { return fData; } - gsl::span<const u32> Addresses() const { return fAdresses; } + gsl::span<const uint32_t> Addresses() const { return fAdresses; } gsl::span<const size_t> Offsets() const { return fOffsets; } @@ -149,7 +148,7 @@ namespace cbm::algo gsl::span<T> fData; gsl::span<const size_t> fOffsets; - gsl::span<const u32> fAdresses; + gsl::span<const uint32_t> fAdresses; // FIXME code duplication with PartitionedVector @@ -176,10 +175,10 @@ namespace cbm::algo // template auto deduction template<typename T, template<typename> class Container> - PartitionedSpan(Container<T>&, gsl::span<const size_t>, gsl::span<const u32>) -> PartitionedSpan<T>; + PartitionedSpan(Container<T>&, gsl::span<const size_t>, gsl::span<const uint32_t>) -> PartitionedSpan<T>; template<typename T, template<typename> class Container> - PartitionedSpan(const Container<T>&, gsl::span<const size_t>, gsl::span<const u32>) -> PartitionedSpan<const T>; + PartitionedSpan(const Container<T>&, gsl::span<const size_t>, gsl::span<const uint32_t>) -> PartitionedSpan<const T>; template<typename T, typename Allocator> PartitionedSpan(PartitionedVector<T, Allocator>&) -> PartitionedSpan<T>; diff --git a/algo/base/PartitionedVector.h b/algo/base/pvector/PartitionedVector.h similarity index 91% rename from algo/base/PartitionedVector.h rename to algo/base/pvector/PartitionedVector.h index 6aa91585c0..6c8cab3b5f 100644 --- a/algo/base/PartitionedVector.h +++ b/algo/base/pvector/PartitionedVector.h @@ -4,8 +4,7 @@ #ifndef CBM_ALGO_BASE_PARTITIONED_VECTOR_H #define CBM_ALGO_BASE_PARTITIONED_VECTOR_H -#include "Definitions.h" -#include "util/PODAllocator.h" +#include "PODAllocator.h" #include <boost/serialization/access.hpp> #include <boost/serialization/vector.hpp> @@ -46,7 +45,7 @@ namespace cbm::algo * * @note Requires sizes.size() == addresses.size() */ - PartitionedVector(Container_t&& data, gsl::span<const size_t> sizes, gsl::span<const u32> addresses) + PartitionedVector(Container_t&& data, gsl::span<const size_t> sizes, gsl::span<const uint32_t> addresses) : fData(std::move(data)) , fOffsets() , fAddresses(addresses.begin(), addresses.end()) @@ -149,7 +148,7 @@ namespace cbm::algo /** * @brief Get the hardware address of partition i. */ - u32 Address(size_t i) const + uint32_t Address(size_t i) const { EnsureBounds(i); return fAddresses[i]; @@ -169,19 +168,19 @@ namespace cbm::algo /** * @brief Get a pair of the data and the hardware address of partition i. */ - std::pair<gsl::span<T>, u32> Partition(size_t i) + std::pair<gsl::span<T>, uint32_t> Partition(size_t i) { EnsureBounds(i); - return std::pair<gsl::span<T>, u32>(UnsafePartitionSpan(i), fAddresses[i]); + return std::pair<gsl::span<T>, uint32_t>(UnsafePartitionSpan(i), fAddresses[i]); } /** * @brief Get a pair of the data and the hardware address of partition i. */ - std::pair<gsl::span<const T>, u32> Partition(size_t i) const + std::pair<gsl::span<const T>, uint32_t> Partition(size_t i) const { EnsureBounds(i); - return std::pair<gsl::span<const T>, u32>(UnsafePartitionSpan(i), fAddresses[i]); + return std::pair<gsl::span<const T>, uint32_t>(UnsafePartitionSpan(i), fAddresses[i]); } /** @@ -221,7 +220,7 @@ namespace cbm::algo /** * @brief Get the addresses. */ - const std::vector<u32>& Addresses() const { return fAddresses; } + const std::vector<uint32_t>& Addresses() const { return fAddresses; } /** * @brief Get the underlying offsets. @@ -230,9 +229,9 @@ namespace cbm::algo private: - Container_t fData; //< Data - std::vector<size_t> fOffsets; // < Offsets of the partitions in fData - std::vector<u32> fAddresses; //< Hardware addresses of the partitions + Container_t fData; ///< Data + std::vector<size_t> fOffsets; ///< Offsets of the partitions in fData + std::vector<uint32_t> fAddresses; ///< Addresses of the partitions void EnsureDimensions() const { diff --git a/algo/test/_GTestPartitionedSpan.cxx b/algo/test/_GTestPartitionedSpan.cxx index ccc3823250..3da8519974 100644 --- a/algo/test/_GTestPartitionedSpan.cxx +++ b/algo/test/_GTestPartitionedSpan.cxx @@ -1,6 +1,9 @@ /* Copyright (C) 2023 FIAS Frankfurt Institute for Advanced Studies, Frankfurt / Main SPDX-License-Identifier: GPL-3.0-only Authors: Felix Weiglhofer [committer] */ + +#include "Definitions.h" + #include "PartitionedSpan.h" #include "PartitionedVector.h" diff --git a/algo/test/_GTestPartitionedVector.cxx b/algo/test/_GTestPartitionedVector.cxx index 49ab5b1760..61876f6c3c 100644 --- a/algo/test/_GTestPartitionedVector.cxx +++ b/algo/test/_GTestPartitionedVector.cxx @@ -2,6 +2,8 @@ SPDX-License-Identifier: GPL-3.0-only Authors: Felix Weiglhofer [committer] */ +#include "Definitions.h" + #include "PODVector.h" #include "PartitionedVector.h" #include "gtest/gtest.h" -- GitLab From aa3d366f49db4dd3739d2805d8ec3c332eb548fe Mon Sep 17 00:00:00 2001 From: "s.zharko@gsi.de" <s.zharko@gsi.de> Date: Thu, 19 Dec 2024 01:39:41 +0100 Subject: [PATCH 2/4] - Moving contents of PVector into the CbmContainers/OnlineContainers library; - the PartitionedVector and co. are moved from cbm::algo to the cbm namespace; - the CMake rule for building the OnlineData is moved from algo/data to algo/online/data directory --- algo/CMakeLists.txt | 44 +++++++++++++++++-- algo/base/CMakeLists.txt | 1 - algo/base/pvector/CMakeLists.txt | 21 --------- algo/detectors/bmon/Clusterizer.h | 2 +- algo/detectors/sts/HitfinderChain.cxx | 2 + algo/online/CMakeLists.txt | 6 +++ algo/online/containers/CMakeLists.txt | 17 +++++++ algo/{ => online}/data/CMakeLists.txt | 2 +- algo/test/_GTestPartitionedSpan.cxx | 4 +- algo/test/_GTestPartitionedVector.cxx | 5 ++- core/CMakeLists.txt | 1 + core/containers/CMakeLists.txt | 36 +++++++++++++++ .../containers}/PODAllocator.h | 4 +- .../pvector => core/containers}/PODVector.h | 4 +- .../containers}/PartitionedSpan.h | 9 ++-- .../containers}/PartitionedVector.h | 4 +- reco/steer/CbmSourceRecoTimeslice.cxx | 8 ++-- reco/steer/CbmSourceRecoTimeslice.h | 8 ++-- reco/tasks/CbmTaskInspectRecoTimeslice.h | 8 ++-- 19 files changed, 135 insertions(+), 51 deletions(-) delete mode 100644 algo/base/pvector/CMakeLists.txt create mode 100644 algo/online/CMakeLists.txt create mode 100644 algo/online/containers/CMakeLists.txt rename algo/{ => online}/data/CMakeLists.txt (96%) create mode 100644 core/containers/CMakeLists.txt rename {algo/base/pvector => core/containers}/PODAllocator.h (96%) rename {algo/base/pvector => core/containers}/PODVector.h (94%) rename {algo/base/pvector => core/containers}/PartitionedSpan.h (98%) rename {algo/base/pvector => core/containers}/PartitionedVector.h (99%) diff --git a/algo/CMakeLists.txt b/algo/CMakeLists.txt index 4f7f9b50ef..c08f4afc82 100644 --- a/algo/CMakeLists.txt +++ b/algo/CMakeLists.txt @@ -55,7 +55,7 @@ endif() add_subdirectory(base) add_subdirectory(log) add_subdirectory(ca) -add_subdirectory(data) +add_subdirectory(online) add_subdirectory(kf) add_subdirectory(kfp) @@ -216,7 +216,7 @@ target_include_directories(Algo target_link_libraries(Algo PUBLIC OnlineData - PVector + OnlineContainers KfCore CaCore ROOT::GenVector @@ -294,7 +294,7 @@ if (NOT CBM_ONLINE_STANDALONE) target_link_libraries(AlgoOffline PUBLIC CbmData - PVector + CbmContainers KfCoreOffline CaCoreOffline ROOT::GenVector @@ -362,11 +362,49 @@ install(DIRECTORY evbuild TYPE INCLUDE FILES_MATCHING PATTERN "*.h") install( FILES + base/ChainContext.h + base/Definitions.h + base/HistogramSender.h + base/Options.h + base/RecoParams.h + base/SubChain.h + base/System.h + base/PartitionedVector.h + base/PartitionedSpan.h + base/DigiData.h + base/PODVector.h + base/AlgoTraits.h + base/AuxDigiData.h + base/BuildInfo.h + base/Exceptions.h + base/MainConfig.h + evselector/DigiEventSelector.h + evselector/DigiEventSelectorConfig.h + trigger/DigiTriggerConfig.h + trigger/HitMultTrigger.h + trigger/TimeClusterTrigger.h + trigger/V0Trigger.h + trigger/V0TriggerConfig.h + unpack/CommonUnpacker.h + unpack/UnpackMSBase.h + global/ParFiles.h global/Reco.h global/RecoResults.h global/RecoResultsInputArchive.h global/RecoResultsOutputArchive.h global/StorableRecoResults.h + qa/Accumulators.h + qa/Histogram.h + ca/TrackingChain.h + ca/TrackingChainConfig.h + ca/TrackingDefs.h + ca/TrackingSetup.h + # NOTE: SZh 20.11.2023: + # The ca/qa directory depends on the online qa classes, so for now it has to be a part of the Algo library. + ca/qa/CaQa.h + DESTINATION include/ ) + + diff --git a/algo/base/CMakeLists.txt b/algo/base/CMakeLists.txt index ec043f688c..93b295fe0a 100644 --- a/algo/base/CMakeLists.txt +++ b/algo/base/CMakeLists.txt @@ -1,2 +1 @@ add_subdirectory(yaml) -add_subdirectory(pvector) diff --git a/algo/base/pvector/CMakeLists.txt b/algo/base/pvector/CMakeLists.txt deleted file mode 100644 index dd79d38da0..0000000000 --- a/algo/base/pvector/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -set(INCLUDE_DIRECTORIES - ${CMAKE_CURRENT_SOURCE_DIR} -) - -add_library(PVector INTERFACE) - -target_include_directories(PVector - INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} -) - -target_link_libraries(PVector - INTERFACE GSL -) - -install( - FILES - PartitionedVector.h - PartitionedSpan.h - DESTINATION - include/ -) diff --git a/algo/detectors/bmon/Clusterizer.h b/algo/detectors/bmon/Clusterizer.h index 86b3c76e3b..276f28d1ba 100644 --- a/algo/detectors/bmon/Clusterizer.h +++ b/algo/detectors/bmon/Clusterizer.h @@ -9,7 +9,7 @@ #pragma once -#include "base/PODVector.h" +#include "PODVector.h" #include "bmon/ClusterizerPars.h" #include "bmon/Hit.h" diff --git a/algo/detectors/sts/HitfinderChain.cxx b/algo/detectors/sts/HitfinderChain.cxx index 6f65f46212..2b4a4324b1 100644 --- a/algo/detectors/sts/HitfinderChain.cxx +++ b/algo/detectors/sts/HitfinderChain.cxx @@ -12,6 +12,8 @@ #include <numeric> using namespace cbm::algo; +using cbm::PartitionedSpan; +using cbm::PartitionedVector; void sts::HitfinderChain::SetParameters(const HitfinderChainPars& parameters) { diff --git a/algo/online/CMakeLists.txt b/algo/online/CMakeLists.txt new file mode 100644 index 0000000000..f72fc4858c --- /dev/null +++ b/algo/online/CMakeLists.txt @@ -0,0 +1,6 @@ +# A rule to build the online versions of CbmRoot core libraries +# +add_subdirectory(containers) +add_subdirectory(data) + + diff --git a/algo/online/containers/CMakeLists.txt b/algo/online/containers/CMakeLists.txt new file mode 100644 index 0000000000..34a95ef9d3 --- /dev/null +++ b/algo/online/containers/CMakeLists.txt @@ -0,0 +1,17 @@ +# Online version of libCbmContainers + +set(OFFLINE_CONTAINERS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../core/containers) + +add_library(OnlineContainers INTERFACE) + +target_include_directories(OnlineContainers + INTERFACE ${OFFLINE_CONTAINERS_DIR} +) + +target_compile_definitions(OnlineContainers INTERFACE NO_ROOT) + +target_link_libraries(OnlineContainers + INTERFACE GSL +) + +install(TARGETS OnlineContainers DESTINATION lib) diff --git a/algo/data/CMakeLists.txt b/algo/online/data/CMakeLists.txt similarity index 96% rename from algo/data/CMakeLists.txt rename to algo/online/data/CMakeLists.txt index 717ba53896..0d99f1d5fa 100644 --- a/algo/data/CMakeLists.txt +++ b/algo/online/data/CMakeLists.txt @@ -2,7 +2,7 @@ # the array . # The extension is already found. Any number of sources could be listed here. -set(OFFLINE_DATA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../core/data) +set(OFFLINE_DATA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../core/data) set(SRCS ${OFFLINE_DATA_DIR}/CbmDefs.cxx diff --git a/algo/test/_GTestPartitionedSpan.cxx b/algo/test/_GTestPartitionedSpan.cxx index 3da8519974..08bd000939 100644 --- a/algo/test/_GTestPartitionedSpan.cxx +++ b/algo/test/_GTestPartitionedSpan.cxx @@ -3,7 +3,6 @@ Authors: Felix Weiglhofer [committer] */ #include "Definitions.h" - #include "PartitionedSpan.h" #include "PartitionedVector.h" @@ -11,6 +10,9 @@ using namespace cbm::algo; +using cbm::PartitionedSpan; +using cbm::PartitionedVector; + template<typename T> void EXPECT_CONTAINER_EQ(gsl::span<T> a, std::vector<i32> b) { diff --git a/algo/test/_GTestPartitionedVector.cxx b/algo/test/_GTestPartitionedVector.cxx index 61876f6c3c..5eda3d2f97 100644 --- a/algo/test/_GTestPartitionedVector.cxx +++ b/algo/test/_GTestPartitionedVector.cxx @@ -3,13 +3,16 @@ Authors: Felix Weiglhofer [committer] */ #include "Definitions.h" - #include "PODVector.h" #include "PartitionedVector.h" #include "gtest/gtest.h" using namespace cbm::algo; +using cbm::PartitionedPODVector; +using cbm::PartitionedVector; +using cbm::PODAllocator; + template<typename T> void EXPECT_CONTAINER_EQ(gsl::span<const T> a, std::vector<T> b) { diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 7fa667426b..320b0dc4d6 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -2,6 +2,7 @@ set(CBMDATA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/data) set(CBMBASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/base) +add_subdirectory(containers) add_subdirectory(data) add_subdirectory(field) add_subdirectory(base) diff --git a/core/containers/CMakeLists.txt b/core/containers/CMakeLists.txt new file mode 100644 index 0000000000..d1987b2815 --- /dev/null +++ b/core/containers/CMakeLists.txt @@ -0,0 +1,36 @@ +# Library: CbmContainers +# +set(INCLUDE_DIRECTORIES + ${CMAKE_CURRENT_SOURCE_DIR} +) + +set(HEADERS + PartitionedVector.h + PartitionedSpan.h + PODVector.h + PODAllocator.h +) + +set(LIBRARY_NAME CbmContainers) + +add_library(${LIBRARY_NAME} INTERFACE) + +target_include_directories(${LIBRARY_NAME} + INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_link_libraries(${LIBRARY_NAME} + INTERFACE GSL +) + +install(TARGETS CbmContainers DESTINATION lib) + +install( + FILES + PartitionedVector.h + PartitionedSpan.h + PODAllocator.h + PODVector.h + DESTINATION + include/ +) diff --git a/algo/base/pvector/PODAllocator.h b/core/containers/PODAllocator.h similarity index 96% rename from algo/base/pvector/PODAllocator.h rename to core/containers/PODAllocator.h index 45f1ea89f3..8c0dcbc064 100644 --- a/algo/base/pvector/PODAllocator.h +++ b/core/containers/PODAllocator.h @@ -8,7 +8,7 @@ #include <type_traits> #include <utility> -namespace cbm::algo +namespace cbm { /** * @brief Allocator for plain old data types. @@ -39,6 +39,6 @@ namespace cbm::algo bool operator==(const PODAllocator&) const { return true; } bool operator!=(const PODAllocator&) const { return false; } }; -} // namespace cbm::algo +} // namespace cbm #endif // CBM_ALGO_BASE_POD_ALLOCATOR_H diff --git a/algo/base/pvector/PODVector.h b/core/containers/PODVector.h similarity index 94% rename from algo/base/pvector/PODVector.h rename to core/containers/PODVector.h index 587f50bce1..d63f042c93 100644 --- a/algo/base/pvector/PODVector.h +++ b/core/containers/PODVector.h @@ -8,7 +8,7 @@ #include <vector> -namespace cbm::algo +namespace cbm { /** * @brief PODVector is a std::vector that doesn't initialize its elements. @@ -28,6 +28,6 @@ namespace cbm::algo return PODVector<T>(vec.begin(), vec.end()); } -} // namespace cbm::algo +} // namespace cbm #endif // CBM_ALGO_BASE_POD_VECTOR_H diff --git a/algo/base/pvector/PartitionedSpan.h b/core/containers/PartitionedSpan.h similarity index 98% rename from algo/base/pvector/PartitionedSpan.h rename to core/containers/PartitionedSpan.h index beac6c2a7f..20cb76f12b 100644 --- a/algo/base/pvector/PartitionedSpan.h +++ b/core/containers/PartitionedSpan.h @@ -5,12 +5,12 @@ #define CBM_ALGO_BASE_PARTITIONED_SPAN_H #include <array> +#include <cstdint> #include <gsl/span> #include <stdexcept> #include <vector> -#include <cstdint> -namespace cbm::algo +namespace cbm { template<typename T, typename Allocator> @@ -65,7 +65,8 @@ namespace cbm::algo // FIXME disable if T is non-const via SFINAE template<size_t N> - PartitionedSpan(const std::array<T, N>& container, gsl::span<const size_t> offsets, gsl::span<const uint32_t> addresses) + PartitionedSpan(const std::array<T, N>& container, gsl::span<const size_t> offsets, + gsl::span<const uint32_t> addresses) : fData(container) , fOffsets(offsets) , fAdresses(addresses) @@ -186,6 +187,6 @@ namespace cbm::algo template<typename T, typename Allocator> PartitionedSpan(const PartitionedVector<T, Allocator>&) -> PartitionedSpan<const T>; -} // namespace cbm::algo +} // namespace cbm #endif diff --git a/algo/base/pvector/PartitionedVector.h b/core/containers/PartitionedVector.h similarity index 99% rename from algo/base/pvector/PartitionedVector.h rename to core/containers/PartitionedVector.h index 6c8cab3b5f..c059986094 100644 --- a/algo/base/pvector/PartitionedVector.h +++ b/core/containers/PartitionedVector.h @@ -12,7 +12,7 @@ #include <gsl/span> #include <vector> -namespace cbm::algo +namespace cbm { template<typename T> class PartitionedSpan; @@ -284,6 +284,6 @@ namespace cbm::algo template<typename T> using PartitionedPODVector = PartitionedVector<T, PODAllocator<T>>; -} // namespace cbm::algo +} // namespace cbm #endif diff --git a/reco/steer/CbmSourceRecoTimeslice.cxx b/reco/steer/CbmSourceRecoTimeslice.cxx index a94565dfcb..f429905509 100644 --- a/reco/steer/CbmSourceRecoTimeslice.cxx +++ b/reco/steer/CbmSourceRecoTimeslice.cxx @@ -79,22 +79,22 @@ Bool_t CbmSourceRecoTimeslice::Init() }; // TODO: replace individual vectors with reco-timeslice objects - fBmonHits = new PartitionedVector<bmon::Hit>(); + fBmonHits = new cbm::PartitionedVector<bmon::Hit>(); if (!RegisterVector(fBmonHits, "OnlineBmonHit")) { return kFALSE; } - fStsHits = new PartitionedVector<sts::Hit>(); + fStsHits = new cbm::PartitionedVector<sts::Hit>(); if (!RegisterVector(fStsHits, "OnlineStsHit")) { return kFALSE; } - fTrdHits = new PartitionedVector<trd::Hit>(); + fTrdHits = new cbm::PartitionedVector<trd::Hit>(); if (!RegisterVector(fTrdHits, "OnlineTrdHit")) { return kFALSE; } - fTofHits = new PartitionedVector<tof::Hit>(); + fTofHits = new cbm::PartitionedVector<tof::Hit>(); if (!RegisterVector(fTofHits, "OnlineTofHit")) { return kFALSE; } diff --git a/reco/steer/CbmSourceRecoTimeslice.h b/reco/steer/CbmSourceRecoTimeslice.h index 1d0b907a6e..1b2763ab2a 100644 --- a/reco/steer/CbmSourceRecoTimeslice.h +++ b/reco/steer/CbmSourceRecoTimeslice.h @@ -81,10 +81,10 @@ class CbmSourceRecoTimeslice : public FairSource { void ClearOutputVectors(); //* Data containers - cbm::algo::PartitionedVector<cbm::algo::bmon::Hit>* fBmonHits{nullptr}; - cbm::algo::PartitionedVector<cbm::algo::sts::Hit>* fStsHits{nullptr}; - cbm::algo::PartitionedVector<cbm::algo::trd::Hit>* fTrdHits{nullptr}; - cbm::algo::PartitionedVector<cbm::algo::tof::Hit>* fTofHits{nullptr}; + cbm::PartitionedVector<cbm::algo::bmon::Hit>* fBmonHits{nullptr}; + cbm::PartitionedVector<cbm::algo::sts::Hit>* fStsHits{nullptr}; + cbm::PartitionedVector<cbm::algo::trd::Hit>* fTrdHits{nullptr}; + cbm::PartitionedVector<cbm::algo::tof::Hit>* fTofHits{nullptr}; cbm::algo::ca::Vector<cbm::algo::ca::Track>* fTracks{nullptr}; cbm::algo::StorableRecoResults::TrackHitIndexContainer_t* fTrackStsHitIndices{nullptr}; cbm::algo::StorableRecoResults::TrackHitIndexContainer_t* fTrackTrdHitIndices{nullptr}; diff --git a/reco/tasks/CbmTaskInspectRecoTimeslice.h b/reco/tasks/CbmTaskInspectRecoTimeslice.h index 16365d5f41..d1722a851b 100644 --- a/reco/tasks/CbmTaskInspectRecoTimeslice.h +++ b/reco/tasks/CbmTaskInspectRecoTimeslice.h @@ -53,10 +53,10 @@ class CbmTaskInspectRecoTimeslice : public FairTask { virtual InitStatus Init(); //* Data containers - const cbm::algo::PartitionedVector<cbm::algo::bmon::Hit>* fBmonHits{nullptr}; - const cbm::algo::PartitionedVector<cbm::algo::sts::Hit>* fStsHits{nullptr}; - const cbm::algo::PartitionedVector<cbm::algo::trd::Hit>* fTrdHits{nullptr}; - const cbm::algo::PartitionedVector<cbm::algo::tof::Hit>* fTofHits{nullptr}; + const cbm::PartitionedVector<cbm::algo::bmon::Hit>* fBmonHits{nullptr}; + const cbm::PartitionedVector<cbm::algo::sts::Hit>* fStsHits{nullptr}; + const cbm::PartitionedVector<cbm::algo::trd::Hit>* fTrdHits{nullptr}; + const cbm::PartitionedVector<cbm::algo::tof::Hit>* fTofHits{nullptr}; const cbm::algo::ca::Vector<cbm::algo::ca::Track>* fTracks{nullptr}; const cbm::algo::StorableRecoResults::TrackHitIndexContainer_t* fTrackStsHitIndices{nullptr}; const cbm::algo::StorableRecoResults::TrackHitIndexContainer_t* fTrackTrdHitIndices{nullptr}; -- GitLab From ba37ad6cc3b7d25a6ed33b92f8b2af7df4bc6ceb Mon Sep 17 00:00:00 2001 From: "s.zharko@gsi.de" <s.zharko@gsi.de> Date: Fri, 18 Apr 2025 08:05:50 +0200 Subject: [PATCH 3/4] PODAllocator: loosen the requirements on T to non-polymorphic This does not break the allocation mechanism, but allows to use the PODAllocator with derived classes, which still do not rely on virtual functions. --- algo/CMakeLists.txt | 3 --- core/containers/PODAllocator.h | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/algo/CMakeLists.txt b/algo/CMakeLists.txt index c08f4afc82..1f32b344d6 100644 --- a/algo/CMakeLists.txt +++ b/algo/CMakeLists.txt @@ -369,10 +369,7 @@ install( base/RecoParams.h base/SubChain.h base/System.h - base/PartitionedVector.h - base/PartitionedSpan.h base/DigiData.h - base/PODVector.h base/AlgoTraits.h base/AuxDigiData.h base/BuildInfo.h diff --git a/core/containers/PODAllocator.h b/core/containers/PODAllocator.h index 8c0dcbc064..c276655e06 100644 --- a/core/containers/PODAllocator.h +++ b/core/containers/PODAllocator.h @@ -22,7 +22,7 @@ namespace cbm // static_assert(std::is_trivially_constructible_v<T>, "PODAllocator only works for POD types"); // Ensure T has no vtable - static_assert(std::is_standard_layout_v<T>, "PODAllocator only works with types with standard layout"); + static_assert(!std::is_polymorphic_v<T>, "PODAllocator only works with types with non-polymorphic types"); using value_type = T; -- GitLab From 3041236d1f9d3870893af8082049a1d88f2b3ce1 Mon Sep 17 00:00:00 2001 From: "s.zharko@gsi.de" <s.zharko@gsi.de> Date: Tue, 22 Apr 2025 21:12:27 +0200 Subject: [PATCH 4/4] Moving cbm::algo::EnumDict to CbmUtility library as cbm::util::EnumDict --- algo/CMakeLists.txt | 9 +++--- algo/base/CMakeLists.txt | 1 - algo/base/Definitions.h | 20 ++++++------ algo/base/RecoParams.h | 11 +++---- algo/base/util/ProfilingLevel.h | 2 +- algo/detectors/sts/HitfinderChain.cxx | 2 +- algo/global/ParFiles.cxx | 2 +- algo/global/Reco.cxx | 2 +- algo/unpack/CommonUnpacker.cxx | 4 +-- algo/unpack/CommonUnpacker.h | 4 +-- core/CMakeLists.txt | 1 + core/containers/CMakeLists.txt | 3 ++ core/qa/CMakeLists.txt | 1 - core/utility/CMakeLists.txt | 31 +++++++++++++++++++ .../utility/CbmEnumDict.cxx | 4 +-- .../EnumDict.h => core/utility/CbmEnumDict.h | 20 ++++++------ {algo/base => core/utility}/yaml/BaseTypes.h | 0 .../base => core/utility}/yaml/CMakeLists.txt | 5 +-- {algo/base => core/utility}/yaml/Property.h | 2 -- {algo/base => core/utility}/yaml/Yaml.h | 27 +++++++++++----- 20 files changed, 98 insertions(+), 53 deletions(-) delete mode 100644 algo/base/CMakeLists.txt create mode 100644 core/utility/CMakeLists.txt rename algo/base/util/EnumDict.cxx => core/utility/CbmEnumDict.cxx (85%) rename algo/base/util/EnumDict.h => core/utility/CbmEnumDict.h (87%) rename {algo/base => core/utility}/yaml/BaseTypes.h (100%) rename {algo/base => core/utility}/yaml/CMakeLists.txt (68%) rename {algo/base => core/utility}/yaml/Property.h (99%) rename {algo/base => core/utility}/yaml/Yaml.h (93%) diff --git a/algo/CMakeLists.txt b/algo/CMakeLists.txt index 1f32b344d6..c4100eca53 100644 --- a/algo/CMakeLists.txt +++ b/algo/CMakeLists.txt @@ -50,9 +50,9 @@ if (CBM_ONLINE_STANDALONE) include(CbmMacros) # for 'download_project_if_needed', 'Gen_Exe_Script' macro add_subdirectory(../external external) + add_subdirectory(../core/utility utility) endif() -add_subdirectory(base) add_subdirectory(log) add_subdirectory(ca) add_subdirectory(online) @@ -81,7 +81,6 @@ set(SRCS base/compat/Algorithm.cxx base/util/MemoryLogger.cxx base/util/StlUtils.cxx - base/util/EnumDict.cxx base/util/TimingsFormat.cxx data/sts/HitfinderPars.cxx data/sts/LandauTable.cxx @@ -216,6 +215,8 @@ target_include_directories(Algo target_link_libraries(Algo PUBLIC OnlineData + CbmUtility + CbmYamlInterface OnlineContainers KfCore CaCore @@ -234,7 +235,6 @@ target_link_libraries(Algo cppzmq poolstl PRIVATE CbmKFParticleOnlineInterface - INTERFACE CbmYamlInterface ) target_compile_definitions(Algo PUBLIC NO_ROOT) xpu_attach(Algo ${DEVICE_SRCS}) @@ -294,6 +294,8 @@ if (NOT CBM_ONLINE_STANDALONE) target_link_libraries(AlgoOffline PUBLIC CbmData + CbmYamlInterface + CbmUtility CbmContainers KfCoreOffline CaCoreOffline @@ -312,7 +314,6 @@ if (NOT CBM_ONLINE_STANDALONE) cppzmq poolstl PRIVATE CbmKFParticleOnlineInterface - INTERFACE CbmYamlInterface ) xpu_attach(AlgoOffline ${DEVICE_SRCS}) diff --git a/algo/base/CMakeLists.txt b/algo/base/CMakeLists.txt deleted file mode 100644 index 93b295fe0a..0000000000 --- a/algo/base/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(yaml) diff --git a/algo/base/Definitions.h b/algo/base/Definitions.h index c9cac7a917..73cc85bf77 100644 --- a/algo/base/Definitions.h +++ b/algo/base/Definitions.h @@ -4,8 +4,8 @@ #ifndef CBM_BASE_TYPES_H #define CBM_BASE_TYPES_H +#include "CbmEnumDict.h" #include "MicrosliceDescriptor.hpp" // For fles::Subsystem -#include "util/EnumDict.h" #include <cstdint> @@ -108,18 +108,18 @@ CBM_ENUM_DICT(fles::Subsystem, ); CBM_ENUM_DICT(cbm::algo::Step, - {"Unpack", Step::Unpack}, - {"DigiTrigger", Step::DigiTrigger}, - {"LocalReco", Step::LocalReco}, - {"Tracking", Step::Tracking} + {"Unpack", cbm::algo::Step::Unpack}, + {"DigiTrigger", cbm::algo::Step::DigiTrigger}, + {"LocalReco", cbm::algo::Step::LocalReco}, + {"Tracking", cbm::algo::Step::Tracking} ); CBM_ENUM_DICT(cbm::algo::RecoData, - {"DigiTimeslice", RecoData::DigiTimeslice}, - {"DigiEvent", RecoData::DigiEvent}, - {"Cluster", RecoData::Cluster}, - {"Hit", RecoData::Hit}, - {"Track", RecoData::Track} + {"DigiTimeslice", cbm::algo::RecoData::DigiTimeslice}, + {"DigiEvent", cbm::algo::RecoData::DigiEvent}, + {"Cluster", cbm::algo::RecoData::Cluster}, + {"Hit", cbm::algo::RecoData::Hit}, + {"Track", cbm::algo::RecoData::Track} ); CBM_ENUM_DICT(cbm::algo::Setup, diff --git a/algo/base/RecoParams.h b/algo/base/RecoParams.h index db747f189c..c933c63de1 100644 --- a/algo/base/RecoParams.h +++ b/algo/base/RecoParams.h @@ -5,7 +5,6 @@ #define CBM_ALGO_BASE_RECOPARAMS_H #include "Definitions.h" -#include "util/EnumDict.h" #include "yaml/Property.h" #include "yaml/Yaml.h" @@ -106,14 +105,14 @@ namespace cbm::algo CBM_YAML_EXTERN_DECL(cbm::algo::RecoParams); CBM_ENUM_DICT(cbm::algo::RecoParams::SortMode, - {"BlockSort", RecoParams::SortMode::BlockSort}, - {"CUBSegmentedSort", RecoParams::SortMode::CUBSegmentedSort} + {"BlockSort", cbm::algo::RecoParams::SortMode::BlockSort}, + {"CUBSegmentedSort", cbm::algo::RecoParams::SortMode::CUBSegmentedSort} ); CBM_ENUM_DICT(cbm::algo::RecoParams::AllocationMode, - {"Auto", RecoParams::AllocationMode::Auto}, - {"Static", RecoParams::AllocationMode::Static}, - {"Dynamic", RecoParams::AllocationMode::Dynamic} + {"Auto", cbm::algo::RecoParams::AllocationMode::Auto}, + {"Static", cbm::algo::RecoParams::AllocationMode::Static}, + {"Dynamic", cbm::algo::RecoParams::AllocationMode::Dynamic} ); #endif // CBM_ALGO_BASE_RECOPARAMS_H diff --git a/algo/base/util/ProfilingLevel.h b/algo/base/util/ProfilingLevel.h index d358bd36c9..5d9469359e 100644 --- a/algo/base/util/ProfilingLevel.h +++ b/algo/base/util/ProfilingLevel.h @@ -4,7 +4,7 @@ #pragma once -#include "EnumDict.h" +#include "CbmEnumDict.h" namespace cbm::algo { diff --git a/algo/detectors/sts/HitfinderChain.cxx b/algo/detectors/sts/HitfinderChain.cxx index 2b4a4324b1..5796cfa54b 100644 --- a/algo/detectors/sts/HitfinderChain.cxx +++ b/algo/detectors/sts/HitfinderChain.cxx @@ -32,7 +32,7 @@ void sts::HitfinderChain::SetParameters(const HitfinderChainPars& parameters) if (!memoryPars.IsDynamic() && !memoryPars.IsStatic()) { throw std::runtime_error( - fmt::format("STS Hitfinder Chain: Unknown allocation mode: {}", ToString(memoryPars.allocationMode))); + fmt::format("STS Hitfinder Chain: Unknown allocation mode: {}", util::ToString(memoryPars.allocationMode))); } if (memoryPars.IsStatic()) { diff --git a/algo/global/ParFiles.cxx b/algo/global/ParFiles.cxx index 9d4e8ee2cd..85134bd4bb 100644 --- a/algo/global/ParFiles.cxx +++ b/algo/global/ParFiles.cxx @@ -124,6 +124,6 @@ ParFiles::ParFiles(uint32_t runId) kfp.V0FinderConfig = "mcbm2025_02/kfp_lambda_v25a.yaml"; break; - default: throw FatalError("Unknown setup: {}", ToString(setup)); + default: throw FatalError("Unknown setup: {}", util::ToString(setup)); } } diff --git a/algo/global/Reco.cxx b/algo/global/Reco.cxx index 1554da152a..3736872a02 100644 --- a/algo/global/Reco.cxx +++ b/algo/global/Reco.cxx @@ -646,7 +646,7 @@ void Reco::QueueUnpackerMetricsDet(const UnpackMonitor<MSMonitor>& monitor) return; } - std::string_view det = ToString(monitor.system); + std::string_view det = util::ToString(monitor.system); auto MkKey = [&](std::string_view key) { return fmt::format("{}{}", key, Capitalize(det)); }; diff --git a/algo/unpack/CommonUnpacker.cxx b/algo/unpack/CommonUnpacker.cxx index d7cc52db07..ba737260e9 100644 --- a/algo/unpack/CommonUnpacker.cxx +++ b/algo/unpack/CommonUnpacker.cxx @@ -23,7 +23,7 @@ detail::MSData::MSData(const fles::Timeslice& ts, fles::Subsystem subsystem, gsl if (std::find(legalEqIds.begin(), legalEqIds.end(), componentId) == legalEqIds.end()) { L_(error) << "Invalid equipment id 0x" << std::hex << std::setw(4) << componentId << std::dec << " for subsystem " - << ToString(subsystem); + << util::ToString(subsystem); monitor.errInvalidEqId++; continue; } @@ -36,5 +36,5 @@ detail::MSData::MSData(const fles::Timeslice& ts, fles::Subsystem subsystem, gsl msContent.push_back(ts.content(comp, mslice)); } } - L_(debug) << "Found " << monitor.numMs << " microslices for subsystem " << ToString(subsystem); + L_(debug) << "Found " << monitor.numMs << " microslices for subsystem " << util::ToString(subsystem); } diff --git a/algo/unpack/CommonUnpacker.h b/algo/unpack/CommonUnpacker.h index 3db3952e78..3d644c1c9b 100644 --- a/algo/unpack/CommonUnpacker.h +++ b/algo/unpack/CommonUnpacker.h @@ -118,12 +118,12 @@ namespace cbm::algo if (algo == fAlgos.end()) { if (!Contains(legalEqIds, msDesc.eq_id)) { L_(error) << "Invalid equip id " << std::hex << int{msDesc.eq_id} << std::dec << " for subsystem " - << ToString(subsystem); + << util::ToString(subsystem); monitorOut.errInvalidEqId++; } else { L_(error) << "Invalid system version " << std::hex << int{msDesc.sys_ver} << std::dec << " for subsystem " - << ToString(subsystem); + << util::ToString(subsystem); monitorOut.errInvalidSysVer++; } continue; diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 320b0dc4d6..c574819054 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -7,6 +7,7 @@ add_subdirectory(data) add_subdirectory(field) add_subdirectory(base) add_subdirectory(qa) +add_subdirectory(utility) add_subdirectory(detectors/trd) add_subdirectory(detectors/rich) diff --git a/core/containers/CMakeLists.txt b/core/containers/CMakeLists.txt index d1987b2815..6de870b63a 100644 --- a/core/containers/CMakeLists.txt +++ b/core/containers/CMakeLists.txt @@ -1,5 +1,8 @@ # Library: CbmContainers # + +message("!!!! BUILDING CbmContainers") + set(INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR} ) diff --git a/core/qa/CMakeLists.txt b/core/qa/CMakeLists.txt index 9b022d7bb8..18f04ce3ab 100644 --- a/core/qa/CMakeLists.txt +++ b/core/qa/CMakeLists.txt @@ -2,7 +2,6 @@ set(INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/checker ${CMAKE_CURRENT_SOURCE_DIR}/report ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_SOURCE_DIR}/algo/base # For "algo/base/yaml/*.h" included as relative "yaml/?????.h" to fit install tree ) set(SRCS diff --git a/core/utility/CMakeLists.txt b/core/utility/CMakeLists.txt new file mode 100644 index 0000000000..f4e2b13683 --- /dev/null +++ b/core/utility/CMakeLists.txt @@ -0,0 +1,31 @@ +# A library for CBM common utilities. The utilities include generic functions and classes +# to extend the STL and BOOST C++. The library is not a place for a detector- or analysis-specific +# software. +# +add_subdirectory(yaml) + +set(SRCS + CbmEnumDict.cxx +) + +add_library(CbmUtility SHARED ${SRCS}) + +target_include_directories(CbmUtility + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_link_libraries(CbmUtility + PUBLIC GSL + fmt::fmt + xpu +) + +install(TARGETS CbmUtility DESTINATION lib) + +install( + FILES + CbmEnumDict.h + DESTINATION + include/ +) + diff --git a/algo/base/util/EnumDict.cxx b/core/utility/CbmEnumDict.cxx similarity index 85% rename from algo/base/util/EnumDict.cxx rename to core/utility/CbmEnumDict.cxx index a0ffd40f36..960d54df60 100644 --- a/algo/base/util/EnumDict.cxx +++ b/core/utility/CbmEnumDict.cxx @@ -1,11 +1,11 @@ /* Copyright (C) 2023 FIAS Frankfurt Institute for Advanced Studies, Frankfurt / Main SPDX-License-Identifier: GPL-3.0-only Authors: Felix Weiglhofer [committer] */ -#include "EnumDict.h" +#include "CbmEnumDict.h" #include <sstream> -void cbm::algo::detail::RaiseUnknownEntry(std::string_view str, const std::vector<std::string_view>& validEntries) +void cbm::util::detail::RaiseUnknownEntry(std::string_view str, const std::vector<std::string_view>& validEntries) { std::ostringstream oss; oss << "Could not parse '" << str << "'. Valid entries are: "; diff --git a/algo/base/util/EnumDict.h b/core/utility/CbmEnumDict.h similarity index 87% rename from algo/base/util/EnumDict.h rename to core/utility/CbmEnumDict.h index fde2d6d785..c60ab8a5a0 100644 --- a/algo/base/util/EnumDict.h +++ b/core/utility/CbmEnumDict.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2023 FIAS Frankfurt Institute for Advanced Studies, Frankfurt / Main +/* Copyright (C) 2023-2025 FIAS Frankfurt Institute for Advanced Studies, Frankfurt / Main SPDX-License-Identifier: GPL-3.0-only Authors: Felix Weiglhofer [committer] */ #ifndef CBM_ALGO_BASE_UTIL_SERIALIZABLEENUM_H @@ -16,7 +16,7 @@ #include <fmt/format.h> #include <xpu/defines.h> -namespace cbm::algo +namespace cbm::util { namespace detail { @@ -68,7 +68,7 @@ namespace cbm::algo if (it == dict.end()) throw std::runtime_error(fmt::format("Entry {} for enum missing!", static_cast<int>(t))); return it->first; } -} // namespace cbm::algo +} // namespace cbm::util #if XPU_IS_CPU /** @@ -97,9 +97,9 @@ namespace cbm::algo */ #define CBM_ENUM_DICT(type, ...) \ template<> \ - inline const cbm::algo::detail::EnumDict_t<type> cbm::algo::detail::EnumDict<type> = {__VA_ARGS__}; \ + inline const cbm::util::detail::EnumDict_t<type> cbm::util::detail::EnumDict<type> = {__VA_ARGS__}; \ template<> \ - struct cbm::algo::detail::EnumHasDict<type> : std::true_type { \ + struct cbm::util::detail::EnumHasDict<type> : std::true_type { \ } #else // XPU_IS_CPU // Disable macro in GPU code, causes some issues with nvcc @@ -110,22 +110,22 @@ namespace cbm::algo // Placed in global namespace to be found by ADL e.g. for std::ostream_iterator namespace std { - template<typename T, typename = std::enable_if_t<cbm::algo::detail::EnumHasDict_v<T>>> + template<typename T, typename = std::enable_if_t<cbm::util::detail::EnumHasDict_v<T>>> std::ostream& operator<<(std::ostream& os, T t) { - os << cbm::algo::ToString(t); + os << cbm::util::ToString(t); return os; } - template<typename T, typename = std::enable_if_t<cbm::algo::detail::EnumHasDict_v<T>>> + template<typename T, typename = std::enable_if_t<cbm::util::detail::EnumHasDict_v<T>>> std::istream& operator>>(std::istream& is, T& t) { std::string str; is >> str; - auto maybet = cbm::algo::FromString<T>(str); + auto maybet = cbm::util::FromString<T>(str); if (!maybet) { - cbm::algo::detail::RaiseUnknownEntry(str, cbm::algo::detail::ValidEntries<T>()); + cbm::util::detail::RaiseUnknownEntry(str, cbm::util::detail::ValidEntries<T>()); } t = *maybet; diff --git a/algo/base/yaml/BaseTypes.h b/core/utility/yaml/BaseTypes.h similarity index 100% rename from algo/base/yaml/BaseTypes.h rename to core/utility/yaml/BaseTypes.h diff --git a/algo/base/yaml/CMakeLists.txt b/core/utility/yaml/CMakeLists.txt similarity index 68% rename from algo/base/yaml/CMakeLists.txt rename to core/utility/yaml/CMakeLists.txt index 756401d832..992fcfc5cc 100644 --- a/algo/base/yaml/CMakeLists.txt +++ b/core/utility/yaml/CMakeLists.txt @@ -1,15 +1,16 @@ set(INCLUDE_DIRECTORIES - ${CMAKE_SOURCE_DIR}/algo/base # For "algo/base/yaml/*.h" included as relative "yaml/?????.h" to fit install tree + ${CMAKE_CURRENT_SOURCE_DIR}/.. # For inclusions like "yaml/Yaml.h" ) add_library(CbmYamlInterface INTERFACE) target_include_directories(CbmYamlInterface - INTERFACE ${CMAKE_CURRENT_SOURCE_DIR} + INTERFACE ${INCLUDE_DIRECTORIES} ) target_link_libraries(CbmYamlInterface INTERFACE GSL + CbmUtility xpu fmt::fmt external::yaml-cpp diff --git a/algo/base/yaml/Property.h b/core/utility/yaml/Property.h similarity index 99% rename from algo/base/yaml/Property.h rename to core/utility/yaml/Property.h index 223a978542..95ef674408 100644 --- a/algo/base/yaml/Property.h +++ b/core/utility/yaml/Property.h @@ -5,8 +5,6 @@ #define CBM_YAML_PROPERTY_H #pragma once -#include "Definitions.h" - #include <optional> #include <string_view> #include <tuple> diff --git a/algo/base/yaml/Yaml.h b/core/utility/yaml/Yaml.h similarity index 93% rename from algo/base/yaml/Yaml.h rename to core/utility/yaml/Yaml.h index e5dfa3d33a..13cbbf58d4 100644 --- a/algo/base/yaml/Yaml.h +++ b/core/utility/yaml/Yaml.h @@ -5,12 +5,12 @@ #define CBM_YAML_YAML_H #pragma once -#include "Definitions.h" -#include "compat/Filesystem.h" -#include "util/EnumDict.h" +#include "CbmEnumDict.h" #include "yaml/BaseTypes.h" #include "yaml/Property.h" +#include <boost/filesystem.hpp> + #include <sstream> #include <string_view> @@ -19,6 +19,19 @@ namespace cbm::algo::yaml { + namespace fs = boost::filesystem; + + // typealias for Rust-like fixed size integer types + using i8 = std::int8_t; + using u8 = std::uint8_t; + using i16 = std::int16_t; + using u16 = std::uint16_t; + using i32 = std::int32_t; + using u32 = std::uint32_t; + using i64 = std::int64_t; + using u64 = std::uint64_t; + using f32 = float; + using f64 = double; template<typename T> T Read(const YAML::Node& node); @@ -71,14 +84,14 @@ namespace cbm::algo::yaml #endif using Type = std::remove_cv_t<std::remove_reference_t<T>>; - static_assert(!IsEnum<T> || detail::EnumHasDict_v<T>, "Enum must have a dictionary to be deserializable"); + static_assert(!IsEnum<T> || util::detail::EnumHasDict_v<T>, "Enum must have a dictionary to be deserializable"); // TODO: error handling if constexpr (IsFundamental<Type>) { return node.as<Type>(); } else if constexpr (IsEnum<Type>) { - std::optional<T> maybet = FromString<T>(node.as<std::string>()); + std::optional<T> maybet = util::FromString<T>(node.as<std::string>()); if (!maybet) { throw std::runtime_error(fmt::format("Invalid enum value: {}", node.as<std::string>())); } @@ -207,7 +220,7 @@ namespace cbm::algo::yaml template<typename T> void DoDump(const T& object, YAML::Emitter& ss, std::optional<YAML::EMITTER_MANIP> formatEntries = {}) { - static_assert(!IsEnum<T> || detail::EnumHasDict_v<T>, "Enum must have a dictionary"); + static_assert(!IsEnum<T> || util::detail::EnumHasDict_v<T>, "Enum must have a dictionary"); if constexpr (IsFundamental<T>) { // Take care that i8 and u8 are printed as integers not as characters @@ -217,7 +230,7 @@ namespace cbm::algo::yaml ss << object; } else if constexpr (IsEnum<T>) { - ss << std::string{ToString<T>(object)}; + ss << std::string{util::ToString<T>(object)}; } else if constexpr (IsVector<T> || IsArray<T> || IsSet<T>) { ss << YAML::BeginSeq; -- GitLab