Store RDataframe.Filter results in an array

ROOT Version:6.14
Platform:linux
Compiler:gcc 7.3.1

I have recently changed my ROOT version from 6.12.6 to 6.14 and I noticed that the results of RDataframe.Filter(…) cannot be stored in a std::vector anymore, which was possible which the former TDataFrame.

I vary the number of cuts based on different analyses, but I also need to be able to address each filter. This rules out chaining of filters, because it would require to change the code and recompile or to hard code each filter set. Now I am wondering, if there is an equivalent way to store or address each filter separately.

Thanks for your help

Cheers Thomas

Hi Thomas,

what is the piece of code which actually does not work anymore? Could you share it on the forum?

Best,
D

Hi Thomas,
just wanted to add that yes, there were breaking changes between v6.12 and v6.14 as RDataFrame left the ROOT::Experimental namespace – it was a one-time thing and it shouldn’t happen again :slight_smile:

For string filters, i.e. Filter("x > 0"), you can store them in a std::vector<ROOT::RDF::Interface<ROOT::Detail::RDF::RJittedFilter>>.
Lambda filters, i.e. Filter([] (int x) { return x > 0; }, {"x"}) are trickier.

Soon™ you will just be able to cast every dataframe node to the same simple type RNode, see this PR which was spurred by an use-case similar to yours.

Cheers,
Enrico

Hey Guys,

thanks for your fast replies :). I am looking forward to the mentioned RNode. Is there an approximate eta when this abstraction could go live? Is more like month or weeks?.

For reference the following code was possible with TDataFrame:

using TFilter = ROOT::Detail::TDF::TFilterBase;
using TInterface = ROOT::Experimental::TDF::TInterface<TFilter>;

template<typename BranchType,class Interface>
TInterface getFilter
    ( Interface& predecessor
    , BranchType low
    , BranchType high
    , const std::string& filtername
    )
{
    auto newFilter = predecessor.Filter(
        [low,high](const std::vector<BranchType>& branch)->bool{
            for(auto value : branch){
                if(value >= low && value <= high){
                    return true;
                }
            }
            return false;
        }
        , {getBranchNameForCut(aCut.type)}
        , {filtername}
    );
    return newFilter;
}

int main()
{
   TDataFrame d(...);
 
   std::vector<TInterFace> filter;
   filter.emplace_back(getFilter<int>(d,0,1,"testfilter"));
   filter.emplace_back(getFilter<float>(filter.back(),0.0,1.0,aCut,"testfilter2"));

  return 0;
}

Modulo some typing errors

1 Like

Hi Thomas,
I see, thank you. This is a bug report then: we (or, given the commit’s author, I) inadvertently removed a useful feature that you (and possibly others) were using.

As for the RNode PR, it should be merged in master hopefully in O(days/few weeks).

I also opened ROOT-9506 to make sure that we solve the problem in v6.14 as well, in one way or another. You can follow the issue there.

Thanks a lot!
Enrico

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.