# TTree compression factor 1.00

**URL:** <https://root-forum.cern.ch/t/ttree-compression-factor-1-00/31850>\
**Category:** ROOT\
**Tags:** tree\
**Created:** [December 2, 2018, 4:53pm UTC](https://root-forum.cern.ch/t/ttree-compression-factor-1-00/31850 "2018-12-02T16:53:10Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_Green](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/matthew_green/32/19997_2.png) [@Matthew\_Green](https://root-forum.cern.ch/u/Matthew_Green)\
**Post date:** [December 2, 2018, 4:53pm UTC](https://root-forum.cern.ch/t/ttree-compression-factor-1-00/31850/1 "2018-12-02T16:53:10Z")

</div>

Hi-

I’m having an issue where the root files I build as a result of a TTree-based analysis are not being compressed. If I check the compression of the tree with a tree-\>Print(), each branch and the total tree return a compression factor of 1.00. Previous analysis of similar data have yielded compression factors of \> 15. If I manually specify a compression level or compression settings prior to the TFile-\>Write() it seems to have no effect. I realize this is a somewhat vague question, but what things might prevent a TFile from being compressed?

-Matt

* * *

_ROOT Version:_ 6.12.06, 6.14.06  
_Platform:_ SL 6.4, MACOSX 10.14.1  
_Compiler:_ gcc4.8.2, Xcode

* * *

---

<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 2, 2018, 5:12pm UTC](https://root-forum.cern.ch/t/ttree-compression-factor-1-00/31850/2 "2018-12-02T17:12:54Z")

</div>

It ‘could’ that this particular data set is uncompressible or too small to be compressed.

If you provide both the odd file and a typical file we can take a closer look at what might have caused it.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [December 2, 2018, 6:32pm UTC](https://root-forum.cern.ch/t/ttree-compression-factor-1-00/31850/3 "2018-12-02T18:32:41Z")

</div>

Try to enforce the compression algorithm and its level, e.g.:  
[`TFile *f = TFile::Open("f.root", "RECREATE", "", 101); // 101 = 100 * ROOT::kZLIB + 1`](https://root-forum.cern.ch/t/help-on-method-s-to-create-tree-from-multi-fold-gamma-ray-coincidence-data/29704/19)

---

<div class="post-metadata">

**Author:** ![Matthew\_Green](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/matthew_green/32/19997_2.png) [@Matthew\_Green](https://root-forum.cern.ch/u/Matthew_Green)\
**Post date:** [December 2, 2018, 6:50pm UTC](https://root-forum.cern.ch/t/ttree-compression-factor-1-00/31850/4 "2018-12-02T18:50:05Z")

</div>

Hi Wile, thanks for the tip, but setting at TFile creation or immediately before closing with TFile::SetCompressionSettings() doesn’t seem to have an effect.

---

<div class="post-metadata">

**Author:** ![Matthew\_Green](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/matthew_green/32/19997_2.png) [@Matthew\_Green](https://root-forum.cern.ch/u/Matthew_Green)\
**Post date:** [December 2, 2018, 7:30pm UTC](https://root-forum.cern.ch/t/ttree-compression-factor-1-00/31850/5 "2018-12-02T19:30:01Z")

</div>

Attached are 2 sample root files, the results of processing of the same data set. The only difference between these 2 files is should be the values in the fNPE branch of the tree simTree. samplefile.root is incompressible, while samplefile\_small.root has a compression factor of 20.

[samplefile.root](https://drive.google.com/file/d/1Su6_gvVq7_otE-wqdlniNYyQ0-dOkEnj/view?usp=sharing)  
[samplefile\_small.root](https://drive.google.com/file/d/1Gk3ARjx8gN0coDGzQd1WRFf0ocp8AAda/view?usp=sharing)

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [December 2, 2018, 7:43pm UTC](https://root-forum.cern.ch/t/ttree-compression-factor-1-00/31850/6 "2018-12-02T19:43:50Z")

</div>

The “simTree” in the “samplefile.root” file has one additional branch:

```auto
*Br 29 :fAnalysisEventDataVector.fIsVetoOnly : *
* | Bool_t fIsVetoOnly[fAnalysisEventDataVector_] *

```

Also, the “samplefile.root” was created with ROOT 6.12/06 while the “samplefile\_small.root” file with ROOT 6.12/04.

---

<div class="post-metadata">

**Author:** ![Matthew\_Green](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/matthew_green/32/19997_2.png) [@Matthew\_Green](https://root-forum.cern.ch/u/Matthew_Green)\
**Post date:** [December 2, 2018, 7:58pm UTC](https://root-forum.cern.ch/t/ttree-compression-factor-1-00/31850/7 "2018-12-02T19:58:48Z")

</div>

Yes, you’re right; I’d missed that. That branch is populated with zeros; I’m not sure how that would affect its compressibility, though.

---

<div class="post-metadata">

**Author:** ![Matthew\_Green](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/matthew_green/32/19997_2.png) [@Matthew\_Green](https://root-forum.cern.ch/u/Matthew_Green)\
**Post date:** [December 2, 2018, 8:29pm UTC](https://root-forum.cern.ch/t/ttree-compression-factor-1-00/31850/8 "2018-12-02T20:29:52Z")

</div>

Removing the fIsVetoOnly branch from the analysis doesn’t affect the compressibility, so the problem is not in that branch.

---

<div class="post-metadata">

**Author:** ![Matthew\_Green](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/matthew_green/32/19997_2.png) [@Matthew\_Green](https://root-forum.cern.ch/u/Matthew_Green)\
**Post date:** [December 3, 2018, 5:05pm UTC](https://root-forum.cern.ch/t/ttree-compression-factor-1-00/31850/9 "2018-12-03T17:05:24Z")

</div>

Hi all-

I seem to have sorted this out. As part of the analysis process I loaded a pair of histograms, a TH2D and a TH3D from an external root file to use as lookup tables. I did this by doing the following:

fMapFile = new TFile(fMapFileName.c\_str());  
if(fMapFile==NULL) { cerr \<\< "Couldn’t open file: " \<\< fMapFileName \<\< endl; return; }  
fProbMapInterior = (TH3D\*) fMapFile-\>Get(“ProbMapInterior”);  
fProbMapInterior-\>SetDirectory(0);  
fProbMapExterior = (TH2D\*) fMapFile-\>Get(“ProbMapExterior”);  
fProbMapExterior-\>SetDirectory(0);  
fMapFile-\>Close();

This allowed for the tree building and writing to file to proceed while these 2 histograms remained resident in memory. However either not explicitly returning to the previously created output file before writing the tree, or leaving these 2 histograms in memory in Directory(0) prevented the output tree from being compressible.

Instead of moving these histograms to Directory(0), I leave the file open, and use a cd() call to move to the file when I need to access the histograms, and another cd() to return to the previous directory and it seems to work fine.

Thanks for your input.

---

<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 3, 2018, 5:35pm UTC](https://root-forum.cern.ch/t/ttree-compression-factor-1-00/31850/10 "2018-12-03T17:35:43Z")

</div>

This does not sound right. What you describe should _not_ affect the compression of the TTree. So there is either a behavior I forgot about or a deficiency we need to fix. Could you provide a reproducer?

Thanks,  
Philippe.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [December 3, 2018, 8:28pm UTC](https://root-forum.cern.ch/t/ttree-compression-factor-1-00/31850/11 "2018-12-03T20:28:08Z")

</div>

I think I can reproduce the problem (the fix is trivial, as you can see below):

```auto
{
  // create a new file
  TFile *f_new = TFile::Open("f_new.root", "recreate", "", 101);
  
#if 1 /* 0 or 1 */
  gROOT->cd(); // switch to RAM
#else /* 0 or 1 */
  // open some old file
  TFile *f_old = TFile::Open("f_old.root");
  // retrieve any objects
  delete f_old;
#endif /* 0 or 1 */
  
  f_new->cd(); // MANDATORY, OTHERWISE THE FILE COMPRESSION WILL NOT WORK !!!
  TTree *t = new TTree("t", "t"); // create a new DISK RESIDENT tree
  
  // fill the tree
  Float_t v; t->Branch("v", &v, "v/F");
  for (Int_t i = 0; i < 999999; i++) { v = gRandom->Gaus(0., 1.); t->Fill(); }
  
  // save the tree to a file
  f_new->cd(); // just a precaution
  t->Write();
  delete f_new; // automatically deletes "t", too
}

```

@pcanal So, if you create a “RAM resident” tree and then write it to a file, it will NOT be compressed (a bug in ROOT? or a feature?).

@pcanal Unfortunately, I have also found that the ROOT command line tools, which can change the compression settings for the destination file (e.g. “rootcp” and “rootmv”), are NOT able to change the compression level for trees (a bug in ROOT? or a feature?).

---

<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 12, 2018, 6:30pm UTC](https://root-forum.cern.ch/t/ttree-compression-factor-1-00/31850/12 "2018-12-12T18:30:46Z")

</div>

> So, if you create a “RAM resident” tree and then write it to a file, it will NOT be compressed (a bug in ROOT? or a feature?).

It is a bug …

> Unfortunately, I have also found that the ROOT command line tools, which can change the compression settings for the destination file (e.g. “rootcp” and “rootmv”), are NOT able to change the compression level for trees (a bug in ROOT? or a feature?).

likely also a bug.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [December 26, 2018, 6:30pm UTC](https://root-forum.cern.ch/t/ttree-compression-factor-1-00/31850/13 "2018-12-26T18:30:47Z")

</div>

Closed on December 26, 2018, 6:30pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [September 14, 2020, 1:59pm UTC](https://root-forum.cern.ch/t/ttree-compression-factor-1-00/31850/14 "2020-09-14T13:59:52Z")

</div>

Could you create a bug report (and possibly fix it, depending on relative priority), @pcanal ?

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [September 14, 2020, 2:00pm UTC](https://root-forum.cern.ch/t/ttree-compression-factor-1-00/31850/15 "2020-09-14T14:00:17Z")

</div>

Opened on September 14, 2020, 2:00pm UTC



---

<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:** [September 14, 2020, 9:47pm UTC](https://root-forum.cern.ch/t/ttree-compression-factor-1-00/31850/16 "2020-09-14T21:47:11Z")

</div>

See [https://github.com/root-project/root/issues/6349](https://github.com/root-project/root/issues/6349) (rootcp and rootmv and compression level update)  
and [https://github.com/root-project/root/issues/6350](https://github.com/root-project/root/issues/6350) (lack of compression)

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [September 22, 2020, 7:12pm UTC](https://root-forum.cern.ch/t/ttree-compression-factor-1-00/31850/17 "2020-09-22T19:12:07Z")

</div>

Closed on September 22, 2020, 7:12pm UTC


