Dear ROOT experts,
I am truly enjoying the use of RDataFrame
and has been using it in my python scripts to make histograms and produce skimmed ntuples. In my workflow, I use dictionaries to map RNode
(?) to strings. Here is a much simplified example of my script:
import ROOT
ROOT.gROOT.SetBatch()
df = ROOT.RDataFrame("mumu","ntuples.root")
df_filters = {}
df_filters["passCut1"] = df.Filter("passCut1")
df_filters["passSR"] = df_filters["passCut1"].Filter("passSR")
df_filters["passCR"] = df_filters["passCut1"].Filter("passCR")
print "passSR = " + str(df_filters["passSR"].Count().GetValue())
print "passCR = " + str(df_filters["passCR"].Count().GetValue())
What I’m trying to do right now is to make an equivalent C++ script by using std::map
like the following:
#include "ROOT/RDataFrame.hxx"
#include "ROOT/RDF/RInterface.hxx"
using namespace ROOT;
using RNode = ROOT::RDF::RNode;
using namespace std;
void RDFMaps(){
gROOT->SetBatch();
ROOT::RDataFrame df("mumu","ntuples.root");
map<string, RNode> df_filters;
df_filters["passCut1"] = df.Filter("passCut1");
df_filters["passSR"] = df_filters["passCut1"].Filter("passSR");
df_filters["passCR"] = df_filters["passCut1"].Filter("passCR");
cout << "passSR = " << *df_filters["passSR"].Count() << endl;
cout << "passCR = " << *df_filters["passCR"].Count() << endl;
}
int main(){
RDFMaps();
}
When I try to compile the script and make an executable, I get the compilation errors below:
g++ -c -o RDFMaps.o RDFMaps.C -O3 -pthread -std=c++11 -m64 -I/cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include
In file included from /usr/include/c++/4.8.2/functional:55:0,
from /usr/include/c++/4.8.2/bits/stl_algo.h:66,
from /usr/include/c++/4.8.2/algorithm:62,
from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/TMathBase.h:33,
from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/TString.h:26,
from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/TNamed.h:26,
from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/TDictionary.h:44,
from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/TDataType.h:25,
from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/TBuffer.h:24,
from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/TDirectory.h:24,
from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/TROOT.h:28,
from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/ROOT/RDataFrame.hxx:19,
from RDFMaps.C:1:
/usr/include/c++/4.8.2/tuple: In instantiation of 'std::pair<_T1, _T2>::pair(std::tuple<_Args1 ...>&, std::tuple<_Args2 ...>&, std::_Index_tuple<_Indexes1 ...>, std::_Index_tuple<_Indexes2 ...>) [with _Args1 = {std::basic_string<char, std::char_traits<char>, std::allocator<char> >&&}; long unsigned int ..._Indexes1 = {0ul}; _Args2 = {}; long unsigned int ..._Indexes2 = {}; _T1 = const std::basic_string<char>; _T2 = ROOT::RDF::RInterface<ROOT::Detail::RDF::RNodeBase, void>]':
/usr/include/c++/4.8.2/tuple:1079:63: required from 'std::pair<_T1, _T2>::pair(std::piecewise_construct_t, std::tuple<_Args1 ...>, std::tuple<_Args2 ...>) [with _Args1 = {std::basic_string<char, std::char_traits<char>, std::allocator<char> >&&}; _Args2 = {}; _T1 = const std::basic_string<char>; _T2 = ROOT::RDF::RInterface<ROOT::Detail::RDF::RNodeBase, void>]'
/usr/include/c++/4.8.2/bits/stl_tree.h:140:49: required from 'std::_Rb_tree_node<_Val>::_Rb_tree_node(_Args&& ...) [with _Args = {const std::piecewise_construct_t&, std::tuple<std::basic_string<char, std::char_traits<char>, std::allocator<char> >&&>, std::tuple<>}; _Val = std::pair<const std::basic_string<char>, ROOT::RDF::RInterface<ROOT::Detail::RDF::RNodeBase, void> >]'
/usr/include/c++/4.8.2/ext/new_allocator.h:120:4: required from 'void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = std::_Rb_tree_node<std::pair<const std::basic_string<char>, ROOT::RDF::RInterface<ROOT::Detail::RDF::RNodeBase, void> > >; _Args = {const std::piecewise_construct_t&, std::tuple<std::basic_string<char, std::char_traits<char>, std::allocator<char> >&&>, std::tuple<>}; _Tp = std::_Rb_tree_node<std::pair<const std::basic_string<char>, ROOT::RDF::RInterface<ROOT::Detail::RDF::RNodeBase, void> > >]'
/usr/include/c++/4.8.2/bits/alloc_traits.h:254:4: required from 'static typename std::enable_if<std::allocator_traits<_Alloc>::__construct_helper<_Tp, _Args>::value, void>::type std::allocator_traits<_Alloc>::_S_construct(_Alloc&, _Tp*, _Args&& ...) [with _Tp = std::_Rb_tree_node<std::pair<const std::basic_string<char>, ROOT::RDF::RInterface<ROOT::Detail::RDF::RNodeBase, void> > >; _Args = {const std::piecewise_construct_t&, std::tuple<std::basic_string<char, std::char_traits<char>, std::allocator<char> >&&>, std::tuple<>}; _Alloc = std::allocator<std::_Rb_tree_node<std::pair<const std::basic_string<char>, ROOT::RDF::RInterface<ROOT::Detail::RDF::RNodeBase, void> > > >; typename std::enable_if<std::allocator_traits<_Alloc>::__construct_helper<_Tp, _Args>::value, void>::type = void]'
/usr/include/c++/4.8.2/bits/alloc_traits.h:393:57: required from 'static decltype (_S_construct(__a, __p, (forward<_Args>)(std::allocator_traits::construct::__args)...)) std::allocator_traits<_Alloc>::construct(_Alloc&, _Tp*, _Args&& ...) [with _Tp = std::_Rb_tree_node<std::pair<const std::basic_string<char>, ROOT::RDF::RInterface<ROOT::Detail::RDF::RNodeBase, void> > >; _Args = {const std::piecewise_construct_t&, std::tuple<std::basic_string<char, std::char_traits<char>, std::allocator<char> >&&>, std::tuple<>}; _Alloc = std::allocator<std::_Rb_tree_node<std::pair<const std::basic_string<char>, ROOT::RDF::RInterface<ROOT::Detail::RDF::RNodeBase, void> > > >; decltype (_S_construct(__a, __p, (forward<_Args>)(std::allocator_traits::construct::__args)...)) = <type error>]'
/usr/include/c++/4.8.2/bits/stl_tree.h:408:36: required from 'std::_Rb_tree_node<_Val>* std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_create_node(_Args&& ...) [with _Args = {const std::piecewise_construct_t&, std::tuple<std::basic_string<char, std::char_traits<char>, std::allocator<char> >&&>, std::tuple<>}; _Key = std::basic_string<char>; _Val = std::pair<const std::basic_string<char>, ROOT::RDF::RInterface<ROOT::Detail::RDF::RNodeBase, void> >; _KeyOfValue = std::_Select1st<std::pair<const std::basic_string<char>, ROOT::RDF::RInterface<ROOT::Detail::RDF::RNodeBase, void> > >; _Compare = std::less<std::basic_string<char> >; _Alloc = std::allocator<std::pair<const std::basic_string<char>, ROOT::RDF::RInterface<ROOT::Detail::RDF::RNodeBase, void> > >; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Link_type = std::_Rb_tree_node<std::pair<const std::basic_string<char>, ROOT::RDF::RInterface<ROOT::Detail::RDF::RNodeBase, void> > >*]'
/usr/include/c++/4.8.2/bits/stl_tree.h:1669:64: required from 'std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_emplace_hint_unique(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator, _Args&& ...) [with _Args = {const std::piecewise_construct_t&, std::tuple<std::basic_string<char, std::char_traits<char>, std::allocator<char> >&&>, std::tuple<>}; _Key = std::basic_string<char>; _Val = std::pair<const std::basic_string<char>, ROOT::RDF::RInterface<ROOT::Detail::RDF::RNodeBase, void> >; _KeyOfValue = std::_Select1st<std::pair<const std::basic_string<char>, ROOT::RDF::RInterface<ROOT::Detail::RDF::RNodeBase, void> > >; _Compare = std::less<std::basic_string<char> >; _Alloc = std::allocator<std::pair<const std::basic_string<char>, ROOT::RDF::RInterface<ROOT::Detail::RDF::RNodeBase, void> > >; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator = std::_Rb_tree_iterator<std::pair<const std::basic_string<char>, ROOT::RDF::RInterface<ROOT::Detail::RDF::RNodeBase, void> > >; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::const_iterator = std::_Rb_tree_const_iterator<std::pair<const std::basic_string<char>, ROOT::RDF::RInterface<ROOT::Detail::RDF::RNodeBase, void> > >]'
/usr/include/c++/4.8.2/bits/stl_map.h:484:8: required from 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](std::map<_Key, _Tp, _Compare, _Alloc>::key_type&&) [with _Key = std::basic_string<char>; _Tp = ROOT::RDF::RInterface<ROOT::Detail::RDF::RNodeBase, void>; _Compare = std::less<std::basic_string<char> >; _Alloc = std::allocator<std::pair<const std::basic_string<char>, ROOT::RDF::RInterface<ROOT::Detail::RDF::RNodeBase, void> > >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = ROOT::RDF::RInterface<ROOT::Detail::RDF::RNodeBase, void>; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = std::basic_string<char>]'
RDFMaps.C:20:24: required from here
/usr/include/c++/4.8.2/tuple:1090:70: error: no matching function for call to 'ROOT::RDF::RInterface<ROOT::Detail::RDF::RNodeBase, void>::RInterface()'
second(std::forward<_Args2>(std::get<_Indexes2>(__tuple2))...)
^
/usr/include/c++/4.8.2/tuple:1090:70: note: candidates are:
In file included from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/ROOT/RDataFrame.hxx:20:0,
from RDFMaps.C:1:
/cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/ROOT/RDF/RInterface.hxx:2481:4: note: ROOT::RDF::RInterface<T, V>::RInterface(const std::shared_ptr<_Tp1>&, ROOT::RDF::RInterface<T, V>::RLoopManager&, const ROOT::Internal::RDF::RBookedCustomColumns&, ROOT::RDF::RDataSource*) [with Proxied = ROOT::Detail::RDF::RNodeBase; DataSource = void; ROOT::RDF::RInterface<T, V>::RLoopManager = ROOT::Detail::RDF::RLoopManager]
RInterface(const std::shared_ptr<Proxied> &proxied, RLoopManager &lm,
^
/cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/ROOT/RDF/RInterface.hxx:2481:4: note: candidate expects 4 arguments, 0 provided
In file included from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/ROOT/RDataFrame.hxx:20:0,
from RDFMaps.C:1:
/cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/ROOT/RDF/RInterface.hxx:126:4: note: template<class T, typename std::enable_if<std::is_same<T, ROOT::Detail::RDF::RLoopManager>::value, int>::type <anonymous> > ROOT::RDF::RInterface<T, V>::RInterface(const std::shared_ptr<_Tp1>&)
RInterface(const std::shared_ptr<Proxied> &proxied)
^
/cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/ROOT/RDF/RInterface.hxx:126:4: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/4.8.2/functional:55:0,
from /usr/include/c++/4.8.2/bits/stl_algo.h:66,
from /usr/include/c++/4.8.2/algorithm:62,
from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/TMathBase.h:33,
from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/TString.h:26,
from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/TNamed.h:26,
from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/TDictionary.h:44,
from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/TDataType.h:25,
from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/TBuffer.h:24,
from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/TDirectory.h:24,
from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/TROOT.h:28,
from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/ROOT/RDataFrame.hxx:19,
from RDFMaps.C:1:
/usr/include/c++/4.8.2/tuple:1090:70: note: candidate expects 1 argument, 0 provided
second(std::forward<_Args2>(std::get<_Indexes2>(__tuple2))...)
^
In file included from /cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/ROOT/RDataFrame.hxx:20:0,
from RDFMaps.C:1:
/cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/ROOT/RDF/RInterface.hxx:121:4: note: ROOT::RDF::RInterface<T, V>::RInterface(ROOT::RDF::RInterface<T, V>&&) [with Proxied = ROOT::Detail::RDF::RNodeBase; DataSource = void]
RInterface(RInterface &&) = default;
^
/cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/ROOT/RDF/RInterface.hxx:121:4: note: candidate expects 1 argument, 0 provided
/cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/ROOT/RDF/RInterface.hxx:117:4: note: ROOT::RDF::RInterface<T, V>::RInterface(const ROOT::RDF::RInterface<T, V>&) [with Proxied = ROOT::Detail::RDF::RNodeBase; DataSource = void]
RInterface(const RInterface &) = default;
^
/cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/include/ROOT/RDF/RInterface.hxx:117:4: note: candidate expects 1 argument, 0 provided
make: *** [RDFMaps.o] Error 1
Does this mean I can’t map RNode
to strings in C++ using std::map
or am I just not declaring the right type properly? Apologies for this question because I’m not familiar with the underlying machinery of RDataFrame
.
Kind regards,
Fikri
=========================================================================
I am using ROOT version 6.18.00 on lxplus by sourcing the following file:
/cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.18.00/x86_64-centos7-gcc48-opt/bin/thisroot.sh