Uploaded image for project: 'ROOT'
  1. ROOT
  2. ROOT-9731

[DF] Cannot read columns holding TVector3 pointers

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: High
    • Resolution: Fixed
    • Affects Version/s: 6.14/04
    • Fix Version/s: 6.24/00, 6.22/02
    • Component/s: RDataFrame
    • Labels:
      None
    • Environment:

      all

      Description

      Dave H. reports on the forum that it is not possible to work with ROOT datasets which contain columns holding pointers to `TVector3`. This causes a crash, also when such columns are not involved in the actions/transformations (see https://root-forum.cern.ch/t/how-can-i-create-an-rdataframe-from-a-ttree-containing-a-branch-of-type-tbranchobject/31144/6).
      This is the reproducer:

      // This script produces the following output:
      //
      // root [0]
      // Processing example_tbranchobject_problem.C...
      // a is a TBranchElement
      // b is a TBranchElement
      // c is a TBranchObject
      // terminate called after throwing an instance of 'std::runtime_error'
      //  what():  GetBranchNames: unsupported branch type
       
       
      #include "TFile.h"
      #include "TTree.h"
      #include "ROOT/RDataFrame.hxx"
       
      void createtree() {
        TFile tfile("examplefile.root", "RECREATE");
        TTree tree("tree", "tree");
        auto a = TVector3();
        auto b = TVector3();
        auto c = new TVector3();
        tree.Branch("a", &a);
        tree.Branch("b", &b);
        tree.Branch("c", "TVector3", &c, 32000, 0); // This method of creating a branch creates a branch of type "TBranchObject". If this line is commented out the script runs as expected.
        for (int ii = 0; ii < 10; ++ii) {
          a.SetX(ii);
          b.SetX(2*ii);
          c->SetX(3*ii);
          tree.Fill();
        }
        tree.Write();
        tfile.Close();
        return;
      }
       
      void checktype() {
        TFile tfile("examplefile.root", "READ");
        auto tree = (TTree*)tfile.Get("tree");
        for (auto br : *tree->GetListOfBranches()) {
          std::cout << br->GetName() << " is a " << br->IsA()->GetName() << std::endl;
        }
      }
       
      void readtree() {
        ROOT::RDataFrame rdf("tree", "examplefile.root");
        auto ha = rdf.Define("aval", "a.X()").Histo1D("aval");
        auto hb = rdf.Define("bval", "b.X()").Histo1D("bval");
        auto hc = rdf.Define("cval", "c.X()").Histo1D("cval");
        std::cout << "mu(a):" << ha->GetMean() << std::endl;
        std::cout << "mu(b):" << hb->GetMean() << std::endl;
        std::cout << "mu(c):" << hc->GetMean() << std::endl;
      }
       
      void example_tbranchobject_problem() {
        createtree();
        checktype();
        readtree();
        return;
      }
      

        Attachments

          Activity

            People

            • Assignee:
              eguiraud Enrico Guiraud
              Reporter:
              dpiparo Danilo Piparo
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: