Skip to content

Commit

Permalink
Add utility function to load parameters in RDataFrame
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Jun 12, 2024
1 parent b38c1d6 commit b4e581f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
8 changes: 4 additions & 4 deletions include/podio/GenericParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ class GenericParameters {
}

/// Load multiple key value pairs simultaneously
template <typename T>
void loadFrom(std::vector<std::string> keys, std::vector<std::vector<T>> values);
template <typename T, template <typename...> typename VecLike>
void loadFrom(VecLike<std::string> keys, VecLike<std::vector<T>> values);

/// Get the number of elements stored under the given key for a type
template <typename T, typename = EnableIfValidGenericDataType<T>>
Expand Down Expand Up @@ -277,8 +277,8 @@ std::vector<std::vector<T>> GenericParameters::getValues() const {
return values;
}

template <typename T>
void GenericParameters::loadFrom(std::vector<std::string> keys, std::vector<std::vector<T>> values) {
template <typename T, template <typename...> typename VecLike>
void GenericParameters::loadFrom(VecLike<std::string> keys, VecLike<std::vector<T>> values) {
auto& map = getMap<T>();
auto& mtx = getMutex<T>();

Expand Down
9 changes: 9 additions & 0 deletions include/podio/utilities/RootHelpers.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#ifndef PODIO_UTILITIES_ROOTHELPERS_H
#define PODIO_UTILITIES_ROOTHELPERS_H

#include "podio/GenericParameters.h"

#include "ROOT/RVec.hxx"
#include "TBranch.h"

#include <string>
Expand Down Expand Up @@ -77,6 +80,12 @@ namespace root_utils {
std::vector<std::vector<T>>* m_valuesPtr{nullptr};
};

GenericParameters
loadParamsFrom(ROOT::VecOps::RVec<std::string> intKeys, ROOT::VecOps::RVec<std::vector<int>> intValues,
ROOT::VecOps::RVec<std::string> floatKeys, ROOT::VecOps::RVec<std::vector<float>> floatValues,
ROOT::VecOps::RVec<std::string> doubleKeys, ROOT::VecOps::RVec<std::vector<double>> doubleValues,
ROOT::VecOps::RVec<std::string> stringKeys, ROOT::VecOps::RVec<std::vector<std::string>> stringValues);

} // namespace root_utils
} // namespace podio

Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ SET(root_sources
ROOTReader.cc
ROOTLegacyReader.cc
ROOTFrameData.cc
RootHelpers.cc
)
if(ENABLE_RNTUPLE)
list(APPEND root_sources
Expand Down
4 changes: 4 additions & 0 deletions tests/root_io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,7 @@ if (ENABLE_RNTUPLE)

set_property(TEST read_python_frame_rntuple PROPERTY DEPENDS write_python_frame_rntuple)
endif()

add_test(NAME param_reading_rdataframe COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/param_reading_rdataframe.py example_frame.root)
PODIO_SET_TEST_ENV(param_reading_rdataframe)
set_property(TEST param_reading_rdataframe PROPERTY DEPENDS write_frame_root)

0 comments on commit b4e581f

Please sign in to comment.