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

[TTree] Wrong data could be silently written if data-member of object has same name as another branch

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 6.22/00
    • Fix Version/s: 6.22/00, 6.24/00, 6.20/08
    • Component/s: TTree
    • Labels:
      None
    • Environment:

      any

      Description

      To reproducer, run with:

      root -l -q -e '.L repro.cpp++' && g++ -o repro repro.cpp $(root-config --libs --cflags) && ./repro
      

      the following code:

      // repro.cpp
      #include <TTree.h>
      #include <TFile.h>
      #include <TInterpreter.h>
       
      struct Int {
         int x;
      };
       
      int main()
      {
         gInterpreter->Load("repro_cpp.so");
         TFile f("f.root", "recreate");
         Int i{-1};
         int x = 1;
         TTree t("t", "t");
         t.Branch("i", &i);
         t.Branch("x", &x);
         t.Fill();
         t.Write();
         f.Close();
       
         TFile("f.root").Get<TTree>("t")->Scan();   return 0;
      }
      

      prints

      ************************************
      *    Row   *       i.x *         x *
      ************************************
      *        0 *        -1 *        -1 *
      ************************************
      

      x value should be 1, it's -1 instead.

      Interestingly, inverting the order of the Branch calls fixes the issue.

      A more complete reproducer for all issues I have found so far is available in the comments.

        Attachments

          Activity

            People

            • Assignee:
              pcanal Philippe Canal
              Reporter:
              eguiraud Enrico Guiraud
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: