Setting TFile name at the moment of writing a TTree

Hello,

I have a one run tree, and several event trees. I know the names of event trees’ files only at the time of writing the trees after filling with all the events, since the names contain the last event number. I wonder how can I store the trees to such files.

What I was doing was to create temporary files, write the trees, and then rename the files calling OS commands from the program. However, I also add the run tree as a friend to all the event trees before writing them. This way I have no problem later reading event_tree1, but event_tree2 complains about failing to find the file with event_tree1, as it holds the file’s temporary name, not the name after renaming.

Is there a way to do it, or perhaps I am missing something in the ROOT philosophy of setting file names?

Hi,

Interesting issue.
I think it’s not a matter of philosophy but perhaps causality :slight_smile:
Can you get out of this trouble by using symlinks?

Best,
D

It depends what do you mean by “using symlinks” :slight_smile: If leaving a temporary file and creating a symlink when I know the name - not in an elegant way because I will have many files of the same type, like tree_event1, for chaining. So I would be left with many temporary files such as tree_event1_1, tree_event1_2… , tree_event2_1, tree_event2_2 and corresponding symlinks with proper names.

What I am thinking about now is that I need to save an event tree to a temp file, rename the file, then open the file and add a run tree/file as a friend. This way the run tree to which I link the rest of the event files will have the correct file name of other event files, I hope. Cumbersome and slow, but if this is the only way to make it work. I only hope that adding a friend and writing back the tree (without any additional filling) does not take too much extra time.

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