11 #ifndef ROOT_PyROOTHelpers
12 #define ROOT_PyROOTHelpers
24 template <
typename dtype>
25 ULong64_t GetVectorAddress(std::vector<dtype> &p)
27 return reinterpret_cast<ULong64_t
>(&p);
30 inline ULong64_t GetAddress(std::vector<std::string> &p)
32 return reinterpret_cast<ULong64_t
>(&p);
34 inline ULong64_t GetAddress(TTree &p)
36 return reinterpret_cast<ULong64_t
>(&p);
39 template <
typename BufType,
typename... ColTypes, std::size_t... Idx>
40 void TTreeAsFlatMatrix(std::index_sequence<Idx...>, TTree &tree, std::vector<BufType> &matrix,
41 std::vector<std::string> &columns)
43 auto buffer = matrix.data();
45 auto fillMatrix = [buffer](ColTypes... cols, ULong64_t entry) {
46 int expander[] = {(buffer[entry *
sizeof...(Idx) + Idx] = cols, 0)...};
50 auto columnsWithEntry = columns;
51 columnsWithEntry.emplace_back(
"tdfentry_");
53 ROOT::RDataFrame dataframe(tree, columns);
54 dataframe.Foreach(fillMatrix, columnsWithEntry);
57 template <
typename BufType,
typename... ColTypes>
58 void TTreeAsFlatMatrixHelper(TTree &tree, std::vector<BufType> &matrix, std::vector<std::string> &columns)
60 TTreeAsFlatMatrix<BufType, ColTypes...>(std::index_sequence_for<ColTypes...>(), tree, matrix, columns);
67 ROOT::RDF::RResultPtr<std::vector<T>> RDataFrameTake(ROOT::RDF::RNode df, std::string_view column)
69 return df.Take<T>(column);