I was just trying out the shiny new TDataFrame
, when I ran into a problem.
The following code, which uses a lambda function to select events, works:
#include "TFile.h"
#include "ROOT/TDataFrame.hxx"
#include <iostream>
#include <stdlib.h>
auto tqCut = [](double TrPChi2) { return TrPChi2 > 0.001; };
void reduce_df(std::string file)
{
auto f = TFile::Open(file.c_str());
ROOT::Experimental::TDataFrame df("DYTuple/DecayTree", f);
auto selected = df.Filter(tqCut, {"muplus_TrPChi2"}).Filter(tqCut, {"muminus_TrPChi2"}).Count();
std::cout << *selected << std::endl;
}
When trying to use a string isntead (as should be possible according to the documentation), using this code:
#include "TFile.h"
#include "ROOT/TDataFrame.hxx"
#include <iostream>
#include <stdlib.h>
void reduce_df(std::string file)
{
auto f = TFile::Open(file.c_str());
ROOT::Experimental::TDataFrame df("DYTuple/DecayTree", f);
auto selected = df.Filter("muplus_TrPChi2 > 0.001 && muminus_TrPChi2 > 0.001").Count();
std::cout << *selected << std::endl;
}
This does not even compile:
Processing reduce_df.cxx++("../ntuple/dy_tuple_12_md.root")...
Info in <TUnixSystem::ACLiC>: creating shared library /home/andreas/cernbox/work/drell-yan/scripts/./reduce_df_cxx.so
In file included from input_line_11:9:
In file included from ././reduce_df.cxx:2:
In file included from /cern/root-6.09.02/include/ROOT/TDataFrame.hxx:21:
In file included from /cern/root-6.09.02/include/ROOT/TDFOperations.hxx:14:
/cern/root-6.09.02/include/ROOT/TDFTraitsUtils.hxx:31:54: error: type 'const char *' cannot be used prior to '::' because it has no members
using Args_t = typename TFunctionTraits<decltype(&T::operator())>::Args_t;
^
/cern/root-6.09.02/include/ROOT/TDataFrame.hxx:421:52: note: in instantiation of template class 'ROOT::Internal::TDFTraitsUtils::TFunctionTraits<const char *>' requested here
auto nArgs = ROOT::Internal::TDFTraitsUtils::TFunctionTraits<F>::Args_t::fgSize;
^
././reduce_df.cxx:17:49: note: in instantiation of function template specialization
'ROOT::Experimental::TDataFrameInterface<ROOT::Detail::TDataFrameImpl>::Filter<const char *>' requested here
auto selected = df.Filter("muplus_TrPChi2 > 0.001 && muminus_TrPChi2 > 0.001").Count();
^
In file included from input_line_11:9:
In file included from ././reduce_df.cxx:2:
In file included from /cern/root-6.09.02/include/ROOT/TDataFrame.hxx:21:
In file included from /cern/root-6.09.02/include/ROOT/TDFOperations.hxx:14:
/cern/root-6.09.02/include/ROOT/TDFTraitsUtils.hxx:32:61: error: type 'const char *' cannot be used prior to '::' because it has no members
using ArgsNoDecay_t = typename TFunctionTraits<decltype(&T::operator())>::ArgsNoDecay_t;
^
/cern/root-6.09.02/include/ROOT/TDFTraitsUtils.hxx:33:53: error: type 'const char *' cannot be used prior to '::' because it has no members
using Ret_t = typename TFunctionTraits<decltype(&T::operator())>::Ret_t;
^
In file included from input_line_11:9:
In file included from ././reduce_df.cxx:2:
/cern/root-6.09.02/include/ROOT/TDataFrame.hxx:215:4: error: static_assert failed "filter functions must return a bool"
static_assert(std::is_same<FilterRet_t, bool>::value, "filter functions must return a bool");
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/cern/root-6.09.02/include/ROOT/TDataFrame.hxx:418:23: note: in instantiation of function template specialization 'ROOT::Internal::CheckFilter<const char *>' requested here
ROOT::Internal::CheckFilter(f);
^
././reduce_df.cxx:17:49: note: in instantiation of function template specialization
'ROOT::Experimental::TDataFrameInterface<ROOT::Detail::TDataFrameImpl>::Filter<const char *>' requested here
auto selected = df.Filter("muplus_TrPChi2 > 0.001 && muminus_TrPChi2 > 0.001").Count();
^
Error in <ACLiC>: Dictionary generation failed!
Is this behaviour just not finished yet, or am I doing something wrong?
Cheers,
Andreas