RTrivialDS can not define new column with function

ROOT Version: 6.22/08
Built for linuxx8664gcc on Mar 10 2021, 14:20:04
From tags/v6-22-08@v6-22-08

Hello, I have tried ROOT::RDF::MakeTrivialDataFrame, but I found that the RDataframe from MakeTrivialDataFrame can only define new column with string and when defining new column with function, error will happen.

simple to reproduce the bug with

  ROOT::RDF::MakeTrivialDataFrame(10)
    .Define("x", [](int i) { return i + 1; }, {"col0"})

And no error would be produced when defining column using string as df010_trivialDataSource.C or using dataframe from a normal root file.

The error is like

In module 'ROOTDataFrame':
/home/arch/opt/root-6.22.08/include/ROOT/RDF/RInterface.hxx:2355:14: error: no viable conversion from returned value of type 'RInterface<[...], (default) void>' to function return type 'RInterface<[...], ROOT::RDF::RTrivialDS>'
      return newInterface;
             ^~~~~~~~~~~~
/home/arch/opt/root-6.22.08/include/ROOT/RDF/RInterface.hxx:296:14: note: in instantiation of function template specialization 'ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager, ROOT::RDF::RTrivialDS>::DefineImpl<(lambda at
      /home/arch/Analysis/root/test_dataframe_histo2d.cpp:13:18), ROOT::Detail::RDF::CustomColExtraArgs::None, int>' requested here
      return DefineImpl<F, RDFDetail::CustomColExtraArgs::None>(name, std::move(expression), columns);
             ^
/home/arch/Analysis/root/test_dataframe_histo2d.cpp:13:6: note: in instantiation of function template specialization 'ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager, ROOT::RDF::RTrivialDS>::Define<(lambda at
      /home/arch/Analysis/root/test_dataframe_histo2d.cpp:13:18), 0>' requested here
    .Define("x", [](int i) { return i + 1; }, {"col0"})
     ^
/home/arch/opt/root-6.22.08/include/ROOT/RDF/RInterface.hxx:117:4: note: candidate constructor not viable: no known conversion from 'RInterface<ROOT::Detail::RDF::RLoopManager>' to 'const ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager,
      ROOT::RDF::RTrivialDS> &' for 1st argument
   RInterface(const RInterface &) = default;
   ^
/home/arch/opt/root-6.22.08/include/ROOT/RDF/RInterface.hxx:121:4: note: candidate constructor not viable: no known conversion from 'RInterface<ROOT::Detail::RDF::RLoopManager>' to 'ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager,
      ROOT::RDF::RTrivialDS> &&' for 1st argument
   RInterface(RInterface &&) = default;
   ^
/home/arch/opt/root-6.22.08/include/ROOT/RDF/RInterface.hxx:126:4: note: candidate constructor not viable: no known conversion from 'RInterface<ROOT::Detail::RDF::RLoopManager>' to 'const std::shared_ptr<RLoopManager> &' for 1st argument
   RInterface(const std::shared_ptr<Proxied> &proxied)
   ^
/home/arch/opt/root-6.22.08/include/ROOT/RDF/RInterface.hxx:150:4: note: candidate function
   operator RNode() const
   ^

 *** Break *** segmentation violation
 Generating stack trace...
 0x00007f2ef9743f39 in <unknown> from /home/arch/opt/root-6.22.08/lib/libCling.so
 0x00007f2ef973e876 in <unknown> from /home/arch/opt/root-6.22.08/lib/libCling.so
 0x00007f2ef973fb86 in <unknown> from /home/arch/opt/root-6.22.08/lib/libCling.so
 0x00007f2ef9743f39 in <unknown> from /home/arch/opt/root-6.22.08/lib/libCling.so
 0x00007f2ef97441e2 in cling::DeclUnloader::VisitFunctionDecl(clang::FunctionDecl*) + 0x182 from /home/arch/opt/root-6.22.08/lib/libCling.so
 0x00007f2ef971a6d4 in cling::TransactionUnloader::unloadDeclarations(cling::Transaction*, cling::DeclUnloader&) + 0xf4 from /home/arch/opt/root-6.22.08/lib/libCling.so
 0x00007f2ef971aa41 in cling::TransactionUnloader::RevertTransaction(cling::Transaction*) + 0x2f1 from /home/arch/opt/root-6.22.08/lib/libCling.so
 0x00007f2ef9705bda in cling::Interpreter::unload(cling::Transaction&) + 0x24a from /home/arch/opt/root-6.22.08/lib/libCling.so
 0x00007f2ef9779457 in cling::IncrementalParser::commitTransaction(llvm::PointerIntPair<cling::Transaction*, 2u, cling::IncrementalParser::EParseResult, llvm::PointerLikeTypeTraits<cling::Transaction*>, llvm::PointerIntPairInfo<cling::Transaction*, 2u, llvm::PointerLikeTypeTraits<cling::Transaction*> > >&, bool) at IncrementalParser.cpp:? from /home/arch/opt/root-6.22.08/lib/libCling.so
 0x00007f2ef977c246 in cling::IncrementalParser::Compile(llvm::StringRef, cling::CompilationOptions const&) + 0x66 from /home/arch/opt/root-6.22.08/lib/libCling.so
 0x00007f2ef9700d7c in cling::Interpreter::DeclareInternal(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::CompilationOptions const&, cling::Transaction**) const + 0x4c from /home/arch/opt/root-6.22.08/lib/libCling.so
 0x00007f2ef9703597 in cling::Interpreter::loadHeader(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::Transaction**) + 0x187 from /home/arch/opt/root-6.22.08/lib/libCling.so
 0x00007f2ef97b7c18 in cling::MetaSema::actOnLCommand(llvm::StringRef, cling::Transaction**) + 0x168 from /home/arch/opt/root-6.22.08/lib/libCling.so
 0x00007f2ef97b7dd1 in cling::MetaSema::actOnxCommand(llvm::StringRef, llvm::StringRef, cling::Value*) + 0x51 from /home/arch/opt/root-6.22.08/lib/libCling.so
 0x00007f2ef97c64a2 in cling::MetaParser::isXCommand(cling::MetaSema::ActionResult&, cling::Value*) + 0x192 from /home/arch/opt/root-6.22.08/lib/libCling.so
 0x00007f2ef97c78ae in cling::MetaParser::isCommand(cling::MetaSema::ActionResult&, cling::Value*) + 0x9e from /home/arch/opt/root-6.22.08/lib/libCling.so
 0x00007f2ef97b17c9 in cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) + 0x199 from /home/arch/opt/root-6.22.08/lib/libCling.so
 0x00007f2ef9662e9c in <unknown> from /home/arch/opt/root-6.22.08/lib/libCling.so
 0x00007f2ef967c9b6 in <unknown> from /home/arch/opt/root-6.22.08/lib/libCling.so
 0x00007f2ef967ccf2 in <unknown> from /home/arch/opt/root-6.22.08/lib/libCling.so
 0x00007f2efd38bb45 in TApplication::ExecuteFile(char const*, int*, bool) at TApplication.cxx:? from /home/arch/opt/root-6.22.08/lib/libCore.so
 0x00007f2efd68207c in TRint::ProcessLineNr(char const*, char const*, int*) + 0x5c from /home/arch/opt/root-6.22.08/lib/libRint.so
 0x00007f2efd683834 in TRint::Run(bool) + 0x2e4 from /home/arch/opt/root-6.22.08/lib/libRint.so
 0x000055ba4957f10c in <unknown> from /home/arch/opt/root-6.22.08/bin/root.exe
 0x00007f2efcc7eb25 in __libc_start_main + 0xd5 from /usr/lib/libc.so.6
 0x000055ba4957f15e in _start + 0x2e from /home/arch/opt/root-6.22.08/bin/root.exe
Root > %                   

Thank you very much! :grinning:

Hi,
yes that looks like a bug.
However RTrivialDS does not serve any useful purpose other than being a simple example of a custom RDataSource implementation (iow you should never need to use RTrivialDS in practice).

If you want an RDF with no columns and 10 entries, you can just use

ROOT::RDataFrame(10).Define(...)

I’ll fix the bug and clarify the docs.

Cheers,
Enrico

EDIT: the fix is at https://github.com/root-project/root/pull/9039

Thank you very much, :grinning:

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