# Automatically write all histograms created in a macro?

**URL:** <https://root-forum.cern.ch/t/automatically-write-all-histograms-created-in-a-macro/59166>\
**Category:** Newbie\
**Created:** [April 29, 2024, 1:39pm UTC](https://root-forum.cern.ch/t/automatically-write-all-histograms-created-in-a-macro/59166 "2024-04-29T13:39:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![utkarsh-2000](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/u/e47774/32.png) [@utkarsh-2000](https://root-forum.cern.ch/u/utkarsh-2000)\
**Post date:** [April 29, 2024, 1:39pm UTC](https://root-forum.cern.ch/t/automatically-write-all-histograms-created-in-a-macro/59166/1 "2024-04-29T13:39:11Z")

</div>

Hi all,

Though not of much use but,  
Is there some feature to automatically write out all the histograms into a root file which are created in a macro ? That is without specifying `hist->Write()` for each and every histogram?

Thanks

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [April 29, 2024, 6:19pm UTC](https://root-forum.cern.ch/t/automatically-write-all-histograms-created-in-a-macro/59166/2 "2024-04-29T18:19:09Z")

</div>

Hi,

If all of the histograms are owned by a TFile, you can use [TFile::Write](https://root.cern.ch/doc/master/classTDirectoryFile.html#ac07fc68f2161700baeeb54aa2810ffc1).

Best,  
D
