Logo ROOT   6.16/01
Reference Guide
TTreeAsFlatMatrix.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_TTreeAsFlatMatrix
12#define ROOT_TTreeAsFlatMatrix
13
14#include "ROOT/RDataFrame.hxx"
15
16#include <vector>
17#include <string>
18#include <utility>
19
20namespace ROOT {
21namespace Detail {
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} // namespace RDF
64} // namespace Detail
65} // namespace ROOT
66
67#endif
unsigned long long ULong64_t
Definition: RtypesCore.h:70
typedef void((*Func_t)())
void Foreach(F f, const ColumnNames_t &columns={})
Execute a user-defined function on each entry (instant action)
Definition: RInterface.hxx:730
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTrees,...
Definition: RDataFrame.hxx:41
A TTree object has a header with a name and a title.
Definition: TTree.h:71
ULong64_t GetAddress(std::vector< std::string > &p)
void TTreeAsFlatMatrixHelper(TTree &tree, std::vector< BufType > &matrix, std::vector< std::string > &columns)
void TTreeAsFlatMatrix(std::index_sequence< Idx... >, TTree &tree, std::vector< BufType > &matrix, std::vector< std::string > &columns)
ULong64_t GetVectorAddress(std::vector< dtype > &p)
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
make_index_sequence< sizeof...(_Tp)> index_sequence_for
Definition: tree.py:1