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?
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.
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.
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:
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.
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?
I think I can reproduce the problem (the fix is trivial, as you can see below):
{
// 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?).
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?).