Hi Danilo,
Ok, I think that is exactly what I need.
So far I tried this:
#include <ROOT/RDataFrame.hxx>
#include "ROOT/RDF/RInterface.hxx"
#include <iostream>
ROOT::RDF::RNode defines(ROOT::RDF::RNode node, int ncols){
if(ncols > 0){
return defines(node.Define("x"+std::to_string(ncols), [ncols](){return ncols;}), ncols-1);
}
else{
return node;
}
}
int snapshotperf(){
ROOT::RDataFrame df_orig(10);
auto df = defines(df_orig, 3);
std::time_t start = std::time(0);
ROOT::RDF::RSnapshotOptions opts;
opts.fLazy = true;
using SnapRet_t = ROOT::RDF::RResultPtr<ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager>>;
std::vector<SnapRet_t> rets;
std::vector<std::string> columnnames = {"x1", "x2", "x3"};
std::vector<std::string> columntypes = {"int", "int", "int"};
std::string template_expr("<");
for(int i = 0; i < columntypes.size(); i++){
template_expr+=columntypes[i];
if(i!= columntypes.size()-1)
template_expr+=",";
}
template_expr+=">";
std::string declare_expr(
"ROOT::RDF::RResultPtr<ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager>> make_snap(ROOT::RDF::RNode df, std::string treename, std::string fname, std::vector<std::string> columnnames, ROOT::RDF::RSnapshotOptions opts){"
"return df.Snapshot"+template_expr+"(treename, fname, columnnames, opts);"
"}");
gInterpreter->Declare(declare_expr.c_str());
TInterpreterValue *tiv = gInterpreter->CreateTemporary();
std::string eval_str(
"[](ROOT::RDF::RNode df, std::string treename, std::string fname, std::vector<std::string> columnnames, ROOT::RDF::RSnapshotOptions opts)"
" {return make_snap(df, treename, fname, columnnames, opts);};"
);
gInterpreter->Evaluate(eval_str.c_str(), *tiv);
using functype = std::function<SnapRet_t(ROOT::RDF::RNode,std::string,std::string,std::vector<std::string>, ROOT::RDF::RSnapshotOptions)>;
functype make_snap = *(functype*)tiv->GetAsPointer();
for (auto i = 0; i < 5; ++i){
SnapRet_t res = make_snap(df, "t", "f" + std::to_string(i) + ".root", columnnames, opts);
rets.emplace_back(res);
}
return df.Count().GetValue();
}
So far this gives me a segmentation violation. Do you know what I did wrong?
Cheers,
Christian
*** Break *** segmentation violation
[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)
[<unknown binary>] (no debug info)
[<unknown binary>] (no debug info)
[<unknown binary>] (no debug info)
[<unknown binary>] (no debug info)
[/Users/Christian/work/root/root_v6_16/lib/libCling.so] cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) (no debug info)
[/Users/Christian/work/root/root_v6_16/lib/libCling.so] cling::Interpreter::EvaluateInternal(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) (no debug info)
[/Users/Christian/work/root/root_v6_16/lib/libCling.so] cling::MetaSema::actOnxCommand(llvm::StringRef, llvm::StringRef, cling::Value*) (no debug info)
[/Users/Christian/work/root/root_v6_16/lib/libCling.so] cling::MetaParser::isXCommand(cling::MetaSema::ActionResult&, cling::Value*) (no debug info)
[/Users/Christian/work/root/root_v6_16/lib/libCling.so] cling::MetaParser::isCommand(cling::MetaSema::ActionResult&, cling::Value*) (no debug info)
[/Users/Christian/work/root/root_v6_16/lib/libCling.so] cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) (no debug info)
[/Users/Christian/work/root/root_v6_16/lib/libCling.so] HandleInterpreterException(cling::MetaProcessor*, char const*, cling::Interpreter::CompilationResult&, cling::Value*) (no debug info)
[/Users/Christian/work/root/root_v6_16/lib/libCling.so] TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) (no debug info)
[/Users/Christian/work/root/root_v6_16/lib/libCling.so] TCling::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) (no debug info)
[/Users/Christian/work/root/root_v6_16/lib/libCore.6.16.so] TApplication::ExecuteFile(char const*, int*, bool) (no debug info)
[/Users/Christian/work/root/root_v6_16/lib/libRint.6.16.so] TRint::ProcessLineNr(char const*, char const*, int*) (no debug info)
[/Users/Christian/work/root/root_v6_16/lib/libRint.6.16.so] TRint::Run(bool) (no debug info)
[/Users/Christian/work/root/root_v6_16/bin/root.exe] main (no debug info)
[/usr/lib/system/libdyld.dylib] start (no debug info)