How to copy one file's content into a new file's directory?

I have many files that each contains several histogram. I want to copy all these files’ contents into one data file. For example, the file h11.root, h12.root …, h90.root that each contains these TH1 Objects:

  KEY: TH2F     ph_psd;1        Kmax/KmaxNT 2D Histogram
  KEY: TH1F     ph;1    Kmax/KmaxNT 1D Histogram
  KEY: TH2F     phm_tofm;1      Kmax/KmaxNT 2D Histogram
  KEY: TH1F     phm;1   Kmax/KmaxNT 1D Histogram
  KEY: TH1F     psd;1   Kmax/KmaxNT 1D Histogram
  KEY: TH1F     tof;1   Kmax/KmaxNT 1D Histogram
  KEY: TH1F     tofm;1  Kmax/KmaxNT 1D Histogram

I want the contents of h12.root becomes the content of directory “h12” in the new file “hists.root”. How to realize this?

After searching the forum, I got some example about displaying the contents of a directory. But I still have no idea about how to implement my task.

Hope to get your help. Regards.

I mean copy the contents of “file1.root” into the directory “file1” within file2.root. All objects and directories will be copied too. How to?

See example in the attachement. This example is a new tutorial
in $ROOTSYS/tutorials/copyFiles.C

Rene
copyFiles.C (2.19 KB)

I hope this function can be added to TDirectory or TFile like this:
TDirectory::CopyDirectory(TDirectory *dir, char *newName=NULL);
or
TDirectory:ImportDir(TDirectory *dir, char *newName=NULL);

Thank you very much. :slight_smile:

I mean, when I create a TBrowser object, in the browser window, I can drag and drop one dir from one file into another directory. If this is implemented, it will be more convinient. I expect it in the future version. :slight_smile:

The CopyDir function cannot be added as it is in TDirectory because
it depends on TTree. More generally, it could be that users store
objects like TTree with overflow of buffers on disk. These objects may
require special code to copy these buffers.
I leave it for the time being as an example in the tutorials.

Rene