Copy several histogram in one root file

Dear experts,

I have several root files with many histograms and the histograms have different name. I want to copy all these histogram in one root file.
Please notice that I do not want to add the histogram, I want to keep them separate, and have all of them in a single root file.
Is there an option to do that, or do you have an idea on how I can achieve that?

Regards

We have now new shell commands doing that:

$ rootcp -h
usage: rootcp [-h] [-c COMPRESS] [--recreate] [-r] [--replace]
              SOURCE [SOURCE ...] DEST

Copy objects from ROOT files into an other

positional arguments:
  SOURCE                Source file
  DEST                  Destination file

optional arguments:
  -h, --help            show this help message and exit
  -c COMPRESS, --compress COMPRESS
                        change the compression settings of the destination
                        file (if not already existing).
  --recreate            recreate the destination file.
  -r, --recursive       recurse inside directories
  --replace             replace object if already existing

Examples:
- roocp source.root:hist* dest.root
  Copy all histograms whose named starts with 'hist' from 'source.root' to 'dest.root'.

- roocp source1.root:hist1 source2.root:hist2 dest.root
  Copy histograms 'hist1' from 'source1.root' and 'hist2' from 'source2.root' to 'dest.root'.

- roocp --recreate source.root:hist dest.root
  Recreate the destination file 'dest.root' and copy the histogram named 'hist' from 'source.root' into it.

- roocp -c 1 source.root:hist dest.root
  Change the compression factor of the destination file 'dest.root' if not existing and copy the histogram named 'hist' from 'source.root' into it.
1 Like

Dear couet,

than you for your answer, but when I doing “rootcp -h” I have the error message “rools: command not found”.
I’m using ROOT 6.02/05. Do you know how I can solve this?

Regards

The command line tools are in $ROOTSYS/bin/
see if rootcp is there
 if not it means it has not been installed.

Dear Couet,

I did not see it in my $ROOTSYS/bin/, shouldn’t it been automatically install with root?
I did not find many tutorial on this, can you please tell me (or point my a web site) how to install it?

Regards

It is automatically installed. Did you use the cmake method?

I did not install root, so I do not know it a cmake method was done. should I do it? if yes how?

Regards

From where do you get ROOT version 6.02/05?
By the way the command line tools are only available from master branch. The first version to include them is 6.05.

I got it from CMSSW_7_4_6_patch1. Do you know which CMSSW provide root 6.05?

regards

On lxplus I sourced: source /afs/cern.ch/sw/lcg/app/releases/ROOT/6.05.02

but when I run root, the version does not match. Do you know how to source the root version that we want?

Regard

If you do “which rootcp” from where you get the command?

If I do: which rootcp I have:
rootcp: Command not found.

because it is still an holder root version. This source command does not work.

Regards

I was confused by one of your comments that ‘rootcp’ was there and not ‘roots’. It seems that you have nothing since you are using 6.02. So in this case you have two options:

Dear experts,

I copied then untar root_v6.05.02.Linux-slc6-x86_64-gcc4.9.tar.gz

because my gcc version is 4.9.1.

then I source ~/root/bin/thisroot.sh

and when I launch root I got many warning[1]:

and rootcp -h give:
rootcp: command not found

Does someone know how if rootcp is already available, and if yes how it works?

[1]
-bash-4.1$ root
Warning in TInterpreter::ReadRootmapFile: class pair<const int,int> found in libDataFormatsStdDictionaries.so is already in libCore.so
Warning in TInterpreter::ReadRootmapFile: class pair<const std::string,int> found in libDataFormatsStdDictionaries.so is already in libCore.so
Warning in TInterpreter::ReadRootmapFile: class pair<const string,int> found in libDataFormatsStdDictionaries.so is already in libCore.so
Warning in TInterpreter::ReadRootmapFile: class pair<double,double> found in libDataFormatsStdDictionaries.so is already in libCore.so
Warning in TInterpreter::ReadRootmapFile: class pair<float,float> found in libDataFormatsStdDictionaries.so is already in libCore.so
Warning in TInterpreter::ReadRootmapFile: class pair<int,double> found in libDataFormatsStdDictionaries.so is already in libCore.so
Warning in TInterpreter::ReadRootmapFile: class pair<int,int> found in libDataFormatsStdDictionaries.so is already in libCore.so
Warning in TInterpreter::ReadRootmapFile: class pairstd::string,int found in libDataFormatsStdDictionaries.so is already in libCore.so
Warning in TInterpreter::ReadRootmapFile: class pair<string,double> found in libDataFormatsStdDictionaries.so is already in libCore.so
Warning in TInterpreter::ReadRootmapFile: class pair<string,float> found in libDataFormatsStdDictionaries.so is already in libCore.so
Warning in TInterpreter::ReadRootmapFile: class pair<string,int> found in libDataFormatsStdDictionaries.so is already in libCore.so

| Welcome to ROOT 6.05/02 root.cern.ch |
| © 1995-2014, The ROOT Team |
| Built for linuxx8664gcc |
| From tag v6-05-02, 14 September 2015 |

Try ‘.help’, ‘.demo’, ‘.license’, ‘.credits’, ‘.quit’/’.q’

I noticed a mistake today and already correct it in the master. The new commands line programs were installed in the wrong place. Please use $ROOTSYS/bin/bin/rootcp -h :slight_smile:

Hi Mato,

  • I had to make it executable “chmod u+x rootcp”.
  • then I got many warning message, should I care about them [1]?

Regards

[1]
-bash-4.1$ $ROOTSYS/bin/bin/rootcp -h
Warning in TInterpreter::ReadRootmapFile: class pair<const int,int> found in libDataFormatsStdDictionaries.so is already in libCore.so
Warning in TInterpreter::ReadRootmapFile: class pair<const std::string,int> found in libDataFormatsStdDictionaries.so is already in libCore.so
Warning in TInterpreter::ReadRootmapFile: class pair<const string,int> found in libDataFormatsStdDictionaries.so is already in libCore.so
Warning in TInterpreter::ReadRootmapFile: class pair<double,double> found in libDataFormatsStdDictionaries.so is already in libCore.so
Warning in TInterpreter::ReadRootmapFile: class pair<float,float> found in libDataFormatsStdDictionaries.so is already in libCore.so
Warning in TInterpreter::ReadRootmapFile: class pair<int,double> found in libDataFormatsStdDictionaries.so is already in libCore.so
Warning in TInterpreter::ReadRootmapFile: class pair<int,int> found in libDataFormatsStdDictionaries.so is already in libCore.so
Warning in TInterpreter::ReadRootmapFile: class pairstd::string,int found in libDataFormatsStdDictionaries.so is already in libCore.so
Warning in TInterpreter::ReadRootmapFile: class pair<string,double> found in libDataFormatsStdDictionaries.so is already in libCore.so
Warning in TInterpreter::ReadRootmapFile: class pair<string,float> found in libDataFormatsStdDictionaries.so is already in libCore.so
Warning in TInterpreter::ReadRootmapFile: class pair<string,int> found in libDataFormatsStdDictionaries.so is already in libCore.so
usage: rootcp [-h] [-c COMPRESS] [–recreate] [-r] [–replace]
SOURCE [SOURCE 
] DEST

Copy objects from ROOT files into an other

positional arguments:
SOURCE Source file
DEST Destination file

optional arguments:
-h, --help show this help message and exit
-c COMPRESS, --compress COMPRESS
change the compression settings of the destination
file (if not already existing).
–recreate recreate the destination file.
-r, --recursive recurse inside directories
–replace replace object if already existing

Examples:

  • roocp source.root:hist* dest.root
    Copy all histograms whose named starts with ‘hist’ from ‘source.root’ to ‘dest.root’.

  • roocp source1.root:hist1 source2.root:hist2 dest.root
    Copy histograms ‘hist1’ from ‘source1.root’ and ‘hist2’ from ‘source2.root’ to ‘dest.root’.

  • roocp --recreate source.root:hist dest.root
    Recreate the destination file ‘dest.root’ and copy the histogram named ‘hist’ from ‘source.root’ into it.

  • roocp -c 1 source.root:hist dest.root
    Change the compression factor of the destination file ‘dest.root’ if not existing and copy the histogram named ‘hist’ from ‘source.root’ into it.

A related issue:

if I do:

rootcp source.root:*pattern* dest.root 

It complains:

WARNING: Same name objects aren't supported: 'some_name_with_pattern' of 'source.root' won't be processed

The object some_name_with_pattern usually has multiple versions: ;1, ;2 etc. I would like to copy just the latest version but I don’t want to hardcode the version and would like to use just *pattern* while copying.

Here, @couet said:

Note: If an object has been written to a file multiple times, rootcp will copy only the latest version of that object.

does that mean, despite the warning, 'source.root' won't be processed, dest.root will still be good?