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

[TTreeReader] IsValid returns false before TTreeReaderValue is dereferenced for the first time

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: High
    • Resolution: Clarified
    • Affects Version/s: 6.20/04
    • Fix Version/s: 6.22/02
    • Component/s: None
    • Labels:
      None
    • Environment:

      any

    • Development:

      Description

      A workaround is to check GetSetupStatus() == 0 instead.

      Reproducer:

      #include <TTree.h>
      #include <TFile.h>
      #include <TTreeReader.h>
      #include <TTreeReaderValue.h>
      #include <cassert>
      int main()
                          
      {
         const auto fname = "f.root";
         {
            TFile f(fname, "recreate");
            int x = 1;
            TTree t("t", "t");
            t.Branch("x", &x);
            t.Fill();
            t.Write();
            f.Close();
         }
         TFile f(fname);
         TTreeReader r("t", &f);
         TTreeReaderValue<int> xv(r, "x");
         r.Next();
         // prints "false 1 true"
         std::cout << std::boolalpha << xv.IsValid() << " " << *xv << " " << xv.IsValid() << std::endl;
         return 0;
      }
      

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: