I currently have some troubles when trying to define a new column in an RDataFrame:
I have created a simple test file that contains a single branch as a std::vector<int>
TFile* f = new TFile("test_file.root", "recreate");
TTree* t = new TTree("tree", "tree with some values");
auto* vec = new std::vector<int>();
vec->reserve(5);
t->Branch("vec", &vec);
for (int i = 0; i < 10; ++i) {
vec->clear();
for (int j = 0; j < 5; ++j) {
vec->push_back((int) gRandom->Uniform(0, 10));
}
t->Fill();
}
t->Write();
f->Write();
f->Close();
When I then try to Define a new column in an RDataFrame using
import ROOT
ROOT.gInterpreter.ProcessLine('''
std::vector<int> double_index(ROOT::VecOps::RVec<int> ind) {
std::vector<int> indices;
indices.reserve(ind.size());
for (const auto i : ind) {
indices.push_back(i * 2);
}
return indices;
}''')
rdf = ROOT.RDataFrame('tree', 'test_file.root')
rdf.Define('double_idx', ROOT.double_index, ['vec'])
I get the following error
Traceback (most recent call last):
File "rdf_new.py", line 14, in <module>
rdf.Define('double_idx', ROOT.double_index, ['vec'])
TypeError: can not resolve method template call for 'Define'
The problem in this case does not seem to be the ['vec']
that is not correctly identified as a std::vector<std::string>
but rather the double_index
function. I have tried the workaround for specifying the last argument as an actual vector of strings, outlined in Problem callding RDataFrame::Define with ColumnNames_t with python and that leads to the same error.
I am not sure whether I am running into a bug here, or whether I have to call Define
in a slightly different way. Any help is very much appreciated.
Please read tips for efficient and successful posting and posting code
_ROOT Version: 6.20.04
_Platform: CentOS7
_Compiler: gcc8.3.0