Std::vector for TTree in ROOT 6

Hi,
I searched for a way to read a std::vector from TTree, though each example I have found on the forum is highly outdated. Is there a better way than it was 10 years ago?
Also, if possible, I would like to save “writing to tree” format as follows:

TTree *td = new TTree(“td”,“something”);
Int_t npar=0;
std::vector<Int_t> bar(k);
td->Branch(“npar”,&npar,“npar/I”);
td->Branch(“bar”,&bar[0],“bar[npar]/I”);

Thanks in advance.

The newest read syntax is to use RDataFrame.

Also, if possible, I would like to save “writing to tree” format as follows:

Yes, as long a bar->capacity() does not increase after the calls to Branch.

1 Like

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