Making a new tree via CopyTree memory resident

Dear Root experts,

I would like to read a tree from a root file, open a new file on which I point to write some stuff, and then copy my original tree with the TTree:CopyTree command but letting it as a memory resident tree.
Pointing to a new file is setting the directory of the new tree to the output file I have, and this is not what I want, but it will be very complicated to do otherwise.

So my question can be resume to : “is it possible to change the original directory of a new file produced with the CopyTree function?”

Many thanks by advance,
Best regards
Matthieu

Hi,

[quote]So my question can be resume to : “is it possible to change the original directory of a new file produced with the CopyTree function?”[/quote]Changing it after the fact is not effective (it would not re-load the data from the file).

You can either make sure it is created as a memory TTree by setting gDirectory to nullptr before copying.gDirectory = nullptr; // Or TDirectory::TContext ctxt(nullptr); TTree* newtree = oldtree->CopyTree(...);

Or you can request the loading of all the basket in memory from an existing TTree and then detach it from the input file.tree->LoadBaskets(); // If the TTree is larger that 2GB pass the max amount of memory (expressed in bytes) the TTree is allowed to use. tree->SetDirectory(nullptr);

Cheers,
Philippe.