Dear ROOT experts,
I have a class TRestComponent
that contains a method named std::vector<Double_t> GetRandom()
and a member named std::vector <std::string> fVariables
. Both vectors fVariables
and the vector returned by GetRandom
will have the same dimension.
I want to implement a method that populates a RDataFrame using the results of GetRandom
where each component is associated to a column name with names given by fVariables
.
After some discussions with chatGPT, she agreed that the following should do the job:
ROOT::RDF::RNode TRestComponent::GetMonteCarloDataFrame(Int_t N) {
// Create a RDataFrame with the specified columns
ROOT::RDataFrame df(N);
// Function to fill the RDataFrame using GetRandom method
auto fillDataFrame = [this,&df](unsigned int idx) {
auto randomValues = GetRandom();
// Check if the size of randomValues matches the size of columnNames
if (randomValues.size() != fVariables.size()) {
throw std::runtime_error("Mismatch in sizes of fVariables and randomValues");
}
// Fill the RDataFrame with values from GetRandom
for (size_t i = 0; i < randomValues.size(); ++i) {
df.Define(fVariables[i], randomValues[i]);
}
};
// Apply the fillDataFrame function to each entry in the RDataFrame
df.Foreach(fillDataFrame, {"idx"});
// Return the RNode (RDataFrame)
return df;
}
However, I get the following compilation error:
[ 1%] Building CXX object source/framework/CMakeFiles/RestFramework.dir/sensitivity/src/TRestComponent.cxx.o
In file included from /nfs/dust/iaxo/group/software/root/6.26.02/install/include/ROOT/RDataFrame.hxx:20,
from /afs/desy.de/user/j/jgalan/rest-framework/source/framework/core/inc/TRestDataSet.h:28,
from /afs/desy.de/user/j/jgalan/rest-framework/source/framework/sensitivity/inc/TRestComponent.h:29,
from /afs/desy.de/user/j/jgalan/rest-framework/source/framework/sensitivity/src/TRestComponent.cxx:41:
/nfs/dust/iaxo/group/software/root/6.26.02/install/include/ROOT/RDF/RInterface.hxx: In instantiation of ‘ROOT::RDF::RInterface<T, V> ROOT::RDF::RInterface<T, V>::Define(std::string_view, F, const ColumnNames_t&) [with F = double; typename std::enable_if<(! std::is_convertible<F, std::basic_string<char> >::value), int>::type <anonymous> = 0; Proxied = ROOT::Detail::RDF::RLoopManager; DataSource = void; std::string_view = std::basic_string_view<char>; ROOT::RDF::ColumnNames_t = std::vector<std::basic_string<char> >]’:
/afs/desy.de/user/j/jgalan/rest-framework/source/framework/sensitivity/src/TRestComponent.cxx:307:44: required from here
/nfs/dust/iaxo/group/software/root/6.26.02/install/include/ROOT/RDF/RInterface.hxx:394:111: error: no matching function for call to ‘ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager>::DefineImpl<double, ROOT::Detail::RDF::CustomColExtraArgs::None>(std::string_view&, std::remove_reference<double&>::type, const ColumnNames_t&, const char [7])’
394 | return DefineImpl<F, RDFDetail::CustomColExtraArgs::None>(name, std::move(expression), columns, "Define");
| ^
In file included from /nfs/dust/iaxo/group/software/root/6.26.02/install/include/ROOT/RDataFrame.hxx:20,
from /afs/desy.de/user/j/jgalan/rest-framework/source/framework/core/inc/TRestDataSet.h:28,
from /afs/desy.de/user/j/jgalan/rest-framework/source/framework/sensitivity/inc/TRestComponent.h:29,
from /afs/desy.de/user/j/jgalan/rest-framework/source/framework/sensitivity/src/TRestComponent.cxx:41:
/nfs/dust/iaxo/group/software/root/6.26.02/install/include/ROOT/RDF/RInterface.hxx:3173:4: note: candidate: ‘template<class F, class DefineType, class RetType> std::enable_if_t<std::is_default_constructible<RetType>::value, ROOT::RDF::RInterface<T, V> > ROOT::RDF::RInterface<T, V>::DefineImpl(std::string_view, F&&, const ColumnNames_t&, const string&) [with F = F; DefineType = DefineType; RetType = RetType; Proxied = ROOT::Detail::RDF::RLoopManager; DataSource = void]’
3173 | DefineImpl(std::string_view name, F &&expression, const ColumnNames_t &columns, const std::string &where)
| ^~~~~~~~~~
/nfs/dust/iaxo/group/software/root/6.26.02/install/include/ROOT/RDF/RInterface.hxx:3173:4: note: template argument deduction/substitution failed:
/nfs/dust/iaxo/group/software/root/6.26.02/install/include/ROOT/RDF/RInterface.hxx:3171:47: error: no type named ‘ret_type’ in ‘struct ROOT::Detail::CallableTraitsImpl<double, false>’
3171 | template <typename F, typename DefineType, typename RetType = typename TTraits::CallableTraits<F>::ret_type>
| ^~~~~~~~
/nfs/dust/iaxo/group/software/root/6.26.02/install/include/ROOT/RDF/RInterface.hxx:3224:4: note: candidate: ‘template<class F, class DefineType, class RetType, bool IsFStringConv, bool IsRetTypeDefConstr> std::enable_if_t<((! IsFStringConv) && (! IsRetTypeDefConstr)), ROOT::RDF::RInterface<T, V> > ROOT::RDF::RInterface<T, V>::DefineImpl(std::string_view, F, const ColumnNames_t&) [with F = F; DefineType = DefineType; RetType = RetType; bool IsFStringConv = IsFStringConv; bool IsRetTypeDefConstr = IsRetTypeDefConstr; Proxied = ROOT::Detail::RDF::RLoopManager; DataSource = void]’
3224 | DefineImpl(std::string_view, F, const ColumnNames_t &)
| ^~~~~~~~~~
/nfs/dust/iaxo/group/software/root/6.26.02/install/include/ROOT/RDF/RInterface.hxx:3224:4: note: template argument deduction/substitution failed:
In file included from /nfs/dust/iaxo/group/software/root/6.26.02/install/include/ROOT/RDataFrame.hxx:20,
from /afs/desy.de/user/j/jgalan/rest-framework/source/framework/core/inc/TRestDataSet.h:28,
from /afs/desy.de/user/j/jgalan/rest-framework/source/framework/sensitivity/inc/TRestComponent.h:29,
from /afs/desy.de/user/j/jgalan/rest-framework/source/framework/sensitivity/src/TRestComponent.cxx:41:
/nfs/dust/iaxo/group/software/root/6.26.02/install/include/ROOT/RDF/RInterface.hxx:394:111: note: candidate expects 3 arguments, 4 provided
394 | return DefineImpl<F, RDFDetail::CustomColExtraArgs::None>(name, std::move(expression), columns, "Define");
| ^
make[2]: *** [source/framework/CMakeFiles/RestFramework.dir/sensitivity/src/TRestComponent.cxx.o] Error 1
make[1]: *** [source/framework/CMakeFiles/RestFramework.dir/all] Error 2
make: *** [all] Error 2
Press ENTER or type command to continue
Any guesses on how to solve this issue?
Thank you!