# Copy several histogram in one root file

**URL:** <https://root-forum.cern.ch/t/copy-several-histogram-in-one-root-file/20113>\
**Category:** ROOT\
**Created:** [October 30, 2015, 3:12pm UTC](https://root-forum.cern.ch/t/copy-several-histogram-in-one-root-file/20113 "2015-10-30T15:12:14Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![calbet](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/4af34b/32.png) [@calbet](https://root-forum.cern.ch/u/calbet)\
**Post date:** [October 30, 2015, 3:12pm UTC](https://root-forum.cern.ch/t/copy-several-histogram-in-one-root-file/20113/1 "2015-10-30T15:12:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [October 30, 2015, 3:18pm UTC](https://root-forum.cern.ch/t/copy-several-histogram-in-one-root-file/20113/2 "2015-10-30T15:18:00Z")

</div>

We have now new shell commands doing that:

```auto
$ 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.

```

---

<div class="post-metadata">

**Author:** ![calbet](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/4af34b/32.png) [@calbet](https://root-forum.cern.ch/u/calbet)\
**Post date:** [November 1, 2015, 12:35am UTC](https://root-forum.cern.ch/t/copy-several-histogram-in-one-root-file/20113/3 "2015-11-01T00:35:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [November 2, 2015, 8:12am UTC](https://root-forum.cern.ch/t/copy-several-histogram-in-one-root-file/20113/4 "2015-11-02T08:12:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![calbet](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/4af34b/32.png) [@calbet](https://root-forum.cern.ch/u/calbet)\
**Post date:** [November 2, 2015, 9:18am UTC](https://root-forum.cern.ch/t/copy-several-histogram-in-one-root-file/20113/5 "2015-11-02T09:18:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mato](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mato/32/12317_2.png) [@mato](https://root-forum.cern.ch/u/mato)\
**Post date:** [November 2, 2015, 10:01am UTC](https://root-forum.cern.ch/t/copy-several-histogram-in-one-root-file/20113/6 "2015-11-02T10:01:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![calbet](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/4af34b/32.png) [@calbet](https://root-forum.cern.ch/u/calbet)\
**Post date:** [November 2, 2015, 10:18am UTC](https://root-forum.cern.ch/t/copy-several-histogram-in-one-root-file/20113/7 "2015-11-02T10:18:00Z")

</div>

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

Regards

---

<div class="post-metadata">

**Author:** ![mato](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mato/32/12317_2.png) [@mato](https://root-forum.cern.ch/u/mato)\
**Post date:** [November 2, 2015, 10:29am UTC](https://root-forum.cern.ch/t/copy-several-histogram-in-one-root-file/20113/8 "2015-11-02T10:29:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![calbet](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/4af34b/32.png) [@calbet](https://root-forum.cern.ch/u/calbet)\
**Post date:** [November 2, 2015, 10:40am UTC](https://root-forum.cern.ch/t/copy-several-histogram-in-one-root-file/20113/9 "2015-11-02T10:40:32Z")

</div>

I got it from CMSSW\_7\_4\_6\_patch1. Do you know which CMSSW provide root 6.05?

regards

---

<div class="post-metadata">

**Author:** ![calbet](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/4af34b/32.png) [@calbet](https://root-forum.cern.ch/u/calbet)\
**Post date:** [November 2, 2015, 1:30pm UTC](https://root-forum.cern.ch/t/copy-several-histogram-in-one-root-file/20113/10 "2015-11-02T13:30:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mato](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mato/32/12317_2.png) [@mato](https://root-forum.cern.ch/u/mato)\
**Post date:** [November 2, 2015, 1:32pm UTC](https://root-forum.cern.ch/t/copy-several-histogram-in-one-root-file/20113/11 "2015-11-02T13:32:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![calbet](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/4af34b/32.png) [@calbet](https://root-forum.cern.ch/u/calbet)\
**Post date:** [November 2, 2015, 1:51pm UTC](https://root-forum.cern.ch/t/copy-several-histogram-in-one-root-file/20113/12 "2015-11-02T13:51:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mato](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mato/32/12317_2.png) [@mato](https://root-forum.cern.ch/u/mato)\
**Post date:** [November 2, 2015, 2:44pm UTC](https://root-forum.cern.ch/t/copy-several-histogram-in-one-root-file/20113/13 "2015-11-02T14:44:13Z")

</div>

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:

- Install latest version of ROOT (6.05.02) and the follow the suggestion from Olivier
- Have a look at the file [github.com/root-mirror/root/blo … neUtils.py](https://github.com/root-mirror/root/blob/master/main/python/cmdLineUtils.py) and extract from there the python code to do what you need.

---

<div class="post-metadata">

**Author:** ![calbet](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/4af34b/32.png) [@calbet](https://root-forum.cern.ch/u/calbet)\
**Post date:** [November 3, 2015, 3:06pm UTC](https://root-forum.cern.ch/t/copy-several-histogram-in-one-root-file/20113/14 "2015-11-03T15:06:35Z")

</div>

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](http://libDataFormatsStdDictionaries.so) is already in [libCore.so](http://libCore.so) Warning in TInterpreter::ReadRootmapFile: class pair\<const std::string,int\> found in [libDataFormatsStdDictionaries.so](http://libDataFormatsStdDictionaries.so) is already in [libCore.so](http://libCore.so) Warning in TInterpreter::ReadRootmapFile: class pair\<const string,int\> found in [libDataFormatsStdDictionaries.so](http://libDataFormatsStdDictionaries.so) is already in [libCore.so](http://libCore.so) Warning in TInterpreter::ReadRootmapFile: class pair\<double,double\> found in [libDataFormatsStdDictionaries.so](http://libDataFormatsStdDictionaries.so) is already in [libCore.so](http://libCore.so) Warning in TInterpreter::ReadRootmapFile: class pair\<float,float\> found in [libDataFormatsStdDictionaries.so](http://libDataFormatsStdDictionaries.so) is already in [libCore.so](http://libCore.so) Warning in TInterpreter::ReadRootmapFile: class pair\<int,double\> found in [libDataFormatsStdDictionaries.so](http://libDataFormatsStdDictionaries.so) is already in [libCore.so](http://libCore.so) Warning in TInterpreter::ReadRootmapFile: class pair\<int,int\> found in [libDataFormatsStdDictionaries.so](http://libDataFormatsStdDictionaries.so) is already in [libCore.so](http://libCore.so) Warning in TInterpreter::ReadRootmapFile: class pairstd::string,int found in [libDataFormatsStdDictionaries.so](http://libDataFormatsStdDictionaries.so) is already in [libCore.so](http://libCore.so) Warning in TInterpreter::ReadRootmapFile: class pair\<string,double\> found in [libDataFormatsStdDictionaries.so](http://libDataFormatsStdDictionaries.so) is already in [libCore.so](http://libCore.so) Warning in TInterpreter::ReadRootmapFile: class pair\<string,float\> found in [libDataFormatsStdDictionaries.so](http://libDataFormatsStdDictionaries.so) is already in [libCore.so](http://libCore.so) Warning in TInterpreter::ReadRootmapFile: class pair\<string,int\> found in [libDataFormatsStdDictionaries.so](http://libDataFormatsStdDictionaries.so) is already in [libCore.so](http://libCore.so)

| Welcome to ROOT 6.05/02 [root.cern.ch](http://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’ |
| --- |

---

<div class="post-metadata">

**Author:** ![mato](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mato/32/12317_2.png) [@mato](https://root-forum.cern.ch/u/mato)\
**Post date:** [November 3, 2015, 4:07pm UTC](https://root-forum.cern.ch/t/copy-several-histogram-in-one-root-file/20113/15 "2015-11-03T16:07:46Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![calbet](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/4af34b/32.png) [@calbet](https://root-forum.cern.ch/u/calbet)\
**Post date:** [November 3, 2015, 5:07pm UTC](https://root-forum.cern.ch/t/copy-several-histogram-in-one-root-file/20113/16 "2015-11-03T17:07:18Z")

</div>

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](http://libDataFormatsStdDictionaries.so) is already in [libCore.so](http://libCore.so)  
Warning in TInterpreter::ReadRootmapFile: class pair\<const std::string,int\> found in [libDataFormatsStdDictionaries.so](http://libDataFormatsStdDictionaries.so) is already in [libCore.so](http://libCore.so)  
Warning in TInterpreter::ReadRootmapFile: class pair\<const string,int\> found in [libDataFormatsStdDictionaries.so](http://libDataFormatsStdDictionaries.so) is already in [libCore.so](http://libCore.so)  
Warning in TInterpreter::ReadRootmapFile: class pair\<double,double\> found in [libDataFormatsStdDictionaries.so](http://libDataFormatsStdDictionaries.so) is already in [libCore.so](http://libCore.so)  
Warning in TInterpreter::ReadRootmapFile: class pair\<float,float\> found in [libDataFormatsStdDictionaries.so](http://libDataFormatsStdDictionaries.so) is already in [libCore.so](http://libCore.so)  
Warning in TInterpreter::ReadRootmapFile: class pair\<int,double\> found in [libDataFormatsStdDictionaries.so](http://libDataFormatsStdDictionaries.so) is already in [libCore.so](http://libCore.so)  
Warning in TInterpreter::ReadRootmapFile: class pair\<int,int\> found in [libDataFormatsStdDictionaries.so](http://libDataFormatsStdDictionaries.so) is already in [libCore.so](http://libCore.so)  
Warning in TInterpreter::ReadRootmapFile: class pairstd::string,int found in [libDataFormatsStdDictionaries.so](http://libDataFormatsStdDictionaries.so) is already in [libCore.so](http://libCore.so)  
Warning in TInterpreter::ReadRootmapFile: class pair\<string,double\> found in [libDataFormatsStdDictionaries.so](http://libDataFormatsStdDictionaries.so) is already in [libCore.so](http://libCore.so)  
Warning in TInterpreter::ReadRootmapFile: class pair\<string,float\> found in [libDataFormatsStdDictionaries.so](http://libDataFormatsStdDictionaries.so) is already in [libCore.so](http://libCore.so)  
Warning in TInterpreter::ReadRootmapFile: class pair\<string,int\> found in [libDataFormatsStdDictionaries.so](http://libDataFormatsStdDictionaries.so) is already in [libCore.so](http://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.

---

<div class="post-metadata">

**Author:** ![quantatanu](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/quantatanu/32/20730_2.png) [@quantatanu](https://root-forum.cern.ch/u/quantatanu)\
**Post date:** [May 20, 2020, 4:36pm UTC](https://root-forum.cern.ch/t/copy-several-histogram-in-one-root-file/20113/17 "2020-05-20T16:36:52Z")

</div>

A related issue:

if I do:

```auto
rootcp source.root:*pattern* dest.root 

```

It complains:

```auto
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](https://root-forum.cern.ch/t/rooteventselector-and-multiple-ttree-with-the-same-name/28096/6), @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?
