Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TTreeReader] Wrong (empty) arrays silently read for complex data members of TClonesArray elements #11769

Open
eguiraud opened this issue Nov 24, 2022 · 4 comments

Comments

@eguiraud
Copy link
Member

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!
  }
}
@Axel-Naumann
Copy link
Member

Silently reading wrong data: critical!

@eguiraud eguiraud added this to the 6.28/00 milestone Dec 14, 2022
@eguiraud
Copy link
Member Author

Added 6.28 milestone as per discussion with @pcanal

@pcanal
Copy link
Member

pcanal commented Jan 27, 2023

#12137 Makes this setup a visible error pending the actual implementation.

@Axel-Naumann
Copy link
Member

As this error is now unsilenced in 6.28 we can at least remove the blocker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants