TTree compression factor 1.00

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?).

1 Like