Open eguiraud opened 2 years ago
First reported at https://root-forum.cern.ch/t/trouble-reading-rvec-of-vector-from-branch-with-tclonesarray-of-objects-with-std-vector-member/52482 .
A reproducer:
// repro.C #include <ROOT/RDataFrame.hxx> #include <ROOT/RVec.hxx> #include <TClonesArray.h> #include <TObject.h> #include <TTree.h> #include <iostream> #include <vector> class Track : public TObject { public: std::vector<double> hitEnergies; int id = 42; Track(const std::vector<double> &v = {}) : hitEnergies{v} {}; ClassDef(Track, 1); }; ClassImp(Track); void repro() { // write file { TFile f("f.root", "recreate"); TTree tree("Events", "events"); TClonesArray arr("Track", 1); tree.Branch("Tracks", &arr); arr.ConstructedAt(0); ((Track *)arr.At(0))->hitEnergies.assign({1.0, 2.0, 3.0}); arr.ConstructedAt(1); ((Track *)arr.At(1))->hitEnergies.assign({4.0, 5.0}); tree.Fill(); tree.Write(); } TFile f("f.root"); { // reading back the `id` data member works TTreeReader r("Events", &f); TTreeReaderArray<int> ids(r, "Tracks.id"); r.Next(); std::cout << ids.GetSize() << '\n'; // prints 2 std::cout << ids[0] << ' ' << ids[1] << '\n'; // prints '42 42' } { // reading back hitEnergies data member does not work TTreeReader r("Events", &f); TTreeReaderArray<std::vector<double>> tracks(r, "Tracks.hitEnergies"); r.Next(); std::cout << tracks.GetSize() << '\n'; // prints 0! } }
Silently reading wrong data: critical!
Added 6.28 milestone as per discussion with @pcanal
As this error is now unsilenced in 6.28 we can at least remove the blocker.
First reported at https://root-forum.cern.ch/t/trouble-reading-rvec-of-vector-from-branch-with-tclonesarray-of-objects-with-std-vector-member/52482 .
A reproducer: