RDF error: Inconsistent deduction for auto return type when using .Filter

Dear experts,

I ran into a problem when adding a new module to my RDF analyzer. I included the error at the end since it’s pretty lengthy. The issue seems to be coming from using .Filter in the module HEM.h that is called in postprocess_W.cxx and is ran with runpostprocess_W.sh. I’ve used the Filter function in the past in other modules but never ran into this error. Thank you for the help!

Hichem
Platform: lxplus el9

Error:

In file included from postprocess_W.cxx:39:
helpers/HEM.h: In instantiation of 'auto ApplyHEM(T&, std::string) [with T = ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager>; std::string = std::__cxx11::basic_string<char>]':
postprocess_W.cxx:242:24:   required from here
helpers/HEM.h:40:110: error: inconsistent deduction for auto return type: 'ROOT::RDF::RInterface<ROOT::Detail::RDF::RJittedFilter, void>' and then ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager>'
   40 |      return df.Define("weight_HEM_nominal", HEM_region_WH, {"eta_fatjet", "phi_fatjet", "eta_lep", "phi_lep"});
      |                                                                                                              ^
helpers/HEM.h:40:110: error: no matching function for call to 'ROOT::RDF::RInterface<ROOT::Detail::RDF::RJittedFilter, void>::RInterface(ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager>)'
In file included from /cvmfs/cms.cern.ch/el9_amd64_gcc11/cms/cmssw/CMSSW_13_1_0_pre4/external/el9_amd64_gcc11/bin/../../../../../../../el9_amd64_gcc11/lcg/root/6.26.11-c74497fa7b0ab8f85c01e868f4d2fa9e/include/ROOT/RDataFrame.hxx:21,
                 from postprocess_W.cxx:12:
/cvmfs/cms.cern.ch/el9_amd64_gcc11/cms/cmssw/CMSSW_13_1_0_pre4/external/el9_amd64_gcc11/bin/../../../../../../../el9_amd64_gcc11/lcg/root/6.26.11-c74497fa7b0ab8f85c01e868f4d2fa9e/include/ROOT/RDF/RInterface.hxx:226:4: note: candidate: 'template<class T, class> ROOT::RDF::RInterface<T, V>::RInterface(const std::shared_ptr<ROOT::Detail::RDF::RLoopManager>&) [with T = T; <template-parameter-2-2> = <template-parameter-1-2>; Proxied = ROOT::Detail::RDF::RJittedFilter; DataSource = void]'
  226 |    RInterface(const std::shared_ptr<RLoopManager> &proxied)
      |    ^~~~~~~~~~
/cvmfs/cms.cern.ch/el9_amd64_gcc11/cms/cmssw/CMSSW_13_1_0_pre4/external/el9_amd64_gcc11/bin/../../../../../../../el9_amd64_gcc11/lcg/root/6.26.11-c74497fa7b0ab8f85c01e868f4d2fa9e/include/ROOT/RDF/RInterface.hxx:226:4: note:   template argument deduction/substitution failed:
In file included from /cvmfs/cms.cern.ch/el9_amd64_gcc11/cms/cmssw/CMSSW_13_1_0_pre4/external/el9_amd64_gcc11/bin/../../../../../../../el9_amd64_gcc11/lcg/root/6.26.11-c74497fa7b0ab8f85c01e868f4d2fa9e/include/Rtypes.h:31,
                 from /cvmfs/cms.cern.ch/el9_amd64_gcc11/cms/cmssw/CMSSW_13_1_0_pre4/external/el9_amd64_gcc11/bin/../../../../../../../el9_amd64_gcc11/lcg/root/6.26.11-c74497fa7b0ab8f85c01e868f4d2fa9e/include/TObject.h:17,
                 from /cvmfs/cms.cern.ch/el9_amd64_gcc11/cms/cmssw/CMSSW_13_1_0_pre4/external/el9_amd64_gcc11/bin/../../../../../../../el9_amd64_gcc11/lcg/root/6.26.11-c74497fa7b0ab8f85c01e868f4d2fa9e/include/TNamed.h:25,
                 from /cvmfs/cms.cern.ch/el9_amd64_gcc11/cms/cmssw/CMSSW_13_1_0_pre4/external/el9_amd64_gcc11/bin/../../../../../../../el9_amd64_gcc11/lcg/root/6.26.11-c74497fa7b0ab8f85c01e868f4d2fa9e/include/TDirectory.h:24,
                 from /cvmfs/cms.cern.ch/el9_amd64_gcc11/cms/cmssw/CMSSW_13_1_0_pre4/external/el9_amd64_gcc11/bin/../../../../../../../el9_amd64_gcc11/lcg/root/6.26.11-c74497fa7b0ab8f85c01e868f4d2fa9e/include/TROOT.h:28,
                 from /cvmfs/cms.cern.ch/el9_amd64_gcc11/cms/cmssw/CMSSW_13_1_0_pre4/external/el9_amd64_gcc11/bin/../../../../../../../el9_amd64_gcc11/lcg/root/6.26.11-c74497fa7b0ab8f85c01e868f4d2fa9e/include/ROOT/RDataFrame.hxx:19,
                 from postprocess_W.cxx:12:
/cvmfs/cms.cern.ch/el9_amd64_gcc11/external/gcc/11.2.1-f9b9dfdd886f71cd63f5538223d8f161/include/c++/11.2.1/type_traits: In substitution of 'template<bool _Cond, class _Tp> using enable_if_t = typename std::enable_if::type [with bool _Cond = false; _Tp = int]':
/cvmfs/cms.cern.ch/el9_amd64_gcc11/cms/cmssw/CMSSW_13_1_0_pre4/external/el9_amd64_gcc11/bin/../../../../../../../el9_amd64_gcc11/lcg/root/6.26.11-c74497fa7b0ab8f85c01e868f4d2fa9e/include/ROOT/RDF/RInterface.hxx:225:36:   required from 'auto ApplyHEM(T&, std::string) [with T = ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager>; std::string = std::__cxx11::basic_string<char>]'
postprocess_W.cxx:242:24:   required from here
/cvmfs/cms.cern.ch/el9_amd64_gcc11/external/gcc/11.2.1-f9b9dfdd886f71cd63f5538223d8f161/include/c++/11.2.1/type_traits:2585:11: error: no type named 'type' in 'struct std::enable_if<false, int>'
 2585 |     using enable_if_t = typename enable_if<_Cond, _Tp>::type;
      |           ^~~~~~~~~~~
In file included from /cvmfs/cms.cern.ch/el9_amd64_gcc11/cms/cmssw/CMSSW_13_1_0_pre4/external/el9_amd64_gcc11/bin/../../../../../../../el9_amd64_gcc11/lcg/root/6.26.11-c74497fa7b0ab8f85c01e868f4d2fa9e/include/ROOT/RDataFrame.hxx:21,
                 from postprocess_W.cxx:12:
helpers/HEM.h: In instantiation of 'auto ApplyHEM(T&, std::string) [with T = ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager>; std::string = std::__cxx11::basic_string<char>]':
postprocess_W.cxx:242:24:   required from here
/cvmfs/cms.cern.ch/el9_amd64_gcc11/cms/cmssw/CMSSW_13_1_0_pre4/external/el9_amd64_gcc11/bin/../../../../../../../el9_amd64_gcc11/lcg/root/6.26.11-c74497fa7b0ab8f85c01e868f4d2fa9e/include/ROOT/RDF/RInterface.hxx:3299:4: note: candidate: 'ROOT::RDF::RInterface<T, V>::RInterface(const std::shared_ptr<_Tp>&, ROOT::RDF::RInterface<T, V>::RLoopManager&, const ROOT::Internal::RDF::RColumnRegister&, ROOT::RDF::RDataSource*) [with Proxied = ROOT::Detail::RDF::RJittedFilter; DataSource = void; ROOT::RDF::RInterface<T, V>::RLoopManager = ROOT::Detail::RDF::RLoopManager]'
 3299 |    RInterface(const std::shared_ptr<Proxied> &proxied, RLoopManager &lm, const RDFInternal::RColumnRegister &columns,
      |    ^~~~~~~~~~
/cvmfs/cms.cern.ch/el9_amd64_gcc11/cms/cmssw/CMSSW_13_1_0_pre4/external/el9_amd64_gcc11/bin/../../../../../../../el9_amd64_gcc11/lcg/root/6.26.11-c74497fa7b0ab8f85c01e868f4d2fa9e/include/ROOT/RDF/RInterface.hxx:3299:4: note:   candidate expects 4 arguments, 1 provided
In file included from /cvmfs/cms.cern.ch/el9_amd64_gcc11/cms/cmssw/CMSSW_13_1_0_pre4/external/el9_amd64_gcc11/bin/../../../../../../../el9_amd64_gcc11/lcg/root/6.26.11-c74497fa7b0ab8f85c01e868f4d2fa9e/include/ROOT/RDataFrame.hxx:21,
                 from postprocess_W.cxx:12:
/cvmfs/cms.cern.ch/el9_amd64_gcc11/cms/cmssw/CMSSW_13_1_0_pre4/external/el9_amd64_gcc11/bin/../../../../../../../el9_amd64_gcc11/lcg/root/6.26.11-c74497fa7b0ab8f85c01e868f4d2fa9e/include/ROOT/RDF/RInterface.hxx:216:4: note: candidate: 'ROOT::RDF::RInterface<T, V>::RInterface(ROOT::RDF::RInterface<T, V>&&) [with Proxied = ROOT::Detail::RDF::RJittedFilter; DataSource = void]'
  216 |    RInterface(RInterface &&) = default;
      |    ^~~~~~~~~~
/cvmfs/cms.cern.ch/el9_amd64_gcc11/cms/cmssw/CMSSW_13_1_0_pre4/external/el9_amd64_gcc11/bin/../../../../../../../el9_amd64_gcc11/lcg/root/6.26.11-c74497fa7b0ab8f85c01e868f4d2fa9e/include/ROOT/RDF/RInterface.hxx:216:15: note:   no known conversion for argument 1 from 'ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager>' to 'ROOT::RDF::RInterface<ROOT::Detail::RDF::RJittedFilter, void>&&'
  216 |    RInterface(RInterface &&) = default;
      |               ^~~~~~~~~~~~~
/cvmfs/cms.cern.ch/el9_amd64_gcc11/cms/cmssw/CMSSW_13_1_0_pre4/external/el9_amd64_gcc11/bin/../../../../../../../el9_amd64_gcc11/lcg/root/6.26.11-c74497fa7b0ab8f85c01e868f4d2fa9e/include/ROOT/RDF/RInterface.hxx:212:4: note: candidate: 'ROOT::RDF::RInterface<T, V>::RInterface(const ROOT::RDF::RInterface<T, V>&) [with Proxied = ROOT::Detail::RDF::RJittedFilter; DataSource = void]'
  212 |    RInterface(const RInterface &) = default;
      |    ^~~~~~~~~~
/cvmfs/cms.cern.ch/el9_amd64_gcc11/cms/cmssw/CMSSW_13_1_0_pre4/external/el9_amd64_gcc11/bin/../../../../../../../el9_amd64_gcc11/lcg/root/6.26.11-c74497fa7b0ab8f85c01e868f4d2fa9e/include/ROOT/RDF/RInterface.hxx:212:15: note:   no known conversion for argument 1 from 'ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager>' to 'const ROOT::RDF::RInterface<ROOT::Detail::RDF::RJittedFilter, void>&'
  212 |    RInterface(const RInterface &) = default;

Hi @bouchamaouihichem,
thanks for reaching out!
It’s hard to tell what could be the issue here, are you able to isolate the problem and to provide us a small reproducer?

Cheers,
Monica

Hi Monica,

Thank you for your help, as I mentioned above, the issue comes from the new module that I added HEM.h, here’s a very simplified version of that module:

template <typename T>
auto ApplyHEM(T &df) {
if (condition true){
return df.Define(“var1_float”, function_that_returns_float, {“input_branch_float”})
.Filter("var1 == 1 || input_branch_int > some_int ", “Remove events that don’t pass the 2 conditions”);
}else{
return df.Define(“var1_float”, function_that_returns_float, {“input_branch_float”});
}
}

The problem seems to be coming from .Filter since I was able to run the code without it, but I used that in other modules, so I’m not sure why .Filter is not working in this instance.
Thank you for your help,
Hichem

It looks like you problem is related to manipulating RDF objects in functions. Did you try to use RNode? You may want to have a look at this tutorial.

Also, in order to further help you, it would be useful to have full reproducer, defining input values and all the functions used (e.g. function_that_returns_float), and giving the same error after execution

Hi Monica,

Thank you for the suggestion, I tried RNode and I am able to filter events successfully, but I need to return and RDF, not an RNode for the next step.

Here is the barebone function, with no extra stuff.

 ROOT::RDataFrame df(8); // some random rdf similar to the example provided [here](https://root.cern/doc/master/df025__RNode_8C.html)
 bool cond = False; // also try with True
 
auto function( ROOT::RDataFrame &df, bool cond) {
    if (cond){
         return df.Filter("rdf_entry < 3", "Apply filter");
     }else{     
         return df;   
     }    
}                                                                                                                                                                                                                                                                  

The error is still similar:
inconsistent deduction for auto return type: ‘ROOT::RDF::RInterface<ROOT::Detail::RDF::RJittedFilter, void>’ and then ‘ROOT::RDF::RInterfaceROOT::Detail::RDF::RLoopManager
59 | return df;
| ^~
helpers/HEM.h:59:13: error: no matching function for call to ‘ROOT::RDF::RInterface<ROOT::Detail::RDF::RJittedFilter, void>::RInterface(ROOT::RDF::RInterfaceROOT::Detail::RDF::RLoopManager)’

Thank you for your help,
Hichem

Hi Monica,

My collaborator (@skkwan) helped me figure out the issue. It seems that df.Filter doesn’t return exactly the same type as df. I’m still not sure why, but the fix is to add df.Filter to the else statement with a true statement and the code will run.

 ROOT::RDataFrame df(8); // some random rdf similar to the example provided [here](https://root.cern/doc/master/df025__RNode_8C.html)
 bool cond = False; // also try with True
 
auto function( ROOT::RDataFrame &df, bool cond) {
    if (cond){
         return df.Filter("rdf_entry < 3", "Apply filter");
     }else{     
         return df.Filter("True"; "Dummy filter, no events discarded");
     }    
}       

Thank you for your help,
Hichem

I’m happy you solved your issue, thanks for sharing the solution!