vepadulano / PyRDF

Python Library for doing ROOT RDataFrame analysis
https://pyrdf.readthedocs.io/en/latest/
9 stars 7 forks source link

Snapshot error passing branch lists #90

Closed omazapa closed 4 years ago

omazapa commented 4 years ago

Hi Javier,

I am trying to save a snapshot with multiple branches but it is not working,

import PyRDF
df = PyRDF.RDataFrame("data", ['https://root.cern/files/teaching/CMS_Open_Dataset.root',])

etaCutStr = "fabs(eta1) < 2.3 && fabs(eta2) < 2.3"
df_f = df.Filter(etaCutStr)

branchList = ("eta1","eta2") # the same error with ["eta1","eta2"] 
df_f.Snapshot('filtered', 'out3.root', branchList)

I am using the last version.

error

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-10-c4cbf40f254f> in <module>
      6 
      7 branchList = ("eta1","eta2")
----> 8 df_f.Snapshot('filtered', 'out3.root', branchList)

/eos/home-o/ozapatam/SWAN_projects/rho3/deps/PyRDF/Proxy.py in _create_new_op(self, *args, **kwargs)
    181             from PyRDF import current_backend
    182             generator = CallableGenerator(self.proxied_node.get_head())
--> 183             current_backend.execute(generator)
    184             return newNode.value
    185         else:

/eos/home-o/ozapatam/SWAN_projects/rho3/deps/PyRDF/backend/Local.py in execute(self, generator)
     61             self.pyroot_rdf = ROOT.ROOT.RDataFrame(*generator.head_node.args)
     62 
---> 63         values = mapper(self.pyroot_rdf)  # Execute the mapper function
     64 
     65         # Get the action nodes in the same order as values

/eos/home-o/ozapatam/SWAN_projects/rho3/deps/PyRDF/CallableGenerator.py in mapper(node_cpp, node_py, rdf_range)
    131             for n in node_py.children:
    132                 # Recurse through children and get their output
--> 133                 prev_vals = mapper(parent_node, node_py=n, rdf_range=rdf_range)
    134 
    135                 # Attach the output of the children node

/eos/home-o/ozapatam/SWAN_projects/rho3/deps/PyRDF/CallableGenerator.py in mapper(node_cpp, node_py, rdf_range)
    131             for n in node_py.children:
    132                 # Recurse through children and get their output
--> 133                 prev_vals = mapper(parent_node, node_py=n, rdf_range=rdf_range)
    134 
    135                 # Attach the output of the children node

/eos/home-o/ozapatam/SWAN_projects/rho3/deps/PyRDF/CallableGenerator.py in mapper(node_cpp, node_py, rdf_range)
    107                 else:
    108                     pyroot_node = RDFOperation(*operation.args,
--> 109                                                **operation.kwargs)
    110 
    111                 # The result is a pyroot object which is stored together with

TypeError: none of the 3 overloaded methods succeeded. Full details:
  ROOT::RDF::RResultPtr<ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager,void> > ROOT::RDF::RInterface<ROOT::Detail::RDF::RJittedFilter,void>::Snapshot(basic_string_view<char,char_traits<char> > treename, basic_string_view<char,char_traits<char> > filename, const vector<string>& columnList, const ROOT::RDF::RSnapshotOptions& options = ROOT::RDF::RSnapshotOptions()) =>
    could not convert argument 3 (none of the 10 overloaded methods succeeded. Full details:
  vector<string>::vector<string>() =>
    takes at most 0 arguments (2 given)
  vector<string>::vector<string>(const allocator<string>& __a) =>
    takes at most 1 arguments (2 given)
  vector<string>::vector<string>(unsigned long __n, const allocator<string>& __a = std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::allocator_type()) =>
    could not convert argument 1 (an integer is required)
  vector<string>::vector<string>(unsigned long __n, const string& __value, const allocator<string>& __a = std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::allocator_type()) =>
    could not convert argument 1 (an integer is required)
  vector<string>::vector<string>(const vector<string>& __x) =>
    takes at most 1 arguments (2 given)
  vector<string>::vector<string>(vector<string>&& __x) =>
    takes at most 1 arguments (2 given)
  vector<string>::vector<string>(const vector<string>& __x, const allocator<string>& __a) =>
    could not convert argument 1
  vector<string>::vector<string>(vector<string>&& __rv, const allocator<string>& __m) =>
    could not convert argument 1 (this method can not (yet) be called)
  vector<string>::vector<string>(initializer_list<string> __l, const allocator<string>& __a = std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::allocator_type()) =>
    could not convert argument 1
  vector<string>::vector<string>(__gnu_cxx::__normal_iterator<const basic_string_view<char,char_traits<char> >*,vector<basic_string_view<char,char_traits<char> > > > __first, __gnu_cxx::__normal_iterator<const basic_string_view<char,char_traits<char> >*,vector<basic_string_view<char,char_traits<char> > > > __last, const allocator<string>& __a = std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::allocator_type()) =>
    could not convert argument 1)
  ROOT::RDF::RResultPtr<ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager,void> > ROOT::RDF::RInterface<ROOT::Detail::RDF::RJittedFilter,void>::Snapshot(basic_string_view<char,char_traits<char> > treename, basic_string_view<char,char_traits<char> > filename, basic_string_view<char,char_traits<char> > columnNameRegexp = "", const ROOT::RDF::RSnapshotOptions& options = ROOT::RDF::RSnapshotOptions()) =>
    could not convert argument 3
  ROOT::RDF::RResultPtr<ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager,void> > ROOT::RDF::RInterface<ROOT::Detail::RDF::RJittedFilter,void>::Snapshot(basic_string_view<char,char_traits<char> > treename, basic_string_view<char,char_traits<char> > filename, initializer_list<string> columnList, const ROOT::RDF::RSnapshotOptions& options = ROOT::RDF::RSnapshotOptions()) =>
    could not convert argument 3 (none of the 3 overloaded methods succeeded. Full details:
  initializer_list<string>::initializer_list<string>() =>
    takes at most 0 arguments (2 given)
  initializer_list<string>::initializer_list<string>(const initializer_list<string>&) =>
    takes at most 1 arguments (2 given)
  initializer_list<string>::initializer_list<string>(initializer_list<string>&&) =>
    takes at most 1 arguments (2 given))
etejedor commented 4 years ago

Can you check what happens if the branch list is an std::vector constructed from Python?

branchList = ROOT.std.vector('std::string')()
branchList.push_back('eta1')
branchList.push_back('eta2')
omazapa commented 4 years ago

it works, thanks, Enric!