Is there a way to save dataframe to an already existing root file?

We must be doing something different. This works for me:

#include <ROOT/RDataFrame.hxx>

int main() {
   auto df = ROOT::RDataFrame(10).Define("x", [] { return 42; });

   // produce initial file
   df.Snapshot<int>("t1", "f.root", {"x"});

   // write another tree to that file
   ROOT::RDF::RSnapshotOptions opts1;
   opts1.fMode = "update";
   df.Snapshot<int>("t2", "f.root", {"x"}, opts1);

   // overwrite the t1
   ROOT::RDF::RSnapshotOptions opts2;
   opts2.fMode = "update";
   opts2.fOverwriteIfExists = true;
   df.Range(5).Snapshot<int>("t1", "f.root", {"x"}, opts2);

   return 0;
}

At the end of the program f.root contains t1 with 5 entries and t2 with 10. What am I doing differently?

Cheers,
Enrico

1 Like