Dear ROOT-ers,
Exploring the capabilities of RDataFrame I have run into the following question: can I refer to tree branches containing two-dimensional statically-allocated C++ arrays (e.g. Float_t x[2][2]
) when defining the new variables, filtering etc.?
The following script illustrates the problem I have encountered.
#include <ROOT/RDataFrame.hxx>
#include <TFile.h>
#include <TTree.h>
void test(){
// generate a tree with 2d array branch
Float_t array2d[2][2];
TFile * f_out = new TFile("test.root", "RECREATE");
TTree * T = new TTree("h1", "");
T->Branch("array2d", array2d, "array2d[2][2]/F");
for(int i=0;i<10;++i){
T->Fill();
}
T->Write();
f_out->Close();
// try to process with RDataFrame
ROOT::RDataFrame d("h1", "test.root");
d.Filter("array2d[0][0] > 0.");
}
If I try to process a tree with a branch containing a 2d array like in this example, accessing the array’s elements is not recognized when parsing the definitions and filters:
input_line_46:2:18: error: subscripted value is not an array, pointer, or vector
return array2d[0][0] > 0.
~~~~~~~~~~^~
terminate called after throwing an instance of 'std::runtime_error'
what(): Cannot interpret the following expression:
array2d[0][0] > 0.
Make sure it is valid C++.
Trying to understand the problem, I have discovered that TTreeReader also does not handle such branches, so that when trying to generate a TSelector from the tree created by the above script, I got the following warning (unless generating the legacy selector version):
Warning in <AddReader>: Ingored branch array2d because type is unknown.
Am I doing something wrong or is it a limitation of RDataFrame and TTreeReader?
From a quick check it seems that I can access the array as a 1d array, i.e. replacing array2d[i][j]
with array2d[i*Ncolumns+j]
. Of course this should work with statically-allocated multidimentional C++ arrays, but do you know if the continuous memory layout is preserved when reading from the TTree in a file so that such a workaround would be reliable?
Many thanks,
Alek
_ROOT Version: 6.14/04, 6.15/01 (git master)
_Platform: x86_64 Debian GNU/Linux
_Compiler: g++ (Debian 7.3.0-27) 7.3.0