Root retruns all zeroes, when iterating through branch

Currently, I use the following script to read .root file

#include <iostream>
#include <fstream>
#include <string>

void read_tree() {
    TFile* file = TFile::Open("my_file.root");
    TTree* frames = (TTree*)file->Get("Frames;1/fr");
    frames.Print();

    Long64_t size = frames->GetEntries();   
    std::cout << size << std::endl;
    Int_t ids = 0;
    frames->SetBranchAddress("id", &ids);

    for (Long64_t index=0; index < 20; ++index) {
        frames->GetEntry(index);
        std::cout << ids << std::endl;
    }
}

Usually this works fine and i got read all the values. However, on this particular my_file.root, I get printed all 0!
The size variable above is ok, and contains correct value.

Is there are any problem with file I got, or I am missing something?

Try:

TTree* frames; file->GetObject("Frames",frames);

i.e. do not request a specific cycle.

Cheers,
Philippe.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.