Home | News | Documentation | Download

Two Trees are getting created while asking for one


ROOT Version: 6.20/08
Platform: Ubuntu 18.04.06
Compiler: gcc7.5.0


Hi Experts,
I was trying to extract some variables from one ROOT file to another. I am defining only one TTree to be created, but the new file is having two TTree. I cannot understand what is happening. More peculiarly, when I was creating the macro it was working fine. But just when I ran it via a shell script it started this behavior. After that even for manual single runs, it’s not working. This happened twice.
Could you people give some idea what’s wrong in the macro?
I guess I have to delete the memory pointer to the new TTree. But how to do it? I tried with delete outtree; delete outfile;, but it didn’t work.
I have attached an example input file and the macro.
Thanks in advance.

Regards,
Saumyen

Zextract.C (2.9 KB)
ToyFile.root (2.4 MB)

Instead of

  outfile->Write();
delete outtree;
delete outfile;

try

outfile->cd();  // just in case
outtree->Write();
outfile->Close();
delete outfile;

What do you get from: outfile->ls();

Thanks a lot to both of you @dastudillo and @Wile_E_Coyote .
I tried the suggestion by @dastudillo. But that didn’t work. Then I tried @Wile_E_Coyote’s suggestion to see what’s happening. What I found is this:

TFile**		/home/photoniman/Research/SP_BP2.root	
TFile*		/home/photoniman/Research/SP_BP2.root	
  OBJ: TTree	event_tree	Test : 0 at: 0x55981d7365f0
  KEY: TTree	event_tree;2	Test
  KEY: TTree	event_tree;1	Test

Although in TBrowser it was showing this:
Screenshot from 2021-12-03 01-54-52

Any idea what’s happening?

Regards,
Saumyen

Thanks a lot @Wile_E_Coyote . Now it’s working fine. I just replaced outtree->Write(); with outtree->Write("", TObject::kOverwrite); in @dastudillo’s code-suggestion.
Thanks to both of you.

Regards,
Saumyen

Note that event_tree;2 and event_tree;1 are not two completely different trees. These are namecycles for the same tree (see e.g. the link by @Wile_E_Coyote ), a crash-recovery mechanism. Only the TTree metadata is duplicated between namecycles, data is only present once in the file.

In practice you can ignore the namecycles and only use the name event_tree. @pcanal might be able to point you to more resources.

Cheers,
Enrico

1 Like

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