Filling a TBranch inside a loop


ROOT Version: 6
_Platform:_64bit
Compiler: Cling


I am having an issue with my code. Let me share the code snippet first.

TFile *f = new TFile("temp.root","update");
TTree *t = (TTree*)f->Get("trackpatterns");

//Read a TBrach of type TObject (), PndPattern is a class.
PndPattern *p = new PndPattern();
t->SetBranchAddress("pattern", &p);

int m_TubeIDs;
TBranch *btubes = t->Branch("fTubeIDs",&m_TubeIDs,"m_TubeIDs/I");
for (Long64_t i=0; i<t->GetEntries() /*~ 1300*/; i++)
 {
    t->GetEntry(i);
    // There are roughly 52000 tubeids.
    std::set<int> tubeids = p->GetTubeIDs();

    for (auto const& tubeid: tubeids) {
        m_TubeIDs = tubeid;        
        btubes->Fill();
    }
}
t->Write();

I don’t see any logical mistake in this code. But when I run my macro, it seems TBranch “btubes” is filled only ones. TTree entries are around 13000, as std::set has various lengths (total entries should be around 52000). Basically, I am converting an std::set member of the PndPattern class into a separate TBrach containing integer values.

Try:
PndPattern *p = 0;

and

// There are roughly 52000 tubeids.
std::set<int> tubeids = p->GetTubeIDs();
cout<<"size "<<tubeids->size()<<endl;

m_TubeIDs = tubeid;
cout<<"tubeId "<<m_TubeIDs<<endl;

will probably give you some clues.

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