# Global variables in ROOT7?

**URL:** <https://root-forum.cern.ch/t/global-variables-in-root7/22396>\
**Category:** Evolution Proposals, Apps & Ideas\
**Created:** [December 21, 2016, 5:34am UTC](https://root-forum.cern.ch/t/global-variables-in-root7/22396 "2016-12-21T05:34:31Z")\
**Posts on this page:** 2\
**Page:** 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 21, 2016, 5:34am UTC](https://root-forum.cern.ch/t/global-variables-in-root7/22396/1 "2016-12-21T05:34:31Z")

</div>

I read some old slides from ROOT7 ([indico.cern.ch/event/471936/con … -Intro.pdf](https://indico.cern.ch/event/471936/contributions/1991145/attachments/1206234/1757785/ROOT7-Discussion-Intro.pdf)) which mentioned interoperability with STL and “no context state: gDirectory […]”

I’d like to raise an old suggestion which seems to contradict with current ROOT design: is it possible to make the copy constructor of histograms copy their directory, so I can put them into std::vector? ([TH1I copy constructor does not copy current directory](https://root-forum.cern.ch/t/th1i-copy-constructor-does-not-copy-current-directory/18614/1))

The example code on [root.cern.ch/root-7](https://root.cern.ch/root-7)

` TFilePtr file = TFile::Recreate("jetmuontag.root");
  file->Write("hist_mupt", hMuPtTag);
  file->Write("hist_jetet", hJetEtTag);`  
makes it seem to me that this is still implemented effectively with some global variable (or static member of some class).

PS: I just subscribed to the root7-discussion mail list but it doesn’t allow me (lightweight account [pliuphys@gmail.com](mailto:pliuphys@gmail.com)) to read the archive.

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [December 21, 2016, 4:22pm UTC](https://root-forum.cern.ch/t/global-variables-in-root7/22396/2 "2016-12-21T16:22:57Z")

</div>

Hi,

We indeed need to think this through.

As a side, we also don’t have a move construction in the v6 histogram so even if the directory was copied, adding them to a vector could still be expansive (copying _all_ the data). So alternatively, you use a std::vector\<std::unique\_ptr\>.

Cheers,  
Philippe.
