Inserting entries into a tree

Hi all,

Is there an easy way to insert entries into a tree, i.e. not appending them to the end of the tree like with TTree::Fill but to insert them on a specified position?

Thx, Mathias

What do you mean by “on a specified position”?
May be you can have a look at the copytree tutorials.

Rene

When comparing a Tree with a STL vector TTree::Fill corresponds to vector::push_back, i.e. an element is inserted at the very end of the tree/vector. What I am looking for is something like the vector::insert method That inserts an entry into a tree but not necessarily at its end. One way to do that would be copying a tree up to a certain point, inserting the new value and continuing the copy-operation. I was just wondering if there is no way to do an in-place insertion, i.e. inserting an entry into an existing tree without having to copy it.

Cheers, Mathias

This would be an expensive operation.
If you look at tutorial copytree3.C, you can easily achieve this.
Modify the loop to
-copy entries 0 to N
-fill the destination Tree with your new entry
-continue the loop

Rene

Ok, thats exactly what I did.

Thanks Rene,

Mathias

[quote=“Mathias”]When comparing a Tree with a STL vector TTree::Fill corresponds to vector::push_back, i.e. an element is inserted at the very end of the tree/vector. What I am looking for is something like the vector::insert method That inserts an entry into a tree but not necessarily at its end. One way to do that would be copying a tree up to a certain point, inserting the new value and continuing the copy-operation. I was just wondering if there is no way to do an in-place insertion, i.e. inserting an entry into an existing tree without having to copy it.
[/quote]

Just out of curiosity, why not just “push” the entries on the end? (I could almost imagine doing what you want to create a tree for debugging purposes…)

Cheers,
Charles

It’s just to maintain the order in time for my events. I want to insert some artificial events to get rid of some deadtime purposes of my experiment. Therefore I have to insert these events into specific positions to maintain the chronicle order of my events. That’s it.