Skip to content

Commit

Permalink
Separating datasource into standalone library
Browse files Browse the repository at this point in the history
  • Loading branch information
kjvbrt committed Jul 25, 2024
1 parent 29f88a0 commit 3dc015b
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 78 deletions.
12 changes: 8 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,25 @@ option(CREATE_DOC "Whether or not to create doxygen doc target." OFF)
option(ENABLE_SIO "Build SIO I/O support" OFF)
option(PODIO_RELAX_PYVER "Do not require exact python version match with ROOT" OFF)
option(ENABLE_RNTUPLE "Build with support for the new ROOT NTtuple format" OFF)
option(ENABLE_DATASOURCE "Build podio's ROOT DataSource" OFF)
option(PODIO_USE_CLANG_FORMAT "Use clang-format to format the code" OFF)
option(ENABLE_JULIA "Enable Julia support. When enabled, Julia datamodels will be generated, and Julia tests will run." OFF)


#--- Declare ROOT dependency ---------------------------------------------------
list(APPEND CMAKE_PREFIX_PATH $ENV{ROOTSYS})
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
if(NOT ENABLE_RNTUPLE)
find_package(ROOT REQUIRED COMPONENTS RIO Tree ROOTDataFrame)
else()
find_package(ROOT REQUIRED COMPONENTS RIO Tree ROOTNTuple)
set(root_components_needed RIO Tree)
if(ENABLE_RNTUPLE)
list(APPEND root_components_needed ROOTNTuple)
if(${ROOT_VERSION} VERSION_LESS 6.28.02)
message(FATAL_ERROR "You are trying to build podio with support for the new ROOT NTuple format, but your ROOT version is too old. Please update ROOT to at least version 6.28.02")
endif()
endif()
if(ENABLE_DATASOURCE)
list(APPEND root_components_needed ROOTDataFrame)
endif()
find_package(ROOT REQUIRED COMPONENTS ${root_components_needed})

# ROOT_CXX_STANDARD was introduced in https://github.com/root-project/root/pull/6466
# before that it's an empty variable so we check if it's any number > 0
Expand Down
45 changes: 21 additions & 24 deletions include/podio/ROOTDataSource.h → include/podio/DataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,64 +18,61 @@
#include <vector>

namespace podio {
class ROOTDataSource : public ROOT::RDF::RDataSource {
class DataSource : public ROOT::RDF::RDataSource {
public:
///
/// @brief Construct the podio::ROOTDataSource from the provided file.
/// @brief Construct the podio::DataSource from the provided file.
///
explicit ROOTDataSource(const std::string& filePath, int nEvents = -1);
explicit DataSource(const std::string& filePath, int nEvents = -1);

///
/// @brief Construct the podio::ROOTDataSource from the provided file
/// list.
/// @brief Construct the podio::DataSource from the provided file list.
///
explicit ROOTDataSource(const std::vector<std::string>& filePathList, int nEvents = -1);
explicit DataSource(const std::vector<std::string>& filePathList, int nEvents = -1);

///
/// @brief Inform the podio::ROOTDataSource of the desired level of
/// parallelism.
/// @brief Inform the podio::DataSource of the desired level of parallelism.
///
void SetNSlots(unsigned int nSlots) override;

///
/// @brief Retrieve from podio::ROOTDataSource per-thread readers for the
/// desired columns.
/// @brief Retrieve from podio::DataSource per-thread readers for the desired
/// columns.
///
template <typename T>
std::vector<T**> GetColumnReaders(std::string_view columnName);

///
/// @brief Inform podio::ROOTDataSource that an event-loop is about to
/// start.
/// @brief Inform podio::DataSource that an event-loop is about to start.
///
void Initialize() override;

///
/// @brief Retrieve from podio::ROOTDataSource a set of ranges of entries
/// that can be processed concurrently.
/// @brief Retrieve from podio::DataSource a set of ranges of entries that
/// can be processed concurrently.
///
std::vector<std::pair<ULong64_t, ULong64_t>> GetEntryRanges() override;

///
/// @brief Inform podio::ROOTDataSource that a certain thread is about to
/// start working on a certain range of entries.
/// @brief Inform podio::DataSource that a certain thread is about to start
/// working on a certain range of entries.
///
void InitSlot(unsigned int slot, ULong64_t firstEntry) override;

///
/// @brief Inform podio::ROOTDataSource that a certain thread is about to
/// start working on a certain entry.
/// @brief Inform podio::DataSource that a certain thread is about to start
/// working on a certain entry.
///
bool SetEntry(unsigned int slot, ULong64_t entry) override;

///
/// @brief Inform podio::ROOTDataSource that a certain thread finished
/// working on a certain range of entries.
/// @brief Inform podio::DataSource that a certain thread finished working
/// on a certain range of entries.
///
void FinalizeSlot(unsigned int slot) override;

///
/// @brief Inform podio::ROOTDataSource that an event-loop finished.
/// @brief Inform podio::DataSource that an event-loop finished.
///
void Finalize() override;

Expand Down Expand Up @@ -141,7 +138,7 @@ class ROOTDataSource : public ROOT::RDF::RDataSource {
std::vector<std::unique_ptr<podio::Frame>> m_frames = {};

///
/// @brief Setup input for the podio::ROOTDataSource.
/// @brief Setup input for the podio::DataSource.
///
/// @param[in] Number of events.
/// @return void.
Expand All @@ -153,8 +150,8 @@ class ROOTDataSource : public ROOT::RDF::RDataSource {
/// Not used.
///
template <typename T>
std::vector<T**> ROOTDataSource::GetColumnReaders(std::string_view) {
// std::cout << "podio::ROOTDataSource: Getting column readers for column: " << columnName << std::endl;
std::vector<T**> DataSource::GetColumnReaders(std::string_view) {
// std::cout << "podio::DataSource: Getting column readers for column: " << columnName << std::endl;

std::vector<T**> readers;

Expand Down
76 changes: 58 additions & 18 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ FUNCTION(PODIO_ADD_LIB_AND_DICT libname headers sources selection )
target_include_directories(${dictname} PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_link_libraries(${dictname} PUBLIC podio::${libname} podio::podio
podio::podioIO ROOT::Core ROOT::Tree)
target_link_libraries(${dictname} PUBLIC podio::${libname} podio::podio ROOT::Core ROOT::Tree)
if(ENABLE_RNTUPLE)
target_link_libraries(${dictname} PUBLIC ROOT::ROOTNTuple)
endif()
Expand Down Expand Up @@ -83,7 +82,6 @@ SET(root_sources
ROOTLegacyReader.cc
ROOTFrameData.cc
RootHelpers.cc
ROOTDataSource.cc
)
if(ENABLE_RNTUPLE)
list(APPEND root_sources
Expand All @@ -98,7 +96,6 @@ SET(root_headers
${PROJECT_SOURCE_DIR}/include/podio/ROOTWriter.h
${PROJECT_SOURCE_DIR}/include/podio/ROOTFrameData.h
${PROJECT_SOURCE_DIR}/include/podio/utilities/RootHelpers.h
${PROJECT_SOURCE_DIR}/include/podio/ROOTDataSource.h
)
if(ENABLE_RNTUPLE)
list(APPEND root_headers
Expand All @@ -108,12 +105,7 @@ if(ENABLE_RNTUPLE)
endif()

PODIO_ADD_LIB_AND_DICT(podioRootIO "${root_headers}" "${root_sources}" root_selection.xml)
target_link_libraries(podioRootIO PUBLIC podio::podio
ROOT::Core
ROOT::RIO
ROOT::Tree
ROOT::ROOTVecOps
ROOT::ROOTDataFrame)
target_link_libraries(podioRootIO PUBLIC podio::podio ROOT::Core ROOT::RIO ROOT::Tree ROOT::ROOTVecOps)
if(ENABLE_RNTUPLE)
target_link_libraries(podioRootIO PUBLIC ROOT::ROOTNTuple)
target_compile_definitions(podioRootIO PUBLIC PODIO_ENABLE_RNTUPLE=1)
Expand Down Expand Up @@ -147,6 +139,7 @@ if(ENABLE_SIO)
LIST(APPEND INSTALL_LIBRARIES podioSioIO podioSioIODict)
endif()


# --- IO
set(io_sources
Writer.cc
Expand All @@ -168,18 +161,57 @@ if(ENABLE_SIO)
target_link_libraries(podioIO PUBLIC podio::podioSioIO)
endif()


# --- DataSource
if(ENABLE_DATASOURCE)
set(rds_sources
DataSource.cc
)

set(rds_headers
${PROJECT_SOURCE_DIR}/include/podio/DataSource.h
)

podio_add_lib_and_dict(podioDataSource "${rds_headers}" "${rds_sources}" rds_selection.xml)
target_link_libraries(podioDataSource PUBLIC podio::podio
podio::podioIO
podio::podioRootIO
ROOT::Core
ROOT::RIO
ROOT::Tree
ROOT::ROOTVecOps
ROOT::ROOTDataFrame
)
target_compile_definitions(podioDataSource PUBLIC PODIO_ENABLE_DATASOURCE=1)
endif()


# --- Install everything
install(TARGETS podio podioDict podioRootIO podioRootIODict podioIO ${INSTALL_LIBRARIES}
EXPORT podioTargets
DESTINATION "${CMAKE_INSTALL_LIBDIR}")
if (NOT ENABLE_DATASOURCE)
install(TARGETS podio podioDict podioRootIO podioRootIODict podioIO ${INSTALL_LIBRARIES}
EXPORT podioTargets
DESTINATION "${CMAKE_INSTALL_LIBDIR}")
else()
install(TARGETS podio podioDict podioRootIO podioRootIODict podioIO podioDataSource ${INSTALL_LIBRARIES}
EXPORT podioTargets
DESTINATION "${CMAKE_INSTALL_LIBDIR}")
endif()

# Only install the necessary headers
if (ENABLE_SIO)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/podio DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
else()
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/podio DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
REGEX SIO.*\\.h$ EXCLUDE )
file(GLOB headers_necessary
RELATIVE ${PROJECT_SOURCE_DIR}
"${PROJECT_SOURCE_DIR}/install/podio/*.h")

if (NOT ENABLE_SIO)
list(FILTER headers_necessary EXCLUDE REGEX SIO.*\\.h$)
endif()
if (NOT ENABLE_RNTUPLE)
list(FILTER headers_necessary EXCLUDE REGEX RNTuple.*\\.h$)
endif()
if (NOT ENABLE_RNTUPLE)
list(FILTER headers_necessary EXCLUDE REGEX DataSource.h)
endif()
install(FILES ${headers_necessary} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/podio")

install(FILES
${CMAKE_CURRENT_BINARY_DIR}/podioDictDict.rootmap
Expand All @@ -196,6 +228,14 @@ if (ENABLE_SIO)
)
endif()

if (ENABLE_DATASOURCE)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/podioDataSourceDictDict.rootmap
${CMAKE_CURRENT_BINARY_DIR}/libpodioDataSourceDict_rdict.pcm
DESTINATION "${CMAKE_INSTALL_LIBDIR}"
)
endif()

add_executable(podio_test_hashes test_hashes.cpp)
target_link_libraries(podio_test_hashes PRIVATE podio::podio)
install(TARGETS podio_test_hashes
Expand Down
Loading

0 comments on commit 3dc015b

Please sign in to comment.