Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
PyROOTHelpers.hxx
Go to the documentation of this file.
1// Author: Danilo Piparo, Enrico Guiraud, Stefan Wunsch CERN 04/2018
2
3/*************************************************************************
4 * Copyright (C) 1995-2018, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11#ifndef ROOT_PyROOTHelpers
12#define ROOT_PyROOTHelpers
13
14#include "ROOT/RDataFrame.hxx"
15
16#include <vector>
17#include <string>
18#include <utility>
19
20namespace ROOT {
21namespace Internal {
22namespace RDF {
23
24template <typename dtype>
25ULong64_t GetVectorAddress(std::vector<dtype> &p)
26{
27 return reinterpret_cast<ULong64_t>(&p);
28}
29
30inline ULong64_t GetAddress(std::vector<std::string> &p)
31{
32 return reinterpret_cast<ULong64_t>(&p);
33}
35{
36 return reinterpret_cast<ULong64_t>(&p);
37}
38
39template <typename BufType, typename... ColTypes, std::size_t... Idx>
40void TTreeAsFlatMatrix(std::index_sequence<Idx...>, TTree &tree, std::vector<BufType> &matrix,
41 std::vector<std::string> &columns)
42{
43 auto buffer = matrix.data();
44
45 auto fillMatrix = [buffer](ColTypes... cols, ULong64_t entry) {
46 int expander[] = {(buffer[entry * sizeof...(Idx) + Idx] = cols, 0)...};
47 (void)expander;
48 };
49
50 auto columnsWithEntry = columns;
51 columnsWithEntry.emplace_back("tdfentry_");
52
53 ROOT::RDataFrame dataframe(tree, columns);
54 dataframe.Foreach(fillMatrix, columnsWithEntry);
55}
56
57template <typename BufType, typename... ColTypes>
58void TTreeAsFlatMatrixHelper(TTree &tree, std::vector<BufType> &matrix, std::vector<std::string> &columns)
59{
60 TTreeAsFlatMatrix<BufType, ColTypes...>(std::index_sequence_for<ColTypes...>(), tree, matrix, columns);
61}
62
63// RDataFrame.AsNumpy helpers
64
65// NOTE: This is a workaround for the missing Take action in the PyROOT interface
66template <typename T>
68{
69 return df.Take<T>(column);
70}
71
72} // namespace RDF
73} // namespace Internal
74} // namespace ROOT
75
76#endif
unsigned long long ULong64_t
Definition RtypesCore.h:81
winID h TVirtualViewer3D TVirtualGLPainter p
The public interface to the RDataFrame federation of classes.
RResultPtr< COLL > Take(std::string_view column="")
Return a collection of values of a column (lazy action, returns a std::vector by default).
void Foreach(F f, const ColumnNames_t &columns={})
Execute a user-defined function on each entry (instant action).
Smart pointer for the return type of actions.
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
A TTree represents a columnar dataset.
Definition TTree.h:79
void TTreeAsFlatMatrixHelper(TTree &tree, std::vector< BufType > &matrix, std::vector< std::string > &columns)
ROOT::RDF::RResultPtr< std::vector< T > > RDataFrameTake(ROOT::RDF::RNode df, std::string_view column)
void TTreeAsFlatMatrix(std::index_sequence< Idx... >, TTree &tree, std::vector< BufType > &matrix, std::vector< std::string > &columns)
ULong64_t GetVectorAddress(std::vector< dtype > &p)
ULong64_t GetAddress(std::vector< std::string > &p)
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
Definition tree.py:1