# TH1I copy constructor does not copy current directory

**URL:** <https://root-forum.cern.ch/t/th1i-copy-constructor-does-not-copy-current-directory/18614>\
**Category:** ROOT\
**Created:** [December 12, 2014, 9:03pm UTC](https://root-forum.cern.ch/t/th1i-copy-constructor-does-not-copy-current-directory/18614 "2014-12-12T21:03:40Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![pliuphys](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/3da27b/32.png) [@pliuphys](https://root-forum.cern.ch/u/pliuphys)\
**Post date:** [December 12, 2014, 9:03pm UTC](https://root-forum.cern.ch/t/th1i-copy-constructor-does-not-copy-current-directory/18614/1 "2014-12-12T21:03:40Z")

</div>

Hi,

I was trying to put some histograms into STL vectors, assign them to a TFile. But I found that when I push\_back more, the previous histograms sometimes disappears in the TFile. See Attachment.

I believe this is because that the directory information is not saved when copying. Eg:

void histSimple()  
{  
TH1::AddDirectory(kFALSE);  
TFile f;  
TH1I h1(“h1”,“h1”,100,0.0,1.0);  
h1.SetDirectory(&f);  
cout\<\<“h1 directory:”\<\<h1.GetDirectory()\<\<endl;  
TH1I h2(h1);  
cout\<\<“h2 directory:”\<\<h2.GetDirectory()\<\<endl;  
}

Output:  
h1 directory:0xf591b0  
h2 directory:0

Is this behavior intended? I know histograms are put into pwd by default, and so with TH1::AddDirectory(kFALSE) it makes some sense to be 0. But I feel that it’s nicer to make an exception for the copy constructor.

PS:this was tested on ROOT 5.34/23.  
[histClone.C](https://root-forum.cern.ch/uploads/default/original/2X/d/d4005c51cf9833dc8fcc85e22c29e054eb0ccbc6.C) (1.16 KB)

---

_[View the full topic](https://root-forum.cern.ch/t/th1i-copy-constructor-does-not-copy-current-directory/18614)._
