Pointers in root tree?

Do pointers still work when we save objects into a root tree? Is there a way to store pointers to information in a root tree? (I have not gotten very far on my root journey. Right now I’m concentrating on designing my data model and writing the code to store the data. I haven’t gotten as far as actually working with the data in ROOT, so I’m sorry if this is a silly question)

For example, I would like to store a linked list in the root tree. If I store all the elements in the list in the tree, can I still traverse them in root via the pointer somehow? Similarly, I would like to store a bunch of information which all contain a certain “primary key”. It would be faster to store related info based on this primary key rather than search multiple data structures to locate the entries based on this primary key. Searching a single structure based on the primary key and getting a set of pointers to data structures related to this primary key would more convenient I think. (of course I would have to store such a group of relevant pointers for every primary key)

Alternatively, is there a better way to emulate such a database-style approach?

Thanks

Hi,

You can store pointers into a TTree but significant restrictions. If the pointer and the pointee are stored in the same un-split branch ; in this case when reading back the pointer will be properly restore to point to the object (that will be recreated when reading back). However the pointer and the pointee are stored in different branches, when writing 2 copies of the pointee object will be stored (one in each proper branch and one in the same branch as the pointer).

Instead of pointers, to reference an object in a different branch (but in the same entry), you can use a TRef object and/or a TRefArray. (And in conjunction with TTree::BranchRef, it can even load automatic the referenced object).

Another alternative is to store a numerical ‘index’ into a collection instead of a pointer or a TRef.

Cheers,
Philippe.