Odd RDataFrame behavior?

I’ve been experiencing some unusual behavior when using an RDataFrame (unfortunately, I cannot narrow the issue down further). Namely, no code after Foreach() runs. Cling doesn’t throw any errors, nor does gcc. The issue occurs on two machines, one running Ubuntu 20.04 with ROOT hosted in a Conda environment, and one running an older version of Debian with ROOT built from source. I’m stumped.

Here’s a small example (note that I can confirm there’s nothing wrong with the file.root file, it does have data, and it does have a column named myColumn). The program does not print “Success” and, in fact, nothing placed here or after executes. Very bizzarre:

{

	ROOT::RDataFrame myFrame("D","./file.root");
	
	vector<vector<double>> myVec;
	
	myFrame.Foreach([&](double entry){
	
		myVec.push_back({entry,entry,entry});	
                printf("%f\n",entry);
	
	},{"myColumn"});
	
	printf("Success\n");

}

Edit:

The issue doesn’t occur with this code:

{

	ROOT::RDataFrame myFrame("D","./file.root");


	int i = 0;
	myFrame.Foreach([&](double entry){
	
		++i;
	
	},{"myColumn"});
	
	printf("Success\n");

}

I’m certain it’s not an issue of lack of sufficient memory, and I’m not sure what the vector could possibly have to do with this, as I’ve written very similar code before (often working with much larger datasets) and never had an issue.


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Hi @KAM,
I agree, that’s bizarre :smiley:

I tried to reproduce the problem with the following code:

#include <ROOT/RDataFrame.hxx>
#include <cstdlib>
#include <vector>
using namespace std;

void write_file() {
  ROOT::RDataFrame(10)
      .Define("myColumn", [] { return 42.; })
      .Snapshot<double>("D", "file.root", {"myColumn"});
}

void repro() {
  ROOT::RDataFrame myFrame("D", "./file.root");
  vector<vector<double>> myVec;
  myFrame.Foreach(
      [&](double entry) {
        myVec.push_back({entry, entry, entry});
        printf("%f\n", entry);
      },
      {"myColumn"});

  printf("Success\n");
}

#ifndef __CLING__
int main() {
  write_file();
  repro();
  return 0;
}
#endif

which I ran both as a compiled program and through root -l, with no problems.

  1. can you step through with gdb --args root.exe -l macro.C (note the usage of root.exe instead of root) and see what the code is doing?
  2. do you still see this behavior if the code is compiled rather than interpreted via root?
  3. are you sure the printf is not executed, or could it be that it’s “just” never flushed to standard output? does std::cout << "Success" << std::endl work instead? (<< std::endl forces a flush to stdout, which \n in a printf call should also do, but :man_shrugging:)

Cheers,
Enrico

@eguiraud

Hmm. I too am unable to reproduce the error with your code, but continue to get the error with mine (letter for letter exactly as written here). Very strange.

To answer your questions: yes, I do see the error when the code is compiled (I used g++, with no compiler errors thrown), and I also see the error when using std::cout << "Success" << std::endl;. I’ll try your suggestion with gdb.

Thanks!

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