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

[TTreeReader] Wrong entries are loaded in case of TChain+TEntryList

    XMLWordPrintable

    Details

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

      any

      Description

      In the following repro one would expect TTreeReader(&chain, chain.GetEntryList()) to read the same entries as chain.Scan, but that's not the case.

      First reported on the forum.

      #include <TFile.h>
      #include <TTree.h>
      #include <TChain.h>
      #include <TEntryList.h>
      #include <TTreeReader.h>
      #include <TTreeReaderValue.h>
      #include <iostream>
       
      void MakeInputFiles()
      {
         int e = 0;
         for (int i = 1; i <= 2; ++i) {
            TFile f(("f" + std::to_string(i) + ".root").c_str(), "recreate");
            TTree t("t", "t");
            t.Branch("e", &e);
            for (int j = 0; j < 3; ++j) {
               t.Fill();
               ++e;
            }
            t.Write();
            f.Close();
         }
      }
       
      int main()
      {
         // files "f{1,2}.root" with TTree "t" values "e" = {0,1,2} and {3,4,5}
         MakeInputFiles();
       
         TEntryList elist1("e", "e", "t", "f1.root");
         elist1.Enter(0);
         elist1.Enter(2);
         TEntryList elist2("e", "e", "t", "f2.root");
         elist2.Enter(0);
         elist2.Enter(2);
       
       
         // make a TEntryList that contains two TEntryLists in its list of TEntryLists,
         // as required by TChain (see TEntryList's doc)
         TEntryList elists;
         elists.Add(&elist1);
         elists.Add(&elist2);
       
         TChain c("t");
         c.Add("f1.root", 3);
         c.Add("f2.root", 3);
         c.SetEntryList(&elists);
       
         TTreeReader r(&c, c.GetEntryList());
         TTreeReaderValue<int> e(r, "e");
         while (r.Next())
            std::cout << *e << " ";
         std::cout << std::endl;
       
         c.Scan("e");   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: