I/O w/ TTree & (small) non-ROOT objects

The goal: store a small object – e.g. a fundamental type like double, or STL type like std::array<double,N> – in a TTree.

My problem: I can convert the object (e.g. that array) to a native ROOT type (e.g. a TVector). I can add it to a TTree using the TTree::Branch() method that uses (constructs?) a TBranchElement, and write the TTree to disk in a TFile. I can reopen that file, get the TTree, and then retrieve that branch with the TTree::GetBranch() method. However, I can’t the actual data from the branch.

I think the solution probably involves using the TBranchElement::SetAddress() function, but I can’t yet retrieve an actual TBranchElement. TTree::GetBranch() returns a TBranch*, but I get a compile-time error if I try to use it to get a TBranchElement* ( even though TBranchElement descends from TBranch). All of the TBranchElement constructors apparently assume (require?) that the branch object be a TClonesArray or an STL container, so it seems I can’t use them to get a TVector. Incidentally, TBranchSTL wouldn’t work for me: ROOT5 doesn’t know about std::array, and the STL types it does know are expected to be collections of pointers. My containers contain the objets themselves.

My aim is just to have the simplest possible method for writing/reading non-ROOT objects to TTrees/TFiles.I’m not set on using TBranchElements, that just seemed the appropriate class. I do realize the conversion to/from ROOT and STL types is less than optimal. However, I much prefer using the latter, and will accept the trade off of making I/O more painful. If converting from an STL type to a C++ fundamental type, e.g. a C-style array, would make this easier, I’d happily do that.

I’m using 5-34-18 on OSX 10.9.2. Thanks in advance for any guidance.

Patrick