Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RExports.cxx
Go to the documentation of this file.
1// Author: Omar Zapata Omar.Zapata@cern.ch 2014
2
3/*************************************************************************
4 * Copyright (C) 1995-2021, 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#include<RExports.h>
11#include<TRFunctionExport.h>
12#include<TRObject.h>
13#include<TRDataFrame.h>
14#include<Rcpp/Vector.h>
15
16namespace ROOT {
17 namespace R {
18 const Rcpp::internal::NamedPlaceHolder &Label(Rcpp::_);
19 }
20}
21
22namespace Rcpp {
23//TVectorT
24 template<> SEXP wrap(const TVectorT<Double_t> &v)
25 {
26 std::vector<Double_t> vec(v.GetMatrixArray(), v.GetMatrixArray() + v.GetNoElements());
27 return wrap(vec);
28 }
29
30 template<> TVectorT<Double_t> as(SEXP v)
31 {
32 std::vector<Double_t> vec =::Rcpp::as<std::vector<Double_t> >(v);
33 return TVectorT<Double_t>(vec.size(), vec.data());
34 }
35
36 template<> SEXP wrap(const TVectorT<Float_t> &v)
37 {
38 std::vector<Float_t> vec(v.GetMatrixArray(), v.GetMatrixArray() + v.GetNoElements());
39 return wrap(vec);
40 }
41
42 template<> TVectorT<Float_t> as(SEXP v)
43 {
44 std::vector<Float_t> vec =::Rcpp::as<std::vector<Float_t> >(v);
45 return TVectorT<Float_t>(vec.size(), vec.data());
46 }
47
48//TMatrixT
49 template<> SEXP wrap(const TMatrixT<Double_t> &m)
50 {
51 Int_t rows = m.GetNrows();
52 Int_t cols = m.GetNcols();
53 Double_t *data = new Double_t[rows * cols];
54 m.GetMatrix2Array(data, "F"); //ROOT has a bug here(Fixed)
55 NumericMatrix mat(rows, cols, data);
56 return wrap(mat);
57 }
58
59 template<> TMatrixT<Double_t> as(SEXP m)
60 {
61 NumericMatrix mat =::Rcpp::as<NumericMatrix>(m);
62 return TMatrixT<Double_t>(mat.rows(), mat.cols(), mat.begin(), "F");
63 }
64
65 template<> SEXP wrap(const TMatrixT<Float_t> &m)
66 {
67 Int_t rows = m.GetNrows();
68 Int_t cols = m.GetNcols();
69 Float_t *data = new Float_t[rows * cols];
70 m.GetMatrix2Array(data, "F"); //ROOT has a bug here(Fixed)
71 NumericMatrix mat(rows, cols, data);
72 return wrap(mat);
73 }
74
75 template<> TMatrixT<Float_t> as(SEXP m)
76 {
77 NumericMatrix mat =::Rcpp::as<NumericMatrix>(m);
78 std::vector<Float_t> dat = Rcpp::as<std::vector<Float_t>>(mat);
79 return TMatrixT<Float_t>(mat.rows(), mat.cols(), &dat[0], "F");
80 }
81
82//TRObject
83 template<> SEXP wrap(const ROOT::R::TRObject &obj)
84 {
85 return obj.fObj;
86 }
87
88 template<> ROOT::R::TRObject as(SEXP obj)
89 {
90 return ROOT::R::TRObject(obj);
91 }
92//TRDataFrame
93 template<> SEXP wrap(const ROOT::R::TRDataFrame &obj)
94 {
95 return obj.df;
96 }
97
98 template<> ROOT::R::TRDataFrame as(SEXP obj)
99 {
100 return ROOT::R::TRDataFrame(Rcpp::as<Rcpp::DataFrame>(obj));
101 }
102
103//TRFunctionImport
104 template<> SEXP wrap(const ROOT::R::TRFunctionImport &obj)
105 {
106 return *obj.f;
107 }
108
109 template<> ROOT::R::TRFunctionImport as(SEXP obj)
110 {
111 return ROOT::R::TRFunctionImport(Rcpp::as<Rcpp::Function>(obj));
112 }
113
114}
115namespace ROOT {
116 namespace R {
117 VARIABLE_IS_NOT_USED SEXP ModuleSymRef = NULL;
118 }
119}
double Double_t
Definition RtypesCore.h:59
float Float_t
Definition RtypesCore.h:57
This is a class to create DataFrames from ROOT to R.
Rcpp::DataFrame df
This is a class to pass functions from ROOT to R.
This is a class to get ROOT's objects from R's objects.
Definition TRObject.h:70
Rcpp::RObject fObj
Definition TRObject.h:73
TMatrixT.
Definition TMatrixT.h:39
TVectorT.
Definition TVectorT.h:27
const Rcpp::internal::NamedPlaceHolder & Label
VARIABLE_IS_NOT_USED SEXP ModuleSymRef
Definition RExports.cxx:117
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
This is a class to support deprecated method to pass function to R's Environment, based in Rcpp::Inte...
Definition RExports.h:61
SEXP wrap(const TString &s)
Definition RExports.h:64
TString as(SEXP s)
Definition RExports.h:68
auto * m
Definition textangle.C:8